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,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
@@ -0,0 +1,87 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
3
+ import { ChevronLeftIcon, ChevronRightIcon } from '../../internal/vueIcons'
4
+ import { pageRange } from './range'
5
+ import styles from './Pagination.module.css'
6
+
7
+ // The Vue Pagination: the same look (Pagination.module.css) and gliding pill as the React one.
8
+
9
+ const props = withDefaults(
10
+ defineProps<{
11
+ /** Total number of pages. Pages count from 1. */
12
+ pageCount: number
13
+ /** Starting page when there is no v-model:page. */
14
+ defaultPage?: number
15
+ /** Pages shown on each side of the current one. */
16
+ siblings?: number
17
+ /** Screen reader name for the nav landmark. */
18
+ label?: string
19
+ /** Screen reader name for the previous button. */
20
+ previousLabel?: string
21
+ /** Screen reader name for the next button. */
22
+ nextLabel?: string
23
+ /** Builds the screen reader name for each page button. */
24
+ pageLabel?: (page: number) => string
25
+ }>(),
26
+ { defaultPage: 1, siblings: 1, label: 'Pagination', previousLabel: 'Previous page', nextLabel: 'Next page', pageLabel: (p: number) => `Page ${p}` },
27
+ )
28
+
29
+ /** Current page, counting from 1. Use v-model:page, or leave it out and the part keeps its own state. */
30
+ const model = defineModel<number | undefined>('page', { default: undefined })
31
+ const local = ref(props.defaultPage)
32
+ // A stored page can sit past the end after pageCount drops.
33
+ const page = computed(() => Math.min(Math.max(model.value ?? local.value, 1), Math.max(props.pageCount, 1)))
34
+ const pages = computed(() => pageRange(page.value, props.pageCount, props.siblings))
35
+
36
+ const list = ref<HTMLUListElement | null>(null)
37
+ const pill = ref<{ x: number; w: number } | null>(null)
38
+ const ready = ref(false)
39
+
40
+ const measure = () => {
41
+ const el = list.value?.querySelector<HTMLElement>('[aria-current="page"]')
42
+ pill.value = el ? { x: el.offsetLeft, w: el.offsetWidth } : null
43
+ }
44
+ // Keeps the current page in view when the list scrolls on a narrow screen.
45
+ const center = () => {
46
+ const el = list.value?.querySelector<HTMLElement>('[aria-current="page"]')
47
+ if (!list.value || !el || list.value.scrollWidth <= list.value.clientWidth) return
48
+ list.value.scrollLeft = el.offsetLeft - (list.value.clientWidth - el.offsetWidth) / 2
49
+ }
50
+ let ro: ResizeObserver | null = null
51
+ onMounted(() => {
52
+ measure()
53
+ center()
54
+ requestAnimationFrame(() => (ready.value = true))
55
+ ro = new ResizeObserver(measure)
56
+ if (list.value) ro.observe(list.value)
57
+ })
58
+ watch([page, () => props.pageCount, () => props.siblings], () => (measure(), center()), { flush: 'post' })
59
+ onBeforeUnmount(() => ro?.disconnect())
60
+
61
+ const go = (p: number) => {
62
+ const next = Math.min(Math.max(p, 1), props.pageCount)
63
+ if (next === page.value) return
64
+ local.value = next
65
+ model.value = next
66
+ }
67
+ </script>
68
+
69
+ <template>
70
+ <nav :aria-label="label" :class="styles.root">
71
+ <button type="button" :class="[styles.btn, styles.edge]" :aria-label="previousLabel" :disabled="page <= 1" @click="go(page - 1)">
72
+ <ChevronLeftIcon />
73
+ </button>
74
+ <ul ref="list" :class="styles.list">
75
+ <li v-if="pill" aria-hidden="true" :class="styles.pill" :data-ready="ready || undefined" :style="{ transform: `translateX(${pill.x}px)`, width: `${pill.w}px` }" />
76
+ <template v-for="(p, i) in pages" :key="p === 'gap' ? `gap-${i}` : p">
77
+ <li v-if="p === 'gap'" :class="styles.gap" aria-hidden="true">…</li>
78
+ <li v-else>
79
+ <button type="button" :class="styles.btn" :aria-label="pageLabel(p)" :aria-current="p === page ? 'page' : undefined" @click="go(p)">{{ p }}</button>
80
+ </li>
81
+ </template>
82
+ </ul>
83
+ <button type="button" :class="[styles.btn, styles.edge]" :aria-label="nextLabel" :disabled="page >= pageCount" @click="go(page + 1)">
84
+ <ChevronRightIcon />
85
+ </button>
86
+ </nav>
87
+ </template>
@@ -0,0 +1,15 @@
1
+ // Which pages show, the same in every framework.
2
+
3
+ const span = (from: number, to: number) => Array.from({ length: to - from + 1 }, (_, i) => from + i)
4
+
5
+ /** Always the same number of slots, so the row keeps its width. A gap hides at least two pages. */
6
+ export function pageRange(page: number, count: number, siblings: number): Array<number | 'gap'> {
7
+ const total = siblings * 2 + 5
8
+ if (count <= total) return span(1, count)
9
+ const side = total - 2
10
+ const leftGap = page - siblings > 3
11
+ const rightGap = page + siblings < count - 2
12
+ if (!leftGap) return [...span(1, side), 'gap', count]
13
+ if (!rightGap) return [1, 'gap', ...span(count - side + 1, count)]
14
+ return [1, 'gap', ...span(page - siblings, page + siblings), 'gap', count]
15
+ }
@@ -0,0 +1,53 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref } from 'vue'
3
+ import Input from '../Input/Input.vue'
4
+ import styles from './PasswordInput.module.css'
5
+
6
+ // The Vue PasswordInput: an Input with a show and hide toggle, the same look (PasswordInput.module.css) as the React one.
7
+ // Every Input prop and attribute passes through; autocomplete defaults to current-password.
8
+ const props = withDefaults(
9
+ defineProps<{
10
+ /** Always required. A placeholder is only an example, never the label. */
11
+ label: string
12
+ /** Start with the password shown, when there is no v-model:visible. */
13
+ defaultVisible?: boolean
14
+ /** Name of the toggle. It stays the same; aria-pressed says whether it is on. */
15
+ toggleLabel?: string
16
+ disabled?: boolean
17
+ }>(),
18
+ { defaultVisible: false, toggleLabel: 'Show password' },
19
+ )
20
+ /** The text, passed to the Input. */
21
+ const model = defineModel<string>()
22
+ /** Whether the password shows as plain text. Use v-model:visible, or leave it out and the field keeps its own state. */
23
+ const visibleModel = defineModel<boolean | undefined>('visible', { default: undefined })
24
+ const inner = ref(props.defaultVisible)
25
+ const visible = computed(() => visibleModel.value ?? inner.value)
26
+ const toggle = () => {
27
+ inner.value = !visible.value
28
+ visibleModel.value = !visible.value
29
+ }
30
+ </script>
31
+
32
+ <template>
33
+ <Input
34
+ v-model="model"
35
+ :label="label"
36
+ :class="styles.root"
37
+ :type="visible ? 'text' : 'password'"
38
+ autocomplete="current-password"
39
+ spellcheck="false"
40
+ autocapitalize="off"
41
+ :disabled="disabled"
42
+ >
43
+ <template #trailing>
44
+ <button type="button" :class="styles.toggle" :aria-label="toggleLabel" :aria-pressed="visible" :disabled="disabled" @click="toggle">
45
+ <svg viewBox="0 0 24 24" :class="styles.eye" :data-open="visible || undefined" aria-hidden="true" focusable="false">
46
+ <path :class="styles.lid" d="M2.5 12s3.5-6.5 9.5-6.5 9.5 6.5 9.5 6.5-3.5 6.5-9.5 6.5S2.5 12 2.5 12z" />
47
+ <circle :class="styles.pupil" cx="12" cy="12" r="2.75" />
48
+ <path :class="styles.slash" d="M4 4l16 16" pathLength="1" />
49
+ </svg>
50
+ </button>
51
+ </template>
52
+ </Input>
53
+ </template>
@@ -0,0 +1,48 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref } from 'vue'
3
+ import { dateWheel, today } from '../../internal/motion/pickerWheel'
4
+ import PickerWheel from './PickerWheel.vue'
5
+
6
+ // PickerWheel set up for a date: day, month and year, with each month's real length (the Vue DateWheel).
7
+ // Other props (detail, haptics) go to the PickerWheel.
8
+
9
+ const props = defineProps<{
10
+ /** Visible name of the whole wheel, read by screen readers as the group's name. */
11
+ label: string
12
+ /** Starting date when there is no v-model. Undefined starts today. */
13
+ defaultValue?: string
14
+ /** The first year on the wheel. Undefined is 100 years ago. */
15
+ fromYear?: number
16
+ /** The last year on the wheel. Undefined is 10 years from now. */
17
+ toYear?: number
18
+ /** Dates, as "YYYY-MM-DD", drawn stronger. Undefined is today. */
19
+ strong?: string[]
20
+ }>()
21
+ const emit = defineEmits<{ /** The date in the band while the wheel still turns, as "YYYY-MM-DD". */ scrub: [value: string] }>()
22
+
23
+ const now = today()
24
+ /** The date as "YYYY-MM-DD", set once the wheel comes to rest. Use v-model, or leave it out and the wheel keeps its own date. */
25
+ const model = defineModel<string>()
26
+ const local = ref(props.defaultValue ?? now)
27
+ const value = computed({
28
+ get: () => model.value ?? local.value,
29
+ set: (next: string) => {
30
+ local.value = next
31
+ model.value = next
32
+ },
33
+ })
34
+ const wheel = computed(() => dateWheel(value.value, now, props.fromYear, props.toYear, props.strong))
35
+ </script>
36
+
37
+ <template>
38
+ <PickerWheel
39
+ :label="label"
40
+ :columns="wheel.columns"
41
+ :model-value="wheel.rows"
42
+ :format-value="wheel.show"
43
+ @update:model-value="(rows) => rows && (value = wheel.toDate(rows))"
44
+ @scrub="emit('scrub', wheel.toDate($event))"
45
+ >
46
+ <template v-for="(_, name) in $slots" #[name]><slot :name="name" /></template>
47
+ </PickerWheel>
48
+ </template>