gooee 0.48.0 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/package.json +4 -2
  2. package/scripts/add.js +28 -6
  3. package/src/components/Accordion/Accordion.vue +62 -0
  4. package/src/components/Accordion/AccordionItem.vue +45 -0
  5. package/src/components/Accordion/accordionContext.ts +6 -0
  6. package/src/components/Alert/Alert.tsx +7 -27
  7. package/src/components/Alert/Alert.vue +59 -0
  8. package/src/components/AlertDialog/AlertDialog.vue +126 -0
  9. package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
  10. package/src/components/AspectRatio/AspectRatio.vue +17 -0
  11. package/src/components/Avatar/Avatar.vue +56 -0
  12. package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
  13. package/src/components/Badge/Badge.vue +32 -0
  14. package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
  15. package/src/components/Button/Button.vue +130 -0
  16. package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
  17. package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
  18. package/src/components/Card/Card.vue +34 -0
  19. package/src/components/Center/Center.vue +32 -0
  20. package/src/components/Checkbox/Checkbox.tsx +8 -25
  21. package/src/components/Checkbox/Checkbox.vue +108 -0
  22. package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
  23. package/src/components/Cluster/Cluster.vue +34 -0
  24. package/src/components/CodeBlock/CodeBlock.vue +45 -0
  25. package/src/components/Collapsible/Collapsible.vue +59 -0
  26. package/src/components/Container/Container.vue +22 -0
  27. package/src/components/CopyButton/CopyButton.tsx +3 -49
  28. package/src/components/CopyButton/CopyButton.vue +116 -0
  29. package/src/components/Dial/Dial.tsx +12 -120
  30. package/src/components/Dial/Dial.vue +228 -0
  31. package/src/components/Dialog/Dialog.vue +139 -0
  32. package/src/components/Divider/Divider.vue +27 -0
  33. package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
  34. package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
  35. package/src/components/EmptyState/EmptyState.vue +33 -0
  36. package/src/components/Fab/Fab.tsx +4 -14
  37. package/src/components/Fab/Fab.vue +115 -0
  38. package/src/components/Fieldset/Fieldset.vue +42 -0
  39. package/src/components/FormField/FormField.tsx +2 -17
  40. package/src/components/FormField/FormField.vue +64 -0
  41. package/src/components/Grid/Grid.vue +43 -0
  42. package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -142
  43. package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
  44. package/src/components/IconButton/IconButton.vue +25 -0
  45. package/src/components/Input/Input.vue +112 -0
  46. package/src/components/InputGroup/InputGroup.vue +102 -0
  47. package/src/components/Kbd/Kbd.tsx +2 -12
  48. package/src/components/Kbd/Kbd.vue +21 -0
  49. package/src/components/Link/Link.vue +38 -0
  50. package/src/components/LivePill/LivePill.tsx +12 -40
  51. package/src/components/LivePill/LivePill.vue +152 -0
  52. package/src/components/Meter/Meter.vue +88 -0
  53. package/src/components/MorphButton/MorphButton.tsx +11 -67
  54. package/src/components/MorphButton/MorphButton.vue +120 -0
  55. package/src/components/NumberInput/NumberInput.tsx +11 -48
  56. package/src/components/NumberInput/NumberInput.vue +184 -0
  57. package/src/components/Pagination/Pagination.tsx +2 -15
  58. package/src/components/Pagination/Pagination.vue +87 -0
  59. package/src/components/Pagination/range.ts +15 -0
  60. package/src/components/PasswordInput/PasswordInput.vue +53 -0
  61. package/src/components/PickerWheel/DateWheel.vue +48 -0
  62. package/src/components/PickerWheel/PickerWheel.tsx +15 -129
  63. package/src/components/PickerWheel/PickerWheel.vue +77 -0
  64. package/src/components/PickerWheel/TimeWheel.vue +50 -0
  65. package/src/components/PickerWheel/WheelColumn.vue +70 -0
  66. package/src/components/Popover/Popover.vue +108 -0
  67. package/src/components/ProgressBar/ProgressBar.vue +48 -0
  68. package/src/components/Prose/Prose.vue +18 -0
  69. package/src/components/Radio/Radio.vue +49 -0
  70. package/src/components/Radio/RadioGroup.vue +69 -0
  71. package/src/components/Retime/Retime.tsx +7 -40
  72. package/src/components/Retime/Retime.vue +64 -0
  73. package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
  74. package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
  75. package/src/components/ScrollArea/ScrollArea.tsx +17 -129
  76. package/src/components/ScrollArea/ScrollArea.vue +58 -0
  77. package/src/components/SearchInput/SearchInput.tsx +2 -15
  78. package/src/components/SearchInput/SearchInput.vue +70 -0
  79. package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
  80. package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
  81. package/src/components/Select/Select.tsx +16 -47
  82. package/src/components/Select/Select.vue +236 -0
  83. package/src/components/Sheet/Sheet.tsx +52 -231
  84. package/src/components/Sheet/Sheet.vue +249 -0
  85. package/src/components/Skeleton/Skeleton.vue +38 -0
  86. package/src/components/Slider/Slider.tsx +25 -84
  87. package/src/components/Slider/Slider.vue +113 -0
  88. package/src/components/Spinner/Spinner.vue +30 -0
  89. package/src/components/Split/Split.vue +34 -0
  90. package/src/components/SplitFlap/SplitFlap.tsx +11 -175
  91. package/src/components/SplitFlap/SplitFlap.vue +52 -0
  92. package/src/components/Stack/Stack.vue +22 -0
  93. package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
  94. package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
  95. package/src/components/Switch/Switch.tsx +6 -75
  96. package/src/components/Switch/Switch.vue +66 -0
  97. package/src/components/Table/Table.module.css +12 -3
  98. package/src/components/Table/Table.tsx +8 -59
  99. package/src/components/Table/Table.vue +274 -0
  100. package/src/components/TableOfContents/TableOfContents.vue +90 -0
  101. package/src/components/Tabs/Tab.vue +37 -0
  102. package/src/components/Tabs/TabList.vue +47 -0
  103. package/src/components/Tabs/TabPanel.vue +26 -0
  104. package/src/components/Tabs/Tabs.module.css +2 -2
  105. package/src/components/Tabs/Tabs.tsx +11 -84
  106. package/src/components/Tabs/Tabs.vue +33 -0
  107. package/src/components/Tabs/tabsContext.ts +15 -0
  108. package/src/components/Tag/Tag.tsx +6 -26
  109. package/src/components/Tag/Tag.vue +63 -0
  110. package/src/components/Textarea/Textarea.tsx +2 -22
  111. package/src/components/Textarea/Textarea.vue +120 -0
  112. package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
  113. package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
  114. package/src/components/Toast/Toast.tsx +34 -264
  115. package/src/components/Toast/Toast.vue +138 -0
  116. package/src/components/Toast/ToastItem.vue +108 -0
  117. package/src/components/Toggle/Toggle.vue +52 -0
  118. package/src/components/Tooltip/Tooltip.tsx +17 -48
  119. package/src/components/Tooltip/Tooltip.vue +95 -0
  120. package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
  121. package/src/internal/FieldMessage.vue +41 -0
  122. package/src/internal/Roll.vue +20 -0
  123. package/src/internal/fling.ts +29 -106
  124. package/src/internal/focus.ts +4 -79
  125. package/src/internal/icons.module.css +39 -27
  126. package/src/internal/layers.ts +7 -61
  127. package/src/internal/liquid.ts +26 -213
  128. package/src/internal/liquidMatter.ts +9 -181
  129. package/src/internal/liquidMore.ts +6 -669
  130. package/src/internal/motion/alert.ts +17 -0
  131. package/src/internal/motion/buttonGroup.ts +21 -0
  132. package/src/internal/motion/checkbox.ts +39 -0
  133. package/src/internal/motion/collapseOut.ts +26 -0
  134. package/src/internal/motion/copyButton.ts +48 -0
  135. package/src/internal/motion/dial.ts +137 -0
  136. package/src/internal/motion/fab.ts +14 -0
  137. package/src/internal/motion/fling.ts +147 -0
  138. package/src/internal/motion/floating.ts +58 -0
  139. package/src/internal/motion/focus.ts +88 -0
  140. package/src/internal/motion/formField.ts +19 -0
  141. package/src/internal/motion/holdToConfirm.ts +147 -0
  142. package/src/internal/motion/index.ts +20 -0
  143. package/src/internal/motion/keys.ts +42 -0
  144. package/src/internal/motion/layers.ts +78 -0
  145. package/src/internal/motion/liquid.ts +241 -0
  146. package/src/internal/motion/liquidMatter.ts +198 -0
  147. package/src/internal/motion/liquidMore.ts +676 -0
  148. package/src/internal/motion/listbox.ts +69 -0
  149. package/src/internal/motion/livePill.ts +71 -0
  150. package/src/internal/motion/menuKeys.ts +58 -0
  151. package/src/internal/motion/morphButton.ts +71 -0
  152. package/src/internal/motion/numberInput.ts +57 -0
  153. package/src/internal/motion/pickerWheel.ts +166 -0
  154. package/src/internal/motion/retime.ts +45 -0
  155. package/src/internal/motion/ruler.ts +57 -0
  156. package/src/internal/motion/scrollArea.ts +133 -0
  157. package/src/internal/motion/scrollFrame.ts +152 -0
  158. package/src/internal/motion/scrubLook.ts +15 -0
  159. package/src/internal/motion/scrubber.ts +154 -0
  160. package/src/internal/motion/segmented.ts +63 -0
  161. package/src/internal/motion/sheetDetents.ts +271 -0
  162. package/src/internal/motion/slider.ts +108 -0
  163. package/src/internal/motion/softPress.ts +334 -0
  164. package/src/internal/motion/splitFlap.ts +205 -0
  165. package/src/internal/motion/swipeDeck.ts +236 -0
  166. package/src/internal/motion/switchThumb.ts +83 -0
  167. package/src/internal/motion/table.ts +77 -0
  168. package/src/internal/motion/tabs.ts +105 -0
  169. package/src/internal/motion/textarea.ts +22 -0
  170. package/src/internal/motion/themeIcon.ts +91 -0
  171. package/src/internal/motion/themeReveal.ts +71 -0
  172. package/src/internal/motion/toast.ts +291 -0
  173. package/src/internal/motion/tooltip.ts +58 -0
  174. package/src/internal/scrollFrame.ts +4 -145
  175. package/src/internal/softPress.ts +27 -289
  176. package/src/internal/themeReveal.ts +3 -61
  177. package/src/internal/useFloating.ts +9 -49
  178. package/src/internal/useScrub.ts +15 -120
  179. package/src/internal/vue/trigger.ts +18 -0
  180. package/src/internal/vue/useFloating.ts +38 -0
  181. package/src/internal/vue/usePresence.ts +21 -0
  182. package/src/internal/vue/useScrub.ts +40 -0
  183. package/src/internal/vueIcons.ts +134 -0
  184. package/src/tokens.css +5 -0
  185. package/src/internal/relativeTime.ts +0 -26
