gooee 0.50.0 → 0.51.1

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 (172) hide show
  1. package/README.md +17 -4
  2. package/package.json +5 -3
  3. package/scripts/add.js +28 -6
  4. package/src/components/Accordion/Accordion.vue +62 -0
  5. package/src/components/Accordion/AccordionItem.vue +45 -0
  6. package/src/components/Accordion/accordionContext.ts +6 -0
  7. package/src/components/Alert/Alert.tsx +7 -27
  8. package/src/components/Alert/Alert.vue +59 -0
  9. package/src/components/AlertDialog/AlertDialog.vue +126 -0
  10. package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
  11. package/src/components/AspectRatio/AspectRatio.vue +17 -0
  12. package/src/components/Avatar/Avatar.vue +56 -0
  13. package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
  14. package/src/components/Badge/Badge.vue +32 -0
  15. package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
  16. package/src/components/Button/Button.vue +130 -0
  17. package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
  18. package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
  19. package/src/components/Card/Card.vue +34 -0
  20. package/src/components/Center/Center.vue +32 -0
  21. package/src/components/Checkbox/Checkbox.tsx +8 -25
  22. package/src/components/Checkbox/Checkbox.vue +108 -0
  23. package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
  24. package/src/components/Cluster/Cluster.vue +34 -0
  25. package/src/components/CodeBlock/CodeBlock.vue +45 -0
  26. package/src/components/Collapsible/Collapsible.vue +59 -0
  27. package/src/components/Container/Container.vue +22 -0
  28. package/src/components/CopyButton/CopyButton.tsx +3 -49
  29. package/src/components/CopyButton/CopyButton.vue +116 -0
  30. package/src/components/Dial/Dial.tsx +12 -120
  31. package/src/components/Dial/Dial.vue +228 -0
  32. package/src/components/Dialog/Dialog.vue +139 -0
  33. package/src/components/Divider/Divider.vue +27 -0
  34. package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
  35. package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
  36. package/src/components/EmptyState/EmptyState.vue +33 -0
  37. package/src/components/Fab/Fab.tsx +4 -14
  38. package/src/components/Fab/Fab.vue +115 -0
  39. package/src/components/Fieldset/Fieldset.vue +42 -0
  40. package/src/components/FormField/FormField.tsx +2 -17
  41. package/src/components/FormField/FormField.vue +64 -0
  42. package/src/components/Grid/Grid.vue +43 -0
  43. package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -143
  44. package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
  45. package/src/components/IconButton/IconButton.vue +25 -0
  46. package/src/components/Input/Input.vue +112 -0
  47. package/src/components/InputGroup/InputGroup.vue +102 -0
  48. package/src/components/Kbd/Kbd.tsx +2 -12
  49. package/src/components/Kbd/Kbd.vue +21 -0
  50. package/src/components/Link/Link.vue +38 -0
  51. package/src/components/LivePill/LivePill.tsx +11 -39
  52. package/src/components/LivePill/LivePill.vue +152 -0
  53. package/src/components/Meter/Meter.vue +88 -0
  54. package/src/components/MorphButton/MorphButton.tsx +11 -67
  55. package/src/components/MorphButton/MorphButton.vue +120 -0
  56. package/src/components/NumberInput/NumberInput.tsx +11 -48
  57. package/src/components/NumberInput/NumberInput.vue +184 -0
  58. package/src/components/Pagination/Pagination.tsx +2 -15
  59. package/src/components/Pagination/Pagination.vue +87 -0
  60. package/src/components/Pagination/range.ts +15 -0
  61. package/src/components/PasswordInput/PasswordInput.vue +53 -0
  62. package/src/components/PickerWheel/DateWheel.vue +48 -0
  63. package/src/components/PickerWheel/PickerWheel.tsx +15 -129
  64. package/src/components/PickerWheel/PickerWheel.vue +77 -0
  65. package/src/components/PickerWheel/TimeWheel.vue +50 -0
  66. package/src/components/PickerWheel/WheelColumn.vue +70 -0
  67. package/src/components/Popover/Popover.vue +108 -0
  68. package/src/components/ProgressBar/ProgressBar.vue +48 -0
  69. package/src/components/Prose/Prose.vue +18 -0
  70. package/src/components/Radio/Radio.vue +49 -0
  71. package/src/components/Radio/RadioGroup.vue +69 -0
  72. package/src/components/Retime/Retime.tsx +7 -40
  73. package/src/components/Retime/Retime.vue +64 -0
  74. package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
  75. package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
  76. package/src/components/ScrollArea/ScrollArea.tsx +17 -129
  77. package/src/components/ScrollArea/ScrollArea.vue +58 -0
  78. package/src/components/SearchInput/SearchInput.tsx +2 -15
  79. package/src/components/SearchInput/SearchInput.vue +70 -0
  80. package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
  81. package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
  82. package/src/components/Select/Select.tsx +16 -47
  83. package/src/components/Select/Select.vue +236 -0
  84. package/src/components/Sheet/Sheet.tsx +52 -231
  85. package/src/components/Sheet/Sheet.vue +249 -0
  86. package/src/components/Skeleton/Skeleton.vue +38 -0
  87. package/src/components/Slider/Slider.tsx +25 -84
  88. package/src/components/Slider/Slider.vue +113 -0
  89. package/src/components/Spinner/Spinner.vue +30 -0
  90. package/src/components/Split/Split.vue +34 -0
  91. package/src/components/SplitFlap/SplitFlap.tsx +11 -175
  92. package/src/components/SplitFlap/SplitFlap.vue +52 -0
  93. package/src/components/Stack/Stack.vue +22 -0
  94. package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
  95. package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
  96. package/src/components/Switch/Switch.tsx +6 -75
  97. package/src/components/Switch/Switch.vue +66 -0
  98. package/src/components/Table/Table.module.css +12 -3
  99. package/src/components/Table/Table.tsx +8 -59
  100. package/src/components/Table/Table.vue +274 -0
  101. package/src/components/TableOfContents/TableOfContents.vue +90 -0
  102. package/src/components/Tabs/Tab.vue +37 -0
  103. package/src/components/Tabs/TabList.vue +47 -0
  104. package/src/components/Tabs/TabPanel.vue +26 -0
  105. package/src/components/Tabs/Tabs.module.css +2 -2
  106. package/src/components/Tabs/Tabs.tsx +11 -84
  107. package/src/components/Tabs/Tabs.vue +33 -0
  108. package/src/components/Tabs/tabsContext.ts +15 -0
  109. package/src/components/Tag/Tag.tsx +6 -26
  110. package/src/components/Tag/Tag.vue +63 -0
  111. package/src/components/Textarea/Textarea.tsx +2 -22
  112. package/src/components/Textarea/Textarea.vue +120 -0
  113. package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
  114. package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
  115. package/src/components/Toast/Toast.tsx +34 -264
  116. package/src/components/Toast/Toast.vue +138 -0
  117. package/src/components/Toast/ToastItem.vue +108 -0
  118. package/src/components/Toggle/Toggle.vue +52 -0
  119. package/src/components/Tooltip/Tooltip.tsx +17 -48
  120. package/src/components/Tooltip/Tooltip.vue +95 -0
  121. package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
  122. package/src/internal/FieldMessage.vue +41 -0
  123. package/src/internal/Roll.vue +20 -0
  124. package/src/internal/focus.ts +4 -47
  125. package/src/internal/icons.module.css +39 -27
  126. package/src/internal/layers.ts +7 -61
  127. package/src/internal/motion/alert.ts +17 -0
  128. package/src/internal/motion/buttonGroup.ts +21 -0
  129. package/src/internal/motion/checkbox.ts +39 -0
  130. package/src/internal/motion/collapseOut.ts +26 -0
  131. package/src/internal/motion/copyButton.ts +48 -0
  132. package/src/internal/motion/dial.ts +137 -0
  133. package/src/internal/motion/fab.ts +14 -0
  134. package/src/internal/motion/floating.ts +58 -0
  135. package/src/internal/motion/focus.ts +53 -0
  136. package/src/internal/motion/formField.ts +19 -0
  137. package/src/internal/motion/holdToConfirm.ts +147 -0
  138. package/src/internal/motion/keys.ts +42 -0
  139. package/src/internal/motion/layers.ts +78 -0
  140. package/src/internal/motion/listbox.ts +69 -0
  141. package/src/internal/motion/livePill.ts +71 -0
  142. package/src/internal/motion/menuKeys.ts +58 -0
  143. package/src/internal/motion/morphButton.ts +71 -0
  144. package/src/internal/motion/numberInput.ts +57 -0
  145. package/src/internal/motion/pickerWheel.ts +166 -0
  146. package/src/internal/motion/retime.ts +45 -0
  147. package/src/internal/motion/ruler.ts +57 -0
  148. package/src/internal/motion/scrollArea.ts +133 -0
  149. package/src/internal/motion/scrubLook.ts +15 -0
  150. package/src/internal/motion/segmented.ts +63 -0
  151. package/src/internal/motion/sheetDetents.ts +271 -0
  152. package/src/internal/motion/slider.ts +108 -0
  153. package/src/internal/motion/splitFlap.ts +205 -0
  154. package/src/internal/motion/swipeDeck.ts +236 -0
  155. package/src/internal/motion/switchThumb.ts +83 -0
  156. package/src/internal/motion/table.ts +77 -0
  157. package/src/internal/motion/tabs.ts +105 -0
  158. package/src/internal/motion/textarea.ts +22 -0
  159. package/src/internal/motion/themeIcon.ts +91 -0
  160. package/src/internal/motion/themeReveal.ts +71 -0
  161. package/src/internal/motion/toast.ts +291 -0
  162. package/src/internal/motion/tooltip.ts +58 -0
  163. package/src/internal/themeReveal.ts +3 -61
  164. package/src/internal/useFloating.ts +9 -49
  165. package/src/internal/useScrub.ts +1 -13
  166. package/src/internal/vue/trigger.ts +18 -0
  167. package/src/internal/vue/useFloating.ts +38 -0
  168. package/src/internal/vue/usePresence.ts +21 -0
  169. package/src/internal/vue/useScrub.ts +40 -0
  170. package/src/internal/vueIcons.ts +134 -0
  171. package/src/tokens.css +5 -0
  172. package/src/internal/relativeTime.ts +0 -26
