gooee 0.50.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 (171) 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 -143
  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 +11 -39
  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/focus.ts +4 -47
  124. package/src/internal/icons.module.css +39 -27
  125. package/src/internal/layers.ts +7 -61
  126. package/src/internal/motion/alert.ts +17 -0
  127. package/src/internal/motion/buttonGroup.ts +21 -0
  128. package/src/internal/motion/checkbox.ts +39 -0
  129. package/src/internal/motion/collapseOut.ts +26 -0
  130. package/src/internal/motion/copyButton.ts +48 -0
  131. package/src/internal/motion/dial.ts +137 -0
  132. package/src/internal/motion/fab.ts +14 -0
  133. package/src/internal/motion/floating.ts +58 -0
  134. package/src/internal/motion/focus.ts +53 -0
  135. package/src/internal/motion/formField.ts +19 -0
  136. package/src/internal/motion/holdToConfirm.ts +147 -0
  137. package/src/internal/motion/keys.ts +42 -0
  138. package/src/internal/motion/layers.ts +78 -0
  139. package/src/internal/motion/listbox.ts +69 -0
  140. package/src/internal/motion/livePill.ts +71 -0
  141. package/src/internal/motion/menuKeys.ts +58 -0
  142. package/src/internal/motion/morphButton.ts +71 -0
  143. package/src/internal/motion/numberInput.ts +57 -0
  144. package/src/internal/motion/pickerWheel.ts +166 -0
  145. package/src/internal/motion/retime.ts +45 -0
  146. package/src/internal/motion/ruler.ts +57 -0
  147. package/src/internal/motion/scrollArea.ts +133 -0
  148. package/src/internal/motion/scrubLook.ts +15 -0
  149. package/src/internal/motion/segmented.ts +63 -0
  150. package/src/internal/motion/sheetDetents.ts +271 -0
  151. package/src/internal/motion/slider.ts +108 -0
  152. package/src/internal/motion/splitFlap.ts +205 -0
  153. package/src/internal/motion/swipeDeck.ts +236 -0
  154. package/src/internal/motion/switchThumb.ts +83 -0
  155. package/src/internal/motion/table.ts +77 -0
  156. package/src/internal/motion/tabs.ts +105 -0
  157. package/src/internal/motion/textarea.ts +22 -0
  158. package/src/internal/motion/themeIcon.ts +91 -0
  159. package/src/internal/motion/themeReveal.ts +71 -0
  160. package/src/internal/motion/toast.ts +291 -0
  161. package/src/internal/motion/tooltip.ts +58 -0
  162. package/src/internal/themeReveal.ts +3 -61
  163. package/src/internal/useFloating.ts +9 -49
  164. package/src/internal/useScrub.ts +1 -13
  165. package/src/internal/vue/trigger.ts +18 -0
  166. package/src/internal/vue/useFloating.ts +38 -0
  167. package/src/internal/vue/usePresence.ts +21 -0
  168. package/src/internal/vue/useScrub.ts +40 -0
  169. package/src/internal/vueIcons.ts +134 -0
  170. package/src/tokens.css +5 -0
  171. package/src/internal/relativeTime.ts +0 -26
