Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mode prop to Checkbox.Item component (#2375)
- Loading branch information
1 parent
29354ee
commit 0ec3587
Showing
5 changed files
with
557 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as React from 'react'; | ||
import { View, StyleSheet } from 'react-native'; | ||
import { Checkbox, Colors, useTheme } from 'react-native-paper'; | ||
|
||
const CheckboxExample = () => { | ||
const [checkedDefault, setCheckedDefault] = React.useState<boolean>(true); | ||
const [checkedAndroid, setCheckedAndroid] = React.useState<boolean>(true); | ||
const [checkedIOS, setCheckedIOS] = React.useState<boolean>(true); | ||
const { | ||
colors: { background }, | ||
} = useTheme(); | ||
|
||
return ( | ||
<View | ||
style={[ | ||
styles.container, | ||
{ | ||
backgroundColor: background, | ||
}, | ||
]} | ||
> | ||
<Checkbox.Item | ||
label="Default (will look like whatever system this is running on)" | ||
status={checkedDefault ? 'checked' : 'unchecked'} | ||
onPress={() => setCheckedDefault(!checkedDefault)} | ||
/> | ||
<Checkbox.Item | ||
label="Android" | ||
mode="android" | ||
status={checkedAndroid ? 'checked' : 'unchecked'} | ||
onPress={() => setCheckedAndroid(!checkedAndroid)} | ||
/> | ||
<Checkbox.Item | ||
label="iOS" | ||
mode="ios" | ||
status={checkedIOS ? 'checked' : 'unchecked'} | ||
onPress={() => setCheckedIOS(!checkedIOS)} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
CheckboxExample.title = 'Checkbox Item'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: Colors.white, | ||
paddingVertical: 8, | ||
}, | ||
}); | ||
|
||
export default CheckboxExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as React from 'react'; | ||
import { Platform } from 'react-native'; | ||
import renderer from 'react-test-renderer'; | ||
import CheckboxItem from '../../Checkbox/CheckboxItem'; | ||
|
||
it('renders unchecked', () => { | ||
const tree = renderer | ||
.create(<CheckboxItem status="unchecked" label="Unchecked Button" />) | ||
.toJSON(); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('can render the iOS checkbox on different platforms', () => { | ||
Platform.OS = 'android'; | ||
const tree = renderer | ||
.create(<CheckboxItem status="unchecked" label="iOS Checkbox" mode="ios" />) | ||
.toJSON(); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('can render the Android checkbox on different platforms', () => { | ||
Platform.OS = 'ios'; | ||
const tree = renderer | ||
.create( | ||
<CheckboxItem status="unchecked" label="iOS Checkbox" mode="android" /> | ||
) | ||
.toJSON(); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); |
Oops, something went wrong.