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,10 +3,8 @@
3
3
  import { useEffect, useId, useLayoutEffect, useRef, useState, type KeyboardEvent, type MouseEvent, type PointerEvent, type ReactNode } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
5
  import { CheckIcon, XIcon } from '../../internal/icons'
6
- import { bezier } from '../../internal/feel'
7
- import { morphCurve, prefersReducedMotion, readMotionMs } from '../../internal/motion'
8
- import { frames, layer, morphEase, motionFor } from '../../internal/liquidMatter'
9
- import { body, boxPath, lerp, loopsPath, pincher, seg, trace, type Box } from '../../internal/liquidPath'
6
+ import { prefersReducedMotion } from '../../internal/motion'
7
+ import { bud, createFuse, cssMs, DONE_FOR, GUARD, HINT_AFTER, LEAVE, outline, TAP } from '../../internal/motion/holdToConfirm'
10
8
  import styles from './HoldToConfirm.module.css'
11
9
 
12
10
  export type HoldToConfirmProps = {
@@ -34,101 +32,6 @@ export type HoldToConfirmProps = {
34
32
 
35
33
  type Phase = 'idle' | 'step' | 'done'
36
34
 
37
- // A press shorter than this is a tap: it opens the confirm step, like one key press does.
38
- const TAP = 250
39
- // Held this long, the hint changes to "Keep holding".
40
- const HINT_AFTER = 300
41
- // A finger that slides this far off the button lets go.
42
- const LEAVE = 16
43
- // How long the done state shows before the button can be used again.
44
- const DONE_FOR = 2400
45
- // A click this soon after the step opens is the rest of a double-click, not a choice.
46
- const GUARD = 500
47
-
48
- /**
49
- * The cancel drop buds out of the button's right edge, its neck stretches and breaks, and it grows into
50
- * the round cancel button (`in`), or flows back into the button (`out`). The button keeps its own look:
51
- * the drawing is cut out where it is. Returns a stop, or null when motion is reduced.
52
- */
53
- function bud(row: HTMLElement, shell: HTMLElement, x: HTMLElement, way: 'in' | 'out') {
54
- // 400ms both ways: the drop is small, and at the morph's 600ms the cancel button felt late to arrive.
55
- const ms = motionFor('reveal')
56
- if (!ms) return null
57
- const box = (el: HTMLElement): Box => {
58
- const r = el.getBoundingClientRect(),
59
- o = row.getBoundingClientRect()
60
- return { cx: r.left - o.left + r.width / 2, cy: r.top - o.top + r.height / 2, hw: r.width / 2, hh: r.height / 2, r: r.height / 2 }
61
- }
62
- const O = box(shell)
63
- const look = getComputedStyle(x)
64
- const line = parseFloat(look.getPropertyValue('--gooee-line-thick')) || 1.5
65
- const T = box(x)
66
- const T2: Box = { ...T, hw: T.hw - line / 2, hh: T.hh - line / 2, r: T.r - line / 2 }
67
- const { svg, paths } = layer(row, styles.bud, null)
68
- const path = paths[0]
69
- path.style.fill = look.backgroundColor
70
- path.style.stroke = look.getPropertyValue('--gooee-color-border-strong')
71
- path.style.strokeWidth = `${line}px`
72
- const clip = svg.appendChild(document.createElementNS('http://www.w3.org/2000/svg', 'clipPath'))
73
- clip.id = `gooee-hold-${Math.random().toString(36).slice(2)}`
74
- const hole = clip.appendChild(document.createElementNS('http://www.w3.org/2000/svg', 'path'))
75
- hole.setAttribute('clip-rule', 'evenodd')
76
- hole.setAttribute('d', `M-4000 -4000H4000V4000H-4000Z${boxPath({ ...O, hw: O.hw + 0.5, hh: O.hh + 0.5, r: O.r + 0.5 })}`)
77
- path.setAttribute('clip-path', `url(#${clip.id})`)
78
- const e = morphEase()
79
- const pin = pincher(e, motionFor('fast'))
80
- const edge = O.cx + O.hw - O.hh
81
- const r0 = O.hh * 0.45
82
- x.style.opacity = '0'
83
- const stop = frames(
84
- ms,
85
- (k, now) => {
86
- const u = way === 'in' ? k : 1 - k
87
- const f = e(u)
88
- const r = lerp(r0, T2.hh, e(seg(u, 0.25, 1)))
89
- const D: Box = { cx: lerp(O.cx + O.hw - r0, T2.cx, f), cy: O.cy, hw: r, hh: r, r }
90
- const p = pin(body(O, [edge, O.cy]), body(D), now)
91
- path.setAttribute(
92
- 'd',
93
- loopsPath(
94
- trace(p.sdf, [
95
- [edge, O.cy, 0, 1],
96
- [D.cx, D.cy, 0, 1],
97
- ]),
98
- ),
99
- )
100
- },
101
- () => {
102
- svg.remove()
103
- x.style.opacity = ''
104
- },
105
- )
106
- return () => {
107
- stop()
108
- svg.remove()
109
- x.style.opacity = ''
110
- }
111
- }
112
-
113
- // The pill's outline as one closed path that starts on the bottom edge at x and runs left first. The
114
- // line is drawn at both ends of the path at once, so it burns out both ways from x and meets opposite.
115
- function outline(w: number, h: number, inset: number, x: number) {
116
- const r = h / 2 - inset
117
- const t = inset
118
- const b = h - inset
119
- const l = h / 2
120
- const rr = w - h / 2
121
- const px = Math.max(l, Math.min(rr, x))
122
- return `M${px},${b} H${l} A${r},${r} 0 0 1 ${l},${t} H${rr} A${r},${r} 0 0 1 ${rr},${b} Z`
123
- }
124
-
125
- const ms = (el: Element | null, name: string, fallback: number) => {
126
- const raw = el ? getComputedStyle(el).getPropertyValue(name).trim() : ''
127
- const v = parseFloat(raw)
128
- if (!Number.isFinite(v)) return fallback
129
- return raw.endsWith('ms') ? v : raw.endsWith('s') ? v * 1000 : v
130
- }
131
-
132
35
  export function HoldToConfirm({
133
36
  children,
134
37
  onConfirm,
@@ -155,8 +58,9 @@ export function HoldToConfirm({
155
58
  const [keep, setKeep] = useState(false)
156
59
  const [said, setSaid] = useState('')
157
60
 
158
- const p = useRef(0)
159
- const raf = useRef(0)
61
+ // The burning line (motion/holdToConfirm.ts).
62
+ const fuse = useRef<ReturnType<typeof createFuse>>(null)
63
+ fuse.current ??= createFuse(() => runRef.current)
160
64
  const tapTimer = useRef(0)
161
65
  const press = useRef<{ t0: number; pointer: number | 'key'; key?: string } | null>(null)
162
66
  const phaseRef = useRef(phase)
@@ -181,16 +85,10 @@ export function HoldToConfirm({
181
85
  return () => ro.disconnect()
182
86
  }, [])
183
87
 
184
- const paint = (v: number) => {
185
- p.current = v
186
- const run = runRef.current
187
- if (!run) return
188
- run.style.strokeDasharray = `${v / 2} ${1 - v} ${v / 2} 0`
189
- run.style.opacity = v > 0 ? '1' : '0'
190
- }
88
+ const paint = (v: number) => fuse.current!.paint(v)
191
89
 
192
90
  const finish = () => {
193
- cancelAnimationFrame(raf.current)
91
+ fuse.current!.stop()
194
92
  press.current = null
195
93
  paint(1)
196
94
  setKeep(false)
@@ -202,42 +100,14 @@ export function HoldToConfirm({
202
100
  calls.current.onConfirm()
203
101
  }
204
102
 
205
- // Forward at an even speed: it is a clock.
206
- const run = () => {
207
- cancelAnimationFrame(raf.current)
208
- const total = ms(shellRef.current, '--gooee-hold-time', 1500)
209
- let last = performance.now()
210
- const step = (now: number) => {
211
- const next = Math.min(1, p.current + (now - last) / total)
212
- last = now
213
- paint(next)
214
- if (press.current && now - press.current.t0 > HINT_AFTER) setKeep(true)
215
- if (next >= 1) return finish()
216
- raf.current = requestAnimationFrame(step)
217
- }
218
- raf.current = requestAnimationFrame(step)
219
- }
220
-
221
- // Back fast on the morph curve: a rubber band, not a clock.
222
- const rewind = () => {
223
- cancelAnimationFrame(raf.current)
224
- const from = p.current
225
- const length = readMotionMs('fast')
226
- if (!length || !from) return paint(0)
227
- const ease = bezier(morphCurve())
228
- const t0 = performance.now()
229
- const step = (now: number) => {
230
- const t = Math.min(1, (now - t0) / length)
231
- paint(from * (1 - ease(t)))
232
- if (t < 1) raf.current = requestAnimationFrame(step)
233
- }
234
- raf.current = requestAnimationFrame(step)
235
- }
103
+ // Forward at an even speed, and back fast on the morph curve.
104
+ const run = () => fuse.current!.forward(cssMs(shellRef.current, '--gooee-hold-time', 1500), (now) => press.current && now - press.current.t0 > HINT_AFTER && setKeep(true), finish)
105
+ const rewind = () => fuse.current!.rewind()
236
106
 
237
107
  const openStep = () => {
238
108
  window.clearTimeout(tapTimer.current)
239
109
  tapTimer.current = 0
240
- cancelAnimationFrame(raf.current)
110
+ fuse.current!.stop()
241
111
  paint(0)
242
112
  stepAt.current = performance.now()
243
113
  setPhase('step')
@@ -270,12 +140,12 @@ export function HoldToConfirm({
270
140
  shell = shellRef.current,
271
141
  x = cancelRef.current
272
142
  if (!row || !shell || !x) return
273
- return bud(row, shell, x, isOpen ? 'in' : 'out') ?? undefined
143
+ return bud(row, shell, x, isOpen ? 'in' : 'out', styles.bud) ?? undefined
274
144
  }, [phase])
275
145
 
276
146
  useEffect(
277
147
  () => () => {
278
- cancelAnimationFrame(raf.current)
148
+ fuse.current!.stop()
279
149
  window.clearTimeout(tapTimer.current)
280
150
  },
281
151
  [],
@@ -0,0 +1,281 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, useId, watch } from 'vue'
3
+ import { prefersReducedMotion } from '../../internal/motion'
4
+ import { bud, createFuse, cssMs, DONE_FOR, GUARD, HINT_AFTER, LEAVE, outline, TAP } from '../../internal/motion/holdToConfirm'
5
+ import { CheckIcon, XIcon } from '../../internal/vueIcons'
6
+ import styles from './HoldToConfirm.module.css'
7
+
8
+ // The Vue HoldToConfirm: the same look (HoldToConfirm.module.css), hold, confirm step and motion as the
9
+ // React one. The action's label goes in the default slot.
10
+ const props = withDefaults(
11
+ defineProps<{
12
+ /** The action as a verb for the confirm step's line, such as "Delete": "Press it again to delete, or Cancel." */
13
+ confirmLabel?: string
14
+ /** The name of the round cancel button that buds out beside it in the confirm step. */
15
+ cancelLabel?: string
16
+ /** Shown in place of the label once it is done, such as "Workspace deleted". The done slot replaces it. */
17
+ doneLabel?: string
18
+ /** The line under the button. Defaults to how to use it. The hint slot replaces it. */
19
+ hint?: string
20
+ /** The line under the button while the confirm step is open. The stepHint slot replaces it. */
21
+ stepHint?: string
22
+ /** Blocks the button. Say why in the hint. */
23
+ disabled?: boolean
24
+ }>(),
25
+ { confirmLabel: 'Confirm', cancelLabel: 'Cancel', doneLabel: 'Done', hint: 'Hold to confirm, or tap for a confirm step.', disabled: false },
26
+ )
27
+ /** confirm: once the hold runs to the end, or the button is pressed again in the confirm step. cancel: a hold let go early, or the step cancelled. */
28
+ const emit = defineEmits<{ confirm: []; cancel: [] }>()
29
+ defineSlots<{ default?: () => unknown; done?: () => unknown; hint?: () => unknown; stepHint?: () => unknown }>()
30
+
31
+ type Phase = 'idle' | 'step' | 'done'
32
+
33
+ const id = useId()
34
+ const rootEl = ref<HTMLElement | null>(null)
35
+ const shellEl = ref<HTMLElement | null>(null)
36
+ const mainEl = ref<HTMLButtonElement | null>(null)
37
+ const rowEl = ref<HTMLElement | null>(null)
38
+ const cancelEl = ref<HTMLButtonElement | null>(null)
39
+ const runEl = ref<SVGPathElement | null>(null)
40
+ const phase = ref<Phase>('idle')
41
+ const size = ref({ w: 0, h: 0, inset: 1 })
42
+ const path = ref('')
43
+ const keep = ref(false)
44
+ const said = ref('')
45
+
46
+ // The burning line (motion/holdToConfirm.ts).
47
+ const fuse = createFuse(() => runEl.value)
48
+ let stepAt = 0
49
+ let tapTimer = 0
50
+ let press: { t0: number; pointer: number | 'key'; key?: string } | null = null
51
+
52
+ let ro: ResizeObserver | undefined
53
+ onMounted(() => {
54
+ const root = rootEl.value
55
+ const main = mainEl.value
56
+ if (!root || !main) return
57
+ const measure = () => {
58
+ const w = main.offsetWidth
59
+ const h = main.offsetHeight
60
+ const inset = parseFloat(getComputedStyle(root).getPropertyValue('--gooee-hold-stroke')) / 2 || 1
61
+ size.value = { w, h, inset }
62
+ path.value = outline(w, h, inset, w / 2)
63
+ }
64
+ measure()
65
+ ro = new ResizeObserver(measure)
66
+ ro.observe(main)
67
+ })
68
+
69
+ const finish = () => {
70
+ fuse.stop()
71
+ press = null
72
+ fuse.paint(1)
73
+ keep.value = false
74
+ // From the step, focus goes back to the button: the step closes under it. Safari never focused Confirm.
75
+ if (phase.value === 'step') mainEl.value?.focus({ preventScroll: true })
76
+ phase.value = 'done'
77
+ said.value = props.doneLabel
78
+ if (!prefersReducedMotion()) navigator.vibrate?.(12)
79
+ emit('confirm')
80
+ }
81
+
82
+ // Forward at an even speed, and back fast on the morph curve.
83
+ const run = () =>
84
+ fuse.forward(
85
+ cssMs(shellEl.value, '--gooee-hold-time', 1500),
86
+ (now) => {
87
+ if (press && now - press.t0 > HINT_AFTER) keep.value = true
88
+ },
89
+ finish,
90
+ )
91
+
92
+ const openStep = () => {
93
+ window.clearTimeout(tapTimer)
94
+ tapTimer = 0
95
+ fuse.stop()
96
+ fuse.paint(0)
97
+ stepAt = performance.now()
98
+ phase.value = 'step'
99
+ }
100
+
101
+ const closeStep = () => {
102
+ phase.value = 'idle'
103
+ mainEl.value?.focus({ preventScroll: true })
104
+ emit('cancel')
105
+ }
106
+
107
+ watch(
108
+ phase,
109
+ (now, _, onCleanup) => {
110
+ if (now === 'step') cancelEl.value?.focus({ preventScroll: true })
111
+ if (now !== 'done') return
112
+ const t = window.setTimeout(() => {
113
+ fuse.paint(0)
114
+ phase.value = 'idle'
115
+ said.value = ''
116
+ }, DONE_FOR)
117
+ onCleanup(() => window.clearTimeout(t))
118
+ },
119
+ { flush: 'post' },
120
+ )
121
+
122
+ // The cancel drop buds out when the step opens and flows back when it closes, either way.
123
+ let wasOpen = false
124
+ watch(
125
+ phase,
126
+ (now, _, onCleanup) => {
127
+ const isOpen = now === 'step'
128
+ if (isOpen === wasOpen) return
129
+ wasOpen = isOpen
130
+ const row = rowEl.value,
131
+ shell = shellEl.value,
132
+ x = cancelEl.value
133
+ if (!row || !shell || !x) return
134
+ const stop = bud(row, shell, x, isOpen ? 'in' : 'out', styles.bud)
135
+ if (stop) onCleanup(stop)
136
+ },
137
+ { flush: 'post' },
138
+ )
139
+
140
+ onBeforeUnmount(() => {
141
+ ro?.disconnect()
142
+ fuse.stop()
143
+ window.clearTimeout(tapTimer)
144
+ })
145
+
146
+ const start = (pointer: number | 'key', x: number, key?: string) => {
147
+ press = { t0: performance.now(), pointer, key }
148
+ path.value = outline(size.value.w, size.value.h, size.value.inset, x)
149
+ shellEl.value?.setAttribute('data-held', '')
150
+ run()
151
+ }
152
+
153
+ const letGo = (tapAllowed: boolean) => {
154
+ const pr = press
155
+ press = null
156
+ shellEl.value?.removeAttribute('data-held')
157
+ keep.value = false
158
+ if (!pr || phase.value !== 'idle') return
159
+ const tap = tapAllowed && performance.now() - pr.t0 < TAP
160
+ fuse.rewind()
161
+ if (!tap) return emit('cancel')
162
+ if (pr.pointer === 'key') return openStep()
163
+ // A tapped step opens on the click that follows, after the browser has focused the button, so focus
164
+ // can then move to Cancel. If no click comes, it opens anyway.
165
+ tapTimer = window.setTimeout(openStep, TAP)
166
+ }
167
+
168
+ const onPointerDown = (e: PointerEvent) => {
169
+ if (props.disabled || phase.value !== 'idle' || press || (e.pointerType === 'mouse' && e.button !== 0)) return
170
+ const el = e.currentTarget as HTMLElement
171
+ el.setPointerCapture?.(e.pointerId)
172
+ start(e.pointerId, e.clientX - el.getBoundingClientRect().left)
173
+ }
174
+
175
+ const onPointerMove = (e: PointerEvent) => {
176
+ if (!press || press.pointer !== e.pointerId) return
177
+ const r = (e.currentTarget as HTMLElement).getBoundingClientRect()
178
+ if (e.clientX < r.left - LEAVE || e.clientX > r.right + LEAVE || e.clientY < r.top - LEAVE || e.clientY > r.bottom + LEAVE) letGo(false)
179
+ }
180
+
181
+ const onPointerEnd = (e: PointerEvent) => {
182
+ if (press?.pointer === e.pointerId) letGo(e.type === 'pointerup')
183
+ }
184
+
185
+ // Held Enter or Space works like a held finger, from the middle of the button. One press opens the
186
+ // confirm step, since holding a key is hard for many people.
187
+ const onKeyDown = (e: KeyboardEvent) => {
188
+ if (phase.value === 'step') {
189
+ // In the step the button confirms with its own click; Escape steps back.
190
+ if (e.key === 'Escape') closeStep()
191
+ return
192
+ }
193
+ if (e.key !== 'Enter' && e.key !== ' ') return
194
+ e.preventDefault()
195
+ if (e.repeat || props.disabled || phase.value !== 'idle' || press) return
196
+ start('key', size.value.w / 2, e.key)
197
+ }
198
+
199
+ const onKeyUp = (e: KeyboardEvent) => {
200
+ if (phase.value === 'step' || (e.key !== 'Enter' && e.key !== ' ')) return
201
+ e.preventDefault()
202
+ if (press?.key === e.key) letGo(true)
203
+ }
204
+
205
+ // A screen reader or voice control sends a click with no press: it opens the confirm step.
206
+ const onClick = (e: MouseEvent) => {
207
+ // In the step, pressing the button again confirms it, unless it is the second half of a double-click.
208
+ if (phase.value === 'step') {
209
+ if (e.detail === 0 || performance.now() - stepAt > GUARD) finish()
210
+ return
211
+ }
212
+ if (props.disabled || phase.value !== 'idle' || press) return
213
+ if (e.detail === 0 || tapTimer) openStep()
214
+ }
215
+
216
+ const onCancelKey = (e: KeyboardEvent) => {
217
+ if (e.key !== 'Escape') return
218
+ e.stopPropagation()
219
+ closeStep()
220
+ }
221
+
222
+ const open = computed(() => phase.value === 'step')
223
+ </script>
224
+
225
+ <template>
226
+ <div ref="rootEl" :class="styles.root">
227
+ <div ref="rowEl" :class="styles.row">
228
+ <div ref="shellEl" :class="styles.shell" :data-phase="phase" :data-disabled="disabled || undefined">
229
+ <button
230
+ ref="mainEl"
231
+ type="button"
232
+ :class="styles.main"
233
+ :aria-describedby="`${id}-hint`"
234
+ :aria-expanded="open"
235
+ :aria-controls="`${id}-step`"
236
+ :aria-disabled="disabled || undefined"
237
+ @pointerdown="onPointerDown"
238
+ @pointermove="onPointerMove"
239
+ @pointerup="onPointerEnd"
240
+ @pointercancel="onPointerEnd"
241
+ @contextmenu.prevent
242
+ @keydown="onKeyDown"
243
+ @keyup="onKeyUp"
244
+ @blur="press?.pointer === 'key' && letGo(false)"
245
+ @click="onClick"
246
+ >
247
+ <span :class="styles.faces">
248
+ <span :class="styles.face" data-face="idle" :aria-hidden="phase === 'done' || undefined"><slot /></span>
249
+ <span :class="styles.face" data-face="done" :aria-hidden="phase !== 'done' || undefined">
250
+ <CheckIcon />
251
+ <slot name="done">{{ doneLabel }}</slot>
252
+ </span>
253
+ </span>
254
+ <svg :class="styles.fuse" :width="size.w" :height="size.h" aria-hidden="true">
255
+ <path ref="runEl" :d="path" :class="styles.run" :pathLength="1" />
256
+ </svg>
257
+ </button>
258
+ </div>
259
+ <button
260
+ :id="`${id}-step`"
261
+ ref="cancelEl"
262
+ type="button"
263
+ :class="styles.cancel"
264
+ :aria-label="cancelLabel"
265
+ :aria-describedby="`${id}-hint`"
266
+ :inert="!open"
267
+ @click="closeStep"
268
+ @keydown="onCancelKey"
269
+ >
270
+ <XIcon />
271
+ </button>
272
+ </div>
273
+ <p :id="`${id}-hint`" :class="styles.hint">
274
+ <slot v-if="open" name="stepHint">{{ stepHint ?? `Press it again to ${confirmLabel.toLowerCase()}, or ${cancelLabel}.` }}</slot>
275
+ <template v-else-if="phase === 'done'" />
276
+ <template v-else-if="keep">Keep holding</template>
277
+ <slot v-else name="hint">{{ hint }}</slot>
278
+ </p>
279
+ <p :class="styles.srOnly" aria-live="polite">{{ said }}</p>
280
+ </div>
281
+ </template>
@@ -0,0 +1,25 @@
1
+ <script setup lang="ts">
2
+ import styles from './IconButton.module.css'
3
+
4
+ // The Vue IconButton: the same look (IconButton.module.css) as the React one. The icon goes in the icon slot;
5
+ // other attributes and listeners, such as aria-pressed or a click listener, go to the button.
6
+ withDefaults(
7
+ defineProps<{
8
+ /** Required: the accessible name, since the button has no visible text. */
9
+ label: string
10
+ /** Visual weight. Ghost has no fill until hover. */
11
+ variant?: 'primary' | 'secondary' | 'ghost'
12
+ /** Size of the button. */
13
+ size?: 'sm' | 'md' | 'lg'
14
+ type?: 'button' | 'submit' | 'reset'
15
+ }>(),
16
+ { variant: 'ghost', size: 'md', type: 'button' },
17
+ )
18
+ defineSlots<{ icon?: () => unknown }>()
19
+ </script>
20
+
21
+ <template>
22
+ <button :type="type" :aria-label="label" :class="[styles.root, styles[variant], styles[size]]">
23
+ <span :class="styles.icon"><slot name="icon" /></span>
24
+ </button>
25
+ </template>
@@ -0,0 +1,112 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, useAttrs, useId } from 'vue'
3
+ import FieldMessage from '../../internal/FieldMessage.vue'
4
+ import { edgeFlow } from '../../internal/motion/liquidMore'
5
+ import styles from './Input.module.css'
6
+
7
+ // The Vue Input: the same look (Input.module.css) and focus edge as the React one.
8
+ // Other attributes, such as name, type or placeholder, go to the input. class and style go to the root, like React's className.
9
+ defineOptions({ inheritAttrs: false })
10
+
11
+ const props = withDefaults(
12
+ defineProps<{
13
+ /** Always required. A placeholder is only an example, never the label. */
14
+ label: string
15
+ /** "top" puts the label above the field, "floating" puts it inside and moves it up. */
16
+ labelPlacement?: 'top' | 'floating'
17
+ /** Hint under the field. Hidden while there is an error. */
18
+ help?: string
19
+ /** Error message under the field. Marks the field invalid. */
20
+ error?: string
21
+ /** Height of the field. */
22
+ size?: 'sm' | 'md' | 'lg'
23
+ /** Adds "(optional)" after the label. */
24
+ optional?: boolean
25
+ /** Text added to the label, so you can translate it. */
26
+ labels?: { optional?: string }
27
+ disabled?: boolean
28
+ id?: string
29
+ }>(),
30
+ { labelPlacement: 'top', size: 'md' },
31
+ )
32
+ /** The text. Use v-model, or leave it out and the input keeps its own value. */
33
+ const model = defineModel<string>()
34
+ const slots = defineSlots<{ leading?: () => unknown; trailing?: () => unknown }>()
35
+ const attrs = useAttrs()
36
+
37
+ const inputAttrs = computed(() => {
38
+ const { class: _class, style: _style, ...rest } = attrs
39
+ return rest
40
+ })
41
+ const optionalText = computed(() => props.labels?.optional ?? '(optional)')
42
+ const auto = useId()
43
+ const inputId = computed(() => props.id ?? auto)
44
+ const helpId = computed(() => `${inputId.value}-help`)
45
+ const errorId = computed(() => `${inputId.value}-error`)
46
+ const floating = computed(() => props.labelPlacement === 'floating')
47
+ const typed = ref(String(attrs.value ?? model.value ?? '') !== '')
48
+ const filled = computed(() => (model.value !== undefined ? model.value !== '' : typed.value))
49
+ // The caller's ids join ours, so help and error stay linked.
50
+ const describedBy = computed(() => [props.help && !props.error ? helpId.value : null, props.error ? errorId.value : null, attrs['aria-describedby']].filter(Boolean).join(' ') || undefined)
51
+
52
+ const input = ref<HTMLInputElement | null>(null)
53
+ const field = ref<HTMLElement | null>(null)
54
+ defineExpose({ input })
55
+ const onInput = (e: Event) => {
56
+ const v = (e.target as HTMLInputElement).value
57
+ typed.value = v !== ''
58
+ if (model.value !== undefined) model.value = v
59
+ }
60
+
61
+ // Focus draws the dark edge round the field from where it was pressed (motion/liquidMore.ts).
62
+ let stopEdge = () => {}
63
+ // A native form reset changes the value without an input event.
64
+ let frame = 0
65
+ const onReset = () => {
66
+ frame = requestAnimationFrame(() => (typed.value = input.value?.value !== ''))
67
+ }
68
+ onMounted(() => {
69
+ if (field.value) stopEdge = edgeFlow(field.value, field.value, ':focus-within', styles.edge)
70
+ input.value?.form?.addEventListener('reset', onReset)
71
+ })
72
+ onBeforeUnmount(() => {
73
+ stopEdge()
74
+ input.value?.form?.removeEventListener('reset', onReset)
75
+ cancelAnimationFrame(frame)
76
+ })
77
+ </script>
78
+
79
+ <template>
80
+ <div :class="[styles.root, attrs.class]" :style="attrs.style as string | undefined">
81
+ <label v-if="!floating" :for="inputId" :class="styles.topLabel">
82
+ {{ label }}<span v-if="optional" :class="styles.optional">{{ ` ${optionalText}` }}</span>
83
+ </label>
84
+ <div
85
+ ref="field"
86
+ :class="[styles.field, styles[size], floating && styles.floating]"
87
+ :data-filled="filled || undefined"
88
+ :data-invalid="error ? true : undefined"
89
+ :data-disabled="disabled || undefined"
90
+ >
91
+ <span v-if="slots.leading" :class="styles.adorn"><slot name="leading" /></span>
92
+ <div :class="styles.control">
93
+ <label v-if="floating" :for="inputId" :class="styles.floatLabel">
94
+ {{ label }}<span v-if="optional" :class="styles.optional">{{ ` ${optionalText}` }}</span>
95
+ </label>
96
+ <input
97
+ v-bind="inputAttrs"
98
+ :id="inputId"
99
+ ref="input"
100
+ :class="styles.input"
101
+ :value="model ?? (attrs.value as string | undefined)"
102
+ :disabled="disabled"
103
+ :aria-invalid="error ? true : (attrs['aria-invalid'] as boolean | undefined)"
104
+ :aria-describedby="describedBy"
105
+ @input="onInput"
106
+ />
107
+ </div>
108
+ <span v-if="slots.trailing" :class="styles.adorn"><slot name="trailing" /></span>
109
+ </div>
110
+ <FieldMessage :help-id="helpId" :error-id="errorId" :help="help" :error="error" />
111
+ </div>
112
+ </template>