@cdx-ui/components 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/AGENTS.md +24 -0
  2. package/README.md +2 -0
  3. package/coverage.svg +1 -1
  4. package/docs/components/accordion/content.md +538 -0
  5. package/docs/components/alert/content.md +203 -0
  6. package/docs/components/alert-dialog/content.md +319 -0
  7. package/docs/components/avatar/content.md +368 -0
  8. package/docs/components/avatar/design.md +202 -0
  9. package/docs/components/badge/content.md +225 -0
  10. package/docs/components/bottom-sheet/content.md +353 -0
  11. package/docs/components/bottom-sheet/design.md +249 -0
  12. package/docs/components/box/content.md +141 -0
  13. package/docs/components/breadcrumbs/content.md +169 -0
  14. package/docs/components/button/content.md +398 -0
  15. package/docs/components/button/design.md +258 -0
  16. package/docs/components/calendar/content.md +137 -0
  17. package/docs/components/card/content.md +283 -0
  18. package/docs/components/carousel/content.md +417 -0
  19. package/docs/components/checkbox/content.md +236 -0
  20. package/docs/components/checkbox/design.md +214 -0
  21. package/docs/components/chip/content.md +439 -0
  22. package/docs/components/chip/design.md +418 -0
  23. package/docs/components/color-area/content.md +84 -0
  24. package/docs/components/color-field/content.md +132 -0
  25. package/docs/components/color-picker/content.md +209 -0
  26. package/docs/components/color-slider/content.md +118 -0
  27. package/docs/components/color-swatch/content.md +62 -0
  28. package/docs/components/color-swatch-picker/content.md +124 -0
  29. package/docs/components/content.md +98 -0
  30. package/docs/components/currency-input/content.md +205 -0
  31. package/docs/components/data-grid/content.md +521 -0
  32. package/docs/components/date-field/content.md +147 -0
  33. package/docs/components/date-picker/content.md +360 -0
  34. package/docs/components/date-range-picker/content.md +301 -0
  35. package/docs/components/date-time-field/content.md +157 -0
  36. package/docs/components/date-time-list/content.md +105 -0
  37. package/docs/components/date-time-picker/content.md +272 -0
  38. package/docs/components/dialog/content.md +436 -0
  39. package/docs/components/dialog/design.md +192 -0
  40. package/docs/components/divider/content.md +112 -0
  41. package/docs/components/drawer/content.md +428 -0
  42. package/docs/components/field/content.md +277 -0
  43. package/docs/components/form/content.md +62 -0
  44. package/docs/components/full-screen-dialog/content.md +881 -0
  45. package/docs/components/heading/content.md +55 -0
  46. package/docs/components/icon/content.md +190 -0
  47. package/docs/components/icon-button/content.md +200 -0
  48. package/docs/components/icon-button/design.md +165 -0
  49. package/docs/components/image/content.md +104 -0
  50. package/docs/components/input/content.md +346 -0
  51. package/docs/components/input/design.md +389 -0
  52. package/docs/components/insurance-disclosure/content.md +103 -0
  53. package/docs/components/link/content.md +180 -0
  54. package/docs/components/link/design.md +160 -0
  55. package/docs/components/list-item/content.md +695 -0
  56. package/docs/components/menu/content.md +1254 -0
  57. package/docs/components/month-calendar/content.md +84 -0
  58. package/docs/components/month-picker/content.md +273 -0
  59. package/docs/components/otp-input/content.md +327 -0
  60. package/docs/components/progress-bar/content.md +87 -0
  61. package/docs/components/progress-circle/content.md +176 -0
  62. package/docs/components/progress-segmented/content.md +119 -0
  63. package/docs/components/quick-action-button/content.md +154 -0
  64. package/docs/components/quick-action-button/design.md +170 -0
  65. package/docs/components/radio/content.md +224 -0
  66. package/docs/components/range-calendar/content.md +123 -0
  67. package/docs/components/reorderable-list/content.md +311 -0
  68. package/docs/components/scoped-theme/content.md +47 -0
  69. package/docs/components/scroll-shadow/content.md +693 -0
  70. package/docs/components/select/content.md +473 -0
  71. package/docs/components/select/design.md +301 -0
  72. package/docs/components/skeleton/content.md +104 -0
  73. package/docs/components/slider/content.md +423 -0
  74. package/docs/components/stack/content.md +161 -0
  75. package/docs/components/switch/content.md +150 -0
  76. package/docs/components/switch/design.md +208 -0
  77. package/docs/components/table/content.md +548 -0
  78. package/docs/components/table-pagination/content.md +177 -0
  79. package/docs/components/tabs/content.md +297 -0
  80. package/docs/components/text/content.md +142 -0
  81. package/docs/components/textarea/content.md +222 -0
  82. package/docs/components/tile/content.md +702 -0
  83. package/docs/components/toast/content.md +456 -0
  84. package/docs/components/toggle-button/content.md +505 -0
  85. package/docs/components/tooltip/content.md +350 -0
  86. package/docs/components/virtualized-list/content.md +250 -0
  87. package/docs/foundations/content.md +9 -0
  88. package/docs/foundations/expressions/icons/content.md +19 -0
  89. package/docs/foundations/styles/tokens/all-tokens/content.md +192 -0
  90. package/docs/foundations/styles/tokens/what-are-tokens/content.md +33 -0
  91. package/docs/foundations/styles/tokens/what-are-tokens/design.md +33 -0
  92. package/docs/getting-started/content.md +4 -0
  93. package/docs/getting-started/designers/content.md +13 -0
  94. package/docs/getting-started/designers/design.md +13 -0
  95. package/docs/getting-started/developers/accessibility/content.md +31 -0
  96. package/docs/getting-started/developers/content.md +612 -0
  97. package/docs/getting-started/developers/styling/content.md +195 -0
  98. package/docs/llms.txt +195 -0
  99. package/docs/patterns/account-management/content.md +75 -0
  100. package/docs/patterns/authentication/content.md +50 -0
  101. package/docs/patterns/content.md +10 -0
  102. package/docs/patterns/dashboard/content.md +34 -0
  103. package/docs/patterns/empty-states/content.md +32 -0
  104. package/docs/patterns/forms/content.md +108 -0
  105. package/docs/patterns/onboarding/content.md +69 -0
  106. package/docs/patterns/payments/content.md +35 -0
  107. package/docs/patterns/settings/content.md +72 -0
  108. package/docs/resources/content.md +9 -0
  109. package/docs/resources/figma-libraries/content.md +42 -0
  110. package/docs/resources/release-notes/0.0.1-beta.118/content.md +27 -0
  111. package/docs/resources/release-notes/0.0.1-beta.122/content.md +21 -0
  112. package/docs/resources/release-notes/0.0.1-beta.124/content.md +16 -0
  113. package/docs/resources/release-notes/0.0.1-beta.126/content.md +10 -0
  114. package/docs/resources/release-notes/0.0.1-beta.127/content.md +14 -0
  115. package/docs/resources/release-notes/0.0.1-beta.128/content.md +9 -0
  116. package/docs/resources/release-notes/0.0.1-beta.129/content.md +18 -0
  117. package/docs/resources/release-notes/0.0.1-beta.130/content.md +18 -0
  118. package/docs/resources/release-notes/0.0.1-beta.133/content.md +7 -0
  119. package/docs/resources/release-notes/0.0.1-beta.134/content.md +17 -0
  120. package/docs/resources/release-notes/0.0.1-beta.136/content.md +7 -0
  121. package/docs/resources/release-notes/0.0.1-beta.137/content.md +10 -0
  122. package/docs/resources/release-notes/0.0.1-beta.138/content.md +7 -0
  123. package/docs/resources/release-notes/0.0.1-beta.139/content.md +13 -0
  124. package/docs/resources/release-notes/0.0.1-beta.140/content.md +26 -0
  125. package/docs/resources/release-notes/0.0.1-beta.141/content.md +63 -0
  126. package/docs/resources/release-notes/0.0.1-beta.142/content.md +7 -0
  127. package/docs/resources/release-notes/0.0.1-beta.143/content.md +12 -0
  128. package/docs/resources/release-notes/0.0.1-beta.144/content.md +7 -0
  129. package/docs/resources/release-notes/0.0.1-beta.145/content.md +7 -0
  130. package/docs/resources/release-notes/0.0.1-beta.147/content.md +10 -0
  131. package/docs/resources/release-notes/0.0.1-beta.149/content.md +10 -0
  132. package/docs/resources/release-notes/0.0.1-beta.150/content.md +13 -0
  133. package/docs/resources/release-notes/0.0.1-beta.152/content.md +7 -0
  134. package/docs/resources/release-notes/0.0.1-beta.154/content.md +15 -0
  135. package/docs/resources/release-notes/0.0.1-beta.156/content.md +7 -0
  136. package/docs/resources/release-notes/0.0.1-beta.158/content.md +9 -0
  137. package/docs/resources/release-notes/0.0.1-beta.159/content.md +11 -0
  138. package/docs/resources/release-notes/0.0.1-beta.160/content.md +7 -0
  139. package/docs/resources/release-notes/0.0.1-beta.161/content.md +7 -0
  140. package/docs/resources/release-notes/0.0.1-beta.163/content.md +7 -0
  141. package/docs/resources/release-notes/0.0.1-beta.164/content.md +9 -0
  142. package/docs/resources/release-notes/0.0.1-beta.166/content.md +17 -0
  143. package/docs/resources/release-notes/0.0.1-beta.167/content.md +7 -0
  144. package/docs/resources/release-notes/0.0.1-beta.168/content.md +7 -0
  145. package/docs/resources/release-notes/0.0.1-beta.169/content.md +7 -0
  146. package/docs/resources/release-notes/0.0.1-beta.171/content.md +16 -0
  147. package/docs/resources/release-notes/0.0.1-beta.172/content.md +24 -0
  148. package/docs/resources/release-notes/0.0.1-beta.173/content.md +15 -0
  149. package/docs/resources/release-notes/0.0.1-beta.174/content.md +7 -0
  150. package/docs/resources/release-notes/0.0.1-beta.176/content.md +32 -0
  151. package/docs/resources/release-notes/0.0.1-beta.179/content.md +11 -0
  152. package/docs/resources/release-notes/0.0.1-beta.182/content.md +13 -0
  153. package/docs/resources/release-notes/0.0.1-beta.185/content.md +7 -0
  154. package/docs/resources/release-notes/0.0.1-beta.187/content.md +27 -0
  155. package/docs/resources/release-notes/0.1.1/content.md +23 -0
  156. package/docs/resources/release-notes/0.1.2/content.md +7 -0
  157. package/docs/resources/release-notes/0.1.4/content.md +19 -0
  158. package/docs/resources/release-notes/0.1.5/content.md +7 -0
  159. package/docs/resources/release-notes/0.1.6/content.md +7 -0
  160. package/docs/resources/release-notes/0.2.0/content.md +31 -0
  161. package/docs/resources/release-notes/0.2.1/content.md +17 -0
  162. package/docs/resources/release-notes/0.2.2/content.md +11 -0
  163. package/docs/resources/release-notes/0.2.3/content.md +15 -0
  164. package/docs/resources/release-notes/0.2.4/content.md +17 -0
  165. package/docs/resources/release-notes/content.md +65 -0
  166. package/lib/commonjs/components/Box/Box.js +9 -1
  167. package/lib/commonjs/components/Box/Box.js.map +1 -1
  168. package/lib/commonjs/components/Breadcrumbs/index.js +28 -3
  169. package/lib/commonjs/components/Breadcrumbs/index.js.map +1 -1
  170. package/lib/commonjs/components/Breadcrumbs/styles.js +27 -0
  171. package/lib/commonjs/components/Breadcrumbs/styles.js.map +1 -1
  172. package/lib/commonjs/components/DateTimeList/index.js +11 -26
  173. package/lib/commonjs/components/DateTimeList/index.js.map +1 -1
  174. package/lib/commonjs/components/DateTimeList/styles.js +2 -12
  175. package/lib/commonjs/components/DateTimeList/styles.js.map +1 -1
  176. package/lib/commonjs/components/ListItem/index.js.map +1 -1
  177. package/lib/commonjs/components/ListItem/styles.js +2 -1
  178. package/lib/commonjs/components/ListItem/styles.js.map +1 -1
  179. package/lib/commonjs/components/Menu/index.js +11 -5
  180. package/lib/commonjs/components/Menu/index.js.map +1 -1
  181. package/lib/commonjs/components/ScrollShadow/gradient.js +29 -0
  182. package/lib/commonjs/components/ScrollShadow/gradient.js.map +1 -0
  183. package/lib/commonjs/components/ScrollShadow/index.js +171 -44
  184. package/lib/commonjs/components/ScrollShadow/index.js.map +1 -1
  185. package/lib/commonjs/components/ScrollShadow/styles.js +58 -14
  186. package/lib/commonjs/components/ScrollShadow/styles.js.map +1 -1
  187. package/lib/commonjs/components/ScrollShadow/useComposedScrollHandler.js +63 -0
  188. package/lib/commonjs/components/ScrollShadow/useComposedScrollHandler.js.map +1 -0
  189. package/lib/commonjs/components/ScrollShadow/useScrollShadow.js +48 -8
  190. package/lib/commonjs/components/ScrollShadow/useScrollShadow.js.map +1 -1
  191. package/lib/commonjs/components/Stack/HStack.js +6 -2
  192. package/lib/commonjs/components/Stack/HStack.js.map +1 -1
  193. package/lib/commonjs/components/Stack/VStack.js +6 -2
  194. package/lib/commonjs/components/Stack/VStack.js.map +1 -1
  195. package/lib/commonjs/components/Tabs/index.js +16 -23
  196. package/lib/commonjs/components/Tabs/index.js.map +1 -1
  197. package/lib/commonjs/components/Tabs/styles.js +1 -10
  198. package/lib/commonjs/components/Tabs/styles.js.map +1 -1
  199. package/lib/commonjs/figma/ListItem.SectionHeader.figma.js +20 -5
  200. package/lib/commonjs/figma/ListItem.SectionHeader.figma.js.map +1 -1
  201. package/lib/commonjs/index.js +10 -10
  202. package/lib/commonjs/index.js.map +1 -1
  203. package/lib/module/components/Box/Box.js +9 -1
  204. package/lib/module/components/Box/Box.js.map +1 -1
  205. package/lib/module/components/Breadcrumbs/index.js +29 -4
  206. package/lib/module/components/Breadcrumbs/index.js.map +1 -1
  207. package/lib/module/components/Breadcrumbs/styles.js +26 -0
  208. package/lib/module/components/Breadcrumbs/styles.js.map +1 -1
  209. package/lib/module/components/DateTimeList/index.js +12 -27
  210. package/lib/module/components/DateTimeList/index.js.map +1 -1
  211. package/lib/module/components/DateTimeList/styles.js +1 -11
  212. package/lib/module/components/DateTimeList/styles.js.map +1 -1
  213. package/lib/module/components/ListItem/index.js.map +1 -1
  214. package/lib/module/components/ListItem/styles.js +2 -1
  215. package/lib/module/components/ListItem/styles.js.map +1 -1
  216. package/lib/module/components/Menu/index.js +11 -5
  217. package/lib/module/components/Menu/index.js.map +1 -1
  218. package/lib/module/components/ScrollShadow/gradient.js +24 -0
  219. package/lib/module/components/ScrollShadow/gradient.js.map +1 -0
  220. package/lib/module/components/ScrollShadow/index.js +170 -48
  221. package/lib/module/components/ScrollShadow/index.js.map +1 -1
  222. package/lib/module/components/ScrollShadow/styles.js +57 -13
  223. package/lib/module/components/ScrollShadow/styles.js.map +1 -1
  224. package/lib/module/components/ScrollShadow/useComposedScrollHandler.js +57 -0
  225. package/lib/module/components/ScrollShadow/useComposedScrollHandler.js.map +1 -0
  226. package/lib/module/components/ScrollShadow/useScrollShadow.js +46 -8
  227. package/lib/module/components/ScrollShadow/useScrollShadow.js.map +1 -1
  228. package/lib/module/components/Stack/HStack.js +6 -2
  229. package/lib/module/components/Stack/HStack.js.map +1 -1
  230. package/lib/module/components/Stack/VStack.js +6 -2
  231. package/lib/module/components/Stack/VStack.js.map +1 -1
  232. package/lib/module/components/Tabs/index.js +17 -24
  233. package/lib/module/components/Tabs/index.js.map +1 -1
  234. package/lib/module/components/Tabs/styles.js +0 -9
  235. package/lib/module/components/Tabs/styles.js.map +1 -1
  236. package/lib/module/figma/ListItem.SectionHeader.figma.js +20 -5
  237. package/lib/module/figma/ListItem.SectionHeader.figma.js.map +1 -1
  238. package/lib/module/index.js +6 -1
  239. package/lib/module/index.js.map +1 -1
  240. package/lib/typescript/animation/hooks/usePopupDialogContentAnimation.d.ts +2 -2
  241. package/lib/typescript/animation/hooks/usePopupOverlayAnimation.d.ts +2 -2
  242. package/lib/typescript/components/Box/Box.d.ts +4 -0
  243. package/lib/typescript/components/Box/Box.d.ts.map +1 -1
  244. package/lib/typescript/components/Breadcrumbs/index.d.ts +3 -1
  245. package/lib/typescript/components/Breadcrumbs/index.d.ts.map +1 -1
  246. package/lib/typescript/components/Breadcrumbs/styles.d.ts +2 -0
  247. package/lib/typescript/components/Breadcrumbs/styles.d.ts.map +1 -1
  248. package/lib/typescript/components/DateTimeList/index.d.ts.map +1 -1
  249. package/lib/typescript/components/DateTimeList/styles.d.ts +1 -4
  250. package/lib/typescript/components/DateTimeList/styles.d.ts.map +1 -1
  251. package/lib/typescript/components/ListItem/index.d.ts +5 -4
  252. package/lib/typescript/components/ListItem/index.d.ts.map +1 -1
  253. package/lib/typescript/components/ListItem/styles.d.ts +1 -1
  254. package/lib/typescript/components/ListItem/styles.d.ts.map +1 -1
  255. package/lib/typescript/components/Menu/index.d.ts.map +1 -1
  256. package/lib/typescript/components/ScrollShadow/gradient.d.ts +7 -0
  257. package/lib/typescript/components/ScrollShadow/gradient.d.ts.map +1 -0
  258. package/lib/typescript/components/ScrollShadow/index.d.ts +57 -15
  259. package/lib/typescript/components/ScrollShadow/index.d.ts.map +1 -1
  260. package/lib/typescript/components/ScrollShadow/styles.d.ts +8 -2
  261. package/lib/typescript/components/ScrollShadow/styles.d.ts.map +1 -1
  262. package/lib/typescript/components/ScrollShadow/useComposedScrollHandler.d.ts +13 -0
  263. package/lib/typescript/components/ScrollShadow/useComposedScrollHandler.d.ts.map +1 -0
  264. package/lib/typescript/components/ScrollShadow/useScrollShadow.d.ts +15 -2
  265. package/lib/typescript/components/ScrollShadow/useScrollShadow.d.ts.map +1 -1
  266. package/lib/typescript/components/Stack/HStack.d.ts +3 -2
  267. package/lib/typescript/components/Stack/HStack.d.ts.map +1 -1
  268. package/lib/typescript/components/Stack/VStack.d.ts +3 -2
  269. package/lib/typescript/components/Stack/VStack.d.ts.map +1 -1
  270. package/lib/typescript/components/Tabs/index.d.ts.map +1 -1
  271. package/lib/typescript/components/Tabs/styles.d.ts +0 -7
  272. package/lib/typescript/components/Tabs/styles.d.ts.map +1 -1
  273. package/lib/typescript/components/Toast/animation.d.ts +3 -3
  274. package/lib/typescript/components/Toast/animation.d.ts.map +1 -1
  275. package/lib/typescript/figma/ListItem.SectionHeader.figma.d.ts.map +1 -1
  276. package/lib/typescript/index.d.ts +6 -1
  277. package/lib/typescript/index.d.ts.map +1 -1
  278. package/package.json +11 -9
  279. package/src/components/Box/Box.tsx +18 -4
  280. package/src/components/Breadcrumbs/index.tsx +28 -4
  281. package/src/components/Breadcrumbs/styles.ts +30 -0
  282. package/src/components/DateTimeList/index.tsx +13 -26
  283. package/src/components/DateTimeList/styles.ts +1 -10
  284. package/src/components/ListItem/index.tsx +5 -4
  285. package/src/components/ListItem/styles.ts +1 -0
  286. package/src/components/Menu/index.tsx +11 -8
  287. package/src/components/ScrollShadow/gradient.ts +48 -0
  288. package/src/components/ScrollShadow/index.tsx +300 -69
  289. package/src/components/ScrollShadow/styles.ts +45 -28
  290. package/src/components/ScrollShadow/useComposedScrollHandler.ts +58 -0
  291. package/src/components/ScrollShadow/useScrollShadow.ts +72 -10
  292. package/src/components/Stack/HStack.tsx +8 -4
  293. package/src/components/Stack/VStack.tsx +8 -4
  294. package/src/components/Tabs/index.tsx +25 -35
  295. package/src/components/Tabs/styles.ts +0 -9
  296. package/src/index.ts +8 -1
