Skip to content

Checkbox - indeterminate state #2703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions demo/src/screens/componentScreens/CheckboxScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import {Checkbox, Assets, Text, View, Colors} from 'react-native-ui-lib'; //eslint-disable-line
import {Assets, Colors, View, Text, Checkbox} from 'react-native-ui-lib'; //eslint-disable-line

export default class CheckboxScreen extends Component {
state = {
Expand All @@ -9,17 +9,19 @@ export default class CheckboxScreen extends Component {
value3: true,
value4: true,
value5: false,
value6: false
value6: false,
value7: true
};

render() {
return (
<View flex padding-page>
<Text text40 $textDefault marginB-20>
Checkbox
</Text>

<Text marginB-s4>Customizable UI</Text>
<Text marginV-s4>Customizable UI</Text>

<View row marginB-s5 centerV>
<Checkbox value={this.state.value1} onValueChange={value1 => this.setState({value1})}/>
<Checkbox
Expand Down Expand Up @@ -50,10 +52,18 @@ export default class CheckboxScreen extends Component {
containerStyle={styles.checkbox}
/>

<Checkbox
value={this.state.value7}
onValueChange={value7 => this.setState({value7})}
indeterminate
label={'Indeterminate state'}
color={Colors.green20}
containerStyle={styles.checkbox}
/>

<View row style={styles.row}>
<Text $textDefault marginR-10>
Disabled States
</Text>
<Text $textDefault marginR-10>Disabled States</Text>

<Checkbox
disabled
value={this.state.value5}
Expand Down
3 changes: 3 additions & 0 deletions src/assets/icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const icons = {
get checkSmall() {
return require('./check-small.png');
},
get minusSmall() {
return require('./minusSmall.png');
},
get plusSmall() {
return require('./plusSmall.png');
},
Expand Down
Binary file added src/assets/icons/minusSmall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/components/checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface CheckboxProps extends TouchableOpacityProps {
* Additional styling for checkbox and label container
*/
containerStyle?: StyleProp<ViewStyle>;
indeterminate?: boolean;
}

interface CheckboxState {
Expand Down Expand Up @@ -205,7 +206,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
}

renderCheckbox() {
const {selectedIcon, label, testID, style, containerStyle, ...others} = this.props;
const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props;
return (
//@ts-ignore
<TouchableOpacity
Expand All @@ -226,7 +227,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
>
<AnimatedIcon
style={[this.styles.selectedIcon, {transform: this.animationStyle.transform}]}
source={selectedIcon || Assets.icons.checkSmall}
source={indeterminate ? Assets.icons.minusSmall : selectedIcon || Assets.icons.checkSmall}
testID={`${testID}.selected`}
tintColor={this.getTintColor()}
/>
Expand All @@ -238,6 +239,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {

render() {
const {label, labelStyle, containerStyle, labelProps} = this.props;

return label ? (
<View row centerV style={containerStyle}>
{this.renderCheckbox()}
Expand Down