@@ -0,0 +1,25 @@
1
+ <script setup lang="ts">
2
+ import styles from './IconButton.module.css'
3
+
4
+ // The Vue IconButton: the same look (IconButton.module.css) as the React one. The icon goes in the icon slot;
5
+ // other attributes and listeners, such as aria-pressed or a click listener, go to the button.
6
+ withDefaults(
7
+ defineProps<{
8
+ /** Required: the accessible name, since the button has no visible text. */
9
+ label: string
10
+ /** Visual weight. Ghost has no fill until hover. */
11
+ variant?: 'primary' | 'secondary' | 'ghost'
12
+ /** Size of the button. */
13
+ size?: 'sm' | 'md' | 'lg'
14
+ type?: 'button' | 'submit' | 'reset'
15
+ }>(),
16
+ { variant: 'ghost', size: 'md', type: 'button' },
17
+ )
18
+ defineSlots<{ icon?: () => unknown }>()
19
+ </script>
20
+
21
+ <template>
22
+ <button :type="type" :aria-label="label" :class="[styles.root, styles[variant], styles[size]]">
23
+ <span :class="styles.icon"><slot name="icon" /></span>
24
+ </button>
25
+ </template>
@@ -0,0 +1,112 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, useAttrs, useId } from 'vue'
3
+ import FieldMessage from '../../internal/FieldMessage.vue'
4
+ import { edgeFlow } from '../../internal/motion/liquidMore'
5
+ import styles from './Input.module.css'
6
+
7
+ // The Vue Input: the same look (Input.module.css) and focus edge as the React one.
8
+ // Other attributes, such as name, type or placeholder, go to the input. class and style go to the root, like React's className.
9
+ defineOptions({ inheritAttrs: false })
10
+
11
+ const props = withDefaults(
12
+ defineProps<{
13
+ /** Always required. A placeholder is only an example, never the label. */
14
+ label: string
15
+ /** "top" puts the label above the field, "floating" puts it inside and moves it up. */
16
+ labelPlacement?: 'top' | 'floating'
17
+ /** Hint under the field. Hidden while there is an error. */
18
+ help?: string
19
+ /** Error message under the field. Marks the field invalid. */
20
+ error?: string
21
+ /** Height of the field. */
22
+ size?: 'sm' | 'md' | 'lg'
23
+ /** Adds "(optional)" after the label. */
24
+ optional?: boolean
25
+ /** Text added to the label, so you can translate it. */
26
+ labels?: { optional?: string }
27
+ disabled?: boolean
28
+ id?: string
29
+ }>(),
30
+ { labelPlacement: 'top', size: 'md' },
31
+ )
32
+ /** The text. Use v-model, or leave it out and the input keeps its own value. */
33
+ const model = defineModel<string>()
34
+ const slots = defineSlots<{ leading?: () => unknown; trailing?: () => unknown }>()
35
+ const attrs = useAttrs()
36
+
37
+ const inputAttrs = computed(() => {
38
+ const { class: _class, style: _style, ...rest } = attrs
39
+ return rest
40
+ })
41
+ const optionalText = computed(() => props.labels?.optional ?? '(optional)')
42
+ const auto = useId()
43
+ const inputId = computed(() => props.id ?? auto)
44
+ const helpId = computed(() => `${inputId.value}-help`)
45
+ const errorId = computed(() => `${inputId.value}-error`)
46
+ const floating = computed(() => props.labelPlacement === 'floating')
47
+ const typed = ref(String(attrs.value ?? model.value ?? '') !== '')
48
+ const filled = computed(() => (model.value !== undefined ? model.value !== '' : typed.value))
49
+ // The caller's ids join ours, so help and error stay linked.
50
+ const describedBy = computed(() => [props.help && !props.error ? helpId.value : null, props.error ? errorId.value : null, attrs['aria-describedby']].filter(Boolean).join(' ') || undefined)
51
+
52
+ const input = ref<HTMLInputElement | null>(null)
53
+ const field = ref<HTMLElement | null>(null)
54
+ defineExpose({ input })
55
+ const onInput = (e: Event) => {
56
+ const v = (e.target as HTMLInputElement).value
57
+ typed.value = v !== ''
58
+ if (model.value !== undefined) model.value = v
59
+ }
60
+
61
+ // Focus draws the dark edge round the field from where it was pressed (motion/liquidMore.ts).
62
+ let stopEdge = () => {}
63
+ // A native form reset changes the value without an input event.
64
+ let frame = 0
65
+ const onReset = () => {
66
+ frame = requestAnimationFrame(() => (typed.value = input.value?.value !== ''))
67
+ }
68
+ onMounted(() => {
69
+ if (field.value) stopEdge = edgeFlow(field.value, field.value, ':focus-within', styles.edge)
70
+ input.value?.form?.addEventListener('reset', onReset)
71
+ })
72
+ onBeforeUnmount(() => {
73
+ stopEdge()
74
+ input.value?.form?.removeEventListener('reset', onReset)
75
+ cancelAnimationFrame(frame)
76
+ })
77
+ </script>
78
+
79
+ <template>
80
+ <div :class="[styles.root, attrs.class]" :style="attrs.style as string | undefined">
81
+ <label v-if="!floating" :for="inputId" :class="styles.topLabel">
82
+ {{ label }}<span v-if="optional" :class="styles.optional">{{ ` ${optionalText}` }}</span>
83
+ </label>
84
+ <div
85
+ ref="field"
86
+ :class="[styles.field, styles[size], floating && styles.floating]"
87
+ :data-filled="filled || undefined"
88
+ :data-invalid="error ? true : undefined"
89
+ :data-disabled="disabled || undefined"
90
+ >
91
+ <span v-if="slots.leading" :class="styles.adorn"><slot name="leading" /></span>
92
+ <div :class="styles.control">
93
+ <label v-if="floating" :for="inputId" :class="styles.floatLabel">
94
+ {{ label }}<span v-if="optional" :class="styles.optional">{{ ` ${optionalText}` }}</span>
95
+ </label>
96
+ <input
97
+ v-bind="inputAttrs"
98
+ :id="inputId"
99
+ ref="input"
100
+ :class="styles.input"
101
+ :value="model ?? (attrs.value as string | undefined)"
102
+ :disabled="disabled"
103
+ :aria-invalid="error ? true : (attrs['aria-invalid'] as boolean | undefined)"
104
+ :aria-describedby="describedBy"
105
+ @input="onInput"
106
+ />
107
+ </div>
108
+ <span v-if="slots.trailing" :class="styles.adorn"><slot name="trailing" /></span>
109
+ </div>
110
+ <FieldMessage :help-id="helpId" :error-id="errorId" :help="help" :error="error" />
111
+ </div>
112
+ </template>
@@ -0,0 +1,102 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, useAttrs, useId } from 'vue'
3
+ import FieldMessage from '../../internal/FieldMessage.vue'
4
+ import styles from './InputGroup.module.css'
5
+
6
+ // The Vue InputGroup: the same look (InputGroup.module.css) as the React one.
7
+ // Other attributes, such as name, type or placeholder, go to the input. class and style go to the root.
8
+ defineOptions({ inheritAttrs: false })
9
+
10
+ const props = withDefaults(
11
+ defineProps<{
12
+ /** Always required. A placeholder is only an example, never the label. */
13
+ label: string
14
+ /** Hides the label visually but keeps it as the field's name. */
15
+ hideLabel?: boolean
16
+ /** Text joined before the field, in a shaded cell. For an icon or a button, use the prefix slot. */
17
+ prefix?: string
18
+ /** Text joined after the field, the same way as prefix. */
19
+ suffix?: string
20
+ /** Hint under the field. Hidden while there is an error. */
21
+ help?: string
22
+ /** Error message under the field. Marks the group invalid. */
23
+ error?: string
24
+ /** Height of the group, matching Input. */
25
+ size?: 'sm' | 'md' | 'lg'
26
+ /** The starting text when there is no v-model. */
27
+ defaultValue?: string
28
+ disabled?: boolean
29
+ id?: string
30
+ }>(),
31
+ { size: 'md' },
32
+ )
33
+ /** The text. Use v-model, or leave it out and the input keeps its own value. */
34
+ const model = defineModel<string>()
35
+ const slots = defineSlots<{ prefix?: () => unknown; suffix?: () => unknown }>()
36
+ const attrs = useAttrs()
37
+
38
+ const inputAttrs = computed(() => {
39
+ const { class: _class, style: _style, 'aria-describedby': _d, ...rest } = attrs
40
+ return rest
41
+ })
42
+ const auto = useId()
43
+ const inputId = computed(() => props.id ?? auto)
44
+ const helpId = computed(() => `${inputId.value}-help`)
45
+ const errorId = computed(() => `${inputId.value}-error`)
46
+ const hasPrefix = computed(() => !!slots.prefix || props.prefix !== undefined)
47
+ const hasSuffix = computed(() => !!slots.suffix || props.suffix !== undefined)
48
+ // Text beside the field, such as a unit or "https://", is read as part of its description.
49
+ const textPrefix = computed(() => !slots.prefix && props.prefix !== undefined)
50
+ const textSuffix = computed(() => !slots.suffix && props.suffix !== undefined)
51
+ const describedBy = computed(
52
+ () =>
53
+ [
54
+ textPrefix.value ? `${inputId.value}-prefix` : null,
55
+ textSuffix.value ? `${inputId.value}-suffix` : null,
56
+ props.help && !props.error ? helpId.value : null,
57
+ props.error ? errorId.value : null,
58
+ attrs['aria-describedby'],
59
+ ]
60
+ .filter(Boolean)
61
+ .join(' ') || undefined,
62
+ )
63
+
64
+ const inner = ref<HTMLInputElement | null>(null)
65
+ defineExpose({ input: inner })
66
+
67
+ // A press on a shaded cell puts the caret in the field, as it would on the field itself.
68
+ const focusField = (e: PointerEvent) => {
69
+ if (e.target instanceof Element && e.target.closest('button, a, input, select, textarea')) return
70
+ e.preventDefault()
71
+ inner.value?.focus()
72
+ }
73
+ const onInput = (e: Event) => {
74
+ if (model.value !== undefined) model.value = (e.target as HTMLInputElement).value
75
+ }
76
+ </script>
77
+
78
+ <template>
79
+ <div :class="[styles.root, attrs.class]" :style="attrs.style as string | undefined">
80
+ <label :for="inputId" :class="[styles.label, hideLabel && styles.srOnly]">{{ label }}</label>
81
+ <div :class="[styles.group, styles[size]]" :data-invalid="error ? true : undefined" :data-disabled="disabled || undefined">
82
+ <span v-if="hasPrefix" :id="textPrefix ? `${inputId}-prefix` : undefined" :class="styles.addon" data-side="prefix" @pointerdown="focusField">
83
+ <slot name="prefix">{{ prefix }}</slot>
84
+ </span>
85
+ <input
86
+ v-bind="inputAttrs"
87
+ :id="inputId"
88
+ ref="inner"
89
+ :class="styles.input"
90
+ :value="model ?? defaultValue"
91
+ :disabled="disabled"
92
+ :aria-invalid="error ? true : undefined"
93
+ :aria-describedby="describedBy"
94
+ @input="onInput"
95
+ />
96
+ <span v-if="hasSuffix" :id="textSuffix ? `${inputId}-suffix` : undefined" :class="styles.addon" data-side="suffix" @pointerdown="focusField">
97
+ <slot name="suffix">{{ suffix }}</slot>
98
+ </span>
99
+ </div>
100
+ <FieldMessage :help-id="helpId" :error-id="errorId" :help="help" :error="error" />
101
+ </div>
102
+ </template>
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useEffect, useState, type ReactNode } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
+ import { holdKey } from '../../internal/motion/keys'
5
6
  import styles from './Kbd.module.css'
