gooee 0.50.0 → 0.51.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 (171) hide show
  1. package/package.json +4 -2
  2. package/scripts/add.js +28 -6
  3. package/src/components/Accordion/Accordion.vue +62 -0
  4. package/src/components/Accordion/AccordionItem.vue +45 -0
  5. package/src/components/Accordion/accordionContext.ts +6 -0
  6. package/src/components/Alert/Alert.tsx +7 -27
  7. package/src/components/Alert/Alert.vue +59 -0
  8. package/src/components/AlertDialog/AlertDialog.vue +126 -0
  9. package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
  10. package/src/components/AspectRatio/AspectRatio.vue +17 -0
  11. package/src/components/Avatar/Avatar.vue +56 -0
  12. package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
  13. package/src/components/Badge/Badge.vue +32 -0
  14. package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
  15. package/src/components/Button/Button.vue +130 -0
  16. package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
  17. package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
  18. package/src/components/Card/Card.vue +34 -0
  19. package/src/components/Center/Center.vue +32 -0
  20. package/src/components/Checkbox/Checkbox.tsx +8 -25
  21. package/src/components/Checkbox/Checkbox.vue +108 -0
  22. package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
  23. package/src/components/Cluster/Cluster.vue +34 -0
  24. package/src/components/CodeBlock/CodeBlock.vue +45 -0
  25. package/src/components/Collapsible/Collapsible.vue +59 -0
  26. package/src/components/Container/Container.vue +22 -0
  27. package/src/components/CopyButton/CopyButton.tsx +3 -49
  28. package/src/components/CopyButton/CopyButton.vue +116 -0
  29. package/src/components/Dial/Dial.tsx +12 -120
  30. package/src/components/Dial/Dial.vue +228 -0
  31. package/src/components/Dialog/Dialog.vue +139 -0
  32. package/src/components/Divider/Divider.vue +27 -0
  33. package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
  34. package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
  35. package/src/components/EmptyState/EmptyState.vue +33 -0
  36. package/src/components/Fab/Fab.tsx +4 -14
  37. package/src/components/Fab/Fab.vue +115 -0
  38. package/src/components/Fieldset/Fieldset.vue +42 -0
  39. package/src/components/FormField/FormField.tsx +2 -17
  40. package/src/components/FormField/FormField.vue +64 -0
  41. package/src/components/Grid/Grid.vue +43 -0
  42. package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -143
  43. package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
  44. package/src/components/IconButton/IconButton.vue +25 -0
  45. package/src/components/Input/Input.vue +112 -0
  46. package/src/components/InputGroup/InputGroup.vue +102 -0
  47. package/src/components/Kbd/Kbd.tsx +2 -12
  48. package/src/components/Kbd/Kbd.vue +21 -0
  49. package/src/components/Link/Link.vue +38 -0
  50. package/src/components/LivePill/LivePill.tsx +11 -39
  51. package/src/components/LivePill/LivePill.vue +152 -0
  52. package/src/components/Meter/Meter.vue +88 -0
  53. package/src/components/MorphButton/MorphButton.tsx +11 -67
  54. package/src/components/MorphButton/MorphButton.vue +120 -0
  55. package/src/components/NumberInput/NumberInput.tsx +11 -48
  56. package/src/components/NumberInput/NumberInput.vue +184 -0
  57. package/src/components/Pagination/Pagination.tsx +2 -15
  58. package/src/components/Pagination/Pagination.vue +87 -0
  59. package/src/components/Pagination/range.ts +15 -0
  60. package/src/components/PasswordInput/PasswordInput.vue +53 -0
  61. package/src/components/PickerWheel/DateWheel.vue +48 -0
  62. package/src/components/PickerWheel/PickerWheel.tsx +15 -129
  63. package/src/components/PickerWheel/PickerWheel.vue +77 -0
  64. package/src/components/PickerWheel/TimeWheel.vue +50 -0
  65. package/src/components/PickerWheel/WheelColumn.vue +70 -0
  66. package/src/components/Popover/Popover.vue +108 -0
  67. package/src/components/ProgressBar/ProgressBar.vue +48 -0
  68. package/src/components/Prose/Prose.vue +18 -0
  69. package/src/components/Radio/Radio.vue +49 -0
  70. package/src/components/Radio/RadioGroup.vue +69 -0
  71. package/src/components/Retime/Retime.tsx +7 -40
  72. package/src/components/Retime/Retime.vue +64 -0
  73. package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
  74. package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
  75. package/src/components/ScrollArea/ScrollArea.tsx +17 -129
  76. package/src/components/ScrollArea/ScrollArea.vue +58 -0
  77. package/src/components/SearchInput/SearchInput.tsx +2 -15
  78. package/src/components/SearchInput/SearchInput.vue +70 -0
  79. package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
  80. package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
  81. package/src/components/Select/Select.tsx +16 -47
  82. package/src/components/Select/Select.vue +236 -0
  83. package/src/components/Sheet/Sheet.tsx +52 -231
  84. package/src/components/Sheet/Sheet.vue +249 -0
  85. package/src/components/Skeleton/Skeleton.vue +38 -0
  86. package/src/components/Slider/Slider.tsx +25 -84
  87. package/src/components/Slider/Slider.vue +113 -0
  88. package/src/components/Spinner/Spinner.vue +30 -0
  89. package/src/components/Split/Split.vue +34 -0
  90. package/src/components/SplitFlap/SplitFlap.tsx +11 -175
  91. package/src/components/SplitFlap/SplitFlap.vue +52 -0
  92. package/src/components/Stack/Stack.vue +22 -0
  93. package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
  94. package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
  95. package/src/components/Switch/Switch.tsx +6 -75
  96. package/src/components/Switch/Switch.vue +66 -0
  97. package/src/components/Table/Table.module.css +12 -3
  98. package/src/components/Table/Table.tsx +8 -59
  99. package/src/components/Table/Table.vue +274 -0
  100. package/src/components/TableOfContents/TableOfContents.vue +90 -0
  101. package/src/components/Tabs/Tab.vue +37 -0
  102. package/src/components/Tabs/TabList.vue +47 -0
  103. package/src/components/Tabs/TabPanel.vue +26 -0
  104. package/src/components/Tabs/Tabs.module.css +2 -2
  105. package/src/components/Tabs/Tabs.tsx +11 -84
  106. package/src/components/Tabs/Tabs.vue +33 -0
  107. package/src/components/Tabs/tabsContext.ts +15 -0
  108. package/src/components/Tag/Tag.tsx +6 -26
  109. package/src/components/Tag/Tag.vue +63 -0
  110. package/src/components/Textarea/Textarea.tsx +2 -22
  111. package/src/components/Textarea/Textarea.vue +120 -0
  112. package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
  113. package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
  114. package/src/components/Toast/Toast.tsx +34 -264
  115. package/src/components/Toast/Toast.vue +138 -0
  116. package/src/components/Toast/ToastItem.vue +108 -0
  117. package/src/components/Toggle/Toggle.vue +52 -0
  118. package/src/components/Tooltip/Tooltip.tsx +17 -48
  119. package/src/components/Tooltip/Tooltip.vue +95 -0
  120. package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
  121. package/src/internal/FieldMessage.vue +41 -0
  122. package/src/internal/Roll.vue +20 -0
  123. package/src/internal/focus.ts +4 -47
  124. package/src/internal/icons.module.css +39 -27
  125. package/src/internal/layers.ts +7 -61
  126. package/src/internal/motion/alert.ts +17 -0
  127. package/src/internal/motion/buttonGroup.ts +21 -0
  128. package/src/internal/motion/checkbox.ts +39 -0
  129. package/src/internal/motion/collapseOut.ts +26 -0
  130. package/src/internal/motion/copyButton.ts +48 -0
  131. package/src/internal/motion/dial.ts +137 -0
  132. package/src/internal/motion/fab.ts +14 -0
  133. package/src/internal/motion/floating.ts +58 -0
  134. package/src/internal/motion/focus.ts +53 -0
  135. package/src/internal/motion/formField.ts +19 -0
  136. package/src/internal/motion/holdToConfirm.ts +147 -0
  137. package/src/internal/motion/keys.ts +42 -0
  138. package/src/internal/motion/layers.ts +78 -0
  139. package/src/internal/motion/listbox.ts +69 -0
  140. package/src/internal/motion/livePill.ts +71 -0
  141. package/src/internal/motion/menuKeys.ts +58 -0
  142. package/src/internal/motion/morphButton.ts +71 -0
  143. package/src/internal/motion/numberInput.ts +57 -0
  144. package/src/internal/motion/pickerWheel.ts +166 -0
  145. package/src/internal/motion/retime.ts +45 -0
  146. package/src/internal/motion/ruler.ts +57 -0
  147. package/src/internal/motion/scrollArea.ts +133 -0
  148. package/src/internal/motion/scrubLook.ts +15 -0
  149. package/src/internal/motion/segmented.ts +63 -0
  150. package/src/internal/motion/sheetDetents.ts +271 -0
  151. package/src/internal/motion/slider.ts +108 -0
  152. package/src/internal/motion/splitFlap.ts +205 -0
  153. package/src/internal/motion/swipeDeck.ts +236 -0
  154. package/src/internal/motion/switchThumb.ts +83 -0
  155. package/src/internal/motion/table.ts +77 -0
  156. package/src/internal/motion/tabs.ts +105 -0
  157. package/src/internal/motion/textarea.ts +22 -0
  158. package/src/internal/motion/themeIcon.ts +91 -0
  159. package/src/internal/motion/themeReveal.ts +71 -0
  160. package/src/internal/motion/toast.ts +291 -0
  161. package/src/internal/motion/tooltip.ts +58 -0
  162. package/src/internal/themeReveal.ts +3 -61
  163. package/src/internal/useFloating.ts +9 -49
  164. package/src/internal/useScrub.ts +1 -13
  165. package/src/internal/vue/trigger.ts +18 -0
  166. package/src/internal/vue/useFloating.ts +38 -0
  167. package/src/internal/vue/usePresence.ts +21 -0
  168. package/src/internal/vue/useScrub.ts +40 -0
  169. package/src/internal/vueIcons.ts +134 -0
  170. package/src/tokens.css +5 -0
  171. package/src/internal/relativeTime.ts +0 -26
