Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
Sqrrl committed Nov 20, 2024
1 parent 0e3dd71 commit a560368
Show file tree
Hide file tree
Showing 195 changed files with 10,826 additions and 925 deletions.
592 changes: 592 additions & 0 deletions apps/swirl-docs/CHANGELOG.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions apps/swirl-docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "swirl-docs",
"version": "0.1.402",
"version": "0.1.466",
"author": "Flip GmbH",
"description": "Swirl documentation",
"licence": "SEE LICENCE IN LICENSE.md",
Expand All @@ -28,9 +28,9 @@
"@algolia/autocomplete-theme-classic": "^1.7.4",
"@floating-ui/dom": "^1.1.0",
"@floating-ui/react": "^0.18.0",
"@getflip/swirl-components": "^0.217.0",
"@getflip/swirl-components-react": "^0.217.0",
"@getflip/swirl-icons": "^0.39.0",
"@getflip/swirl-components": "^0.257.0",
"@getflip/swirl-components-react": "^0.257.0",
"@getflip/swirl-icons": "^0.45.0",
"@getflip/swirl-tokens": "^2.6.0",
"@mdx-js/loader": "^2.1.3",
"@next/mdx": "^12.2.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { SwirlIconAdd, SwirlIconRemove } from "@getflip/swirl-components-react";
import classNames from "classnames";
import { AnimatePresence, motion } from "framer-motion";
import { ReactNode, useState } from "react";
import { ReactNode } from "react";
import { Tag } from "../../Tags";
import { DocumentationMarkdown } from "../DocumentationMarkdown";
import {
getStatusText,
HttpStatusCode,
isValidStatusCode,
} from "../HttpStatusCodeMapper";
import { isProdDeployment } from "@swirl/lib/env";
import { Expandable } from "../Expandable";

interface ParameterProps {
children?: ReactNode;
name: string;
type?: string;
required?: boolean;
hidden?: boolean;
description?: string;
enumValues?: string[];
array?: boolean;
}

