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 radio button item (#2379)
- Loading branch information
Showing
5 changed files
with
529 additions
and
35 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,56 @@ | ||
import * as React from 'react'; | ||
import { View, StyleSheet } from 'react-native'; | ||
import { RadioButton, Colors, useTheme } from 'react-native-paper'; | ||
|
||
const RadioButtonItemExample = () => { | ||
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, | ||
}, | ||
]} | ||
> | ||
<RadioButton.Item | ||
label="Default (will look like whatever system this is running on)" | ||
status={checkedDefault ? 'checked' : 'unchecked'} | ||
onPress={() => setCheckedDefault(!checkedDefault)} | ||
value="default" | ||
/> | ||
<RadioButton.Item | ||
label="Android" | ||
mode="android" | ||
status={checkedAndroid ? 'checked' : 'unchecked'} | ||
onPress={() => setCheckedAndroid(!checkedAndroid)} | ||
value="android" | ||
/> | ||
<RadioButton.Item | ||
label="iOS" | ||
mode="ios" | ||
status={checkedIOS ? 'checked' : 'unchecked'} | ||
onPress={() => setCheckedIOS(!checkedIOS)} | ||
value="iOS" | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
RadioButtonItemExample.title = 'Radio Button Item'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: Colors.white, | ||
paddingVertical: 8, | ||
}, | ||
}); | ||
|
||
export default RadioButtonItemExample; |
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
50 changes: 50 additions & 0 deletions
50
src/components/__tests__/RadioButton/RadioButtonItem.test.js
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,50 @@ | ||
import * as React from 'react'; | ||
import { Platform } from 'react-native'; | ||
import renderer from 'react-test-renderer'; | ||
import RadioButtonItem from '../../RadioButton/RadioButtonItem'; | ||
|
||
it('renders unchecked', () => { | ||
const tree = renderer | ||
.create( | ||
<RadioButtonItem | ||
status="unchecked" | ||
label="Unchecked Button" | ||
value="unchecked" | ||
/> | ||
) | ||
.toJSON(); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('can render the iOS radio button on different platforms', () => { | ||
Platform.OS = 'android'; | ||
const tree = renderer | ||
.create( | ||
<RadioButtonItem | ||
status="unchecked" | ||
label="iOS Radio button" | ||
mode="ios" | ||
value="ios" | ||
/> | ||
) | ||
.toJSON(); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('can render the Android radio button on different platforms', () => { | ||
Platform.OS = 'ios'; | ||
const tree = renderer | ||
.create( | ||
<RadioButtonItem | ||
status="unchecked" | ||
label="iOS Checkbox" | ||
mode="android" | ||
value="android" | ||
/> | ||
) | ||
.toJSON(); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); |
Oops, something went wrong.