gooee 0.0.0-stage → 0.41.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 (247) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -2
  3. package/package.json +36 -4
  4. package/scripts/add.js +533 -0
  5. package/scripts/pro-components.json +82 -0
  6. package/src/base.css +39 -0
  7. package/src/components/Accordion/Accordion.module.css +90 -0
  8. package/src/components/Accordion/Accordion.tsx +125 -0
  9. package/src/components/Accordion/index.ts +1 -0
  10. package/src/components/Alert/Alert.module.css +121 -0
  11. package/src/components/Alert/Alert.tsx +90 -0
  12. package/src/components/Alert/index.ts +1 -0
  13. package/src/components/AlertDialog/AlertDialog.module.css +2 -0
  14. package/src/components/AlertDialog/AlertDialog.tsx +108 -0
  15. package/src/components/AlertDialog/index.ts +1 -0
  16. package/src/components/AnimatedNumber/AnimatedNumber.module.css +48 -0
  17. package/src/components/AnimatedNumber/AnimatedNumber.tsx +52 -0
  18. package/src/components/AnimatedNumber/index.ts +1 -0
  19. package/src/components/AspectRatio/AspectRatio.module.css +15 -0
  20. package/src/components/AspectRatio/AspectRatio.tsx +12 -0
  21. package/src/components/AspectRatio/index.ts +1 -0
  22. package/src/components/Avatar/Avatar.module.css +62 -0
  23. package/src/components/Avatar/Avatar.tsx +55 -0
  24. package/src/components/Avatar/index.ts +3 -0
  25. package/src/components/AvatarGroup/AvatarGroup.module.css +53 -0
  26. package/src/components/AvatarGroup/AvatarGroup.tsx +43 -0
  27. package/src/components/AvatarGroup/index.ts +1 -0
  28. package/src/components/Badge/Badge.module.css +69 -0
  29. package/src/components/Badge/Badge.tsx +25 -0
  30. package/src/components/Badge/index.ts +1 -0
  31. package/src/components/Breadcrumb/Breadcrumb.module.css +104 -0
  32. package/src/components/Breadcrumb/Breadcrumb.tsx +76 -0
  33. package/src/components/Breadcrumb/index.ts +1 -0
  34. package/src/components/Button/Button.module.css +191 -0
  35. package/src/components/Button/Button.tsx +148 -0
  36. package/src/components/Button/index.ts +1 -0
  37. package/src/components/ButtonGroup/ButtonGroup.module.css +59 -0
  38. package/src/components/ButtonGroup/ButtonGroup.tsx +45 -0
  39. package/src/components/ButtonGroup/index.ts +1 -0
  40. package/src/components/Card/Card.module.css +82 -0
  41. package/src/components/Card/Card.tsx +34 -0
  42. package/src/components/Card/index.ts +1 -0
  43. package/src/components/Center/Center.module.css +15 -0
  44. package/src/components/Center/Center.tsx +28 -0
  45. package/src/components/Center/index.ts +1 -0
  46. package/src/components/Checkbox/Checkbox.module.css +120 -0
  47. package/src/components/Checkbox/Checkbox.tsx +133 -0
  48. package/src/components/Checkbox/index.ts +1 -0
  49. package/src/components/CheckboxGroup/CheckboxGroup.module.css +30 -0
  50. package/src/components/CheckboxGroup/CheckboxGroup.tsx +88 -0
  51. package/src/components/CheckboxGroup/index.ts +1 -0
  52. package/src/components/Cluster/Cluster.module.css +25 -0
  53. package/src/components/Cluster/Cluster.tsx +26 -0
  54. package/src/components/Cluster/index.ts +1 -0
  55. package/src/components/CodeBlock/CodeBlock.module.css +74 -0
  56. package/src/components/CodeBlock/CodeBlock.tsx +53 -0
  57. package/src/components/CodeBlock/highlight.ts +73 -0
  58. package/src/components/CodeBlock/index.ts +1 -0
  59. package/src/components/Collapsible/Collapsible.module.css +75 -0
  60. package/src/components/Collapsible/Collapsible.tsx +71 -0
  61. package/src/components/Collapsible/index.ts +1 -0
  62. package/src/components/Container/Container.module.css +14 -0
  63. package/src/components/Container/Container.tsx +19 -0
  64. package/src/components/Container/index.ts +1 -0
  65. package/src/components/CopyButton/CopyButton.module.css +125 -0
  66. package/src/components/CopyButton/CopyButton.tsx +160 -0
  67. package/src/components/CopyButton/index.ts +1 -0
  68. package/src/components/Dial/Dial.module.css +344 -0
  69. package/src/components/Dial/Dial.tsx +332 -0
  70. package/src/components/Dial/index.ts +1 -0
  71. package/src/components/Dialog/Dialog.module.css +190 -0
  72. package/src/components/Dialog/Dialog.tsx +100 -0
  73. package/src/components/Dialog/index.ts +1 -0
  74. package/src/components/Divider/Divider.module.css +39 -0
  75. package/src/components/Divider/Divider.tsx +34 -0
  76. package/src/components/Divider/index.ts +1 -0
  77. package/src/components/DropdownMenu/DropdownMenu.module.css +134 -0
  78. package/src/components/DropdownMenu/DropdownMenu.tsx +215 -0
  79. package/src/components/DropdownMenu/index.ts +1 -0
  80. package/src/components/EmptyState/EmptyState.module.css +66 -0
  81. package/src/components/EmptyState/EmptyState.tsx +38 -0
  82. package/src/components/EmptyState/index.ts +1 -0
  83. package/src/components/Fab/Fab.module.css +176 -0
  84. package/src/components/Fab/Fab.tsx +117 -0
  85. package/src/components/Fab/index.ts +1 -0
  86. package/src/components/Fieldset/Fieldset.module.css +34 -0
  87. package/src/components/Fieldset/Fieldset.tsx +41 -0
  88. package/src/components/Fieldset/index.ts +1 -0
  89. package/src/components/FormField/FormField.module.css +62 -0
  90. package/src/components/FormField/FormField.tsx +91 -0
  91. package/src/components/FormField/index.ts +2 -0
  92. package/src/components/Grid/Grid.module.css +39 -0
  93. package/src/components/Grid/Grid.tsx +35 -0
  94. package/src/components/Grid/index.ts +1 -0
  95. package/src/components/HoldToConfirm/HoldToConfirm.module.css +175 -0
  96. package/src/components/HoldToConfirm/HoldToConfirm.tsx +334 -0
  97. package/src/components/HoldToConfirm/index.ts +1 -0
  98. package/src/components/IconButton/IconButton.module.css +78 -0
  99. package/src/components/IconButton/IconButton.tsx +35 -0
  100. package/src/components/IconButton/index.ts +1 -0
  101. package/src/components/Input/Input.module.css +157 -0
  102. package/src/components/Input/Input.tsx +133 -0
  103. package/src/components/Input/index.ts +1 -0
  104. package/src/components/InputGroup/InputGroup.module.css +146 -0
  105. package/src/components/InputGroup/InputGroup.tsx +90 -0
  106. package/src/components/InputGroup/index.ts +1 -0
  107. package/src/components/Kbd/Kbd.module.css +28 -0
  108. package/src/components/Kbd/Kbd.tsx +38 -0
  109. package/src/components/Kbd/index.ts +1 -0
  110. package/src/components/Link/Link.module.css +65 -0
  111. package/src/components/Link/Link.tsx +41 -0
  112. package/src/components/Link/index.ts +1 -0
  113. package/src/components/LivePill/LivePill.module.css +207 -0
  114. package/src/components/LivePill/LivePill.tsx +182 -0
  115. package/src/components/LivePill/index.ts +1 -0
  116. package/src/components/Meter/Meter.module.css +91 -0
  117. package/src/components/Meter/Meter.tsx +109 -0
  118. package/src/components/Meter/index.ts +1 -0
  119. package/src/components/MorphButton/MorphButton.module.css +152 -0
  120. package/src/components/MorphButton/MorphButton.tsx +203 -0
  121. package/src/components/MorphButton/index.ts +1 -0
  122. package/src/components/NumberInput/NumberInput.module.css +104 -0
  123. package/src/components/NumberInput/NumberInput.tsx +252 -0
  124. package/src/components/NumberInput/index.ts +2 -0
  125. package/src/components/Pagination/Pagination.module.css +88 -0
  126. package/src/components/Pagination/Pagination.tsx +126 -0
  127. package/src/components/Pagination/index.ts +1 -0
  128. package/src/components/PasswordInput/PasswordInput.module.css +64 -0
  129. package/src/components/PasswordInput/PasswordInput.tsx +63 -0
  130. package/src/components/PasswordInput/index.ts +2 -0
  131. package/src/components/PickerWheel/PickerWheel.module.css +123 -0
  132. package/src/components/PickerWheel/PickerWheel.tsx +326 -0
  133. package/src/components/PickerWheel/index.ts +1 -0
  134. package/src/components/Popover/Popover.module.css +78 -0
  135. package/src/components/Popover/Popover.tsx +117 -0
  136. package/src/components/Popover/index.ts +1 -0
  137. package/src/components/ProgressBar/ProgressBar.module.css +61 -0
  138. package/src/components/ProgressBar/ProgressBar.tsx +48 -0
  139. package/src/components/ProgressBar/index.ts +1 -0
  140. package/src/components/Prose/Prose.module.css +115 -0
  141. package/src/components/Prose/Prose.tsx +14 -0
  142. package/src/components/Prose/index.ts +1 -0
  143. package/src/components/Radio/Radio.module.css +106 -0
  144. package/src/components/Radio/Radio.tsx +115 -0
  145. package/src/components/Radio/index.ts +1 -0
  146. package/src/components/Retime/Retime.tsx +116 -0
  147. package/src/components/Retime/index.ts +1 -0
  148. package/src/components/RulerScrubber/RulerScrubber.module.css +146 -0
  149. package/src/components/RulerScrubber/RulerScrubber.tsx +209 -0
  150. package/src/components/RulerScrubber/index.ts +1 -0
  151. package/src/components/ScrollArea/ScrollArea.module.css +72 -0
  152. package/src/components/ScrollArea/ScrollArea.tsx +172 -0
  153. package/src/components/ScrollArea/index.ts +1 -0
  154. package/src/components/SearchInput/SearchInput.module.css +53 -0
  155. package/src/components/SearchInput/SearchInput.tsx +104 -0
  156. package/src/components/SearchInput/index.ts +2 -0
  157. package/src/components/SegmentedControl/SegmentedControl.module.css +150 -0
  158. package/src/components/SegmentedControl/SegmentedControl.tsx +169 -0
  159. package/src/components/SegmentedControl/index.ts +1 -0
  160. package/src/components/Select/Select.module.css +204 -0
  161. package/src/components/Select/Select.tsx +254 -0
  162. package/src/components/Select/index.ts +1 -0
  163. package/src/components/Sheet/Sheet.module.css +228 -0
  164. package/src/components/Sheet/Sheet.tsx +449 -0
  165. package/src/components/Sheet/index.ts +1 -0
  166. package/src/components/Skeleton/Skeleton.module.css +56 -0
  167. package/src/components/Skeleton/Skeleton.tsx +37 -0
  168. package/src/components/Skeleton/index.ts +1 -0
  169. package/src/components/Slider/Slider.module.css +155 -0
  170. package/src/components/Slider/Slider.tsx +200 -0
  171. package/src/components/Slider/index.ts +1 -0
  172. package/src/components/Spinner/Spinner.module.css +50 -0
  173. package/src/components/Spinner/Spinner.tsx +29 -0
  174. package/src/components/Spinner/index.ts +1 -0
  175. package/src/components/Split/Split.module.css +29 -0
  176. package/src/components/Split/Split.tsx +33 -0
  177. package/src/components/Split/index.ts +1 -0
  178. package/src/components/SplitFlap/SplitFlap.module.css +107 -0
  179. package/src/components/SplitFlap/SplitFlap.tsx +225 -0
  180. package/src/components/SplitFlap/index.ts +1 -0
  181. package/src/components/Stack/Stack.module.css +17 -0
  182. package/src/components/Stack/Stack.tsx +19 -0
  183. package/src/components/Stack/index.ts +1 -0
  184. package/src/components/SwipeDeck/SwipeDeck.module.css +250 -0
  185. package/src/components/SwipeDeck/SwipeDeck.tsx +350 -0
  186. package/src/components/SwipeDeck/index.ts +1 -0
  187. package/src/components/Switch/Switch.module.css +97 -0
  188. package/src/components/Switch/Switch.tsx +147 -0
  189. package/src/components/Switch/index.ts +1 -0
  190. package/src/components/Table/Table.module.css +369 -0
  191. package/src/components/Table/Table.tsx +368 -0
  192. package/src/components/Table/index.ts +1 -0
  193. package/src/components/TableOfContents/TableOfContents.module.css +107 -0
  194. package/src/components/TableOfContents/TableOfContents.tsx +93 -0
  195. package/src/components/TableOfContents/index.ts +1 -0
  196. package/src/components/Tabs/Tabs.module.css +101 -0
  197. package/src/components/Tabs/Tabs.tsx +190 -0
  198. package/src/components/Tabs/index.ts +1 -0
  199. package/src/components/Tag/Tag.module.css +120 -0
  200. package/src/components/Tag/Tag.tsx +109 -0
  201. package/src/components/Tag/index.ts +1 -0
  202. package/src/components/Textarea/Textarea.module.css +79 -0
  203. package/src/components/Textarea/Textarea.tsx +130 -0
  204. package/src/components/Textarea/index.ts +1 -0
  205. package/src/components/ThemeToggle/ThemeToggle.module.css +21 -0
  206. package/src/components/ThemeToggle/ThemeToggle.tsx +69 -0
  207. package/src/components/ThemeToggle/index.ts +1 -0
  208. package/src/components/Toast/Toast.module.css +202 -0
  209. package/src/components/Toast/Toast.tsx +473 -0
  210. package/src/components/Toast/index.ts +1 -0
  211. package/src/components/Toggle/Toggle.module.css +94 -0
  212. package/src/components/Toggle/Toggle.tsx +50 -0
  213. package/src/components/Toggle/index.ts +1 -0
  214. package/src/components/Tooltip/Tooltip.module.css +34 -0
  215. package/src/components/Tooltip/Tooltip.tsx +154 -0
  216. package/src/components/Tooltip/index.ts +1 -0
  217. package/src/components/VisuallyHidden/VisuallyHidden.module.css +13 -0
  218. package/src/components/VisuallyHidden/VisuallyHidden.tsx +12 -0
  219. package/src/components/VisuallyHidden/index.ts +1 -0
  220. package/src/internal/FieldMessage.module.css +49 -0
  221. package/src/internal/FieldMessage.tsx +44 -0
  222. package/src/internal/Portal.tsx +7 -0
  223. package/src/internal/Roll.module.css +31 -0
  224. package/src/internal/Roll.tsx +20 -0
  225. package/src/internal/cx.ts +3 -0
  226. package/src/internal/feel.ts +355 -0
  227. package/src/internal/fling.ts +118 -0
  228. package/src/internal/focus.ts +94 -0
  229. package/src/internal/icons.module.css +62 -0
  230. package/src/internal/icons.tsx +511 -0
  231. package/src/internal/keyboard.ts +62 -0
  232. package/src/internal/layers.ts +85 -0
  233. package/src/internal/liquid.ts +248 -0
  234. package/src/internal/liquidMatter.ts +168 -0
  235. package/src/internal/liquidMore.ts +686 -0
  236. package/src/internal/liquidPath.ts +519 -0
  237. package/src/internal/mergeRefs.ts +10 -0
  238. package/src/internal/motion.ts +37 -0
  239. package/src/internal/relativeTime.ts +26 -0
  240. package/src/internal/scrollFrame.ts +157 -0
  241. package/src/internal/softPress.ts +299 -0
  242. package/src/internal/space.ts +6 -0
  243. package/src/internal/useControllable.ts +21 -0
  244. package/src/internal/useFloating.ts +85 -0
  245. package/src/internal/usePresence.ts +15 -0
  246. package/src/internal/useScrub.ts +160 -0
  247. package/src/tokens.css +727 -0
