@@ -21,8 +21,7 @@ import {
2121 Text ,
2222 useContextProps
2323} from 'react-aria-components' ;
24- import { baseColor , style } from '../style/spectrum-theme' with { type : 'macro' } ;
25- import ChevronIcon from '../ui-icons/Chevron' ;
24+ import { baseColor , size , style } from '../style/spectrum-theme' with { type : 'macro' } ;
2625import { createContext , CSSProperties , ForwardedRef , forwardRef , ReactNode , Ref , useContext , useImperativeHandle , useMemo , useRef } from 'react' ;
2726import { createFocusableRef } from '@react-spectrum/utils' ;
2827import Dash from '../ui-icons/Dash' ;
@@ -38,23 +37,21 @@ import {useSpectrumContextProps} from './useSpectrumContextProps';
3837
3938
4039export interface NumberFieldProps extends
41- AriaNumberFieldProps ,
40+ Omit < AriaNumberFieldProps , 'children' | 'className' | 'style' > ,
4241 StyleProps ,
4342 SpectrumLabelableProps ,
4443 HelpTextProps {
4544 /**
46- * Whether the NumberField step buttons should be collapsed into a single column.
47- *
48- * @default "false"
45+ * Whether to hide the increment and decrement buttons.
46+ * @default false
4947 */
50- isCollapsed ?: boolean ,
48+ hideStepper ?: boolean ,
5149 /**
5250 * The size of the NumberField.
5351 *
5452 * @default "M"
5553 */
56- size ?: 'S' | 'M' | 'L' | 'XL' ,
57- label ?: ReactNode
54+ size ?: 'S' | 'M' | 'L' | 'XL'
5855}
5956
6057export const NumberFieldContext = createContext < ContextValue < NumberFieldProps , TextFieldRef > > ( null ) ;
@@ -94,52 +91,22 @@ const inputButton = style({
9491 justifyContent : 'center' ,
9592 width : {
9693 size : {
97- S : {
98- default : 16 ,
99- isCollapsed : 24
100- } ,
101- M : {
102- default : 20 ,
103- isCollapsed : 24
104- } ,
105- L : {
106- default : 24 ,
107- isCollapsed : 32
108- } ,
109- XL : {
110- default : 32 ,
111- isCollapsed : 40
112- }
113- }
114- } ,
115- height : {
116- default : 'auto' ,
117- isCollapsed : {
118- size : {
119- S : 8 ,
120- M : 12 ,
121- L : 16 ,
122- XL : 20
123- }
94+ S : 16 ,
95+ M : 20 ,
96+ L : 24 ,
97+ XL : 32
12498 }
12599 } ,
100+ height : 'auto' ,
126101 marginStart : {
127102 default : 'text-to-control' ,
128103 type : {
129104 increment : 0
130105 }
131106 } ,
132- aspectRatio : {
133- default : 'square' ,
134- isCollapsed : 'auto'
135- } ,
136- flexShrink : {
137- default : 0 ,
138- isCollapsed : 1
139- } ,
140- minHeight : {
141- isCollapsed : 0
142- } ,
107+ aspectRatio : 'square' ,
108+ flexShrink : 0 ,
109+ minHeight : 0 ,
143110 transition : {
144111 default : 'default' ,
145112 forcedColors : 'none'
@@ -179,59 +146,33 @@ const iconStyles = style({
179146
180147const stepperContainerStyles = style ( {
181148 display : 'flex' ,
182- flexDirection : {
183- default : 'row' ,
184- isCollapsed : 'column-reverse'
185- } ,
149+ flexDirection : 'row' ,
186150 gap : {
187- default : {
188- size : {
189- S : 8 ,
190- M : 4 ,
191- L : 8 ,
192- XL : 8
193- }
194- } ,
195- isCollapsed : '[2px]'
196- } ,
197- maxHeight : {
198- isCollapsed : {
199- size : {
200- S : 16 ,
201- M : 24 ,
202- L : 32 ,
203- XL : 40 // 40
204- }
151+ size : {
152+ S : 8 ,
153+ M : 4 ,
154+ L : 8 ,
155+ XL : 8
205156 }
206157 } ,
207158 paddingEnd : {
208- default : {
209- size : {
210- S : '[2px]' ,
211- M : '[4px]' ,
212- L : '[6px]' ,
213- XL : '[6px]'
214- }
215- } ,
216- isCollapsed : '[2px]'
159+ size : {
160+ S : size ( 2 ) ,
161+ M : 4 ,
162+ L : size ( 6 ) ,
163+ XL : size ( 6 )
164+ }
217165 }
218166} ) ;
219167
220- const chevronSize = {
221- S : 'XS' ,
222- M : 'S' ,
223- L : 'L' ,
224- XL : 'XL'
225- } as const ;
226-
227168function NumberField ( props : NumberFieldProps , ref : Ref < TextFieldRef > ) {
228169 [ props , ref ] = useSpectrumContextProps ( props , ref , NumberFieldContext ) ;
229170 let {
230171 label,
231172 contextualHelp,
232173 description : descriptionMessage ,
233174 errorMessage,
234- isCollapsed ,
175+ hideStepper ,
235176 isRequired,
236177 size = 'M' ,
237178 labelPosition = 'top' ,
@@ -293,9 +234,11 @@ function NumberField(props: NumberFieldProps, ref: Ref<TextFieldRef>) {
293234 styles = { style ( {
294235 ...fieldInput ( ) ,
295236 paddingStart : 'edge-to-text' ,
296- paddingEnd : 0 ,
297- cursor : 'default'
298- } ) ( { size} ) } >
237+ paddingEnd : {
238+ default : 0 ,
239+ isStepperHidden : 'edge-to-text'
240+ }
241+ } ) ( { size, isStepperHidden : hideStepper } ) } >
299242 < InputContext . Consumer >
300243 { ctx => (
301244 < InputContext . Provider value = { { ...ctx , ref : mergeRefs ( ( ctx as any ) ?. ref , inputRef ) } } >
@@ -304,40 +247,30 @@ function NumberField(props: NumberFieldProps, ref: Ref<TextFieldRef>) {
304247 ) }
305248 </ InputContext . Consumer >
306249 { isInvalid && < FieldErrorIcon isDisabled = { isDisabled } /> }
307- < div className = { stepperContainerStyles ( { isCollapsed , size} ) } >
250+ { ! hideStepper && < div className = { stepperContainerStyles ( { size} ) } >
308251 < StepButton
309252 ref = { decrementButtonRef }
310253 slot = "decrement"
311254 style = { renderProps => pressScale ( decrementButtonRef ) ( renderProps ) }
312255 className = { renderProps => inputButton ( {
313256 ...renderProps ,
314- type : isCollapsed ? 'decrementStep' : 'decrement' ,
315- isCollapsed,
257+ type : 'decrement' ,
316258 size
317259 } ) } >
318- {
319- isCollapsed
320- ? < ChevronIcon size = { chevronSize [ size ] } className = { iconStyles ( { type : 'decrementStep' } ) } />
321- : < Dash size = { size } className = { iconStyles ( { } ) } />
322- }
260+ < Dash size = { size } className = { iconStyles ( { } ) } />
323261 </ StepButton >
324262 < StepButton
325263 ref = { incrementButtonRef }
326264 slot = "increment"
327265 style = { renderProps => pressScale ( incrementButtonRef ) ( renderProps ) }
328266 className = { renderProps => inputButton ( {
329267 ...renderProps ,
330- type : isCollapsed ? 'incrementStep' : 'increment' ,
331- isCollapsed,
268+ type : 'increment' ,
332269 size
333270 } ) } >
334- {
335- isCollapsed
336- ? < ChevronIcon size = { chevronSize [ size ] } className = { iconStyles ( { type : 'incrementStep' } ) } />
337- : < Add size = { size } className = { iconStyles ( { } ) } />
338- }
271+ < Add size = { size } className = { iconStyles ( { } ) } />
339272 </ StepButton >
340- </ div >
273+ </ div > }
341274 </ FieldGroup >
342275 { descriptionMessage && < Text slot = "description" > { descriptionMessage } </ Text > }
343276 < HelpText
0 commit comments