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
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type FocusEvent, type ReactNode } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
- import { easing, motionMs } from '../../internal/motion'
5
+ import { flipRows, groupRows, nextSort, readCell as read, revealCell, scrollEdges, sortRows, type TableSort } from '../../internal/motion/table'
6
6
  import { useControllable } from '../../internal/useControllable'
7
7
  import { Skeleton } from '../Skeleton'
8
8
  import styles from './Table.module.css'
@@ -21,7 +21,7 @@ export type TableColumn<T> = {
21
21
  width?: CSSProperties['width']
22
22
  }
23
23
 
24
- export type TableSort = { key: string; direction: 'ascending' | 'descending' }
24
+ export type { TableSort }
25
25
 
26
26
  export type TableLabels = {
27
27
  /** Name of the checkbox in the header. */
@@ -112,8 +112,6 @@ function Check({ checked, mixed, label, disabled, onChange }: { checked: boolean
112
112
  )
113
113
  }
114
114
 
115
- const read = (row: unknown, key: string) => (row as Record<string, unknown>)[key]
116
-
117
115
  export function Table<T>({
118
116
  columns,
119
117
  rows,
@@ -145,24 +143,11 @@ export function Table<T>({
145
143
  const measure = () => {
146
144
  const el = scrollRef.current
147
145
  if (!el) return
148
- const start = el.scrollLeft > 1
149
- const end = el.scrollLeft + el.clientWidth < el.scrollWidth - 1
146
+ const { start, end } = scrollEdges(el)
150
147
  setMore((m) => (m.start === start && m.end === end ? m : { start, end }))
151
- // The sticky first column's width, so a cell that takes focus scrolls clear of it (WCAG 2.4.11).
152
- const first = el.querySelector<HTMLElement>('thead th')
153
- el.style.setProperty('--first-w', first && getComputedStyle(first).left === '0px' ? `${first.offsetWidth}px` : '0px')
154
148
  }
155
- // Browsers do not scroll a sticky header cell into view on focus, so its button could stay under the
156
- // sticky first column. Nudge the sideways scroll until the focused cell is clear on both sides.
157
149
  const reveal = (e: FocusEvent<HTMLDivElement>) => {
158
- const el = scrollRef.current
159
- const cell = e.target.closest('th, td')
160
- if (!el || !cell || cell === cell.parentElement?.firstElementChild) return
161
- const box = el.getBoundingClientRect()
162
- const r = cell.getBoundingClientRect()
163
- const under = r.left - box.left - (parseFloat(el.style.getPropertyValue('--first-w')) || 0)
164
- if (under < 0) el.scrollLeft += under
165
- else if (r.right > box.right) el.scrollLeft += r.right - box.right
150
+ if (scrollRef.current) revealCell(scrollRef.current, e.target)
166
151
  }
167
152
  useEffect(() => {
168
153
  const el = scrollRef.current
@@ -180,28 +165,9 @@ export function Table<T>({
180
165
  const lastShape = useRef('')
181
166
  const groupOrder = useRef<string[]>([])
182
167
 
183
- const sorted = useMemo(() => {
184
- if (!sort) return rows
185
- const col = columns.find((c) => c.key === sort.key)
186
- if (!col) return rows
187
- const value = (r: T) => (col.sortValue ? col.sortValue(r) : (read(r, col.key) as string | number))
188
- const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
189
- const out = [...rows].sort((a, b) => {
190
- const va = value(a)
191
- const vb = value(b)
192
- const c = typeof va === 'number' && typeof vb === 'number' ? va - vb : collator.compare(String(va ?? ''), String(vb ?? ''))
193
- return sort.direction === 'ascending' ? c : -c
194
- })
195
- return out
196
- }, [rows, columns, sort])
168
+ const sorted = useMemo(() => sortRows(rows, columns, sort), [rows, columns, sort])
197
169
 
198
- // Groups take the order they first appear in, and keep it: a sort, or a row moving to another group,
199
- // never shuffles the groups themselves. A group seen for the first time joins at the end.
200
- let groups: Array<{ key: string; rows: T[] }> | null = null
201
- if (groupBy) {
202
- for (const key of new Set(rows.map(groupBy))) if (!groupOrder.current.includes(key)) groupOrder.current.push(key)
203
- groups = groupOrder.current.map((key) => ({ key, rows: sorted.filter((r) => groupBy(r) === key) })).filter((g) => g.rows.length)
204
- }
170
+ const groups = groupBy ? groupRows(rows, sorted, groupBy, groupOrder.current) : null
205
171
  const shape = groups ? groups.map((g) => g.key).join('|') : ''
206
172
  const order = groups ? groups.map((g) => `${g.key}:${g.rows.map(getRowId).join(',')}`).join('|') : sorted.map(getRowId).join('|')
207
173
 
@@ -210,31 +176,14 @@ export function Table<T>({
210
176
  useLayoutEffect(() => {
211
177
  const table = tableRef.current
212
178
  if (!table) return
213
- const duration = motionMs('slow')
214
- const ease = easing(shape !== lastShape.current ? 'spring' : 'out')
179
+ lastTops.current = flipRows(table, lastTops.current, shape !== lastShape.current)
215
180
  lastShape.current = shape
216
- const now = new Map<string, number>()
217
- table.querySelectorAll<HTMLElement>('tbody [data-row-id]').forEach((tr) => {
218
- const rid = tr.dataset.rowId!
219
- const top = tr.offsetTop
220
- now.set(rid, top)
221
- const before = lastTops.current.get(rid)
222
- if (before !== undefined && before !== top && duration > 0) {
223
- tr.animate([{ transform: `translateY(${before - top}px)` }, { transform: 'none' }], { duration, easing: ease })
224
- }
225
- })
226
- lastTops.current = now
227
181
  }, [order])
228
182
 
229
183
  const labelOf = (c: TableColumn<T>) => c.label ?? (typeof c.header === 'string' ? c.header : c.key)
230
184
 
231
185
  const toggleSort = (key: string) => {
232
- const same = sort?.key === key
233
- const next: TableSort | null = !same
234
- ? { key, direction: 'ascending' }
235
- : sort.direction === 'ascending'
236
- ? { key, direction: 'descending' }
237
- : null
186
+ const next = nextSort(sort, key)
238
187
  setSort(next)
239
188
  const col = columns.find((c) => c.key === key)
240
189
  const name = col ? labelOf(col) : key
@@ -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;