File size: 2,637 Bytes
68465df | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | import {View, ViewStyle, TextStyle, TouchableOpacity} from "react-native"
import {Text} from "@/components/ignite"
import CheckBox from "@/components/ui/CheckBox"
import {useAppTheme} from "@/contexts/ThemeContext"
import {ThemedStyle} from "@/theme"
type Option = {
label: string
value: string
}
type MultiSelectSettingProps = {
label: string
values: string[]
options: Option[]
onValueChange: (selectedValues: string[]) => void
isFirst?: boolean
isLast?: boolean
}
const MultiSelectSetting: React.FC<MultiSelectSettingProps> = ({
label,
values = [],
options,
onValueChange,
isFirst,
isLast,
}) => {
const {theme, themed} = useAppTheme()
const groupedStyle: ViewStyle | undefined =
isFirst !== undefined || isLast !== undefined
? {
borderTopLeftRadius: isFirst ? theme.spacing.s4 : theme.spacing.s1,
borderTopRightRadius: isFirst ? theme.spacing.s4 : theme.spacing.s1,
borderBottomLeftRadius: isLast ? theme.spacing.s4 : theme.spacing.s1,
borderBottomRightRadius: isLast ? theme.spacing.s4 : theme.spacing.s1,
marginBottom: isLast ? 0 : theme.spacing.s2,
}
: undefined
const toggleValue = (value: string) => {
if (values.includes(value)) {
onValueChange(values.filter((v) => v !== value))
} else {
onValueChange([...values, value])
}
}
return (
<View style={[themed($container), groupedStyle]}>
<Text style={themed($label)}>{label}</Text>
{options.map((opt) => (
<TouchableOpacity key={opt.value} style={themed($option)} onPress={() => toggleValue(opt.value)}>
<CheckBox checked={values.includes(opt.value)} onChange={() => toggleValue(opt.value)} />
<Text style={themed($optionLabel)}>{opt.label}</Text>
</TouchableOpacity>
))}
</View>
)
}
const $container: ThemedStyle<ViewStyle> = ({colors, spacing}) => ({
width: "100%",
backgroundColor: colors.primary_foreground,
borderRadius: spacing.s4,
paddingVertical: spacing.s4,
paddingHorizontal: spacing.s4,
})
const $label: ThemedStyle<TextStyle> = ({colors, spacing}) => ({
fontSize: 14,
fontWeight: "600",
color: colors.text,
marginBottom: spacing.s2,
})
const $option: ThemedStyle<ViewStyle> = ({spacing}) => ({
flexDirection: "row",
alignItems: "center",
marginVertical: spacing.s1,
})
const $optionLabel: ThemedStyle<TextStyle> = ({colors, spacing}) => ({
fontSize: 14,
color: colors.text,
marginLeft: spacing.s2,
})
export default MultiSelectSetting
|