diff --git a/src/components/common/Input/Input.tsx b/src/components/common/Input/Input.tsx new file mode 100644 index 0000000..a638d1a --- /dev/null +++ b/src/components/common/Input/Input.tsx @@ -0,0 +1,53 @@ +import * as React from 'react' +import { cn } from '@/lib/utils' +import { cva, VariantProps } from 'class-variance-authority' + +const InputVariants = cva( + 'typo-body3 border p-4 rounded-sm outline-none placeholder-assistive text-secondary', + { + variants: { + variant: { + default: 'border-assist-line', + focused: 'border-secondary', + error: 'border-error', + disabled: 'border-assist-line bg-disabled-fill cursor-not-allowed text-disabled', + }, + }, + defaultVariants: { + variant: 'default', + }, + }, +) + +interface InputProps + extends React.InputHTMLAttributes, + VariantProps { + error?: boolean +} + +const Input = ({ className, variant, type, disabled, error, ...props }: InputProps) => { + const [isFocused, setIsFocused] = React.useState(false) + + let currentState = variant + if (disabled) { + currentState = 'disabled' + } else if (isFocused) { + currentState = 'focused' + } else if (error) { + currentState = 'error' + } + + return ( + setIsFocused(true)} + onBlur={() => setIsFocused(false)} + {...props} + /> + ) +} + +export { Input } diff --git a/src/components/common/Textarea/Textarea.tsx b/src/components/common/Textarea/Textarea.tsx new file mode 100644 index 0000000..8e16c07 --- /dev/null +++ b/src/components/common/Textarea/Textarea.tsx @@ -0,0 +1,51 @@ +import * as React from 'react' +import { cn } from '@/lib/utils' +import { cva, VariantProps } from 'class-variance-authority' + +const TextareaVariants = cva( + 'typo-body3 border p-4 rounded-sm outline-none placeholder-assistive text-secondary resize-none custom-scrollbar', + { + variants: { + variant: { + default: 'border-assist-line', + focused: 'border-secondary', + error: 'border-error', + disabled: 'border-assist-line bg-disabled-fill cursor-not-allowed text-disabled', + }, + }, + defaultVariants: { + variant: 'default', + }, + }, +) + +interface TextareaProps + extends React.TextareaHTMLAttributes, + VariantProps { + error?: boolean +} + +const Textarea = ({ className, variant, disabled, error, ...props }: TextareaProps) => { + const [isFocused, setIsFocused] = React.useState(false) + + let currentState = variant + if (disabled) { + currentState = 'disabled' + } else if (isFocused) { + currentState = 'focused' + } else if (error) { + currentState = 'error' + } + return ( +