@@ -4,8 +4,6 @@ import { twMerge } from "tailwind-merge";
44
55import { RequiredKeys } from "@/types/utility" ;
66
7- import Label , { style as labelStyle } from "./Label" ;
8-
97export const style = cva ( "w-full rounded-full py-2 px-3 border-2" , {
108 variants : {
119 color : {
@@ -18,94 +16,29 @@ export const style = cva("w-full rounded-full py-2 px-3 border-2", {
1816 }
1917} ) ;
2018
21- const borderStyle = cva ( "absolute inset-0 border-2 top-[-9px] rounded-[inherit] pl-[var(--label-inset)] pointer-events-none" , {
22- variants : {
23- color : {
24- primary : "border-primary" ,
25- secondary : "border-secondary"
26- } ,
27- }
28- } ) ;
29-
30- export type BaseProps = {
31- inputClassName ?: string ;
32- labelClassName ?: string ;
33- fieldsetClassName ?: string ;
34- labelInset ?: string ;
35- label ?: ReactNode ;
36- } ;
37-
3819export type TagProps = Omit < InputHTMLAttributes < HTMLInputElement > , "color" > ;
3920export type VariantProps = GetVariantProps < typeof style > ;
40- export type InputProps = BaseProps & TagProps & RequiredKeys < VariantProps , "color" > ;
21+ export type InputProps = TagProps & RequiredKeys < VariantProps , "color" > ;
4122
4223const Input = forwardRef ( (
4324 {
4425 className,
45- inputClassName,
46- labelClassName,
47- fieldsetClassName,
48- labelInset = "1.5rem" ,
49- label,
5026 color,
51- id,
5227 ...props
5328 } : InputProps ,
5429 ref : ForwardedRef < HTMLInputElement >
5530) => {
5631
57- const fallbackId = useId ( ) ;
58-
59- const computedClassName = useMemo (
60- ( ) => twMerge ( "relative rounded-full" , className ) ,
61- [ className ]
62- ) ;
63-
64- const computedInputClassName = useMemo (
65- ( ) => twMerge (
66- style ( { color } ) ,
67- "rounded-[inherit]" ,
68- label ? "border-transparent" : "" ,
69- inputClassName
70- ) ,
71- [ inputClassName , color , label ]
72- ) ;
73-
74- const computedLabelClassName = useMemo (
75- ( ) => twMerge ( "absolute left-[var(--label-inset)] top-0 translate-x-[2px] -translate-y-1/2 px-1" , labelClassName ) ,
76- [ labelClassName ]
77- ) ;
78-
79- const computedFieldsetClassName = useMemo (
80- ( ) => twMerge ( borderStyle ( { color } ) , fieldsetClassName ) ,
81- [ color , fieldsetClassName ]
82- ) ;
83-
84- const computedLegendClassName = useMemo (
85- ( ) => twMerge ( labelStyle ( ) , "px-1 opacity-0" ) ,
86- [ computedLabelClassName ]
87- ) ;
88-
89- const insetProps = useMemo < Record < string , string > > (
90- ( ) => ( { "--label-inset" : labelInset } ) ,
91- [ labelInset ]
92- ) ;
32+ const computedClassName = useMemo ( ( ) => {
33+ return twMerge ( style ( { color } ) , className ) ;
34+ } , [ className , color ] ) ;
9335
9436 return (
95- < div className = { computedClassName } >
96- { label && < Label className = { computedLabelClassName } htmlFor = { id ?? fallbackId } style = { insetProps } >
97- { label }
98- </ Label > }
99- { label && < fieldset aria-hidden className = { computedFieldsetClassName } style = { insetProps } >
100- < legend className = { computedLegendClassName } > { label } </ legend >
101- </ fieldset > }
102- < input
103- ref = { ref }
104- className = { computedInputClassName }
105- id = { id ?? fallbackId }
106- { ...props }
107- />
108- </ div >
37+ < input
38+ ref = { ref }
39+ className = { computedClassName }
40+ { ...props }
41+ />
10942 ) ;
11043} ) ;
11144
0 commit comments