gooee 0.48.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 (185) 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 -142
  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 +12 -40
  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/fling.ts +29 -106
  124. package/src/internal/focus.ts +4 -79
  125. package/src/internal/icons.module.css +39 -27
  126. package/src/internal/layers.ts +7 -61
  127. package/src/internal/liquid.ts +26 -213
  128. package/src/internal/liquidMatter.ts +9 -181
  129. package/src/internal/liquidMore.ts +6 -669
  130. package/src/internal/motion/alert.ts +17 -0
  131. package/src/internal/motion/buttonGroup.ts +21 -0
  132. package/src/internal/motion/checkbox.ts +39 -0
  133. package/src/internal/motion/collapseOut.ts +26 -0
  134. package/src/internal/motion/copyButton.ts +48 -0
  135. package/src/internal/motion/dial.ts +137 -0
  136. package/src/internal/motion/fab.ts +14 -0
  137. package/src/internal/motion/fling.ts +147 -0
  138. package/src/internal/motion/floating.ts +58 -0
  139. package/src/internal/motion/focus.ts +88 -0
  140. package/src/internal/motion/formField.ts +19 -0
  141. package/src/internal/motion/holdToConfirm.ts +147 -0
  142. package/src/internal/motion/index.ts +20 -0
  143. package/src/internal/motion/keys.ts +42 -0
  144. package/src/internal/motion/layers.ts +78 -0
  145. package/src/internal/motion/liquid.ts +241 -0
  146. package/src/internal/motion/liquidMatter.ts +198 -0
  147. package/src/internal/motion/liquidMore.ts +676 -0
  148. package/src/internal/motion/listbox.ts +69 -0
  149. package/src/internal/motion/livePill.ts +71 -0
  150. package/src/internal/motion/menuKeys.ts +58 -0
  151. package/src/internal/motion/morphButton.ts +71 -0
  152. package/src/internal/motion/numberInput.ts +57 -0
  153. package/src/internal/motion/pickerWheel.ts +166 -0
  154. package/src/internal/motion/retime.ts +45 -0
  155. package/src/internal/motion/ruler.ts +57 -0
  156. package/src/internal/motion/scrollArea.ts +133 -0
  157. package/src/internal/motion/scrollFrame.ts +152 -0
  158. package/src/internal/motion/scrubLook.ts +15 -0
  159. package/src/internal/motion/scrubber.ts +154 -0
  160. package/src/internal/motion/segmented.ts +63 -0
  161. package/src/internal/motion/sheetDetents.ts +271 -0
  162. package/src/internal/motion/slider.ts +108 -0
  163. package/src/internal/motion/softPress.ts +334 -0
  164. package/src/internal/motion/splitFlap.ts +205 -0
  165. package/src/internal/motion/swipeDeck.ts +236 -0
  166. package/src/internal/motion/switchThumb.ts +83 -0
  167. package/src/internal/motion/table.ts +77 -0
  168. package/src/internal/motion/tabs.ts +105 -0
  169. package/src/internal/motion/textarea.ts +22 -0
  170. package/src/internal/motion/themeIcon.ts +91 -0
  171. package/src/internal/motion/themeReveal.ts +71 -0
  172. package/src/internal/motion/toast.ts +291 -0
  173. package/src/internal/motion/tooltip.ts +58 -0
  174. package/src/internal/scrollFrame.ts +4 -145
  175. package/src/internal/softPress.ts +27 -289
  176. package/src/internal/themeReveal.ts +3 -61
  177. package/src/internal/useFloating.ts +9 -49
  178. package/src/internal/useScrub.ts +15 -120
  179. package/src/internal/vue/trigger.ts +18 -0
  180. package/src/internal/vue/useFloating.ts +38 -0
  181. package/src/internal/vue/usePresence.ts +21 -0
  182. package/src/internal/vue/useScrub.ts +40 -0
  183. package/src/internal/vueIcons.ts +134 -0
  184. package/src/tokens.css +5 -0
  185. package/src/internal/relativeTime.ts +0 -26
