| 1 | import { SegmentedButton, SingleChoiceSegmentedButtonRow, Text } from "@expo/ui/jetpack-compose"; |
| 2 | import { defaultMinSize, fillMaxWidth } from "@expo/ui/jetpack-compose/modifiers"; |
| 3 | import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider"; |
| 4 | import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole"; |
| 5 | import type { SegmentedControlProps } from "./SegmentedControl.types"; |
| 6 | |
| 7 | /** Compose content shared by screen controls and native dialogs, inside their existing Host. */ |
| 8 | export function MaterialSegmentedButtons<Value extends number | string>( |
| 9 | props: SegmentedControlProps<Value>, |
| 10 | ) { |
| 11 | const { themeVariables: colors } = useAppearancePreferences(); |
| 12 | const typography = useScaledTextRole("footnote"); |
| 13 | return ( |
| 14 | <SingleChoiceSegmentedButtonRow modifiers={[fillMaxWidth()]}> |
| 15 | {props.options.map((option) => ( |
| 16 | <SegmentedButton |
| 17 | key={String(option.value)} |
| 18 | selected={option.value === props.selected} |
| 19 | onClick={() => props.onSelect(option.value)} |
| 20 | modifiers={[defaultMinSize({ minHeight: 48 })]} |
| 21 | colors={{ |
| 22 | activeContainerColor: colors["--color-secondary"], |
| 23 | activeContentColor: colors["--color-secondary-foreground"], |
| 24 | inactiveContainerColor: "transparent", |
| 25 | inactiveContentColor: colors["--color-foreground"], |
| 26 | activeBorderColor: colors["--color-border"], |
| 27 | inactiveBorderColor: colors["--color-border"], |
| 28 | }} |
| 29 | > |
| 30 | <SegmentedButton.Label> |
| 31 | <Text style={typography}>{option.label}</Text> |
| 32 | </SegmentedButton.Label> |
| 33 | </SegmentedButton> |
| 34 | ))} |
| 35 | </SingleChoiceSegmentedButtonRow> |
| 36 | ); |
| 37 | } |