Skip to content

Commit a60209b

Browse files
authored
Checkbox - indeterminate state (#2703)
* NestedCheckbox - new component * other unfinished stuff * Checkbox - adding indeterminate state * adding example to screen
1 parent 99128aa commit a60209b

File tree

8 files changed

+24
-9
lines changed

8 files changed

+24
-9
lines changed

demo/src/screens/componentScreens/CheckboxScreen.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {Component} from 'react';
22
import {StyleSheet} from 'react-native';
3-
import {Checkbox, Assets, Text, View, Colors} from 'react-native-ui-lib'; //eslint-disable-line
3+
import {Assets, Colors, View, Text, Checkbox} from 'react-native-ui-lib'; //eslint-disable-line
44

55
export default class CheckboxScreen extends Component {
66
state = {
@@ -9,17 +9,19 @@ export default class CheckboxScreen extends Component {
99
value3: true,
1010
value4: true,
1111
value5: false,
12-
value6: false
12+
value6: false,
13+
value7: true
1314
};
14-
15+
1516
render() {
1617
return (
1718
<View flex padding-page>
1819
<Text text40 $textDefault marginB-20>
1920
Checkbox
2021
</Text>
2122

22-
<Text marginB-s4>Customizable UI</Text>
23+
<Text marginV-s4>Customizable UI</Text>
24+
2325
<View row marginB-s5 centerV>
2426
<Checkbox value={this.state.value1} onValueChange={value1 => this.setState({value1})}/>
2527
<Checkbox
@@ -50,10 +52,18 @@ export default class CheckboxScreen extends Component {
5052
containerStyle={styles.checkbox}
5153
/>
5254

55+
<Checkbox
56+
value={this.state.value7}
57+
onValueChange={value7 => this.setState({value7})}
58+
indeterminate
59+
label={'Indeterminate state'}
60+
color={Colors.green20}
61+
containerStyle={styles.checkbox}
62+
/>
63+
5364
<View row style={styles.row}>
54-
<Text $textDefault marginR-10>
55-
Disabled States
56-
</Text>
65+
<Text $textDefault marginR-10>Disabled States</Text>
66+
5767
<Checkbox
5868
disabled
5969
value={this.state.value5}

src/assets/icons/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export const icons = {
55
get checkSmall() {
66
return require('./check-small.png');
77
},
8+
get minusSmall() {
9+
return require('./minusSmall.png');
10+
},
811
get plusSmall() {
912
return require('./plusSmall.png');
1013
},

src/assets/icons/minusSmall.png

159 Bytes
Loading

src/assets/icons/[email protected]

181 Bytes
Loading

src/assets/icons/[email protected]

214 Bytes
Loading

src/assets/icons/[email protected]

265 Bytes
Loading

src/assets/icons/[email protected]

288 Bytes
Loading

src/components/checkbox/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export interface CheckboxProps extends TouchableOpacityProps {
8383
* Additional styling for checkbox and label container
8484
*/
8585
containerStyle?: StyleProp<ViewStyle>;
86+
indeterminate?: boolean;
8687
}
8788

8889
interface CheckboxState {
@@ -205,7 +206,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
205206
}
206207

207208
renderCheckbox() {
208-
const {selectedIcon, label, testID, style, containerStyle, ...others} = this.props;
209+
const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props;
209210
return (
210211
//@ts-ignore
211212
<TouchableOpacity
@@ -226,7 +227,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
226227
>
227228
<AnimatedIcon
228229
style={[this.styles.selectedIcon, {transform: this.animationStyle.transform}]}
229-
source={selectedIcon || Assets.icons.checkSmall}
230+
source={indeterminate ? Assets.icons.minusSmall : selectedIcon || Assets.icons.checkSmall}
230231
testID={`${testID}.selected`}
231232
tintColor={this.getTintColor()}
232233
/>
@@ -238,6 +239,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
238239

239240
render() {
240241
const {label, labelStyle, containerStyle, labelProps} = this.props;
242+
241243
return label ? (
242244
<View row centerV style={containerStyle}>
243245
{this.renderCheckbox()}

0 commit comments

Comments
 (0)