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,139 @@
1
+ <script setup lang="ts">
2
+ import { computed, nextTick, onBeforeUnmount, ref, useId, watch } from 'vue'
3
+ import { createDragClose } from '../../internal/motion/fling'
4
+ import { trapFocus } from '../../internal/motion/focus'
5
+ import { dismissable, lockScroll } from '../../internal/motion/layers'
6
+ import { createDialogMorph } from '../../internal/motion/liquid'
7
+ import { motionMs } from '../../internal/motion'
8
+ import styles from './Dialog.module.css'
9
+
10
+ // The Vue Dialog: the same look (Dialog.module.css), morph, focus and drag to close as the React one.
11
+
12
+ const props = withDefaults(
13
+ defineProps<{
14
+ /** Heading of the dialog. Also its accessible name. The title slot replaces it. */
15
+ title?: string
16
+ /** Short text under the title, read out when the dialog opens. The description slot replaces it. */
17
+ description?: string
18
+ /** Maximum width of the panel. */
19
+ size?: 'sm' | 'md' | 'lg'
20
+ /** Set false for dialogs that must not close by a stray tap, like unsaved work. */
21
+ dismissOnOverlay?: boolean
22
+ /** Screen reader name for the close button. */
23
+ closeLabel?: string
24
+ /** Element to focus first. Defaults to the first focusable element. */
25
+ initialFocus?: HTMLElement | null
26
+ }>(),
27
+ { size: 'md', dismissOnOverlay: true, closeLabel: 'Close' },
28
+ )
29
+
30
+ /** Shows the dialog. Use v-model:open; the close button, Esc, an outside tap or a pull down set it false. */
31
+ const open = defineModel<boolean>('open', { required: true })
32
+ const slots = defineSlots<{ default?: () => unknown; title?: () => unknown; description?: () => unknown; footer?: () => unknown }>()
33
+
34
+ const id = useId()
35
+ const panel = ref<HTMLElement | null>(null)
36
+ const hasDescription = computed(() => !!(props.description || slots.description))
37
+ const close = () => (open.value = false)
38
+
39
+ // Stays in the page through the fold, then leaves.
40
+ const mounted = ref(open.value)
41
+ const state = computed(() => (open.value ? 'open' : 'closed'))
42
+ let leaving = 0
43
+
44
+ // The panel grows out of the control that opened it and folds back into it (motion/liquid.ts).
45
+ const morph = createDialogMorph(() => panel.value)
46
+ // On a phone the dialog is a bottom sheet, and the hand can pull it down to close.
47
+ const drag = createDragClose(() => panel.value, {
48
+ onClose: close,
49
+ isOpen: () => open.value,
50
+ can: (e) => window.matchMedia('(max-width: 520px)').matches && !!(e.target as HTMLElement).closest(`.${styles.handle}, .${styles.header}`),
51
+ })
52
+
53
+ let release: Array<() => void> = []
54
+ const stop = () => {
55
+ release.forEach((r) => r())
56
+ release = []
57
+ }
58
+
59
+ // On the server (Nuxt) there is no page to move or hold, so both watchers wait for the browser.
60
+ const server = typeof window === 'undefined'
61
+
62
+ // Before the new state renders, so the opener is read while it still has focus.
63
+ watch(
64
+ open,
65
+ (now, was) => {
66
+ if (server) return
67
+ clearTimeout(leaving)
68
+ if (now && !was) morph.opening()
69
+ if (now) {
70
+ mounted.value = true
71
+ drag.fling.opened()
72
+ } else {
73
+ drag.fling.closed()
74
+ leaving = window.setTimeout(() => (mounted.value = false), motionMs('morph-out'))
75
+ }
76
+ },
77
+ { immediate: true, flush: 'pre' },
78
+ )
79
+
80
+ // Once the panel is in the page: play the morph, and hold the scroll, the layer and focus while open.
81
+ watch(
82
+ [state, mounted],
83
+ async () => {
84
+ if (server || !mounted.value) return
85
+ await nextTick()
86
+ morph.play(state.value)
87
+ stop()
88
+ if (!open.value || !panel.value) return
89
+ const el = panel.value
90
+ release.push(lockScroll(), dismissable(() => [el], close, { outside: props.dismissOnOverlay }), trapFocus(el, { initialFocus: props.initialFocus }))
91
+ },
92
+ { immediate: true, flush: 'post' },
93
+ )
94
+
95
+ onBeforeUnmount(() => {
96
+ clearTimeout(leaving)
97
+ stop()
98
+ morph.destroy()
99
+ drag.fling.stop()
100
+ })
101
+
102
+ const grab = computed(() =>
103
+ props.dismissOnOverlay ? { onPointerdown: drag.down, onPointermove: drag.move, onPointerup: drag.up, onPointercancel: drag.up } : {},
104
+ )
105
+ </script>
106
+
107
+ <template>
108
+ <Teleport v-if="mounted" to="body">
109
+ <div :class="styles.overlay" :data-state="state" aria-hidden="true" />
110
+ <div :class="styles.positioner">
111
+ <div
112
+ ref="panel"
113
+ role="dialog"
114
+ aria-modal="true"
115
+ :aria-labelledby="`${id}-title`"
116
+ :aria-describedby="hasDescription ? `${id}-desc` : undefined"
117
+ tabindex="-1"
118
+ :class="[styles.panel, styles[size]]"
119
+ :data-state="state"
120
+ v-bind="grab"
121
+ >
122
+ <span v-if="dismissOnOverlay" :class="styles.handle" aria-hidden="true" />
123
+ <header :class="styles.header">
124
+ <div :class="styles.titles">
125
+ <h2 :id="`${id}-title`" :class="styles.title"><slot name="title">{{ title }}</slot></h2>
126
+ <p v-if="hasDescription" :id="`${id}-desc`" :class="styles.description"><slot name="description">{{ description }}</slot></p>
127
+ </div>
128
+ <button type="button" :class="styles.close" :aria-label="closeLabel" data-skip-initial-focus="true" @click="close">
129
+ <svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
130
+ <path d="M6 6l12 12M18 6L6 18" />
131
+ </svg>
132
+ </button>
133
+ </header>
134
+ <div v-if="slots.default" :class="styles.body"><slot /></div>
135
+ <footer v-if="slots.footer" :class="styles.footer"><slot name="footer" /></footer>
136
+ </div>
137
+ </div>
138
+ </Teleport>
139
+ </template>
@@ -0,0 +1,27 @@
1
+ <script setup lang="ts">
2
+ import styles from './Divider.module.css'
3
+
4
+ // The Vue Divider: the same look (Divider.module.css) as the React one.
5
+ withDefaults(
6
+ defineProps<{
7
+ /** Direction of the line. A vertical line stretches to the height of its flex row. */
8
+ orientation?: 'horizontal' | 'vertical'
9
+ /** Text in the middle of a horizontal line, such as "or". The label slot replaces it. */
10
+ label?: string
11
+ /** Draws the line in from the centre when it mounts. */
12
+ animated?: boolean
13
+ }>(),
14
+ { orientation: 'horizontal', animated: true },
15
+ )
16
+ const slots = defineSlots<{ label?: () => unknown }>()
17
+ </script>
18
+
19
+ <template>
20
+ <!-- A separator hides its children, so the role sits on the lines and the label is still read. -->
21
+ <div v-if="(label || slots.label) && orientation === 'horizontal'" :class="[styles.labelled, animated && styles.animated]">
22
+ <span :class="styles.line" role="separator" aria-orientation="horizontal" />
23
+ <span :class="styles.text"><slot name="label">{{ label }}</slot></span>
24
+ <span :class="styles.line" role="separator" aria-orientation="horizontal" />
25
+ </div>
26
+ <div v-else role="separator" :aria-orientation="orientation" :class="[styles.root, styles[orientation], animated && styles.animated]" />
27
+ </template>
@@ -17,6 +17,7 @@ import { useDismiss } from '../../internal/layers'
17
17
  import { useLiquid } from '../../internal/liquid'
