gooee 0.52.0 → 1.0.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 +10 -3
- package/package.json +6 -2
- package/scripts/add.js +181 -42
- package/src/base.css +3 -1
- package/src/components/Accordion/Accordion.module.css +7 -5
- package/src/components/Accordion/Accordion.tsx +13 -11
- package/src/components/Accordion/Accordion.vue +16 -15
- package/src/components/Accordion/AccordionItem.vue +8 -7
- package/src/components/Alert/Alert.module.css +9 -7
- package/src/components/Alert/Alert.tsx +25 -16
- package/src/components/Alert/Alert.vue +31 -27
- package/src/components/AlertDialog/AlertDialog.module.css +2 -0
- package/src/components/AlertDialog/AlertDialog.tsx +8 -7
- package/src/components/AlertDialog/AlertDialog.vue +25 -23
- package/src/components/AnimatedNumber/AnimatedNumber.module.css +5 -3
- package/src/components/AnimatedNumber/AnimatedNumber.tsx +6 -6
- package/src/components/AnimatedNumber/AnimatedNumber.vue +5 -5
- package/src/components/AspectRatio/AspectRatio.module.css +2 -0
- package/src/components/AspectRatio/AspectRatio.tsx +3 -3
- package/src/components/AspectRatio/AspectRatio.vue +5 -8
- package/src/components/Avatar/Avatar.module.css +10 -8
- package/src/components/Avatar/Avatar.tsx +4 -3
- package/src/components/Avatar/Avatar.vue +17 -19
- package/src/components/Avatar/index.ts +0 -2
- package/src/components/AvatarGroup/AvatarGroup.module.css +11 -9
- package/src/components/AvatarGroup/AvatarGroup.tsx +4 -4
- package/src/components/AvatarGroup/AvatarGroup.vue +13 -16
- package/src/components/Badge/Badge.module.css +6 -4
- package/src/components/Badge/Badge.tsx +3 -3
- package/src/components/Badge/Badge.vue +15 -14
- package/src/components/Breadcrumb/Breadcrumb.module.css +5 -3
- package/src/components/Breadcrumb/Breadcrumb.tsx +20 -12
- package/src/components/Breadcrumb/Breadcrumb.vue +33 -25
- package/src/components/Button/Button.module.css +16 -14
- package/src/components/Button/Button.tsx +6 -4
- package/src/components/Button/Button.vue +42 -33
- package/src/components/ButtonGroup/ButtonGroup.module.css +2 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +1 -1
- package/src/components/ButtonGroup/ButtonGroup.vue +9 -12
- package/src/components/Card/Card.module.css +6 -4
- package/src/components/Card/Card.tsx +6 -6
- package/src/components/Card/Card.vue +18 -21
- package/src/components/Center/Center.module.css +2 -0
- package/src/components/Center/Center.tsx +1 -1
- package/src/components/Center/Center.vue +18 -15
- package/src/components/Checkbox/Checkbox.module.css +10 -8
- package/src/components/Checkbox/Checkbox.tsx +15 -9
- package/src/components/Checkbox/Checkbox.vue +29 -31
- package/src/components/CheckboxGroup/CheckboxGroup.module.css +3 -1
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +4 -4
- package/src/components/CheckboxGroup/CheckboxGroup.vue +33 -30
- package/src/components/Cluster/Cluster.module.css +2 -0
- package/src/components/Cluster/Cluster.tsx +1 -1
- package/src/components/Cluster/Cluster.vue +21 -17
- package/src/components/CodeBlock/CodeBlock.module.css +12 -10
- package/src/components/CodeBlock/CodeBlock.tsx +18 -10
- package/src/components/CodeBlock/CodeBlock.vue +30 -27
- package/src/components/CodeBlock/highlight.ts +1 -1
- package/src/components/Collapsible/Collapsible.module.css +7 -5
- package/src/components/Collapsible/Collapsible.tsx +7 -6
- package/src/components/Collapsible/Collapsible.vue +30 -26
- package/src/components/Container/Container.module.css +2 -0
- package/src/components/Container/Container.tsx +1 -1
- package/src/components/Container/Container.vue +13 -12
- package/src/components/CopyButton/CopyButton.module.css +20 -18
- package/src/components/CopyButton/CopyButton.tsx +21 -14
- package/src/components/CopyButton/CopyButton.vue +41 -31
- package/src/components/Dial/Dial.module.css +26 -11
- package/src/components/Dial/Dial.tsx +18 -18
- package/src/components/Dial/Dial.vue +57 -60
- package/src/components/Dialog/Dialog.module.css +4 -2
- package/src/components/Dialog/Dialog.tsx +22 -13
- package/src/components/Dialog/Dialog.vue +34 -30
- package/src/components/Divider/Divider.module.css +5 -3
- package/src/components/Divider/Divider.tsx +6 -4
- package/src/components/Divider/Divider.vue +13 -16
- package/src/components/DropdownMenu/DropdownMenu.module.css +8 -6
- package/src/components/DropdownMenu/DropdownMenu.tsx +12 -9
- package/src/components/DropdownMenu/DropdownMenu.vue +25 -28
- package/src/components/EmptyState/EmptyState.module.css +6 -4
- package/src/components/EmptyState/EmptyState.tsx +6 -6
- package/src/components/EmptyState/EmptyState.vue +14 -17
- package/src/components/Fab/Fab.module.css +19 -17
- package/src/components/Fab/Fab.tsx +11 -9
- package/src/components/Fab/Fab.vue +29 -26
- package/src/components/Fieldset/Fieldset.module.css +2 -0
- package/src/components/Fieldset/Fieldset.tsx +4 -3
- package/src/components/Fieldset/Fieldset.vue +4 -4
- package/src/components/FormField/FormField.module.css +5 -3
- package/src/components/FormField/FormField.tsx +7 -7
- package/src/components/FormField/FormField.vue +4 -4
- package/src/components/Grid/Grid.module.css +2 -0
- package/src/components/Grid/Grid.tsx +1 -1
- package/src/components/Grid/Grid.vue +25 -22
- package/src/components/HoldToConfirm/HoldToConfirm.module.css +13 -11
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +11 -9
- package/src/components/HoldToConfirm/HoldToConfirm.vue +37 -32
- package/src/components/IconButton/IconButton.module.css +7 -5
- package/src/components/IconButton/IconButton.tsx +2 -1
- package/src/components/IconButton/IconButton.vue +15 -14
- package/src/components/Input/Input.module.css +12 -10
- package/src/components/Input/Input.tsx +9 -7
- package/src/components/Input/Input.vue +45 -35
- package/src/components/InputGroup/InputGroup.module.css +8 -6
- package/src/components/InputGroup/InputGroup.tsx +5 -4
- package/src/components/InputGroup/InputGroup.vue +41 -36
- package/src/components/Kbd/Kbd.module.css +9 -7
- package/src/components/Kbd/Kbd.tsx +1 -1
- package/src/components/Kbd/Kbd.vue +1 -1
- package/src/components/Link/Link.module.css +4 -2
- package/src/components/Link/Link.tsx +4 -3
- package/src/components/Link/Link.vue +13 -16
- package/src/components/LivePill/LivePill.module.css +39 -37
- package/src/components/LivePill/LivePill.tsx +11 -10
- package/src/components/LivePill/LivePill.vue +38 -40
- package/src/components/Meter/Meter.module.css +5 -3
- package/src/components/Meter/Meter.tsx +9 -8
- package/src/components/Meter/Meter.vue +52 -43
- package/src/components/MorphButton/MorphButton.module.css +11 -9
- package/src/components/MorphButton/MorphButton.tsx +20 -10
- package/src/components/MorphButton/MorphButton.vue +29 -25
- package/src/components/NumberInput/NumberInput.module.css +7 -5
- package/src/components/NumberInput/NumberInput.tsx +11 -8
- package/src/components/NumberInput/NumberInput.vue +69 -57
- package/src/components/Pagination/Pagination.module.css +147 -5
- package/src/components/Pagination/Pagination.tsx +216 -41
- package/src/components/Pagination/Pagination.vue +201 -36
- package/src/components/Pagination/labels.ts +38 -0
- package/src/components/PasswordInput/PasswordInput.module.css +10 -8
- package/src/components/PasswordInput/PasswordInput.tsx +15 -7
- package/src/components/PasswordInput/PasswordInput.vue +20 -16
- package/src/components/PasswordInput/index.ts +1 -1
- package/src/components/PickerWheel/DateWheel.vue +20 -12
- package/src/components/PickerWheel/PickerWheel.module.css +15 -6
- package/src/components/PickerWheel/PickerWheel.tsx +70 -44
- package/src/components/PickerWheel/PickerWheel.vue +39 -38
- package/src/components/PickerWheel/TimeWheel.vue +23 -21
- package/src/components/PickerWheel/WheelColumn.vue +7 -5
- package/src/components/Popover/Popover.module.css +5 -3
- package/src/components/Popover/Popover.tsx +17 -8
- package/src/components/Popover/Popover.vue +26 -25
- package/src/components/ProgressBar/ProgressBar.module.css +4 -2
- package/src/components/ProgressBar/ProgressBar.tsx +6 -5
- package/src/components/ProgressBar/ProgressBar.vue +28 -25
- package/src/components/Prose/Prose.module.css +5 -3
- package/src/components/Prose/Prose.tsx +1 -1
- package/src/components/Prose/Prose.vue +5 -8
- package/src/components/Radio/Radio.module.css +10 -8
- package/src/components/Radio/Radio.tsx +10 -8
- package/src/components/Radio/Radio.vue +8 -8
- package/src/components/Radio/RadioGroup.vue +33 -35
- package/src/components/Radio/radioContext.ts +12 -0
- package/src/components/Retime/Retime.vue +25 -22
- package/src/components/RulerScrubber/RulerScrubber.module.css +11 -2
- package/src/components/RulerScrubber/RulerScrubber.tsx +19 -18
- package/src/components/RulerScrubber/RulerScrubber.vue +50 -54
- package/src/components/ScrollArea/ScrollArea.module.css +17 -15
- package/src/components/ScrollArea/ScrollArea.tsx +5 -4
- package/src/components/ScrollArea/ScrollArea.vue +15 -17
- package/src/components/SearchInput/SearchInput.module.css +6 -4
- package/src/components/SearchInput/SearchInput.tsx +22 -10
- package/src/components/SearchInput/SearchInput.vue +20 -17
- package/src/components/SearchInput/index.ts +1 -1
- package/src/components/SegmentedControl/SegmentedControl.module.css +7 -5
- package/src/components/SegmentedControl/SegmentedControl.tsx +9 -5
- package/src/components/SegmentedControl/SegmentedControl.vue +25 -29
- package/src/components/Select/Select.module.css +19 -17
- package/src/components/Select/Select.tsx +31 -18
- package/src/components/Select/Select.vue +63 -58
- package/src/components/Sheet/Sheet.module.css +6 -4
- package/src/components/Sheet/Sheet.tsx +39 -29
- package/src/components/Sheet/Sheet.vue +46 -40
- package/src/components/Skeleton/Skeleton.module.css +4 -2
- package/src/components/Skeleton/Skeleton.tsx +3 -2
- package/src/components/Skeleton/Skeleton.vue +16 -18
- package/src/components/Slider/Slider.module.css +14 -12
- package/src/components/Slider/Slider.tsx +27 -11
- package/src/components/Slider/Slider.vue +47 -37
- package/src/components/Spinner/Spinner.module.css +2 -0
- package/src/components/Spinner/Spinner.tsx +3 -3
- package/src/components/Spinner/Spinner.vue +9 -12
- package/src/components/Split/Split.module.css +2 -0
- package/src/components/Split/Split.tsx +3 -3
- package/src/components/Split/Split.vue +19 -17
- package/src/components/SplitFlap/SplitFlap.module.css +9 -7
- package/src/components/SplitFlap/SplitFlap.tsx +2 -2
- package/src/components/SplitFlap/SplitFlap.vue +24 -21
- package/src/components/Stack/Stack.module.css +2 -0
- package/src/components/Stack/Stack.tsx +1 -1
- package/src/components/Stack/Stack.vue +13 -12
- package/src/components/SwipeDeck/SwipeDeck.module.css +13 -11
- package/src/components/SwipeDeck/SwipeDeck.tsx +23 -28
- package/src/components/SwipeDeck/SwipeDeck.vue +32 -38
- package/src/components/Switch/Switch.module.css +10 -8
- package/src/components/Switch/Switch.tsx +6 -5
- package/src/components/Switch/Switch.vue +22 -24
- package/src/components/Table/Table.module.css +24 -22
- package/src/components/Table/Table.tsx +27 -30
- package/src/components/Table/Table.vue +93 -79
- package/src/components/TableOfContents/TableOfContents.module.css +9 -7
- package/src/components/TableOfContents/TableOfContents.tsx +8 -8
- package/src/components/TableOfContents/TableOfContents.vue +20 -23
- package/src/components/Tabs/Tab.vue +3 -0
- package/src/components/Tabs/TabList.vue +2 -2
- package/src/components/Tabs/TabPanel.vue +2 -0
- package/src/components/Tabs/Tabs.module.css +4 -2
- package/src/components/Tabs/Tabs.tsx +10 -5
- package/src/components/Tabs/Tabs.vue +1 -1
- package/src/components/Tag/Tag.module.css +12 -10
- package/src/components/Tag/Tag.tsx +13 -15
- package/src/components/Tag/Tag.vue +12 -14
- package/src/components/Textarea/Textarea.module.css +8 -6
- package/src/components/Textarea/Textarea.tsx +4 -3
- package/src/components/Textarea/Textarea.vue +32 -34
- package/src/components/ThemeToggle/ThemeToggle.module.css +2 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +7 -7
- package/src/components/ThemeToggle/ThemeToggle.vue +24 -22
- package/src/components/Toast/Toast.module.css +17 -15
- package/src/components/Toast/Toast.tsx +51 -34
- package/src/components/Toast/Toast.vue +35 -24
- package/src/components/Toast/ToastItem.vue +17 -16
- package/src/components/Toggle/Toggle.module.css +11 -9
- package/src/components/Toggle/Toggle.tsx +3 -2
- package/src/components/Toggle/Toggle.vue +13 -15
- package/src/components/Tooltip/Tooltip.module.css +5 -3
- package/src/components/Tooltip/Tooltip.tsx +1 -0
- package/src/components/Tooltip/Tooltip.vue +13 -18
- package/src/components/VisuallyHidden/VisuallyHidden.module.css +2 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +1 -1
- package/src/components/VisuallyHidden/VisuallyHidden.vue +5 -8
- package/src/{internal → icons}/icons.module.css +4 -2
- package/src/{internal → icons}/icons.tsx +15 -16
- package/src/internal/FieldMessage.module.css +5 -3
- package/src/internal/FieldMessage.tsx +2 -2
- package/src/internal/FieldMessage.vue +2 -2
- package/src/internal/Roll.module.css +5 -3
- package/src/internal/feel.ts +12 -10
- package/src/internal/fling.ts +3 -3
- package/src/internal/liquid.ts +12 -10
- package/src/internal/liquidMatter.ts +1 -1
- package/src/internal/liquidMore.ts +7 -7
- package/src/internal/motion/checkbox.ts +4 -4
- package/src/internal/motion/fling.ts +19 -9
- package/src/internal/motion/holdToConfirm.ts +3 -3
- package/src/internal/motion/index.ts +8 -6
- package/src/internal/motion/liquid.ts +16 -4
- package/src/internal/motion/liquidMatter.ts +8 -6
- package/src/internal/motion/liquidMore.ts +44 -25
- package/src/internal/motion/livePill.ts +1 -1
- package/src/internal/motion/numberInput.ts +2 -2
- package/src/internal/motion/pickerWheel.ts +7 -4
- package/src/internal/motion/ruler.ts +1 -1
- package/src/internal/motion/scrollArea.ts +3 -3
- package/src/internal/motion/scrollFrame.ts +9 -7
- package/src/internal/motion/scrubber.ts +39 -20
- package/src/internal/motion/slider.ts +38 -4
- package/src/internal/motion/softPress.ts +10 -9
- package/src/internal/motion/splitFlap.ts +4 -4
- package/src/internal/motion/swipeDeck.ts +38 -7
- package/src/internal/motion/table.ts +3 -6
- package/src/internal/motion/themeIcon.ts +1 -1
- package/src/internal/motion/themeReveal.ts +1 -1
- package/src/internal/motion/toast.ts +3 -3
- package/src/internal/motion.ts +7 -8
- package/src/internal/scrollFrame.ts +3 -3
- package/src/internal/useScrub.ts +1 -15
- package/src/internal/vue/useScrub.ts +2 -6
- package/src/tokens.css +81 -421
- package/src/{internal/vueIcons.ts → icons/vue.ts} +5 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@layer gooee.components {
|
|
1
2
|
/* The anchor keeps the button's place in the page. The shell is the panel's final box, laid out from
|
|
2
3
|
the start, so nothing inside it reflows while it grows. */
|
|
3
4
|
.anchor {
|
|
@@ -15,8 +16,8 @@
|
|
|
15
16
|
.shell[data-width="md"] { width: min(var(--gooee-panel-w-md), calc(100vw - var(--gooee-space-5) * 2)); }
|
|
16
17
|
|
|
17
18
|
/* Shut, only the button takes the pointer: the rest of the box is empty space over the page. */
|
|
18
|
-
.shell
|
|
19
|
-
.shell
|
|
19
|
+
.shell[data-state='closed'] { pointer-events: none; }
|
|
20
|
+
.shell[data-state='closed'] .trigger { pointer-events: auto; }
|
|
20
21
|
|
|
21
22
|
.shell[data-corner="tl"] { top: 0; left: 0; }
|
|
22
23
|
.shell[data-corner="tr"] { top: 0; right: 0; }
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
transition: clip-path var(--gooee-motion-morph-out) var(--gooee-ease-morph);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
.shell[data-open] .surface {
|
|
48
|
+
.shell[data-state='open'] .surface {
|
|
48
49
|
border-radius: var(--gooee-radius-panel);
|
|
49
50
|
box-shadow: var(--gooee-shadow-3);
|
|
50
51
|
transition:
|
|
@@ -53,15 +54,15 @@
|
|
|
53
54
|
box-shadow var(--gooee-motion-morph) var(--gooee-ease-morph);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
.shell[data-open] .content {
|
|
57
|
+
.shell[data-state='open'] .content {
|
|
57
58
|
clip-path: inset(var(--t) var(--r) var(--b) var(--l) round var(--gooee-radius-panel));
|
|
58
59
|
transition: clip-path var(--gooee-motion-morph) var(--gooee-ease-morph);
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
.shell
|
|
62
|
+
.shell[data-state='closed']:has(.trigger:focus-visible) .surface { box-shadow: var(--gooee-focus-ring); }
|
|
62
63
|
|
|
63
64
|
@media (hover: hover) {
|
|
64
|
-
.shell
|
|
65
|
+
.shell[data-state='closed']:has(.trigger:hover) .surface { background: var(--gooee-color-surface-hover); }
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
.trigger {
|
|
@@ -99,7 +100,7 @@
|
|
|
99
100
|
.shell[data-corner="bl"] .trigger { bottom: 0; left: 0; }
|
|
100
101
|
.shell[data-corner="br"] .trigger { bottom: 0; right: 0; }
|
|
101
102
|
|
|
102
|
-
.shell[data-open] .trigger:focus-visible { box-shadow: inset 0 0 0 var(--gooee-
|
|
103
|
+
.shell[data-state='open'] .trigger:focus-visible { box-shadow: inset 0 0 0 var(--gooee-focus-width) var(--gooee-color-fg); }
|
|
103
104
|
|
|
104
105
|
/* The panel's content clears the button's row, which is now its title, above or below it. */
|
|
105
106
|
.panel {
|
|
@@ -112,7 +113,7 @@
|
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
/* Shut, the panel leaves the accessibility tree and the tab order, once the fold has finished. */
|
|
115
|
-
.shell
|
|
116
|
+
.shell[data-state='closed'] .panel {
|
|
116
117
|
visibility: hidden;
|
|
117
118
|
transition: visibility 0s linear var(--gooee-motion-morph-out);
|
|
118
119
|
}
|
|
@@ -153,4 +154,5 @@
|
|
|
153
154
|
.close:hover { background: var(--gooee-color-surface-hover); color: var(--gooee-color-fg); }
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
.close:focus-visible { outline: none; box-shadow: inset 0 0 0 var(--gooee-
|
|
157
|
+
.close:focus-visible { outline: none; box-shadow: inset 0 0 0 var(--gooee-focus-width) var(--gooee-color-fg); }
|
|
158
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { useEffect, useId, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode, type RefObject } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
5
|
import { focusables } from '../../internal/focus'
|
|
6
|
-
import { XIcon } from '../../
|
|
6
|
+
import { XIcon } from '../../icons/icons'
|
|
7
7
|
import { useDismiss } from '../../internal/layers'
|
|
8
8
|
import { morphInsets, observeMorphButton, placeMorphButton, takesFocus, type MorphCorner } from '../../internal/motion/morphButton'
|
|
9
9
|
import { useControllable } from '../../internal/useControllable'
|
|
@@ -24,14 +24,21 @@ export type MorphButtonProps = {
|
|
|
24
24
|
onOpenChange?: (open: boolean) => void
|
|
25
25
|
/** How wide the panel grows. It never runs past the edge of the screen. */
|
|
26
26
|
width?: 'sm' | 'md'
|
|
27
|
-
/**
|
|
28
|
-
|
|
27
|
+
/** Text for the button's controls, so you can translate it. Missing keys use the English defaults. */
|
|
28
|
+
labels?: Partial<MorphButtonLabels>
|
|
29
29
|
/** Element to focus when it opens. Defaults to the first control in the panel. */
|
|
30
30
|
initialFocus?: RefObject<HTMLElement | null>
|
|
31
31
|
/** Extra class for the outer box, which keeps the button's place in the page. */
|
|
32
32
|
className?: string
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
export type MorphButtonLabels = {
|
|
36
|
+
/** Screen reader name for the close button. */
|
|
37
|
+
close: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const defaultLabels: MorphButtonLabels = { close: 'Close' }
|
|
41
|
+
|
|
35
42
|
export function MorphButton({
|
|
36
43
|
label,
|
|
37
44
|
icon,
|
|
@@ -40,10 +47,11 @@ export function MorphButton({
|
|
|
40
47
|
defaultOpen = false,
|
|
41
48
|
onOpenChange,
|
|
42
49
|
width = 'sm',
|
|
43
|
-
|
|
50
|
+
labels: labelsProp,
|
|
44
51
|
initialFocus,
|
|
45
52
|
className,
|
|
46
53
|
}: MorphButtonProps) {
|
|
54
|
+
const labels = { ...defaultLabels, ...labelsProp }
|
|
47
55
|
const id = useId()
|
|
48
56
|
const [open, setOpen] = useControllable(openProp, defaultOpen, onOpenChange)
|
|
49
57
|
const [corner, setCorner] = useState<MorphCorner>('tl')
|
|
@@ -105,13 +113,14 @@ export function MorphButton({
|
|
|
105
113
|
const vars = { ...morphInsets(corner, box, open), maxWidth: room } as CSSProperties
|
|
106
114
|
|
|
107
115
|
return (
|
|
108
|
-
<div ref={anchorRef} className={cx(styles.anchor, className)} style={{ width: box.tw || undefined, height: box.th || undefined }}>
|
|
109
|
-
<div ref={shellRef} className={styles.shell} data-
|
|
116
|
+
<div ref={anchorRef} data-slot="morph-button" className={cx(styles.anchor, className)} style={{ width: box.tw || undefined, height: box.th || undefined }}>
|
|
117
|
+
<div ref={shellRef} data-slot="morph-button-shell" className={styles.shell} data-state={open ? 'open' : 'closed'} data-corner={corner} data-width={width} style={vars}>
|
|
110
118
|
<div className={styles.surface} aria-hidden="true" />
|
|
111
119
|
<div className={styles.content}>
|
|
112
120
|
<button
|
|
113
121
|
ref={triggerRef}
|
|
114
122
|
type="button"
|
|
123
|
+
data-slot="morph-button-trigger"
|
|
115
124
|
className={styles.trigger}
|
|
116
125
|
aria-expanded={open}
|
|
117
126
|
aria-haspopup="dialog"
|
|
@@ -119,17 +128,18 @@ export function MorphButton({
|
|
|
119
128
|
onClick={() => show(!open)}
|
|
120
129
|
>
|
|
121
130
|
{icon && (
|
|
122
|
-
<span className={styles.icon} aria-hidden="true">
|
|
131
|
+
<span data-slot="morph-button-icon" className={styles.icon} aria-hidden="true">
|
|
123
132
|
{icon}
|
|
124
133
|
</span>
|
|
125
134
|
)}
|
|
126
|
-
<span id={`${id}-label`}>{label}</span>
|
|
135
|
+
<span id={`${id}-label`} data-slot="morph-button-label">{label}</span>
|
|
127
136
|
</button>
|
|
128
|
-
<div ref={panelRef} id={`${id}-panel`} role="dialog" aria-labelledby={`${id}-label`} tabIndex={-1} className={styles.panel} inert={!open} aria-hidden={!open || undefined}>
|
|
137
|
+
<div ref={panelRef} id={`${id}-panel`} role="dialog" aria-labelledby={`${id}-label`} tabIndex={-1} data-slot="morph-button-panel" className={styles.panel} inert={!open} aria-hidden={!open || undefined}>
|
|
129
138
|
<button
|
|
130
139
|
type="button"
|
|
140
|
+
data-slot="morph-button-close"
|
|
131
141
|
className={styles.close}
|
|
132
|
-
aria-label={
|
|
142
|
+
aria-label={labels.close}
|
|
133
143
|
data-skip-initial-focus
|
|
134
144
|
onClick={() => {
|
|
135
145
|
setOpen(false)
|
|
@@ -3,32 +3,36 @@ import { computed, onBeforeUnmount, onMounted, ref, useId, useSlots, watch } fro
|
|
|
3
3
|
import { focusables } from '../../internal/motion/focus'
|
|
4
4
|
import { dismissable } from '../../internal/motion/layers'
|
|
5
5
|
import { morphInsets, observeMorphButton, placeMorphButton, takesFocus, type MorphBox, type MorphCorner } from '../../internal/motion/morphButton'
|
|
6
|
-
import { XIcon } from '../../
|
|
6
|
+
import { XIcon } from '../../icons/vue'
|
|
7
7
|
import styles from './MorphButton.module.css'
|
|
8
8
|
|
|
9
9
|
// The Vue MorphButton: the same look (MorphButton.module.css), growth and dismiss as the React one. The
|
|
10
10
|
// panel's content goes in the default slot, the icon in the icon slot.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
|
|
12
|
+
export type MorphButtonLabels = {
|
|
13
|
+
/** Screen reader name for the close button. */
|
|
14
|
+
close: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { defaultOpen = false, width = 'sm', labels: labelsProp, initialFocus } = defineProps<{
|
|
18
|
+
/** The button's text. It stays on the same spot and becomes the panel's title and name. The label slot replaces it. */
|
|
19
|
+
label?: string
|
|
20
|
+
/** Starting open state when there is no v-model. */
|
|
21
|
+
defaultOpen?: boolean
|
|
22
|
+
/** How wide the panel grows. It never runs past the edge of the screen. */
|
|
23
|
+
width?: 'sm' | 'md'
|
|
24
|
+
/** Text for the button's controls, so you can translate it. Missing keys use the English defaults. */
|
|
25
|
+
labels?: Partial<MorphButtonLabels>
|
|
26
|
+
/** Element to focus when it opens. Defaults to the first control in the panel. */
|
|
27
|
+
initialFocus?: HTMLElement | null
|
|
28
|
+
}>()
|
|
29
|
+
const labels = computed<MorphButtonLabels>(() => ({ close: 'Close', ...labelsProp }))
|
|
26
30
|
/** Whether the panel is open. Use v-model:open, or leave it out and the button keeps its own state. */
|
|
27
31
|
const model = defineModel<boolean | undefined>('open', { type: Boolean, default: undefined })
|
|
28
32
|
const slots = useSlots() as { default?: () => unknown; label?: () => unknown; icon?: () => unknown }
|
|
29
33
|
|
|
30
34
|
const id = useId()
|
|
31
|
-
const own = ref(
|
|
35
|
+
const own = ref(defaultOpen)
|
|
32
36
|
const open = computed(() => model.value ?? own.value)
|
|
33
37
|
const setOpen = (next: boolean) => {
|
|
34
38
|
own.value = next
|
|
@@ -82,7 +86,7 @@ const onOpen = (now: boolean) => {
|
|
|
82
86
|
{ focusOut: true },
|
|
83
87
|
)
|
|
84
88
|
if (!panelEl.value) return
|
|
85
|
-
const first =
|
|
89
|
+
const first = initialFocus ?? focusables(panelEl.value).find((el) => !el.hasAttribute('data-skip-initial-focus')) ?? panelEl.value
|
|
86
90
|
first.focus({ preventScroll: true })
|
|
87
91
|
}
|
|
88
92
|
watch(open, onOpen, { flush: 'post' })
|
|
@@ -100,16 +104,16 @@ const close = () => {
|
|
|
100
104
|
</script>
|
|
101
105
|
|
|
102
106
|
<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-
|
|
107
|
+
<div ref="anchorEl" data-slot="morph-button" :class="styles.anchor" :style="{ width: box.tw ? `${box.tw}px` : undefined, height: box.th ? `${box.th}px` : undefined }">
|
|
108
|
+
<div ref="shellEl" data-slot="morph-button-shell" :class="styles.shell" :data-state="open ? 'open' : 'closed'" :data-corner="corner" :data-width="width" :style="vars">
|
|
105
109
|
<div :class="styles.surface" aria-hidden="true" />
|
|
106
110
|
<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>
|
|
111
|
+
<button ref="triggerEl" type="button" data-slot="morph-button-trigger" :class="styles.trigger" :aria-expanded="open" aria-haspopup="dialog" :aria-controls="`${id}-panel`" @click="show(!open)">
|
|
112
|
+
<span v-if="slots.icon" data-slot="morph-button-icon" :class="styles.icon" aria-hidden="true"><slot name="icon" /></span>
|
|
113
|
+
<span :id="`${id}-label`" data-slot="morph-button-label"><slot name="label">{{ label }}</slot></span>
|
|
110
114
|
</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="
|
|
115
|
+
<div ref="panelEl" :id="`${id}-panel`" role="dialog" :aria-labelledby="`${id}-label`" tabindex="-1" data-slot="morph-button-panel" :class="styles.panel" :inert="!open" :aria-hidden="!open || undefined">
|
|
116
|
+
<button type="button" data-slot="morph-button-close" :class="styles.close" :aria-label="labels.close" data-skip-initial-focus="true" @click="close">
|
|
113
117
|
<XIcon />
|
|
114
118
|
</button>
|
|
115
119
|
<slot />
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@layer gooee.components {
|
|
1
2
|
.root {
|
|
2
3
|
display: flex;
|
|
3
4
|
flex-direction: column;
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
display: inline-flex;
|
|
15
16
|
align-items: center;
|
|
16
17
|
align-self: flex-start;
|
|
17
|
-
width: var(--gooee-number-w);
|
|
18
|
+
width: var(--gooee-number-input-w, 168px);
|
|
18
19
|
max-width: 100%;
|
|
19
20
|
min-height: var(--gooee-hit-min);
|
|
20
21
|
padding: 0;
|
|
@@ -26,8 +27,8 @@
|
|
|
26
27
|
border-radius: var(--gooee-radius-control);
|
|
27
28
|
background: var(--gooee-color-surface);
|
|
28
29
|
transition:
|
|
29
|
-
outline-color var(--gooee-motion-fast) var(--gooee-ease-
|
|
30
|
-
box-shadow var(--gooee-motion-base) var(--gooee-ease-
|
|
30
|
+
outline-color var(--gooee-motion-fast) var(--gooee-ease-morph),
|
|
31
|
+
box-shadow var(--gooee-motion-base) var(--gooee-ease-morph);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
@media (hover: hover) {
|
|
@@ -60,8 +61,8 @@
|
|
|
60
61
|
user-select: none;
|
|
61
62
|
-webkit-tap-highlight-color: transparent;
|
|
62
63
|
transition:
|
|
63
|
-
background-color var(--gooee-motion-fast) var(--gooee-ease-
|
|
64
|
-
transform var(--gooee-motion-slow) var(--gooee-ease-
|
|
64
|
+
background-color var(--gooee-motion-fast) var(--gooee-ease-morph),
|
|
65
|
+
transform var(--gooee-motion-slow) var(--gooee-ease-morph);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
@media (hover: hover) {
|
|
@@ -106,3 +107,4 @@
|
|
|
106
107
|
font-weight: var(--gooee-weight-medium);
|
|
107
108
|
pointer-events: none;
|
|
108
109
|
}
|
|
110
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { useEffect, useId, useMemo, useRef, useState, type KeyboardEvent, type PointerEvent, type ReactNode } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
5
|
import { FieldMessage } from '../../internal/FieldMessage'
|
|
6
|
-
import { MinusIcon, PlusIcon } from '../../
|
|
6
|
+
import { MinusIcon, PlusIcon } from '../../icons/icons'
|
|
7
7
|
import { createHold, parseNumber, type NumberInputLabels } from '../../internal/motion/numberInput'
|
|
8
8
|
import { useControllable } from '../../internal/useControllable'
|
|
9
9
|
import { AnimatedNumber } from '../AnimatedNumber'
|
|
@@ -34,7 +34,7 @@ export type NumberInputProps = {
|
|
|
34
34
|
/** Step for Page Up and Page Down. Defaults to ten steps. */
|
|
35
35
|
largeStep?: number
|
|
36
36
|
/** Passed to Intl.NumberFormat, for currency, units or decimals. */
|
|
37
|
-
|
|
37
|
+
formatOptions?: Intl.NumberFormatOptions
|
|
38
38
|
/** Locale for showing and reading numbers. Undefined uses the browser locale. */
|
|
39
39
|
locale?: string
|
|
40
40
|
/** Hint under the field. Hidden while an error shows. */
|
|
@@ -60,7 +60,7 @@ export function NumberInput({
|
|
|
60
60
|
max = Infinity,
|
|
61
61
|
step = 1,
|
|
62
62
|
largeStep,
|
|
63
|
-
|
|
63
|
+
formatOptions,
|
|
64
64
|
locale,
|
|
65
65
|
help,
|
|
66
66
|
error,
|
|
@@ -84,7 +84,7 @@ export function NumberInput({
|
|
|
84
84
|
typed.current = editing ? text : null
|
|
85
85
|
const [hold] = useState(createHold)
|
|
86
86
|
const decimals = (String(step).split('.')[1] ?? '').length
|
|
87
|
-
const fmt = useMemo(() => new Intl.NumberFormat(locale,
|
|
87
|
+
const fmt = useMemo(() => new Intl.NumberFormat(locale, formatOptions), [locale, formatOptions])
|
|
88
88
|
const plain = useMemo(() => new Intl.NumberFormat(locale, { useGrouping: false, maximumFractionDigits: 20 }), [locale])
|
|
89
89
|
|
|
90
90
|
const clamp = (n: number) => Number(Math.min(max, Math.max(min, n)).toFixed(decimals))
|
|
@@ -140,13 +140,14 @@ export function NumberInput({
|
|
|
140
140
|
const describedBy = [help && !error ? helpId : null, error ? errorId : null].filter(Boolean).join(' ')
|
|
141
141
|
|
|
142
142
|
return (
|
|
143
|
-
<div className={cx(styles.root, className)}>
|
|
144
|
-
<label htmlFor={id} className={styles.label}>{label}</label>
|
|
145
|
-
<div className={styles.field} data-invalid={error ? true : undefined} data-disabled={disabled || undefined}>
|
|
143
|
+
<div className={cx(styles.root, className)} data-slot="number-input">
|
|
144
|
+
<label htmlFor={id} className={styles.label} data-slot="field-label">{label}</label>
|
|
145
|
+
<div className={styles.field} data-slot="number-input-field" data-invalid={error ? true : undefined} data-disabled={disabled || undefined}>
|
|
146
146
|
<button
|
|
147
147
|
type="button"
|
|
148
148
|
tabIndex={-1}
|
|
149
149
|
className={styles.step}
|
|
150
|
+
data-slot="number-input-decrement"
|
|
150
151
|
aria-label={nameOf(labels.decrease)}
|
|
151
152
|
aria-controls={id}
|
|
152
153
|
disabled={disabled || atMin}
|
|
@@ -162,6 +163,7 @@ export function NumberInput({
|
|
|
162
163
|
<input
|
|
163
164
|
id={id}
|
|
164
165
|
className={styles.input}
|
|
166
|
+
data-slot="number-input-input"
|
|
165
167
|
type="text"
|
|
166
168
|
inputMode={decimals || min < 0 ? 'decimal' : 'numeric'}
|
|
167
169
|
role="spinbutton"
|
|
@@ -188,7 +190,7 @@ export function NumberInput({
|
|
|
188
190
|
/>
|
|
189
191
|
{!editing && value !== null && (
|
|
190
192
|
<span className={styles.rolling} aria-hidden="true">
|
|
191
|
-
<AnimatedNumber value={value}
|
|
193
|
+
<AnimatedNumber value={value} formatOptions={formatOptions} locale={locale} />
|
|
192
194
|
</span>
|
|
193
195
|
)}
|
|
194
196
|
</div>
|
|
@@ -196,6 +198,7 @@ export function NumberInput({
|
|
|
196
198
|
type="button"
|
|
197
199
|
tabIndex={-1}
|
|
198
200
|
className={styles.step}
|
|
201
|
+
data-slot="number-input-increment"
|
|
199
202
|
aria-label={nameOf(labels.increase)}
|
|
200
203
|
aria-controls={id}
|
|
201
204
|
disabled={disabled || atMax}
|
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, onBeforeUnmount, ref, useId } from 'vue'
|
|
3
3
|
import FieldMessage from '../../internal/FieldMessage.vue'
|
|
4
|
-
import { MinusIcon, PlusIcon } from '../../
|
|
4
|
+
import { MinusIcon, PlusIcon } from '../../icons/vue'
|
|
5
5
|
import { createHold, parseNumber, type NumberInputLabels } from '../../internal/motion/numberInput'
|
|
6
6
|
import AnimatedNumber from '../AnimatedNumber/AnimatedNumber.vue'
|
|
7
7
|
import styles from './NumberInput.module.css'
|
|
8
8
|
|
|
9
9
|
// The Vue NumberInput: the same look (NumberInput.module.css), keys and hold to repeat as the React one.
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
10
|
+
const {
|
|
11
|
+
label,
|
|
12
|
+
defaultValue = null,
|
|
13
|
+
min = -Infinity,
|
|
14
|
+
max = Infinity,
|
|
15
|
+
step = 1,
|
|
16
|
+
largeStep,
|
|
17
|
+
formatOptions,
|
|
18
|
+
locale,
|
|
19
|
+
help,
|
|
20
|
+
error,
|
|
21
|
+
labels,
|
|
22
|
+
} = defineProps<{
|
|
23
|
+
/** Visible name of the field, also read by screen readers. */
|
|
24
|
+
label: string
|
|
25
|
+
/** Starting value when there is no v-model. */
|
|
26
|
+
defaultValue?: number | null
|
|
27
|
+
/** Lowest allowed number. Typed values are clamped to it. */
|
|
28
|
+
min?: number
|
|
29
|
+
/** Highest allowed number. Typed values are clamped to it. */
|
|
30
|
+
max?: number
|
|
31
|
+
/** How much the buttons and arrow keys change the value. Its decimals set the rounding. */
|
|
32
|
+
step?: number
|
|
33
|
+
/** Step for Page Up and Page Down. Defaults to ten steps. */
|
|
34
|
+
largeStep?: number
|
|
35
|
+
/** Passed to Intl.NumberFormat, for currency, units or decimals. */
|
|
36
|
+
formatOptions?: Intl.NumberFormatOptions
|
|
37
|
+
/** Locale for showing and reading numbers. Undefined uses the browser locale. */
|
|
38
|
+
locale?: string
|
|
39
|
+
/** Hint under the field. Hidden while an error shows. */
|
|
40
|
+
help?: string
|
|
41
|
+
/** Error message under the field. Also marks the field invalid. */
|
|
42
|
+
error?: string
|
|
43
|
+
/** Stops typing and the step buttons. */
|
|
44
|
+
disabled?: boolean
|
|
45
|
+
/** Submits the plain number in a hidden field with this name. */
|
|
46
|
+
name?: string
|
|
47
|
+
/** Screen reader names for the step buttons. */
|
|
48
|
+
labels?: Partial<NumberInputLabels>
|
|
49
|
+
}>()
|
|
41
50
|
/** The number, or null when the field is empty. Use v-model, or leave it out and the field keeps its own. */
|
|
42
51
|
const model = defineModel<number | null | undefined>({ default: undefined })
|
|
43
|
-
const inner = ref<number | null>(
|
|
52
|
+
const inner = ref<number | null>(defaultValue)
|
|
44
53
|
const value = computed(() => (model.value !== undefined ? model.value : inner.value))
|
|
45
54
|
const setValue = (next: number | null) => {
|
|
46
55
|
inner.value = next
|
|
@@ -49,28 +58,28 @@ const setValue = (next: number | null) => {
|
|
|
49
58
|
|
|
50
59
|
const nameOf = (text: NumberInputLabels['decrease'] | undefined, fallback: (l: string) => string) => {
|
|
51
60
|
const t = text ?? fallback
|
|
52
|
-
return typeof t === 'function' ? t(
|
|
61
|
+
return typeof t === 'function' ? t(label) : t
|
|
53
62
|
}
|
|
54
|
-
const decreaseName = computed(() => nameOf(
|
|
55
|
-
const increaseName = computed(() => nameOf(
|
|
63
|
+
const decreaseName = computed(() => nameOf(labels?.decrease, (l) => `Decrease ${l}`))
|
|
64
|
+
const increaseName = computed(() => nameOf(labels?.increase, (l) => `Increase ${l}`))
|
|
56
65
|
const id = useId()
|
|
57
66
|
const helpId = `${id}-help`
|
|
58
67
|
const errorId = `${id}-error`
|
|
59
68
|
const editing = ref(false)
|
|
60
69
|
const text = ref('')
|
|
61
|
-
const decimals = computed(() => (String(
|
|
62
|
-
const fmt = computed(() => new Intl.NumberFormat(
|
|
63
|
-
const plain = computed(() => new Intl.NumberFormat(
|
|
70
|
+
const decimals = computed(() => (String(step).split('.')[1] ?? '').length)
|
|
71
|
+
const fmt = computed(() => new Intl.NumberFormat(locale, formatOptions))
|
|
72
|
+
const plain = computed(() => new Intl.NumberFormat(locale, { useGrouping: false, maximumFractionDigits: 20 }))
|
|
64
73
|
|
|
65
|
-
const clamp = (n: number) => Number(Math.min(
|
|
74
|
+
const clamp = (n: number) => Number(Math.min(max, Math.max(min, n)).toFixed(decimals.value))
|
|
66
75
|
const commit = (n: number | null) => {
|
|
67
76
|
const next = n === null ? null : clamp(n)
|
|
68
77
|
if (next !== value.value) setValue(next)
|
|
69
78
|
if (editing.value) text.value = next === null ? '' : plain.value.format(next)
|
|
70
79
|
}
|
|
71
|
-
const bump = (dir: 1 | -1, size =
|
|
72
|
-
const current = (editing.value ? parseNumber(text.value,
|
|
73
|
-
const base = current ?? (
|
|
80
|
+
const bump = (dir: 1 | -1, size = step) => {
|
|
81
|
+
const current = (editing.value ? parseNumber(text.value, locale) : null) ?? value.value
|
|
82
|
+
const base = current ?? (min > -Infinity ? min : 0)
|
|
74
83
|
commit(current === null ? base : base + dir * size)
|
|
75
84
|
}
|
|
76
85
|
|
|
@@ -80,25 +89,25 @@ const startHold = (dir: 1 | -1) => (e: PointerEvent) => {
|
|
|
80
89
|
if (e.button !== 0 || (e.currentTarget as HTMLButtonElement).disabled) return
|
|
81
90
|
e.preventDefault()
|
|
82
91
|
hold.start(
|
|
83
|
-
(big) => bump(dir, big ?
|
|
92
|
+
(big) => bump(dir, big ? step * 5 : step),
|
|
84
93
|
() => {
|
|
85
94
|
const v = value.value
|
|
86
|
-
return v !== null && (dir > 0 ? v >=
|
|
95
|
+
return v !== null && (dir > 0 ? v >= max : v <= min)
|
|
87
96
|
},
|
|
88
97
|
)
|
|
89
98
|
}
|
|
90
99
|
onBeforeUnmount(hold.stop)
|
|
91
100
|
|
|
92
101
|
const onKeydown = (e: KeyboardEvent) => {
|
|
93
|
-
const big =
|
|
102
|
+
const big = largeStep ?? step * 10
|
|
94
103
|
const k = e.key
|
|
95
104
|
if (k === 'ArrowUp') bump(1)
|
|
96
105
|
else if (k === 'ArrowDown') bump(-1)
|
|
97
106
|
else if (k === 'PageUp') bump(1, big)
|
|
98
107
|
else if (k === 'PageDown') bump(-1, big)
|
|
99
|
-
else if (k === 'Home' &&
|
|
100
|
-
else if (k === 'End' &&
|
|
101
|
-
else if (k === 'Enter') commit(parseNumber(text.value,
|
|
108
|
+
else if (k === 'Home' && min > -Infinity) commit(min)
|
|
109
|
+
else if (k === 'End' && max < Infinity) commit(max)
|
|
110
|
+
else if (k === 'Enter') commit(parseNumber(text.value, locale))
|
|
102
111
|
else return
|
|
103
112
|
e.preventDefault()
|
|
104
113
|
}
|
|
@@ -107,24 +116,25 @@ const onFocus = () => {
|
|
|
107
116
|
text.value = value.value === null ? '' : plain.value.format(value.value)
|
|
108
117
|
}
|
|
109
118
|
const onBlur = () => {
|
|
110
|
-
commit(parseNumber(text.value,
|
|
119
|
+
commit(parseNumber(text.value, locale))
|
|
111
120
|
editing.value = false
|
|
112
121
|
}
|
|
113
122
|
|
|
114
|
-
const atMin = computed(() => value.value !== null && value.value <=
|
|
115
|
-
const atMax = computed(() => value.value !== null && value.value >=
|
|
116
|
-
const describedBy = computed(() => [
|
|
123
|
+
const atMin = computed(() => value.value !== null && value.value <= min)
|
|
124
|
+
const atMax = computed(() => value.value !== null && value.value >= max)
|
|
125
|
+
const describedBy = computed(() => [help && !error ? helpId : null, error ? errorId : null].filter(Boolean).join(' ') || undefined)
|
|
117
126
|
const shown = computed(() => (editing.value ? text.value : value.value === null ? '' : fmt.value.format(value.value)))
|
|
118
127
|
</script>
|
|
119
128
|
|
|
120
129
|
<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">
|
|
130
|
+
<div :class="styles.root" data-slot="number-input">
|
|
131
|
+
<label :for="id" :class="styles.label" data-slot="field-label">{{ label }}</label>
|
|
132
|
+
<div :class="styles.field" data-slot="number-input-field" :data-invalid="error ? true : undefined" :data-disabled="disabled || undefined">
|
|
124
133
|
<button
|
|
125
134
|
type="button"
|
|
126
135
|
tabindex="-1"
|
|
127
136
|
:class="styles.step"
|
|
137
|
+
data-slot="number-input-decrement"
|
|
128
138
|
:aria-label="decreaseName"
|
|
129
139
|
:aria-controls="id"
|
|
130
140
|
:disabled="disabled || atMin"
|
|
@@ -140,6 +150,7 @@ const shown = computed(() => (editing.value ? text.value : value.value === null
|
|
|
140
150
|
<input
|
|
141
151
|
:id="id"
|
|
142
152
|
:class="styles.input"
|
|
153
|
+
data-slot="number-input-input"
|
|
143
154
|
type="text"
|
|
144
155
|
:inputmode="decimals || min < 0 ? 'decimal' : 'numeric'"
|
|
145
156
|
role="spinbutton"
|
|
@@ -159,13 +170,14 @@ const shown = computed(() => (editing.value ? text.value : value.value === null
|
|
|
159
170
|
@keydown="onKeydown"
|
|
160
171
|
/>
|
|
161
172
|
<span v-if="!editing && value !== null" :class="styles.rolling" aria-hidden="true">
|
|
162
|
-
<AnimatedNumber :value="value" :format="
|
|
173
|
+
<AnimatedNumber :value="value" :format-options="formatOptions" :locale="locale" />
|
|
163
174
|
</span>
|
|
164
175
|
</div>
|
|
165
176
|
<button
|
|
166
177
|
type="button"
|
|
167
178
|
tabindex="-1"
|
|
168
179
|
:class="styles.step"
|
|
180
|
+
data-slot="number-input-increment"
|
|
169
181
|
:aria-label="increaseName"
|
|
170
182
|
:aria-controls="id"
|
|
171
183
|
:disabled="disabled || atMax"
|