-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SegmentedButtons component (#3283)
Co-authored-by: Satyajit Sahoo <[email protected]>
- Loading branch information
1 parent
6ff9a20
commit 0d32dd7
Showing
20 changed files
with
1,992 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
46 changes: 46 additions & 0 deletions
46
example/src/Examples/SegmentedButtons/SegmentedButtonDefault.tsx
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,46 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { List, SegmentedButtons } from 'react-native-paper'; | ||
|
||
const SegmentedButtonDefault = () => { | ||
const [value, setValue] = React.useState(''); | ||
|
||
return ( | ||
<List.Section title={`Segmented Button`}> | ||
<SegmentedButtons | ||
value={value} | ||
onValueChange={setValue} | ||
buttons={[ | ||
{ | ||
value: 'walk', | ||
icon: 'walk', | ||
label: 'Walking', | ||
style: styles.button, | ||
}, | ||
{ | ||
value: 'train', | ||
icon: 'train', | ||
label: 'Transit', | ||
style: styles.button, | ||
}, | ||
{ | ||
value: 'drive', | ||
icon: 'car', | ||
label: 'Driving', | ||
style: styles.button, | ||
}, | ||
]} | ||
style={styles.group} | ||
/> | ||
</List.Section> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
button: { | ||
flex: 1, | ||
}, | ||
group: { paddingHorizontal: 20, justifyContent: 'center' }, | ||
}); | ||
|
||
export default SegmentedButtonDefault; |
44 changes: 44 additions & 0 deletions
44
example/src/Examples/SegmentedButtons/SegmentedButtonDisabled.tsx
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,44 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { List, SegmentedButtons } from 'react-native-paper'; | ||
|
||
const SegmentedButtonDisabled = () => { | ||
const [value, setValue] = React.useState(''); | ||
|
||
return ( | ||
<List.Section title={`Segmented Button - disabled`}> | ||
<SegmentedButtons | ||
onValueChange={setValue} | ||
buttons={[ | ||
{ | ||
value: 'walk', | ||
label: 'Walking', | ||
style: styles.button, | ||
}, | ||
{ | ||
value: 'disabled', | ||
label: 'Disabled', | ||
disabled: true, | ||
style: styles.button, | ||
}, | ||
{ | ||
value: 'drive', | ||
label: 'Driving', | ||
style: styles.button, | ||
}, | ||
]} | ||
value={value} | ||
style={styles.group} | ||
/> | ||
</List.Section> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
button: { | ||
flex: 1, | ||
}, | ||
group: { paddingHorizontal: 20, justifyContent: 'center' }, | ||
}); | ||
|
||
export default SegmentedButtonDisabled; |
47 changes: 47 additions & 0 deletions
47
example/src/Examples/SegmentedButtons/SegmentedButtonMultiselect.tsx
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,47 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { List, SegmentedButtons } from 'react-native-paper'; | ||
|
||
const SegmentedButtonMultiselect = () => { | ||
const [value, setValue] = React.useState<string[]>([]); | ||
|
||
return ( | ||
<List.Section title={`Segmented Button - multiselect`}> | ||
<SegmentedButtons | ||
multiSelect | ||
onValueChange={setValue} | ||
value={value} | ||
style={styles.group} | ||
buttons={[ | ||
{ | ||
style: styles.button, | ||
value: 'walk', | ||
label: 'Walking', | ||
showSelectedCheck: true, | ||
}, | ||
{ | ||
style: styles.button, | ||
value: 'transit', | ||
label: 'Transit', | ||
showSelectedCheck: true, | ||
}, | ||
{ | ||
style: styles.button, | ||
value: 'drive', | ||
label: 'Driving', | ||
showSelectedCheck: true, | ||
}, | ||
]} | ||
/> | ||
</List.Section> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
group: { paddingHorizontal: 20, justifyContent: 'center' }, | ||
button: { | ||
flex: 1, | ||
}, | ||
}); | ||
|
||
export default SegmentedButtonMultiselect; |
46 changes: 46 additions & 0 deletions
46
example/src/Examples/SegmentedButtons/SegmentedButtonMultiselectIcons.tsx
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,46 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { List, SegmentedButtons } from 'react-native-paper'; | ||
|
||
const SegmentedButtonMultiselectIcons = () => { | ||
const [value, setValue] = React.useState<string[]>([]); | ||
|
||
return ( | ||
<List.Section title={`Segmented Button - multiselect only icons`}> | ||
<SegmentedButtons | ||
multiSelect | ||
onValueChange={setValue} | ||
value={value} | ||
style={styles.group} | ||
buttons={[ | ||
{ | ||
value: 'size-s', | ||
icon: 'size-s', | ||
}, | ||
{ | ||
value: 'size-m', | ||
icon: 'size-m', | ||
}, | ||
{ | ||
value: 'size-l', | ||
icon: 'size-l', | ||
}, | ||
{ | ||
value: 'size-xl', | ||
icon: 'size-xl', | ||
}, | ||
{ | ||
value: 'size-xxl', | ||
icon: 'size-xxl', | ||
}, | ||
]} | ||
/> | ||
</List.Section> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
group: { paddingHorizontal: 20, justifyContent: 'center' }, | ||
}); | ||
|
||
export default SegmentedButtonMultiselectIcons; |
37 changes: 37 additions & 0 deletions
37
example/src/Examples/SegmentedButtons/SegmentedButtonOnlyIcons.tsx
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,37 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { List, SegmentedButtons } from 'react-native-paper'; | ||
|
||
const SegmentedButtonOnlyIcons = () => { | ||
const [value, setValue] = React.useState(''); | ||
|
||
return ( | ||
<List.Section title={`Segmented Button - only icons`}> | ||
<SegmentedButtons | ||
onValueChange={setValue} | ||
style={styles.group} | ||
value={value} | ||
buttons={[ | ||
{ | ||
icon: 'walk', | ||
value: 'walk', | ||
}, | ||
{ | ||
icon: 'train', | ||
value: 'trainsit', | ||
}, | ||
{ | ||
icon: 'car', | ||
value: 'drive', | ||
}, | ||
]} | ||
/> | ||
</List.Section> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
group: { paddingHorizontal: 20, justifyContent: 'center' }, | ||
}); | ||
|
||
export default SegmentedButtonOnlyIcons; |
40 changes: 40 additions & 0 deletions
40
example/src/Examples/SegmentedButtons/SegmentedButtonOnlyIconsWithCheck.tsx
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,40 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { List, SegmentedButtons } from 'react-native-paper'; | ||
|
||
const SegmentedButtonOnlyIconsWithCheck = () => { | ||
const [value, setValue] = React.useState(''); | ||
|
||
return ( | ||
<List.Section title={`Segmented Button - icons + show selected check`}> | ||
<SegmentedButtons | ||
onValueChange={setValue} | ||
style={styles.group} | ||
value={value} | ||
buttons={[ | ||
{ | ||
icon: 'walk', | ||
value: 'walk', | ||
showSelectedCheck: true, | ||
}, | ||
{ | ||
icon: 'train', | ||
value: 'transit', | ||
showSelectedCheck: true, | ||
}, | ||
{ | ||
icon: 'car', | ||
value: 'drive', | ||
showSelectedCheck: true, | ||
}, | ||
]} | ||
/> | ||
</List.Section> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
group: { paddingHorizontal: 20, justifyContent: 'center' }, | ||
}); | ||
|
||
export default SegmentedButtonOnlyIconsWithCheck; |
44 changes: 44 additions & 0 deletions
44
example/src/Examples/SegmentedButtons/SegmentedButtonWithDensity.tsx
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,44 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { List, SegmentedButtons } from 'react-native-paper'; | ||
|
||
const SegmentedButtonWithDensity = () => { | ||
const [value, setValue] = React.useState(''); | ||
|
||
return ( | ||
<List.Section title={`Segmented Button - only labels + density`}> | ||
<SegmentedButtons | ||
onValueChange={setValue} | ||
value={value} | ||
density="medium" | ||
style={styles.group} | ||
buttons={[ | ||
{ | ||
style: styles.button, | ||
value: 'walk', | ||
label: 'Walking', | ||
}, | ||
{ | ||
style: styles.button, | ||
value: 'transit', | ||
label: 'Transit', | ||
}, | ||
{ | ||
style: styles.button, | ||
value: 'drive', | ||
label: 'Driving', | ||
}, | ||
]} | ||
/> | ||
</List.Section> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
button: { | ||
flex: 1, | ||
}, | ||
group: { paddingHorizontal: 20, justifyContent: 'center' }, | ||
}); | ||
|
||
export default SegmentedButtonWithDensity; |
Oops, something went wrong.