18
18
  import { useBead } from '../../internal/liquidMore'
19
19
  import { mergeRefs } from '../../internal/mergeRefs'
20
+ import { createMenuKeys, itemKey, menuButtonKey, menuItems } from '../../internal/motion/menuKeys'
20
21
  import { Portal } from '../../internal/Portal'
21
22
  import { useFloating, type Align } from '../../internal/useFloating'
22
23
  import { usePresence } from '../../internal/usePresence'
@@ -62,7 +63,6 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
62
63
  const [focusAt, setFocusAt] = useState<'first' | 'last'>('first')
63
64
  const anchorRef = useRef<HTMLElement>(null)
64
65
  const menuRef = useRef<HTMLDivElement>(null)
65
- const typeahead = useRef({ text: '', at: 0 })
66
66
  const { mounted, state } = usePresence(open, 'morph-out')
67
67
  const floating = useFloating(anchorRef, menuRef, { open: mounted, side: 'bottom', align, offset: 6 })
68
68
  // The menu grows out of its button and folds back into it.
@@ -76,12 +76,9 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
76
76
  }
77
77
  useDismiss(open, [anchorRef, menuRef], (reason) => close(reason === 'escape'))
78
78
 
79
- const menuItems = () =>
80
- Array.from(menuRef.current?.querySelectorAll<HTMLElement>('[role="menuitem"]:not([aria-disabled="true"])') ?? [])
81
-
82
79
  useEffect(() => {
83
80
  if (!open) return
84
- const list = menuItems()
81
+ const list = menuItems(menuRef.current)
85
82
  ;(focusAt === 'first' ? list[0] : list[list.length - 1])?.focus({ preventScroll: true })
86
83
  }, [open, focusAt])
