Skip to content

Commit

Permalink
feat: add InputFilled component
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Jul 19, 2024
1 parent 2aeccfb commit d76d916
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ButtonPrimary": "button",
"ButtonSecondary": "button",
"ButtonTertiary": "button",
"InputFilled": "input",
"InputOutlined": "input"
}
}
Expand Down
64 changes: 64 additions & 0 deletions src/components/InputFilled.stories.tsx
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;
31 changes: 31 additions & 0 deletions src/components/InputFilled.tsx
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}
/>
);
});
1 change: 1 addition & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
ButtonTertiary,
type ButtonTertiaryProps,
} from "./components/ButtonTertiary";
export { InputFilled, type InputFilledProps } from "./components/InputFilled";
export {
InputOutlined,
type InputOutlinedProps,
Expand Down

0 comments on commit d76d916

Please sign in to comment.