@mrpelz/uikit-ish 7.8.0 → 7.10.0

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 (308) hide show
  1. package/dist/components/accordion/main.d.ts +12 -0
  2. package/dist/components/accordion/main.d.ts.map +1 -0
  3. package/dist/components/accordion/main.js +20 -0
  4. package/dist/components/accordion/main.js.map +1 -0
  5. package/dist/components/accordion/style.css +23 -0
  6. package/dist/components/action-sheet/main.d.ts +22 -16
  7. package/dist/components/action-sheet/main.d.ts.map +1 -1
  8. package/dist/components/action-sheet/main.js +89 -19
  9. package/dist/components/action-sheet/main.js.map +1 -1
  10. package/dist/components/action-sheet/props.d.ts +17 -5
  11. package/dist/components/action-sheet/props.d.ts.map +1 -1
  12. package/dist/components/action-sheet/style.css +24 -0
  13. package/dist/components/activity-view/main.d.ts +15 -4
  14. package/dist/components/activity-view/main.d.ts.map +1 -1
  15. package/dist/components/activity-view/main.js +27 -14
  16. package/dist/components/activity-view/main.js.map +1 -1
  17. package/dist/components/activity-view/props.d.ts +2 -10
  18. package/dist/components/activity-view/props.d.ts.map +1 -1
  19. package/dist/components/activity-view/style.css +29 -67
  20. package/dist/components/alert/main.d.ts +8 -7
  21. package/dist/components/alert/main.d.ts.map +1 -1
  22. package/dist/components/alert/main.js +32 -19
  23. package/dist/components/alert/main.js.map +1 -1
  24. package/dist/components/alert/props.d.ts +13 -2
  25. package/dist/components/alert/props.d.ts.map +1 -1
  26. package/dist/components/alert/style.css +36 -50
  27. package/dist/components/avatar/main.d.ts +5 -3
  28. package/dist/components/avatar/main.d.ts.map +1 -1
  29. package/dist/components/avatar/main.js +10 -8
  30. package/dist/components/avatar/main.js.map +1 -1
  31. package/dist/components/avatar/props.d.ts +4 -0
  32. package/dist/components/avatar/props.d.ts.map +1 -1
  33. package/dist/components/avatar/style.css +1 -7
  34. package/dist/components/badge/main.d.ts +3 -3
  35. package/dist/components/badge/main.d.ts.map +1 -1
  36. package/dist/components/badge/main.js +9 -9
  37. package/dist/components/badge/main.js.map +1 -1
  38. package/dist/components/badge/props.d.ts +4 -3
  39. package/dist/components/badge/props.d.ts.map +1 -1
  40. package/dist/components/badge/style.css +10 -4
  41. package/dist/components/button/main.d.ts.map +1 -1
  42. package/dist/components/button/main.js +15 -15
  43. package/dist/components/button/main.js.map +1 -1
  44. package/dist/components/button/props.d.ts +8 -8
  45. package/dist/components/button/props.d.ts.map +1 -1
  46. package/dist/components/button/style.css +37 -55
  47. package/dist/components/checkbox/main.d.ts.map +1 -1
  48. package/dist/components/checkbox/main.js +5 -7
  49. package/dist/components/checkbox/main.js.map +1 -1
  50. package/dist/components/checkbox/style.css +5 -8
  51. package/dist/components/collapsible/main.d.ts +9 -0
  52. package/dist/components/collapsible/main.d.ts.map +1 -0
  53. package/dist/components/collapsible/main.js +19 -0
  54. package/dist/components/collapsible/main.js.map +1 -0
  55. package/dist/components/collapsible/style.css +23 -0
  56. package/dist/components/color-picker/main.d.ts +27 -4
  57. package/dist/components/color-picker/main.d.ts.map +1 -1
  58. package/dist/components/color-picker/main.js +292 -110
  59. package/dist/components/color-picker/main.js.map +1 -1
  60. package/dist/components/color-picker/props.d.ts +64 -15
  61. package/dist/components/color-picker/props.d.ts.map +1 -1
  62. package/dist/components/color-picker/style.css +133 -65
  63. package/dist/components/contextual-menu/main.d.ts +11 -7
  64. package/dist/components/contextual-menu/main.d.ts.map +1 -1
  65. package/dist/components/contextual-menu/main.js +207 -202
  66. package/dist/components/contextual-menu/main.js.map +1 -1
  67. package/dist/components/contextual-menu/props.d.ts +21 -34
  68. package/dist/components/contextual-menu/props.d.ts.map +1 -1
  69. package/dist/components/contextual-menu/style.css +63 -34
  70. package/dist/components/date-picker/handle.d.ts +41 -0
  71. package/dist/components/date-picker/handle.d.ts.map +1 -0
  72. package/dist/components/date-picker/handle.js +47 -0
  73. package/dist/components/date-picker/handle.js.map +1 -0
  74. package/dist/components/date-picker/main.d.ts +31 -49
  75. package/dist/components/date-picker/main.d.ts.map +1 -1
  76. package/dist/components/date-picker/main.js +373 -178
  77. package/dist/components/date-picker/main.js.map +1 -1
  78. package/dist/components/date-picker/pager.d.ts +24 -0
  79. package/dist/components/date-picker/pager.d.ts.map +1 -0
  80. package/dist/components/date-picker/pager.js +307 -0
  81. package/dist/components/date-picker/pager.js.map +1 -0
  82. package/dist/components/date-picker/props.d.ts +98 -27
  83. package/dist/components/date-picker/props.d.ts.map +1 -1
  84. package/dist/components/date-picker/style.css +110 -118
  85. package/dist/components/drawer/main.d.ts +31 -0
  86. package/dist/components/drawer/main.d.ts.map +1 -0
  87. package/dist/components/drawer/main.js +119 -0
  88. package/dist/components/drawer/main.js.map +1 -0
  89. package/dist/components/drawer/props.d.ts +39 -0
  90. package/dist/components/drawer/props.d.ts.map +1 -0
  91. package/dist/components/drawer/props.js +2 -0
  92. package/dist/components/drawer/props.js.map +1 -0
  93. package/dist/components/drawer/style.css +135 -0
  94. package/dist/components/edit-menu/main.d.ts +7 -7
  95. package/dist/components/edit-menu/main.d.ts.map +1 -1
  96. package/dist/components/edit-menu/main.js +57 -40
  97. package/dist/components/edit-menu/main.js.map +1 -1
  98. package/dist/components/edit-menu/props.d.ts +14 -1
  99. package/dist/components/edit-menu/props.d.ts.map +1 -1
  100. package/dist/components/edit-menu/style.css +15 -8
  101. package/dist/components/form/main.d.ts +8 -0
  102. package/dist/components/form/main.d.ts.map +1 -1
  103. package/dist/components/form/main.js +18 -5
  104. package/dist/components/form/main.js.map +1 -1
  105. package/dist/components/form/props.d.ts +1 -2
  106. package/dist/components/form/props.d.ts.map +1 -1
  107. package/dist/components/glass/main.d.ts +1 -1
  108. package/dist/components/glass/main.js +4 -4
  109. package/dist/components/glass/main.js.map +1 -1
  110. package/dist/components/glass/props.d.ts +5 -5
  111. package/dist/components/glass/props.d.ts.map +1 -1
  112. package/dist/components/glass/style.css +176 -161
  113. package/dist/components/header/main.d.ts +5 -4
  114. package/dist/components/header/main.d.ts.map +1 -1
  115. package/dist/components/header/main.js +64 -34
  116. package/dist/components/header/main.js.map +1 -1
  117. package/dist/components/header/props.d.ts +2 -3
  118. package/dist/components/header/props.d.ts.map +1 -1
  119. package/dist/components/header/style.css +46 -65
  120. package/dist/components/index.d.ts +27 -23
  121. package/dist/components/index.d.ts.map +1 -1
  122. package/dist/components/index.js +17 -13
  123. package/dist/components/index.js.map +1 -1
  124. package/dist/components/layout/main.d.ts +2 -2
  125. package/dist/components/layout/main.d.ts.map +1 -1
  126. package/dist/components/layout/main.js +63 -167
  127. package/dist/components/layout/main.js.map +1 -1
  128. package/dist/components/layout/props.d.ts +2 -20
  129. package/dist/components/layout/props.d.ts.map +1 -1
  130. package/dist/components/layout/style.css +20 -91
  131. package/dist/components/list/main.d.ts +58 -10
  132. package/dist/components/list/main.d.ts.map +1 -1
  133. package/dist/components/list/main.js +1022 -465
  134. package/dist/components/list/main.js.map +1 -1
  135. package/dist/components/list/props.d.ts +211 -21
  136. package/dist/components/list/props.d.ts.map +1 -1
  137. package/dist/components/list/reorder.d.ts +146 -0
  138. package/dist/components/list/reorder.d.ts.map +1 -0
  139. package/dist/components/list/reorder.js +819 -0
  140. package/dist/components/list/reorder.js.map +1 -0
  141. package/dist/components/list/select.d.ts +6 -0
  142. package/dist/components/list/select.d.ts.map +1 -0
  143. package/dist/components/list/select.js +141 -0
  144. package/dist/components/list/select.js.map +1 -0
  145. package/dist/components/list/style.css +492 -507
  146. package/dist/components/list/swipe-actions-handle.d.ts +40 -0
  147. package/dist/components/list/swipe-actions-handle.d.ts.map +1 -0
  148. package/dist/components/list/swipe-actions-handle.js +51 -0
  149. package/dist/components/list/swipe-actions-handle.js.map +1 -0
  150. package/dist/components/menu/main.d.ts +102 -32
  151. package/dist/components/menu/main.d.ts.map +1 -1
  152. package/dist/components/menu/main.js +510 -99
  153. package/dist/components/menu/main.js.map +1 -1
  154. package/dist/components/menu/props.d.ts +5 -5
  155. package/dist/components/menu/props.d.ts.map +1 -1
  156. package/dist/components/menu/style.css +35 -43
  157. package/dist/components/navigation/main.d.ts +14 -2
  158. package/dist/components/navigation/main.d.ts.map +1 -1
  159. package/dist/components/navigation/main.js +437 -119
  160. package/dist/components/navigation/main.js.map +1 -1
  161. package/dist/components/navigation/props.d.ts +53 -3
  162. package/dist/components/navigation/props.d.ts.map +1 -1
  163. package/dist/components/navigation/style.css +56 -9
  164. package/dist/components/page/main.d.ts.map +1 -1
  165. package/dist/components/page/main.js +13 -8
  166. package/dist/components/page/main.js.map +1 -1
  167. package/dist/components/page/props.d.ts +8 -0
  168. package/dist/components/page/props.d.ts.map +1 -1
  169. package/dist/components/page/style.css +39 -4
  170. package/dist/components/page-control/main.d.ts +2 -2
  171. package/dist/components/page-control/main.d.ts.map +1 -1
  172. package/dist/components/page-control/main.js +66 -32
  173. package/dist/components/page-control/main.js.map +1 -1
  174. package/dist/components/page-control/props.d.ts +10 -2
  175. package/dist/components/page-control/props.d.ts.map +1 -1
  176. package/dist/components/page-control/style.css +7 -2
  177. package/dist/components/popover/main.d.ts +11 -6
  178. package/dist/components/popover/main.d.ts.map +1 -1
  179. package/dist/components/popover/main.js +63 -38
  180. package/dist/components/popover/main.js.map +1 -1
  181. package/dist/components/popover/props.d.ts +7 -6
  182. package/dist/components/popover/props.d.ts.map +1 -1
  183. package/dist/components/popover/style.css +54 -4
  184. package/dist/components/progress/main.d.ts +2 -3
  185. package/dist/components/progress/main.d.ts.map +1 -1
  186. package/dist/components/progress/main.js +148 -29
  187. package/dist/components/progress/main.js.map +1 -1
  188. package/dist/components/progress/props.d.ts +43 -9
  189. package/dist/components/progress/props.d.ts.map +1 -1
  190. package/dist/components/progress/style.css +82 -50
  191. package/dist/components/roll/main.d.ts +1 -1
  192. package/dist/components/roll/main.d.ts.map +1 -1
  193. package/dist/components/roll/main.js +90 -34
  194. package/dist/components/roll/main.js.map +1 -1
  195. package/dist/components/roll/props.d.ts +25 -8
  196. package/dist/components/roll/props.d.ts.map +1 -1
  197. package/dist/components/roll/style.css +12 -24
  198. package/dist/components/segmented/main.d.ts.map +1 -1
  199. package/dist/components/segmented/main.js +47 -30
  200. package/dist/components/segmented/main.js.map +1 -1
  201. package/dist/components/segmented/style.css +16 -23
  202. package/dist/components/sheet/main.d.ts +25 -15
  203. package/dist/components/sheet/main.d.ts.map +1 -1
  204. package/dist/components/sheet/main.js +66 -78
  205. package/dist/components/sheet/main.js.map +1 -1
  206. package/dist/components/sheet/props.d.ts +37 -3
  207. package/dist/components/sheet/props.d.ts.map +1 -1
  208. package/dist/components/sheet/style.css +183 -45
  209. package/dist/components/sidebar/main.d.ts.map +1 -1
  210. package/dist/components/sidebar/main.js +9 -13
  211. package/dist/components/sidebar/main.js.map +1 -1
  212. package/dist/components/sidebar/style.css +20 -14
  213. package/dist/components/slider/main.d.ts.map +1 -1
  214. package/dist/components/slider/main.js +23 -22
  215. package/dist/components/slider/main.js.map +1 -1
  216. package/dist/components/slider/props.d.ts +1 -2
  217. package/dist/components/slider/props.d.ts.map +1 -1
  218. package/dist/components/slider/style.css +27 -53
  219. package/dist/components/stepper/main.d.ts +4 -6
  220. package/dist/components/stepper/main.d.ts.map +1 -1
  221. package/dist/components/stepper/main.js +29 -25
  222. package/dist/components/stepper/main.js.map +1 -1
  223. package/dist/components/stepper/style.css +12 -16
  224. package/dist/components/switch/main.d.ts.map +1 -1
  225. package/dist/components/switch/main.js +40 -28
  226. package/dist/components/switch/main.js.map +1 -1
  227. package/dist/components/switch/props.d.ts +7 -5
  228. package/dist/components/switch/props.d.ts.map +1 -1
  229. package/dist/components/switch/style.css +40 -17
  230. package/dist/components/symbol/main.d.ts +2 -2
  231. package/dist/components/symbol/main.d.ts.map +1 -1
  232. package/dist/components/symbol/main.js +36 -28
  233. package/dist/components/symbol/main.js.map +1 -1
  234. package/dist/components/symbol/props.d.ts +39 -4
  235. package/dist/components/symbol/props.d.ts.map +1 -1
  236. package/dist/components/symbol/style.css +26 -5
  237. package/dist/components/tab-bar/main.d.ts +2 -2
  238. package/dist/components/tab-bar/main.d.ts.map +1 -1
  239. package/dist/components/tab-bar/main.js +133 -101
  240. package/dist/components/tab-bar/main.js.map +1 -1
  241. package/dist/components/tab-bar/props.d.ts +6 -6
  242. package/dist/components/tab-bar/props.d.ts.map +1 -1
  243. package/dist/components/tab-bar/style.css +113 -99
  244. package/dist/components/text-field/main.d.ts +3 -2
  245. package/dist/components/text-field/main.d.ts.map +1 -1
  246. package/dist/components/text-field/main.js +29 -30
  247. package/dist/components/text-field/main.js.map +1 -1
  248. package/dist/components/text-field/props.d.ts +23 -1
  249. package/dist/components/text-field/props.d.ts.map +1 -1
  250. package/dist/components/text-field/style.css +122 -82
  251. package/dist/components/toolbar/main.js +27 -27
  252. package/dist/components/toolbar/main.js.map +1 -1
  253. package/dist/components/toolbar/props.d.ts +10 -4
  254. package/dist/components/toolbar/props.d.ts.map +1 -1
  255. package/dist/components/toolbar/style.css +39 -33
  256. package/dist/components/tooltip/main.d.ts +10 -9
  257. package/dist/components/tooltip/main.d.ts.map +1 -1
  258. package/dist/components/tooltip/main.js +39 -10
  259. package/dist/components/tooltip/main.js.map +1 -1
  260. package/dist/components/tooltip/props.d.ts +2 -0
  261. package/dist/components/tooltip/props.d.ts.map +1 -1
  262. package/dist/components/tooltip/style.css +16 -16
  263. package/dist/components/typography/main.d.ts +2 -2
  264. package/dist/components/typography/main.d.ts.map +1 -1
  265. package/dist/components/typography/main.js +24 -16
  266. package/dist/components/typography/main.js.map +1 -1
  267. package/dist/components/typography/props.d.ts +11 -18
  268. package/dist/components/typography/props.d.ts.map +1 -1
  269. package/dist/components/typography/style.css +503 -623
  270. package/dist/components/utils/main.d.ts +78 -8
  271. package/dist/components/utils/main.d.ts.map +1 -1
  272. package/dist/components/utils/main.js +235 -16
  273. package/dist/components/utils/main.js.map +1 -1
  274. package/dist/components/utils/props.d.ts +27 -4
  275. package/dist/components/utils/props.d.ts.map +1 -1
  276. package/dist/components/utils/style.css +31 -18
  277. package/dist/components/viewport/edge-effect.d.ts +10 -0
  278. package/dist/components/viewport/edge-effect.d.ts.map +1 -0
  279. package/dist/components/viewport/edge-effect.js +100 -0
  280. package/dist/components/viewport/edge-effect.js.map +1 -0
  281. package/dist/components/viewport/edge.d.ts +39 -0
  282. package/dist/components/viewport/edge.d.ts.map +1 -0
  283. package/dist/components/viewport/edge.js +151 -0
  284. package/dist/components/viewport/edge.js.map +1 -0
  285. package/dist/components/viewport/input.d.ts +39 -0
  286. package/dist/components/viewport/input.d.ts.map +1 -0
  287. package/dist/components/viewport/input.js +280 -0
  288. package/dist/components/viewport/input.js.map +1 -0
  289. package/dist/components/viewport/main.d.ts +47 -9
  290. package/dist/components/viewport/main.d.ts.map +1 -1
  291. package/dist/components/viewport/main.js +745 -86
  292. package/dist/components/viewport/main.js.map +1 -1
  293. package/dist/components/viewport/padding.d.ts +78 -0
  294. package/dist/components/viewport/padding.d.ts.map +1 -0
  295. package/dist/components/viewport/padding.js +321 -0
  296. package/dist/components/viewport/padding.js.map +1 -0
  297. package/dist/components/viewport/props.d.ts +220 -11
  298. package/dist/components/viewport/props.d.ts.map +1 -1
  299. package/dist/components/viewport/style.css +377 -6
  300. package/dist/main.d.ts +0 -1
  301. package/dist/main.d.ts.map +1 -1
  302. package/dist/main.js.map +1 -1
  303. package/dist/styles.css +318 -302
  304. package/dist/styles.d.ts +2 -1
  305. package/dist/styles.d.ts.map +1 -1
  306. package/dist/styles.js +2 -1
  307. package/dist/styles.js.map +1 -1
  308. package/package.json +8 -16
