Skip to content

Commit d33b24a

Browse files
feat: add input component for ShadCN
1 parent 885edaa commit d33b24a

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

tailwind.config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Config } from "tailwindcss"
2+
import plugin from "tailwindcss/plugin"
23

34
const config = {
45
darkMode: ["class"],
@@ -106,7 +107,24 @@ const config = {
106107
},
107108
},
108109
},
109-
plugins: [require("tailwindcss-animate")],
110+
plugins: [
111+
require("tailwindcss-animate"),
112+
plugin(function ({ matchVariant }) {
113+
// The :not() pseudo-class. `i.e. not-[:checked]`
114+
matchVariant(
115+
"not",
116+
(value) => {
117+
return `&:not(${value})`
118+
},
119+
{
120+
values: {
121+
// not-disabled => ":not(:disabled)"
122+
disabled: ":disabled",
123+
},
124+
}
125+
)
126+
}),
127+
],
110128
} satisfies Config
111129

112130
export default config

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 { 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)