@@ -21,8 +21,7 @@ import {
21
21
Text ,
22
22
useContextProps
23
23
} 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' } ;
26
25
import { createContext , CSSProperties , ForwardedRef , forwardRef , ReactNode , Ref , useContext , useImperativeHandle , useMemo , useRef } from 'react' ;
27
26
import { createFocusableRef } from '@react-spectrum/utils' ;
28
27
import Dash from '../ui-icons/Dash' ;
@@ -38,23 +37,21 @@ import {useSpectrumContextProps} from './useSpectrumContextProps';
38
37
39
38
40
39
export interface NumberFieldProps extends
41
- AriaNumberFieldProps ,
40
+ Omit < AriaNumberFieldProps , 'children' | 'className' | 'style' > ,
42
41
StyleProps ,
43
42
SpectrumLabelableProps ,
44
43
HelpTextProps {
45
44
/**
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
49
47
*/
50
- isCollapsed ?: boolean ,
48
+ hideStepper ?: boolean ,
51
49
/**
52
50
* The size of the NumberField.
53
51
*
54
52
* @default "M"
55
53
*/
56
- size ?: 'S' | 'M' | 'L' | 'XL' ,
57
- label ?: ReactNode
54
+ size ?: 'S' | 'M' | 'L' | 'XL'
58
55
}
59
56
60
57
export const NumberFieldContext = createContext < ContextValue < NumberFieldProps , TextFieldRef > > ( null ) ;
@@ -94,52 +91,22 @@ const inputButton = style({
94
91
justifyContent : 'center' ,
95
92
width : {
96
93
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
124
98
}
125
99
} ,
100
+ height : 'auto' ,
126
101
marginStart : {
127
102
default : 'text-to-control' ,
128
103
type : {
129
104
increment : 0
130
105
}
131
106
} ,
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 ,
143
110
transition : {
144
111
default : 'default' ,
145
112
forcedColors : 'none'
@@ -179,59 +146,33 @@ const iconStyles = style({
179
146
180
147
const stepperContainerStyles = style ( {
181
148
display : 'flex' ,
182
- flexDirection : {
183
- default : 'row' ,
184
- isCollapsed : 'column-reverse'
185
- } ,
149
+ flexDirection : 'row' ,
186
150
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
205
156
}
206
157
} ,
207
158
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
+ }
217
165
}
218
166
} ) ;
219
167
220
- const chevronSize = {
221
- S : 'XS' ,
222
- M : 'S' ,
223
- L : 'L' ,
224
- XL : 'XL'
225
- } as const ;
226
-
227
168
function NumberField ( props : NumberFieldProps , ref : Ref < TextFieldRef > ) {
228
169
[ props , ref ] = useSpectrumContextProps ( props , ref , NumberFieldContext ) ;
229
170
let {
230
171
label,
231
172
contextualHelp,
232
173
description : descriptionMessage ,
233
174
errorMessage,
234
- isCollapsed ,
175
+ hideStepper ,
235
176
isRequired,
236
177
size = 'M' ,
237
178
labelPosition = 'top' ,
@@ -293,9 +234,11 @@ function NumberField(props: NumberFieldProps, ref: Ref<TextFieldRef>) {
293
234
styles = { style ( {
294
235
...fieldInput ( ) ,
295
236
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 } ) } >
299
242
< InputContext . Consumer >
300
243
{ ctx => (
301
244
< InputContext . Provider value = { { ...ctx , ref : mergeRefs ( ( ctx as any ) ?. ref , inputRef ) } } >
@@ -304,40 +247,30 @@ function NumberField(props: NumberFieldProps, ref: Ref<TextFieldRef>) {
304
247
) }
305
248
</ InputContext . Consumer >
306
249
{ isInvalid && < FieldErrorIcon isDisabled = { isDisabled } /> }
307
- < div className = { stepperContainerStyles ( { isCollapsed , size} ) } >
250
+ { ! hideStepper && < div className = { stepperContainerStyles ( { size} ) } >
308
251
< StepButton
309
252
ref = { decrementButtonRef }
310
253
slot = "decrement"
311
254
style = { renderProps => pressScale ( decrementButtonRef ) ( renderProps ) }
312
255
className = { renderProps => inputButton ( {
313
256
...renderProps ,
314
- type : isCollapsed ? 'decrementStep' : 'decrement' ,
315
- isCollapsed,
257
+ type : 'decrement' ,
316
258
size
317
259
} ) } >
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 ( { } ) } />
323
261
</ StepButton >
324
262
< StepButton
325
263
ref = { incrementButtonRef }
326
264
slot = "increment"
327
265
style = { renderProps => pressScale ( incrementButtonRef ) ( renderProps ) }
328
266
className = { renderProps => inputButton ( {
329
267
...renderProps ,
330
- type : isCollapsed ? 'incrementStep' : 'increment' ,
331
- isCollapsed,
268
+ type : 'increment' ,
332
269
size
333
270
} ) } >
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 ( { } ) } />
339
272
</ StepButton >
340
- </ div >
273
+ </ div > }
341
274
</ FieldGroup >
342
275
{ descriptionMessage && < Text slot = "description" > { descriptionMessage } </ Text > }
343
276
< HelpText
0 commit comments