@@ -1,40 +1,42 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import '../button/style.css';
3
3
  import '../menu/style.css';
4
4
  import '../page-control/style.css';
5
5
  import '../segmented/style.css';
6
- import '../slider/style.css';
7
6
  import './style.css';
8
7
  import { Slider as BaseSlider } from '@base-ui/react/slider';
9
- import { cloneElement, createContext, forwardRef, useContext, useLayoutEffect, useMemo, useRef, useState, } from 'react';
8
+ import { cloneElement, createContext, forwardRef, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState, } from 'react';
10
9
  import { Button } from '../button/main.js';
11
10
  import { Menu } from '../menu/main.js';
12
11
  import { PageControl } from '../page-control/main.js';
13
12
  import { Segmented } from '../segmented/main.js';
14
- import { Slider } from '../slider/main.js';
15
- import { cn, withStyle } from '../utils/main.js';
16
- // Source: Apple iOS 26 Figma (“Color Pickers”, UIKit
17
- // `UIColorPickerViewController`, `UIColorWell`), in the app's popover
18
- // (iPad) or sheet (iPhone), its header the app's (a `Toolbar`: the
13
+ import { cn, useTouchHold, withStyle } from '../utils/main.js';
14
+ import { Viewport } from '../viewport/main.js';
15
+ // A color picker and a color well, in the app's popover (a regular width)
16
+ // or sheet (compact), its header the app's (a `Toolbar`: the
19
17
  // eyedropper, “Colors”, close):