@@ -0,0 +1,42 @@
1
+ <script setup lang="ts">
2
+ import { computed, useAttrs, useId } from 'vue'
3
+ import FieldMessage from '../../internal/FieldMessage.vue'
4
+ import styles from './Fieldset.module.css'
5
+
6
+ // The Vue Fieldset: a native fieldset and legend with the same look (Fieldset.module.css) as the React one.
7
+ defineOptions({ inheritAttrs: false })
8
+
9
+ const props = defineProps<{
10
+ /** Visible name of the group, rendered as the legend. The legend slot replaces it. */
11
+ legend?: string
12
+ /** Muted text under the legend, read with the group. */
13
+ description?: string
14
+ /** Error for the group as a whole, shown under the fields and read with the group. */
15
+ error?: string
16
+ /** Turns off every field inside, natively, so none of them can be focused or sent. */
17
+ disabled?: boolean
18
+ id?: string
19
+ }>()
20
+ const slots = defineSlots<{ default?: () => unknown; legend?: () => unknown; description?: () => unknown }>()
21
+ const attrs = useAttrs()
22
+
23
+ const rest = computed(() => {
24
+ const { 'aria-describedby': _d, ...other } = attrs
25
+ return other
26
+ })
27
+ const auto = useId()
28
+ const base = computed(() => props.id ?? auto)
29
+ const descId = computed(() => `${base.value}-desc`)
30
+ const errorId = computed(() => `${base.value}-error`)
31
+ const hasDescription = computed(() => !!slots.description || !!props.description)
32
+ const describedBy = computed(() => [hasDescription.value ? descId.value : null, props.error ? errorId.value : null, attrs['aria-describedby']].filter(Boolean).join(' ') || undefined)
33
+ </script>
34
+
35
+ <template>
36
+ <fieldset v-bind="rest" :id="id" :class="styles.root" :disabled="disabled" :aria-describedby="describedBy">
37
+ <legend :class="styles.legend"><slot name="legend">{{ legend }}</slot></legend>
38
+ <p v-if="hasDescription" :id="descId" :class="styles.description"><slot name="description">{{ description }}</slot></p>
39
+ <div :class="styles.fields"><slot /></div>
40
+ <FieldMessage :help-id="`${base}-help`" :error-id="errorId" :error="error" />
41
+ </fieldset>
42
+ </template>
@@ -3,21 +3,10 @@
3
3
  import { createContext, useContext, useId, type ReactNode } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
