gooee 0.50.0 → 0.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +17 -4
  2. package/package.json +5 -3
  3. package/scripts/add.js +28 -6
  4. package/src/components/Accordion/Accordion.vue +62 -0
  5. package/src/components/Accordion/AccordionItem.vue +45 -0
  6. package/src/components/Accordion/accordionContext.ts +6 -0
  7. package/src/components/Alert/Alert.tsx +7 -27
  8. package/src/components/Alert/Alert.vue +59 -0
  9. package/src/components/AlertDialog/AlertDialog.vue +126 -0
  10. package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
  11. package/src/components/AspectRatio/AspectRatio.vue +17 -0
  12. package/src/components/Avatar/Avatar.vue +56 -0
  13. package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
  14. package/src/components/Badge/Badge.vue +32 -0
  15. package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
  16. package/src/components/Button/Button.vue +130 -0
  17. package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
  18. package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
  19. package/src/components/Card/Card.vue +34 -0
  20. package/src/components/Center/Center.vue +32 -0
  21. package/src/components/Checkbox/Checkbox.tsx +8 -25
  22. package/src/components/Checkbox/Checkbox.vue +108 -0
  23. package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
  24. package/src/components/Cluster/Cluster.vue +34 -0
  25. package/src/components/CodeBlock/CodeBlock.vue +45 -0
  26. package/src/components/Collapsible/Collapsible.vue +59 -0
  27. package/src/components/Container/Container.vue +22 -0
  28. package/src/components/CopyButton/CopyButton.tsx +3 -49
  29. package/src/components/CopyButton/CopyButton.vue +116 -0
  30. package/src/components/Dial/Dial.tsx +12 -120
  31. package/src/components/Dial/Dial.vue +228 -0
  32. package/src/components/Dialog/Dialog.vue +139 -0
  33. package/src/components/Divider/Divider.vue +27 -0
  34. package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
  35. package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
  36. package/src/components/EmptyState/EmptyState.vue +33 -0
  37. package/src/components/Fab/Fab.tsx +4 -14
  38. package/src/components/Fab/Fab.vue +115 -0
  39. package/src/components/Fieldset/Fieldset.vue +42 -0
  40. package/src/components/FormField/FormField.tsx +2 -17
  41. package/src/components/FormField/FormField.vue +64 -0
  42. package/src/components/Grid/Grid.vue +43 -0
  43. package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -143
  44. package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
  45. package/src/components/IconButton/IconButton.vue +25 -0
  46. package/src/components/Input/Input.vue +112 -0
  47. package/src/components/InputGroup/InputGroup.vue +102 -0
  48. package/src/components/Kbd/Kbd.tsx +2 -12
  49. package/src/components/Kbd/Kbd.vue +21 -0
  50. package/src/components/Link/Link.vue +38 -0
  51. package/src/components/LivePill/LivePill.tsx +11 -39
  52. package/src/components/LivePill/LivePill.vue +152 -0
  53. package/src/components/Meter/Meter.vue +88 -0
  54. package/src/components/MorphButton/MorphButton.tsx +11 -67
  55. package/src/components/MorphButton/MorphButton.vue +120 -0
  56. package/src/components/NumberInput/NumberInput.tsx +11 -48
  57. package/src/components/NumberInput/NumberInput.vue +184 -0
  58. package/src/components/Pagination/Pagination.tsx +2 -15
  59. package/src/components/Pagination/Pagination.vue +87 -0
  60. package/src/components/Pagination/range.ts +15 -0
  61. package/src/components/PasswordInput/PasswordInput.vue +53 -0
  62. package/src/components/PickerWheel/DateWheel.vue +48 -0
  63. package/src/components/PickerWheel/PickerWheel.tsx +15 -129
  64. package/src/components/PickerWheel/PickerWheel.vue +77 -0
  65. package/src/components/PickerWheel/TimeWheel.vue +50 -0
  66. package/src/components/PickerWheel/WheelColumn.vue +70 -0
  67. package/src/components/Popover/Popover.vue +108 -0
  68. package/src/components/ProgressBar/ProgressBar.vue +48 -0
  69. package/src/components/Prose/Prose.vue +18 -0
  70. package/src/components/Radio/Radio.vue +49 -0
  71. package/src/components/Radio/RadioGroup.vue +69 -0
  72. package/src/components/Retime/Retime.tsx +7 -40
  73. package/src/components/Retime/Retime.vue +64 -0
  74. package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
  75. package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
  76. package/src/components/ScrollArea/ScrollArea.tsx +17 -129
  77. package/src/components/ScrollArea/ScrollArea.vue +58 -0
  78. package/src/components/SearchInput/SearchInput.tsx +2 -15
  79. package/src/components/SearchInput/SearchInput.vue +70 -0
  80. package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
  81. package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
  82. package/src/components/Select/Select.tsx +16 -47
  83. package/src/components/Select/Select.vue +236 -0
  84. package/src/components/Sheet/Sheet.tsx +52 -231
  85. package/src/components/Sheet/Sheet.vue +249 -0
  86. package/src/components/Skeleton/Skeleton.vue +38 -0
  87. package/src/components/Slider/Slider.tsx +25 -84
  88. package/src/components/Slider/Slider.vue +113 -0
  89. package/src/components/Spinner/Spinner.vue +30 -0
  90. package/src/components/Split/Split.vue +34 -0
  91. package/src/components/SplitFlap/SplitFlap.tsx +11 -175
  92. package/src/components/SplitFlap/SplitFlap.vue +52 -0
  93. package/src/components/Stack/Stack.vue +22 -0
  94. package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
  95. package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
  96. package/src/components/Switch/Switch.tsx +6 -75
  97. package/src/components/Switch/Switch.vue +66 -0
  98. package/src/components/Table/Table.module.css +12 -3
  99. package/src/components/Table/Table.tsx +8 -59
  100. package/src/components/Table/Table.vue +274 -0
  101. package/src/components/TableOfContents/TableOfContents.vue +90 -0
  102. package/src/components/Tabs/Tab.vue +37 -0
  103. package/src/components/Tabs/TabList.vue +47 -0
  104. package/src/components/Tabs/TabPanel.vue +26 -0
  105. package/src/components/Tabs/Tabs.module.css +2 -2
  106. package/src/components/Tabs/Tabs.tsx +11 -84
  107. package/src/components/Tabs/Tabs.vue +33 -0
  108. package/src/components/Tabs/tabsContext.ts +15 -0
  109. package/src/components/Tag/Tag.tsx +6 -26
  110. package/src/components/Tag/Tag.vue +63 -0
  111. package/src/components/Textarea/Textarea.tsx +2 -22
  112. package/src/components/Textarea/Textarea.vue +120 -0
  113. package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
  114. package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
  115. package/src/components/Toast/Toast.tsx +34 -264
  116. package/src/components/Toast/Toast.vue +138 -0
  117. package/src/components/Toast/ToastItem.vue +108 -0
  118. package/src/components/Toggle/Toggle.vue +52 -0
  119. package/src/components/Tooltip/Tooltip.tsx +17 -48
  120. package/src/components/Tooltip/Tooltip.vue +95 -0
  121. package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
  122. package/src/internal/FieldMessage.vue +41 -0
  123. package/src/internal/Roll.vue +20 -0
  124. package/src/internal/focus.ts +4 -47
  125. package/src/internal/icons.module.css +39 -27
  126. package/src/internal/layers.ts +7 -61
  127. package/src/internal/motion/alert.ts +17 -0
  128. package/src/internal/motion/buttonGroup.ts +21 -0
  129. package/src/internal/motion/checkbox.ts +39 -0
  130. package/src/internal/motion/collapseOut.ts +26 -0
  131. package/src/internal/motion/copyButton.ts +48 -0
  132. package/src/internal/motion/dial.ts +137 -0
  133. package/src/internal/motion/fab.ts +14 -0
  134. package/src/internal/motion/floating.ts +58 -0
  135. package/src/internal/motion/focus.ts +53 -0
  136. package/src/internal/motion/formField.ts +19 -0
  137. package/src/internal/motion/holdToConfirm.ts +147 -0
  138. package/src/internal/motion/keys.ts +42 -0
  139. package/src/internal/motion/layers.ts +78 -0
  140. package/src/internal/motion/listbox.ts +69 -0
  141. package/src/internal/motion/livePill.ts +71 -0
  142. package/src/internal/motion/menuKeys.ts +58 -0
  143. package/src/internal/motion/morphButton.ts +71 -0
  144. package/src/internal/motion/numberInput.ts +57 -0
  145. package/src/internal/motion/pickerWheel.ts +166 -0
  146. package/src/internal/motion/retime.ts +45 -0
  147. package/src/internal/motion/ruler.ts +57 -0
  148. package/src/internal/motion/scrollArea.ts +133 -0
  149. package/src/internal/motion/scrubLook.ts +15 -0
  150. package/src/internal/motion/segmented.ts +63 -0
  151. package/src/internal/motion/sheetDetents.ts +271 -0
  152. package/src/internal/motion/slider.ts +108 -0
  153. package/src/internal/motion/splitFlap.ts +205 -0
  154. package/src/internal/motion/swipeDeck.ts +236 -0
  155. package/src/internal/motion/switchThumb.ts +83 -0
  156. package/src/internal/motion/table.ts +77 -0
  157. package/src/internal/motion/tabs.ts +105 -0
  158. package/src/internal/motion/textarea.ts +22 -0
  159. package/src/internal/motion/themeIcon.ts +91 -0
  160. package/src/internal/motion/themeReveal.ts +71 -0
  161. package/src/internal/motion/toast.ts +291 -0
  162. package/src/internal/motion/tooltip.ts +58 -0
  163. package/src/internal/themeReveal.ts +3 -61
  164. package/src/internal/useFloating.ts +9 -49
  165. package/src/internal/useScrub.ts +1 -13
  166. package/src/internal/vue/trigger.ts +18 -0
  167. package/src/internal/vue/useFloating.ts +38 -0
  168. package/src/internal/vue/usePresence.ts +21 -0
  169. package/src/internal/vue/useScrub.ts +40 -0
  170. package/src/internal/vueIcons.ts +134 -0
  171. package/src/tokens.css +5 -0
  172. package/src/internal/relativeTime.ts +0 -26
@@ -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>
@@ -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>