1
1
import { useFocusableRef } from '@react-spectrum/utils' ;
2
- import { forwardRef , useContext , useRef } from 'react' ;
2
+ import { forwardRef , useContext , useMemo , useRef } from 'react' ;
3
3
import { useCheckbox , useCheckboxGroupItem } from '@react-aria/checkbox' ;
4
4
import { useHover } from '@react-aria/interactions' ;
5
5
import { useToggleState } from '@react-stately/toggle' ;
@@ -20,13 +20,13 @@ import { mergeProps } from '../../../utils/react';
20
20
import { INLINE_LABEL_STYLES , LABEL_STYLES } from '../Label' ;
21
21
import { HiddenInput } from '../../HiddenInput' ;
22
22
import { useFieldProps , useFormProps } from '../Form' ;
23
- import { FieldWrapper } from '../FieldWrapper' ;
24
23
import { FieldBaseProps } from '../../../shared' ;
25
24
import {
26
25
castNullableIsSelected ,
27
26
WithNullableSelected ,
28
27
} from '../../../utils/react/nullableValue' ;
29
28
import { Text } from '../../content/Text' ;
29
+ import { wrapWithField } from '../wrapper' ;
30
30
31
31
import { CheckboxGroup } from './CheckboxGroup' ;
32
32
import { CheckboxGroupContext } from './context' ;
@@ -37,7 +37,9 @@ import type { AriaCheckboxProps } from '@react-types/checkbox';
37
37
export interface CubeCheckboxProps
38
38
extends BaseProps ,
39
39
AriaCheckboxProps ,
40
- FieldBaseProps { }
40
+ FieldBaseProps {
41
+ inputStyles ?: Styles ;
42
+ }
41
43
42
44
function CheckOutlined ( ) {
43
45
return (
@@ -51,7 +53,7 @@ function CheckOutlined() {
51
53
}
52
54
function IndeterminateOutline ( ) {
53
55
return (
54
- < svg width = "9 " height = "3 " fill = "none" xmlns = "http://www.w3.org/2000/svg" >
56
+ < svg width = "8 " height = "2 " fill = "none" xmlns = "http://www.w3.org/2000/svg" >
55
57
< path d = "M0 .044v2.001l.026.025h8.063V.044H0z" fill = "#fff" />
56
58
</ svg >
57
59
) ;
@@ -69,6 +71,7 @@ const CheckboxWrapperElement = tasty({
69
71
flow : 'row' ,
70
72
preset : 'default' ,
71
73
cursor : 'pointer' ,
74
+ width : 'max max-content' ,
72
75
} ,
73
76
} ) ;
74
77
@@ -135,32 +138,28 @@ function Checkbox(
135
138
isDisabled = false ,
136
139
insideForm,
137
140
isRequired,
138
- autoFocus,
139
141
children,
140
142
label,
141
- extra,
142
143
validationState,
143
144
labelProps,
144
145
labelStyles,
145
146
labelPosition,
146
- necessityLabel,
147
- necessityIndicator,
148
- message,
149
- description,
150
- requiredMark = true ,
151
- tooltip,
147
+ inputStyles,
152
148
isHidden,
153
- labelSuffix,
154
149
...otherProps
155
150
} = props ;
156
151
157
152
let styles : Styles = extractStyles ( props , OUTER_STYLES ) ;
158
- let inputStyles = extractStyles ( props , BLOCK_STYLES ) ;
159
153
160
- labelStyles = {
161
- ...( insideForm && ! groupState ? LABEL_STYLES : INLINE_LABEL_STYLES ) ,
162
- ...labelStyles ,
163
- } ;
154
+ inputStyles = extractStyles ( props , BLOCK_STYLES , inputStyles ) ;
155
+
156
+ labelStyles = useMemo (
157
+ ( ) => ( {
158
+ ...( insideForm ? LABEL_STYLES : INLINE_LABEL_STYLES ) ,
159
+ ...labelStyles ,
160
+ } ) ,
161
+ [ insideForm , labelStyles ] ,
162
+ ) ;
164
163
165
164
let { isFocused, focusProps } = useFocus ( { isDisabled } , true ) ;
166
165
let { hoverProps, isHovered } = useHover ( { isDisabled } ) ;
@@ -232,44 +231,25 @@ function Checkbox(
232
231
styles = { { position : 'relative' } }
233
232
>
234
233
< HiddenInput
235
- data-qa = { qa || 'Checkbox' }
234
+ data-qa = "HiddenInput"
236
235
{ ...mergeProps ( inputProps , focusProps ) }
237
236
ref = { inputRef }
238
237
/>
239
- < CheckboxElement qa = " Checkbox" mods = { mods } styles = { inputStyles } >
238
+ < CheckboxElement qa = { qa || ' Checkbox' } mods = { mods } styles = { inputStyles } >
240
239
{ markIcon }
241
240
</ CheckboxElement >
242
- { children && < Text > { children } </ Text > }
241
+ { children && < Text nowrap > { children } </ Text > }
243
242
</ CheckboxWrapperElement >
244
243
) ;
245
244
246
245
if ( insideForm && ! groupState ) {
247
- return (
248
- < FieldWrapper
249
- { ...{
250
- as : 'label' ,
251
- labelPosition,
252
- label,
253
- extra,
254
- styles,
255
- isRequired,
256
- labelStyles,
257
- isHidden,
258
- labelProps,
259
- isDisabled,
260
- validationState,
261
- necessityLabel,
262
- necessityIndicator,
263
- message,
264
- description,
265
- requiredMark,
266
- tooltip,
267
- labelSuffix,
268
- Component : checkboxField ,
269
- ref : domRef ,
270
- } }
271
- />
272
- ) ;
246
+ return wrapWithField ( checkboxField , domRef , {
247
+ ...props ,
248
+ children : null ,
249
+ labelStyles,
250
+ inputStyles,
251
+ styles,
252
+ } ) ;
273
253
}
274
254
275
255
return (
0 commit comments