-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
Tag
component primitive + documentation; + fixes usage bugs (#818
) Co-authored-by: Andrew Jiang <[email protected]>
- Loading branch information
1 parent
de7192b
commit 37455f8
Showing
11 changed files
with
239 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,63 @@ | ||
import { FdrAPI } from "@fern-api/fdr-sdk"; | ||
import cn from "clsx"; | ||
import { memo } from "react"; | ||
import clsx from "clsx"; | ||
import { ReactNode, memo } from "react"; | ||
import { FernTag, FernTagColorScheme, FernTagProps } from "../components/FernTag"; | ||
import { FernTooltip } from "../components/FernTooltip"; | ||
|
||
export declare namespace HttpMethodTag { | ||
export interface Props { | ||
method: FdrAPI.api.v1.read.HttpMethod; | ||
small?: boolean; | ||
className?: string; | ||
export interface Props extends FernTagProps { | ||
method: FdrAPI.api.v1.read.HttpMethod | "STREAM" | "WSS"; | ||
active?: boolean; | ||
} | ||
} | ||
|
||
const UnmemoizedHttpMethodTag: React.FC<HttpMethodTag.Props> = ({ method, small = false, className, active }) => { | ||
const METHOD_COLOR_SCHEMES: Record<HttpMethodTag.Props["method"], FernTagColorScheme> = { | ||
GET: "green", | ||
DELETE: "red", | ||
POST: "blue", | ||
STREAM: "accent", | ||
WSS: "accent", | ||
PUT: "amber", | ||
PATCH: "amber", | ||
}; | ||
|
||
const UnmemoizedHttpMethodTag: React.FC<HttpMethodTag.Props> = ({ | ||
method, | ||
active, | ||
size = "sm", | ||
className, | ||
...rest | ||
}) => { | ||
return ( | ||
<span | ||
className={cn(className, "uppercase font-mono inline-flex justify-center items-center leading-none", { | ||
["bg-tag-method-get text-text-method-get dark:text-method-get-dark"]: | ||
method === FdrAPI.api.v1.read.HttpMethod.Get && !active, | ||
["bg-method-get text-text-default-inverted"]: method === FdrAPI.api.v1.read.HttpMethod.Get && active, | ||
["bg-tag-method-post text-text-method-post"]: method === FdrAPI.api.v1.read.HttpMethod.Post && !active, | ||
["bg-method-post text-text-default-inverted"]: method === FdrAPI.api.v1.read.HttpMethod.Post && active, | ||
["bg-tag-method-delete text-text-method-delete"]: | ||
method === FdrAPI.api.v1.read.HttpMethod.Delete && !active, | ||
["bg-method-delete text-text-default-inverted"]: | ||
method === FdrAPI.api.v1.read.HttpMethod.Delete && active, | ||
["bg-tag-method-put text-text-method-put"]: method === FdrAPI.api.v1.read.HttpMethod.Put && !active, | ||
["bg-method-put text-text-default-inverted"]: method === FdrAPI.api.v1.read.HttpMethod.Put && active, | ||
["bg-tag-method-patch text-text-method-patch"]: | ||
method === FdrAPI.api.v1.read.HttpMethod.Patch && !active, | ||
["bg-method-patch text-text-default-inverted"]: | ||
method === FdrAPI.api.v1.read.HttpMethod.Patch && active, | ||
["rounded-md h-[18px] text-[10px] w-9"]: small, | ||
["py-1 px-2 rounded-lg h-6 text-xs"]: !small, | ||
})} | ||
style={{ | ||
lineHeight: 1, | ||
}} | ||
<FernTag | ||
colorScheme={METHOD_COLOR_SCHEMES[method]} | ||
variant={active ? "solid" : "subtle"} | ||
className={clsx("uppercase", { "w-11": size === "sm" }, className)} | ||
size={size} | ||
{...rest} | ||
> | ||
{method === FdrAPI.api.v1.read.HttpMethod.Delete ? "DEL" : method} | ||
</span> | ||
</FernTag> | ||
); | ||
}; | ||
|
||
export function withStream(text: ReactNode, size: "sm" | "lg" = "sm"): ReactNode { | ||
return ( | ||
<span className="inline-flex items-center gap-2"> | ||
<span>{text}</span> | ||
<UnmemoizedHttpMethodTag size={size} method="STREAM" /> | ||
</span> | ||
); | ||
} | ||
export function withWss(text: ReactNode, size: "sm" | "lg" = "sm"): ReactNode { | ||
return ( | ||
<span className="inline-flex items-center gap-2"> | ||
<span>{text}</span> | ||
<FernTooltip content="WebSocket Channel"> | ||
<UnmemoizedHttpMethodTag size={size} method="WSS" /> | ||
</FernTooltip> | ||
</span> | ||
); | ||
} | ||
|
||
export const HttpMethodTag = memo(UnmemoizedHttpMethodTag); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { FernTag, FernTagColorSchemes, FernTagSizes } from "./FernTag"; | ||
|
||
const methods = ["test", "get", "post", "put", "patch", "delete", "stream", "wss"]; | ||
|
||
const meta: Meta<typeof FernTag> = { | ||
title: "General/FernTag", | ||
component: FernTag, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
tags: ["autodocs"], | ||
args: { | ||
children: "Test", | ||
size: "lg", | ||
variant: "subtle", | ||
colorScheme: "gray", | ||
}, | ||
argTypes: { | ||
size: { | ||
options: ["sm", "lg"], | ||
control: { type: "select" }, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; | ||
|
||
export const ColorSchemes: Story = { | ||
argTypes: { | ||
colorScheme: { | ||
control: false, | ||
}, | ||
}, | ||
render: (args) => { | ||
const colorSchemes = Object.values(FernTagColorSchemes); | ||
return ( | ||
<div className="flex flex-col gap-2"> | ||
{colorSchemes.map((colorScheme, i) => ( | ||
<FernTag key={i} {...args} colorScheme={colorScheme} /> | ||
))} | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
export const Sizes: Story = { | ||
argTypes: { | ||
size: { | ||
control: false, | ||
}, | ||
}, | ||
render: (args) => { | ||
const sizes = Object.values(FernTagSizes); | ||
return ( | ||
<div className="flex gap-2"> | ||
{sizes.map((size, i) => ( | ||
<FernTag key={i} {...args} size={size} /> | ||
))} | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
export const Solid: Story = { | ||
args: { | ||
variant: "solid", | ||
}, | ||
}; | ||
|
||
export const ClassNameOverrides: Story = { | ||
args: { | ||
size: "sm", | ||
className: "w-11 uppercase", | ||
}, | ||
render: (args) => { | ||
return ( | ||
<div className="flex flex-col gap-2"> | ||
{methods.map((method) => ( | ||
<FernTag | ||
key={method} | ||
{...args} | ||
colorScheme={ | ||
method === "GET" | ||
? "green" | ||
: method === "DELETE" | ||
? "red" | ||
: method === "POST" | ||
? "blue" | ||
: method === "STREAM" || method === "WSS" | ||
? "accent" | ||
: method === "PUT" || method === "PATCH" | ||
? "amber" | ||
: "gray" | ||
} | ||
> | ||
{method === "DELETE" ? "DEL" : method} | ||
</FernTag> | ||
))} | ||
</div> | ||
); | ||
}, | ||
}; |
Oops, something went wrong.