6
7
 
7
8
  export type KbdProps = {
@@ -17,18 +18,7 @@ export function Kbd({ children, listen, className }: KbdProps) {
17
18
  const [down, setDown] = useState(false)
18
19
  useEffect(() => {
19
20
  if (!listen) return
20
- const match = (e: KeyboardEvent) => e.key.toLowerCase() === listen.toLowerCase()
21
- const onDown = (e: KeyboardEvent) => match(e) && setDown(true)
22
- const onUp = (e: KeyboardEvent) => match(e) && setDown(false)
23
- const reset = () => setDown(false)
24
- window.addEventListener('keydown', onDown)
25
- window.addEventListener('keyup', onUp)
26
- window.addEventListener('blur', reset)
27
- return () => {
28
- window.removeEventListener('keydown', onDown)
29
- window.removeEventListener('keyup', onUp)
30
- window.removeEventListener('blur', reset)
31
- }
21
+ return holdKey(listen, setDown)
32
22
  }, [listen])
33
23
  return (
34
24
  <kbd className={cx(styles.root, className)} data-down={down || undefined}>
@@ -0,0 +1,21 @@
1
+ <script setup lang="ts">
2
+ import { ref, watchEffect } from 'vue'
3
+ import { holdKey } from '../../internal/motion/keys'
4
+ import styles from './Kbd.module.css'
5
+
6
+ // The Vue Kbd: the same keycap (Kbd.module.css) as the React one. The key name goes in the default slot.
7
+ const props = defineProps<{
8
+ /** A KeyboardEvent.key value. When set, the key presses down while the real key is held. */
9
+ listen?: string
10
+ }>()
11
+
12
+ const down = ref(false)
13
+ watchEffect((stop) => {
14
+ if (!props.listen || typeof window === 'undefined') return
15
+ stop(holdKey(props.listen, (held) => (down.value = held)))
16
+ })
17
+ </script>
18
+
19
+ <template>
20
+ <kbd :class="styles.root" :data-down="down || undefined"><slot /></kbd>
21
+ </template>
@@ -0,0 +1,38 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { ArrowUpRightIcon } from '../../internal/vueIcons'
4
+ import styles from './Link.module.css'
5
+
6
+ export type LinkLabels = {
7
+ /** Screen reader text after an external link's name. */
8
+ newTab: string
9
+ }
10
+
11
+ const defaultLabels: LinkLabels = {
12
+ newTab: '(opens in a new tab)',
13
+ }
14
+
15
+ // The Vue Link: the same look (Link.module.css) as the React one. Other attributes, such as href, go to the link.
16
+ const props = withDefaults(
17
+ defineProps<{
18
+ /** Opens in a new tab, adds a safe rel and an arrow, and tells screen readers. */
19
+ external?: boolean
20
+ /** Inline sits in running text. Standalone gets a full-size touch target. */
21
+ variant?: 'inline' | 'standalone'
22
+ /** Screen reader text, so you can translate it. Missing keys use the English defaults. */
23
+ labels?: Partial<LinkLabels>
24
+ }>(),
25
+ { variant: 'inline' },
26
+ )
27
+ const labels = computed(() => ({ ...defaultLabels, ...props.labels }))
28
+ </script>
29
+
30
+ <template>
31
+ <a :class="[styles.root, styles[variant]]" v-bind="external ? { target: '_blank', rel: 'noopener noreferrer' } : {}">
32
+ <span :class="styles.text"><slot /></span>
33
+ <template v-if="external">
34
+ <ArrowUpRightIcon :class="styles.arrow" />
35
+ <span :class="styles.srOnly"> {{ labels.newTab }}</span>
36
+ </template>
37
+ </a>
38
+ </template>
@@ -3,7 +3,7 @@
3
3
  import { useEffect, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type CSSProperties, type ReactNode } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
5
  import { CheckIcon } from '../../internal/icons'
6
- import { motionMs } from '../../internal/motion'
6
+ import { focusInCard, measurePill, pillAlertTimer, pillOutside, pillVars } from '../../internal/motion/livePill'
7
7
  import { useControllable } from '../../internal/useControllable'
8
8
  import styles from './LivePill.module.css'
9
9
 
@@ -40,9 +40,6 @@ export type LivePillProps = Omit<ComponentPropsWithRef<'div'>, 'children' | 'tit
40
40
  alertMs?: number
41
41
  }
42
42
 
43
- // What the pill can hand focus to when it closes from a tap outside, so a tap on another control keeps it.
44
- const TAKES_FOCUS = 'a[href], button, input, select, textarea, label, [tabindex]:not([tabindex="-1"])'
45
-
46
43
  export function LivePill({
47
44
  label,
48
45
  compact,
@@ -79,32 +76,16 @@ export function LivePill({
79
76
  const openNow = useRef(open)
80
77
  openNow.current = open
81
78
 
82
- // Shut, the card is cut back to the button's own box, so the pill grows out of its own spot.
79
+ // Shut, the card is cut back to the button's own box, so the pill grows out of its own spot (motion/livePill.ts).
83
80
  useLayoutEffect(() => {
84
81
  const sh = shell.current
85
82
  const b = button.current
86
83
  if (!sh || !b) return
87
- const measure = () => {
88
- // Open, the pill's button shrinks to the ring; the shut shape is read only while it is shut.
89
- if (openNow.current) return
90
- // Real fractions, not whole pixels: a half-pixel miss shows as an outline thin on one side and thick on the other.
91
- const s = sh.getBoundingClientRect()
92
- const r = b.getBoundingClientRect()
93
- // A page that scales its content (a zoom, an entrance) scales these boxes too; k turns them back into CSS pixels.
94
- const k = s.width / sh.offsetWidth || 1
95
- setShut(`inset(${(r.top - s.top) / k}px ${(s.right - r.right) / k}px ${(s.bottom - r.bottom) / k}px ${(r.left - s.left) / k}px round ${r.height / k / 2}px)`)
96
- // Shut, the card's ring sits on the pill's ring slot: the distance between the two, read from layout.
97
- const sl = slot.current?.getBoundingClientRect()
98
- const ld = lead.current
99
- if (sl && ld) setRingAt([(sl.left - s.left) / k - ld.offsetLeft, (sl.top - s.top) / k - ld.offsetTop])
100
- const row = b.parentElement as HTMLElement
101
- setRowH(row.offsetHeight)
102
- }
103
- measure()
104
- const ro = new ResizeObserver(measure)
105
- ro.observe(sh)
106
- ro.observe(b)
107
- return () => ro.disconnect()
84
+ return measurePill(sh, b, { slot: () => slot.current, lead: () => lead.current, isOpen: () => openNow.current }, (shape) => {
85
+ setShut(shape.shut)
86
+ if (shape.ringAt) setRingAt(shape.ringAt)
87
+ setRowH(shape.rowH)
88
+ })
108
89
  }, [])
109
90
 
110
91
  useEffect(() => {
@@ -129,34 +110,25 @@ export function LivePill({
129
110
  setOpen(false)
130
111
  if (refocus) button.current?.focus({ preventScroll: true })
131
112
  }
132
- const focusInside = () => !!shell.current?.contains(document.activeElement) && document.activeElement !== button.current
113
+ const focusInside = () => focusInCard(shell.current, button.current)
133
114
 
134
115
  useEffect(() => {
135
116
  if (!open) {
136
117
  setByAlert(false)
137
118
  return
138
119
  }
139
- const outside = (e: PointerEvent) => {
140
- const target = e.target instanceof Element ? e.target : null
141
- if (!target || shell.current?.contains(target)) return
142
- const inside = focusInside()
143
- close(false)
144
- if (inside && !target.closest(TAKES_FOCUS)) window.setTimeout(() => button.current?.focus({ preventScroll: true }))
145
- }
146
- document.addEventListener('pointerdown', outside)
147
- return () => document.removeEventListener('pointerdown', outside)
120
+ return pillOutside(() => shell.current, () => button.current, () => close(false))
148
121
  }, [open])
149
122
 
150
123
  useEffect(() => {
151
124
  if (!open || !byAlert || held) return
152
- const t = window.setTimeout(() => close(focusInside()), Math.max(alertMs, motionMs('liquid')))
153
- return () => window.clearTimeout(t)
125
+ return pillAlertTimer(alertMs, () => close(focusInside()))
154
126
  }, [open, byAlert, held, alertMs])
155
127
 
156
128
  const p = progress === undefined ? undefined : Math.min(1, Math.max(0, progress))
157
129
  const state = status ?? (p === 1 ? 'done' : undefined)
158
130
  const ring = p !== undefined || state !== undefined
159
- const vars = { '--pill-shut': shut, '--pill-row': rowH === undefined ? undefined : `${rowH}px`, '--ring-x': ringAt && `${ringAt[0]}px`, '--ring-y': ringAt && `${ringAt[1]}px`, ...style } as CSSProperties
131
+ const vars = { ...pillVars(shut, rowH, ringAt), ...style } as CSSProperties
160
132
 
161
133
  return (
162
134
  <div className={cx(styles.root, className)} data-placement={placement} data-align={align} data-ring={ring || undefined} data-fixed={fixed || undefined} style={vars} {...rest}>
@@ -0,0 +1,152 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, watch, watchEffect } from 'vue'
3
+ import { focusInCard, measurePill, pillAlertTimer, pillOutside, pillVars } from '../../internal/motion/livePill'
4
+ import { CheckIcon } from '../../internal/vueIcons'
5
+ import styles from './LivePill.module.css'
6
+
7
+ // The Vue LivePill: the same look (LivePill.module.css) and grow-from-its-spot card (motion/livePill.ts) as the
8
+ // React one. Other attributes, such as a class or style, go to the root.
9
+ const props = withDefaults(
10
+ defineProps<{
11
+ /** Screen reader name of the pill: start with the words it shows, then the rest of the state, such as "City map 63%, download". People using voice control say what they see. */
12
+ label: string
13
+ /** Where it sits. At the bottom it is in thumb reach and grows up; at the top it grows down. */
14
+ placement?: 'bottom' | 'top'
15
+ /** "center" keeps the pill in the middle of its row, like a status bar. "start" puts it at the row's start edge, and the card grows from there. */
16
+ align?: 'center' | 'start'
17
+ /** Pins it to the screen edge, clear of the safe area. Leave off to place it yourself. */
18
+ fixed?: boolean
19
+ /** From 0 to 1: a ring at the pill's start shows it. Open, the ring grows on its spot with the percent inside. */
20
+ progress?: number
21
+ /** "done" closes the ring into a tick (also at progress 1). "stopped" turns it red with a mark; say why in the words. */
22
+ status?: 'done' | 'stopped'
23
+ /** "paper" is a light pill with an outline; "ink" is a solid dark one. */
24
+ tone?: 'paper' | 'ink'
25
+ /** News for screen readers, said once each time it changes, such as "Download paused". Never a ticking number. */
26
+ news?: string
27
+ /** News that opens the pill by itself, such as "Rider is at your door". Said once, and the pill shrinks back after alertMs. */
28
+ alert?: string
29
+ /** How long an alert keeps it open, in ms. A hand or focus on the pill holds it open. */
30
+ alertMs?: number
31
+ }>(),
32
+ { placement: 'bottom', align: 'center', tone: 'paper', alertMs: 5000 },
33
+ )
34
+ /** Whether it is open. Use v-model:open, or leave it out and the pill keeps its own state. */
35
+ const open = defineModel<boolean>('open', { default: false })
36
+ /** compact: what the small pill shows; it stays on its spot when the pill opens. default: what the open card shows. */
37
+ defineSlots<{ compact?: () => unknown; default?: () => unknown }>()
38
+
39
+ const shell = ref<HTMLElement | null>(null)
40
+ const button = ref<HTMLElement | null>(null)
41
+ const slot = ref<HTMLElement | null>(null)
42
+ const lead = ref<HTMLElement | null>(null)
43
+ const shut = ref<string>()
44
+ const rowH = ref<number>()
45
+ const ringAt = ref<[number, number]>()
46
+ const byAlert = ref(false)
47
+ const held = ref(false)
48
+ const said = ref('')
49
+
50
+ const close = (refocus: boolean) => {
51
+ byAlert.value = false
52
+ open.value = false
53
+ if (refocus) button.value?.focus({ preventScroll: true })
54
+ }
55
+
56
+ watch(
57
+ () => props.news,
58
+ (news) => news && (said.value = news),
59
+ )
60
+ watch(
61
+ () => props.alert,
62
+ (alert) => {
63
+ if (!alert) return
64
+ said.value = alert
65
+ // Only a card the alert opened shrinks back by itself; one the person opened stays.
66
+ if (open.value) return
67
+ byAlert.value = true
68
+ open.value = true
69
+ },
70
+ )
71
+
72
+ const stops: (() => void)[] = []
73
+ onMounted(() => {
74
+ // Shut, the card is cut back to the button's own box, so the pill grows out of its own spot.
75
+ stops.push(
76
+ measurePill(shell.value!, button.value!, { slot: () => slot.value, lead: () => lead.value, isOpen: () => open.value }, (shape) => {
77
+ shut.value = shape.shut
78
+ if (shape.ringAt) ringAt.value = shape.ringAt
79
+ rowH.value = shape.rowH
80
+ }),
81
+ )
82
+ stops.push(
83
+ watch(
84
+ open,
85
+ (now, _, onCleanup) => {
86
+ if (!now) return void (byAlert.value = false)
87
+ onCleanup(pillOutside(() => shell.value, () => button.value, () => close(false)))
88
+ },
89
+ { immediate: true },
90
+ ),
91
+ )
92
+ stops.push(
93
+ watchEffect((onCleanup) => {
94
+ if (!open.value || !byAlert.value || held.value) return
95
+ onCleanup(pillAlertTimer(props.alertMs, () => close(focusInCard(shell.value, button.value))))
96
+ }),
97
+ )
98
+ })
99
+ onBeforeUnmount(() => stops.forEach((stop) => stop()))
100
+
101
+ const p = computed(() => (props.progress === undefined ? undefined : Math.min(1, Math.max(0, props.progress))))
102
+ const state = computed(() => props.status ?? (p.value === 1 ? 'done' : undefined))
103
+ const ring = computed(() => p.value !== undefined || state.value !== undefined)
104
+
105
+ const onKeydown = (e: KeyboardEvent) => {
106
+ if (e.key !== 'Escape' || !open.value) return
107
+ e.stopPropagation()
108
+ close(true)
109
+ }
110
+ const onFocusout = (e: FocusEvent) => {
111
+ if (!(e.currentTarget as HTMLElement).contains(e.relatedTarget as Node)) held.value = false
112
+ }
113
+ </script>
114
+
115
+ <template>
116
+ <div :class="styles.root" :data-placement="placement" :data-align="align" :data-ring="ring || undefined" :data-fixed="fixed || undefined" :style="pillVars(shut, rowH, ringAt)">
117
+ <div
118
+ ref="shell"
119
+ :class="styles.shell"
120
+ :data-open="open || undefined"
121
+ :data-measured="shut ? '' : undefined"
122
+ :data-tone="tone"
123
+ @keydown="onKeydown"
124
+ @pointerenter="held = true"
125
+ @pointerleave="held = false"
126
+ @focusin="held = true"
127
+ @focusout="onFocusout"
128
+ >
129
+ <span v-if="ring" ref="lead" :class="styles.lead" :data-state="state" aria-hidden="true">
130
+ <svg :class="styles.ring" viewBox="0 0 44 44">
131
+ <circle :class="styles.track" cx="22" cy="22" r="20" />
132
+ <circle :class="styles.arc" cx="22" cy="22" r="20" :pathLength="100" :stroke-dasharray="`${state ? 100 : (p ?? 0) * 100} 100`" />
133
+ </svg>
134
+ <CheckIcon v-if="state === 'done'" :class="styles.mark" />
135
+ <svg v-else-if="state === 'stopped'" :class="styles.mark" viewBox="0 0 24 24">
136
+ <path d="M12 7v6M12 17v.01" />
137
+ </svg>
138
+ <span v-else :class="styles.pct">{{ Math.round((p ?? 0) * 100) }}%</span>
139
+ </span>
140
+ <div :class="styles.row">
141
+ <button ref="button" type="button" :class="styles.button" :aria-expanded="open" :aria-label="label" @click="open ? close(false) : (open = true)">
142
+ <span v-if="ring" ref="slot" :class="styles.slot" />
143
+ <span :class="styles.face"><slot name="compact" /></span>
144
+ </button>
145
+ </div>
146
+ <div :class="styles.body" :inert="!open" :aria-hidden="!open || undefined">
147
+ <slot />
148
+ </div>
149
+ </div>
150
+ <span :class="styles.sr" role="status" aria-live="polite" aria-atomic="true">{{ said }}</span>
151
+ </div>
152
+ </template>
@@ -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>