Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add input component for ShadCN #13524

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tailwind/ui/Input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils/cn"

const inputVariants = cva(
"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",
{
variants: {
size: {
md: "p-2",
sm: "p-1 text-sm",
},
},
defaultVariants: {
size: "md",
},
}
)

export interface InputProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">,
VariantProps<typeof inputVariants> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, size, ...props }, ref) => {
return (
<input
type={type}
className={cn(inputVariants({ size, className }))}
ref={ref}
{...props}
/>
)
}
)
Input.displayName = "Input"

export default Input
37 changes: 37 additions & 0 deletions tailwind/ui/__stories__/Input.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Meta, StoryObj } from "@storybook/react/*"

import { VStack } from "../../../src/components/ui/flex"
import Input from "../Input"

const meta = {
title: "Atoms / Form / ShadCN Input",
component: Input,
} satisfies Meta<typeof Input>

export default meta

type Story = StoryObj<typeof meta>

export const Sizes: Story = {
args: {
placeholder: "Search",
},
render: (args) => (
<VStack className="w-[154px]">
<Input {...args} />
<Input {...args} size="sm" />
</VStack>
),
}

export const ElementVariations: Story = {
args: {
placeholder: "input text",
},
render: (args) => (
<VStack className="w-[258px] gap-4">
<Input {...args} autoFocus />
<Input {...args} disabled />
</VStack>
),
}
Loading