import React, { useState } from "react"; import { View } from "react-native"; import type { XOR } from "ts-xor"; import type { BaseSwitchProps } from "./components/BaseSwitch"; import { BaseSwitch } from "./components/BaseSwitch"; import { useStyles } from "./Switch.styles"; import { Text } from "../Text"; interface WithLabelProps extends BaseSwitchProps { /** * Optional label to display in front of the switch */ readonly label: string; /** * Optional descriptive text to display under the switch */ readonly description?: string; } export type SwitchProps = XOR; export function Switch(props: SwitchProps) { const switchProps: SwitchProps = { ...props, accessibilityLabel: props.accessibilityLabel || props.label, }; const [labelWidth, setLabelWidth] = useState(); const styles = useStyles(); return ( {props.label && ( setLabelWidth(event.nativeEvent.layout.width)} testID="switch-label-view" > {props.label} )} {props.description && ( {props.description} )} ); }