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.
- package/README.md +17 -4
- package/package.json +5 -3
- package/scripts/add.js +28 -6
- package/src/components/Accordion/Accordion.vue +62 -0
- package/src/components/Accordion/AccordionItem.vue +45 -0
- package/src/components/Accordion/accordionContext.ts +6 -0
- package/src/components/Alert/Alert.tsx +7 -27
- package/src/components/Alert/Alert.vue +59 -0
- package/src/components/AlertDialog/AlertDialog.vue +126 -0
- package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
- package/src/components/AspectRatio/AspectRatio.vue +17 -0
- package/src/components/Avatar/Avatar.vue +56 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
- package/src/components/Badge/Badge.vue +32 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
- package/src/components/Button/Button.vue +130 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
- package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
- package/src/components/Card/Card.vue +34 -0
- package/src/components/Center/Center.vue +32 -0
- package/src/components/Checkbox/Checkbox.tsx +8 -25
- package/src/components/Checkbox/Checkbox.vue +108 -0
- package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
- package/src/components/Cluster/Cluster.vue +34 -0
- package/src/components/CodeBlock/CodeBlock.vue +45 -0
- package/src/components/Collapsible/Collapsible.vue +59 -0
- package/src/components/Container/Container.vue +22 -0
- package/src/components/CopyButton/CopyButton.tsx +3 -49
- package/src/components/CopyButton/CopyButton.vue +116 -0
- package/src/components/Dial/Dial.tsx +12 -120
- package/src/components/Dial/Dial.vue +228 -0
- package/src/components/Dialog/Dialog.vue +139 -0
- package/src/components/Divider/Divider.vue +27 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
- package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
- package/src/components/EmptyState/EmptyState.vue +33 -0
- package/src/components/Fab/Fab.tsx +4 -14
- package/src/components/Fab/Fab.vue +115 -0
- package/src/components/Fieldset/Fieldset.vue +42 -0
- package/src/components/FormField/FormField.tsx +2 -17
- package/src/components/FormField/FormField.vue +64 -0
- package/src/components/Grid/Grid.vue +43 -0
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -143
- package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
- package/src/components/IconButton/IconButton.vue +25 -0
- package/src/components/Input/Input.vue +112 -0
- package/src/components/InputGroup/InputGroup.vue +102 -0
- package/src/components/Kbd/Kbd.tsx +2 -12
- package/src/components/Kbd/Kbd.vue +21 -0
- package/src/components/Link/Link.vue +38 -0
- package/src/components/LivePill/LivePill.tsx +11 -39
- package/src/components/LivePill/LivePill.vue +152 -0
- package/src/components/Meter/Meter.vue +88 -0
- package/src/components/MorphButton/MorphButton.tsx +11 -67
- package/src/components/MorphButton/MorphButton.vue +120 -0
- package/src/components/NumberInput/NumberInput.tsx +11 -48
- package/src/components/NumberInput/NumberInput.vue +184 -0
- package/src/components/Pagination/Pagination.tsx +2 -15
- package/src/components/Pagination/Pagination.vue +87 -0
- package/src/components/Pagination/range.ts +15 -0
- package/src/components/PasswordInput/PasswordInput.vue +53 -0
- package/src/components/PickerWheel/DateWheel.vue +48 -0
- package/src/components/PickerWheel/PickerWheel.tsx +15 -129
- package/src/components/PickerWheel/PickerWheel.vue +77 -0
- package/src/components/PickerWheel/TimeWheel.vue +50 -0
- package/src/components/PickerWheel/WheelColumn.vue +70 -0
- package/src/components/Popover/Popover.vue +108 -0
- package/src/components/ProgressBar/ProgressBar.vue +48 -0
- package/src/components/Prose/Prose.vue +18 -0
- package/src/components/Radio/Radio.vue +49 -0
- package/src/components/Radio/RadioGroup.vue +69 -0
- package/src/components/Retime/Retime.tsx +7 -40
- package/src/components/Retime/Retime.vue +64 -0
- package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
- package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
- package/src/components/ScrollArea/ScrollArea.tsx +17 -129
- package/src/components/ScrollArea/ScrollArea.vue +58 -0
- package/src/components/SearchInput/SearchInput.tsx +2 -15
- package/src/components/SearchInput/SearchInput.vue +70 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
- package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
- package/src/components/Select/Select.tsx +16 -47
- package/src/components/Select/Select.vue +236 -0
- package/src/components/Sheet/Sheet.tsx +52 -231
- package/src/components/Sheet/Sheet.vue +249 -0
- package/src/components/Skeleton/Skeleton.vue +38 -0
- package/src/components/Slider/Slider.tsx +25 -84
- package/src/components/Slider/Slider.vue +113 -0
- package/src/components/Spinner/Spinner.vue +30 -0
- package/src/components/Split/Split.vue +34 -0
- package/src/components/SplitFlap/SplitFlap.tsx +11 -175
- package/src/components/SplitFlap/SplitFlap.vue +52 -0
- package/src/components/Stack/Stack.vue +22 -0
- package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
- package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
- package/src/components/Switch/Switch.tsx +6 -75
- package/src/components/Switch/Switch.vue +66 -0
- package/src/components/Table/Table.module.css +12 -3
- package/src/components/Table/Table.tsx +8 -59
- package/src/components/Table/Table.vue +274 -0
- package/src/components/TableOfContents/TableOfContents.vue +90 -0
- package/src/components/Tabs/Tab.vue +37 -0
- package/src/components/Tabs/TabList.vue +47 -0
- package/src/components/Tabs/TabPanel.vue +26 -0
- package/src/components/Tabs/Tabs.module.css +2 -2
- package/src/components/Tabs/Tabs.tsx +11 -84
- package/src/components/Tabs/Tabs.vue +33 -0
- package/src/components/Tabs/tabsContext.ts +15 -0
- package/src/components/Tag/Tag.tsx +6 -26
- package/src/components/Tag/Tag.vue +63 -0
- package/src/components/Textarea/Textarea.tsx +2 -22
- package/src/components/Textarea/Textarea.vue +120 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
- package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
- package/src/components/Toast/Toast.tsx +34 -264
- package/src/components/Toast/Toast.vue +138 -0
- package/src/components/Toast/ToastItem.vue +108 -0
- package/src/components/Toggle/Toggle.vue +52 -0
- package/src/components/Tooltip/Tooltip.tsx +17 -48
- package/src/components/Tooltip/Tooltip.vue +95 -0
- package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
- package/src/internal/FieldMessage.vue +41 -0
- package/src/internal/Roll.vue +20 -0
- package/src/internal/focus.ts +4 -47
- package/src/internal/icons.module.css +39 -27
- package/src/internal/layers.ts +7 -61
- package/src/internal/motion/alert.ts +17 -0
- package/src/internal/motion/buttonGroup.ts +21 -0
- package/src/internal/motion/checkbox.ts +39 -0
- package/src/internal/motion/collapseOut.ts +26 -0
- package/src/internal/motion/copyButton.ts +48 -0
- package/src/internal/motion/dial.ts +137 -0
- package/src/internal/motion/fab.ts +14 -0
- package/src/internal/motion/floating.ts +58 -0
- package/src/internal/motion/focus.ts +53 -0
- package/src/internal/motion/formField.ts +19 -0
- package/src/internal/motion/holdToConfirm.ts +147 -0
- package/src/internal/motion/keys.ts +42 -0
- package/src/internal/motion/layers.ts +78 -0
- package/src/internal/motion/listbox.ts +69 -0
- package/src/internal/motion/livePill.ts +71 -0
- package/src/internal/motion/menuKeys.ts +58 -0
- package/src/internal/motion/morphButton.ts +71 -0
- package/src/internal/motion/numberInput.ts +57 -0
- package/src/internal/motion/pickerWheel.ts +166 -0
- package/src/internal/motion/retime.ts +45 -0
- package/src/internal/motion/ruler.ts +57 -0
- package/src/internal/motion/scrollArea.ts +133 -0
- package/src/internal/motion/scrubLook.ts +15 -0
- package/src/internal/motion/segmented.ts +63 -0
- package/src/internal/motion/sheetDetents.ts +271 -0
- package/src/internal/motion/slider.ts +108 -0
- package/src/internal/motion/splitFlap.ts +205 -0
- package/src/internal/motion/swipeDeck.ts +236 -0
- package/src/internal/motion/switchThumb.ts +83 -0
- package/src/internal/motion/table.ts +77 -0
- package/src/internal/motion/tabs.ts +105 -0
- package/src/internal/motion/textarea.ts +22 -0
- package/src/internal/motion/themeIcon.ts +91 -0
- package/src/internal/motion/themeReveal.ts +71 -0
- package/src/internal/motion/toast.ts +291 -0
- package/src/internal/motion/tooltip.ts +58 -0
- package/src/internal/themeReveal.ts +3 -61
- package/src/internal/useFloating.ts +9 -49
- package/src/internal/useScrub.ts +1 -13
- package/src/internal/vue/trigger.ts +18 -0
- package/src/internal/vue/useFloating.ts +38 -0
- package/src/internal/vue/usePresence.ts +21 -0
- package/src/internal/vue/useScrub.ts +40 -0
- package/src/internal/vueIcons.ts +134 -0
- package/src/tokens.css +5 -0
- package/src/internal/relativeTime.ts +0 -26
|
@@ -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
|
-
|
|
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 {
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
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 = () =>
|
|
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
|
-
|
|
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
|
-
|
|
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 = {
|
|
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>
|
|
@@ -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<
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
103
|
-
|
|
104
|
-
|
|
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
|
|
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
|
|
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 }}>
|