87
84
 
@@ -90,33 +87,11 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
90
87
  setOpen(true)
91
88
  }
92
89
 
93
- const onMenuKey = (e: KeyboardEvent) => {
94
- const list = menuItems()
95
- const i = list.indexOf(document.activeElement as HTMLElement)
96
- const go = (n: number) => {
97
- e.preventDefault()
98
- list[(n + list.length) % list.length]?.focus()
99
- }
100
- if (e.key === 'ArrowDown') go(i + 1)
101
- else if (e.key === 'ArrowUp') go(i - 1)
102
- else if (e.key === 'Home') go(0)
103
- else if (e.key === 'End') go(list.length - 1)
104
- // The menu is portalled, so focus goes back to the trigger and Tab carries on from there.
105
- else if (e.key === 'Tab') close()
106
- else if (e.key.length === 1 && /\S/.test(e.key)) {
107
- const now = Date.now()
108
- const t = typeahead.current
109
- t.text = now - t.at > 600 ? e.key.toLowerCase() : t.text + e.key.toLowerCase()
110
- t.at = now
111
- for (let n = 1; n <= list.length; n++) {
112
- const el = list[(i + n) % list.length]
113
- if (el.textContent?.trim().toLowerCase().startsWith(t.text)) {
114
- el.focus()
115
- break
116
- }
117
- }
118
- }
119
- }
90
+ // Arrows, Home, End, type-ahead and Tab (motion/menuKeys.ts).
91
+ const closeRef = useRef(close)
92
+ closeRef.current = close
93
+ const keys = useRef<ReturnType<typeof createMenuKeys>>(null)
94
+ keys.current ??= createMenuKeys(() => menuRef.current, () => closeRef.current())
120
95
 
121
96
  if (!isValidElement(trigger)) return null
122
97
  const tp = trigger.props
@@ -139,13 +114,8 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
139
114
  },
140
115
  onKeyDown: (e: KeyboardEvent<HTMLElement>) => {
141
116
  tp.onKeyDown?.(e)
142
- if (e.key === 'ArrowDown') {
143
- e.preventDefault()
144
- openMenu('first')
145
- } else if (e.key === 'ArrowUp') {
146
- e.preventDefault()
147
- openMenu('last')
148
- }
117
+ const at = menuButtonKey(e)
118
+ if (at) openMenu(at)
149
119
  },
150
120
  } as TriggerProps)}
