Skip to content

Commit 722675a

Browse files
committed
Refactor Checkbox state props name
- Change isSelected prop name to selected. - Change isIndeterminated prop name to indeterminated.
1 parent 0318dfb commit 722675a

File tree

8 files changed

+55
-51
lines changed

8 files changed

+55
-51
lines changed

docs/docs/components/checkbox.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const App = () => {
2727
const [ isSelected, setSelected ] = useState( false );
2828
return (
2929
<Checkbox
30-
isSelected={ isSelected }
30+
selected={ isSelected }
3131
onPress={ () => { setSelected( !isSelected ); } }
3232
/>
3333
);
@@ -36,7 +36,7 @@ const App = () => {
3636

3737
## Props
3838

39-
### isSelected
39+
### selected
4040
If the checkbox is selected or not.
4141

4242
| TYPE | REQUIRED | DEFAULT |
@@ -46,19 +46,19 @@ If the checkbox is selected or not.
4646
<CodePreview>
4747
<HStack>
4848
<Checkbox />
49-
<Checkbox isSelected />
49+
<Checkbox selected />
5050
</HStack>
5151
</CodePreview>
5252

53-
### isIndeterminated
53+
### indeterminated
5454
If the checkbox is indeterminated or not. This is usually used for lists of checkboxes when some of their children are checked but not all of them. This is only a visual state, it only changes the checkbox icon.
5555

5656
| TYPE | REQUIRED | DEFAULT |
5757
| ---- | -------- | ------- |
5858
| bool | No | false |
5959

6060
<CodePreview>
61-
<Checkbox isIndeterminated/>
61+
<Checkbox indeterminated/>
6262
</CodePreview>
6363

6464
### disabled
@@ -71,8 +71,8 @@ If the checkbox is disabled or not.
7171
<CodePreview>
7272
<HStack>
7373
<Checkbox disabled />
74-
<Checkbox disabled isSelected />
75-
<Checkbox disabled isIndeterminated />
74+
<Checkbox disabled selected />
75+
<Checkbox disabled indeterminated />
7676
</HStack>
7777
</CodePreview>
7878

@@ -101,4 +101,4 @@ Sets the component to an accessibility element. It is set by default to `true`.
101101
Communicates the purpose of the component. It is set by default to `"checkbox"`.
102102

103103
### accessibilityState
104-
Describes the current state of the element. By default, indicates if the `Checkbox` is `disabled`, `isSelected` and `isIndeterminated`.
104+
Describes the current state of the element. By default, indicates if the `Checkbox` is `disabled`, `selected` and `indeterminated`.

docs/src/components/ExampleCheckbox/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const ExampleCheckbox = () => {
55
const [ isSelected, setSelected ] = useState( false );
66
return (
77
<Checkbox
8-
isSelected={ isSelected }
8+
selected={ isSelected }
99
onPress={ () => { setSelected( !isSelected ); } }
1010
/>
1111
);

example/src/components/CheckboxExamples.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const CheckboxExamples = () => {
4848

4949
<HStack>
5050
<Checkbox />
51-
<Checkbox isSelected />
52-
<Checkbox isIndeterminated />
51+
<Checkbox selected />
52+
<Checkbox indeterminated />
5353
</HStack>
5454

5555
<View style={styles.vspace} />
@@ -58,16 +58,16 @@ const CheckboxExamples = () => {
5858

5959
<HStack>
6060
<Checkbox disabled />
61-
<Checkbox disabled isSelected />
62-
<Checkbox disabled isIndeterminated />
61+
<Checkbox disabled selected />
62+
<Checkbox disabled indeterminated />
6363
</HStack>
6464

6565
<View style={styles.vspace} />
6666
<Text variant="sh1" color="primary.800">On Change</Text>
6767
<View style={styles.separator} />
6868

6969
<HStack>
70-
<Checkbox isSelected={isSelected} isIndeterminated={isIndeterminated} onPress={onPressed}/>
70+
<Checkbox selected={isSelected} indeterminated={isIndeterminated} onPress={onPressed}/>
7171
</HStack>
7272

7373
<View style={styles.vspace} />
@@ -77,10 +77,10 @@ const CheckboxExamples = () => {
7777

7878
<VStack alignItems="flex-start" justifyContent="flex-start" alignContent="flex-start" space="0">
7979
<Checkbox label="Unselected" />
80-
<Checkbox label="Selected" isSelected />
81-
<Checkbox label="Indeterminated" isIndeterminated />
80+
<Checkbox label="Selected" selected />
81+
<Checkbox label="Indeterminated" indeterminated />
8282
<Checkbox label="Disabled" disabled />
83-
<Checkbox label="Controlled" isSelected={isSelected} isIndeterminated={isIndeterminated} onPress={onPressed}/>
83+
<Checkbox label="Controlled" selected={isSelected} indeterminated={isIndeterminated} onPress={onPressed}/>
8484
</VStack>
8585

8686
<View style={styles.vspace} />

src/components/main/Checkbox/hooks.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ interface IUseCheckboxPropsResolverReturnType {
1616
}
1717

1818
export const useCheckboxPropsResolver = ( {
19-
isSelected = false,
20-
isIndeterminated = false,
19+
selected = false,
20+
indeterminated = false,
2121
...props
2222
} : ICheckboxProps
2323
): IUseCheckboxPropsResolverReturnType => {
@@ -27,13 +27,13 @@ export const useCheckboxPropsResolver = ( {
2727
const { isFocused, onFocus, onBlur } = useIsFocused( props );
2828

2929
const state = useMemo( () => ( {
30-
isSelected,
31-
isIndeterminated,
30+
isSelected: selected,
31+
isIndeterminated: indeterminated,
3232
isDisabled: disabled || false,
3333
isPressed,
3434
isHovered,
3535
isFocused
36-
} ), [ isSelected, isIndeterminated, disabled, isPressed, isHovered, isFocused ] );
36+
} ), [ selected, indeterminated, disabled, isPressed, isHovered, isFocused ] );
3737

3838
const {
3939
__icon: iconProps,

src/components/main/Checkbox/index.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ const defaultUncheckedIcon = <Icon as={UIKitIcon} name="box-unchecked" />;
1414

1515
const defaultIndeterminatedIcon = <Icon as={UIKitIcon} name="box-indeterminated" />;
1616

17-
const selectIcon = ( isSelected: boolean, isIndeterminated: boolean, checkedIcon: JSX.Element,
17+
const selectIcon = ( selected: boolean, indeterminated: boolean, checkedIcon: JSX.Element,
1818
uncheckedIcon: JSX.Element, indeterminatedIcon: JSX.Element ) => {
19-
if ( isIndeterminated ) return indeterminatedIcon;
20-
if ( isSelected ) return checkedIcon;
19+
if ( indeterminated ) return indeterminatedIcon;
20+
if ( selected ) return checkedIcon;
2121
return uncheckedIcon;
2222
};
2323

2424
const Checkbox = ( {
2525
label,
26-
isSelected = false,
27-
isIndeterminated = false,
26+
selected = false,
27+
indeterminated = false,
2828
checkedIcon = defaultCheckedIcon,
2929
uncheckedIcon = defaultUncheckedIcon,
3030
indeterminatedIcon = defaultIndeterminatedIcon,
@@ -37,12 +37,12 @@ const Checkbox = ( {
3737
labelProps,
3838
containerProps
3939
} = useCheckboxPropsResolver( {
40-
isIndeterminated, isSelected, ...props
40+
indeterminated, selected, ...props
4141
} );
4242

4343
const icon = selectIcon(
44-
isSelected,
45-
isIndeterminated,
44+
selected,
45+
indeterminated,
4646
checkedIcon,
4747
uncheckedIcon,
4848
indeterminatedIcon );
@@ -53,7 +53,7 @@ const Checkbox = ( {
5353
accessibilityRole='checkbox'
5454
accessibilityLabel={label}
5555
accessibilityState={{
56-
checked: isIndeterminated ? 'mixed' : isSelected,
56+
checked: indeterminated ? 'mixed' : selected,
5757
disabled: props.disabled || false
5858
}}
5959
testID={testID}

src/components/main/Checkbox/types.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ export interface ICheckboxProps extends Omit<PressableProps, 'children'>,
55
ComponentStyledProps<'Checkbox'>
66
{
77
label?: string,
8+
9+
selected?: boolean,
10+
indeterminated?: boolean,
11+
disabled?: boolean,
12+
13+
checkedIcon?: JSX.Element,
14+
uncheckedIcon?: JSX.Element,
15+
indeterminatedIcon?: JSX.Element
16+
17+
outlineStyle?: string,
18+
819
onPress?: PressableProps['onPress'],
920
onPressOut?: PressableProps['onPressOut'],
1021
onPressIn?: PressableProps['onPressIn'],
1122
onFocus?: PressableProps['onFocus'],
1223
onBlur?: PressableProps['onBlur'],
1324
onHoverIn?: ( ( event: GestureResponderEvent ) => void ),
1425
onHoverOut?: ( ( event: GestureResponderEvent ) => void ),
15-
outlineStyle?: string,
16-
disabled?: boolean,
17-
isSelected?: boolean,
18-
isIndeterminated?: boolean,
19-
checkedIcon?: JSX.Element,
20-
uncheckedIcon?: JSX.Element,
21-
indeterminatedIcon?: JSX.Element
2226
}

tests/components/main/Checkbox.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ describe( 'Checkbox', () => {
5454
} );
5555

5656
it( 'applies the __selected styles when it is selected', () => {
57-
const { getByTestId, debug } = renderComponent( { isSelected: true } );
57+
const { getByTestId } = renderComponent( { selected: true } );
5858
expect( getByTestId( 'test-checkbox-icon' ) ).toHaveStyle( { borderColor: '#4F80FF' } );
5959
accessibilityTest( { getByTestId, checked: true } );
6060
} );
6161

6262
it( 'applies the __indeterminated styles when it is indeterminated', () => {
63-
const { getByTestId } = renderComponent( { isIndeterminated: true } );
63+
const { getByTestId } = renderComponent( { indeterminated: true } );
6464
expect( getByTestId( 'test-checkbox-icon' ) ).toHaveStyle( { borderColor: '#4F80FF' } );
6565
accessibilityTest( { getByTestId, checked: 'mixed' } );
6666
} );

web_example/src/components/CheckboxExamples.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const CheckboxExamples = () => {
4747

4848
<HStack>
4949
<Checkbox />
50-
<Checkbox isSelected />
51-
<Checkbox isIndeterminated />
50+
<Checkbox selected />
51+
<Checkbox indeterminated />
5252
</HStack>
5353

5454
<View style={styles.vspace} />
@@ -57,16 +57,16 @@ const CheckboxExamples = () => {
5757

5858
<HStack>
5959
<Checkbox disabled />
60-
<Checkbox disabled isSelected />
61-
<Checkbox disabled isIndeterminated />
60+
<Checkbox disabled selected />
61+
<Checkbox disabled indeterminated />
6262
</HStack>
6363

6464
<View style={styles.vspace} />
6565
<Text variant="sh1" color="primary.800">On Focus</Text>
6666
<View style={styles.separator} />
6767

6868
<HStack>
69-
<Checkbox isSelected
69+
<Checkbox selected
7070
__focused={{
7171
bg: 'secondary.10',
7272
borderWidth: '1'
@@ -78,9 +78,9 @@ const CheckboxExamples = () => {
7878
<View style={styles.separator} />
7979

8080
<HStack alignItems="center" space="3">
81-
<Checkbox isSelected={isSelected} isIndeterminated={isIndeterminated} onPress={onPressed}/>
81+
<Checkbox selected={isSelected} indeterminated={isIndeterminated} onPress={onPressed}/>
8282
<Text>|</Text>
83-
<Checkbox isSelected={isSelected} isIndeterminated={isIndeterminated} onPress={onPressed} label="With label" />
83+
<Checkbox selected={isSelected} indeterminated={isIndeterminated} onPress={onPressed} label="With label" />
8484
</HStack>
8585

8686
<View style={styles.vspace} />
@@ -91,14 +91,14 @@ const CheckboxExamples = () => {
9191
<VStack alignItems="flex-start" space="2">
9292
<HStack justifyContent="space-between" width="100%">
9393
<Checkbox label="Unselected" />
94-
<Checkbox label="Selected" isSelected />
95-
<Checkbox label="Indeterminated" isIndeterminated />
94+
<Checkbox label="Selected" selected />
95+
<Checkbox label="Indeterminated" indeterminated />
9696
</HStack>
9797

9898
<HStack justifyContent="space-between" width="100%">
9999
<Checkbox disabled label="Unselected" />
100-
<Checkbox disabled label="Selected" isSelected />
101-
<Checkbox disabled label="Indeterminated" isIndeterminated />
100+
<Checkbox disabled label="Selected" selected />
101+
<Checkbox disabled label="Indeterminated" indeterminated />
102102
</HStack>
103103
</VStack>
104104

0 commit comments

Comments
 (0)