20
18
  // - a segmented control (Grid, Spectrum, Sliders), 24px above the view;
21
19
  // - Grid: 12 by 10 swatches (a gray row, then hues by lightness), its
22
20
  // corners 18px, the selected one outlined white (3px);
23
21
  // - Spectrum: hues across, light to dark down (white at the top, pure hues
24
22
  // halfway, black at the bottom), its corners 18px, the color ringed;
25
- // - Sliders: red, green and blue (`Slider`s, 0 to 255);
26
- // - Opacity (15px, semibold), a slider (40px high, a checkerboard under the
27
- // color fading in, its knob 36px, in the color, ringed white, 3px) and its
28
- // percentage (a 75px by 40px field on the system fill, 8px corners, Body
29
- // emphasized);
23
+ // - Sliders: red, green and blue (0 to 255), each a channel's row (see
24
+ // `ChannelRow`): its title (all caps), a slider mixing from the color
25
+ // (the channel at 0 to 255), and its value, typed;
26
+ // - Each channel's row kept above the keyboard as its field's typed into
27
+ // (a `Viewport.KeyboardAccessory`; in a `Viewport.Provider`);
28
+ // - Opacity (optional: its part, `Opacity`), a channel's row too: the
29
+ // color fading in over a checkerboard, its knob the color (translucent),
30
+ // its value a percentage;
30
31
  // - the color (82px, 18px corners) beside the saved colors (30px dots, 25px
31
32
  // apart, rows 22px apart; the color's ringed white, 2px, 4px in) and an
32
33
  // add button (on the system fill, its “+” the label's color).