151
121
  {mounted && (
@@ -160,7 +130,7 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
160
130
  data-state={state}
161
131
  data-side={floating.side}
162
132
  style={floating.style}
163
- onKeyDown={onMenuKey}
133
+ onKeyDown={keys.current}
164
134
  >
165
135
  {items.map((item, i) => {
166
136
  if (item.type === 'separator') return <div key={i} role="separator" className={styles.separator} />
@@ -187,12 +157,7 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
187
157
  close()
188
158
  item.onSelect?.()
189
159
  }}
190
- onKeyDown={(e) => {
191
- if (e.key === 'Enter' || e.key === ' ') {
192
- e.preventDefault()
193
- e.currentTarget.click()
194
- }
195
- }}
160
+ onKeyDown={itemKey}
196
161
  >
197
162
  {item.icon && <span className={styles.icon}>{item.icon}</span>}
198
163
  <span className={styles.label}>
@@ -0,0 +1,185 @@
1
+ <script lang="ts">
2
+ import type { Component } from 'vue'
3
+
4
+ export type MenuEntry =
5
+ | {
6
+ type?: 'item'
7
+ label: string
8
+ /** An icon component, such as EditIcon from the icons. */
9
+ icon?: Component
10
+ shortcut?: string
11
+ onSelect?: () => void
12
+ disabled?: boolean
13
+ /** Why the item is disabled. Shown as small text under the label while it is disabled. */
14
+ disabledReason?: string
15
+ /** Marks a destructive action in red and bold. Use a clear word too, such as "Delete". */
16
+ destructive?: boolean
17
+ }
18
+ | { type: 'separator' }
19
+ | { type: 'label'; label: string }
20
+ </script>
21
+
22
+ <script setup lang="ts">
23
+ import { computed, onBeforeUnmount, ref, shallowRef, useId, watch, type VNode } from 'vue'
24
+ import type { Align } from '../../internal/motion/floating'
25
+ import { dismissable } from '../../internal/motion/layers'
26
+ import { createLiquid } from '../../internal/motion/liquid'
27
+ import { bead } from '../../internal/motion/liquidMore'
28
+ import { createMenuKeys, itemKey, menuButtonKey, menuItems } from '../../internal/motion/menuKeys'
29
+ import { useFloating } from '../../internal/vue/useFloating'
30
+ import { usePresence } from '../../internal/vue/usePresence'
31
+ import { cloneTrigger, elementRef, firstNode } from '../../internal/vue/trigger'
32
+ import styles from './DropdownMenu.module.css'
33
+
34
+ // The Vue DropdownMenu: the same look (DropdownMenu.module.css), keys, growth and bead as the React one.
35
+ // The trigger slot is one button that opens the menu. It gets the menu ARIA attributes, and an id if it has none.
36
+
37
+ const props = withDefaults(
38
+ defineProps<{
39
+ /** Items, separators and group labels, in menu order. */
40
+ items: MenuEntry[]
41
+ /** Accessible name for the menu, if the trigger text is not enough. */
42
+ label?: string
43
+ /** Which edge of the trigger the menu lines up with. */
44
+ align?: Align
45
+ }>(),
46
+ { align: 'start' },
47
+ )
48
+ const slots = defineSlots<{ trigger?: () => VNode[] }>()
49
+
50
+ const id = useId()
51
+ const open = ref(false)
52
+ const focusAt = ref<'first' | 'last'>('first')
53
+ const anchor = shallowRef<HTMLElement | null>(null)
54
+ const setAnchor = elementRef(anchor)
55
+ const menu = ref<HTMLElement | null>(null)
56
+ const { mounted, state } = usePresence(open, 'morph-out')
57
+ const { style, side: placed, ready } = useFloating(anchor, menu, mounted, () => ({ side: 'bottom', align: props.align, offset: 6 }))
58
+ // Vue sets a bare number as no length at all, so the place gets its unit here.
59
+ // The menu grows out of its button and folds back into it.
60
+ const liquid = createLiquid(
61
+ () => menu.value,
62
+ () => anchor.value,
63
+ )
64
+ watch([state, () => mounted.value && ready.value], ([s, on]) => on && liquid.play(s), { flush: 'post' })
65
+
66
+ // The hover fill is a bead that follows the pointer from item to item.
67
+ let stopBead = () => {}
68
+ watch(
69
+ mounted,
70
+ (on) => {
71
+ stopBead()
72
+ stopBead = on && menu.value ? bead(menu.value, styles.bead) : () => {}
73
+ },
74
+ { flush: 'post' },
75
+ )
76
+
77
+ const close = (focusTrigger = true) => {
78
+ open.value = false
79
+ if (focusTrigger) anchor.value?.focus()
80
+ }
81
+ let releaseDismiss = () => {}
82
+ watch(open, (now) => {
83
+ releaseDismiss()
84
+ releaseDismiss = now ? dismissable(() => [anchor.value, menu.value], (reason) => close(reason === 'escape')) : () => {}
85
+ })
86
+
87
+ watch(
88
+ [open, focusAt],
89
+ () => {
90
+ if (!open.value) return
91
+ const list = menuItems(menu.value)
92
+ ;(focusAt.value === 'first' ? list[0] : list[list.length - 1])?.focus({ preventScroll: true })
93
+ },
94
+ { flush: 'post' },
95
+ )
96
+
97
+ onBeforeUnmount(() => {
98
+ releaseDismiss()
99
+ stopBead()
100
+ liquid.destroy()
101
+ })
102
+
103
+ const openMenu = (at: 'first' | 'last') => {
104
+ focusAt.value = at
105
+ open.value = true
106
+ }
107
+
108
+ // Arrows, Home, End, type-ahead and Tab (motion/menuKeys.ts).
109
+ const onMenuKey = createMenuKeys(
110
+ () => menu.value,
111
+ () => close(),
112
+ )
113
+
114
+ const select = (item: Extract<MenuEntry, { label: string; type?: 'item' }>) => {
115
+ if (item.disabled) return
116
+ close()
117
+ item.onSelect?.()
118
+ }
119
+
120
+ // Each item's place in the stagger, counting items only.
121
+ const stagger = computed(() => {
122
+ let n = 0
123
+ return props.items.map((item) => (item.type === 'separator' || item.type === 'label' ? -1 : n++))
124
+ })
125
+
126
+ // A caller's id on the trigger wins, so their own labels and tests keep working. Read in the same render, after the trigger.
127
+ let triggerId = `${id}-trigger`
128
+ // The trigger is the slot's own element, given the menu's ARIA, click and keys, like React's cloneElement.
129
+ const trigger = () => {
130
+ const node = firstNode(slots.trigger?.())
131
+ if (!node) return null
132
+ triggerId = (node.props?.id as string | undefined) ?? `${id}-trigger`
133
+ return cloneTrigger(node, setAnchor, {
134
+ id: triggerId,
135
+ 'aria-haspopup': 'menu',
136
+ 'aria-expanded': open.value,
137
+ 'aria-controls': open.value ? id : undefined,
138
+ onClick: () => (open.value ? close() : openMenu('first')),
139
+ onKeydown: (e: KeyboardEvent) => {
140
+ const at = menuButtonKey(e)
141
+ if (at) openMenu(at)
142
+ },
143
+ })
144
+ }
145
+ const labelledBy = () => triggerId
146
+ </script>
147
+
148
+ <template>
149
+ <component :is="trigger()" />
150
+ <Teleport v-if="mounted" to="body">
151
+ <div
152
+ :id="id"
153
+ ref="menu"
154
+ role="menu"
155
+ :aria-label="label"
156
+ :aria-labelledby="label ? undefined : labelledBy()"
157
+ :class="styles.menu"
158
+ :data-state="state"
159
+ :data-side="placed"
160
+ :style="style"
161
+ @keydown="onMenuKey"
162
+ >
163
+ <template v-for="(item, i) in items" :key="i">
164
+ <div v-if="item.type === 'separator'" role="separator" :class="styles.separator" />
165
+ <div v-else-if="item.type === 'label'" role="presentation" :class="styles.groupLabel">{{ item.label }}</div>
166
+ <div
167
+ v-else
168
+ role="menuitem"
169
+ tabindex="-1"
170
+ :aria-disabled="item.disabled || undefined"
171
+ :class="styles.item"
172
+ :data-destructive="item.destructive || undefined"
173
+ :style="{ '--i': stagger[i] }"
174
+ @pointermove="(e: PointerEvent) => !item.disabled && (e.currentTarget as HTMLElement).focus()"
175
+ @click="select(item)"
176
+ @keydown="itemKey"
177
+ >
178
+ <span v-if="item.icon" :class="styles.icon"><component :is="item.icon" /></span>
179
+ <span :class="styles.label">{{ item.label }}<span v-if="item.disabled && item.disabledReason" :class="styles.reason">{{ item.disabledReason }}</span></span>
180
+ <kbd v-if="item.shortcut" :class="styles.shortcut">{{ item.shortcut }}</kbd>
181
+ </div>
182
+ </template>
183
+ </div>
184
+ </Teleport>
185
+ </template>
@@ -0,0 +1,33 @@
1
+ <script setup lang="ts">
2
+ import { InboxIcon } from '../../internal/vueIcons'
3
+ import styles from './EmptyState.module.css'
4
+
5
+ // The Vue EmptyState: the same look (EmptyState.module.css) as the React one.
6
+ withDefaults(
7
+ defineProps<{
8
+ /** Short heading that says what is empty. The title slot replaces it. */
9
+ title?: string
10
+ /** Text under the title, such as what to do next. The description slot replaces it. */
11
+ description?: string
12
+ /** Heading level for the title, to fit the page outline. Use 1 when the empty state is the whole page. */
13
+ headingLevel?: 1 | 2 | 3 | 4
14
+ }>(),
15
+ { headingLevel: 3 },
16
+ )
17
+ /** icon: the picture above the title, hidden from screen readers. action: one primary action. secondaryAction: a less important one, shown before it. */
18
+ const slots = defineSlots<{ title?: () => unknown; description?: () => unknown; icon?: () => unknown; action?: () => unknown; secondaryAction?: () => unknown }>()
19
+ </script>
20
+
21
+ <template>
22
+ <div :class="styles.root">
23
+ <div :class="styles.icon" :style="{ '--i': 0 }" aria-hidden="true">
24
+ <slot name="icon"><InboxIcon /></slot>
25
+ </div>
26
+ <component :is="`h${headingLevel}`" :class="styles.title" :style="{ '--i': 1 }"><slot name="title">{{ title }}</slot></component>
27
+ <p v-if="description || slots.description" :class="styles.description" :style="{ '--i': 2 }"><slot name="description">{{ description }}</slot></p>
28
+ <div v-if="slots.action || slots.secondaryAction" :class="styles.actions" :style="{ '--i': 3 }">
29
+ <slot name="secondaryAction" />
30
+ <slot name="action" />
31
+ </div>
32
+ </div>
33
+ </template>
@@ -3,6 +3,7 @@
3
3
  import { useId, useRef, useState, type ReactNode } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
5
  import { useDismiss } from '../../internal/layers'
6
+ import { foldOnScroll } from '../../internal/motion/fab'
6
7
  import { useScrollFrame } from '../../internal/scrollFrame'
7
8
  import styles from './Fab.module.css'
8
9
 
@@ -40,20 +41,9 @@ export function Fab({ label, icon, onClick, extended = false, actions, position
40
41
  const firstRef = useRef<HTMLButtonElement>(null)
41
42
  const [open, setOpen] = useState(false)
42
43
  const [compact, setCompact] = useState(false)
43
- const last = useRef<number | null>(null)
44
-
45
- // Extended: down the page it folds to the icon, back up it opens again. It reads the scroll, never a timer.
46
- useScrollFrame(
47
- () => {
48
- const y = window.scrollY
49
- const prev = last.current
50
- last.current = y
51
- if (prev === null || Math.abs(y - prev) < 4) return
52
- const next = y > prev && y > 80
53
- return () => setCompact(next)
54
- },
55
- extended,
56
- )
44
+ // Extended, it folds to the icon down the page and opens again on the way up (motion/fab.ts).
45
+ const [fold] = useState(() => foldOnScroll(setCompact))
46
+ useScrollFrame(fold, extended)
57
47
 
58
48
  useDismiss(open, [rootRef], (reason) => {
59
49
  setOpen(false)
@@ -0,0 +1,115 @@
1
+ <script setup lang="ts">
2
+ import { onBeforeUnmount, onMounted, ref, useId, watch, type Component } from 'vue'
3
+ import { foldOnScroll } from '../../internal/motion/fab'
4
+ import { dismissable } from '../../internal/motion/layers'
5
+ import { onScrollFrame } from '../../internal/motion/scrollFrame'
6
+ import styles from './Fab.module.css'
7
+
8
+ export type FabAction = {
9
+ /** Shown beside the action's button and read as its name. */
10
+ label: string
11
+ /** An icon component, such as EditIcon from the icons. */
12
+ icon: Component
13
+ onSelect: () => void
14
+ }
15
+
16
+ // The Vue Fab: the same look (Fab.module.css), fold and actions as the React one. The main icon goes in the icon slot.
17
+ const props = withDefaults(
18
+ defineProps<{
19
+ /** The button's name. Shown as text when extended, and always read by screen readers. */
20
+ label: string
21
+ /** Shows the label beside the icon. It pours away into the icon as the page scrolls down, and back on the way up. */
22
+ extended?: boolean
23
+ /** A short stack of actions that pours up out of the button when it is tapped. */
24
+ actions?: FabAction[]
25
+ /** Where it sits along the bottom of the screen. */
26
+ position?: 'end' | 'center'
27
+ /** Sits at the bottom of its nearest positioned parent instead of the screen, for a demo or a panel. */
28
+ contained?: boolean
29
+ }>(),
30
+ { extended: false, position: 'end', contained: false },
31
+ )
32
+ /** click: on tap. With actions, a tap opens them instead. */
33
+ const emit = defineEmits<{ click: [] }>()
34
+ defineSlots<{ icon?: () => unknown }>()
35
+
36
+ const id = useId()
37
+ const rootEl = ref<HTMLElement | null>(null)
38
+ const buttonEl = ref<HTMLButtonElement | null>(null)
39
+ const firstEl = ref<HTMLButtonElement | null>(null)
40
+ const open = ref(false)
41
+ const compact = ref(false)
42
+
43
+ // Extended, it folds to the icon down the page and opens again on the way up (motion/fab.ts).
44
+ const fold = foldOnScroll((c) => (compact.value = c))
45
+ let stopFold: (() => void) | undefined
46
+ onMounted(() =>
47
+ watch(
48
+ () => props.extended,
49
+ (on) => {
50
+ stopFold?.()
51
+ stopFold = on ? onScrollFrame(fold) : undefined
52
+ },
53
+ { immediate: true },
54
+ ),
55
+ )
56
+
57
+ let stopDismiss: (() => void) | undefined
58
+ watch(open, (now) => {
59
+ stopDismiss?.()
60
+ stopDismiss = now
61
+ ? dismissable(
62
+ () => [rootEl.value],
63
+ (reason) => {
64
+ open.value = false
65
+ if (reason === 'escape') buttonEl.value?.focus()
66
+ },
67
+ )
68
+ : undefined
69
+ })
70
+ onBeforeUnmount(() => {
71
+ stopFold?.()
72
+ stopDismiss?.()
73
+ })
74
+
75
+ const setFirst = (el: unknown) => (firstEl.value = el as HTMLButtonElement | null)
76
+ const hasActions = () => Boolean(props.actions?.length)
77
+ const toggle = () => {
78
+ if (!hasActions()) return emit('click')
79
+ open.value = !open.value
80
+ if (open.value) requestAnimationFrame(() => firstEl.value?.focus())
81
+ }
82
+ const select = (a: FabAction) => {
83
+ open.value = false
84
+ buttonEl.value?.focus()
85
+ a.onSelect()
86
+ }
87
+ </script>
88
+
89
+ <template>
90
+ <div ref="rootEl" :class="[styles.root, styles[position], contained && styles.contained]" :data-open="open || undefined">
91
+ <ul v-if="actions?.length" :id="`${id}-actions`" :class="styles.actions" :inert="!open">
92
+ <li v-for="(a, i) in actions" :key="a.label" :style="{ '--i': actions.length - 1 - i }">
93
+ <button :ref="i === 0 ? setFirst : undefined" type="button" :class="styles.action" @click="select(a)">
94
+ <span :class="styles.actionLabel">{{ a.label }}</span>
95
+ <span :class="styles.actionIcon" aria-hidden="true"><component :is="a.icon" /></span>
96
+ </button>
97
+ </li>
98
+ </ul>
99
+ <button
100
+ ref="buttonEl"
101
+ type="button"
102
+ :class="styles.fab"
103
+ :aria-label="extended ? undefined : label"
104
+ :aria-expanded="actions?.length ? open : undefined"
105
+ :aria-controls="actions?.length ? `${id}-actions` : undefined"
106
+ :data-extended="(extended && !compact) || undefined"
107
+ @click="toggle"
108
+ >
109
+ <span :class="styles.icon" aria-hidden="true"><slot name="icon" /></span>
110
+ <span v-if="extended" :class="styles.labelWrap">
111
+ <span :class="styles.label">{{ label }}</span>
112
+ </span>
113
+ </button>
114
+ </div>
115
+ </template>