Skip to content

Commit 9361453

Browse files
authored
Merge pull request #13524 from TylerAPfledderer/feat/shadcn-input
feat: add input component for ShadCN
2 parents dd49640 + d831246 commit 9361453

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

tailwind/ui/Input.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as React from "react"
2+
import { cva, type VariantProps } from "class-variance-authority"
3+
4+
import { cn } from "@/lib/utils/cn"
5+
6+
const inputVariants = cva(
7+
"rounded border border-body placeholder:text-disabled hover:not-disabled:border-primary-hover focus-visible:outline focus-visible:outline-primary-hover focus-visible:outline-[3px] focus-visible:-outline-offset-2 disabled:cursor-not-allowed disabled:border-disabled bg-background",
8+
{
9+
variants: {
10+
size: {
11+
md: "p-2",
12+
sm: "p-1 text-sm",
13+
},
14+
},
15+
defaultVariants: {
16+
size: "md",
17+
},
18+
}
19+
)
20+
21+
export interface InputProps
22+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">,
23+
VariantProps<typeof inputVariants> {}
24+
25+
const Input = React.forwardRef<HTMLInputElement, InputProps>(
26+
({ className, type, size, ...props }, ref) => {
27+
return (
28+
<input
29+
type={type}
30+
className={cn(inputVariants({ size, className }))}
31+
ref={ref}
32+
{...props}
33+
/>
34+
)
35+
}
36+
)
37+
Input.displayName = "Input"
38+
39+
export default Input
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { Meta, StoryObj } from "@storybook/react/*"
2+
3+
import { VStack } from "../../../src/components/ui/flex"
4+
import Input from "../Input"
5+
6+
const meta = {
7+
title: "Atoms / Form / ShadCN Input",
8+
component: Input,
9+
} satisfies Meta<typeof Input>
10+
11+
export default meta
12+
13+
type Story = StoryObj<typeof meta>
14+
15+
export const Sizes: Story = {
16+
args: {
17+
placeholder: "Search",
18+
},
19+
render: (args) => (
20+
<VStack className="w-[154px]">
21+
<Input {...args} />
22+
<Input {...args} size="sm" />
23+
</VStack>
24+
),
25+
}
26+
27+
export const ElementVariations: Story = {
28+
args: {
29+
placeholder: "input text",
30+
},
31+
render: (args) => (
32+
<VStack className="w-[258px] gap-4">
33+
<Input {...args} autoFocus />
34+
<Input {...args} disabled />
35+
</VStack>
36+
),
37+
}

0 commit comments

Comments
 (0)