export function Parameter({
Expand All @@ -25,12 +27,12 @@ export function Parameter({
type,
description,
required,
hidden,
enumValues,
array,
}: ParameterProps) {
const [isExpanded, setIsExpanded] = useState(false);

function toggle() {
setIsExpanded((expanded) => !expanded);
if (isProdDeployment && hidden) {
return null;
}

return (
Expand All @@ -56,75 +58,47 @@ export function Parameter({
{isValidStatusCode(name) &&
`${getStatusText(Number(name) as HttpStatusCode)}`}
</code>
{type && <Tag content={type} />}
{type && <Tag content={type + (array ? "[]" : "")} />}
{required && <Tag content="required" scheme="critical" />}
{hidden && <Tag content="hidden for public" scheme="info" /> }
</div>
{description && (
<DocumentationMarkdown className="text-sm text-text-default mt-2">
{description}
</DocumentationMarkdown>
)}
{enumValues?.length && (
<div className="mt-space-8">
<div
className={classNames(
"border-border-1 border-border-default p-4",
"first-of-type:rounded-t-border-radius-sm last-of-type:rounded-b-border-radius-sm",
"border-b-0 last-of-type:border-border-1",
"only:rounded-border-radius-sm only:border-border-1"
)}
>
<Expandable>
<div className="mt-space-8">
<div
className={classNames(
"border-border-1 border-border-default p-4",
"first-of-type:rounded-t-border-radius-sm last-of-type:rounded-b-border-radius-sm",
"border-b-0 last-of-type:border-border-1",
"only:rounded-border-radius-sm only:border-border-1"
)}
>
<span className="font-font-weight-medium text-font-size-sm text-text-subdued">
Possible enum values
</span>
</div>
<div
className={classNames(
"flex flex-wrap gap-y-space-8",
"border-border-1 border-border-default p-4",
"first-of-type:rounded-t-border-radius-sm last-of-type:rounded-b-border-radius-sm",
"border-b-0 last-of-type:border-border-1",
"only:rounded-border-radius-sm only:border-border-1"
)}
>
{enumValues.map((value) => (
<Tag key={value} content={value} />
))}
</div>
</div>
<div
className={classNames(
"flex flex-wrap gap-y-space-8",
"border-border-1 border-border-default p-4",
"first-of-type:rounded-t-border-radius-sm last-of-type:rounded-b-border-radius-sm",
"border-b-0 last-of-type:border-border-1",
"only:rounded-border-radius-sm only:border-border-1"
)}
>
{enumValues.map((value) => (
<Tag key={value} content={value} />
))}
</div>
</div>
)}
{children && (
<div className="mt-space-8 empty:mt-0">
<button
className="inline-flex items-center gap-space-4 font-medium text-font-size-sm text-interactive-primary-default"
onClick={toggle}
type="button"
>
{!isExpanded && (
<>
<SwirlIconAdd size={20} /> Expand
</>
)}
{isExpanded && (
<>
<SwirlIconRemove size={20} /> Collapse
</>
)}
</button>
<AnimatePresence>
{isExpanded && (
<motion.div
initial={{ height: 0, opacity: 0, marginTop: 0 }}
animate={{ height: "auto", opacity: 1, marginTop: 16 }}
exit={{ height: 0, opacity: 0, marginTop: 0 }}
style={{ originY: 0, overflow: "hidden" }}
>
{children}
</motion.div>
)}
</AnimatePresence>
</div>
</Expandable>
)}
{children && <Expandable>{children}</Expandable>}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export class EndpointParameterFactory {

getRenderer(type: string): ParameterRenderer {
switch (type) {
case "array":
return new ArrayParameterRenderer();
case "object":
return new ObjectParameterRenderer();
case "boolean":
Expand Down Expand Up @@ -57,6 +55,8 @@ class ObjectParameterRenderer implements ParameterRenderer {
name={parameter.name}
type={parameter.type}
description={parameter.description}
hidden={parameter.hidden}
array={parameter.array}
required={
parameter.required || schema?.required?.includes(parameter.name)
}
Expand All @@ -83,70 +83,13 @@ class PrimitiveParameterRenderer implements ParameterRenderer {
name={parameter.name}
type={parameter.type}
description={parameter.description}
hidden={parameter.hidden}
array={parameter.array}
enumValues={parameter.enum}
required={
parameter.required || schema?.required?.includes(parameter.name)
}
/>
);
}
}

class ArrayParameterRenderer implements ParameterRenderer {
render(
parameter: OperationSchemaObject,
schema?: OpenAPIV3_1.BaseSchemaObject
) {
if (parameter.items?.type === "object") {
return (
<Parameter
key={`parameter.name${parameter.name}`}
name={parameter.name}
type={parameter.type}
description={parameter.description}
required={
parameter.required || schema?.required?.includes(parameter.name)
}
>
{Object.keys(parameter.items?.properties).map((name) => {
const isRequired = parameter.items?.required
? parameter.items?.required.includes(name)
: false;
return (
<Parameter
key={`parameter.name${parameter.name}${name}`}
name={name}
type={parameter.items?.properties[name].type}
description={parameter.items?.properties[name].description}
required={isRequired}
/>
);
})}
</Parameter>
);
}

return (
<Parameter
key={`parameter.name${parameter.name}`}
name={parameter.name}
type={parameter.type}
description={parameter.description}
required={
parameter.required || schema?.required?.includes(parameter.name)
}
>
{parameter.items?.type === "string" && (
<Parameter
key={`string.${parameter.name}`}
name={parameter.items.format ? parameter.items.format : "enum"}
type={parameter.items?.type}
enumValues={parameter.items.enum}
description={
parameter.items.enum ? parameter.items.enum.join(", ") : "null"
}
/>
)}
</Parameter>
);
}
}
48 changes: 48 additions & 0 deletions apps/swirl-docs/src/components/Documentation/Expandable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ReactNode, useState } from "react";
import { SwirlIconAdd, SwirlIconRemove } from "@getflip/swirl-components-react";
import { AnimatePresence, motion } from "framer-motion";

interface ExpandableProps {
children: ReactNode;
}

export function Expandable({ children }: ExpandableProps) {
const [isExpanded, setIsExpanded] = useState(false);

function toggle() {
setIsExpanded((expanded) => !expanded);
}

return (
<div className="mt-space-8 empty:mt-0">
<button
className="inline-flex items-center gap-space-4 font-medium text-font-size-sm text-interactive-primary-default"
onClick={toggle}
type="button"
>
{!isExpanded && (
<>
<SwirlIconAdd size={20}/> Expand
</>
)}
{isExpanded && (
<>
<SwirlIconRemove size={20}/> Collapse
</>
)}
</button>
<AnimatePresence>
{isExpanded && (
<motion.div
initial={{height: 0, opacity: 0, marginTop: 0}}
animate={{height: "auto", opacity: 1, marginTop: 16}}
exit={{height: 0, opacity: 0, marginTop: 0}}
style={{originY: 0, overflow: "hidden"}}
>
{children}
</motion.div>
)}
</AnimatePresence>
</div>
)
}
8 changes: 4 additions & 4 deletions apps/swirl-docs/src/lib/docs/src/docs.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ export type ApiDoc = {

export type OperationSchemaObject = {
name: string;
type:
| OpenAPIV3_1.ArraySchemaObjectType
| OpenAPIV3_1.NonArraySchemaObjectType;
type: OpenAPIV3_1.NonArraySchemaObjectType;
description: string;
required: boolean;
hidden: boolean;
array: boolean;
properties?: OperationSchemaObject[];
items?: any;
statusCode?: string;
enum?: string[];
};

export type OperationParamType =
Expand Down
Loading

0 comments on commit a560368

Please sign in to comment.