@@ -0,0 +1,150 @@
1
+ # Switch (https://design.candescent.com/docs/components/switch)
2
+
3
+ Resources: [Figma](https://www.figma.com/design/0lEVMVlLj8ZS4fgItr3pmd/%E2%AD%90-Forge-DS--Components?node-id=308-19827), [Storybook](https://victorious-wave-0daadf00f.6.azurestaticapps.net/?path=/story/inputs-switch--default)
4
+
5
+ A switch controls a single setting that takes effect immediately. Always provide an accessible label.
6
+
7
+ ```tsx
8
+ import { Switch } from '@cdx-ui/components';
9
+ ```
10
+
11
+ ## Basic
12
+
13
+ Use `value` and `onValueChange` for a controlled switch, or `defaultValue` for an uncontrolled switch.
14
+
15
+ ```tsx
16
+ import { useState } from 'react';
17
+ import { Box, Switch, Text } from '@cdx-ui/components';
18
+
19
+ export default function SwitchBasicDemo() {
20
+ const [enabled, setEnabled] = useState(false);
21
+
22
+ return (
23
+ <Box className="flex-row items-center gap-3">
24
+ <Switch value={enabled} onValueChange={setEnabled} accessibilityLabel="Account alerts" />
25
+ <Text>Account alerts {enabled ? 'on' : 'off'}</Text>
26
+ </Box>
27
+ );
28
+ }
29
+ ```
30
+
31
+ ## Sizes
32
+
33
+ `size` changes the track and thumb on web. iOS and Android render the system switch, so `size` has no effect.
34
+
35
+ ```tsx
36
+ import { Box, Switch, Text } from '@cdx-ui/components';
37
+
38
+ export default function SwitchSizesDemo() {
39
+ return (
40
+ <Box className="gap-4">
41
+ <Box className="flex-row items-center gap-3">
42
+ <Switch size="sm" defaultValue accessibilityLabel="Small switch" />
43
+ <Text>Small</Text>
44
+ </Box>
45
+ <Box className="flex-row items-center gap-3">
46
+ <Switch size="md" defaultValue accessibilityLabel="Medium switch" />
47
+ <Text>Medium</Text>
48
+ </Box>
49
+ <Box className="flex-row items-center gap-3">
50
+ <Switch size="lg" defaultValue accessibilityLabel="Large switch" />
51
+ <Text>Large</Text>
52
+ </Box>
53
+ </Box>
54
+ );
55
+ }
56
+ ```
57
+
58
+ ## Disabled
59
+
60
+ Disabled switches can display either the on or off state.
61
+
62
+ ```tsx
63
+ import { Box, Switch, Text } from '@cdx-ui/components';
64
+
65
+ export default function SwitchDisabledDemo() {
66
+ return (
67
+ <Box className="gap-4">
68
+ <Box className="flex-row items-center gap-3">
69
+ <Switch isDisabled accessibilityLabel="Disabled off switch" />
70
+ <Text>Disabled off</Text>
71
+ </Box>
72
+ <Box className="flex-row items-center gap-3">
73
+ <Switch isDisabled defaultValue accessibilityLabel="Disabled on switch" />
74
+ <Text>Disabled on</Text>
75
+ </Box>
76
+ </Box>
77
+ );
78
+ }
79
+ ```
80
+
81
+ ## Invalid
82
+
83
+ Use `isInvalid` when the current setting fails validation.
84
+
85
+ ```tsx
86
+ import { Box, Switch, Text } from '@cdx-ui/components';
87
+
88
+ export default function SwitchInvalidDemo() {
89
+ return (
90
+ <Box className="flex-row items-center gap-3">
91
+ <Switch isInvalid accessibilityLabel="Required security alerts" />
92
+ <Text>Security alerts are required</Text>
93
+ </Box>
94
+ );
95
+ }
96
+ ```
97
+
98
+ ## In a list item
99
+
100
+ Place switches after their labels in settings lists. The setting should update as soon as the switch is toggled.
101
+
102
+ ```tsx
103
+ import { useState } from 'react';
104
+ import { Card, ListItem, Switch } from '@cdx-ui/components';
105
+ import { Notifications } from '@cdx-ui/icons';
106
+
107
+ export default function ListItemWithSwitchDemo() {
108
+ const [enabled, setEnabled] = useState(true);
109
+
110
+ return (
111
+ <Card fullBleed className="w-full max-w-md">
112
+ <Card.Content>
113
+ <ListItem showSeparator={false}>
114
+ <ListItem.LeadingSlot>
115
+ <Notifications size={24} />
116
+ </ListItem.LeadingSlot>
117
+ <ListItem.Content>
118
+ <ListItem.Title>Push Notifications</ListItem.Title>
119
+ <ListItem.Description>Receive alerts for account activity</ListItem.Description>
120
+ </ListItem.Content>
121
+ <ListItem.TrailingSlot>
122
+ <Switch value={enabled} onValueChange={setEnabled} />
123
+ </ListItem.TrailingSlot>
124
+ </ListItem>
125
+ </Card.Content>
126
+ </Card>
127
+ );
128
+ }
129
+ ```
130
+
131
+ ## API
132
+
133
+ ### Switch
134
+
135
+ | Prop | Type | Default | Description |
136
+ | --- | --- | --- | --- |
137
+ | `size?` | `'sm' \| 'md' \| 'lg'` | `'md'` | Track and thumb size on web. iOS and Android render the system switch, so `size` has no effect. |
138
+ | `className?` | `string` | — | Additional Uniwind/Tailwind classes, merged after the switch's own styles. |
139
+ | `accessibilityLabel?` | `string` | — | Accessible label announced by screen readers. |
140
+ | `onFocus?` | `(() => void)` | — | Called when the switch receives focus. |
141
+ | `onBlur?` | `(() => void)` | — | Called when the switch loses focus. |
142
+ | `onValueChange?` | `((value: boolean) => void)` | — | Callback invoked when the switch value changes. |
143
+ | `isChecked?` | `boolean` | — | Alias for `value`. `value` takes precedence when both are set. |
144
+ | `value?` | `boolean` | — | Controlled on/off state. Takes precedence over `isChecked`. |
145
+ | `isDisabled?` | `boolean` | — | If true, the switch will be disabled. |
146
+ | `disabled?` | `boolean` | — | Alias for `isDisabled`. Either prop disables the switch. |
147
+ | `defaultValue?` | `boolean` | — | Initial state when uncontrolled. No effect when `value` or `isChecked` is set. |
148
+ | `isInvalid?` | `boolean` | — | If true, set the switch to the invalid state. |
149
+
150
+ Does not extend a React Native base component — every prop is listed above.
@@ -0,0 +1,208 @@
1
+ # Switch — Design (https://design.candescent.com/docs/components/switch)
2
+
3
+ ## Usage
4
+
5
+ **Example**
6
+
7
+ **Common alternative names**: Toggle, Toggle switch
8
+
9
+ ---
10
+
11
+ ## **Anatomy**
12
+
13
+ A switch is made up of a track, and a knob that slides along that track when the switch is toggled.
14
+
15
+ **Anatomy\_switch**
16
+
17
+ 1. **Knob (unchecked)**: In the unchecked (off) state, the knob is smaller, grey, and on the left side of the track.
18
+ 2. **Track (unchecked)**: In the unchecked (off) state, the track is transparent with a grey border.
19
+ 3. **Track (checked)**: In the checked (on) state, the track has a solid fill color.
20
+
21
+ ### **Color**
22
+
23
+ The radio button component is available the colors: **Action**, and **Danger**.
24
+
25
+ - **color: action**
26
+
27
+ Utilizes the defualt color palette. Used for **most switches** in designs.
28
+ - **color: danger**
29
+
30
+ Utilizes the danger color palette when checked. Indicates that there is an error with the user’s selection.
31
+
32
+ ### **Platform**
33
+
34
+ The Switch utilizes the operating system's native switch component on iOS and Android. This causes some visual differences between platforms.
35
+
36
+ - **Platform: iOS**
37
+
38
+ The size for iPhone and iPad. Wider track for touch on native iOS; 64×28 px.
39
+ - **Platform: Web**
40
+
41
+ The default for web and desktop. Pointer-friendly control; 48×28 px.
42
+
43
+ ---
44
+
45
+ Usage
46
+
47
+ ### When to use
48
+
49
+ > [!TIP]
50
+ >
51
+ > **To allow the user to toggle between two binary states**
52
+ >
53
+ > - ex: _on_ and _off_
54
+ > - ex: _yes_ and _no_
55
+ > - ex: _enabled_ and _disabled_
56
+
57
+ > [!TIP]
58
+ >
59
+ > **When the change should take immediate effect**
60
+ >
61
+ > - ex: in a settings menu, turning off the WiFi toggle should immediately turn off the WiFi
62
+ > - See the behavior section for details
63
+
64
+ ### When not to use
65
+
66
+ > [!CAUTION]
67
+ >
68
+ > **Groups of options in a form**
69
+ >
70
+ > - ex: selecting toppings for a pizza
71
+ > - A form can use switch components in certain cases, but they should not generally be grouped.
72
+ > - Use a Form Control with checkboxes or radio buttons instead.
73
+
74
+ > [!CAUTION]
75
+ >
76
+ > **To allow the user to choose between two options that are not binary**
77
+ >
78
+ > - ex: choosing between a business or personal account for a payment
79
+ > - Use a Form Control with radio buttons instead.
80
+
81
+ - **Do:** Use switches for settings that have a clear on and off state.
82
+ - **Don't:** Don’t use switches to select options from a list in a form.
83
+ - **Don't:** Don’t use a switch for options that are not a clear on/off or yes/no binary.
84
+
85
+ ### Switch vs checkbox
86
+
87
+ At first glance, switches and checkboxes appear like they can be used interchangeably. However, the key difference is that toggling a switch should save or take effect immediately, while a checkbox should not take effect until a button is clicked (ex: the **Submit** button on a form).
88
+
89
+ | \*\* \*\* | **Switch** | **Checkbox** |
90
+ | ------------- | ------------------------------------------------------ | ------------------------------------ |
91
+ | **Behavior** | Takes effect immediately | Takes effect after clicking a button |
92
+ | **Use cases** | Settings, preferences | Forms, surveys, terms and conditions |
93
+ | **Platform** | Common on mobile and tablet, especially in native apps | Common on both web and mobile |
94
+
95
+ ### **Labels**
96
+
97
+ A switch should always have a label. The most common method is to use the switch in a List Item component. The list item label also serves as the switch label. This is a common pattern in settings menus found on mobile devices.
98
+
99
+ _usage\_labels\_01-ex_
100
+
101
+ - **Do:** Keep the label positioned at the end.
102
+ - **Caution:** Avoid other label placements unless absolutely necessary.
103
+
104
+ ### **Layout and placement**
105
+
106
+ The layout and placement of switches depends on the context and the device type.
107
+
108
+ #### **Forms**
109
+
110
+ In forms, checkboxes and radio buttons are usually preferred over switches.
111
+
112
+ - **Do:** Use checkboxes when people can choose none, some, or many options in a list. Selections are submitted with the form, not applied immediately.
113
+ - **Don't:** Don’t use toggles for multi-select lists. Toggles read as instant on/off settings, not optional add-ons.
114
+
115
+ #### **Settings**
116
+
117
+ In settings screens and menus, the switch is more commonly placed after the label. Users expect this layout on mobile devices, so using this layout is encouraged when designing for responsive web as well.
118
+
119
+ - **Do:** People scan labels first, then flip the control where they expect it in a list.
120
+ - **Don't:** Don’t put the switch on the left with the label trailing on the right. It breaks the usual settings pattern and makes the control harder to find and tap.
121
+
122
+ ---
123
+
124
+ ## Behavior
125
+
126
+ ### Toggle states
127
+
128
+ Due to their binary nature, switches have two toggle states:
129
+
130
+ - **isChecked: false (default)**
131
+
132
+ This state indicates that the current value of the switch represents off, no, false, disabled, etc.
133
+ - **isChecked: true**
134
+
135
+ This state indicates that the current value of the switch represents on, yes, true, enabled, etc.
136
+
137
+ ### Interaction states
138
+
139
+ The default state of an switch is clickable. The appearance of the switch will respond as the user interacts with it.
140
+
141
+ - **Interaction State: resting**
142
+
143
+ The user can interact with the switch in this state.
144
+ - **Interaction State: hover**
145
+
146
+ The user is currently hovering over the switch.
147
+ - **Interaction State: focus**
148
+
149
+ The user is currently focusing on the switch using keyboard navigation.
150
+
151
+ ### Disabled
152
+
153
+ Switches can be disabled, which prevents the user from clicking on or interacting with it. Note that disabled switches can appear as checked or unchecked, so this state is often used to show read only switches.
154
+
155
+ - **isDisabled: true**
156
+
157
+ The user cannot interact with the switch in this state.
158
+
159
+ ### Dynamic label text
160
+
161
+ The label text should describe what the control will do when the switch is on (checked). The label should not change based on the current state of the switch. For more details about writing label text, see the Content tab.
162
+
163
+ ## Content
164
+
165
+ As mentioned previously, a switch should always be clearly labeled. Consider the following guidelines when writing labels for switches.
166
+
167
+ ## Phrasing
168
+
169
+ The label text should describe what the control will do when the switch is on (checked); it should not be neutral or ambiguous. When in doubt, say the label aloud and append “on” or “off” to the end. If it doesn’t make sense, rewrite the label.
170
+
171
+ - **Do:** In this example, the label describes that airplane mode will be on when the switch is on.
172
+ - **Don't:** Don’t start the label with a verb. In this example, “enable airplane mode is off” will confuse users.
173
+ - **Don't:** Don’t change the text of the label based on the state of the switch. Dynamic label text will not meet accessibility guidelines.
174
+
175
+ ## Punctuation
176
+
177
+ Never end a label with punctuation, even if the label is technically a complete sentence.
178
+
179
+ - **Do:** Use short, informative labels without punctuation.
180
+ - **Don't:** Don’t use end punctuation, including question marks.
181
+
182
+ For additional guidance on creating groups of radio buttons, please see the Form Control page. This page includes information about writing the group label, writing and organizing the options, and writing helper text.
183
+
184
+ ## **Opt-in vs. opt-out**
185
+
186
+ Opt-in and opt-out are two different approaches to gaining consent or permission from a user. Checkboxes and switches are commonly used for these actions. It’s important to know the differences between the two approaches in order to design a user-centered experience.
187
+
188
+ ### **Opt-in**
189
+
190
+ By default, the user **has not** given permission. The user must actively choose to **give** permission. This approach is generally considered more privacy-friendly.
191
+
192
+ Common examples:
193
+
194
+ - A user is asked if they agree to the terms and conditions before they complete their registration.
195
+ - A user is asked if they would like to subscribe to a newsletter before they complete their registration.
196
+
197
+ ### **Opt-out**
198
+
199
+ By the default, the user **has** given consent or permission. The user must actively choose to **revoke or withdraw** permission. This approach is generally considered less privacy-friendly.
200
+
201
+ Common examples:
202
+
203
+ - A user visits a website, and the website considers their use of the website an implicit agreement to the terms and conditions.
204
+ - A user completes their registration, and is then automatically subscribed to that website’s newsletter. They must manually take action to unsubscribe.
205
+
206
+ ### **Further reading**
207
+
208
+ For further reading about opt-in vs. opt-out, check out [this blog post](https://www.cookieyes.com/blog/opt-in-opt-out/).