@@ -0,0 +1,108 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
3
+ import { createToastBud, createToastSwipe, toastStack, toastTimer, watchToastHeight, type ToastLeaving } from '../../internal/motion/toast'
4
+ import { CheckCircleIcon, ErrorIcon, InfoIcon, XIcon } from '../../internal/vueIcons'
5
+ import Spinner from '../Spinner/Spinner.vue'
6
+ import type { ToastItemData } from './Toast.vue'
7
+ import styles from './Toast.module.css'
8
+
9
+ // One toast of the Vue ToastProvider (Toast.vue).
10
+
11
+ const props = defineProps<{ item: ToastItemData; index: number; y: number; expanded: boolean; hidden: boolean; dismissLabel: string }>()
12
+ const emit = defineEmits<{ height: [h: number]; dismiss: [dir: ToastLeaving] }>()
13
+
14
+ const el = ref<HTMLElement | null>(null)
15
+ const dragging = ref(false)
16
+ const hover = ref(false)
17
+ const dismiss = (dir: ToastLeaving) => emit('dismiss', dir)
18
+
19
+ // Thrown sideways, it flies off at the speed of the swipe (motion/toast.ts).
20
+ const swipe = createToastSwipe(() => el.value, {
21
+ leaving: () => props.item.leaving !== false,
22
+ dragging: (on) => (dragging.value = on),
23
+ dismiss,
24
+ })
25
+
26
+ // A drop buds out of the origin, or out of the window's edge, and grows into the toast; a dismiss flows back the same way.
27
+ const bud = createToastBud(
28
+ () => el.value,
29
+ () => props.item.origin,
30
+ styles.bud,
31
+ )
32
+ let stopHeight = () => {}
33
+ onMounted(() => {
34
+ bud.place(props.index)
35
+ bud.change(props.item.leaving)
36
+ stopHeight = watchToastHeight(el.value!, (h) => emit('height', h))
37
+ })
38
+ watch(
39
+ () => props.index,
40
+ (i) => !props.item.leaving && bud.place(i),
41
+ { flush: 'post' },
42
+ )
43
+ watch(
44
+ () => props.item.leaving,
45
+ (leaving) => bud.change(leaving),
46
+ { flush: 'post' },
47
+ )
48
+
49
+ // It leaves on its own, but waits while hovered, focused, held or hidden.
50
+ const paused = computed(() => props.expanded || hover.value || dragging.value || props.item.leaving !== false)
51
+ const remaining = { current: props.item.duration ?? 5000 }
52
+ watch([() => props.item.duration, () => props.item.variant], () => (remaining.current = props.item.duration ?? 5000))
53
+ watch(
54
+ [paused, () => props.item.variant, () => props.item.duration],
55
+ (_, __, onCleanup) => {
56
+ if (paused.value || !Number.isFinite(remaining.current) || props.item.variant === 'loading' || typeof window === 'undefined') return
57
+ onCleanup(toastTimer(remaining, () => dismiss('down')))
58
+ },
59
+ { immediate: true },
60
+ )
61
+
62
+ onBeforeUnmount(() => {
63
+ swipe.stop()
64
+ bud.destroy()
65
+ stopHeight()
66
+ })
67
+
68
+ const place = computed(() => toastStack(props.index, props.y, props.expanded))
69
+ const onAction = () => {
70
+ props.item.action?.onClick()
71
+ dismiss('down')
72
+ }
73
+ </script>
74
+
75
+ <template>
76
+ <li
77
+ ref="el"
78
+ :class="styles.toast"
79
+ :data-leaving="item.leaving || undefined"
80
+ :data-dragging="dragging || undefined"
81
+ :data-hidden="hidden || undefined"
82
+ :data-behind="(!expanded && index > 0) || undefined"
83
+ :style="{ '--y': `${place.y}px`, '--s': place.scale, zIndex: 100 - Math.max(index, 0) }"
84
+ :aria-hidden="hidden || undefined"
85
+ :inert="hidden || undefined"
86
+ @pointerenter="hover = true"
87
+ @pointerleave="hover = false"
88
+ @pointerdown="swipe.down"
89
+ @pointermove="swipe.move"
90
+ @pointerup="swipe.up"
91
+ @pointercancel="swipe.up"
92
+ >
93
+ <span v-if="item.variant && item.variant !== 'default'" :class="styles.icon" :data-variant="item.variant">
94
+ <CheckCircleIcon v-if="item.variant === 'success'" />
95
+ <ErrorIcon v-else-if="item.variant === 'error'" />
96
+ <InfoIcon v-else-if="item.variant === 'info'" />
97
+ <Spinner v-else size="sm" :label="null" />
98
+ </span>
99
+ <div :class="styles.text">
100
+ <p :class="styles.title">{{ item.title }}</p>
101
+ <p v-if="item.description" :class="styles.description">{{ item.description }}</p>
102
+ </div>
103
+ <button v-if="item.action" type="button" :class="styles.action" @click="onAction">{{ item.action.label }}</button>
104
+ <button type="button" :class="styles.close" :aria-label="`${dismissLabel}: ${item.title}`" @click="dismiss('down')">
105
+ <XIcon />
106
+ </button>
107
+ </li>
108
+ </template>
@@ -0,0 +1,52 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, useAttrs, useSlots } from 'vue'
3
+ import styles from './Toggle.module.css'
4
+
5
+ // The Vue Toggle: the same look (Toggle.module.css) as the React one. The icon goes in the icon slot;
6
+ // other attributes and listeners go to the button.
7
+ defineOptions({ inheritAttrs: false })
8
+
9
+ const props = withDefaults(
10
+ defineProps<{
11
+ /** Starting pressed state when there is no v-model. */
12
+ defaultPressed?: boolean
13
+ /** Height and text size, the same as Button. */
14
+ size?: 'sm' | 'md' | 'lg'
15
+ type?: 'button' | 'submit' | 'reset'
16
+ }>(),
17
+ { defaultPressed: false, size: 'md', type: 'button' },
18
+ )
19
+ /** Pressed state. Use v-model:pressed, or leave it out and the toggle keeps its own state. */
20
+ const model = defineModel<boolean | undefined>('pressed', { type: Boolean, default: undefined })
21
+ const slots = useSlots() as { default?: () => unknown; icon?: () => unknown }
22
+ const attrs = useAttrs()
23
+
24
+ const own = ref(props.defaultPressed)
25
+ const pressed = computed(() => model.value ?? own.value)
26
+ const rest = computed(() => {
27
+ const { onClick: _onClick, ...others } = attrs
28
+ return others
29
+ })
30
+ // The caller's click runs first, and can stop the change with preventDefault.
31
+ const onClick = (e: MouseEvent) => {
32
+ const listener = attrs.onClick as ((e: MouseEvent) => void) | Array<(e: MouseEvent) => void> | undefined
33
+ ;(Array.isArray(listener) ? listener : listener ? [listener] : []).forEach((f) => f(e))
34
+ if (e.defaultPrevented) return
35
+ own.value = !pressed.value
36
+ model.value = own.value
37
+ }
38
+ </script>
39
+
40
+ <template>
41
+ <button
42
+ v-bind="rest"
43
+ :type="type"
44
+ :aria-pressed="pressed"
45
+ :class="[styles.root, styles[size], !slots.default && styles.iconOnly]"
46
+ :data-on="pressed || undefined"
47
+ @click="onClick"
48
+ >
49
+ <span v-if="slots.icon" :class="styles.icon"><slot name="icon" /></span>
50
+ <slot />
51
+ </button>
52
+ </template>
@@ -16,7 +16,7 @@ import {
16
16
  import { useDismiss } from '../../internal/layers'
17
17
  import { useLiquid } from '../../internal/liquid'
18
18
  import { mergeRefs } from '../../internal/mergeRefs'
19
- import { motionMs } from '../../internal/motion'
19
+ import { createTipTimer, tipEdge } from '../../internal/motion/tooltip'
20
20
  import { Portal } from '../../internal/Portal'
21
21
  import { useFloating, type Side } from '../../internal/useFloating'
22
22
  import { usePresence } from '../../internal/usePresence'
@@ -33,8 +33,6 @@ type TriggerProps = {
33
33
  onPointerUp?: (e: PointerEvent<HTMLElement>) => void
34
34
  }
35
35
 
36
- // How long a tip stays after a tap on a touch screen, so it can be read.
37
- const TOUCH_SHOW_MS = 1500
38
36
  export type TooltipProps = {
39
37
  /** Short text shown on hover and focus. It also describes the trigger to screen readers. */
40
38
  content: ReactNode
@@ -46,86 +44,57 @@ export type TooltipProps = {
46
44
  delay?: number
47
45
  }
48
46
 
49
- let lastClosedAt = 0
50
-
51
47
  export function Tooltip({ content, side = 'top', children, delay }: TooltipProps) {
52
48
  const id = useId()
53
49
  const [open, setOpen] = useState(false)
54
50
  const anchorRef = useRef<HTMLElement>(null)
55
51
  const tipRef = useRef<HTMLDivElement>(null)
56
- const timer = useRef<number | undefined>(undefined)
57
52
  const { mounted, state } = usePresence(open, 'morph-out')
58
53
  const floating = useFloating(anchorRef, tipRef, { open: mounted, side, offset: 8 })
59
54
  // The tip grows out of the edge of the target it points to, a sliver as wide as the target, and folds back into it.
60
- useLiquid(
61
- tipRef,
62
- () => {
63
- const r = anchorRef.current?.getBoundingClientRect()
64
- if (!r) return null
65
- if (floating.side === 'top') return new DOMRect(r.left, r.top, r.width, 2)
66
- if (floating.side === 'bottom') return new DOMRect(r.left, r.bottom - 2, r.width, 2)
67
- if (floating.side === 'left') return new DOMRect(r.left, r.top, 2, r.height)
68
- return new DOMRect(r.right - 2, r.top, 2, r.height)
69
- },
70
- state,
71
- mounted && floating.ready,
72
- )
55
+ useLiquid(tipRef, () => tipEdge(anchorRef.current, floating.side), state, mounted && floating.ready)
73
56
 
74
- const clear = () => window.clearTimeout(timer.current)
75
- const show = (wait: number) => {
76
- clear()
77
- timer.current = window.setTimeout(() => setOpen(true), wait)
78
- }
79
- const hide = (wait = 80) => {
80
- clear()
81
- timer.current = window.setTimeout(() => {
82
- setOpen(false)
83
- lastClosedAt = Date.now()
84
- }, wait)
85
- }
57
+ const delayRef = useRef(delay)
58
+ delayRef.current = delay
59
+ // When it shows and hides (motion/tooltip.ts).
60
+ const timing = useRef<ReturnType<typeof createTipTimer>>(null)
61
+ timing.current ??= createTipTimer(setOpen, () => delayRef.current)
62
+ const tip = timing.current
86
63
 
87
64
  // Esc hides it without moving focus (WCAG 1.4.13), and only it, not a dialog behind it.
88
65
  useDismiss(open, [], () => setOpen(false), { outside: false, hint: true })
89
66
 
90
- useEffect(() => clear, [])
67
+ useEffect(() => tip.clear, [tip])
91
68
 
92
69
  if (!isValidElement(children)) return children
93
70
  const props = children.props
94
71
 
95
- // Right after one closes, the next shows at once
96
- const hoverDelay = () => (Date.now() - lastClosedAt < 400 ? 0 : (delay ?? motionMs('delay-tooltip')))
97
-
98
72
  const trigger = cloneElement(children, {
99
73
  ref: mergeRefs(anchorRef, props.ref),
100
74
  'aria-describedby': [props['aria-describedby'], open ? id : null].filter(Boolean).join(' ') || undefined,
101
75
  onPointerEnter: (e: PointerEvent<HTMLElement>) => {
102
76
  props.onPointerEnter?.(e)
103
- if (e.pointerType === 'mouse') show(hoverDelay())
77
+ tip.enter(e)
104
78
  },
105
79
  onPointerLeave: (e: PointerEvent<HTMLElement>) => {
106
80
  props.onPointerLeave?.(e)
107
- if (e.pointerType === 'mouse') hide()
81
+ tip.leave(e)
108
82
  },
109
- // Touch has no hover: a tap shows the tip at once, and it fades a moment after the finger lifts.
110
83
  onPointerDown: (e: PointerEvent<HTMLElement>) => {
111
84
  props.onPointerDown?.(e)
112
- // Opened now, not on a timer: the finger lifts in the same moment, which would cancel it.
113
- if (e.pointerType === 'touch') {
114
- clear()
115
- setOpen(true)
116
- }
85
+ tip.down(e)
117
86
  },
118
87
  onPointerUp: (e: PointerEvent<HTMLElement>) => {
119
88
  props.onPointerUp?.(e)
120
- if (e.pointerType === 'touch') hide(TOUCH_SHOW_MS)
89
+ tip.up(e)
121
90
  },
122
91
  onFocus: (e: FocusEvent<HTMLElement>) => {
123
92
  props.onFocus?.(e)
124
- if (e.target.matches(':focus-visible')) show(0)
93
+ tip.focus(e)
125
94
  },
126
95
  onBlur: (e: FocusEvent<HTMLElement>) => {
127
96
  props.onBlur?.(e)
128
- hide(0)
97
+ tip.blur()
129
98
  },
130
99
  })
131
100
 
@@ -142,8 +111,8 @@ export function Tooltip({ content, side = 'top', children, delay }: TooltipProps
142
111
  data-state={state}
143
112
  data-side={floating.side}
144
113
  style={floating.style}
145
- onPointerEnter={clear}
146
- onPointerLeave={() => hide()}
114
+ onPointerEnter={tip.clear}
115
+ onPointerLeave={() => tip.hide()}
147
116
  >
148
117
  {content}
149
118
  </div>
@@ -0,0 +1,95 @@
1
+ <script setup lang="ts">
2
+ import { onBeforeUnmount, ref, shallowRef, useId, watch, type VNode } from 'vue'
3
+ import type { Side } from '../../internal/motion/floating'
4
+ import { dismissable } from '../../internal/motion/layers'
5
+ import { createLiquid } from '../../internal/motion/liquid'
6
+ import { createTipTimer, tipEdge } from '../../internal/motion/tooltip'
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 styles from './Tooltip.module.css'
11
+
12
+ // The Vue Tooltip: the same look (Tooltip.module.css), timing and growth as the React one.
13
+ // The default slot is the trigger: one focusable element, such as a Button.
14
+
15
+ const props = withDefaults(
16
+ defineProps<{
17
+ /** Short text shown on hover and focus. It also describes the trigger to screen readers. The content slot replaces it. */
18
+ content?: string
19
+ /** Preferred side of the trigger. It flips when there is no room. */
20
+ side?: Side
21
+ /** Delay before showing on hover. Defaults to the tooltip delay token. */
22
+ delay?: number
23
+ }>(),
24
+ { side: 'top' },
25
+ )
26
+ const slots = defineSlots<{ default?: () => VNode[]; content?: () => unknown }>()
27
+
28
+ const id = useId()
29
+ const open = ref(false)
30
+ const anchor = shallowRef<HTMLElement | null>(null)
31
+ const setAnchor = elementRef(anchor)
32
+ const tip = ref<HTMLElement | null>(null)
33
+ const { mounted, state } = usePresence(open, 'morph-out')
34
+ const { style, side: placed, ready } = useFloating(anchor, tip, mounted, () => ({ side: props.side, offset: 8 }))
35
+ // Vue sets a bare number as no length at all, so the place gets its unit here.
36
+ // The tip grows out of the edge of the target it points to, a sliver as wide as the target, and folds back into it.
37
+ const liquid = createLiquid(
38
+ () => tip.value,
39
+ () => tipEdge(anchor.value, placed.value),
40
+ )
41
+ watch([state, () => mounted.value && ready.value], ([s, on]) => on && liquid.play(s), { flush: 'post' })
42
+
43
+ // When it shows and hides (motion/tooltip.ts).
44
+ const timer = createTipTimer(
45
+ (v) => (open.value = v),
46
+ () => props.delay,
47
+ )
48
+
49
+ // Esc hides it without moving focus (WCAG 1.4.13), and only it, not a dialog behind it.
50
+ let release = () => {}
51
+ watch(open, (now) => {
52
+ release()
53
+ release = now ? dismissable(() => [], () => (open.value = false), { outside: false, hint: true }) : () => {}
54
+ })
55
+
56
+ onBeforeUnmount(() => {
57
+ timer.clear()
58
+ release()
59
+ liquid.destroy()
60
+ })
61
+
62
+ // The trigger is the slot's own element, given the tip's ARIA and events, like React's cloneElement.
63
+ const trigger = () => {
64
+ const node = firstNode(slots.default?.())
65
+ if (!node) return null
66
+ return cloneTrigger(node, setAnchor, {
67
+ 'aria-describedby': [node.props?.['aria-describedby'], open.value ? id : null].filter(Boolean).join(' ') || undefined,
68
+ onPointerenter: timer.enter,
69
+ onPointerleave: timer.leave,
70
+ onPointerdown: timer.down,
71
+ onPointerup: timer.up,
72
+ onFocus: timer.focus,
73
+ onBlur: timer.blur,
74
+ })
75
+ }
76
+ </script>
77
+
78
+ <template>
79
+ <component :is="trigger()" />
80
+ <Teleport v-if="mounted" to="body">
81
+ <div
82
+ :id="id"
83
+ ref="tip"
84
+ role="tooltip"
85
+ :class="styles.tip"
86
+ :data-state="state"
87
+ :data-side="placed"
88
+ :style="style"
89
+ @pointerenter="timer.clear"
90
+ @pointerleave="timer.hide()"
91
+ >
92
+ <slot name="content">{{ content }}</slot>
93
+ </div>
94
+ </Teleport>
95
+ </template>
@@ -0,0 +1,17 @@
1
+ <script setup lang="ts">
2
+ import styles from './VisuallyHidden.module.css'
3
+
4
+ // The Vue VisuallyHidden: the same look (VisuallyHidden.module.css) as the React one.
5
+ withDefaults(
6
+ defineProps<{
7
+ /** Shows the content while something inside it has keyboard focus, such as a skip link. */
8
+ focusable?: boolean
9
+ }>(),
10
+ { focusable: false },
11
+ )
12
+ defineSlots<{ default?: () => unknown }>()
13
+ </script>
14
+
15
+ <template>
16
+ <span :class="focusable ? styles.focusable : styles.root"><slot /></span>
17
+ </template>
@@ -0,0 +1,41 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, watch } from 'vue'
3
+ import { motionMs } from './motion'
4
+ import styles from './FieldMessage.module.css'
5
+
6
+ // The Vue field message: the same look (FieldMessage.module.css) as the React one.
7
+ const props = defineProps<{ helpId: string; errorId: string; help?: string; error?: string }>()
8
+
9
+ const hasError = computed(() => !!props.error)
10
+ // The last error stays visible while it animates out.
11
+ const lastError = ref(props.error)
12
+ let leaving = 0
13
+ watch(
14
+ () => props.error,
15
+ (now) => {
16
+ clearTimeout(leaving)
17
+ if (now) lastError.value = now
18
+ else leaving = window.setTimeout(() => (lastError.value = undefined), motionMs('base'))
19
+ },
20
+ )
21
+ const shown = computed(() => (hasError.value ? props.error : lastError.value))
22
+ </script>
23
+
24
+ <template>
25
+ <div v-if="help" :class="[styles.collapse, !hasError && styles.open]">
26
+ <div :class="styles.inner">
27
+ <p :id="helpId" :class="styles.help">{{ help }}</p>
28
+ </div>
29
+ </div>
30
+ <div :class="[styles.collapse, hasError && styles.open]" aria-live="polite">
31
+ <div :class="styles.inner">
32
+ <!-- Hidden from screen readers while it closes, so only the live error is read. -->
33
+ <p v-if="shown" :id="hasError ? errorId : undefined" :class="styles.error" :aria-hidden="hasError ? undefined : true">
34
+ <svg viewBox="0 0 16 16" aria-hidden="true" :class="styles.mark">
35
+ <circle cx="8" cy="8" r="7" />
36
+ <path d="M8 4.5v4.25M8 11v.01" />
37
+ </svg>{{ shown }}
38
+ </p>
39
+ </div>
40
+ </div>
41
+ </template>
@@ -0,0 +1,20 @@
1
+ <script setup lang="ts">
2
+ import { ref, watch } from 'vue'
3
+ import styles from './Roll.module.css'
4
+
5
+ // Text that rolls in from the side it moved toward (the Vue twin of Roll.tsx). With reduced motion it just
6
+ // changes. `still` swaps the text in place, for values that change on every frame of a drag.
7
+ const props = defineProps<{ text: string; class?: string; still?: boolean }>()
8
+ const dir = ref<'up' | 'down'>('up')
9
+ watch(
10
+ () => props.text,
11
+ (now, was) => (dir.value = now.localeCompare(was, undefined, { numeric: true }) > 0 ? 'up' : 'down'),
12
+ { flush: 'sync' },
13
+ )
14
+ </script>
15
+
16
+ <template>
17
+ <span :class="props.class ? `${styles.roll} ${props.class}` : styles.roll">
18
+ <span :key="still ? 'still' : text" :class="still ? undefined : styles.in" :data-dir="dir">{{ text }}</span>
19
+ </span>
20
+ </template>
@@ -1,118 +1,41 @@
1
1
  import { useEffect, useRef, type PointerEvent, type RefObject } from 'react'
2
- import { morphTo, rubber, speedTracker } from './feel'
3
- import { morphCurve, readMotionMs } from './motion'
2
+ import { rubber, speedTracker } from './feel'
3
+ import { createDragClose, createFling, release } from './motion/fling'
4
4
 
5
- export { rubber, speedTracker }
5
+ export { rubber, speedTracker, release }
6
6
 
7
- /**
8
- * A let-go: runs from `from` to `to` on the morph curve, starting at `velocity` (units per second), so
9
- * it carries on at the hand's speed. From rest it takes --gooee-motion-morph-out: Retime slows it,
10
- * reduced motion (0ms) jumps. Returns a stop function.
11
- */
12
- export function release(from: number, to: number, velocity: number, onFrame: (value: number) => void, onDone?: () => void) {
13
- return morphTo({ from, to, velocity, duration: readMotionMs('morph-out'), curve: morphCurve(), onFrame, onDone })
14
- }
15
-
16
- /**
17
- * A dialog panel that the hand drags along one axis and lets go of. `fling` glides it to a place at
18
- * the hand's speed. While it runs, data-fluid on the panel turns its CSS motion off; once the parent
19
- * closes it on the way out, the CSS close keyframes stay off too, so they do not start over.
20
- */
7
+ /** React's hold on createFling (motion/fling.ts): the panel's ref and its open state. */
21
8
  export function useFling(ref: RefObject<HTMLElement | null>, open: boolean, axis: 'x' | 'y') {
22
- const at = useRef(0)
23
- const target = useRef(0)
24
- const stop = useRef(() => {})
25
-
26
- const paint = (v: number) => {
27
- at.current = v
28
- if (ref.current) ref.current.style.transform = v ? `translate${axis === 'x' ? 'X' : 'Y'}(${v}px)` : ''
29
- }
9
+ const core = useRef<ReturnType<typeof createFling>>(null)
10
+ core.current ??= createFling(() => ref.current, axis)
11
+ const fling = core.current
30
12
 
31
- const fling = (to: number, speed: number) => {
32
- const el = ref.current
33
- if (!el) return
34
- stop.current()
35
- target.current = to
36
- el.setAttribute('data-fluid', '')
37
- stop.current = release(at.current, to, speed, paint, () => {
38
- if (to === 0) el.removeAttribute('data-fluid')
39
- })
40
- }
41
-
42
- useEffect(() => () => stop.current(), [])
13
+ useEffect(() => () => fling.stop(), [fling])
43
14
  useEffect(() => {
44
- // Opened again, even mid-close on the same panel: it starts at rest, not where the old glide was going.
45
- if (open) {
46
- stop.current()
47
- target.current = 0
48
- paint(0)
49
- ref.current?.removeAttribute('data-fluid')
50
- return
51
- }
52
- // Closed by Esc or a tap while gliding back: the CSS close takes over from where it is.
53
- if (target.current !== 0) return
54
- stop.current()
55
- ref.current?.removeAttribute('data-fluid')
56
- }, [open])
15
+ if (open) fling.opened()
16
+ else fling.closed()
17
+ }, [open, fling])
57
18
 
58
- return { at, paint, fling, stop: () => stop.current() }
19
+ return { at: { get current() { return fling.at } }, paint: fling.paint, fling: fling.fling, stop: fling.stop }
59
20
  }
60
21
 
61
- // Past this share of its height, or flicked down this fast (px per second), a let-go closes the sheet.
62
- const CLOSE_RATIO = 0.3
63
- const CLOSE_SPEED = 500
64
-
65
- /**
66
- * A bottom sheet the hand drags down to close. Returns pointer handlers for the part it is held by. A
67
- * let-go past a third of its height, or a flick down, closes it; any other let-go glides it back.
68
- * `can` is asked at each press, so a part can take hold only in its phone layout, or only by its header.
69
- */
22
+ /** React's hold on createDragClose (motion/fling.ts). Returns pointer handlers for the part it is held by. */
70
23
  export function useDragClose(ref: RefObject<HTMLElement | null>, open: boolean, onClose: () => void, can: (e: PointerEvent<HTMLElement>) => boolean = () => true) {
71
- const drag = useRef<{ y: number; dy: number; pointer: number; speed: ReturnType<typeof speedTracker> } | null>(null)
72
- const openRef = useRef(open)
73
- openRef.current = open
74
- const { at, paint, fling, stop } = useFling(ref, open, 'y')
75
-
76
- const onPointerDown = (e: PointerEvent<HTMLElement>) => {
77
- if ((e.target as HTMLElement).closest('button') || !can(e)) return
78
- if (e.pointerType === 'mouse' && e.button !== 0) return
79
- stop()
80
- // Caught mid-glide, it carries on from where it is.
81
- drag.current = { y: e.clientY - at.current, dy: at.current, pointer: e.pointerId, speed: speedTracker() }
82
- drag.current.speed.add(at.current)
83
- e.currentTarget.setPointerCapture(e.pointerId)
84
- ref.current?.setAttribute('data-dragging', '')
85
- }
86
-
87
- const onPointerMove = (e: PointerEvent<HTMLElement>) => {
88
- const d = drag.current
89
- const panel = ref.current
90
- if (!d || !panel || d.pointer !== e.pointerId) return
91
- const raw = e.clientY - d.y
92
- d.dy = raw >= 0 ? raw : rubber(raw, panel.offsetHeight)
93
- d.speed.add(d.dy)
94
- paint(d.dy)
95
- }
96
-
97
- const onPointerUp = (e: PointerEvent<HTMLElement>) => {
98
- const d = drag.current
99
- const panel = ref.current
100
- drag.current = null
101
- if (!d || !panel) return
102
- e.currentTarget.releasePointerCapture(d.pointer)
103
- panel.removeAttribute('data-dragging')
104
- const cancelled = e.type === 'pointercancel'
105
- const speed = cancelled ? 0 : d.speed.speed()
106
- const h = panel.offsetHeight
107
- if (!cancelled && (d.dy > h * CLOSE_RATIO || (speed > CLOSE_SPEED && d.dy > 24))) {
108
- fling(h, speed)
109
- onClose()
110
- // If the parent keeps it open, it glides back.
111
- requestAnimationFrame(() => {
112
- if (openRef.current) fling(0, 0)
113
- })
114
- } else fling(0, speed)
115
- }
24
+ const latest = useRef({ open, onClose, can })
25
+ latest.current = { open, onClose, can }
26
+ const core = useRef<ReturnType<typeof createDragClose>>(null)
27
+ core.current ??= createDragClose(() => ref.current, {
28
+ onClose: () => latest.current.onClose(),
29
+ isOpen: () => latest.current.open,
30
+ can: (e) => latest.current.can(e as PointerEvent<HTMLElement>),
31
+ })
32
+ const drag = core.current
33
+
34
+ useEffect(() => () => drag.fling.stop(), [drag])
35
+ useEffect(() => {
36
+ if (open) drag.fling.opened()
37
+ else drag.fling.closed()
38
+ }, [open, drag])
116
39
 
117
- return { onPointerDown, onPointerMove, onPointerUp, onPointerCancel: onPointerUp }
40
+ return { onPointerDown: drag.down, onPointerMove: drag.move, onPointerUp: drag.up, onPointerCancel: drag.up }
118
41
  }