import { MotiView } from 'moti'; import React, { useCallback } from 'react'; import { I18nManager, Pressable, type PressableProps, View, } from 'react-native'; import Svg, { Path } from 'react-native-svg'; import colors from '../../components/ui/colors'; import { getColor } from '../../library/style-utils'; import { Text } from './text'; const SIZE = 20; const WIDTH = 50; const HEIGHT = 28; const THUMB_HEIGHT = 22; const THUMB_WIDTH = 22; const THUMB_OFFSET = 4; export interface RootProps extends Omit { onChange: (checked: boolean) => void; checked?: boolean; className?: string; accessibilityLabel?: string; } export type IconProps = { checked: boolean; backgroundColor?: string; borderRadius?: number; }; export const Root = ({ checked = false, children, onChange, disabled, className = '', ...props }: RootProps) => { const handleChange = useCallback(() => { onChange(!checked); }, [onChange, checked]); return ( {children} ); }; type LabelProps = { text: string; className?: string; testID?: string; }; const Label = ({ text, testID, className = '' }: LabelProps) => { return ( {text} ); }; export const CheckboxIcon = ({ checked = false, backgroundColor = colors.primary[300], borderRadius = 5, }: IconProps) => { const color = checked ? getColor(backgroundColor) : colors.charcoal[400]; return ( ); }; const CheckboxRoot = ({ checked = false, children, ...props }: RootProps) => { return ( {children} ); }; const CheckboxBase = ({ checked = false, testID, label, backgroundColor, borderRadius, ...props }: RootProps & { label?: string; backgroundColor?: string; borderRadius?: number; }) => { return ( {label ? ( ); }; export const Checkbox = Object.assign(CheckboxBase, { Icon: CheckboxIcon, Root: CheckboxRoot, Label, }); export const RadioIcon = ({ checked = false }: IconProps) => { const color = checked ? colors.primary[300] : colors.charcoal[400]; return ( ); }; const RadioRoot = ({ checked = false, children, ...props }: RootProps) => { return ( {children} ); }; const RadioBase = ({ checked = false, testID, label, ...props }: RootProps & { label?: string }) => { return ( {label ? ( ); }; export const Radio = Object.assign(RadioBase, { Icon: RadioIcon, Root: RadioRoot, Label, }); export const SwitchIcon = ({ checked = false }: IconProps) => { const translateX = checked ? THUMB_OFFSET : WIDTH - THUMB_WIDTH - THUMB_OFFSET; const backgroundColor = checked ? colors.primary[300] : colors.charcoal[400]; return ( ); }; const SwitchRoot = ({ checked = false, children, ...props }: RootProps) => { return ( {children} ); }; const SwitchBase = ({ checked = false, testID, label, ...props }: RootProps & { label?: string }) => { return ( {label ? ( ); }; export const Switch = Object.assign(SwitchBase, { Icon: SwitchIcon, Root: SwitchRoot, Label, });