@@ -3,22 +3,12 @@
3
3
  import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type ReactNode } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
5
  import { clamp, pull, wheelSteps, wrap } from '../../internal/feel'
6
+ import { columnScrub, columnState, dateWheel, drumRows, timeWheel, today, type ColumnState, type WheelColumn } from '../../internal/motion/pickerWheel'
6
7
  import { useControllable } from '../../internal/useControllable'
7
8
  import { ink, tokenNumber, useOnChange, useScrub } from '../../internal/useScrub'
8
9
  import styles from './PickerWheel.module.css'
9
10
 
10
- export type PickerWheelColumn = {
11
- /** Name screen readers hear for this column, such as "Hour". */
12
- label: string
13
- /** The rows, top to bottom. */
14
- options: string[]
15
- /** The last row runs on into the first, as hours do. */
16
- loop?: boolean
17
- /** Rows, by index, drawn stronger, such as :00 and :30, or today. Page Up and Page Down jump between them. */
18
- strong?: number[]
19
- /** Twice as wide, for words such as month names. */
20
- wide?: boolean
21
- }
11
+ export type PickerWheelColumn = WheelColumn
22
12
 
23
13
  export type PickerWheelProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onChange' | 'children'> & {
24
14
  /** Visible name of the whole wheel, read by screen readers as the group's name. */