33
34
  // A color well (`ColorPicker.Well`): a 28px (or 36px) disk of hues around
34
35
  // white; with a color, the hues as a ring around it.
35
36
  //
36
- // Deviations:
37
- // - Colors are hex strings (`#rrggbb`, `#rrggbbaa` with opacity).
37
+ // Also:
38
+ // - Colors are hex strings (`#rrggbb`, `#rrggbbaa` with opacity; without
39
+ // opacity, always opaque).
38
40
  // - The eyedropper (`ColorPicker.Eyedropper`) is the browser's
39
41
  // (`EyeDropper`; not where it has none, e.g. Safari).
40
42
  // - Saved colors are deleted by their menu (a secondary click: right click,
@@ -62,7 +64,6 @@ const toHex = (value) => Math.round(clamp(value, 0, 255))
62
64
  /** Channels as a hex color (#rrggbb, or #rrggbbaa if not opaque). */
63
65
  export const formatColor = ({ a, b, g, r }) => `#${toHex(r)}${toHex(g)}${toHex(b)}${a < 1 ? toHex(a * 255) : ''}`.toUpperCase();
64
66
  // HSL (hue 0–360, saturation and lightness 0–1), for the spectrum.
65
- // eslint-disable-next-line unicorn/no-unnecessary-parameters
66
67
  const fromHsl = (h, s, l) => {
67
68
  const k = (n) => (n + h / 30) % 12;
68
69
  const amount = s * Math.min(l, 1 - l);
@@ -87,7 +88,7 @@ const toHsl = ({ b, g, r }) => {
87
88
  h = (red - green) / d + 4;
88
89
  return { h: (h * 60 + 360) % 360, l, s };
89
90
  };
90
- /** Figma's grid: a gray row, then hues by lightness. */
91
+ /** The grid: a gray row, then hues by lightness. */
91
92
  const grid = [
92
93
  '#FEFFFE #EBEBEB #D6D6D6 #C2C2C2 #ADADAD #999999 #858585 #707070 #5C5C5C #474747 #333333 #000000',
93
94
  '#00374A #011D57 #11053B #2E063D #3C071B #5C0701 #5A1C00 #583300 #563D00 #666100 #4F5504 #263E0F',
@@ -100,7 +101,7 @@ const grid = [
100
101
  '#93E3FC #A7C6FF #B18CFE #E292FE #F4A4C0 #FFB5AF #FFC5AB #FED9A8 #FDE4A8 #FFFBB9 #F1F7B7 #CDE8B5',
101
102
  '#CBF0FF #D2E2FE #D8C9FE #EFCAFE #F9D3E0 #FFDAD8 #FFE2D6 #FEECD4 #FEF1D5 #FDFBDD #F6FADB #DEEED4',
102
103
  ].map((row) => row.split(' '));
103
- /** Figma's saved colors. */
104
+ /** The default saved colors. */
104
105
  export const defaultSavedColors = [
105
106
  '#000000',
106
107
  '#007AFF',
@@ -115,55 +116,136 @@ export const defaultSavedColors = [
115
116
  const sameColor = (a, b) => Math.round(a.r) === Math.round(b.r) &&
116
117
  Math.round(a.g) === Math.round(b.g) &&
117
118
  Math.round(a.b) === Math.round(b.b);
119
+ const unregister = () => undefined;
118
120
  const PickerContext = createContext({
119
121
  color: { a: 1, b: 0, g: 0, r: 0 },
122
+ registerOpacity: () => unregister,
120
123
  setColor: () => undefined,
121
124
  });
122
125
  /**
123
- * A color picker (UIKit `UIColorPickerViewController`): its color, for its
126
+ * A color picker: its color, for its
124
127
  * parts (`Panel`, `Eyedropper`), in the app's popover or sheet.
125
128
  */
126
- const Root = forwardRef(({ className, defaultValue = '#000000', onValueChange, value, ...props }, ref) => {
129
+ const Root = forwardRef(({ className, defaultValue = '#000000', onValueChange, style, value, ...props }, ref) => {
127
130
  const [own, setOwn] = useState(defaultValue);
128
- const color = parseColor(value ?? own);
131
+ // Its `Opacity`s rendered: without one, the color opaque (its alpha,
132
+ // if given one, dropped).
133
+ const [opacities, setOpacities] = useState(0);
134
+ const hasOpacity = opacities > 0;
135
+ const parsed = parseColor(value ?? own);
136
+ const color = hasOpacity ? parsed : { ...parsed, a: 1 };
137
+ const registerOpacity = useCallback(() => {
138
+ setOpacities((count) => count + 1);
139
+ return () => setOpacities((count) => count - 1);
140
+ }, []);
129
141
  const state = useMemo(() => ({
130
142
  color,
131
- setColor: (next) => {
132
- const hex = formatColor(next);
133
- setOwn(hex);
134
- onValueChange?.(hex);
143
+ registerOpacity,
144
+ // Uncontrolled: its own state; controlled, only the app's `value`.
145
+ setColor: (next, details) => {
146
+ const hex = formatColor(hasOpacity ? next : { ...next, a: 1 });
147
+ if (value === undefined)
148
+ setOwn(hex);
149
+ onValueChange?.(hex, details);
135
150
  },
136
151
  }),
137
152
  // (By its hex value.)
138
153
  // eslint-disable-next-line react-hooks/exhaustive-deps
139
- [value ?? own, onValueChange]);
140
- return (_jsx(PickerContext.Provider, { value: state, children: _jsx("div", { ref: ref, ...props, className: cn('uikit-color-picker-root', className), "data-color-picker-part": "root" }) }));
154
+ [value ?? own, onValueChange, hasOpacity]);
155
+ return (_jsx(PickerContext.Provider, { value: state, children: _jsx("div", { ref: ref, style: withStyle({
156
+ // (For its parts.)
157
+ '--uikit-color-picker-color': formatColor(color),
158
+ '--uikit-color-picker-color-opaque': formatColor({
159
+ ...color,
160
+ a: 1,
161
+ }),
162
+ }, style), ...props, className: cn('uikit-color-picker-root', className), "data-color-picker-part": "root" }) }));
163
+ });
164
+ /**
165
+ * Its panel's modes (see `Panel`): the one shown, chosen by its `Modes`;
166
+ * the first `Mode` (or `View`) unless a default is given.
167
+ */
168
+ const PanelContext = createContext({
169
+ mode: null,
170
+ registerMode: () => undefined,
171
+ setMode: () => undefined,
172
+ });
173
+ /**
174
+ * Its panel: its modes (`Modes`, a `Mode` each; a `View` each, paired by
175
+ * their `value`s), the opacity, the color and the saved colors, as
176
+ * composed (in its padding, its parts spaced).
177
+ */
178
+ const Panel = forwardRef(({ className, defaultMode, mode: modeProp, onModeChange, ...props }, ref) => {
179
+ const [ownMode, setOwnMode] = useState(defaultMode);
180
+ // (Without a default: the first mode, as it's rendered.)
181
+ const [firstMode, setFirstMode] = useState();
182
+ // (Controlled from the start: none yet, before its first mode is
183
+ // known, not undefined, which would leave its control uncontrolled.)
184
+ const mode = modeProp ?? ownMode ?? firstMode ?? null;
185
+ const panel = useMemo(() => ({
186
+ mode,
187
+ registerMode: (value) => setFirstMode((first) => first ?? value),
188
+ // Uncontrolled: its own state; controlled, only the app's `mode`.
189
+ setMode: (next, details) => {
190
+ if (modeProp === undefined)
191
+ setOwnMode(next);
192
+ onModeChange?.(next, details);
193
+ },
194
+ }), [mode, modeProp, onModeChange]);
195
+ return (_jsx(PanelContext.Provider, { value: panel, children: _jsx("div", { ref: ref, ...props, className: cn('uikit-color-picker-panel', className), "data-color-picker-part": "panel" }) }));
196
+ });
197
+ /**
198
+ * Its modes' control: a segmented control (its `Mode`s, its highlight),
199
+ * choosing the `View` shown; 24px above it.
200
+ */
201
+ const Modes = forwardRef(({ children, ...props }, ref) => {
202
+ const { mode, setMode } = useContext(PanelContext);
203
+ return (_jsxs(Segmented.Root, { ref: ref, "aria-label": "Mode", ...props, value: mode, onValueChange: (next, details) => setMode(String(next), details), children: [children, _jsx(Segmented.Highlight, {})] }));
204
+ });
205
+ /** A mode, in its `Modes`: its label, choosing its `View` (by `value`). */
206
+ const Mode = forwardRef(({ value, ...props }, ref) => {
207
+ const { registerMode } = useContext(PanelContext);
208
+ useLayoutEffect(() => registerMode(value), [registerMode, value]);
209
+ return (_jsx(Segmented.Item, { ref: ref, value: value, ...props }));
141
210
  });
142
- const Grid = () => {
211
+ /**
212
+ * A mode's view (by `value`, its `Mode`'s): shown while it's chosen; all
213
+ * as high as the grid (so a popover doesn't move as they're switched).
214
+ */
215
+ const View = forwardRef(({ className, value, ...props }, ref) => {
216
+ const { mode, registerMode } = useContext(PanelContext);
217
+ // (A mode, too: without `Modes`, its only view shown.)
218
+ useLayoutEffect(() => registerMode(value), [registerMode, value]);
219
+ if (mode !== value)
220
+ return null;
221
+ return (_jsx("div", { ref: ref, "data-color-picker-view": value, ...props, className: cn('uikit-color-picker-view', className), "data-color-picker-part": "view" }));
222
+ });
223
+ /** Swatches in rows (a gray row, then hues by lightness), its corners 18px. */
224
+ const Grid = forwardRef(({ className, ...props }, ref) => {
143
225
  const { color, setColor } = useContext(PickerContext);
144
- return (_jsx("div", { "aria-label": "Grid", className: "uikit-color-picker-grid", "data-color-picker-part": "grid", role: "group", children: grid.flatMap((row) => row.map((hex) => {
226
+ return (_jsx("div", { ref: ref, "aria-label": "Grid", role: "group", ...props, className: cn('uikit-color-picker-grid', className), "data-color-picker-part": "grid", children: grid.flatMap((row) => row.map((hex) => {
145
227
  const swatch = parseColor(hex);
146
- return (_jsx("button", { "aria-label": hex, "aria-pressed": sameColor(swatch, color), style: { backgroundColor: hex }, type: "button", onClick: () => setColor({ ...swatch, a: color.a }) }, hex));
228
+ return (_jsx("button", { "aria-label": hex, "aria-pressed": sameColor(swatch, color), style: { backgroundColor: hex }, type: "button", onClick: (event) => setColor({ ...swatch, a: color.a }, { event, reason: 'grid' }) }, hex));
147
229
  })) }));
148
- };
149
- const Spectrum = () => {
230
+ });
231
+ /** Hues across, white to black down, the color ringed; its corners 18px. */
232
+ const Spectrum = forwardRef(({ className, ...props }, ref) => {
150
233
  const { color, setColor } = useContext(PickerContext);
151
234
  const { h, l } = toHsl(color);
152
- const pick = (element, x, y) => {
153
- const { height, left, top, width } = element.getBoundingClientRect();
154
- const hue = clamp((x - left) / width, 0, 1) * 360;
155
- const lightness = 1 - clamp((y - top) / height, 0, 1);
156
- setColor({ ...fromHsl(hue % 360, 1, lightness), a: color.a });
235
+ const pick = (event) => {
236
+ const { height, left, top, width } = event.currentTarget.getBoundingClientRect();
237
+ const hue = clamp((event.clientX - left) / width, 0, 1) * 360;
238
+ const lightness = 1 - clamp((event.clientY - top) / height, 0, 1);
239
+ setColor({ ...fromHsl(hue % 360, 1, lightness), a: color.a }, { event, reason: 'spectrum' });
157
240
  };
158
241
  const handlePointerDown = (event) => {
159
- const element = event.currentTarget;
160
- element.setPointerCapture(event.pointerId);
161
- pick(element, event.clientX, event.clientY);
242
+ event.currentTarget.setPointerCapture(event.pointerId);
243
+ pick(event);
162
244
  };
163
245
  const handlePointerMove = (event) => {
164
246
  if (!event.currentTarget.hasPointerCapture(event.pointerId))
165
247
  return;
166
- pick(event.currentTarget, event.clientX, event.clientY);
248
+ pick(event);
167
249
  };
168
250
  // Arrow keys: hue across (5°), lightness down (5%).
169
251
  const handleKeyDown = (event) => {
@@ -180,45 +262,151 @@ const Spectrum = () => {
180
262
  setColor({
181
263
  ...fromHsl((h + move[0] + 360) % 360, 1, clamp(l + move[1], 0, 1)),
182
264
  a: color.a,
183
- });
265
+ }, { event, reason: 'spectrum' });
184
266
  };
185
- return (_jsx("div", { "aria-label": "Spectrum", "aria-valuetext": formatColor({ ...color, a: 1 }), className: "uikit-color-picker-spectrum", "data-color-picker-part": "spectrum", role: "slider", tabIndex: 0, onKeyDown: handleKeyDown, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, children: _jsx("span", { style: {
267
+ return (_jsx("div", { ref: ref, "aria-label": "Spectrum", "aria-valuetext": formatColor({ ...color, a: 1 }), role: "slider", tabIndex: 0, ...props, className: cn('uikit-color-picker-spectrum', className), "data-base-ui-swipe-ignore": "", "data-color-picker-part": "spectrum", onKeyDown: handleKeyDown, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, children: _jsx("span", { style: {
186
268
  backgroundColor: formatColor({ ...color, a: 1 }),
187
269
  left: `${String((h / 360) * 100)}%`,
188
270
  top: `${String((1 - l) * 100)}%`,
189
271
  } }) }));
190
- };
191
- // Each in its color.
192
- const channels = [
193
- ['r', 'Red', 'var(--color-ios-system-red)'],
194
- ['g', 'Green', 'var(--color-ios-system-green)'],
195
- ['b', 'Blue', 'var(--color-ios-system-blue)'],
196
- ];
197
- const Sliders = () => {
198
- const { color, setColor } = useContext(PickerContext);
199
- return (_jsx("div", { className: "uikit-color-picker-sliders", "data-color-picker-part": "sliders", children: channels.map(([channel, label, tint]) => (_jsxs(Slider.Root, { max: 255, min: 0, tint: tint, value: Math.round(color[channel]), onValueChange: (next) => setColor({ ...color, [channel]: next }), children: [_jsx(Slider.Label, { placement: "block-start", children: label }), _jsx(Slider.Value, { placement: "block-start" }), _jsx(Slider.Control, { children: _jsxs(Slider.Track, { children: [_jsx(Slider.Indicator, {}), _jsx(Slider.Thumb, {})] }) })] }, channel))) }));
200
- };
201
- const Opacity = () => {
202
- const { color, setColor } = useContext(PickerContext);
203
- const percent = Math.round(color.a * 100);
272
+ });
273
+ /**
274
+ * A gradient's stops, across a channel's track (from where its knob's
275
+ * center is at its least to where it is at its most), evenly.
276
+ */
277
+ const trackStops = (colors) => colors
278
+ .map((stop, index) => `${stop} calc(20px + (100% - 40px) * ${String(index / Math.max(colors.length - 1, 1))})`)
279
+ .join(', ');
280
+ /**
281
+ * A channel's row (the sliders', the opacity's): its title (all caps,
282
+ * secondary), a slider (40px high, mixing from the color: its gradient
283
+ * the color with the channel along its range; its knob 36px, in the color,
284
+ * ringed white, 3px) and its value (a 75px by 40px field on the system
285
+ * fill, 8px corners, Body emphasized: typed, committed on Enter or as it's
286
+ * left).
287
+ */
288
+ const ChannelRow = ({ fieldLabel, isCheckered = false, label, max, onValueChange, stops, thumbColor, unit, value, }) => {
204
289
  const [draft, setDraft] = useState(undefined);
205
- const commit = () => {
290
+ // Held, its touch doesn't scroll (see `useTouchHold`).
291
+ const holdHandlers = useTouchHold('x');
292
+ const commit = (event) => {
206
293
  if (draft === undefined)
207
294
  return;
208
295
  const next = Number.parseFloat(draft);
209
296
  if (Number.isFinite(next)) {
210
- setColor({ ...color, a: clamp(next, 0, 100) / 100 });
297
+ onValueChange(clamp(Math.round(next), 0, max), event);
211
298
  }
212
299
  setDraft(undefined);
213
300
  };
214
- return (_jsxs(_Fragment, { children: [_jsx("div", { className: "uikit-color-picker-opacity-title", "data-color-picker-part": "opacity-title", children: "Opacity" }), _jsxs("div", { className: "uikit-color-picker-opacity-row", "data-color-picker-part": "opacity-row", children: [_jsx(BaseSlider.Root, { "aria-label": "Opacity", max: 100, min: 0, style: { display: 'contents' }, thumbAlignment: "center", value: percent, onValueChange: (next) => setColor({ ...color, a: next / 100 }), children: _jsx(BaseSlider.Control, { className: "uikit-color-picker-opacity-control", "data-color-picker-part": "opacity", children: _jsx(BaseSlider.Track, { children: _jsx(BaseSlider.Thumb, { className: "uikit-color-picker-opacity-thumb", "data-color-picker-part": "opacity-thumb" }) }) }) }), _jsxs("label", { className: "uikit-color-picker-percentage-field", "data-color-picker-part": "percentage-field", children: [_jsx("input", { "aria-label": "Opacity percentage", inputMode: "numeric", value: draft ?? String(percent), onBlur: commit, onChange: (event) => setDraft(event.currentTarget.value),
301
+ return (_jsxs(Viewport.KeyboardAccessory, { className: "uikit-color-picker-channel", "data-color-picker-part": "channel", gap: 20, children: [_jsx("div", { "aria-hidden": "true", className: "uikit-color-picker-channel-title", "data-color-picker-part": "channel-title", children: label }), _jsxs("div", { className: "uikit-color-picker-channel-row", "data-color-picker-part": "channel-row", children: [_jsx(BaseSlider.Root, { "aria-label": label, max: max, min: 0, style: { display: 'contents' }, thumbAlignment: "center", value: value, onValueChange: (next, { event }) => onValueChange(next, event), children: _jsx(BaseSlider.Control, { className: "uikit-color-picker-channel-control", "data-base-ui-swipe-ignore": "", "data-checkered": isCheckered ? '' : undefined, "data-color-picker-part": "channel-control",
302
+ // (Its knob's place, for the hole in its gradient: the slider's
303
+ // value, not the color's, which is rounded otherwise.)
304
+ style: {
305
+ '--uikit-color-picker-channel-position': value / max,
306
+ '--uikit-color-picker-channel-stops': trackStops(stops),
307
+ '--uikit-color-picker-channel-thumb': thumbColor,
308
+ }, ...holdHandlers, children: _jsx(BaseSlider.Track, { children: _jsx(BaseSlider.Thumb, { className: "uikit-color-picker-channel-thumb", "data-color-picker-part": "channel-thumb" }) }) }) }), _jsxs("label", { className: "uikit-color-picker-channel-field", "data-color-picker-part": "channel-field", children: [_jsx("input", { "aria-label": fieldLabel ?? `${label} value`, inputMode: "numeric", value: draft ?? String(value), onBlur: (event) => commit(event), onChange: (event) => setDraft(event.currentTarget.value),
215
309
  // Focused, all of it (to type over).
216
310
  onFocus: (event) => event.currentTarget.select(), onKeyDown: (event) => {
217
311
  if (event.key === 'Enter')
218
- commit();
219
- } }), _jsx("span", { "aria-hidden": "true", children: "%" })] })] })] }));
312
+ commit(event);
313
+ } }), unit ? _jsx("span", { "aria-hidden": "true", children: unit }) : null] })] })] }));
314
+ };
315
+ /** Hue (0–360°), saturation and lightness (0–100%). */
316
+ const hsl = {
317
+ channels: [
318
+ { label: 'Hue', max: 360, unit: '°' },
319
+ { label: 'Saturation', max: 100, unit: '%' },
320
+ { label: 'Lightness', max: 100, unit: '%' },
321
+ ],
322
+ from: (color) => {
323
+ const { h, l, s } = toHsl(color);
324
+ return [Math.round(h) % 360, Math.round(s * 100), Math.round(l * 100)];
325
+ },
326
+ to: ([h = 0, s = 0, l = 0]) => fromHsl(h % 360, s / 100, l / 100),
327
+ };
328
+ /**
329
+ * Cyan, magenta, yellow and black (0–100%): naive (from sRGB, no ink's
330
+ * profile), as on screen.
331
+ */
332
+ const cmyk = {
333
+ channels: [
334
+ { label: 'Cyan', max: 100, unit: '%' },
335
+ { label: 'Magenta', max: 100, unit: '%' },
336
+ { label: 'Yellow', max: 100, unit: '%' },
337
+ { label: 'Black', max: 100, unit: '%' },
338
+ ],
339
+ from: ({ b, g, r }) => {
340
+ const k = 1 - Math.max(r, g, b) / 255;
341
+ const ink = (channel) => k >= 1 ? 0 : Math.round(((1 - channel / 255 - k) / (1 - k)) * 100);
342
+ return [ink(r), ink(g), ink(b), Math.round(k * 100)];
343
+ },
344
+ to: ([c = 0, m = 0, y = 0, k = 0]) => {
345
+ const channel = (ink) => 255 * (1 - ink / 100) * (1 - k / 100);
346
+ return { b: channel(y), g: channel(m), r: channel(c) };
347
+ },
348
+ };
349
+ /** Red, green and blue (0–255). */
350
+ const rgb = {
351
+ channels: [
352
+ { label: 'Red', max: 255 },
353
+ { label: 'Green', max: 255 },
354
+ { label: 'Blue', max: 255 },
355
+ ],
356
+ from: ({ b, g, r }) => [r, g, b].map((channel) => Math.round(channel)),
357
+ to: ([r = 0, g = 0, b = 0]) => ({ b, g, r }),
358
+ };
359
+ const models = { cmyk, hsl, rgb };
360
+ /**
361
+ * A channel's track's colors: the color with the channel along its range,
362
+ * enough of them to be exact (linear between them): a hue around (every
363
+ * 60°), a lightness through the pure hue (halfway), the others its ends.
364
+ */
365
+ const trackColors = (model, values, index) => {
366
+ const { max } = model.channels[index] ?? { max: 1 };
367
+ const steps = model === hsl ? ([6, 1, 2][index] ?? 1) : 1;
368
+ return Array.from({ length: steps + 1 }, (_, step) => {
369
+ const next = values.with(index, (max * step) / steps);
370
+ return formatColor({ ...model.to(next), a: 1 });
371
+ });
220
372
  };
221
- // A page of saved colors: 2 rows of 5 (Figma), always as high (so its
373
+ /**
374
+ * Sliders: a color model's channels (`model`: red, green and blue; hue,
375
+ * saturation and lightness; cyan, magenta, yellow and black), each mixing
376
+ * from the color, its value typed too.
377
+ */
378
+ const Sliders = forwardRef(({ className, model: modelName = 'rgb', ...props }, ref) => {
379
+ const { color, setColor } = useContext(PickerContext);
380
+ const model = models[modelName];
381
+ const opaque = formatColor({ ...color, a: 1 });
382
+ // Its values as last set, while they're the color's: so a hue isn't
383
+ // lost to a gray (no saturation), nor inks to black (all of it).
384
+ const [last, setLast] = useState();
385
+ const values = last?.color === opaque ? last.values : model.from(color);
386
+ return (_jsx("div", { ref: ref, ...props, className: cn('uikit-color-picker-sliders', className), "data-color-picker-part": "sliders", "data-model": modelName, children: model.channels.map(({ label, max, unit }, index) => (_jsx(ChannelRow, { label: label, max: max, stops: trackColors(model, values, index), thumbColor: opaque, unit: unit, value: values[index] ?? 0, onValueChange: (next, event) => {
387
+ const nextValues = values.with(index, next);
388
+ const nextColor = { ...model.to(nextValues), a: color.a };
389
+ setLast({
390
+ color: formatColor({ ...nextColor, a: 1 }),
391
+ values: nextValues,
392
+ });
393
+ setColor(nextColor, { event, reason: 'sliders' });
394
+ } }, label))) }));
395
+ });
396
+ /**
397
+ * The opacity: the color fading in over a checkerboard, in percent; 22px
398
+ * above what follows. Rendered, the color has it (see `Root`): without
399
+ * it, it's opaque.
400
+ */
401
+ const Opacity = forwardRef(({ className, ...props }, ref) => {
402
+ const { color, registerOpacity, setColor } = useContext(PickerContext);
403
+ useLayoutEffect(registerOpacity, [registerOpacity]);
404
+ return (_jsx("div", { ref: ref, ...props, className: cn('uikit-color-picker-opacity', className), "data-color-picker-part": "opacity", children: _jsx(ChannelRow, { isCheckered: true, fieldLabel: "Opacity percentage", label: "Opacity", max: 100, thumbColor: formatColor(color), unit: "%", value: Math.round(color.a * 100), stops: [
405
+ formatColor({ ...color, a: 0 }),
406
+ formatColor({ ...color, a: 1 }),
407
+ ], onValueChange: (next, event) => setColor({ ...color, a: next / 100 }, { event, reason: 'opacity' }) }) }));
408
+ });
409
+ // A page of saved colors: 2 rows of 5, always as high (so its
222
410
  // popover doesn't move).
223
411
  const Saved = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn('uikit-color-picker-saved', className), "data-color-picker-part": "saved", ...props })));
224
412
  /** Saved colors per page (with the add button, on the last). */
@@ -227,27 +415,22 @@ const SavedSwatch = ({ hex, onDelete }) => {
227
415
  const { color, setColor } = useContext(PickerContext);
228
416
  const swatch = parseColor(hex);
229
417
  // Its menu (a secondary click: right click, or a long press): delete it.
230
- return (_jsxs(Menu.Root, { children: [_jsx(Menu.Trigger, { openOn: "secondaryClick", render: _jsx("button", { "aria-label": hex, "aria-pressed": sameColor(swatch, color) && swatch.a === color.a, style: { backgroundColor: hex }, type: "button", onClick: () => setColor(swatch) }) }), _jsx(Menu.Portal, { children: _jsx(Menu.Positioner, { children: _jsx(Menu.Popup, { children: _jsx(Menu.Item, { destructive: true, onClick: onDelete, children: _jsx(Menu.Label, { children: "Delete" }) }) }) }) })] }));
418
+ return (_jsxs(Menu.Root, { children: [_jsx(Menu.Trigger, { openOn: "secondaryClick", render: _jsx("button", { "aria-label": hex, "aria-pressed": sameColor(swatch, color) && swatch.a === color.a, style: { backgroundColor: hex }, type: "button", onClick: (event) => setColor(swatch, { event, reason: 'saved' }) }) }), _jsx(Menu.Portal, { children: _jsx(Menu.Positioner, { children: _jsx(Menu.Popup, { children: _jsx(Menu.Item, { destructive: true, onClick: (event) => onDelete(event), children: _jsx(Menu.Label, { children: "Delete" }) }) }) }) })] }));
231
419
  };
232
- const modes = [
233
- ['grid', 'Grid'],
234
- ['spectrum', 'Spectrum'],
235
- ['sliders', 'Sliders'],
236
- ];
237
420
  /**
238
- * Its views (Grid, Spectrum, Sliders), the opacity, the color and the saved
239
- * colors (in pages; adding the color to them, deleting one by its menu).
421
+ * The color (82px, 18px corners; translucent, over black and white) beside
422
+ * the saved colors (in pages, with a page control; adding the color to
423
+ * them, deleting one by its menu).
240
424
  */
241
- const Panel = forwardRef(({ className, defaultMode = 'grid', defaultSavedColors: initialSaved = defaultSavedColors, mode: modeProp, onModeChange, onSavedColorsChange, savedColors: savedProp, style, ...props }, ref) => {
425
+ const Swatches = forwardRef(({ className, defaultSavedColors: initialSaved = defaultSavedColors, onSavedColorsChange, savedColors: savedProp, ...props }, ref) => {
242
426
  const { color } = useContext(PickerContext);
243
- const [ownMode, setOwnMode] = useState(defaultMode);
244
- const mode = modeProp ?? ownMode;
245
427
  const [ownSaved, setOwnSaved] = useState(initialSaved);
246
428
  const saved = savedProp ?? ownSaved;
247
- const opaque = formatColor({ ...color, a: 1 });
248
- const changeSaved = (next) => {
249
- setOwnSaved(next);
250
- onSavedColorsChange?.(next);
429
+ // Uncontrolled: their own state; controlled, only the app's.
430
+ const changeSaved = (next, details) => {
431
+ if (savedProp === undefined)
432
+ setOwnSaved(next);
433
+ onSavedColorsChange?.(next, details);
251
434
  };
252
435
  // Pages of saved colors, the add button after them (unless the color
253
436
  // is one of them).
@@ -273,10 +456,10 @@ const Panel = forwardRef(({ className, defaultMode = 'grid', defaultSavedColors:
273
456
  const { current: element } = pagesRef;
274
457
  if (!element || scrollTarget === undefined)
275
458
  return undefined;
276
- const rtl = getComputedStyle(element).direction === 'rtl';
459
+ const isRightToLeft = getComputedStyle(element).direction === 'rtl';
277
460
  element.scrollTo({
278
461
  behavior: 'smooth',
279
- left: (rtl ? -1 : 1) * scrollTarget * element.clientWidth,
462
+ left: (isRightToLeft ? -1 : 1) * scrollTarget * element.clientWidth,
280
463
  });
281
464
  // (Swipes count again once it's there.)
282
465
  const done = () => setScrollTarget(undefined);
@@ -291,39 +474,30 @@ const Panel = forwardRef(({ className, defaultMode = 'grid', defaultSavedColors:
291
474
  setPage(next);
292
475
  setScrollTarget(next);
293
476
  };
294
- const views = {
295
- grid: _jsx(Grid, {}),
296
- sliders: _jsx(Sliders, {}),
297
- spectrum: _jsx(Spectrum, {}),
298
- };
299
- return (_jsxs("div", { ref: ref, style: withStyle({
300
- // (For its parts.)
301
- '--uikit-color-picker-color': formatColor(color),
302
- '--uikit-color-picker-color-opaque': opaque,
303
- }, style), ...props, className: cn('uikit-color-picker-panel', className), "data-color-picker-part": "panel", children: [_jsxs(Segmented.Root, { "aria-label": "View", value: mode, onValueChange: (next) => {
304
- setOwnMode(next);
305
- onModeChange?.(next);
306
- }, children: [modes.map(([value, label]) => (_jsx(Segmented.Item, { value: value, children: label }, value))), _jsx(Segmented.Highlight, {})] }), _jsx("div", { "data-color-picker-view": mode, children: views[mode] }), _jsx(Opacity, {}), _jsxs("div", { className: "uikit-color-picker-swatches", "data-color-picker-part": "swatches", children: [_jsx("div", { "aria-hidden": "true", className: "uikit-color-picker-current", "data-color-picker-part": "current" }), _jsxs("div", { className: "uikit-color-picker-saved-column", "data-color-picker-part": "saved-column", children: [_jsx("div", { ref: pagesRef, "aria-label": "Saved colors", className: "uikit-color-picker-saved-pages", "data-color-picker-part": "saved-pages", role: "group", onScroll: handleScroll, children: Array.from({ length: pages }, (_, index) => (_jsx(Saved, {
307
- // (Only the page shown can be reached.)
308
- inert: index !== shownPage, children: items
309
- .slice(index * pageSize, (index + 1) * pageSize)
310
- .map((hex) => hex === undefined ? (_jsx("button", { "aria-label": "Add color", "data-add": "", type: "button", onClick: () => {
311
- const next = formatColor(color);
312
- if (saved.includes(next))
313
- return;
314
- changeSaved([...saved, next]);
315
- // On the page it lands on.
316
- goTo(Math.floor(saved.length / pageSize));
317
- }, children: "+" }, "add")) : (_jsx(SavedSwatch, { hex: hex, onDelete: () => changeSaved(saved.filter((other) => other !== hex)) }, hex))) }, index))) }), _jsx(PageControl, { count: Math.max(pages, 2), style: pages > 1 ? undefined : { visibility: 'hidden' }, value: shownPage, variant: "plain", onValueChange: goTo })] })] })] }));
477
+ return (_jsxs("div", { ref: ref, ...props, className: cn('uikit-color-picker-swatches', className), "data-color-picker-part": "swatches", children: [_jsx("div", { "aria-hidden": "true", className: "uikit-color-picker-current", "data-color-picker-part": "current" }), _jsxs("div", { className: "uikit-color-picker-saved-column", "data-color-picker-part": "saved-column", children: [_jsx("div", { ref: pagesRef, "aria-label": "Saved colors", className: "uikit-color-picker-saved-pages", "data-color-picker-part": "saved-pages", role: "group", onScroll: handleScroll, children: Array.from({ length: pages }, (_, index) => (_jsx(Saved, {
478
+ // (Only the page shown can be reached.)
479
+ inert: index !== shownPage, children: items
480
+ .slice(index * pageSize, (index + 1) * pageSize)
481
+ .map((hex) => hex === undefined ? (_jsx("button", { "aria-label": "Add color", "data-add": "", type: "button", onClick: (event) => {
482
+ const next = formatColor(color);
483
+ if (saved.includes(next))
484
+ return;
485
+ changeSaved([...saved, next], {
486
+ event,
487
+ reason: 'add',
488
+ });
489
+ // On the page it lands on.
490
+ goTo(Math.floor(saved.length / pageSize));
491
+ }, children: "+" }, "add")) : (_jsx(SavedSwatch, { hex: hex, onDelete: (event) => changeSaved(saved.filter((other) => other !== hex), { event, reason: 'delete' }) }, hex))) }, index))) }), pages > 1 ? (_jsx(PageControl, { count: pages, value: shownPage, variant: "plain", onValueChange: goTo })) : null] })] }));
318
492
  });
319
- // Its header (Figma “Toolbar” in the panel's popover: 16px from its top,
320
- // 10px above the panel): the app's (e.g. a `Toolbar`: eyedropper, title,
493
+ // Its header (in the panel's popover: 16px from its top, 10px above the
494
+ // panel): the app's (e.g. a `Toolbar`: eyedropper, title,
321
495
  // close); in a sheet, its `Sheet.Header` instead.
322
496
  const Header = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn('uikit-color-picker-header', className), "data-color-picker-part": "header", ...props })));
323
497
  /** The browser's eyedropper (`EyeDropper`), if it has one. */
324
498
  const eyeDropper = () => globalThis.EyeDropper;
325
499
  /**
326
- * Its eyedropper (Figma's leading button): a `Button` (or what it
500
+ * Its eyedropper (the leading button): a `Button` (or what it
327
501
  * renders), picking a color off the screen (the browser's `EyeDropper`;
328
502
  * none without it).
329
503
  */
@@ -332,10 +506,10 @@ const Eyedropper = ({ render, ...props }) => {
332
506
  const Picker = eyeDropper();
333
507
  if (!Picker)
334
508
  return null;
335
- const pick = () => {
509
+ const pick = (event) => {
336
510
  new Picker()
337
511
  .open()
338
- .then(({ sRGBHex }) => setColor({ ...parseColor(sRGBHex), a: color.a }))
512
+ .then(({ sRGBHex }) => setColor({ ...parseColor(sRGBHex), a: color.a }, { event, reason: 'eyedropper' }))
339
513
  .catch(() => undefined);
340
514
  };
341
515
  return render ? (cloneElement(render, {
@@ -344,12 +518,20 @@ const Eyedropper = ({ render, ...props }) => {
344
518
  onClick: pick,
345
519
  })) : (_jsx(Button.Root, { "aria-label": "Eyedropper", ...props, onClick: pick }));
346
520
  };
347
- /** A color well (UIKit `UIColorWell`): its color, opening the picker. */
521
+ /** A color well: its color, opening the picker. */
348
522
  const Well = forwardRef(({ className, color, size = 'small', style, ...props }, ref) => (_jsx("button", { ref: ref, "aria-label": "Color", "data-color": color === undefined ? undefined : '', "data-size": size, style: withStyle({ '--uikit-color-picker-well-color': color }, style), type: "button", ...props, className: cn('uikit-color-picker-well', className), "data-color-picker-part": "well" })));
349
523
  export const ColorPicker = {
350
524
  Root,
351
525
  Header,
352
526
  Panel,
527
+ Modes,
528
+ Mode,
529
+ View,
530
+ Grid,
531
+ Spectrum,
532
+ Sliders,
533
+ Opacity,
534
+ Swatches,
353
535
  Eyedropper,
354
536
  Well,
355
537
  };