TypeScript
refactor(mobile): share themed toggle rows in settings (#18511)
Julius Marminge9a2b9a2d4040
diff --git a/apps/mobile/src/components/ListToggleRow.tsx b/apps/mobile/src/components/ListToggleRow.tsxnew file mode 100644index 00000000000..41d433b9c02--- /dev/null+++ b/apps/mobile/src/components/ListToggleRow.tsx@@ -0,0 +1,45 @@+import { Pressable } from "react-native";++import { AppText } from "./AppText";+import { ListRowLayout, type ListRowContentProps } from "./ListRowLayout";+import { ThemedSwitch } from "./ThemedSwitch";++/** A null value means the selected environments disagree; activation sets them all on. */+export function ListToggleRow(+ props: Omit<ListRowContentProps, "detail"> & {+ readonly value: boolean | null;+ readonly onValueChange: (value: boolean) => void;+ },+) {+ return (+ <ListRowLayout+ icon={props.icon}+ label={props.label}+ description={props.description}+ disabled={props.disabled}+ accessory={+ props.value === null ? (+ <Pressable+ accessibilityLabel={`Set ${props.label} on for selected environments`}+ accessibilityRole="button"+ accessibilityHint={props.description}+ accessibilityState={{ disabled: Boolean(props.disabled) }}+ disabled={props.disabled}+ className="rounded-full bg-subtle px-3 py-2 active:opacity-70"+ onPress={() => props.onValueChange(true)}+ >+ <AppText className="text-sm font-t3-medium text-foreground">Mixed · Set on</AppText>+ </Pressable>+ ) : (+ <ThemedSwitch+ accessibilityLabel={props.label}+ accessibilityHint={props.description}+ disabled={props.disabled}+ onValueChange={props.onValueChange}+ value={props.value}+ />+ )+ }+ />+ );+}diff --git a/apps/mobile/src/features/settings/components/SettingsControlRow.tsx b/apps/mobile/src/features/settings/components/SettingsControlRow.tsxdeleted file mode 100644index 6f442af1b2f..00000000000--- a/apps/mobile/src/features/settings/components/SettingsControlRow.tsx+++ /dev/null@@ -1,39 +0,0 @@-import type { ComponentProps, ReactNode } from "react";-import { Platform, View } from "react-native";--import { SymbolView } from "../../../components/AppSymbol";-import { AppText as Text } from "../../../components/AppText";-import { cn } from "../../../lib/cn";--export function SettingsControlRow(props: {- readonly disabled?: boolean;- readonly icon: ComponentProps<typeof SymbolView>["name"];- readonly label: string;- readonly subtitle?: string;- readonly children: ReactNode;-}) {- return (- <View- className={cn(- "flex-row items-center gap-4 p-4 android:min-h-14 android:py-3",- props.subtitle && "android:min-h-18",- props.disabled && "opacity-[0.45]",- )}- >- <SymbolView- name={props.icon}- size={Platform.OS === "android" ? 24 : 22}- tintColorClassName="accent-icon"- type="monochrome"- weight="regular"- />- <View className="min-w-0 flex-1 android:gap-1">- <Text className="text-lg text-foreground android:text-base">{props.label}</Text>- {props.subtitle ? (- <Text className="text-sm text-foreground-muted">{props.subtitle}</Text>- ) : null}- </View>- {props.children}- </View>- );-}diff --git a/apps/mobile/src/features/settings/components/SettingsSwitchRow.tsx b/apps/mobile/src/features/settings/components/SettingsSwitchRow.tsxindex 3fb95f5699a..156e5e7db38 100644--- a/apps/mobile/src/features/settings/components/SettingsSwitchRow.tsx+++ b/apps/mobile/src/features/settings/components/SettingsSwitchRow.tsx@@ -1,42 +1,12 @@import type { ComponentProps } from "react";-import { Pressable } from "react-native";-import { AppText as Text } from "../../../components/AppText";-import { ThemedSwitch } from "../../../components/ThemedSwitch";-import { SettingsControlRow } from "./SettingsControlRow";+import { ListToggleRow } from "../../../components/ListToggleRow";-export function SettingsSwitchRow(- props: Omit<ComponentProps<typeof SettingsControlRow>, "children"> & {- readonly value: boolean | null;- readonly onValueChange: (value: boolean) => void;- },-) {- return (- <SettingsControlRow- disabled={props.disabled}- icon={props.icon}- label={props.label}- subtitle={props.subtitle}- >- {props.value === null ? (- <Pressable- accessibilityLabel={`Set ${props.label} on for selected environments`}- accessibilityRole="button"- disabled={props.disabled}- className="rounded-full bg-subtle px-3 py-2 active:opacity-70"- onPress={() => props.onValueChange(true)}- >- <Text className="text-sm font-t3-medium text-foreground">Mixed · Set on</Text>- </Pressable>- ) : (- <ThemedSwitch- style={{ alignSelf: "center" }}- accessibilityLabel={props.label}- disabled={props.disabled}- onValueChange={props.onValueChange}- value={props.value}- />- )}- </SettingsControlRow>- );+export function SettingsSwitchRow({+ subtitle,+ ...props+}: Omit<ComponentProps<typeof ListToggleRow>, "description"> & {+ readonly subtitle?: string;+}) {+ return <ListToggleRow {...props} description={subtitle} />;}