1- import * as React from 'react'
1+ import { forwardRef , InputHTMLAttributes } from 'react'
2+
3+ import { cva , VariantProps } from 'class-variance-authority'
24
35import { cn } from '../utils/cn'
46import { Text } from './'
57
6- export interface BaseInputProps extends React . InputHTMLAttributes < HTMLInputElement > {
7- isExtended ?: boolean
8- error ?: string
8+ export interface BaseInputProps
9+ extends Omit < InputHTMLAttributes < HTMLInputElement > , 'size' > ,
10+ VariantProps < typeof inputVariants > {
911 wrapperClassName ?: string
12+ error ?: string
1013}
1114
12- const BaseInput = React . forwardRef < HTMLInputElement , BaseInputProps > (
13- ( { className, type, isExtended, error, wrapperClassName, ...props } , ref ) => {
14- const commonClassName =
15- 'remove-autocomplete-styles bg-transparent placeholder:text-foreground-5 text-foreground-1 px-3 py-1'
16- const specificClassNames = isExtended
17- ? 'border-none grow focus-visible:outline-none'
18- : cn (
15+ const inputVariants = cva (
16+ 'remove-autocomplete-styles bg-transparent placeholder:text-foreground-5 text-foreground-1 px-3 py-1' ,
17+ {
18+ variants : {
19+ variant : {
20+ default :
1921 'flex h-9 w-full rounded border text-sm shadow-sm transition-colors file:border-0 focus-visible:outline-none file:bg-transparent file:text-sm file:font-medium placeholder:text-foreground-4 disabled:cursor-not-allowed disabled:opacity-50' ,
20- error ? 'border-borders-danger' : 'border-borders-2 focus-visible:border-borders-3'
21- )
22+ extended : 'grow border-none focus-visible:outline-none'
23+ } ,
24+ theme : {
25+ default : 'border-borders-2 focus-visible:border-borders-3' ,
26+ danger : 'border-borders-danger'
27+ }
28+ }
29+ }
30+ )
2231
32+ const BaseInput = forwardRef < HTMLInputElement , BaseInputProps > (
33+ ( { className, type, variant = 'default' , theme = 'default' , error, wrapperClassName, ...props } , ref ) => {
2334 return (
2435 < div className = { cn ( 'relative flex flex-col' , wrapperClassName ) } >
25- < input className = { cn ( commonClassName , specificClassNames , className ) } type = { type } ref = { ref } { ...props } />
36+ < input
37+ className = { cn (
38+ inputVariants ( { variant, theme } ) ,
39+ className ,
40+ error ? 'border-borders-danger' : 'border-borders-2'
41+ ) }
42+ type = { type }
43+ ref = { ref }
44+ { ...props }
45+ />
2646 { error && (
2747 < Text
28- className = "absolute top-full translate-y-1 leading-none tracking-tight text-foreground-danger "
48+ className = "absolute top-full translate-y-1 text-foreground-danger leading-none tracking-tight"
2949 weight = "light"
3050 size = { 0 }
3151 >
@@ -51,7 +71,7 @@ const containerClassName =
5171 'remove-autocomplete-styles flex h-9 w-full rounded border border-input text-sm shadow-sm transition-colors placeholder:text-foreground-4 focus-within:outline-none focus-within:ring-1 focus-within:ring-ring disabled:cursor-not-allowed disabled:opacity-50'
5272const leftRightCommonClassName = 'flex items-center text-muted-foreground'
5373
54- const ExtendedInput = React . forwardRef < HTMLInputElement , ExtendedInputProps > (
74+ const ExtendedInput = forwardRef < HTMLInputElement , ExtendedInputProps > (
5575 ( { className, type, left, leftStyle, leftClassName, right, rightStyle, rightClassName, ...props } , ref ) => {
5676 return (
5777 < div className = { cn ( containerClassName , className ) } >
@@ -67,7 +87,7 @@ const ExtendedInput = React.forwardRef<HTMLInputElement, ExtendedInputProps>(
6787 { left }
6888 </ div >
6989 ) }
70- < BaseInput className = { className } type = { type } { ...props } ref = { ref } isExtended = { true } />
90+ < BaseInput className = { className } type = { type } { ...props } ref = { ref } variant = "extended" />
7191 { right && (
7292 < div
7393 className = { cn (
@@ -86,9 +106,9 @@ const ExtendedInput = React.forwardRef<HTMLInputElement, ExtendedInputProps>(
86106)
87107ExtendedInput . displayName = 'ExtendedInput'
88108
89- interface InputProps extends Omit < BaseInputProps , 'isExtended' > , ExtendedInputProps { }
109+ interface InputProps extends ExtendedInputProps { }
90110
91- const Input = React . forwardRef < HTMLInputElement , InputProps > ( ( { left, right, ...props } , ref ) => {
111+ const Input = forwardRef < HTMLInputElement , InputProps > ( ( { left, right, ...props } , ref ) => {
92112 if ( left || right ) {
93113 return < ExtendedInput left = { left } right = { right } { ...props } ref = { ref } />
94114 }
0 commit comments