-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathToggleSwitch.tsx
30 lines (26 loc) · 980 Bytes
/
ToggleSwitch.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React from 'react';
import { SegmentedButtons, SegmentedButtonsProps, useTheme } from "react-native-paper";
type Props = Omit<SegmentedButtonsProps, 'buttons'|'value'|'multiSelect'> & {
onValueChange: (value: string) => void,
value: string,
options: { icon: string, value: string }[],
}
const ToggleSwitch = ({ options, onValueChange, value, ...rest }: Props) => {
const { colors} = useTheme();
return (
<SegmentedButtons onValueChange={onValueChange} value={value}
buttons={options.map(o => ({
value: o.value,
icon: o.icon,
uncheckedColor: colors.onSurfaceDisabled,
showSelectedCheck: true,
style: {
minWidth: 0,
borderTopWidth: rest.density == 'high' ? 0 : 1,
borderBottomWidth: rest.density == 'high' ? 0 : 1,
backgroundColor: value == o.value ? colors.elevation.level2 : colors.surfaceDisabled,
},
}))} {...rest} />
)
}
export default ToggleSwitch;