@@ -0,0 +1,88 @@
1
+ <script setup lang="ts">
2
+ import { computed, useId } from 'vue'
3
+ import { CheckCircleIcon, ErrorIcon, WarningIcon } from '../../internal/vueIcons'
4
+ import styles from './Meter.module.css'
5
+
6
+ // The Vue Meter: the same look (Meter.module.css) and tones as the React one.
7
+ export type MeterTone = 'good' | 'fair' | 'poor'
8
+ export type MeterLabels = Record<MeterTone, string>
9
+
10
+ const props = withDefaults(
11
+ defineProps<{
12
+ /** Says what is measured. Shown above the bar and read by screen readers. */
13
+ label: string
14
+ /** The measurement, from min to max. */
15
+ value: number
16
+ /** Lowest possible value. */
17
+ min?: number
18
+ /** Highest possible value. */
19
+ max?: number
20
+ /** Top of the low range, as in the HTML meter. Set low or high to turn the tones on. */
21
+ low?: number
22
+ /** Bottom of the high range, as in the HTML meter. */
23
+ high?: number
24
+ /** The best value. The range it falls in is good, the next is fair, the far one poor. Left out, it is the middle. */
25
+ optimum?: number
26
+ /** Shown and spoken instead of the percentage, such as "72 GB of 100 GB". */
27
+ valueText?: string
28
+ /** Shows the value next to the label. */
29
+ showValue?: boolean
30
+ /** Hides the label visually but keeps it for screen readers. */
31
+ hideLabel?: boolean
32
+ /** Thickness of the bar. */
33
+ size?: 'sm' | 'md'
34
+ /** Words for each tone, shown with its icon and spoken with the value. Missing keys use the English defaults. */
35
+ labels?: Partial<MeterLabels>
36
+ }>(),
37
+ { min: 0, max: 100, showValue: true, size: 'md' },
38
+ )
39
+
40
+ const defaultLabels: MeterLabels = { good: 'Good', fair: 'Fair', poor: 'Poor' }
41
+ const icons = { good: CheckCircleIcon, fair: WarningIcon, poor: ErrorIcon }
42
+ const clamp = (n: number, lo: number, hi: number) => Math.min(Math.max(n, lo), hi)
43
+
44
+ // The HTML meter's rule: how many ranges lie between the value and the optimum.
45
+ function toneOf(value: number, min: number, max: number, low?: number, high?: number, optimum?: number): MeterTone | undefined {
46
+ if (low === undefined && high === undefined) return undefined
47
+ const lo = clamp(low ?? min, min, max)
48
+ const hi = clamp(high ?? max, lo, max)
49
+ const range = (n: number) => (n < lo ? 0 : n > hi ? 2 : 1)
50
+ const steps = Math.abs(range(value) - range(clamp(optimum ?? (min + max) / 2, min, max)))
51
+ return steps === 0 ? 'good' : steps === 1 ? 'fair' : 'poor'
52
+ }
53
+
54
+ const id = useId()
55
+ const words = computed(() => ({ ...defaultLabels, ...props.labels }))
56
+ const now = computed(() => clamp(props.value, props.min, props.max))
57
+ const at = (n: number) => (clamp(n, props.min, props.max) - props.min) / (props.max - props.min || 1)
58
+ const tone = computed(() => toneOf(now.value, props.min, props.max, props.low, props.high, props.optimum))
59
+ const text = computed(() => props.valueText ?? `${Math.round(at(now.value) * 100)}%`)
60
+ const marks = computed(() => [props.low, props.high].filter((n): n is number => n !== undefined && n > props.min && n < props.max))
61
+ </script>
62
+
63
+ <template>
64
+ <div :class="styles.root" :data-tone="tone">
65
+ <div :class="styles.head">
66
+ <span :id="id" :class="[styles.label, hideLabel && styles.srOnly]">{{ label }}</span>
67
+ <span :class="styles.reading" aria-hidden="true">
68
+ <span v-if="showValue" :class="styles.value">{{ text }}</span>
69
+ <span v-if="tone" :class="styles.tone">
70
+ <component :is="icons[tone]" :class="styles.icon" />
71
+ {{ words[tone] }}
72
+ </span>
73
+ </span>
74
+ </div>
75
+ <div
76
+ role="meter"
77
+ :aria-labelledby="id"
78
+ :aria-valuemin="min"
79
+ :aria-valuemax="max"
80
+ :aria-valuenow="now"
81
+ :aria-valuetext="tone ? `${text}, ${words[tone]}` : text"
82
+ :class="[styles.track, styles[size]]"
83
+ >
84
+ <span :class="styles.fill" :style="{ transform: `scaleX(${at(now)})` }" />
85
+ <span v-for="n in marks" :key="n" :class="styles.mark" :style="{ left: `${at(n) * 100}%` }" />
86
+ </div>
87
+ </div>
88
+ </template>
@@ -5,6 +5,7 @@ import { cx } from '../../internal/cx'
5
5
  import { focusables } from '../../internal/focus'