5
  import { FieldMessage } from '../../internal/FieldMessage'
6
+ import type { FormFieldControlProps, FormFieldLabels } from '../../internal/motion/formField'
6
7
  import styles from './FormField.module.css'
7
8
 
8
- /** Props to spread on the control, so its label, help and error are wired up. */
9
- export type FormFieldControlProps = {
10
- /** Id the label points to with htmlFor. */
11
- id: string
12
- /** Id of the help or error text, whichever is showing. */
13
- 'aria-describedby'?: string
14
- /** Set when the field has an error. */
15
- 'aria-invalid'?: true
16
- /** Set when the field is required. */
17
- 'aria-required'?: true
18
- /** Set when the field is disabled. */
19
- disabled?: boolean
20
- }
9
+ export type { FormFieldControlProps, FormFieldLabels }
21
10
 
22
11
  type FieldContext = { controlProps: FormFieldControlProps; labelId: string }
23
12
 
@@ -51,10 +40,6 @@ export type FormFieldProps = {
51
40
  className?: string
52
41
  }
53
42
 
54
- export type FormFieldLabels = {
55
- optional: string
56
- }
57
-
58
43
  const defaultLabels: FormFieldLabels = {
59
44
  optional: '(optional)',
60
45
  }
@@ -0,0 +1,64 @@
1
+ <script lang="ts">
2
+ import { inject, type ComputedRef, type InjectionKey } from 'vue'
3
+ import type { FormFieldControlProps } from '../../internal/motion/formField'
4
+
5
+ const key: InjectionKey<ComputedRef<FormFieldControlProps>> = Symbol('gooee-form-field')
6
+
7
+ /** Inside a FormField, returns the props for its control (bind them with v-bind). Outside one, returns null. */
8
+ export function useFormField(): ComputedRef<FormFieldControlProps> | null {
9
+ return inject(key, null)
10
+ }
11
+ </script>
12
+
13
+ <script setup lang="ts">
14
+ import { computed, provide, useId } from 'vue'
15
+ import FieldMessage from '../../internal/FieldMessage.vue'
16
+ import type { FormFieldLabels } from '../../internal/motion/formField'
17
+ import styles from './FormField.module.css'
18
+
19
+ // The Vue FormField: the same look (FormField.module.css) as the React one. The control gets its wiring
20
+ // from the default slot's props, or from useFormField() inside your own control.
21
+ const props = defineProps<{
22
+ /** Visible label above the control. The label slot replaces it. */
23
+ label?: string
24
+ /** Hint under the control. Hidden while there is an error. */
25
+ help?: string
26
+ /** Error message under the control. Marks the control invalid. */
27
+ error?: string
28
+ /** Adds a "*" after the label and sets aria-required on the control. */
29
+ required?: boolean
30
+ /** Adds "(optional)" after the label. */
31
+ optional?: boolean
32
+ /** Dims the field and passes disabled to the control. */
33
+ disabled?: boolean
34
+ /** Use a fixed id instead of a generated one. */
35
+ id?: string
36
+ /** Text added to the label, so you can translate it. */
37
+ labels?: Partial<FormFieldLabels>
38
+ }>()
39
+ defineSlots<{ default?: (props: FormFieldControlProps) => unknown; label?: () => unknown }>()
40
+
41
+ const auto = useId()
42
+ const controlId = computed(() => props.id ?? auto)
43
+ const labelId = computed(() => `${controlId.value}-label`)
44
+ const helpId = computed(() => `${controlId.value}-help`)
45
+ const errorId = computed(() => `${controlId.value}-error`)
46
+ const controlProps = computed<FormFieldControlProps>(() => ({
47
+ id: controlId.value,
48
+ 'aria-describedby': [props.help && !props.error ? helpId.value : null, props.error ? errorId.value : null].filter(Boolean).join(' ') || undefined,
49
+ 'aria-invalid': props.error ? true : undefined,
50
+ 'aria-required': props.required ? true : undefined,
51
+ disabled: props.disabled || undefined,
52
+ }))
53
+ provide(key, controlProps)
54
+ </script>
55
+
56
+ <template>
57
+ <div :class="styles.root" :data-invalid="error ? true : undefined" :data-disabled="disabled || undefined">
58
+ <label :id="labelId" :for="controlId" :class="styles.label">
59
+ <slot name="label">{{ label }}</slot><span v-if="required" :class="styles.required" aria-hidden="true"> *</span><span v-if="optional && !required" :class="styles.optional">{{ ` ${labels?.optional ?? '(optional)'}` }}</span>
60
+ </label>
61
+ <div :class="styles.control"><slot v-bind="controlProps" /></div>
62
+ <FieldMessage :help-id="helpId" :error-id="errorId" :help="help" :error="error" />
63
+ </div>
64
+ </template>
@@ -0,0 +1,43 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { space, type Space } from '../../internal/space'
4
+ import styles from './Grid.module.css'
5
+
6
+ // The Vue Grid: the same look (Grid.module.css) as the React one. Other attributes go to the element.
7
+ const props = withDefaults(
8
+ defineProps<{
9
+ /** Fixed number of columns. With min, it becomes the most columns the grid may show. */
10
+ columns?: number
11
+ /** Narrowest a cell may get before a column drops: a token size or any CSS length. Defaults to "md" when columns is not set. */
12
+ min?: 'xs' | 'sm' | 'md' | 'lg' | (string & {})
13
+ /** Space between cells, as a step of the space scale (0 to 12, read as --gooee-space-N). */
14
+ gap?: Space
15
+ /** Element to render, so a set of cards can be a list. */
16
+ as?: 'div' | 'section' | 'ul' | 'ol'
17
+ /** With columns and min: "halves" steps from columns to half of it, then to one (4, 2, 1), so no card is left alone on a row. */
18
+ steps?: 'all' | 'halves'
19
+ }>(),
20
+ { gap: 5, as: 'div', steps: 'all' },
21
+ )
22
+ defineSlots<{ default?: () => unknown }>()
23
+
24
+ const tokenSizes = ['xs', 'sm', 'md', 'lg']
25
+ const vars = computed(() => {
26
+ const min = props.min ?? 'md'
27
+ return {
28
+ '--grid-gap': space(props.gap),
29
+ '--grid-cols': props.columns,
30
+ '--grid-half': props.columns ? Math.max(1, Math.floor(props.columns / 2)) : undefined,
31
+ '--grid-min': tokenSizes.includes(min) ? `var(--gooee-grid-min-${min})` : min,
32
+ }
33
+ })
34
+ const kind = computed(() => {
35
+ const fit = props.min !== undefined || props.columns === undefined
36
+ if (!fit) return styles.fixed
37
+ return !props.columns ? styles.fit : props.steps === 'halves' ? styles.halves : styles.capped
38
+ })
39
+ </script>
40
+
41
+ <template>
42
+ <component :is="as" :class="[styles.root, kind]" :style="vars"><slot /></component>
43
+ </template>
@@ -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>