@@ -0,0 +1,120 @@
1
+ .root {
2
+ display: flex;
3
+ align-items: flex-start;
4
+ gap: var(--gooee-space-4);
5
+ min-height: var(--gooee-hit-min);
6
+ padding-block: var(--gooee-space-4);
7
+ }
8
+
9
+ .root[data-disabled] { opacity: var(--gooee-disabled-opacity); }
10
+
11
+ .boxWrap {
12
+ position: relative;
13
+ display: inline-grid;
14
+ flex: none;
15
+ width: var(--gooee-control-box);
16
+ height: var(--gooee-control-box);
17
+ margin-top: var(--gooee-space-1);
18
+ }
19
+
20
+ /* The real input sits on top, invisible, with a 44px hit area. */
21
+ .input {
22
+ position: absolute;
23
+ inset: min(0px, calc((100% - var(--gooee-hit-min)) / 2));
24
+ margin: 0;
25
+ opacity: 0;
26
+ cursor: pointer;
27
+ z-index: 1;
28
+ }
29
+
30
+ .input:disabled { cursor: not-allowed; }
31
+
32
+ .box {
33
+ position: relative;
34
+ display: grid;
35
+ place-items: center;
36
+ width: 100%;
37
+ height: 100%;
38
+ border: var(--gooee-line-thick) solid var(--gooee-color-border-strong);
39
+ border-radius: var(--gooee-radius-xs);
40
+ background: var(--gooee-color-surface);
41
+ color: var(--gooee-color-accent-fg);
42
+ transition:
43
+ border-color var(--gooee-motion-fast) var(--gooee-ease-out),
44
+ box-shadow var(--gooee-motion-fast) var(--gooee-ease-out);
45
+ }
46
+
47
+ @media (hover: hover) {
48
+ .input:hover:not(:disabled) + .box { border-color: var(--gooee-color-fg); }
49
+ }
50
+ .input:focus-visible + .box { box-shadow: var(--gooee-focus-ring); }
51
+ .root[data-invalid] .box[data-state="off"] { border-color: var(--gooee-color-danger); }
52
+
53
+ /* The checked fill covers the border too. Ink pours into it in Checkbox.tsx (internal/liquidMore.ts);
54
+ here it only holds the end state, so reduced motion lands on it at once. */
55
+ .fill {
56
+ position: absolute;
57
+ inset: calc(var(--gooee-line-thick) * -1);
58
+ border-radius: var(--gooee-radius-xs);
59
+ background: var(--gooee-color-accent);
60
+ clip-path: circle(0 at 50% 50%);
61
+ }
62
+
63
+ .box[data-state="on"] .fill,
64
+ .box[data-state="mixed"] .fill { clip-path: none; }
65
+
66
+ .pour {
67
+ position: absolute;
68
+ overflow: visible;
69
+ pointer-events: none;
70
+ }
71
+
72
+ .box[data-pouring] .fill { visibility: hidden; }
73
+ .box[data-pouring] :is(.tick, .dash) { transition: none; }
74
+
75
+ .mark {
76
+ position: relative;
77
+ width: var(--gooee-icon-sm);
78
+ height: var(--gooee-icon-sm);
79
+ fill: none;
80
+ stroke: currentColor;
81
+ stroke-width: 2;
82
+ stroke-linecap: round;
83
+ stroke-linejoin: round;
84
+ }
85
+
86
+ .tick,
87
+ .dash {
88
+ /* Hidden just before the path starts. A zero-length dash would leave its round ends as a dot in Safari. */
89
+ stroke-dasharray: 1 2;
90
+ stroke-dashoffset: 1.01;
91
+ transition: stroke-dashoffset var(--gooee-motion-base) var(--gooee-ease-out);
92
+ }
93
+
94
+ .box[data-state="on"] .tick {
95
+ stroke-dashoffset: 0;
96
+ transition-delay: var(--gooee-motion-instant);
97
+ }
98
+
99
+ .box[data-state="mixed"] .dash { stroke-dashoffset: 0; }
100
+
101
+ .text {
102
+ display: flex;
103
+ flex-direction: column;
104
+ min-width: 0;
105
+ }
106
+
107
+ .label {
108
+ font-size: var(--gooee-text-md);
109
+ line-height: var(--gooee-leading-snug);
110
+ cursor: pointer;
111
+ }
112
+
113
+ .root[data-disabled] .label { cursor: not-allowed; }
114
+
115
+ .description {
116
+ margin-top: var(--gooee-space-1);
117
+ font-size: var(--gooee-text-sm);
118
+ color: var(--gooee-color-fg-muted);
119
+ line-height: var(--gooee-leading-snug);
120
+ }
@@ -0,0 +1,133 @@
1
+ 'use client'
2
+
3
+ import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type ReactNode } from 'react'
4
+ import { cx } from '../../internal/cx'
5
+ import { FieldMessage } from '../../internal/FieldMessage'
6
+ import { mergeRefs } from '../../internal/mergeRefs'
7
+ import { pour, type Pour } from '../../internal/liquidMore'
8
+ import { useControllable } from '../../internal/useControllable'
9
+ import styles from './Checkbox.module.css'
10
+
11
+ export type CheckboxProps = Omit<ComponentPropsWithRef<'input'>, 'type' | 'checked' | 'defaultChecked' | 'onChange'> & {
12
+ /** Visible text next to the box. Clicking it toggles the box. */
13
+ label: ReactNode
14
+ /** Muted text under the label, linked with aria-describedby. */
15
+ description?: ReactNode
16
+ /** Checked state, when you control it. */
17
+ checked?: boolean
18
+ /** Starting checked state when you do not control it. */
19
+ defaultChecked?: boolean
20
+ /** Called when the checked state changes, with the new state. */
21
+ onCheckedChange?: (checked: boolean) => void
22
+ /** Shows a dash. A click clears the dash and checks the box. */
23
+ indeterminate?: boolean
24
+ /** Error message under the label. Marks the box invalid. */
25
+ error?: ReactNode
26
+ }
27
+
28
+ export function Checkbox({
29
+ label,
30
+ description,
31
+ checked: checkedProp,
32
+ defaultChecked = false,
33
+ onCheckedChange,
34
+ indeterminate = false,
35
+ error,
36
+ id,
37
+ className,
38
+ ref,
39
+ disabled,
40
+ onPointerDown,
41
+ onKeyDown,
42
+ 'aria-describedby': describedByProp,
43
+ ...rest
44
+ }: CheckboxProps) {
45
+ const auto = useId()
46
+ const inputId = id ?? auto
47
+ const errorId = `${inputId}-error`
48
+ const describedBy = [description ? `${inputId}-desc` : null, error ? errorId : null, describedByProp].filter(Boolean).join(' ')
49
+ const [checked, setChecked] = useControllable(checkedProp, defaultChecked, onCheckedChange)
50
+ const inner = useRef<HTMLInputElement>(null)
51
+ // Like a native checkbox, a click clears the mixed look until the prop sets it again.
52
+ const [mixed, setMixed] = useState(indeterminate)
53
+ const [lastProp, setLastProp] = useState(indeterminate)
54
+ if (indeterminate !== lastProp) {
55
+ setLastProp(indeterminate)
56
+ setMixed(indeterminate)
57
+ }
58
+
59
+ useEffect(() => {
60
+ if (inner.current) inner.current.indeterminate = mixed
61
+ }, [mixed])
62
+
63
+ const state = mixed ? 'mixed' : checked ? 'on' : 'off'
64
+
65
+ // Ink pours in from the side that was pressed (a key fills it evenly from below), levels, and then
66
+ // the mark draws. Clearing drains it the same way.
67
+ const boxRef = useRef<HTMLSpanElement>(null)
68
+ const pressedAt = useRef<{ x: number; t: number } | null>(null)
69
+ const pouring = useRef<Pour | null>(null)
70
+ const filled = state !== 'off'
71
+ const was = useRef({ filled, state })
72
+ useLayoutEffect(() => {
73
+ const prev = was.current
74
+ was.current = { filled, state }
75
+ if (prev.filled === filled) return
76
+ const box = boxRef.current
77
+ const at = pressedAt.current
78
+ pressedAt.current = null
79
+ if (!box) return
80
+ const r = box.getBoundingClientRect()
81
+ const side = at && performance.now() - at.t < 1000 ? Math.max(-1, Math.min(1, (at.x - r.left - r.width / 2) / (r.width / 2))) : 0
82
+ const mark = box.querySelector<SVGPathElement>(prev.state === 'mixed' || state === 'mixed' ? '[data-mark="dash"]' : '[data-mark="tick"]')
83
+ pouring.current = pour(box, mark, filled ? 1 : 0, side, styles.pour, pouring.current)
84
+ }, [filled, state])
85
+ useLayoutEffect(() => () => pouring.current?.stop(), [])
86
+
87
+ return (
88
+ <div
89
+ className={cx(styles.root, className)}
90
+ data-disabled={disabled || undefined}
91
+ data-invalid={error ? true : undefined}
92
+ onPointerDown={(e) => {
93
+ pressedAt.current = { x: e.clientX, t: performance.now() }
94
+ }}
95
+ >
96
+ <span className={styles.boxWrap}>
97
+ <input
98
+ ref={mergeRefs(inner, ref)}
99
+ id={inputId}
100
+ type="checkbox"
101
+ className={styles.input}
102
+ checked={checked}
103
+ disabled={disabled}
104
+ aria-invalid={error ? true : undefined}
105
+ aria-describedby={describedBy || undefined}
106
+ onChange={(e) => {
107
+ if (!mixed) return setChecked(e.target.checked)
108
+ setMixed(false)
109
+ setChecked(true)
110
+ }}
111
+ onPointerDown={onPointerDown}
112
+ onKeyDown={(e) => {
113
+ pressedAt.current = null
114
+ onKeyDown?.(e)
115
+ }}
116
+ {...rest}
117
+ />
118
+ <span ref={boxRef} className={styles.box} data-state={state} aria-hidden="true">
119
+ <span className={styles.fill} data-pour-fill />
120
+ <svg viewBox="0 0 16 16" className={styles.mark}>
121
+ <path className={styles.tick} d="M3.5 8.5l3 3 6-7" pathLength="1" data-mark="tick" />
122
+ <path className={styles.dash} d="M4 8h8" pathLength="1" data-mark="dash" />
123
+ </svg>
124
+ </span>
125
+ </span>
126
+ <span className={styles.text}>
127
+ <label htmlFor={inputId} className={styles.label}>{label}</label>
128
+ {description && <span id={`${inputId}-desc`} className={styles.description}>{description}</span>}
129
+ <FieldMessage helpId={`${inputId}-help`} errorId={errorId} error={error} />
130
+ </span>
131
+ </div>
132
+ )
133
+ }
@@ -0,0 +1 @@
1
+ export * from './Checkbox'
@@ -0,0 +1,30 @@
1
+ .group {
2
+ min-width: 0;
3
+ margin: 0;
4
+ padding: 0;
5
+ border: 0;
6
+ }
7
+
8
+ .legend {
9
+ padding: 0;
10
+ margin-bottom: var(--gooee-space-2);
11
+ font-size: var(--gooee-text-sm);
12
+ font-weight: var(--gooee-weight-medium);
13
+ }
14
+
15
+ .description {
16
+ margin: 0 0 var(--gooee-space-2);
17
+ font-size: var(--gooee-text-sm);
18
+ color: var(--gooee-color-fg-muted);
19
+ }
20
+
21
+ .items { display: flex; }
22
+ .vertical { flex-direction: column; }
23
+ .horizontal { flex-wrap: wrap; column-gap: var(--gooee-space-7); }
24
+
25
+ /* Native disabled reaches every box, and each Checkbox dims itself; only the group's own text dims
26
+ here, so no box fades twice. */
27
+ .group[data-disabled] > :is(.legend, .description) { opacity: var(--gooee-disabled-opacity); }
28
+
29
+ /* Each Checkbox's drawn box: red edges on the empty ones, like a RadioGroup with an error. */
30
+ .group[data-invalid] [data-state="off"] { border-color: var(--gooee-color-danger); }
@@ -0,0 +1,88 @@
1
+ 'use client'
2
+
3
+ import { useId, type ReactNode } from 'react'
4
+ import { cx } from '../../internal/cx'
5
+ import { FieldMessage } from '../../internal/FieldMessage'
6
+ import { useControllable } from '../../internal/useControllable'
7
+ import { Checkbox } from '../Checkbox'
8
+ import styles from './CheckboxGroup.module.css'
9
+
10
+ export type CheckboxOption = {
11
+ value: string
12
+ label: ReactNode
13
+ description?: ReactNode
14
+ disabled?: boolean
15
+ }
16
+
17
+ export type CheckboxGroupProps = {
18
+ /** Visible name of the group, rendered as the legend. */
19
+ label: ReactNode
20
+ /** The boxes, in order. */
21
+ options: CheckboxOption[]
22
+ /** Values of the ticked boxes, when you control it. */
23
+ value?: string[]
24
+ /** Starting value when you do not control it. */
25
+ defaultValue?: string[]
26
+ /** Called when a box is ticked or cleared, with the new list of values in option order. */
27
+ onValueChange?: (value: string[]) => void
28
+ /** Muted text under the label, read with the group. */
29
+ description?: ReactNode
30
+ /** Error under the boxes. Marks every box invalid and is read with the group. */
31
+ error?: ReactNode
32
+ /** Form field name shared by every box. Each ticked box sends its value. */
33
+ name?: string
34
+ /** Turns off every box in the group. */
35
+ disabled?: boolean
36
+ /** Stacks the boxes or puts them in a row that wraps. */
37
+ orientation?: 'vertical' | 'horizontal'
38
+ /** Extra class for the root element. */
39
+ className?: string
40
+ }
41
+
42
+ export function CheckboxGroup({
43
+ label,
44
+ options,
45
+ value: valueProp,
46
+ defaultValue = [],
47
+ onValueChange,
48
+ description,
49
+ error,
50
+ name,
51
+ disabled,
52
+ orientation = 'vertical',
53
+ className,
54
+ }: CheckboxGroupProps) {
55
+ const auto = useId()
56
+ const [value, setValue] = useControllable(valueProp, defaultValue, onValueChange)
57
+ const descId = `${auto}-desc`
58
+ const errorId = `${auto}-error`
59
+ const describedBy = [description ? descId : null, error ? errorId : null].filter(Boolean).join(' ')
60
+ const toggle = (v: string, on: boolean) => {
61
+ const next = new Set(value)
62
+ if (on) next.add(v)
63
+ else next.delete(v)
64
+ setValue(options.map((o) => o.value).filter((x) => next.has(x)))
65
+ }
66
+ return (
67
+ <fieldset className={cx(styles.group, className)} disabled={disabled} aria-describedby={describedBy || undefined} data-disabled={disabled || undefined} data-invalid={error ? true : undefined}>
68
+ <legend className={styles.legend}>{label}</legend>
69
+ {description && <p id={descId} className={styles.description}>{description}</p>}
70
+ <div className={cx(styles.items, styles[orientation])}>
71
+ {options.map((o) => (
72
+ <Checkbox
73
+ key={o.value}
74
+ label={o.label}
75
+ description={o.description}
76
+ name={name}
77
+ value={o.value}
78
+ disabled={o.disabled}
79
+ checked={value.includes(o.value)}
80
+ onCheckedChange={(on) => toggle(o.value, on)}
81
+ aria-invalid={error ? true : undefined}
82
+ />
83
+ ))}
84
+ </div>
85
+ <FieldMessage helpId={`${auto}-help`} errorId={errorId} error={error} />
86
+ </fieldset>
87
+ )
88
+ }
@@ -0,0 +1 @@
1
+ export * from './CheckboxGroup'
@@ -0,0 +1,25 @@
1
+ .root {
2
+ display: flex;
3
+ flex-wrap: wrap;
4
+ gap: var(--cluster-row-gap) var(--cluster-gap);
5
+ min-width: 0;
6
+ margin: 0;
7
+ }
8
+
9
+ .root:is(ul, ol) {
10
+ padding: 0;
11
+ list-style: none;
12
+ }
13
+
14
+ .nowrap { flex-wrap: nowrap; }
15
+
16
+ .align-start { align-items: flex-start; }
17
+ .align-center { align-items: center; }
18
+ .align-end { align-items: flex-end; }
19
+ .align-baseline { align-items: baseline; }
20
+ .align-stretch { align-items: stretch; }
21
+
22
+ .justify-start { justify-content: flex-start; }
23
+ .justify-center { justify-content: center; }
24
+ .justify-end { justify-content: flex-end; }
25
+ .justify-between { justify-content: space-between; }
@@ -0,0 +1,26 @@
1
+ import type { ComponentPropsWithRef, CSSProperties } from 'react'
2
+ import { cx } from '../../internal/cx'
3
+ import { space, type Space } from '../../internal/space'
4
+ import styles from './Cluster.module.css'
5
+
6
+ export type ClusterProps = ComponentPropsWithRef<'div'> & {
7
+ /** Space between items, as a step of the space scale (0 to 12, read as --gooee-space-N). */
8
+ gap?: Space
9
+ /** Space between wrapped rows. Defaults to the same step as gap. */
10
+ rowGap?: Space
11
+ /** Lines items up inside a row. "baseline" keeps mixed text sizes on one line. */
12
+ align?: 'start' | 'center' | 'end' | 'baseline' | 'stretch'
13
+ /** Places items along the row. "between" pushes the first and last item to the edges. */
14
+ justify?: 'start' | 'center' | 'end' | 'between'
15
+ /** Lets items flow onto the next row when they run out of room. */
16
+ wrap?: boolean
17
+ /** Element to render, so a row of links can be a nav or a list. */
18
+ as?: 'div' | 'section' | 'nav' | 'header' | 'footer' | 'ul' | 'ol'
19
+ }
20
+
21
+ export function Cluster({ gap = 3, rowGap, align = 'center', justify = 'start', wrap = true, as = 'div', className, style, ...rest }: ClusterProps) {
22
+ // One cast keeps the ref and attribute types simple; every option is a block element.
23
+ const Tag = as as 'div'
24
+ const vars = { '--cluster-gap': space(gap), '--cluster-row-gap': space(rowGap ?? gap), ...style } as CSSProperties
25
+ return <Tag className={cx(styles.root, styles[`align-${align}`], styles[`justify-${justify}`], !wrap && styles.nowrap, className)} style={vars} {...rest} />
26
+ }
@@ -0,0 +1 @@
1
+ export * from './Cluster'
@@ -0,0 +1,74 @@
1
+ /* One card: a header row (title or tabs, and copy) over the code. */
2
+ .root {
3
+ min-width: 0;
4
+ overflow: hidden;
5
+ border: var(--gooee-line) solid var(--gooee-color-border);
6
+ border-radius: var(--gooee-radius-md);
7
+ background: var(--gooee-code-bg);
8
+ color: var(--gooee-code-fg);
9
+ }
10
+
11
+ .head {
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: space-between;
15
+ gap: var(--gooee-space-3);
16
+ min-height: var(--gooee-control-h-md);
17
+ padding: 0 var(--gooee-space-2) 0 var(--gooee-space-4);
18
+ border-bottom: var(--gooee-line) solid var(--gooee-color-border);
19
+ }
20
+
21
+ .title {
22
+ min-width: 0;
23
+ overflow: hidden;
24
+ text-overflow: ellipsis;
25
+ white-space: nowrap;
26
+ font-family: var(--gooee-font-mono);
27
+ font-size: var(--gooee-text-xs);
28
+ color: var(--gooee-color-fg-subtle);
29
+ }
30
+
31
+ .copy { flex: none; margin-left: auto; }
32
+
33
+ .pre {
34
+ margin: 0;
35
+ padding: var(--gooee-space-4) var(--gooee-space-5);
36
+ overflow-x: auto;
37
+ font-family: var(--gooee-font-mono);
38
+ font-size: var(--gooee-text-sm);
39
+ line-height: var(--gooee-leading-normal);
40
+ tab-size: 2;
41
+ }
42
+
43
+ /* The ring goes on the whole block: the root clips its corners, so a ring on the pre would be cut. */
44
+ .pre:focus-visible { outline: none; }
45
+ .root:has(.pre:focus-visible) { box-shadow: var(--gooee-focus-ring); }
46
+
47
+ .pre[data-lines] {
48
+ display: grid;
49
+ grid-template-columns: auto minmax(0, 1fr);
50
+ column-gap: var(--gooee-space-5);
51
+ padding-left: 0;
52
+ }
53
+
54
+ /* Sticks to the left edge while long lines scroll, and is left out when the code is selected. */
55
+ .gutter {
56
+ position: sticky;
57
+ left: 0;
58
+ padding: 0 var(--gooee-space-4) 0 var(--gooee-space-5);
59
+ border-right: var(--gooee-line) solid var(--gooee-color-border);
60
+ background: var(--gooee-code-bg);
61
+ color: var(--gooee-code-gutter);
62
+ text-align: right;
63
+ font-variant-numeric: tabular-nums;
64
+ user-select: none;
65
+ }
66
+
67
+ .code { font: inherit; }
68
+
69
+ .keyword { color: var(--gooee-code-keyword); font-weight: var(--gooee-weight-semibold); }
70
+ .tag { color: var(--gooee-code-tag); font-weight: var(--gooee-weight-semibold); }
71
+ .attr { color: var(--gooee-code-attr); }
72
+ .string { color: var(--gooee-code-string); }
73
+ .number { color: var(--gooee-code-number); }
74
+ .comment { color: var(--gooee-code-comment); font-style: italic; }
@@ -0,0 +1,53 @@
1
+ import type { ReactNode } from 'react'
2
+ import { cx } from '../../internal/cx'
3
+ import { CopyButton } from '../CopyButton'
4
+ import { guessLanguage, tokenize, type CodeLanguage } from './highlight'
5
+ import styles from './CodeBlock.module.css'
6
+
7
+ export type { CodeLanguage } from './highlight'
8
+
9
+ export type CodeBlockProps = {
10
+ /** The code to show and copy. */
11
+ code: string
12
+ /** Sets the colouring. Undefined guesses from the first line. */
13
+ language?: CodeLanguage
14
+ /** File name or short title in the header row. Undefined shows the language. */
15
+ title?: string
16
+ /** Replaces the title in the header row, for example with tabs that switch the code. */
17
+ header?: ReactNode
18
+ /** Shows a line number before each line. They are never copied or read out. */
19
+ lineNumbers?: boolean
20
+ /** Shows the copy button in the header row. */
21
+ copyable?: boolean
22
+ /** Screen reader name for the copy button. */
23
+ copyLabel?: string
24
+ /** Screen reader name for the scrollable code. Undefined uses the title. */
25
+ label?: string
26
+ /** Extra class for the root element. */
27
+ className?: string
28
+ }
29
+
30
+ const NAMES: Record<CodeLanguage, string> = { tsx: 'TSX', html: 'HTML', css: 'CSS', shell: 'Terminal' }
31
+
32
+ export function CodeBlock({ code, language, title, header, lineNumbers = false, copyable = true, copyLabel = 'Copy code', label, className }: CodeBlockProps) {
33
+ const lang = language ?? guessLanguage(code)
34
+ const lines = code.replace(/\n$/, '').split('\n').length
35
+ return (
36
+ <div className={cx(styles.root, className)}>
37
+ <div className={styles.head}>
38
+ {header ?? <span className={styles.title}>{title ?? NAMES[lang]}</span>}
39
+ {copyable && <CopyButton value={code} label={copyLabel} size="sm" className={styles.copy} />}
40
+ </div>
41
+ <pre className={styles.pre} tabIndex={0} aria-label={label ?? (title ? `${title} code` : 'Code example')} data-lines={lineNumbers || undefined}>
42
+ {lineNumbers && (
43
+ <span className={styles.gutter} aria-hidden="true">
44
+ {Array.from({ length: lines }, (_, i) => i + 1).join('\n')}
45
+ </span>
46
+ )}
47
+ <code className={styles.code}>
48
+ {tokenize(code, lang).map((t, i) => (t.kind ? <span key={i} className={styles[t.kind]}>{t.text}</span> : t.text))}
49
+ </code>
50
+ </pre>
51
+ </div>
52
+ )
53
+ }
@@ -0,0 +1,73 @@
1
+ // A small tokenizer for TSX, HTML, CSS and shell: enough to colour short examples. It only splits the
2
+ // text; CodeBlock gives each kind its --gooee-code-* colour.
3
+
4
+ export type CodeLanguage = 'tsx' | 'html' | 'css' | 'shell'
5
+
6
+ export type TokenKind = 'comment' | 'string' | 'tag' | 'attr' | 'keyword' | 'number'
7
+
8
+ export type Token = { text: string; kind?: TokenKind }
9
+
10
+ // TSX and HTML share one set: tags, attributes, strings and both comment styles.
11
+ const MARKUP = new RegExp(
12
+ [
13
+ String.raw`(?<comment>\/\/[^\n]*|\/\*[\s\S]*?\*\/|\{\/\*[\s\S]*?\*\/\}|<!--[\s\S]*?-->)`,
14
+ String.raw`(?<string>'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|` + '`(?:\\\\.|[^`\\\\])*`)',
15
+ String.raw`(?<tag><\/?[A-Za-z][\w.]*|\/?>)`,
16
+ String.raw`(?<attr>\b[A-Za-z][\w-]*(?==))`,
17
+ String.raw`(?<keyword>\b(?:import|from|export|default|const|let|var|function|return|if|else|type|interface|as|async|await|new|true|false|null|undefined|extends|in|of|typeof|void)\b)`,
18
+ String.raw`(?<number>\b\d+(?:\.\d+)?\b)`,
19
+ ].join('|'),
20
+ 'g',
21
+ )
22
+
23
+ const RULES: Record<CodeLanguage, RegExp> = {
24
+ tsx: MARKUP,
25
+ html: MARKUP,
26
+ css: new RegExp(
27
+ [
28
+ String.raw`(?<comment>\/\*[\s\S]*?\*\/)`,
29
+ String.raw`(?<string>'[^'\n]*'|"[^"\n]*")`,
30
+ String.raw`(?<attr>--[\w-]+)`,
31
+ String.raw`(?<keyword>(?<=^|[\s;{])[a-z-]+(?=\s*:))`,
32
+ String.raw`(?<number>-?\b\d+(?:\.\d+)?(?:px|rem|em|ms|s|%|deg|vh|vw|dvh)?\b|#[0-9a-fA-F]{3,8}\b)`,
33
+ ].join('|'),
34
+ 'gm',
35
+ ),
36
+ shell: new RegExp(
37
+ [
38
+ String.raw`(?<comment>#[^\n]*)`,
39
+ String.raw`(?<string>'[^'\n]*'|"[^"\n]*")`,
40
+ String.raw`(?<keyword>^\s*(?:npx|pnpm|yarn|bunx|bun|npm|git|cd)\b)`,
41
+ String.raw`(?<attr>(?<=\s)--?[\w-]+)`,
42
+ ].join('|'),
43
+ 'gm',
44
+ ),
45
+ }
46
+
47
+ /** Guesses the language from the text, when the caller does not say. */
48
+ export function guessLanguage(code: string): CodeLanguage {
49
+ const first = code.trimStart()
50
+ if (/^(npx|pnpm|yarn|bunx|bun|npm|git|cd)\s/.test(first)) return 'shell'
51
+ if (/^(<!--|<html|<!doctype)/i.test(first)) return 'html'
52
+ if (/^(:root|\[data-|@media|\.[\w-]+\s*\{|--[\w-]+\s*:)/.test(first) || /^[\w-]+\s*:\s*[^;]+;/m.test(first)) return 'css'
53
+ return 'tsx'
54
+ }
55
+
56
+ /** The code as tokens, with plain text between them, in order. */
57
+ export function tokenize(code: string, language: CodeLanguage): Token[] {
58
+ const out: Token[] = []
59
+ const re = new RegExp(RULES[language].source, RULES[language].flags)
60
+ let last = 0
61
+ for (let m = re.exec(code); m; m = re.exec(code)) {
62
+ if (m[0] === '') {
63
+ re.lastIndex++
64
+ continue
65
+ }
66
+ const kind = Object.entries(m.groups ?? {}).find(([, v]) => v !== undefined)?.[0] as TokenKind | undefined
67
+ if (m.index > last) out.push({ text: code.slice(last, m.index) })
68
+ out.push({ text: m[0], kind })
69
+ last = m.index + m[0].length
70
+ }
71
+ if (last < code.length) out.push({ text: code.slice(last) })
72
+ return out
73
+ }
@@ -0,0 +1 @@
1
+ export * from './CodeBlock'