6
6
  import { XIcon } from '../../internal/icons'
7
7
  import { useDismiss } from '../../internal/layers'
8
+ import { morphInsets, observeMorphButton, placeMorphButton, takesFocus, type MorphCorner } from '../../internal/motion/morphButton'
8
9
  import { useControllable } from '../../internal/useControllable'
9
10
  import styles from './MorphButton.module.css'
10
11
 
@@ -31,11 +32,6 @@ export type MorphButtonProps = {
31
32
  className?: string
32
33
  }
33
34
 
34
- type Corner = 'tl' | 'tr' | 'bl' | 'br'
35
-
36
- // The space kept between the panel and the edge of the screen.
37
- const EDGE = 16
38
-
39
35
  export function MorphButton({
40
36
  label,
41
37
  icon,
@@ -50,7 +46,7 @@ export function MorphButton({
50
46
  }: MorphButtonProps) {
51
47
  const id = useId()
52
48
  const [open, setOpen] = useControllable(openProp, defaultOpen, onOpenChange)
53
- const [corner, setCorner] = useState<Corner>('tl')
49
+ const [corner, setCorner] = useState<MorphCorner>('tl')
54
50
  const [room, setRoom] = useState<number>()
55
51
  const [box, setBox] = useState({ tw: 0, th: 0, pw: 0, ph: 0 })
56
52
  const anchorRef = useRef<HTMLDivElement>(null)
@@ -58,60 +54,20 @@ export function MorphButton({
58
54
  const triggerRef = useRef<HTMLButtonElement>(null)
59
55
  const panelRef = useRef<HTMLDivElement>(null)
60
56
 
61
- // The box it opens in: the nearest ancestor that clips (a card, a scroller, a demo frame), else the
62
- // window. The panel never grows past its sides, so it fits whatever it sits in, not only the screen.
63
- const sides = () => {
64
- let clip: Element | null = null
65
- for (let e = anchorRef.current?.parentElement; e && e !== document.body; e = e.parentElement)
66
- if (getComputedStyle(e).overflowX !== 'visible') {
67
- clip = e
68
- break
69
- }
70
- const c = clip?.getBoundingClientRect()
71
- return { clip, left: Math.max(0, c?.left ?? 0), right: Math.min(window.innerWidth, c?.right ?? window.innerWidth), top: c?.top ?? 0, bottom: c?.bottom ?? window.innerHeight }
72
- }
73
-
57
+ // Measured now and on every resize, and placed toward the side with room (motion/morphButton.ts).
74
58
  useLayoutEffect(() => {
75
59
  const t = triggerRef.current
76
60
  const s = shellRef.current
77
61
  if (!t || !s) return
78
- const measure = () => setBox({ tw: t.offsetWidth, th: t.offsetHeight, pw: s.offsetWidth, ph: s.offsetHeight })
79
- // Shut, the panel's box is already no wider than the room it has, so it never overflows its box.
80
- const fit = () => {
81
- if (s.dataset.open !== undefined) return
82
- const a = anchorRef.current!.getBoundingClientRect(), { left, right } = sides()
83
- setRoom(Math.max(t.offsetWidth, s.dataset.corner?.endsWith('r') ? a.right - left - EDGE : right - EDGE - a.left))
84
- }
85
- measure()
86
- fit()
87
- const ro = new ResizeObserver(() => {
88
- measure()
89
- fit()
90
- })
91
- ro.observe(t)
92
- ro.observe(s)
93
- const clip = sides().clip
94
- if (clip) ro.observe(clip)
95
- return () => ro.disconnect()
62
+ return observeMorphButton(anchorRef.current!, t, s, setBox, setRoom)
96
63
  }, [])
97
64
 
98
- // It grows toward the side with room, decided before the move starts and never during it.
99
65
  const place = () => {
100
- const a = anchorRef.current?.getBoundingClientRect()
101
- const s = shellRef.current
102
- if (!a || !s) return
103
- const { left: L, right: R, top: T, bottom: B } = sides()
104
- const right = R - EDGE - a.left
105
- const left = a.right - L - EDGE
106
- // Up or down: first the way that fits both its box and the screen, then the way that fits its box
107
- // (a card that clips it would cut it; the page can still scroll), then the way with more room.
108
- const below = { box: B - a.top, screen: window.innerHeight - EDGE - a.top }
109
- const above = { box: a.bottom - T, screen: a.bottom - EDGE }
110
- const fits = (r: { box: number; screen: number }, both: boolean) => r.box >= box.ph && (!both || r.screen >= box.ph)
111
- const up = fits(below, true) ? false : fits(above, true) ? true : fits(below, false) ? false : fits(above, false) ? true : above.box > below.box
112
- const flipX = right < box.pw && left > right
113
- setCorner(`${up ? 'b' : 't'}${flipX ? 'r' : 'l'}` as Corner)
114
- setRoom(Math.max(box.tw, flipX ? left : right))
66
+ if (!shellRef.current) return
67
+ const at = placeMorphButton(anchorRef.current, box)
68
+ if (!at) return
69
+ setCorner(at.corner)
70
+ setRoom(at.room)
115
71
  }
116
72
 
117
73
  const show = (next: boolean) => {
@@ -139,26 +95,14 @@ export function MorphButton({
139
95
  [shellRef],
140
96
  (reason, e) => {
141
97
  setOpen(false)
142
- const target = e.target instanceof Element ? e.target : null
143
98
  if (reason === 'escape') backToButton()
144
- else if (e.type === 'pointerdown' && !target?.closest('a[href], button, input, select, textarea, label, [tabindex]:not([tabindex="-1"])')) window.setTimeout(backToButton)
99
+ else if (e.type === 'pointerdown' && !takesFocus(e.target)) window.setTimeout(backToButton)
145
100
  },
146
101
  { focusOut: true },
147
102
  )
148
103
 
149
104
  // Shut, the surface is cut back to the button's own box in the chosen corner.
150
- const dx = Math.max(0, box.pw - box.tw)
151
- const dy = Math.max(0, box.ph - box.th)
152
- const shut = { tl: [0, dx, dy, 0], tr: [0, 0, dy, dx], bl: [dy, dx, 0, 0], br: [dy, 0, 0, dx] }[corner]
153
- const [t, r, b, l] = open ? [0, 0, 0, 0] : shut
154
- const vars = {
155
- '--t': `${t}px`,
156
- '--r': `${r}px`,
157
- '--b': `${b}px`,
158
- '--l': `${l}px`,
159
- '--pill': `${box.th / 2}px`,
160
- maxWidth: room,
161
- } as CSSProperties
105
+ const vars = { ...morphInsets(corner, box, open), maxWidth: room } as CSSProperties
162
106
 
163
107
  return (
164
108
  <div ref={anchorRef} className={cx(styles.anchor, className)} style={{ width: box.tw || undefined, height: box.th || undefined }}>
@@ -0,0 +1,120 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, useId, useSlots, watch } from 'vue'
3
+ import { focusables } from '../../internal/motion/focus'
4
+ import { dismissable } from '../../internal/motion/layers'
5
+ import { morphInsets, observeMorphButton, placeMorphButton, takesFocus, type MorphBox, type MorphCorner } from '../../internal/motion/morphButton'
6
+ import { XIcon } from '../../internal/vueIcons'
7
+ import styles from './MorphButton.module.css'
8
+
9
+ // The Vue MorphButton: the same look (MorphButton.module.css), growth and dismiss as the React one. The
10
+ // panel's content goes in the default slot, the icon in the icon slot.
11
+ const props = withDefaults(
12
+ defineProps<{
13
+ /** The button's text. It stays on the same spot and becomes the panel's title and name. The label slot replaces it. */
14
+ label?: string
15
+ /** Starting open state when there is no v-model. */
16
+ defaultOpen?: boolean
17
+ /** How wide the panel grows. It never runs past the edge of the screen. */
18
+ width?: 'sm' | 'md'
19
+ /** Screen reader name for the close button. */
20
+ closeLabel?: string
21
+ /** Element to focus when it opens. Defaults to the first control in the panel. */
22
+ initialFocus?: HTMLElement | null
23
+ }>(),
24
+ { defaultOpen: false, width: 'sm', closeLabel: 'Close' },
25
+ )
26
+ /** Whether the panel is open. Use v-model:open, or leave it out and the button keeps its own state. */
27
+ const model = defineModel<boolean | undefined>('open', { type: Boolean, default: undefined })
28
+ const slots = useSlots() as { default?: () => unknown; label?: () => unknown; icon?: () => unknown }
29
+
30
+ const id = useId()
31
+ const own = ref(props.defaultOpen)
32
+ const open = computed(() => model.value ?? own.value)
33
+ const setOpen = (next: boolean) => {
34
+ own.value = next
35
+ model.value = next
36
+ }
37
+ const corner = ref<MorphCorner>('tl')
38
+ const room = ref<number>()
39
+ const box = ref<MorphBox>({ tw: 0, th: 0, pw: 0, ph: 0 })
40
+ const anchorEl = ref<HTMLElement | null>(null)
41
+ const shellEl = ref<HTMLElement | null>(null)
42
+ const triggerEl = ref<HTMLButtonElement | null>(null)
43
+ const panelEl = ref<HTMLElement | null>(null)
44
+
45
+ // Measured now and on every resize, and placed toward the side with room (motion/morphButton.ts).
46
+ let stopObserve: (() => void) | undefined
47
+ onMounted(() => {
48
+ if (!triggerEl.value || !shellEl.value) return
49
+ stopObserve = observeMorphButton(anchorEl.value!, triggerEl.value, shellEl.value, (b) => (box.value = b), (r) => (room.value = r))
50
+ })
51
+
52
+ const place = () => {
53
+ if (!shellEl.value) return
54
+ const at = placeMorphButton(anchorEl.value, box.value)
55
+ if (!at) return
56
+ corner.value = at.corner
57
+ room.value = at.room
58
+ }
59
+ const show = (next: boolean) => {
60
+ if (next) place()
61
+ setOpen(next)
62
+ }
63
+ const backToButton = () => triggerEl.value?.focus({ preventScroll: true })
64
+
65
+ // Esc, a press outside, or focus moving on closes it. A layer it opened, such as a Select's list, is
66
+ // above it, so picking there does not count. Focus goes back to the button unless the press landed on
67
+ // something that takes focus itself.
68
+ let stopDismiss: (() => void) | undefined
69
+ // A controlled open from outside picks its side too; then focus moves into the panel.
70
+ const onOpen = (now: boolean) => {
71
+ stopDismiss?.()
72
+ stopDismiss = undefined
73
+ if (!now) return
74
+ place()
75
+ stopDismiss = dismissable(
76
+ () => [shellEl.value],
77
+ (reason, e) => {
78
+ setOpen(false)
79
+ if (reason === 'escape') backToButton()
80
+ else if (e.type === 'pointerdown' && !takesFocus(e.target)) window.setTimeout(backToButton)
81
+ },
82
+ { focusOut: true },
83
+ )
84
+ if (!panelEl.value) return
85
+ const first = props.initialFocus ?? focusables(panelEl.value).find((el) => !el.hasAttribute('data-skip-initial-focus')) ?? panelEl.value
86
+ first.focus({ preventScroll: true })
87
+ }
88
+ watch(open, onOpen, { flush: 'post' })
89
+ onMounted(() => open.value && onOpen(true))
90
+ onBeforeUnmount(() => {
91
+ stopObserve?.()
92
+ stopDismiss?.()
93
+ })
94
+
95
+ const vars = computed(() => ({ ...morphInsets(corner.value, box.value, open.value), maxWidth: room.value === undefined ? undefined : `${room.value}px` }))
96
+ const close = () => {
97
+ setOpen(false)
98
+ backToButton()
99
+ }
100
+ </script>
101
+
102
+ <template>
103
+ <div ref="anchorEl" :class="styles.anchor" :style="{ width: box.tw ? `${box.tw}px` : undefined, height: box.th ? `${box.th}px` : undefined }">
104
+ <div ref="shellEl" :class="styles.shell" :data-open="open || undefined" :data-corner="corner" :data-width="width" :style="vars">
105
+ <div :class="styles.surface" aria-hidden="true" />
106
+ <div :class="styles.content">
107
+ <button ref="triggerEl" type="button" :class="styles.trigger" :aria-expanded="open" aria-haspopup="dialog" :aria-controls="`${id}-panel`" @click="show(!open)">
108
+ <span v-if="slots.icon" :class="styles.icon" aria-hidden="true"><slot name="icon" /></span>
109
+ <span :id="`${id}-label`"><slot name="label">{{ label }}</slot></span>
110
+ </button>
111
+ <div ref="panelEl" :id="`${id}-panel`" role="dialog" :aria-labelledby="`${id}-label`" tabindex="-1" :class="styles.panel" :inert="!open" :aria-hidden="!open || undefined">
112
+ <button type="button" :class="styles.close" :aria-label="closeLabel" data-skip-initial-focus="true" @click="close">
113
+ <XIcon />
114
+ </button>
115
+ <slot />
116
+ </div>
117
+ </div>
118
+ </div>
119
+ </div>
120
+ </template>
@@ -4,16 +4,12 @@ import { useEffect, useId, useMemo, useRef, useState, type KeyboardEvent, type P
4
4
  import { cx } from '../../internal/cx'
5
5
  import { FieldMessage } from '../../internal/FieldMessage'
6
6
  import { MinusIcon, PlusIcon } from '../../internal/icons'
7
+ import { createHold, parseNumber, type NumberInputLabels } from '../../internal/motion/numberInput'
7
8
  import { useControllable } from '../../internal/useControllable'
8
9
  import { AnimatedNumber } from '../AnimatedNumber'
9
10
  import styles from './NumberInput.module.css'
10
11
 
11
- export type NumberInputLabels = {
12
- /** Name of the minus button. A function gets the field label; a string is used as it is. */
13
- decrease: string | ((label: string) => string)
14
- /** Name of the plus button. A function gets the field label; a string is used as it is. */
15
- increase: string | ((label: string) => string)
16
- }
12
+ export type { NumberInputLabels }
17
13
 
18
14
  const defaultLabels: NumberInputLabels = {
19
15
  decrease: (label) => `Decrease ${label}`,
@@ -55,32 +51,6 @@ export type NumberInputProps = {
55
51
  className?: string
56
52
  }
57
53
 
58
- // Input timings, so reduced motion does not change them
59
- function tokenMs(name: string, fallback: number): number {
60
- if (typeof window === 'undefined') return fallback
61
- const raw = getComputedStyle(document.documentElement).getPropertyValue(name).trim()
62
- if (!raw) return fallback
63
- // The browser may report 500ms as .5s
64
- return raw.endsWith('ms') ? parseFloat(raw) : parseFloat(raw) * 1000
65
- }
66
-
67
- function parseNumber(text: string, locale?: string): number | null {
68
- const parts = new Intl.NumberFormat(locale).formatToParts(-12345.6)
69
- const group = parts.find((p) => p.type === 'group')?.value ?? ','
70
- const decimal = parts.find((p) => p.type === 'decimal')?.value ?? '.'
71
- const minus = parts.find((p) => p.type === 'minusSign')?.value ?? '-'
72
- // sv, nb and fi write minus as U+2212, which the cleanup below would drop
73
- const clean = text
74
- .split(minus).join('-')
75
- .replace(/\u2212/g, '-')
76
- .split(group).join('')
77
- .split(decimal).join('.')
78
- .replace(/[^\d.-]/g, '')
79
- if (clean === '' || clean === '-' || clean === '.') return null
80
- const n = Number(clean)
81
- return Number.isFinite(n) ? n : null
82
- }
83
-
84
54
  export function NumberInput({
85
55
  label,
86
56
  value: valueProp,
@@ -112,7 +82,7 @@ export function NumberInput({
112
82
  // The hold timer keeps calling the bump from its first render, so it reads the typed text from a ref
113
83
  const typed = useRef<string | null>(null)
114
84
  typed.current = editing ? text : null
115
- const hold = useRef<{ timer?: number; count: number }>({ count: 0 })
85
+ const [hold] = useState(createHold)
116
86
  const decimals = (String(step).split('.')[1] ?? '').length
117
87
  const fmt = useMemo(() => new Intl.NumberFormat(locale, format), [locale, format])
118
88
  const plain = useMemo(() => new Intl.NumberFormat(locale, { useGrouping: false, maximumFractionDigits: 20 }), [locale])
@@ -136,25 +106,18 @@ export function NumberInput({
136
106
  commit(current === null ? base : base + dir * size)
137
107
  }
138
108
 
139
- const stopHold = () => {
140
- window.clearTimeout(hold.current.timer)
141
- hold.current.count = 0
142
- }
109
+ const stopHold = hold.stop
143
110
  const startHold = (dir: 1 | -1) => (e: PointerEvent<HTMLButtonElement>) => {
144
111
  // Chromium still sends pointer events to a disabled button
145
112
  if (e.button !== 0 || e.currentTarget.disabled) return
146
113
  e.preventDefault()
147
- bump(dir)
148
- // A disabled button gets no pointerup, so listen on the window
149
- window.addEventListener('pointerup', stopHold, { once: true })
150
- const tick = () => {
151
- const v = valueRef.current
152
- if (v !== null && (dir > 0 ? v >= max : v <= min)) return stopHold()
153
- hold.current.count++
154
- bump(dir, hold.current.count > 12 ? step * 5 : step)
155
- hold.current.timer = window.setTimeout(tick, tokenMs('--gooee-motion-repeat', 70))
156
- }
157
- hold.current.timer = window.setTimeout(tick, tokenMs('--gooee-motion-repeat-delay', 400))
114
+ hold.start(
115
+ (big) => bump(dir, big ? step * 5 : step),
116
+ () => {
117
+ const v = valueRef.current
118
+ return v !== null && (dir > 0 ? v >= max : v <= min)
119
+ },
120
+ )
158
121
  }
159
122
  useEffect(() => stopHold, [])
160
123
 
@@ -0,0 +1,184 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, ref, useId } from 'vue'
3
+ import FieldMessage from '../../internal/FieldMessage.vue'
4
+ import { MinusIcon, PlusIcon } from '../../internal/vueIcons'
5
+ import { createHold, parseNumber, type NumberInputLabels } from '../../internal/motion/numberInput'
6
+ import AnimatedNumber from '../AnimatedNumber/AnimatedNumber.vue'
7
+ import styles from './NumberInput.module.css'
8
+
9
+ // The Vue NumberInput: the same look (NumberInput.module.css), keys and hold to repeat as the React one.
10
+ const props = withDefaults(
11
+ defineProps<{
12
+ /** Visible name of the field, also read by screen readers. */
13
+ label: string
14
+ /** Starting value when there is no v-model. */
15
+ defaultValue?: number | null
16
+ /** Lowest allowed number. Typed values are clamped to it. */
17
+ min?: number
18
+ /** Highest allowed number. Typed values are clamped to it. */
19
+ max?: number
20
+ /** How much the buttons and arrow keys change the value. Its decimals set the rounding. */
21
+ step?: number
22
+ /** Step for Page Up and Page Down. Defaults to ten steps. */
23
+ largeStep?: number
24
+ /** Passed to Intl.NumberFormat, for currency, units or decimals. */
25
+ format?: Intl.NumberFormatOptions
26
+ /** Locale for showing and reading numbers. Undefined uses the browser locale. */
27
+ locale?: string
28
+ /** Hint under the field. Hidden while an error shows. */
29
+ help?: string
30
+ /** Error message under the field. Also marks the field invalid. */
31
+ error?: string
32
+ /** Stops typing and the step buttons. */
33
+ disabled?: boolean
34
+ /** Submits the plain number in a hidden field with this name. */
35
+ name?: string
36
+ /** Screen reader names for the step buttons. */
37
+ labels?: Partial<NumberInputLabels>
38
+ }>(),
39
+ { defaultValue: null, min: -Infinity, max: Infinity, step: 1 },
40
+ )
41
+ /** The number, or null when the field is empty. Use v-model, or leave it out and the field keeps its own. */
42
+ const model = defineModel<number | null | undefined>({ default: undefined })
43
+ const inner = ref<number | null>(props.defaultValue)
44
+ const value = computed(() => (model.value !== undefined ? model.value : inner.value))
45
+ const setValue = (next: number | null) => {
46
+ inner.value = next
47
+ model.value = next
48
+ }
49
+
50
+ const nameOf = (text: NumberInputLabels['decrease'] | undefined, fallback: (l: string) => string) => {
51
+ const t = text ?? fallback
52
+ return typeof t === 'function' ? t(props.label) : t
53
+ }
54
+ const decreaseName = computed(() => nameOf(props.labels?.decrease, (l) => `Decrease ${l}`))
55
+ const increaseName = computed(() => nameOf(props.labels?.increase, (l) => `Increase ${l}`))
56
+ const id = useId()
57
+ const helpId = `${id}-help`
58
+ const errorId = `${id}-error`
59
+ const editing = ref(false)
60
+ const text = ref('')
61
+ const decimals = computed(() => (String(props.step).split('.')[1] ?? '').length)
62
+ const fmt = computed(() => new Intl.NumberFormat(props.locale, props.format))
63
+ const plain = computed(() => new Intl.NumberFormat(props.locale, { useGrouping: false, maximumFractionDigits: 20 }))
64
+
65
+ const clamp = (n: number) => Number(Math.min(props.max, Math.max(props.min, n)).toFixed(decimals.value))
66
+ const commit = (n: number | null) => {
67
+ const next = n === null ? null : clamp(n)
68
+ if (next !== value.value) setValue(next)
69
+ if (editing.value) text.value = next === null ? '' : plain.value.format(next)
70
+ }
71
+ const bump = (dir: 1 | -1, size = props.step) => {
72
+ const current = (editing.value ? parseNumber(text.value, props.locale) : null) ?? value.value
73
+ const base = current ?? (props.min > -Infinity ? props.min : 0)
74
+ commit(current === null ? base : base + dir * size)
75
+ }
76
+
77
+ const hold = createHold()
78
+ const startHold = (dir: 1 | -1) => (e: PointerEvent) => {
79
+ // Chromium still sends pointer events to a disabled button
80
+ if (e.button !== 0 || (e.currentTarget as HTMLButtonElement).disabled) return
81
+ e.preventDefault()
82
+ hold.start(
83
+ (big) => bump(dir, big ? props.step * 5 : props.step),
84
+ () => {
85
+ const v = value.value
86
+ return v !== null && (dir > 0 ? v >= props.max : v <= props.min)
87
+ },
88
+ )
89
+ }
90
+ onBeforeUnmount(hold.stop)
91
+
92
+ const onKeydown = (e: KeyboardEvent) => {
93
+ const big = props.largeStep ?? props.step * 10
94
+ const k = e.key
95
+ if (k === 'ArrowUp') bump(1)
96
+ else if (k === 'ArrowDown') bump(-1)
97
+ else if (k === 'PageUp') bump(1, big)
98
+ else if (k === 'PageDown') bump(-1, big)
99
+ else if (k === 'Home' && props.min > -Infinity) commit(props.min)
100
+ else if (k === 'End' && props.max < Infinity) commit(props.max)
101
+ else if (k === 'Enter') commit(parseNumber(text.value, props.locale))
102
+ else return
103
+ e.preventDefault()
104
+ }
105
+ const onFocus = () => {
106
+ editing.value = true
107
+ text.value = value.value === null ? '' : plain.value.format(value.value)
108
+ }
109
+ const onBlur = () => {
110
+ commit(parseNumber(text.value, props.locale))
111
+ editing.value = false
112
+ }
113
+
114
+ const atMin = computed(() => value.value !== null && value.value <= props.min)
115
+ const atMax = computed(() => value.value !== null && value.value >= props.max)
116
+ const describedBy = computed(() => [props.help && !props.error ? helpId : null, props.error ? errorId : null].filter(Boolean).join(' ') || undefined)
117
+ const shown = computed(() => (editing.value ? text.value : value.value === null ? '' : fmt.value.format(value.value)))
118
+ </script>
119
+
120
+ <template>
121
+ <div :class="styles.root">
122
+ <label :for="id" :class="styles.label">{{ label }}</label>
123
+ <div :class="styles.field" :data-invalid="error ? true : undefined" :data-disabled="disabled || undefined">
124
+ <button
125
+ type="button"
126
+ tabindex="-1"
127
+ :class="styles.step"
128
+ :aria-label="decreaseName"
129
+ :aria-controls="id"
130
+ :disabled="disabled || atMin"
131
+ @pointerdown="startHold(-1)($event)"
132
+ @pointerup="hold.stop"
133
+ @pointerleave="hold.stop"
134
+ @pointercancel="hold.stop"
135
+ @click="$event.detail === 0 && bump(-1)"
136
+ >
137
+ <MinusIcon />
138
+ </button>
139
+ <div :class="styles.control">
140
+ <input
141
+ :id="id"
142
+ :class="styles.input"
143
+ type="text"
144
+ :inputmode="decimals || min < 0 ? 'decimal' : 'numeric'"
145
+ role="spinbutton"
146
+ autocomplete="off"
147
+ :aria-valuenow="value ?? undefined"
148
+ :aria-valuemin="min > -Infinity ? min : undefined"
149
+ :aria-valuemax="max < Infinity ? max : undefined"
150
+ :aria-valuetext="value !== null ? fmt.format(value) : undefined"
151
+ :aria-invalid="error ? true : undefined"
152
+ :aria-describedby="describedBy"
153
+ :data-editing="editing || undefined"
154
+ :disabled="disabled"
155
+ :value="shown"
156
+ @focus="onFocus"
157
+ @blur="onBlur"
158
+ @input="text = ($event.target as HTMLInputElement).value"
159
+ @keydown="onKeydown"
160
+ />
161
+ <span v-if="!editing && value !== null" :class="styles.rolling" aria-hidden="true">
162
+ <AnimatedNumber :value="value" :format="format" :locale="locale" />
163
+ </span>
164
+ </div>
165
+ <button
166
+ type="button"
167
+ tabindex="-1"
168
+ :class="styles.step"
169
+ :aria-label="increaseName"
170
+ :aria-controls="id"
171
+ :disabled="disabled || atMax"
172
+ @pointerdown="startHold(1)($event)"
173
+ @pointerup="hold.stop"
174
+ @pointerleave="hold.stop"
175
+ @pointercancel="hold.stop"
176
+ @click="$event.detail === 0 && bump(1)"
177
+ >
178
+ <PlusIcon />
179
+ </button>
180
+ </div>
181
+ <input v-if="name" type="hidden" :name="name" :value="value ?? ''" />
182
+ <FieldMessage :help-id="helpId" :error-id="errorId" :help="help" :error="error" />
183
+ </div>
184
+ </template>
@@ -4,6 +4,7 @@ import { useLayoutEffect, useRef, useState } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
5
  import { ChevronLeftIcon, ChevronRightIcon } from '../../internal/icons'
6
6
  import { useControllable } from '../../internal/useControllable'
7
+ import { pageRange } from './range'
7
8
  import styles from './Pagination.module.css'
8
9
 
9
10
  export type PaginationProps = {
@@ -29,20 +30,6 @@ export type PaginationProps = {
29
30
  className?: string
30
31
  }
31
32
 
32
- const span = (from: number, to: number) => Array.from({ length: to - from + 1 }, (_, i) => from + i)
33
-
34
- // Always the same number of slots, so the row keeps its width. A gap hides at least two pages.
35
- function range(page: number, count: number, siblings: number): Array<number | 'gap'> {
36
- const total = siblings * 2 + 5
37
- if (count <= total) return span(1, count)
38
- const side = total - 2
39
- const leftGap = page - siblings > 3
40
- const rightGap = page + siblings < count - 2
41
- if (!leftGap) return [...span(1, side), 'gap', count]
42
- if (!rightGap) return [1, 'gap', ...span(count - side + 1, count)]
43
- return [1, 'gap', ...span(page - siblings, page + siblings), 'gap', count]
44
- }
45
-
46
33
  export function Pagination({
47
34
  pageCount,
48
35
  page: pageProp,
@@ -61,7 +48,7 @@ export function Pagination({
61
48
  const listRef = useRef<HTMLUListElement>(null)
62
49
  const [pill, setPill] = useState<{ x: number; w: number } | null>(null)
63
50
  const [ready, setReady] = useState(false)
64
- const pages = range(page, pageCount, siblings)
51
+ const pages = pageRange(page, pageCount, siblings)
65
52
 
66
53
  useLayoutEffect(() => {
67
54
  const list = listRef.current