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,190 @@
1
+ 'use client'
2
+
3
+ import {
4
+ createContext,
5
+ useContext,
6
+ useId,
7
+ useLayoutEffect,
8
+ useRef,
9
+ useState,
10
+ type KeyboardEvent,
11
+ type ReactNode,
12
+ } from 'react'
13
+ import { prefersReducedMotion } from '../../internal/motion'
14
+ import { cx } from '../../internal/cx'
15
+ import { useFlow } from '../../internal/liquidMatter'
16
+ import { useControllable } from '../../internal/useControllable'
17
+ import styles from './Tabs.module.css'
18
+
19
+ type Ctx = { value: string; set: (v: string) => void; baseId: string }
20
+ const TabsCtx = createContext<Ctx | null>(null)
21
+ const useTabs = () => {
22
+ const c = useContext(TabsCtx)
23
+ if (!c) throw new Error('Tabs parts must be inside <Tabs>')
24
+ return c
25
+ }
26
+ // Odd characters become codes like "_20_", so values never share an id
27
+ const safe = (v: string) => v.replace(/[^a-zA-Z0-9-]/g, (c) => `_${c.charCodeAt(0).toString(16)}_`)
28
+
29
+ export type TabsProps = {
30
+ /** Selected tab value, when you control it. */
31
+ value?: string
32
+ /** Starting tab value when you do not control it. Also needed when you do. */
33
+ defaultValue: string
34
+ /** Called when the selected tab changes, with the new tab value. */
35
+ onValueChange?: (value: string) => void
36
+ /** Extra class for the root element. */
37
+ className?: string
38
+ /** A TabList and its TabPanel elements. */
39
+ children: ReactNode
40
+ }
41
+
42
+ export function Tabs({ value: valueProp, defaultValue, onValueChange, className, children }: TabsProps) {
43
+ const baseId = useId()
44
+ const [value, set] = useControllable(valueProp, defaultValue, onValueChange)
45
+ return (
46
+ <TabsCtx.Provider value={{ value, set, baseId }}>
47
+ <div className={cx(styles.root, className)}>{children}</div>
48
+ </TabsCtx.Provider>
49
+ )
50
+ }
51
+
52
+ export type TabListProps = {
53
+ /** Screen reader name for the row of tabs. */
54
+ label: string
55
+ /** Extra class for the root element. */
56
+ className?: string
57
+ /** The Tab elements. */
58
+ children: ReactNode
59
+ }
60
+
61
+ export function TabList({ label, className, children }: TabListProps) {
62
+ const { value } = useTabs()
63
+ const listRef = useRef<HTMLDivElement>(null)
64
+ const [bar, setBar] = useState<{ x: number; w: number } | null>(null)
65
+ const [ready, setReady] = useState(false)
66
+
67
+ useLayoutEffect(() => {
68
+ const list = listRef.current
69
+ if (!list) return
70
+ const measure = () => {
71
+ const el = list.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
72
+ if (el) setBar({ x: el.offsetLeft, w: el.offsetWidth })
73
+ }
74
+ measure()
75
+ const ro = new ResizeObserver(measure)
76
+ ro.observe(list)
77
+ return () => ro.disconnect()
78
+ }, [value])
79
+
80
+ // A Tab only knows itself, so the list picks the tab stop when the value matches no enabled tab.
81
+ useLayoutEffect(() => {
82
+ const tabs = Array.from(listRef.current?.querySelectorAll<HTMLButtonElement>('[role="tab"]') ?? [])
83
+ const enabled = tabs.filter((t) => !t.disabled)
84
+ const stop = enabled.find((t) => t.getAttribute('aria-selected') === 'true') ?? enabled[0]
85
+ for (const t of tabs) t.tabIndex = t === stop ? 0 : -1
86
+ })
87
+
88
+ useLayoutEffect(() => {
89
+ if (bar && !ready) {
90
+ const r = requestAnimationFrame(() => setReady(true))
91
+ return () => cancelAnimationFrame(r)
92
+ }
93
+ }, [bar, ready])
94
+
95
+ // The underline flows to the new tab: it runs ahead, splits, and what is left drains after it.
96
+ const barRef = useRef<HTMLSpanElement>(null)
97
+ useFlow(listRef, barRef, bar, value, ready, styles.liquid, true)
98
+
99
+ // Automatic activation, per the WAI-ARIA tabs pattern
100
+ const onKeyDown = (e: KeyboardEvent) => {
101
+ const tabs = Array.from(listRef.current?.querySelectorAll<HTMLButtonElement>('[role="tab"]:not(:disabled)') ?? [])
102
+ const i = tabs.indexOf(document.activeElement as HTMLButtonElement)
103
+ if (i < 0) return
104
+ let next = -1
105
+ if (e.key === 'ArrowRight') next = (i + 1) % tabs.length
106
+ else if (e.key === 'ArrowLeft') next = (i - 1 + tabs.length) % tabs.length
107
+ else if (e.key === 'Home') next = 0
108
+ else if (e.key === 'End') next = tabs.length - 1
109
+ if (next < 0) return
110
+ e.preventDefault()
111
+ tabs[next].focus()
112
+ tabs[next].click()
113
+ }
114
+
115
+ return (
116
+ <div className={cx(styles.listScroll, className)}>
117
+ <div ref={listRef} role="tablist" aria-label={label} className={styles.list} onKeyDown={onKeyDown}>
118
+ {children}
119
+ {bar && (
120
+ <span
121
+ ref={barRef}
122
+ className={styles.indicator}
123
+ data-ready={ready || undefined}
124
+ style={{ transform: `translateX(${bar.x}px)`, width: bar.w }}
125
+ aria-hidden="true"
126
+ />
127
+ )}
128
+ </div>
129
+ </div>
130
+ )
131
+ }
132
+
133
+ export type TabProps = {
134
+ /** Picks this tab. Must match the value of its TabPanel. */
135
+ value: string
136
+ /** Stops the tab from being picked. Arrow keys skip it. */
137
+ disabled?: boolean
138
+ /** Text on the tab. */
139
+ children: ReactNode
140
+ }
141
+
142
+ export function Tab({ value, disabled, children }: TabProps) {
143
+ const ctx = useTabs()
144
+ const on = ctx.value === value
145
+ const id = `${ctx.baseId}-tab-${safe(value)}`
146
+ return (
147
+ <button
148
+ id={id}
149
+ type="button"
150
+ role="tab"
151
+ aria-selected={on}
152
+ aria-controls={`${ctx.baseId}-panel-${safe(value)}`}
153
+ tabIndex={on ? 0 : -1}
154
+ disabled={disabled}
155
+ className={styles.tab}
156
+ onClick={() => {
157
+ ctx.set(value)
158
+ document.getElementById(id)?.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: prefersReducedMotion() ? 'auto' : 'smooth' })
159
+ }}
160
+ >
161
+ {children}
162
+ </button>
163
+ )
164
+ }
165
+
166
+ export type TabPanelProps = {
167
+ /** Shows this panel when the Tab with the same value is selected. */
168
+ value: string
169
+ /** Extra class for the panel. */
170
+ className?: string
171
+ /** Content of the panel. It mounts only while the panel shows. */
172
+ children: ReactNode
173
+ }
174
+
175
+ export function TabPanel({ value, className, children }: TabPanelProps) {
176
+ const ctx = useTabs()
177
+ const on = ctx.value === value
178
+ return (
179
+ <div
180
+ id={`${ctx.baseId}-panel-${safe(value)}`}
181
+ role="tabpanel"
182
+ aria-labelledby={`${ctx.baseId}-tab-${safe(value)}`}
183
+ hidden={!on}
184
+ tabIndex={0}
185
+ className={cx(styles.panel, className)}
186
+ >
187
+ {on && children}
188
+ </div>
189
+ )
190
+ }
@@ -0,0 +1 @@
1
+ export * from './Tabs'
@@ -0,0 +1,120 @@
1
+ .root {
2
+ display: inline-flex;
3
+ width: fit-content;
4
+ align-items: center;
5
+ max-width: 100%;
6
+ height: var(--gooee-control-h-sm);
7
+ border: var(--gooee-line) solid var(--gooee-color-border-strong);
8
+ border-radius: var(--gooee-radius-control);
9
+ background: var(--gooee-color-surface);
10
+ font-size: var(--gooee-text-sm);
11
+ white-space: nowrap;
12
+ vertical-align: middle;
13
+ animation: tagIn var(--gooee-motion-slow) var(--gooee-ease-spring);
14
+ transition:
15
+ background-color var(--gooee-motion-base) var(--gooee-ease-out),
16
+ color var(--gooee-motion-base) var(--gooee-ease-out),
17
+ border-color var(--gooee-motion-base) var(--gooee-ease-out);
18
+ }
19
+
20
+ .selected {
21
+ background: var(--gooee-color-inverse);
22
+ border-color: var(--gooee-color-inverse);
23
+ color: var(--gooee-color-inverse-fg);
24
+ }
25
+
26
+ .static,
27
+ .toggle {
28
+ display: inline-flex;
29
+ align-items: center;
30
+ gap: var(--gooee-space-2);
31
+ min-width: 0;
32
+ height: 100%;
33
+ padding: 0 var(--gooee-space-4);
34
+ }
35
+
36
+ .root:has(.remove) .static,
37
+ .root:has(.remove) .toggle { padding-right: var(--gooee-space-1); }
38
+
39
+ .toggle {
40
+ position: relative;
41
+ border: 0;
42
+ background: transparent;
43
+ color: inherit;
44
+ font-size: inherit;
45
+ cursor: pointer;
46
+ border-radius: inherit;
47
+ transition: transform var(--gooee-motion-slow) var(--gooee-ease-spring);
48
+ }
49
+
50
+ .toggle::after {
51
+ content: "";
52
+ position: absolute;
53
+ inset-block: min(0px, calc((100% - var(--gooee-hit-min)) / 2));
54
+ inset-inline: 0;
55
+ }
56
+
57
+ .toggle:active { transform: scale(var(--gooee-press-scale)); }
58
+ .toggle:focus-visible { outline: none; box-shadow: var(--gooee-focus-ring); }
59
+
60
+ .text {
61
+ min-width: 0;
62
+ overflow: hidden;
63
+ text-overflow: ellipsis;
64
+ }
65
+
66
+ .icon { display: inline-flex; font-size: var(--gooee-icon-sm); }
67
+
68
+ .check {
69
+ display: inline-flex;
70
+ width: 0;
71
+ margin-right: calc(var(--gooee-space-2) * -1);
72
+ overflow: hidden;
73
+ font-size: var(--gooee-icon-sm);
74
+ opacity: 0;
75
+ transition:
76
+ width var(--gooee-motion-base) var(--gooee-ease-out),
77
+ margin var(--gooee-motion-base) var(--gooee-ease-out),
78
+ opacity var(--gooee-motion-base) var(--gooee-ease-out);
79
+ }
80
+
81
+ .check[data-on] {
82
+ width: var(--gooee-icon-sm);
83
+ margin-right: 0;
84
+ opacity: 1;
85
+ }
86
+
87
+ .remove {
88
+ position: relative;
89
+ display: grid;
90
+ place-items: center;
91
+ flex: none;
92
+ width: var(--gooee-mini-button);
93
+ height: var(--gooee-mini-button);
94
+ margin-right: var(--gooee-space-1);
95
+ padding: 0;
96
+ border: 0;
97
+ border-radius: var(--gooee-radius-full);
98
+ background: transparent;
99
+ color: inherit;
100
+ font-size: var(--gooee-icon-sm);
101
+ cursor: pointer;
102
+ opacity: 0.7;
103
+ transition: background-color var(--gooee-motion-fast) var(--gooee-ease-out), opacity var(--gooee-motion-fast) var(--gooee-ease-out);
104
+ }
105
+
106
+ .remove::after {
107
+ content: "";
108
+ position: absolute;
109
+ inset: calc((var(--gooee-mini-button) - var(--gooee-hit-min)) / 2);
110
+ }
111
+
112
+ @media (hover: hover) {
113
+ .remove:hover { opacity: 1; background: var(--gooee-color-surface-hover); }
114
+ .selected .remove:hover { background: var(--gooee-color-inverse-hover); }
115
+ }
116
+ .remove:focus-visible { outline: none; opacity: 1; box-shadow: var(--gooee-focus-ring); }
117
+
118
+ @keyframes tagIn {
119
+ from { opacity: 0; transform: scale(0.85); }
120
+ }
@@ -0,0 +1,109 @@
1
+ 'use client'
2
+
3
+ import { useRef, useState, type ReactNode } from 'react'
4
+ import { cx } from '../../internal/cx'
5
+ import { focusables } from '../../internal/focus'
6
+ import { CheckIcon, XIcon } from '../../internal/icons'
7
+ import { easing, motionMs } from '../../internal/motion'
8
+ import styles from './Tag.module.css'
9
+
10
+ export type TagLabels = {
11
+ /** Name of the remove button, built from the tag's text. */
12
+ remove: (name: string) => string
13
+ /** Used as the name when the tag's text is not plain text. */
14
+ item: string
15
+ }
16
+
17
+ const defaultLabels: TagLabels = {
18
+ remove: (name) => `Remove ${name}`,
19
+ item: 'item',
20
+ }
21
+
22
+ export type TagProps = {
23
+ /** Text of the tag. Plain text also names the remove button. */
24
+ children: ReactNode
25
+ /** Shows a remove button. Called after the exit animation ends. */
26
+ onRemove?: () => void
27
+ /** Label for the remove button. Wins over labels.remove, which defaults to "Remove <text>". */
28
+ removeLabel?: string
29
+ /** Makes the tag a toggle chip (aria-pressed). */
30
+ selected?: boolean
31
+ /** Called when a toggle chip is pressed, with the new selected state. */
32
+ onSelectedChange?: (selected: boolean) => void
33
+ /** Icon before the text. Not shown on toggle chips, which show a check. */
34
+ icon?: ReactNode
35
+ /** Screen reader text, so you can translate it. Missing keys use the English defaults. */
36
+ labels?: Partial<TagLabels>
37
+ /** Extra class for the root element. */
38
+ className?: string
39
+ }
40
+
41
+ export function Tag({ children, onRemove, removeLabel, selected, onSelectedChange, icon, labels: labelsProp, className }: TagProps) {
42
+ const labels = { ...defaultLabels, ...labelsProp }
43
+ const ref = useRef<HTMLSpanElement>(null)
44
+ const [leaving, setLeaving] = useState(false)
45
+ const selectable = selected !== undefined
46
+
47
+ // The remove button is about to unmount, so focus moves to the next control (or the one before) instead of the body.
48
+ const finish = () => {
49
+ const el = ref.current
50
+ if (el?.contains(document.activeElement)) {
51
+ const others = focusables(document.body).filter((n) => !el.contains(n))
52
+ const next = others.find((n) => el.compareDocumentPosition(n) & Node.DOCUMENT_POSITION_FOLLOWING)
53
+ const prev = [...others].reverse().find((n) => el.compareDocumentPosition(n) & Node.DOCUMENT_POSITION_PRECEDING)
54
+ ;(next ?? prev)?.focus({ preventScroll: true })
55
+ }
56
+ onRemove?.()
57
+ }
58
+
59
+ // Collapse first so neighbours slide in, then tell the parent
60
+ const remove = () => {
61
+ const el = ref.current
62
+ if (!el || leaving) return
63
+ setLeaving(true)
64
+ const ms = motionMs('base')
65
+ if (ms === 0 || !el.animate) return finish()
66
+ const w = el.offsetWidth
67
+ const anim = el.animate(
68
+ [
69
+ { width: `${w}px`, opacity: 1, transform: 'scale(1)' },
70
+ { width: '0px', opacity: 0, transform: 'scale(0.8)', marginInlineEnd: '0px', paddingInline: '0px', borderWidth: '0px' },
71
+ ],
72
+ { duration: ms, easing: easing('morph'), fill: 'forwards' },
73
+ )
74
+ anim.onfinish = finish
75
+ }
76
+
77
+ const label = typeof children === 'string' ? children : labels.item
78
+ const content = (
79
+ <>
80
+ {selectable ? (
81
+ <span className={styles.check} data-on={selected || undefined} aria-hidden="true">
82
+ <CheckIcon />
83
+ </span>
84
+ ) : (
85
+ icon && <span className={styles.icon}>{icon}</span>
86
+ )}
87
+ <span className={styles.text} title={typeof children === 'string' || typeof children === 'number' ? String(children) : undefined}>
88
+ {children}
89
+ </span>
90
+ </>
91
+ )
92
+
93
+ return (
94
+ <span ref={ref} className={cx(styles.root, selected && styles.selected, className)} data-leaving={leaving || undefined}>
95
+ {selectable ? (
96
+ <button type="button" className={styles.toggle} aria-pressed={selected} onClick={() => onSelectedChange?.(!selected)}>
97
+ {content}
98
+ </button>
99
+ ) : (
100
+ <span className={styles.static}>{content}</span>
101
+ )}
102
+ {onRemove && (
103
+ <button type="button" className={styles.remove} aria-label={removeLabel ?? labels.remove(label)} onClick={remove}>
104
+ <XIcon />
105
+ </button>
106
+ )}
107
+ </span>
108
+ )
109
+ }
@@ -0,0 +1 @@
1
+ export * from './Tag'
@@ -0,0 +1,79 @@
1
+ .root {
2
+ display: flex;
3
+ flex-direction: column;
4
+ min-width: 0;
5
+ }
6
+
7
+ .labelRow {
8
+ display: flex;
9
+ justify-content: space-between;
10
+ align-items: baseline;
11
+ gap: var(--gooee-space-4);
12
+ margin-bottom: var(--gooee-space-3);
13
+ }
14
+
15
+ .label {
16
+ font-size: var(--gooee-text-sm);
17
+ font-weight: var(--gooee-weight-medium);
18
+ }
19
+
20
+ .count {
21
+ font-size: var(--gooee-text-xs);
22
+ font-variant-numeric: tabular-nums;
23
+ color: var(--gooee-color-fg-muted);
24
+ }
25
+
26
+ .textarea {
27
+ display: block;
28
+ width: 100%;
29
+ resize: none;
30
+ padding: var(--gooee-space-4) var(--gooee-space-5);
31
+ border: var(--gooee-line) solid var(--gooee-color-border-strong);
32
+ border-radius: var(--gooee-radius-md);
33
+ background: var(--gooee-color-surface);
34
+ font-size: var(--gooee-text-input);
35
+ line-height: var(--gooee-leading-normal);
36
+ outline: none;
37
+ overflow-y: hidden;
38
+ --gooee-flow-edge: var(--gooee-color-fg);
39
+ transition:
40
+ height var(--gooee-motion-base) var(--gooee-ease-out),
41
+ border-color var(--gooee-motion-fast) var(--gooee-ease-out),
42
+ box-shadow var(--gooee-motion-fast) var(--gooee-ease-out);
43
+ }
44
+
45
+ /* Holds the drawn edge (internal/liquidMore.ts), which a textarea cannot. */
46
+ .box { position: relative; }
47
+
48
+ .edge {
49
+ position: absolute;
50
+ overflow: visible;
51
+ pointer-events: none;
52
+ }
53
+
54
+ .textarea::placeholder { color: var(--gooee-color-fg-subtle); }
55
+ @media (hover: hover) {
56
+ .textarea:hover { border-color: var(--gooee-color-fg-muted); }
57
+ }
58
+
59
+ /* Focused: the dark edge flows round, then Textarea.tsx sets data-edge and this 2px edge holds it. It
60
+ is the field's focus indicator, so it lands at once; a blur fades it. */
61
+ .textarea[data-edge] {
62
+ border-color: var(--gooee-flow-edge);
63
+ box-shadow: inset 0 0 0 calc(var(--gooee-line-focus) - var(--gooee-line)) var(--gooee-flow-edge);
64
+ transition: height var(--gooee-motion-base) var(--gooee-ease-out);
65
+ }
66
+
67
+ .textarea[data-invalid] {
68
+ --gooee-flow-edge: var(--gooee-color-danger);
69
+ border-color: var(--gooee-color-danger);
70
+ border-width: var(--gooee-line-thick);
71
+ }
72
+
73
+ .textarea[data-invalid][data-edge] { box-shadow: inset 0 0 0 calc(var(--gooee-line-focus) - var(--gooee-line-thick)) var(--gooee-flow-edge); }
74
+
75
+ .textarea:disabled {
76
+ background: var(--gooee-color-surface-sunken);
77
+ opacity: 0.6;
78
+ cursor: not-allowed;
79
+ }
@@ -0,0 +1,130 @@
1
+ 'use client'
2
+
3
+ import { useCallback, useEffect, useId, useLayoutEffect, useRef, type ComponentPropsWithRef, type ReactNode } from 'react'
4
+ import { cx } from '../../internal/cx'
5
+ import { FieldMessage } from '../../internal/FieldMessage'
6
+ import { useEdgeFlow } from '../../internal/liquidMore'
7
+ import { mergeRefs } from '../../internal/mergeRefs'
8
+ import styles from './Textarea.module.css'
9
+
10
+ export type TextareaProps = ComponentPropsWithRef<'textarea'> & {
11
+ /** Visible name of the field, also read by screen readers. */
12
+ label: string
13
+ /** Hint under the field. Hidden while an error shows. */
14
+ help?: ReactNode
15
+ /** Error message under the field. Also marks the field invalid. */
16
+ error?: ReactNode
17
+ /** Grows with the text. Default true. */
18
+ autoGrow?: boolean
19
+ /** Height in lines when empty. */
20
+ minRows?: number
21
+ /** Most lines it grows to before it scrolls. Only used with autoGrow. */
22
+ maxRows?: number
23
+ /** Shows a live "n / max" count when maxLength is set. */
24
+ showCount?: boolean
25
+ }
26
+
27
+ export function Textarea({
28
+ label,
29
+ help,
30
+ error,
31
+ autoGrow = true,
32
+ minRows = 3,
33
+ maxRows = 10,
34
+ showCount,
35
+ id,
36
+ className,
37
+ ref,
38
+ onChange,
39
+ value,
40
+ defaultValue,
41
+ maxLength,
42
+ 'aria-describedby': describedByProp,
43
+ ...rest
44
+ }: TextareaProps) {
45
+ const auto = useId()
46
+ const fieldId = id ?? auto
47
+ const helpId = `${fieldId}-help`
48
+ const errorId = `${fieldId}-error`
49
+ const countId = `${fieldId}-count`
50
+ const inner = useRef<HTMLTextAreaElement>(null)
51
+ // Focus draws the dark edge round the field from where it was pressed, or from its start edge for a key.
52
+ const boxRef = useRef<HTMLDivElement>(null)
53
+ useEdgeFlow(inner, boxRef, ':focus', styles.edge)
54
+ const countRef = useRef<HTMLSpanElement>(null)
55
+
56
+ const resize = useCallback(() => {
57
+ const el = inner.current
58
+ if (!el) return
59
+ if (countRef.current) countRef.current.textContent = `${el.value.length} / ${maxLength}`
60
+ if (!autoGrow) return
61
+ const cs = getComputedStyle(el)
62
+ const line = parseFloat(cs.lineHeight) || 24
63
+ const pad = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom)
64
+ const border = parseFloat(cs.borderTopWidth) + parseFloat(cs.borderBottomWidth)
65
+ const prev = el.style.height
66
+ el.style.transition = 'none'
67
+ el.style.height = 'auto'
68
+ const min = line * minRows + pad + border
69
+ const max = line * maxRows + pad + border
70
+ const next = Math.min(Math.max(el.scrollHeight + border, min), max)
71
+ // Restore the old height and force layout, so the transition runs
72
+ el.style.height = prev || `${next}px`
73
+ void el.offsetHeight
74
+ el.style.transition = ''
75
+ el.style.height = `${next}px`
76
+ el.style.overflowY = el.scrollHeight + border > max ? 'auto' : 'hidden'
77
+ }, [autoGrow, minRows, maxRows, maxLength])
78
+
79
+ useLayoutEffect(resize, [resize, value])
80
+
81
+ // A native form reset changes the value without an onChange
82
+ useEffect(() => {
83
+ const form = inner.current?.form
84
+ if (!form) return
85
+ let frame = 0
86
+ const onReset = () => {
87
+ frame = requestAnimationFrame(resize)
88
+ }
89
+ form.addEventListener('reset', onReset)
90
+ return () => {
91
+ form.removeEventListener('reset', onReset)
92
+ cancelAnimationFrame(frame)
93
+ }
94
+ }, [resize])
95
+
96
+ const describedBy = [help && !error ? helpId : null, error ? errorId : null, showCount && maxLength ? countId : null, describedByProp]
97
+ .filter(Boolean)
98
+ .join(' ')
99
+
100
+ return (
101
+ <div className={cx(styles.root, className)}>
102
+ <div className={styles.labelRow}>
103
+ <label htmlFor={fieldId} className={styles.label}>{label}</label>
104
+ {showCount && maxLength !== undefined && (
105
+ <span id={countId} ref={countRef} className={styles.count} aria-live="off" />
106
+ )}
107
+ </div>
108
+ <div ref={boxRef} className={styles.box}>
109
+ <textarea
110
+ id={fieldId}
111
+ ref={mergeRefs(inner, ref)}
112
+ rows={minRows}
113
+ className={styles.textarea}
114
+ data-invalid={error ? true : undefined}
115
+ aria-invalid={error ? true : undefined}
116
+ aria-describedby={describedBy || undefined}
117
+ value={value}
118
+ defaultValue={defaultValue}
119
+ maxLength={maxLength}
120
+ onChange={(e) => {
121
+ resize()
122
+ onChange?.(e)
123
+ }}
124
+ {...rest}
125
+ />
126
+ </div>
127
+ <FieldMessage helpId={helpId} errorId={errorId} help={help} error={error} />
128
+ </div>
129
+ )
130
+ }
@@ -0,0 +1 @@
1
+ export * from './Textarea'
@@ -0,0 +1,21 @@
1
+ /* The sun and the moon share one spot: the one for the other theme turns away and shrinks as the
2
+ current one turns in. */
3
+ .icon {
4
+ display: grid;
5
+ width: 1em;
6
+ height: 1em;
7
+ }
8
+
9
+ .sun,
10
+ .moon {
11
+ grid-area: 1 / 1;
12
+ width: 100%;
13
+ height: 100%;
14
+ transition:
15
+ transform var(--gooee-motion-slower) var(--gooee-ease-spring),
16
+ opacity var(--gooee-motion-base) var(--gooee-ease-out);
17
+ }
18
+
19
+ /* Shows the theme the button switches to: the moon in light, the sun in dark. */
20
+ .icon:not([data-theme-shown="dark"]) .sun { opacity: 0; transform: rotate(90deg) scale(0.4); }
21
+ .icon[data-theme-shown="dark"] .moon { opacity: 0; transform: rotate(-90deg) scale(0.4); }