Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | import type React from 'react' import * as Checkbox from '@radix-ui/react-checkbox' import { css } from '@styled/css' export interface ToggleOptionProps { checked: boolean onChange: (checked: boolean) => void label: string description: string children?: React.ReactNode isDark?: boolean } export function ToggleOption({ checked, onChange, label, description, children, isDark = false, }: ToggleOptionProps) { return ( <div data-element="toggle-option-container" className={css({ display: 'flex', flexDirection: 'column', h: children ? 'auto' : '20', bg: checked ? 'brand.50' : isDark ? 'gray.700' : 'white', border: '2px solid', borderColor: checked ? 'brand.500' : isDark ? 'gray.600' : 'gray.200', rounded: 'lg', transition: 'all 0.15s', _hover: { borderColor: checked ? 'brand.600' : isDark ? 'gray.500' : 'gray.300', bg: checked ? 'brand.100' : isDark ? 'gray.600' : 'gray.50', }, })} > <Checkbox.Root checked={checked} onCheckedChange={onChange} data-element="toggle-option" className={css({ display: 'flex', flexDirection: 'column', justifyContent: 'flex-start', gap: '1.5', p: '2.5', bg: 'transparent', border: 'none', rounded: 'lg', cursor: 'pointer', textAlign: 'left', w: 'full', _focus: { outline: 'none', ring: '2px', ringColor: 'brand.300', }, })} > <div className={css({ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '2', })} > <div className={css({ fontSize: 'xs', fontWeight: 'semibold', color: checked ? 'brand.700' : isDark ? 'gray.200' : 'gray.700', })} > {label} </div> <div className={css({ w: '9', h: '5', bg: checked ? 'brand.500' : 'gray.300', rounded: 'full', position: 'relative', transition: 'background-color 0.15s', flexShrink: 0, })} > <div style={{ position: 'absolute', top: '0.125rem', left: checked ? '1.125rem' : '0.125rem', width: '1rem', height: '1rem', background: 'white', borderRadius: '9999px', transition: 'left 0.15s', boxShadow: '0 1px 3px rgba(0,0,0,0.2)', }} /> </div> </div> <div className={css({ fontSize: '2xs', color: checked ? 'brand.600' : isDark ? 'gray.400' : 'gray.500', lineHeight: '1.3', })} > {description} </div> </Checkbox.Root> {children} </div> ) } |