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,274 @@
1
+ <script setup lang="ts" generic="T">
2
+ import { computed, onBeforeUnmount, onMounted, ref, useId, watch, type FunctionalComponent, type VNodeChild } from 'vue'
3
+ import { flipRows, groupRows, nextSort, readCell as read, revealCell, scrollEdges, sortRows, type TableSort } from '../../internal/motion/table'
4
+ import Skeleton from '../Skeleton/Skeleton.vue'
5
+ import styles from './Table.module.css'
6
+
7
+ export type { TableSort }
8
+
9
+ export type TableColumn<R> = {
10
+ key: string
11
+ /** Plain text, or a render function for richer content. */
12
+ header: string | (() => VNodeChild)
13
+ /** Plain-text header, used as the row label on narrow screens. Defaults to header when it is a string. */
14
+ label?: string
15
+ /** Defaults to row[key]. */
16
+ cell?: (row: R) => VNodeChild
17
+ sortable?: boolean
18
+ /** What to sort by. Defaults to row[key]. */
19
+ sortValue?: (row: R) => string | number
20
+ align?: 'start' | 'end'
21
+ /** Any CSS width. A number is pixels. */
22
+ width?: number | string
23
+ }
24
+
25
+ export type TableLabels = {
26
+ /** Name of the checkbox in the header. */
27
+ selectAll: string
28
+ /** Name of each row checkbox, built from the row's name. */
29
+ selectRow: (name: string) => string
30
+ /** Spoken after a sort, with the column name and direction. */
31
+ sortedBy: (column: string, direction: TableSort['direction']) => string
32
+ /** Spoken when a third press turns the sort off. */
33
+ unsorted: (column: string) => string
34
+ /** The row count beside each group's name. */
35
+ groupCount: (count: number) => string
36
+ /** Spoken while the rows load. */
37
+ loading: string
38
+ }
39
+
40
+ // The Vue Table: the same look (Table.module.css), sort, groups and row glide (motion/table.ts) as the React one.
41
+ const props = withDefaults(
42
+ defineProps<{
43
+ /** The columns, in order, and how each one reads and shows a row. */
44
+ columns: TableColumn<T>[]
45
+ /** The data, one item per row. */
46
+ rows: T[]
47
+ /** Returns a stable, unique id for a row. Used for keys, selection and sort motion. */
48
+ getRowId: (row: T) => string
49
+ /** Always required. Names the table for screen readers. */
50
+ caption: string
51
+ /** Hides the caption visually but keeps it for screen readers. */
52
+ hideCaption?: boolean
53
+ /** Starting sort when there is no v-model:sort. */
54
+ defaultSort?: TableSort | null
55
+ /** Gathers rows under a header per group, such as each row's status. Groups keep the order they first
56
+ * appear in; the sort applies inside each group. Rows glide to their group when it changes. */
57
+ groupBy?: (row: T) => string
58
+ /** Adds a checkbox column. */
59
+ selectable?: boolean
60
+ /** Starting selection when there is no v-model:selected. */
61
+ defaultSelected?: string[]
62
+ /** Names each row checkbox, such as the person's name. Defaults to the first column's value. */
63
+ rowLabel?: (row: T) => string
64
+ /** On a narrow screen: 'scroll' keeps the table and scrolls it sideways with the first column
65
+ * in place; 'stack' turns each row into a card with its labels. */
66
+ layout?: 'scroll' | 'stack'
67
+ /** Scrolls the body under a sticky header past this height. A number is pixels. */
68
+ maxHeight?: number | string
69
+ /** Shown in place of rows when there are none. The empty slot replaces it. */
70
+ emptyText?: string
71
+ /** Shows skeleton rows in place of the data and holds sorting and selection still. */
72
+ loading?: boolean
73
+ /** How many skeleton rows show while loading. */
74
+ loadingRows?: number
75
+ /** Screen reader text for checkboxes and sort news. Missing keys use the English defaults. */
76
+ labels?: Partial<TableLabels>
77
+ }>(),
78
+ { defaultSort: null, defaultSelected: () => [], layout: 'scroll', emptyText: 'Nothing here yet.', loading: false, loadingRows: 5 },
79
+ )
80
+ /** The sort: ascending, descending, then null as a header is pressed. Leave it out and the table keeps its own. */
81
+ const sortModel = defineModel<TableSort | null | undefined>('sort', { default: undefined })
82
+ /** Ids of the selected rows. Leave it out and the table keeps its own. */
83
+ const selectedModel = defineModel<string[] | undefined>('selected', { default: undefined })
84
+ defineSlots<{ empty?: () => unknown }>()
85
+
86
+ const labels = computed<TableLabels>(() => ({
87
+ selectAll: 'Select all rows',
88
+ selectRow: (name) => `Select ${name}`,
89
+ sortedBy: (column, direction) => `Sorted by ${column}, ${direction}`,
90
+ unsorted: (column) => `No longer sorted by ${column}`,
91
+ groupCount: (count) => `${count} ${count === 1 ? 'row' : 'rows'}`,
92
+ loading: 'Loading rows',
93
+ ...props.labels,
94
+ }))
95
+ const id = useId()
96
+ const px = (v: number | string | undefined) => (typeof v === 'number' ? `${v}px` : v)
97
+
98
+ const sort = computed(() => (sortModel.value === undefined ? props.defaultSort : sortModel.value))
99
+ const selected = computed(() => selectedModel.value ?? props.defaultSelected)
100
+ const announce = ref('')
101
+
102
+ const scrollEl = ref<HTMLDivElement | null>(null)
103
+ const tableEl = ref<HTMLTableElement | null>(null)
104
+ const more = ref({ start: false, end: false })
105
+ const measure = () => {
106
+ if (!scrollEl.value) return
107
+ const { start, end } = scrollEdges(scrollEl.value)
108
+ if (more.value.start !== start || more.value.end !== end) more.value = { start, end }
109
+ }
110
+ const reveal = (e: FocusEvent) => scrollEl.value && revealCell(scrollEl.value, e.target)
111
+ let ro: ResizeObserver | undefined
112
+
113
+ const sorted = computed(() => sortRows(props.rows, props.columns, sort.value))
114
+ const groupOrder: string[] = []
115
+ const groups = computed(() => (props.groupBy ? groupRows(props.rows, sorted.value, props.groupBy, groupOrder) : null))
116
+ const shape = computed(() => (groups.value ? groups.value.map((g) => g.key).join('|') : ''))
117
+ const order = computed(() => (groups.value ? groups.value.map((g) => `${g.key}:${g.rows.map(props.getRowId).join(',')}`).join('|') : sorted.value.map(props.getRowId).join('|')))
118
+
119
+ // FLIP: rows glide to their new place after a sort, and snap with the spring when the groups change (motion/table.ts).
120
+ let lastTops = new Map<string, number>()
121
+ let lastShape = ''
122
+ const flip = () => {
123
+ if (!tableEl.value) return
124
+ lastTops = flipRows(tableEl.value, lastTops, shape.value !== lastShape)
125
+ lastShape = shape.value
126
+ }
127
+ watch(order, flip, { flush: 'post' })
128
+ onMounted(() => {
129
+ flip()
130
+ const el = scrollEl.value
131
+ if (!el) return
132
+ ro = new ResizeObserver(measure)
133
+ ro.observe(el)
134
+ if (el.firstElementChild) ro.observe(el.firstElementChild)
135
+ })
136
+ onBeforeUnmount(() => ro?.disconnect())
137
+
138
+ const labelOf = (c: TableColumn<T>) => c.label ?? (typeof c.header === 'string' ? c.header : c.key)
139
+
140
+ const toggleSort = (key: string) => {
141
+ const next = nextSort(sort.value, key)
142
+ sortModel.value = next
143
+ const col = props.columns.find((c) => c.key === key)
144
+ const name = col ? labelOf(col) : key
145
+ announce.value = next ? labels.value.sortedBy(name, next.direction) : labels.value.unsorted(name)
146
+ }
147
+
148
+ const ids = computed(() => sorted.value.map(props.getRowId))
149
+ const selectedSet = computed(() => new Set(selected.value))
150
+ const allOn = computed(() => ids.value.length > 0 && ids.value.every((r) => selectedSet.value.has(r)))
151
+ const someOn = computed(() => !allOn.value && ids.value.some((r) => selectedSet.value.has(r)))
152
+ const scrollable = computed(() => Boolean(props.maxHeight) || more.value.start || more.value.end)
153
+ const nameOf = (row: T) => (props.rowLabel ? props.rowLabel(row) : String(read(row, props.columns[0]?.key ?? '') ?? props.getRowId(row)))
154
+ const colCount = computed(() => props.columns.length + (props.selectable ? 1 : 0))
155
+ const setRow = (rid: string, on: boolean) => (selectedModel.value = on ? [...selected.value, rid] : selected.value.filter((s) => s !== rid))
156
+ const setAll = (on: boolean) => (selectedModel.value = on ? Array.from(new Set([...selected.value, ...ids.value])) : selected.value.filter((s) => !ids.value.includes(s)))
157
+
158
+ // Keeps the entrance stagger going across groups.
159
+ const rowGroups = computed(() => {
160
+ let i = 0
161
+ const list = groups.value && groups.value.length > 0 ? groups.value : [{ key: '', rows: sorted.value }]
162
+ return list.map((g) => ({ key: g.key, rows: g.rows.map((row) => ({ row, rid: props.getRowId(row), i: Math.min(i++, 12) })) }))
163
+ })
164
+ // Draws what a header or cell function returns.
165
+ const Out: FunctionalComponent<{ v: VNodeChild }> = (p) => p.v
166
+ </script>
167
+
168
+ <template>
169
+ <div :class="styles.root" :data-layout="layout" :data-more-start="more.start || undefined" :data-more-end="more.end || undefined">
170
+ <div
171
+ ref="scrollEl"
172
+ :class="styles.scroll"
173
+ :style="{ maxHeight: px(maxHeight) }"
174
+ :tabindex="scrollable ? 0 : undefined"
175
+ :role="scrollable ? 'region' : undefined"
176
+ :aria-labelledby="scrollable ? `${id}-cap` : undefined"
177
+ @scroll="measure"
178
+ @focusin="reveal"
179
+ >
180
+ <!-- Explicit roles keep table semantics when rows restyle as cards (layout="stack") -->
181
+ <table ref="tableEl" role="table" :class="styles.table" :aria-labelledby="`${id}-cap`" :aria-busy="loading || undefined">
182
+ <caption :id="`${id}-cap`" :class="[styles.caption, hideCaption && styles.srOnly]">{{ caption }}</caption>
183
+ <thead role="rowgroup" :class="styles.head">
184
+ <tr role="row">
185
+ <th v-if="selectable" role="columnheader" scope="col" :class="styles.checkCell">
186
+ <span :class="styles.check">
187
+ <input
188
+ type="checkbox"
189
+ :aria-label="labels.selectAll"
190
+ :checked="allOn"
191
+ :indeterminate="someOn"
192
+ :disabled="loading"
193
+ :class="styles.checkInput"
194
+ @change="setAll(($event.target as HTMLInputElement).checked)"
195
+ />
196
+ <span :class="styles.checkBox" :data-state="someOn ? 'mixed' : allOn ? 'on' : 'off'" aria-hidden="true">
197
+ <svg viewBox="0 0 16 16"><path :class="styles.tick" d="M3.5 8.5l3 3 6-7" pathLength="1" /><path :class="styles.dash" d="M4 8h8" pathLength="1" /></svg>
198
+ </span>
199
+ </span>
200
+ </th>
201
+ <th
202
+ v-for="c in columns"
203
+ :key="c.key"
204
+ role="columnheader"
205
+ scope="col"
206
+ :aria-sort="c.sortable ? (sort?.key === c.key ? sort.direction : 'none') : undefined"
207
+ :class="styles.th"
208
+ :data-align="c.align ?? 'start'"
209
+ :data-sortable="c.sortable || undefined"
210
+ :style="{ width: px(c.width) }"
211
+ >
212
+ <button
213
+ v-if="c.sortable"
214
+ type="button"
215
+ :class="styles.sortButton"
216
+ :disabled="loading"
217
+ :data-active="sort?.key === c.key || undefined"
218
+ @click="toggleSort(c.key)"
219
+ >
220
+ <span><Out :v="typeof c.header === 'string' ? c.header : c.header()" /></span>
221
+ <svg viewBox="0 0 16 16" :class="styles.sortIcon" :data-dir="sort?.key === c.key ? sort.direction : undefined" aria-hidden="true">
222
+ <path d="M8 12.5v-9M4.5 7L8 3.5 11.5 7" />
223
+ </svg>
224
+ </button>
225
+ <Out v-else :v="typeof c.header === 'string' ? c.header : c.header()" />
226
+ </th>
227
+ </tr>
228
+ </thead>
229
+ <tbody v-if="loading" role="rowgroup">
230
+ <tr v-for="r in loadingRows" :key="r" aria-hidden="true" :class="[styles.row, styles.loadingRow]">
231
+ <td v-if="selectable" :class="styles.checkCell" />
232
+ <td v-for="(c, i) in columns" :key="c.key" :class="styles.td" :data-align="c.align ?? 'start'" :data-label="labelOf(c)">
233
+ <Skeleton shape="text" :width="`${[72, 56, 84][(r - 1 + i) % 3]}%`" />
234
+ </td>
235
+ </tr>
236
+ </tbody>
237
+ <template v-else>
238
+ <tbody v-for="g in rowGroups" :key="g.key" role="rowgroup" v-bind="groups && groups.length > 0 ? { class: styles.group } : {}">
239
+ <tr v-if="groups && groups.length > 0" role="row" :data-row-id="`group:${g.key}`" :class="styles.groupRow">
240
+ <th role="rowheader" scope="rowgroup" :colspan="colCount" :class="styles.groupHead">
241
+ <span>{{ g.key }}</span>{{ ' ' }}<span :class="styles.groupCount">{{ labels.groupCount(g.rows.length) }}</span>
242
+ </th>
243
+ </tr>
244
+ <tr v-for="{ row, rid, i } in g.rows" :key="rid" role="row" :data-row-id="rid" :class="styles.row" :data-selected="selectedSet.has(rid) || undefined" :style="{ '--i': i }">
245
+ <td v-if="selectable" role="cell" :class="styles.checkCell">
246
+ <span :class="styles.check">
247
+ <input
248
+ type="checkbox"
249
+ :aria-label="labels.selectRow(nameOf(row))"
250
+ :checked="selectedSet.has(rid)"
251
+ :class="styles.checkInput"
252
+ @change="setRow(rid, ($event.target as HTMLInputElement).checked)"
253
+ />
254
+ <span :class="styles.checkBox" :data-state="selectedSet.has(rid) ? 'on' : 'off'" aria-hidden="true">
255
+ <svg viewBox="0 0 16 16"><path :class="styles.tick" d="M3.5 8.5l3 3 6-7" pathLength="1" /><path :class="styles.dash" d="M4 8h8" pathLength="1" /></svg>
256
+ </span>
257
+ </span>
258
+ </td>
259
+ <td v-for="c in columns" :key="c.key" role="cell" :class="styles.td" :data-align="c.align ?? 'start'" :data-label="labelOf(c)">
260
+ <!-- One wrapper, so the card layout always gets a label and a value -->
261
+ <span><Out :v="c.cell ? c.cell(row) : String(read(row, c.key) ?? '')" /></span>
262
+ </td>
263
+ </tr>
264
+ <tr v-if="!groups?.length && sorted.length === 0" role="row">
265
+ <td role="cell" :colspan="colCount" :class="styles.empty"><slot name="empty">{{ emptyText }}</slot></td>
266
+ </tr>
267
+ </tbody>
268
+ </template>
269
+ </table>
270
+ </div>
271
+ <p :class="styles.srOnly" role="status">{{ announce }}</p>
272
+ <p :class="styles.srOnly" role="status">{{ loading ? labels.loading : '' }}</p>
273
+ </div>
274
+ </template>
@@ -0,0 +1,90 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
3
+ import { prefersReducedMotion } from '../../internal/motion'
4
+ import { ArrowUpIcon } from '../../internal/vueIcons'
5
+ import styles from './TableOfContents.module.css'
6
+
7
+ // The Vue TableOfContents: the same look (TableOfContents.module.css) and reading strip as the React one.
8
+
9
+ export type TocItem = {
10
+ /** The id of the heading on the page. */
11
+ id: string
12
+ label: string
13
+ }
14
+
15
+ const props = withDefaults(
16
+ defineProps<{
17
+ /** The sections, in page order: each heading's id and the text to show for it. */
18
+ items: TocItem[]
19
+ /** Heading above the list, also the nav's name. */
20
+ title?: string
21
+ /** Adds a way back to the top once the reader has passed the first section. */
22
+ backToTop?: boolean
23
+ }>(),
24
+ { title: 'On this page', backToTop: false },
25
+ )
26
+
27
+ const active = ref(props.items[0]?.id)
28
+ const at = computed(() => Math.max(0, props.items.findIndex((t) => t.id === active.value)))
29
+
30
+ // The section being read is the last heading past the top third of the screen.
31
+ let headings: HTMLElement[] = []
32
+ const update = () => {
33
+ const line = window.innerHeight / 3
34
+ let current = headings[0]?.id
35
+ for (const h of headings) if (h.getBoundingClientRect().top <= line) current = h.id
36
+ // A short last section never reaches the line, so the bottom of the page selects it.
37
+ const atBottom = window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 2
38
+ active.value = atBottom ? headings[headings.length - 1]?.id : current
39
+ }
40
+ const find = () => {
41
+ headings = props.items.map((t) => document.getElementById(t.id)).filter((h): h is HTMLElement => !!h)
42
+ update()
43
+ }
44
+ onMounted(() => {
45
+ find()
46
+ window.addEventListener('scroll', update, { passive: true })
47
+ window.addEventListener('resize', update)
48
+ })
49
+ watch(() => props.items, find)
50
+ onBeforeUnmount(() => {
51
+ window.removeEventListener('scroll', update)
52
+ window.removeEventListener('resize', update)
53
+ })
54
+
55
+ const plain = (e: MouseEvent) => e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey
56
+
57
+ // A plain click scrolls there and keeps one history entry; Cmd-click still opens a new tab.
58
+ const go = (e: MouseEvent, id: string) => {
59
+ const heading = document.getElementById(id)
60
+ if (!plain(e) || !heading) return
61
+ e.preventDefault()
62
+ heading.scrollIntoView({ behavior: prefersReducedMotion() ? 'auto' : 'smooth', block: 'start' })
63
+ if (!heading.hasAttribute('tabindex')) heading.setAttribute('tabindex', '-1')
64
+ heading.focus({ preventScroll: true })
65
+ window.history.replaceState(window.history.state, '', `#${id}`)
66
+ }
67
+
68
+ const toTop = (e: MouseEvent) => {
69
+ if (!plain(e)) return
70
+ e.preventDefault()
71
+ window.scrollTo({ top: 0, behavior: prefersReducedMotion() ? 'auto' : 'smooth' })
72
+ window.history.replaceState(window.history.state, '', window.location.pathname + window.location.search)
73
+ }
74
+ </script>
75
+
76
+ <template>
77
+ <nav :class="styles.root" :aria-label="title">
78
+ <p :class="styles.title">{{ title }}</p>
79
+ <ol :class="styles.list">
80
+ <li v-for="(t, n) in items" :key="t.id" :data-state="n < at ? 'read' : n === at ? 'here' : 'ahead'">
81
+ <a :href="`#${t.id}`" :class="styles.link" :aria-current="active === t.id ? 'location' : undefined" @click="go($event, t.id)">
82
+ <span :class="styles.node" aria-hidden="true" />{{ t.label }}</a
83
+ >
84
+ </li>
85
+ </ol>
86
+ <a v-if="backToTop && at > 0" href="#" :class="styles.toTop" @click="toTop">
87
+ <ArrowUpIcon aria-hidden="true" />Back to top</a
88
+ >
89
+ </nav>
90
+ </template>
@@ -0,0 +1,37 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { revealTab } from '../../internal/motion/tabs'
4
+ import { safe, useTabs } from './tabsContext'
5
+ import styles from './Tabs.module.css'
6
+
7
+ const props = defineProps<{
8
+ /** Picks this tab. Must match the value of its TabPanel. */
9
+ value: string
10
+ /** Stops the tab from being picked. Arrow keys skip it. */
11
+ disabled?: boolean
12
+ }>()
13
+
14
+ const ctx = useTabs()
15
+ const on = computed(() => ctx.value.value === props.value)
16
+ const id = computed(() => `${ctx.baseId}-tab-${safe(props.value)}`)
17
+ const pick = () => {
18
+ ctx.set(props.value)
19
+ revealTab(id.value)
20
+ }
21
+ </script>
22
+
23
+ <template>
24
+ <button
25
+ :id="id"
26
+ type="button"
27
+ role="tab"
28
+ :aria-selected="on"
29
+ :aria-controls="`${ctx.baseId}-panel-${safe(value)}`"
30
+ :tabindex="on ? 0 : -1"
31
+ :disabled="disabled"
32
+ :class="styles.tab"
33
+ @click="pick"
34
+ >
35
+ <slot />
36
+ </button>
37
+ </template>
@@ -0,0 +1,47 @@
1
+ <script setup lang="ts">
2
+ import { nextTick, onBeforeUnmount, onMounted, onUpdated, ref, watch } from 'vue'
3
+ import { createTabsRise, measureTab, setTabStop, tabKey, type TabBar } from '../../internal/motion/tabs'
4
+ import { useTabs } from './tabsContext'
5
+ import styles from './Tabs.module.css'
6
+
7
+ defineProps<{
8
+ /** Screen reader name for the row of tabs. */
9
+ label: string
10
+ }>()
11
+
12
+ const { value } = useTabs()
13
+ const list = ref<HTMLElement | null>(null)
14
+ const riseEl = ref<HTMLElement | null>(null)
15
+ const bar = ref<TabBar | null>(null)
16
+
17
+ const measure = () => {
18
+ const next = list.value && measureTab(list.value, value.value)
19
+ if (next) bar.value = next
20
+ }
21
+ let ro: ResizeObserver | null = null
22
+ onMounted(() => {
23
+ measure()
24
+ setTabStop(list.value)
25
+ ro = new ResizeObserver(measure)
26
+ if (list.value) ro.observe(list.value)
27
+ })
28
+ onUpdated(() => setTabStop(list.value))
29
+ watch(value, () => nextTick(() => (measure(), setTabStop(list.value))))
30
+
31
+ // The rise stretches over to a new choice (motion/tabs.ts).
32
+ const rise = createTabsRise()
33
+ watch(bar, (b) => rise.place(riseEl.value, b), { flush: 'post' })
34
+ onBeforeUnmount(() => {
35
+ ro?.disconnect()
36
+ rise.destroy()
37
+ })
38
+ </script>
39
+
40
+ <template>
41
+ <div :class="styles.listScroll">
42
+ <div ref="list" role="tablist" :aria-label="label" :class="styles.list" @keydown="tabKey(list, $event)">
43
+ <slot />
44
+ <span v-if="bar" ref="riseEl" :class="styles.rise" aria-hidden="true" />
45
+ </div>
46
+ </div>
47
+ </template>
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { safe, useTabs } from './tabsContext'
4
+ import styles from './Tabs.module.css'
5
+
6
+ const props = defineProps<{
7
+ /** Shows this panel when the Tab with the same value is selected. Its content mounts only then. */
8
+ value: string
9
+ }>()
10
+
11
+ const ctx = useTabs()
12
+ const on = computed(() => ctx.value.value === props.value)
13
+ </script>
14
+
15
+ <template>
16
+ <div
17
+ :id="`${ctx.baseId}-panel-${safe(value)}`"
18
+ role="tabpanel"
19
+ :aria-labelledby="`${ctx.baseId}-tab-${safe(value)}`"
20
+ :hidden="!on"
21
+ :tabindex="0"
22
+ :class="styles.panel"
23
+ >
24
+ <slot v-if="on" />
25
+ </div>
26
+ </template>
@@ -1,6 +1,6 @@
1
1
  .root {
2
- /* The panel's surface; the chosen tab rises out of it in the same colour. */
3
- --tabs-panel: var(--gooee-color-surface-sunken);
2
+ /* The panel's surface; the chosen tab rises out of it in the same colour (--gooee-tabs-panel, by theme). */
3
+ --tabs-panel: var(--gooee-tabs-panel);
4
4
  --tabs-r: var(--gooee-radius-md);
5
5
  display: flex;
6
6
  flex-direction: column;
@@ -10,8 +10,7 @@ import {
10
10
  type KeyboardEvent,
11
11
  type ReactNode,
12
12
  } from 'react'
13
- import { morphCurve, motionMs, prefersReducedMotion } from '../../internal/motion'
14
- import { bezier } from '../../internal/feel'
13
+ import { createTabsRise, measureTab, revealTab, setTabStop, tabKey } from '../../internal/motion/tabs'
15
14
  import { cx } from '../../internal/cx'
16
15
  import { useControllable } from '../../internal/useControllable'
17
16
  import styles from './Tabs.module.css'
@@ -69,8 +68,8 @@ export function TabList({ label, className, children }: TabListProps) {
69
68
  const list = listRef.current
70
69
  if (!list) return
71
70
  const measure = () => {
72
- const el = list.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
73
- if (el) setBar({ x: el.offsetLeft, w: el.offsetWidth, room: list.offsetWidth, value })
71
+ const next = measureTab(list, value)
72
+ if (next) setBar(next)
74
73
  }
75
74
  measure()
76
75
  const ro = new ResizeObserver(measure)
@@ -78,88 +77,16 @@ export function TabList({ label, className, children }: TabListProps) {
78
77
  return () => ro.disconnect()
79
78
  }, [value])
80
79
 
81
- // A Tab only knows itself, so the list picks the tab stop when the value matches no enabled tab.
82
- useLayoutEffect(() => {
83
- const tabs = Array.from(listRef.current?.querySelectorAll<HTMLButtonElement>('[role="tab"]') ?? [])
84
- const enabled = tabs.filter((t) => !t.disabled)
85
- const stop = enabled.find((t) => t.getAttribute('aria-selected') === 'true') ?? enabled[0]
86
- for (const t of tabs) t.tabIndex = t === stop ? 0 : -1
87
- })
80
+ useLayoutEffect(() => setTabStop(listRef.current))
88
81
 
89
- // The rise moves by script, so each frame knows how far each edge is from the row's ends. Near an end
90
- // the panel's corner and the rise's inside corner shrink together; at the end the rise and the panel
91
- // share one straight edge.
82
+ // The rise stretches over to a new choice (motion/tabs.ts).
92
83
  const riseRef = useRef<HTMLSpanElement>(null)
93
- const drawn = useRef<{ l: number; r: number; value: string } | null>(null)
94
- const raf = useRef(0)
95
- // Where a running move is heading. A re-measure of the same tab (the size watcher reports once more
96
- // after every change) only updates this; it never restarts or cuts the move short.
97
- const aim = useRef<{ l: number; r: number; value: string } | null>(null)
98
- useLayoutEffect(() => {
99
- const rise = riseRef.current
100
- const root = listRef.current?.closest<HTMLElement>('[data-gooee-tabs]')
101
- if (!bar || !rise || !root) return
102
- const R = parseFloat(getComputedStyle(root).getPropertyValue('--tabs-r')) || 0
103
- // Within two corners of an end, the panel's corner and the inside corner each take half the room, so
104
- // they meet as one even S; at the end both are gone.
105
- const curve = (gap: number) => `${Math.max(0, Math.min(R, gap / 2))}px`
106
- const draw = (l: number, r: number) => {
107
- rise.style.left = `${l}px`
108
- rise.style.right = `${r}px`
109
- rise.style.setProperty('--tabs-in-start', curve(l))
110
- rise.style.setProperty('--tabs-in-end', curve(r))
111
- root.style.setProperty('--tabs-corner-start', curve(l))
112
- root.style.setProperty('--tabs-corner-end', curve(r))
113
- drawn.current = { l, r, value: aim.current?.value ?? bar.value }
114
- }
115
- const to = { l: bar.x, r: bar.room - bar.x - bar.w }
116
- if (aim.current?.value === bar.value) {
117
- aim.current = { ...to, value: bar.value }
118
- return
119
- }
120
- const from = drawn.current
121
- cancelAnimationFrame(raf.current)
122
- aim.current = null
123
- const length = motionMs('morph-out')
124
- // Only a new choice moves; a resize or the first paint just puts it in place.
125
- if (!from || from.value === bar.value || !length || prefersReducedMotion()) return draw(to.l, to.r)
126
- // The edge on the way leads; the other follows a beat later, so the rise stretches, then settles.
127
- const lag = motionMs('instant')
128
- const ease = bezier(morphCurve())
129
- const toEnd = to.l > from.l
130
- const t0 = performance.now()
131
- aim.current = { ...to, value: bar.value }
132
- const step = (now: number) => {
133
- const at = aim.current
134
- if (!at) return
135
- const t = now - t0
136
- const lead = ease(Math.min(1, t / length))
137
- const trail = ease(Math.min(1, Math.max(0, (t - lag) / length)))
138
- const ul = toEnd ? trail : lead
139
- const ur = toEnd ? lead : trail
140
- draw(from.l + (at.l - from.l) * ul, from.r + (at.r - from.r) * ur)
141
- if (t < length + lag) raf.current = requestAnimationFrame(step)
142
- else aim.current = null
143
- }
144
- raf.current = requestAnimationFrame(step)
145
- }, [bar])
146
- useLayoutEffect(() => () => cancelAnimationFrame(raf.current), [])
84
+ const rise = useRef<ReturnType<typeof createTabsRise>>(null)
85
+ rise.current ??= createTabsRise()
86
+ useLayoutEffect(() => rise.current?.place(riseRef.current, bar), [bar])
87
+ useLayoutEffect(() => () => rise.current?.destroy(), [])
147
88
 
148
- // Automatic activation, per the WAI-ARIA tabs pattern
149
- const onKeyDown = (e: KeyboardEvent) => {
150
- const tabs = Array.from(listRef.current?.querySelectorAll<HTMLButtonElement>('[role="tab"]:not(:disabled)') ?? [])
151
- const i = tabs.indexOf(document.activeElement as HTMLButtonElement)
152
- if (i < 0) return
153
- let next = -1
154
- if (e.key === 'ArrowRight') next = (i + 1) % tabs.length
155
- else if (e.key === 'ArrowLeft') next = (i - 1 + tabs.length) % tabs.length
156
- else if (e.key === 'Home') next = 0
157
- else if (e.key === 'End') next = tabs.length - 1
158
- if (next < 0) return
159
- e.preventDefault()
160
- tabs[next].focus()
161
- tabs[next].click()
162
- }
89
+ const onKeyDown = (e: KeyboardEvent) => tabKey(listRef.current, e)
163
90
 
164
91
  return (
165
92
  <div className={cx(styles.listScroll, className)}>
@@ -198,7 +125,7 @@ export function Tab({ value, disabled, children }: TabProps) {
198
125
  className={styles.tab}
199
126
  onClick={() => {
200
127
  ctx.set(value)
201
- document.getElementById(id)?.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: prefersReducedMotion() ? 'auto' : 'smooth' })
128
+ revealTab(id)
202
129
  }}
203
130
  >
204
131
  {children}
@@ -0,0 +1,33 @@
1
+ <script setup lang="ts">
2
+ import { computed, provide, ref, useId } from 'vue'
3
+ import { tabsKey } from './tabsContext'
4
+ import styles from './Tabs.module.css'
5
+
6
+ // The Vue Tabs: the same look (Tabs.module.css), keys and rise as the React one. Put a TabList and its
7
+ // TabPanel parts inside.
8
+
9
+ const props = defineProps<{
10
+ /** Starting tab value when there is no v-model. */
11
+ defaultValue: string
12
+ }>()
13
+
14
+ /** The selected tab value. Use v-model, or leave it out and the tabs keep their own state. */
15
+ const model = defineModel<string>()
16
+ const local = ref(props.defaultValue)
17
+ const value = computed(() => model.value ?? local.value)
18
+
19
+ provide(tabsKey, {
20
+ value,
21
+ set: (v) => {
22
+ local.value = v
23
+ model.value = v
24
+ },
25
+ baseId: useId(),
26
+ })
27
+ </script>
28
+
29
+ <template>
30
+ <div :class="styles.root" data-gooee-tabs="">
31
+ <slot />
32
+ </div>
33
+ </template>
@@ -0,0 +1,15 @@
1
+ import { inject, type ComputedRef, type InjectionKey } from 'vue'
2
+
3
+ // What the Vue Tabs shares with its TabList, Tab and TabPanel.
4
+ export type TabsContext = { value: ComputedRef<string>; set: (v: string) => void; baseId: string }
5
+
6
+ export const tabsKey: InjectionKey<TabsContext> = Symbol('gooee-tabs')
7
+
8
+ export function useTabs() {
9
+ const c = inject(tabsKey, null)
10
+ if (!c) throw new Error('Tabs parts must be inside <Tabs>')
11
+ return c
12
+ }
13
+
14
+ // Odd characters become codes like "_20_", so values never share an id.
15
+ export const safe = (v: string) => v.replace(/[^a-zA-Z0-9-]/g, (c) => `_${c.charCodeAt(0).toString(16)}_`)