@@ -41,9 +31,6 @@ export type PickerWheelProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue'
41
31
  haptics?: boolean
42
32
  }
43
33
 
44
- // Rows drawn either side of the band. At the tilt token's 18 degrees a row this far round is nearly edge on.
45
- const SPAN = 4
46
-
47
34
  type ColumnProps = {
48
35
  column: PickerWheelColumn
49
36
  index: number
@@ -57,71 +44,23 @@ function Column({ column, index, onChange, onShown, haptics }: ColumnProps) {
57
44
  const { options, loop = false } = column
58
45
  const n = options.length
59
46
  const strong = new Set(column.strong ?? [])
60
- const typed = useRef({ text: '', at: 0 })
61
- const row = useRef(0)
47
+ const state = useRef<ColumnState>(null)
48
+ state.current ??= columnState(index)
49
+ const st = state.current
62
50
  const wheel = useRef(wheelSteps())
63
- // In a loop the position runs on past the last row; the row shown is the position folded into the list.
64
- const nearest = (t: number, i: number) => (loop ? Math.round(t) + ((((i - wrap(Math.round(t), n)) % n) + n + Math.floor(n / 2)) % n) - Math.floor(n / 2) : i)
65
- const fit = (v: number) => (loop ? v : clamp(v, 0, n - 1))
66
- const rested = useRef(index)
67
- const strongFrom = (t: number, dir: 1 | -1) => {
68
- const i = wrap(Math.round(t), n)
69
- for (let d = 1; d < n; d++) if (strong.has(wrap(i + dir * d, n)) && (loop || (i + dir * d >= 0 && i + dir * d < n))) return fit(Math.round(t) + dir * d)
70
- return fit(Math.round(t) + dir * 5)
71
- }
72
51
 
52
+ // The keys, tap and wheel of one column (motion/pickerWheel.ts) on the shared scrubber.
73
53
  const sc = useScrub({
74
- value: nearest(rested.current, clamp(index, 0, n - 1)),
75
- min: loop ? undefined : 0,
76
- max: loop ? undefined : n - 1,
77
- edge: 0.6,
78
- land: (p) => fit(Math.round(p)),
79
- maxSpeed: 40,
80
- move: (e, last) => -(e.clientY - last.y) / (row.current || 1),
81
- // The APG spinbutton keys: Up is the next, higher value and Down the one before.
82
- key: (k, t) => {
83
- if (k === 'ArrowUp') return fit(Math.round(t) + 1)
84
- if (k === 'ArrowDown') return fit(Math.round(t) - 1)
85
- if (k === 'PageUp') return strongFrom(t, 1)
86
- if (k === 'PageDown') return strongFrom(t, -1)
87
- if (k === 'Home') return nearest(t, 0)
88
- if (k === 'End') return nearest(t, n - 1)
89
- if (k.length === 1 && /\S/.test(k)) {
90
- const now = performance.now()
91
- typed.current = { text: (now - typed.current.at < 800 ? typed.current.text : '') + k.toLowerCase(), at: now }
92
- const q = typed.current.text
93
- // A padded number answers to its plain digits, so "5" finds "05" before "50".
94
- const said = (o: string) => (/^\d+$/.test(o) ? String(Number(o)) : o.toLowerCase())
95
- const exact = options.findIndex((o) => o.toLowerCase() === q || said(o) === q)
96
- const hit = exact >= 0 ? exact : options.findIndex((o) => o.toLowerCase().startsWith(q))
97
- return hit >= 0 ? nearest(t, hit) : null
98
- }
99
- return null
100
- },
101
- tap: (e, at) => {
102
- const r = e.currentTarget.getBoundingClientRect()
103
- const tilt = (tokenNumber(e.currentTarget, '--gooee-wheel-tilt') * Math.PI) / 180
104
- const radius = row.current / 2 / Math.tan(tilt / 2)
105
- const dy = e.clientY - (r.top + r.height / 2)
106
- if (!tilt || !radius) return null
107
- return fit(Math.round(at + Math.asin(clamp(dy / radius, -1, 1)) / tilt))
108
- },
109
- // Only a focused column takes the wheel, and at an end it lets the page scroll on.
110
- wheel: (e, t, focused) => {
111
- if (!focused || !e.deltaY) return null
112
- const dir = Math.sign(e.deltaY)
113
- if (!loop && ((dir > 0 && t >= n - 1) || (dir < 0 && t <= 0))) return null
114
- return fit(t + wheel.current(e.deltaY * (e.deltaMode === 1 ? 40 : 1)))
115
- },
54
+ ...columnScrub(column, index, st, wheel.current),
116
55
  onSettle: (to) => {
117
- rested.current = to
56
+ st.rested = to
118
57
  onChange(wrap(to, n))
119
58
  },
120
59
  haptics,
121
60
  })
122
61
 
123
62
  useLayoutEffect(() => {
124
- row.current = tokenNumber(sc.ref.current, '--gooee-hit-min')
63
+ st.row = tokenNumber(sc.ref.current, '--gooee-hit-min')
125
64
  }, [sc.ref])
126
65
 
127
66
  // The list got shorter (31 days to 30): stay on the last row instead of jumping.
@@ -130,22 +69,18 @@ function Column({ column, index, onChange, onShown, haptics }: ColumnProps) {
130
69
  if (lastN.current === n) return
131
70
  const i = Math.min(wrap(Math.round(sc.target()), lastN.current), n - 1)
132
71
  lastN.current = n
133
- rested.current = i
72
+ st.rested = i
134
73
  sc.place(i)
135
74
  }, [n, sc])
136
75
 
137
- const settled = wrap(Math.round(rested.current), n)
76
+ const settled = wrap(Math.round(st.rested), n)
138
77
  const shown = wrap(Math.round(sc.at), n)
139
78
  const told = useRef(onShown)
140
79
  told.current = onShown
141
80
  useEffect(() => told.current(shown), [shown])
142
81
 
143
82
  const grip = pull(sc.at - Math.round(sc.at), 0.5)
144
- const rows: { k: number; d: number; i: number }[] = []
145
- for (let k = Math.floor(sc.at) - SPAN; k <= Math.ceil(sc.at) + SPAN; k++) {
146
- if (!loop && (k < 0 || k > n - 1)) continue
147
- rows.push({ k, d: k - sc.at, i: wrap(k, n) })
148
- }
83
+ const rows = drumRows(sc.at, n, loop)
149
84
 
150
85
  return (
151
86
  <div
@@ -218,8 +153,6 @@ export function PickerWheel({ label, columns, value: valueProp, defaultValue, on
218
153
  )
219
154
  }
220
155
 
221
- const pad = (v: number) => String(v).padStart(2, '0')
222
-
223
156
  export type TimeWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defaultValue' | 'onValueChange' | 'onScrub' | 'formatValue'> & {
224
157
  /** The time as "HH:mm" in 24 hours, when you control it. */
225
158
  value?: string
@@ -240,38 +173,10 @@ export type TimeWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defau
240
173
  /** PickerWheel set up for a time: hour, minute and, on a 12 hour clock, AM or PM. */
241
174
  export function TimeWheel({ value: valueProp, defaultValue = '09:00', onValueChange, onScrub, hourCycle = 12, minuteStep = 1, strong = [0, 30], ...rest }: TimeWheelProps) {
242
175
  const [value, setValue] = useControllable(valueProp, defaultValue, onValueChange)
243
- const twelve = hourCycle === 12
244
- const minutes = Array.from({ length: Math.ceil(60 / minuteStep) }, (_, i) => i * minuteStep)
245
- const columns: PickerWheelColumn[] = [
246
- { label: 'Hour', options: twelve ? Array.from({ length: 12 }, (_, i) => String(i + 1)) : Array.from({ length: 24 }, (_, i) => pad(i)), loop: true },
247
- { label: 'Minute', options: minutes.map(pad), loop: true, strong: strong.map((m) => minutes.indexOf(m)).filter((i) => i >= 0) },
248
- ...(twelve ? [{ label: 'AM or PM', options: ['AM', 'PM'] }] : []),
249
- ]
250
- const toRows = (hhmm: string) => {
251
- const [h = 0, m = 0] = hhmm.split(':').map(Number)
252
- const mi = clamp(Math.round(m / minuteStep), 0, minutes.length - 1)
253
- return twelve ? [(h % 12 || 12) - 1, mi, h >= 12 ? 1 : 0] : [h, mi]
254
- }
255
- const toTime = (rows: number[]) => {
256
- const h = twelve ? ((rows[0] + 1) % 12) + (rows[2] ? 12 : 0) : rows[0]
257
- return `${pad(h)}:${pad(minutes[rows[1]])}`
258
- }
259
- const show = (rows: number[]) => (twelve ? `${rows[0] + 1}:${pad(minutes[rows[1]])} ${rows[2] ? 'PM' : 'AM'}` : `${pad(rows[0])}:${pad(minutes[rows[1]])}`)
176
+ const { columns, toRows, toTime, show } = timeWheel(hourCycle, minuteStep, strong)
260
177
  return <PickerWheel {...rest} columns={columns} value={toRows(value)} onValueChange={(rows) => setValue(toTime(rows))} onScrub={onScrub && ((rows) => onScrub(toTime(rows)))} formatValue={show} />
261
178
  }
262
179
 
263
- const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
264
- const daysIn = (month: number, year: number) => new Date(year, month + 1, 0).getDate()
265
- const iso = (y: number, m: number, d: number) => `${y}-${pad(m + 1)}-${pad(d)}`
266
- const parse = (s: string) => {
267
- const [y, m, d] = s.split('-').map(Number)
268
- return { y, m: m - 1, d }
269
- }
270
- const today = () => {
271
- const t = new Date()
272
- return iso(t.getFullYear(), t.getMonth(), t.getDate())
273
- }
274
-
275
180
  export type DateWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defaultValue' | 'onValueChange' | 'onScrub' | 'formatValue'> & {
276
181
  /** The date as "YYYY-MM-DD", when you control it. */
277
182
  value?: string
@@ -293,31 +198,12 @@ export type DateWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defau
293
198
  export function DateWheel({ value: valueProp, defaultValue, onValueChange, onScrub, fromYear, toYear, strong, ...rest }: DateWheelProps) {
294
199
  const now = today()
295
200
  const [value, setValue] = useControllable(valueProp, defaultValue ?? now, onValueChange)
296
- const first = fromYear ?? parse(now).y - 100
297
- const last = toYear ?? parse(now).y + 10
298
- const years = Array.from({ length: Math.max(1, last - first + 1) }, (_, i) => first + i)
299
- const at = parse(value)
300
- const y = clamp(at.y, first, last)
301
- const count = daysIn(at.m, y)
302
- const marks = (strong ?? [now]).map(parse)
303
- const columns: PickerWheelColumn[] = [
304
- { label: 'Day', options: Array.from({ length: count }, (_, i) => String(i + 1)), loop: true, strong: marks.filter((s) => s.y === y && s.m === at.m).map((s) => s.d - 1) },
305
- { label: 'Month', options: MONTHS, loop: true, wide: true, strong: marks.filter((s) => s.y === y).map((s) => s.m) },
306
- { label: 'Year', options: years.map(String), strong: marks.map((s) => years.indexOf(s.y)).filter((i) => i >= 0) },
307
- ]
308
- const toDate = (rows: number[]) => {
309
- const yy = years[rows[2]]
310
- return iso(yy, rows[1], Math.min(rows[0] + 1, daysIn(rows[1], yy)))
311
- }
312
- const show = (rows: number[]) => {
313
- const p = parse(toDate(rows))
314
- return new Date(p.y, p.m, p.d).toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' })
315
- }
201
+ const { columns, rows, toDate, show } = dateWheel(value, now, fromYear, toYear, strong)
316
202
  return (
317
203
  <PickerWheel
318
204
  {...rest}
319
205
  columns={columns}
320
- value={[Math.min(at.d, count) - 1, at.m, years.indexOf(y)]}
206
+ value={rows}
321
207
  onValueChange={(rows) => setValue(toDate(rows))}
322
208
  onScrub={onScrub && ((rows) => onScrub(toDate(rows)))}
323
209
  formatValue={show}
@@ -0,0 +1,77 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, useId, useSlots, watch } from 'vue'
3
+ import { clamp } from '../../internal/feel'
4
+ import type { WheelColumn as PickerWheelColumn } from '../../internal/motion/pickerWheel'
5
+ import WheelColumn from './WheelColumn.vue'
6
+ import styles from './PickerWheel.module.css'
7
+
8
+ // The Vue PickerWheel: the same look (PickerWheel.module.css), drag, coast and landing as the React one.
9
+
10
+ export type { PickerWheelColumn }
11
+
12
+ const props = withDefaults(
13
+ defineProps<{
14
+ /** Visible name of the whole wheel, read by screen readers as the group's name. */
15
+ label: string
16
+ /** The columns, left to right. */
17
+ columns: PickerWheelColumn[]
18
+ /** Starting rows when there is no v-model. Undefined starts on the first row of each. */
19
+ defaultValue?: number[]
20
+ /** Turns the rows into a large readout above the wheel. No readout when left out. */
21
+ formatValue?: (value: number[]) => string
22
+ /** A line under the label and readout, such as what the choice means. The detail slot replaces it. */
23
+ detail?: string
24
+ /** A short buzz on each row while it turns, on phones that can (Android). */
25
+ haptics?: boolean
26
+ }>(),
27
+ { haptics: false },
28
+ )
29
+ const emit = defineEmits<{ /** The rows in the band while the wheel still turns. */ scrub: [value: number[]] }>()
30
+ const slots = useSlots()
31
+
32
+ /** The chosen row of each column, set once a column comes to rest. Use v-model, or leave it out and the wheel keeps its own rows. */
33
+ const model = defineModel<number[]>()
34
+ const local = ref(props.defaultValue ?? props.columns.map(() => 0))
35
+ const raw = computed({
36
+ get: () => model.value ?? local.value,
37
+ set: (next: number[]) => {
38
+ local.value = next
39
+ model.value = next
40
+ },
41
+ })
42
+
43
+ const labelId = useId()
44
+ const detailId = useId()
45
+ const value = computed(() => props.columns.map((c, i) => clamp(raw.value[i] ?? 0, 0, c.options.length - 1)))
46
+ // The rows as last set, so two columns that settle at once both count.
47
+ let latest = value.value
48
+ watch(value, (v) => (latest = v), { flush: 'sync' })
49
+ const onChange = (i: number, row: number) => {
50
+ if (latest[i] === row) return
51
+ const next = latest.map((v, j) => (j === i ? row : v))
52
+ latest = next
53
+ raw.value = next
54
+ }
55
+ const live = ref(value.value)
56
+ const onShown = (i: number, row: number) => {
57
+ if (live.value[i] !== row) live.value = live.value.map((v, j) => (j === i ? row : v))
58
+ }
59
+ watch(
60
+ () => live.value.join(','),
61
+ () => emit('scrub', live.value),
62
+ )
63
+ const hasDetail = computed(() => !!(props.detail || slots.detail))
64
+ </script>
65
+
66
+ <template>
67
+ <div :class="styles.root">
68
+ <div :class="styles.head">
69
+ <span :id="labelId" :class="styles.label">{{ label }}</span>
70
+ <span v-if="formatValue" :class="styles.readout">{{ formatValue(live) }}</span>
71
+ <span v-if="hasDetail" :id="detailId" :class="styles.detail"><slot name="detail">{{ detail }}</slot></span>
72
+ </div>
73
+ <div :class="styles.wheel" role="group" :aria-labelledby="labelId" :aria-describedby="hasDetail ? detailId : undefined">
74
+ <WheelColumn v-for="(c, i) in columns" :key="i" :column="c" :index="value[i]" :haptics="haptics" @change="onChange(i, $event)" @shown="onShown(i, $event)" />
75
+ </div>
76
+ </div>
77
+ </template>
@@ -0,0 +1,50 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref } from 'vue'
3
+ import { timeWheel } from '../../internal/motion/pickerWheel'
4
+ import PickerWheel from './PickerWheel.vue'
5
+
6
+ // PickerWheel set up for a time: hour, minute and, on a 12 hour clock, AM or PM (the Vue TimeWheel).
7
+ // Other props (detail, haptics) go to the PickerWheel.
8
+
9
+ const props = withDefaults(
10
+ defineProps<{
11
+ /** Visible name of the whole wheel, read by screen readers as the group's name. */
12
+ label: string
13
+ /** Starting time when there is no v-model. */
14
+ defaultValue?: string
15
+ /** 12 shows AM and PM; 24 shows hours 00 to 23. */
16
+ hourCycle?: 12 | 24
17
+ /** Minutes between two rows. */
18
+ minuteStep?: number
19
+ /** Minutes drawn stronger. Page Up and Page Down jump between them. */
20
+ strong?: number[]
21
+ }>(),
22
+ { defaultValue: '09:00', hourCycle: 12, minuteStep: 1, strong: () => [0, 30] },
23
+ )
24
+ const emit = defineEmits<{ /** The time in the band while the wheel still turns, as "HH:mm". */ scrub: [value: string] }>()
25
+
26
+ /** The time as "HH:mm" in 24 hours, set once the wheel comes to rest. Use v-model, or leave it out and the wheel keeps its own time. */
27
+ const model = defineModel<string>()
28
+ const local = ref(props.defaultValue)
29
+ const value = computed({
30
+ get: () => model.value ?? local.value,
31
+ set: (next: string) => {
32
+ local.value = next
33
+ model.value = next
34
+ },
35
+ })
36
+ const wheel = computed(() => timeWheel(props.hourCycle, props.minuteStep, props.strong))
37
+ </script>
38
+
39
+ <template>
40
+ <PickerWheel
41
+ :label="label"
42
+ :columns="wheel.columns"
43
+ :model-value="wheel.toRows(value)"
44
+ :format-value="wheel.show"
45
+ @update:model-value="(rows) => rows && (value = wheel.toTime(rows))"
46
+ @scrub="emit('scrub', wheel.toTime($event))"
47
+ >
48
+ <template v-for="(_, name) in $slots" #[name]><slot :name="name" /></template>
49
+ </PickerWheel>
50
+ </template>
@@ -0,0 +1,70 @@
1
+ <script setup lang="ts">
2
+ import { computed, onMounted, reactive, watch } from 'vue'
3
+ import { pull, wheelSteps, wrap } from '../../internal/feel'
4
+ import { columnScrub, columnState, drumRows, type WheelColumn } from '../../internal/motion/pickerWheel'
5
+ import { ink, tokenNumber } from '../../internal/motion/scrubLook'
6
+ import { useScrub } from '../../internal/vue/useScrub'
7
+ import styles from './PickerWheel.module.css'
8
+
9
+ // One column of the Vue PickerWheel: its rows are the marks. A drag follows the hand; a let-go lands on a row.
10
+
11
+ const props = defineProps<{ column: WheelColumn; index: number; haptics: boolean }>()
12
+ const emit = defineEmits<{ change: [index: number]; shown: [index: number] }>()
13
+
14
+ const n = computed(() => props.column.options.length)
15
+ const strong = computed(() => new Set(props.column.strong ?? []))
16
+ const st = reactive(columnState(props.index))
17
+ const wheel = wheelSteps()
18
+
19
+ // The keys, tap and wheel of one column (motion/pickerWheel.ts) on the shared scrubber.
20
+ const sc = useScrub(() => ({
21
+ ...columnScrub(props.column, props.index, st, wheel),
22
+ onSettle: (to: number) => {
23
+ st.rested = to
24
+ emit('change', wrap(to, n.value))
25
+ },
26
+ haptics: props.haptics,
27
+ }))
28
+ const scrubEl = sc.el
29
+ onMounted(() => (st.row = tokenNumber(scrubEl.value, '--gooee-hit-min')))
30
+
31
+ // The list got shorter (31 days to 30): stay on the last row instead of jumping.
32
+ watch(
33
+ n,
34
+ (now, was) => {
35
+ const i = Math.min(wrap(Math.round(sc.target()), was), now - 1)
36
+ st.rested = i
37
+ sc.place(i)
38
+ },
39
+ { flush: 'post' },
40
+ )
41
+
42
+ const settled = computed(() => wrap(Math.round(st.rested), n.value))
43
+ const shown = computed(() => wrap(Math.round(sc.at.value), n.value))
44
+ watch(shown, (i) => emit('shown', i), { immediate: true })
45
+
46
+ const grip = computed(() => pull(sc.at.value - Math.round(sc.at.value), 0.5))
47
+ const rows = computed(() => drumRows(sc.at.value, n.value, !!props.column.loop))
48
+ </script>
49
+
50
+ <template>
51
+ <div
52
+ ref="scrubEl"
53
+ :class="styles.column"
54
+ role="spinbutton"
55
+ tabindex="0"
56
+ :aria-label="column.label"
57
+ :aria-valuenow="settled"
58
+ :aria-valuetext="column.options[settled]"
59
+ :aria-valuemin="0"
60
+ :aria-valuemax="n - 1"
61
+ :data-wide="column.wide || undefined"
62
+ :data-moving="sc.moving.value || undefined"
63
+ v-on="sc.handlers"
64
+ >
65
+ <span :class="styles.band" :style="{ '--grip': grip.toFixed(3) }" aria-hidden="true" />
66
+ <div :class="styles.drum" aria-hidden="true">
67
+ <span v-for="r in rows" :key="r.k" :class="styles.row" :data-strong="strong.has(r.i) || undefined" :style="{ '--d': r.d.toFixed(3), color: ink(pull(r.d, 1)) }">{{ column.options[r.i] }}</span>
68
+ </div>
69
+ </div>
70
+ </template>
@@ -0,0 +1,108 @@
1
+ <script setup lang="ts">
2
+ import { onBeforeUnmount, ref, shallowRef, useId, watch, type VNode } from 'vue'
3
+ import type { Align, Side } from '../../internal/motion/floating'
4
+ import { trapFocus } from '../../internal/motion/focus'
5
+ import { dismissable } from '../../internal/motion/layers'
6
+ import { createLiquid } from '../../internal/motion/liquid'
7
+ import { useFloating } from '../../internal/vue/useFloating'
8
+ import { usePresence } from '../../internal/vue/usePresence'
9
+ import { cloneTrigger, elementRef, firstNode } from '../../internal/vue/trigger'
10
+ import { XIcon } from '../../internal/vueIcons'
11
+ import styles from './Popover.module.css'
12
+
13
+ // The Vue Popover: the same look (Popover.module.css), growth, dismiss and focus as the React one.
14
+ // The trigger slot is one element, such as a Button, that opens and closes it on click.
15
+ // Other attributes, such as class, go to the panel.
16
+ defineOptions({ inheritAttrs: false })
17
+
18
+ const props = withDefaults(
19
+ defineProps<{
20
+ /** Visible heading, also the dialog's accessible name. The title slot replaces it. */
21
+ title?: string
22
+ /** Preferred side of the trigger. It flips when there is no room. */
23
+ side?: Side
24
+ /** How the panel lines up with the trigger along that side. */
25
+ align?: Align
26
+ /** Label for the close button. */
27
+ closeLabel?: string
28
+ }>(),
29
+ { side: 'bottom', align: 'start', closeLabel: 'Close' },
30
+ )
31
+ /** Whether the panel is open. Use v-model:open to control it; without it the popover keeps its own state. */
32
+ const open = defineModel<boolean>('open', { default: false })
33
+ const slots = defineSlots<{ trigger?: () => VNode[]; default?: () => unknown; title?: () => unknown }>()
34
+
35
+ const id = useId()
36
+ const anchor = shallowRef<HTMLElement | null>(null)
37
+ const setAnchor = elementRef(anchor)
38
+ const panel = ref<HTMLElement | null>(null)
39
+ const close = () => (open.value = false)
40
+ const { mounted, state } = usePresence(open, 'morph-out')
41
+ const { style, side: placed, ready } = useFloating(anchor, panel, mounted, () => ({ side: props.side, align: props.align, offset: 8 }))
42
+ // Vue sets a bare number as no length at all, so the place gets its unit here.
43
+ // The panel grows out of its trigger and folds back into it.
44
+ const liquid = createLiquid(
45
+ () => panel.value,
46
+ () => anchor.value,
47
+ )
48
+ watch([state, () => mounted.value && ready.value], ([s, on]) => on && liquid.play(s), { flush: 'post' })
49
+
50
+ let releaseDismiss = () => {}
51
+ watch(open, (now) => {
52
+ releaseDismiss()
53
+ releaseDismiss = now ? dismissable(() => [anchor.value, panel.value], close) : () => {}
54
+ })
55
+ // Focus moves in while it is open, and goes back when it closes.
56
+ let releaseTrap = () => {}
57
+ watch(
58
+ () => open.value && mounted.value,
59
+ (on) => {
60
+ releaseTrap()
61
+ releaseTrap = on && panel.value ? trapFocus(panel.value) : () => {}
62
+ },
63
+ { flush: 'post' },
64
+ )
65
+
66
+ onBeforeUnmount(() => {
67
+ releaseDismiss()
68
+ releaseTrap()
69
+ liquid.destroy()
70
+ })
71
+
72
+ // The trigger is the slot's own element, given the popover's ARIA and click, like React's cloneElement.
73
+ const trigger = () => {
74
+ const node = firstNode(slots.trigger?.())
75
+ return cloneTrigger(node, setAnchor, {
76
+ onClick: () => (open.value = !open.value),
77
+ 'aria-haspopup': 'dialog',
78
+ 'aria-expanded': open.value,
79
+ 'aria-controls': open.value ? id : undefined,
80
+ })
81
+ }
82
+ </script>
83
+
84
+ <template>
85
+ <component :is="trigger()" />
86
+ <Teleport v-if="mounted" to="body">
87
+ <div
88
+ v-bind="$attrs"
89
+ :id="id"
90
+ ref="panel"
91
+ role="dialog"
92
+ :aria-labelledby="`${id}-title`"
93
+ tabindex="-1"
94
+ :class="styles.panel"
95
+ :data-state="state"
96
+ :data-side="placed"
97
+ :style="style"
98
+ >
99
+ <div :class="styles.head">
100
+ <h2 :id="`${id}-title`" :class="styles.title"><slot name="title">{{ title }}</slot></h2>
101
+ <button type="button" :class="styles.close" :aria-label="closeLabel" data-skip-initial-focus="true" @click="close">
102
+ <XIcon />
103
+ </button>
104
+ </div>
105
+ <div :class="styles.body"><slot /></div>
106
+ </div>
107
+ </Teleport>
108
+ </template>
@@ -0,0 +1,48 @@
1
+ <script setup lang="ts">
2
+ import { computed, useId } from 'vue'
3
+ import styles from './ProgressBar.module.css'
4
+
5
+ // The Vue ProgressBar: the same look (ProgressBar.module.css) as the React one.
6
+ const props = withDefaults(
7
+ defineProps<{
8
+ /** Says what is in progress. Shown above the bar and read by screen readers. */
9
+ label: string
10
+ /** 0 to max. Leave it out for an indeterminate bar. */
11
+ value?: number
12
+ /** The value that means done. */
13
+ max?: number
14
+ /** Shows the percentage next to the label. */
15
+ showValue?: boolean
16
+ /** Hides the label visually but keeps it for screen readers. */
17
+ hideLabel?: boolean
18
+ /** Thickness of the bar. */
19
+ size?: 'sm' | 'md'
20
+ }>(),
21
+ { max: 100, showValue: true, size: 'md' },
22
+ )
23
+
24
+ const id = useId()
25
+ const determinate = computed(() => props.value !== undefined)
26
+ const ratio = computed(() => (props.value !== undefined ? Math.min(Math.max(props.value / props.max, 0), 1) : 0))
27
+ const now = computed(() => (props.value !== undefined ? Math.min(Math.max(props.value, 0), props.max) : undefined))
28
+ </script>
29
+
30
+ <template>
31
+ <div :class="styles.root">
32
+ <div :class="[styles.head, hideLabel && styles.srOnly]">
33
+ <span :id="id" :class="styles.label">{{ label }}</span>
34
+ <span v-if="determinate && showValue" :class="styles.value" aria-hidden="true">{{ Math.round(ratio * 100) }}%</span>
35
+ </div>
36
+ <div
37
+ role="progressbar"
38
+ :aria-labelledby="id"
39
+ :aria-valuemin="determinate ? 0 : undefined"
40
+ :aria-valuemax="determinate ? max : undefined"
41
+ :aria-valuenow="now"
42
+ :class="[styles.track, styles[size]]"
43
+ :data-indeterminate="!determinate || undefined"
44
+ >
45
+ <span :class="styles.fill" :style="determinate ? { transform: `scaleX(${ratio})` } : undefined" />
46
+ </div>
47
+ </div>
48
+ </template>
@@ -0,0 +1,18 @@
1
+ <script setup lang="ts">
2
+ import styles from './Prose.module.css'
3
+
4
+ // The Vue Prose: the same look (Prose.module.css) as the React one. It styles the plain HTML inside it,
5
+ // so Markdown or CMS HTML can go in with v-html, or as the default slot.
6
+ withDefaults(
7
+ defineProps<{
8
+ /** The element to render, such as article. */
9
+ as?: string
10
+ }>(),
11
+ { as: 'div' },
12
+ )
13
+ defineSlots<{ default?: () => unknown }>()
14
+ </script>
15
+
16
+ <template>
17
+ <component :is="as" :class="styles.root"><slot /></component>
18
+ </template>
@@ -0,0 +1,49 @@
1
+ <script setup lang="ts">
2
+ import { computed, inject, useId } from 'vue'
3
+ import { radioKey } from './RadioGroup.vue'
4
+ import styles from './Radio.module.css'
5
+
6
+ // The Vue Radio: one choice inside a RadioGroup, the same look (Radio.module.css) as the React one.
7
+
8
+ const props = defineProps<{
9
+ /** The group value this radio stands for. */
10
+ value: string
11
+ /** Visible text next to the circle. Clicking it picks the radio. */
12
+ label: string
13
+ /** Extra text under the label, also read by screen readers. */
14
+ description?: string
15
+ /** Turns off only this radio. */
16
+ disabled?: boolean
17
+ }>()
18
+
19
+ const ctx = inject(radioKey)
20
+ if (!ctx) throw new Error('Radio must be inside RadioGroup')
21
+ const id = useId()
22
+ const isOn = computed(() => ctx.value.value === props.value)
23
+ </script>
24
+
25
+ <template>
26
+ <div :class="styles.root" :data-disabled="disabled || ctx.disabled.value || undefined">
27
+ <span :class="styles.circleWrap">
28
+ <input
29
+ :id="id"
30
+ type="radio"
31
+ :class="styles.input"
32
+ :name="ctx.name.value"
33
+ :value="value"
34
+ :checked="isOn"
35
+ :disabled="disabled"
36
+ :aria-invalid="ctx.invalid.value || undefined"
37
+ :aria-describedby="description ? `${id}-desc` : undefined"
38
+ @change="ctx.set(value)"
39
+ />
40
+ <span :class="styles.circle" :data-on="isOn || undefined" aria-hidden="true">
41
+ <span :class="styles.dot" />
42
+ </span>
43
+ </span>
44
+ <span :class="styles.text">
45
+ <label :for="id" :class="styles.label">{{ label }}</label>
46
+ <span v-if="description" :id="`${id}-desc`" :class="styles.description">{{ description }}</span>
47
+ </span>
48
+ </div>
49
+ </template>