-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { userEvent } from "@storybook/test"; | ||
|
||
import { InputFilled } from "./InputFilled"; | ||
|
||
const meta = { | ||
component: InputFilled, | ||
} satisfies Meta<typeof InputFilled>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Basic = { | ||
args: { | ||
placeholder: "Placeholder", | ||
defaultValue: "", | ||
"aria-invalid": false, | ||
readOnly: false, | ||
disabled: false, | ||
}, | ||
} satisfies Story; | ||
|
||
export const Interactivity = { | ||
args: { | ||
placeholder: "Placeholder", | ||
}, | ||
render: (args) => ( | ||
<div className="flex flex-col items-start gap-4"> | ||
<InputFilled {...args} defaultValue="Focused" /> | ||
<InputFilled {...args} defaultValue="Invalid" aria-invalid /> | ||
<InputFilled {...args} defaultValue="Read-only" readOnly /> | ||
<InputFilled {...args} placeholder="Placeholder" /> | ||
<InputFilled {...args} defaultValue="Disabled" disabled /> | ||
</div> | ||
), | ||
play: async () => { | ||
await userEvent.tab(); | ||
}, | ||
} satisfies Story; | ||
|
||
export const Sizes = { | ||
args: { | ||
placeholder: "Placeholder", | ||
}, | ||
render: () => ( | ||
<div className="flex flex-col items-start gap-4"> | ||
<InputFilled size="sm" placeholder="Small" /> | ||
<InputFilled size="md" placeholder="Medium" /> | ||
<InputFilled size="lg" placeholder="Large" /> | ||
</div> | ||
), | ||
} satisfies Story; | ||
|
||
export const Shapes = { | ||
args: { | ||
placeholder: "Placeholder", | ||
}, | ||
render: () => ( | ||
<div className="flex flex-col items-start gap-4"> | ||
<InputFilled shape="rectangle" placeholder="Rectangle" /> | ||
<InputFilled shape="pill" placeholder="Pill" /> | ||
</div> | ||
), | ||
} satisfies Story; |
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,31 @@ | ||
import { clsx } from "clsx/lite"; | ||
import { forwardRef } from "react"; | ||
|
||
import { controlClassName } from "../utils/controlClassName"; | ||
|
||
export interface InputFilledProps | ||
extends Omit<React.ComponentPropsWithRef<"input">, "size"> { | ||
size?: "sm" | "md" | "lg"; | ||
shape?: "rectangle" | "pill"; | ||
placeholder: string; | ||
} | ||
|
||
export const InputFilled = forwardRef(function InputFilled( | ||
{ size = "md", shape = "rectangle", className, ...props }: InputFilledProps, | ||
ref: React.ForwardedRef<HTMLInputElement>, | ||
) { | ||
return ( | ||
<input | ||
ref={ref} | ||
className={clsx( | ||
className, | ||
controlClassName({ size, shape }), | ||
"bg-ui-neutral-200 text-ui-neutral-950 placeholder:text-ui-neutral-600 aria-invalid:ring-2 aria-invalid:ring-inset aria-invalid:ring-ui-danger-600", | ||
size === "sm" && "px-2.5", | ||
size === "md" && "px-3", | ||
size === "lg" && "px-4", | ||
)} | ||
{...props} | ||
/> | ||
); | ||
}); |
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