@@ -10,11 +10,11 @@ import {
1010 type TextFieldProps as TextFieldPrimitiveProps ,
1111} from "react-aria-components"
1212
13- import { FieldError , FieldProps } from "./field"
13+ import { FieldError , type FieldProps } from "./field"
1414import { Description , FieldGroup , Input , Label } from "./field"
1515import { Loader } from "./loader"
1616import { composeTailwindRenderProps } from "./primitive"
17- import { Typography } from "./typography" ;
17+ import { Typography } from "./typography"
1818
1919type InputType = Exclude < TextInputDOMProps [ "type" ] , "password" >
2020
@@ -40,20 +40,20 @@ interface NonRevealableTextFieldProps extends BaseTextFieldProps {
4040type TextFieldProps = RevealableTextFieldProps | NonRevealableTextFieldProps
4141
4242const TextField = ( {
43- placeholder,
44- label,
45- description,
46- errorMessage,
47- prefix,
48- suffix,
49- isPending,
50- className,
51- isRevealable,
52- type,
53- leftDescription,
54- rightDescription,
55- ...props
56- } : TextFieldProps ) => {
43+ placeholder,
44+ label,
45+ description,
46+ errorMessage,
47+ prefix,
48+ suffix,
49+ isPending,
50+ className,
51+ isRevealable,
52+ type,
53+ leftDescription,
54+ rightDescription,
55+ ...props
56+ } : TextFieldProps ) => {
5757 const [ isPasswordVisible , setIsPasswordVisible ] = useState ( false )
5858 const [ autoError , setAutoError ] = useState < string | null > ( null )
5959
@@ -76,68 +76,70 @@ const TextField = ({
7676 }
7777
7878 return (
79- < TextFieldPrimitive
80- type = { inputType }
81- { ...props }
82- className = { composeTailwindRenderProps ( className , "group flex flex-col gap-y-1" ) }
83- >
84- { ! props . children ? (
85- < >
86- { label &&
87- < Typography as = "div" >
88- < Label isRequired = { props . isRequired } > { label } </ Label >
89- </ Typography >
90- }
91- < FieldGroup
92- isDisabled = { props . isDisabled }
93- isInvalid = { ! ! errorMessage || ! ! autoError }
94- data-loading = { isPending ? "true" : undefined }
79+ < TextFieldPrimitive
80+ type = { inputType }
81+ { ...props }
82+ className = { composeTailwindRenderProps ( className , "group flex flex-col gap-y-1" ) }
83+ >
84+ { ! props . children ? (
85+ < >
86+ { label && (
87+ < Typography as = "div" >
88+ < Label isRequired = { props . isRequired } > { label } </ Label >
89+ </ Typography >
90+ ) }
91+ < FieldGroup
92+ isDisabled = { props . isDisabled }
93+ isInvalid = { ! ! errorMessage || ! ! autoError }
94+ data-loading = { isPending ? "true" : undefined }
95+ >
96+ { prefix && typeof prefix === "string" ? (
97+ < Typography as = "div" >
98+ < span className = "ml-2 text-muted-fg" > { prefix } </ span >
99+ </ Typography >
100+ ) : (
101+ < Typography as = "div" > { prefix } </ Typography >
102+ ) }
103+ < Input placeholder = { placeholder } onInvalid = { handleInvalid } onInput = { handleInput } />
104+ { isRevealable ? (
105+ < ButtonPrimitive
106+ type = "button"
107+ aria-label = "Toggle password visibility"
108+ onPress = { handleTogglePasswordVisibility }
109+ className = "relative mr-1 grid shrink-0 place-content-center rounded-sm border-transparent outline-hidden data-focus-visible:*:data-[slot=icon]:text-primary *:data-[slot=icon]:text-muted-fg"
95110 >
96- { prefix && typeof prefix === "string" ? (
97- < Typography as = "div" > < span className = "ml-2 text-muted-fg" > { prefix } </ span > </ Typography >
98- ) : (
99- < Typography as = "div" > { prefix } </ Typography >
100- ) }
101- < Input
102- placeholder = { placeholder }
103- onInvalid = { handleInvalid }
104- onInput = { handleInput }
105- />
106- { isRevealable ? (
107- < ButtonPrimitive
108- type = "button"
109- aria-label = "Toggle password visibility"
110- onPress = { handleTogglePasswordVisibility }
111- className = "relative mr-1 grid shrink-0 place-content-center rounded-sm border-transparent outline-hidden data-focus-visible:*:data-[slot=icon]:text-primary *:data-[slot=icon]:text-muted-fg"
112- >
113- { isPasswordVisible ? < IconEyeClosed /> : < IconEye /> }
114- </ ButtonPrimitive >
115- ) : isPending ? (
116- < Loader variant = "spin" />
117- ) : suffix ? (
118- typeof suffix === "string" ? (
119- < span className = "mr-2 text-muted-fg" > { suffix } </ span >
120- ) : (
121- suffix
122- )
123- ) : null }
124- </ FieldGroup >
125-
126- { description && < Typography as = "div" > < Description > { description } </ Description > </ Typography > }
127-
128- { ( leftDescription || autoError || rightDescription ) && (
129- < Typography as = "div" >
130- < div className = "mt-1 flex justify-between text-sm text-muted-fg" >
131- < div > { autoError ? < FieldError > { autoError } </ FieldError > : leftDescription } </ div >
132- < div > { rightDescription } </ div >
133- </ div >
134- </ Typography >
135- ) }
136- </ >
137- ) : (
138- props . children
139- ) }
140- </ TextFieldPrimitive >
111+ { isPasswordVisible ? < IconEyeClosed /> : < IconEye /> }
112+ </ ButtonPrimitive >
113+ ) : isPending ? (
114+ < Loader variant = "spin" />
115+ ) : suffix ? (
116+ typeof suffix === "string" ? (
117+ < span className = "mr-2 text-muted-fg" > { suffix } </ span >
118+ ) : (
119+ suffix
120+ )
121+ ) : null }
122+ </ FieldGroup >
123+
124+ { description && (
125+ < Typography as = "div" >
126+ < Description > { description } </ Description >
127+ </ Typography >
128+ ) }
129+
130+ { ( leftDescription || autoError || rightDescription ) && (
131+ < Typography as = "div" >
132+ < div className = "mt-1 flex justify-between text-muted-fg text-sm" >
133+ < div > { autoError ? < FieldError > { autoError } </ FieldError > : leftDescription } </ div >
134+ < div > { rightDescription } </ div >
135+ </ div >
136+ </ Typography >
137+ ) }
138+ </ >
139+ ) : (
140+ props . children
141+ ) }
142+ </ TextFieldPrimitive >
141143 )
142144}
143145
0 commit comments