gooee 0.52.0 → 1.0.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.
- 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 +7 -5
- 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 +11 -8
- package/src/components/DropdownMenu/DropdownMenu.vue +24 -27
- 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 +15 -8
- 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 +30 -17
- package/src/components/Select/Select.vue +62 -57
- 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 +20 -9
- 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
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type ReactNode } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
5
|
import { clamp, pull, wheelSteps, wrap } from '../../internal/feel'
|
|
6
|
-
import { columnScrub, columnState, dateWheel, drumRows, timeWheel, today, type ColumnState, type WheelColumn } from '../../internal/motion/pickerWheel'
|
|
6
|
+
import { columnScrub, columnState, dateWheel, drumRows, localeHourCycle, timeWheel, today, type ColumnState, type WheelColumn } from '../../internal/motion/pickerWheel'
|
|
7
7
|
import { useControllable } from '../../internal/useControllable'
|
|
8
|
-
import { ink, tokenNumber,
|
|
8
|
+
import { ink, tokenNumber, useScrub } from '../../internal/useScrub'
|
|
9
9
|
import styles from './PickerWheel.module.css'
|
|
10
10
|
|
|
11
11
|
export type PickerWheelColumn = WheelColumn
|
|
@@ -19,10 +19,10 @@ export type PickerWheelProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue'
|
|
|
19
19
|
value?: number[]
|
|
20
20
|
/** Starting rows when you do not control them. Undefined starts on the first row of each. */
|
|
21
21
|
defaultValue?: number[]
|
|
22
|
-
/** Called
|
|
22
|
+
/** Called with every column's row each time a new row comes into the band, while the wheel still turns. */
|
|
23
23
|
onValueChange?: (value: number[]) => void
|
|
24
|
-
/** Called
|
|
25
|
-
|
|
24
|
+
/** Called once a column comes to rest on a new row, with every column's row. */
|
|
25
|
+
onValueCommit?: (value: number[]) => void
|
|
26
26
|
/** Turns the rows into a large readout above the wheel. No readout when left out. */
|
|
27
27
|
formatValue?: (value: number[]) => string
|
|
28
28
|
/** A line under the label and readout, such as what the choice means. */
|
|
@@ -34,13 +34,13 @@ export type PickerWheelProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue'
|
|
|
34
34
|
type ColumnProps = {
|
|
35
35
|
column: PickerWheelColumn
|
|
36
36
|
index: number
|
|
37
|
-
|
|
37
|
+
onCommit: (index: number) => void
|
|
38
38
|
onShown: (index: number) => void
|
|
39
39
|
haptics: boolean
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/** One column: its rows are the marks. A drag follows the hand; a let-go lands on a row. */
|
|
43
|
-
function Column({ column, index,
|
|
43
|
+
function Column({ column, index, onCommit, onShown, haptics }: ColumnProps) {
|
|
44
44
|
const { options, loop = false } = column
|
|
45
45
|
const n = options.length
|
|
46
46
|
const strong = new Set(column.strong ?? [])
|
|
@@ -52,9 +52,10 @@ function Column({ column, index, onChange, onShown, haptics }: ColumnProps) {
|
|
|
52
52
|
// The keys, tap and wheel of one column (motion/pickerWheel.ts) on the shared scrubber.
|
|
53
53
|
const sc = useScrub({
|
|
54
54
|
...columnScrub(column, index, st, wheel.current),
|
|
55
|
-
onSettle: (to) => {
|
|
55
|
+
onSettle: (to, from) => {
|
|
56
56
|
st.rested = to
|
|
57
|
-
|
|
57
|
+
// A loop turned all the way round rests on the row it left: no news.
|
|
58
|
+
if (wrap(to, n) !== wrap(Math.round(from), n)) onCommit(wrap(to, n))
|
|
58
59
|
},
|
|
59
60
|
haptics,
|
|
60
61
|
})
|
|
@@ -86,6 +87,7 @@ function Column({ column, index, onChange, onShown, haptics }: ColumnProps) {
|
|
|
86
87
|
<div
|
|
87
88
|
ref={sc.ref}
|
|
88
89
|
className={styles.column}
|
|
90
|
+
data-slot="picker-wheel-column"
|
|
89
91
|
role="spinbutton"
|
|
90
92
|
tabIndex={0}
|
|
91
93
|
aria-label={column.label}
|
|
@@ -97,10 +99,10 @@ function Column({ column, index, onChange, onShown, haptics }: ColumnProps) {
|
|
|
97
99
|
data-moving={sc.moving || undefined}
|
|
98
100
|
{...sc.handlers}
|
|
99
101
|
>
|
|
100
|
-
<span className={styles.band} style={{ ['--grip' as string]: grip.toFixed(3) }} aria-hidden />
|
|
102
|
+
<span className={styles.band} data-slot="picker-wheel-band" style={{ ['--grip' as string]: grip.toFixed(3) }} aria-hidden />
|
|
101
103
|
<div className={styles.drum} aria-hidden>
|
|
102
104
|
{rows.map(({ k, d, i }) => (
|
|
103
|
-
<span key={k} className={styles.row} data-strong={strong.has(i) || undefined} style={{ ['--d' as string]: d.toFixed(3), color: ink(pull(d, 1)) }}>
|
|
105
|
+
<span key={k} className={styles.row} data-slot="picker-wheel-row" data-strong={strong.has(i) || undefined} style={{ ['--d' as string]: d.toFixed(3), color: ink(pull(d, 1)) }}>
|
|
104
106
|
{options[i]}
|
|
105
107
|
</span>
|
|
106
108
|
))}
|
|
@@ -109,43 +111,55 @@ function Column({ column, index, onChange, onShown, haptics }: ColumnProps) {
|
|
|
109
111
|
)
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
export function PickerWheel({ label, columns, value: valueProp, defaultValue, onValueChange,
|
|
114
|
+
export function PickerWheel({ label, columns, value: valueProp, defaultValue, onValueChange, onValueCommit, formatValue, detail, haptics = false, className, ...rest }: PickerWheelProps) {
|
|
113
115
|
const labelId = useId()
|
|
114
116
|
const detailId = useId()
|
|
115
117
|
const [raw, setValue] = useControllable(valueProp, defaultValue ?? columns.map(() => 0), onValueChange)
|
|
116
118
|
const value = columns.map((c, i) => clamp(raw[i] ?? 0, 0, c.options.length - 1))
|
|
117
|
-
const latest = useRef(value)
|
|
118
|
-
latest.current = value
|
|
119
119
|
const [live, setLive] = useState(value)
|
|
120
|
-
|
|
120
|
+
const liveRef = useRef(value)
|
|
121
|
+
// The rows last told, so a row comes once whether it came while moving or at rest.
|
|
122
|
+
const told = useRef(value.join(','))
|
|
123
|
+
const tell = (rows: number[]) => {
|
|
124
|
+
if (rows.join(',') === told.current) return
|
|
125
|
+
told.current = rows.join(',')
|
|
126
|
+
setValue(rows)
|
|
127
|
+
}
|
|
128
|
+
const tellRef = useRef(tell)
|
|
129
|
+
tellRef.current = tell
|
|
130
|
+
useEffect(() => tellRef.current(live), [live])
|
|
121
131
|
|
|
122
132
|
return (
|
|
123
|
-
<div className={cx(styles.root, className)} {...rest}>
|
|
133
|
+
<div className={cx(styles.root, className)} data-slot="picker-wheel" {...rest}>
|
|
124
134
|
<div className={styles.head}>
|
|
125
|
-
<span id={labelId} className={styles.label}>
|
|
135
|
+
<span id={labelId} className={styles.label} data-slot="field-label">
|
|
126
136
|
{label}
|
|
127
137
|
</span>
|
|
128
|
-
{formatValue && <span className={styles.readout}>{formatValue(live)}</span>}
|
|
138
|
+
{formatValue && <span className={styles.readout} data-slot="picker-wheel-value">{formatValue(live)}</span>}
|
|
129
139
|
{detail && (
|
|
130
|
-
<span id={detailId} className={styles.detail}>
|
|
140
|
+
<span id={detailId} className={styles.detail} data-slot="picker-wheel-detail">
|
|
131
141
|
{detail}
|
|
132
142
|
</span>
|
|
133
143
|
)}
|
|
134
144
|
</div>
|
|
135
|
-
<div className={styles.wheel} role="group" aria-labelledby={labelId} aria-describedby={detail ? detailId : undefined}>
|
|
145
|
+
<div className={styles.wheel} data-slot="picker-wheel-columns" role="group" aria-labelledby={labelId} aria-describedby={detail ? detailId : undefined}>
|
|
136
146
|
{columns.map((c, i) => (
|
|
137
147
|
<Column
|
|
138
148
|
key={i}
|
|
139
149
|
column={c}
|
|
140
150
|
index={value[i]}
|
|
141
151
|
haptics={haptics}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
onCommit={(row) => {
|
|
153
|
+
const next = liveRef.current.map((v, j) => (j === i ? row : v))
|
|
154
|
+
liveRef.current = next
|
|
155
|
+
tell(next)
|
|
156
|
+
onValueCommit?.(next)
|
|
157
|
+
}}
|
|
158
|
+
onShown={(row) => {
|
|
159
|
+
if (liveRef.current[i] === row) return
|
|
160
|
+
liveRef.current = liveRef.current.map((v, j) => (j === i ? row : v))
|
|
161
|
+
setLive(liveRef.current)
|
|
147
162
|
}}
|
|
148
|
-
onShown={(row) => setLive((l) => (l[i] === row ? l : l.map((v, j) => (j === i ? row : v))))}
|
|
149
163
|
/>
|
|
150
164
|
))}
|
|
151
165
|
</div>
|
|
@@ -153,39 +167,39 @@ export function PickerWheel({ label, columns, value: valueProp, defaultValue, on
|
|
|
153
167
|
)
|
|
154
168
|
}
|
|
155
169
|
|
|
156
|
-
export type TimeWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defaultValue' | 'onValueChange' | '
|
|
170
|
+
export type TimeWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defaultValue' | 'onValueChange' | 'onValueCommit' | 'formatValue'> & {
|
|
157
171
|
/** The time as "HH:mm" in 24 hours, when you control it. */
|
|
158
172
|
value?: string
|
|
159
173
|
/** Starting time when you do not control it. */
|
|
160
174
|
defaultValue?: string
|
|
161
|
-
/** Called
|
|
175
|
+
/** Called with the time in the band, as "HH:mm", each time it changes while the wheel still turns. */
|
|
162
176
|
onValueChange?: (value: string) => void
|
|
163
|
-
/** Called
|
|
164
|
-
|
|
165
|
-
/** 12 shows AM and PM; 24 shows hours 00 to 23. */
|
|
177
|
+
/** Called once the wheel comes to rest on a new time, as "HH:mm". */
|
|
178
|
+
onValueCommit?: (value: string) => void
|
|
179
|
+
/** 12 shows AM and PM; 24 shows hours 00 to 23. Defaults to what the browser's locale uses. */
|
|
166
180
|
hourCycle?: 12 | 24
|
|
167
|
-
/** Minutes between two rows. */
|
|
168
|
-
|
|
181
|
+
/** Minutes between two rows, such as 5 or 15. */
|
|
182
|
+
step?: number
|
|
169
183
|
/** Minutes drawn stronger. Page Up and Page Down jump between them. */
|
|
170
184
|
strong?: number[]
|
|
171
185
|
}
|
|
172
186
|
|
|
173
187
|
/** PickerWheel set up for a time: hour, minute and, on a 12 hour clock, AM or PM. */
|
|
174
|
-
export function TimeWheel({ value: valueProp, defaultValue = '09:00', onValueChange,
|
|
188
|
+
export function TimeWheel({ value: valueProp, defaultValue = '09:00', onValueChange, onValueCommit, hourCycle, step = 1, strong = [0, 30], ...rest }: TimeWheelProps) {
|
|
175
189
|
const [value, setValue] = useControllable(valueProp, defaultValue, onValueChange)
|
|
176
|
-
const { columns, toRows, toTime, show } = timeWheel(hourCycle,
|
|
177
|
-
return <PickerWheel {...rest} columns={columns} value={toRows(value)} onValueChange={(rows) => setValue(toTime(rows))}
|
|
190
|
+
const { columns, toRows, toTime, show } = timeWheel(hourCycle ?? localeHourCycle(), step, strong)
|
|
191
|
+
return <PickerWheel {...rest} columns={columns} value={toRows(value)} onValueChange={(rows) => setValue(toTime(rows))} onValueCommit={onValueCommit && ((rows) => onValueCommit(toTime(rows)))} formatValue={show} />
|
|
178
192
|
}
|
|
179
193
|
|
|
180
|
-
export type DateWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defaultValue' | 'onValueChange' | '
|
|
194
|
+
export type DateWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defaultValue' | 'onValueChange' | 'onValueCommit' | 'formatValue'> & {
|
|
181
195
|
/** The date as "YYYY-MM-DD", when you control it. */
|
|
182
196
|
value?: string
|
|
183
197
|
/** Starting date when you do not control it. Undefined starts today. */
|
|
184
198
|
defaultValue?: string
|
|
185
|
-
/** Called
|
|
199
|
+
/** Called with the date in the band, as "YYYY-MM-DD", each time it changes while the wheel still turns. */
|
|
186
200
|
onValueChange?: (value: string) => void
|
|
187
|
-
/** Called
|
|
188
|
-
|
|
201
|
+
/** Called once the wheel comes to rest on a new date, as "YYYY-MM-DD". */
|
|
202
|
+
onValueCommit?: (value: string) => void
|
|
189
203
|
/** The first year on the wheel. Undefined is 100 years ago. */
|
|
190
204
|
fromYear?: number
|
|
191
205
|
/** The last year on the wheel. Undefined is 10 years from now. */
|
|
@@ -195,17 +209,29 @@ export type DateWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defau
|
|
|
195
209
|
}
|
|
196
210
|
|
|
197
211
|
/** PickerWheel set up for a date: day, month and year, with each month's real length. */
|
|
198
|
-
export function DateWheel({ value: valueProp, defaultValue, onValueChange,
|
|
212
|
+
export function DateWheel({ value: valueProp, defaultValue, onValueChange, onValueCommit, fromYear, toYear, strong, ...rest }: DateWheelProps) {
|
|
199
213
|
const now = today()
|
|
200
214
|
const [value, setValue] = useControllable(valueProp, defaultValue ?? now, onValueChange)
|
|
201
|
-
|
|
215
|
+
// The days follow the month the wheel rests on, not each month that turns past (31 stays 31 on the way
|
|
216
|
+
// through February). A date from outside, not one this wheel told, is a new rest.
|
|
217
|
+
const told = useRef(value)
|
|
218
|
+
const [rested, setRested] = useState(value)
|
|
219
|
+
if (value !== told.current && value !== rested) setRested(value)
|
|
220
|
+
const { columns, rows, toDate, show } = dateWheel(rested, now, fromYear, toYear, strong)
|
|
202
221
|
return (
|
|
203
222
|
<PickerWheel
|
|
204
223
|
{...rest}
|
|
205
224
|
columns={columns}
|
|
206
225
|
value={rows}
|
|
207
|
-
onValueChange={(rows) =>
|
|
208
|
-
|
|
226
|
+
onValueChange={(rows) => {
|
|
227
|
+
told.current = toDate(rows)
|
|
228
|
+
setValue(told.current)
|
|
229
|
+
}}
|
|
230
|
+
onValueCommit={(rows) => {
|
|
231
|
+
told.current = toDate(rows)
|
|
232
|
+
setRested(told.current)
|
|
233
|
+
onValueCommit?.(told.current)
|
|
234
|
+
}}
|
|
209
235
|
formatValue={show}
|
|
210
236
|
/>
|
|
211
237
|
)
|
|
@@ -9,29 +9,26 @@ import styles from './PickerWheel.module.css'
|
|
|
9
9
|
|
|
10
10
|
export type { PickerWheelColumn }
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{ haptics: false },
|
|
28
|
-
)
|
|
29
|
-
const emit = defineEmits<{ /** The rows in the band while the wheel still turns. */ scrub: [value: number[]] }>()
|
|
12
|
+
const { columns, defaultValue, detail, haptics = false } = defineProps<{
|
|
13
|
+
/** Visible name of the whole wheel, read by screen readers as the group's name. */
|
|
14
|
+
label: string
|
|
15
|
+
/** The columns, left to right. */
|
|
16
|
+
columns: PickerWheelColumn[]
|
|
17
|
+
/** Starting rows when there is no v-model. Undefined starts on the first row of each. */
|
|
18
|
+
defaultValue?: number[]
|
|
19
|
+
/** Turns the rows into a large readout above the wheel. No readout when left out. */
|
|
20
|
+
formatValue?: (value: number[]) => string
|
|
21
|
+
/** A line under the label and readout, such as what the choice means. The detail slot replaces it. */
|
|
22
|
+
detail?: string
|
|
23
|
+
/** A short buzz on each row while it turns, on phones that can (Android). */
|
|
24
|
+
haptics?: boolean
|
|
25
|
+
}>()
|
|
26
|
+
const emit = defineEmits<{ /** Every column's row, once a column comes to rest on a new row. */ valueCommit: [value: number[]] }>()
|
|
30
27
|
const slots = useSlots()
|
|
31
28
|
|
|
32
|
-
/** The
|
|
29
|
+
/** The row of each column in the band, set each time a new row comes in while the wheel turns. Use v-model, or leave it out and the wheel keeps its own rows. */
|
|
33
30
|
const model = defineModel<number[]>()
|
|
34
|
-
const local = ref(
|
|
31
|
+
const local = ref(defaultValue ?? columns.map(() => 0))
|
|
35
32
|
const raw = computed({
|
|
36
33
|
get: () => model.value ?? local.value,
|
|
37
34
|
set: (next: number[]) => {
|
|
@@ -42,36 +39,40 @@ const raw = computed({
|
|
|
42
39
|
|
|
43
40
|
const labelId = useId()
|
|
44
41
|
const detailId = useId()
|
|
45
|
-
const value = computed(() =>
|
|
46
|
-
// The rows as last set, so two columns that settle at once both count.
|
|
47
|
-
let latest = value.value
|
|
48
|
-
watch(value, (v) => (latest = v), { flush: 'sync' })
|
|
49
|
-
const onChange = (i: number, row: number) => {
|
|
50
|
-
if (latest[i] === row) return
|
|
51
|
-
const next = latest.map((v, j) => (j === i ? row : v))
|
|
52
|
-
latest = next
|
|
53
|
-
raw.value = next
|
|
54
|
-
}
|
|
42
|
+
const value = computed(() => columns.map((c, i) => clamp(raw.value[i] ?? 0, 0, c.options.length - 1)))
|
|
55
43
|
const live = ref(value.value)
|
|
44
|
+
// The rows last told, so a row comes once whether it came while moving or at rest.
|
|
45
|
+
let told = value.value.join(',')
|
|
46
|
+
const tell = (rows: number[]) => {
|
|
47
|
+
if (rows.join(',') === told) return
|
|
48
|
+
told = rows.join(',')
|
|
49
|
+
raw.value = rows
|
|
50
|
+
}
|
|
56
51
|
const onShown = (i: number, row: number) => {
|
|
57
52
|
if (live.value[i] !== row) live.value = live.value.map((v, j) => (j === i ? row : v))
|
|
58
53
|
}
|
|
59
54
|
watch(
|
|
60
55
|
() => live.value.join(','),
|
|
61
|
-
() =>
|
|
56
|
+
() => tell(live.value),
|
|
62
57
|
)
|
|
63
|
-
const
|
|
58
|
+
const onCommit = (i: number, row: number) => {
|
|
59
|
+
const next = live.value.map((v, j) => (j === i ? row : v))
|
|
60
|
+
live.value = next
|
|
61
|
+
tell(next)
|
|
62
|
+
emit('valueCommit', next)
|
|
63
|
+
}
|
|
64
|
+
const hasDetail = computed(() => !!(detail || slots.detail))
|
|
64
65
|
</script>
|
|
65
66
|
|
|
66
67
|
<template>
|
|
67
|
-
<div :class="styles.root">
|
|
68
|
+
<div :class="styles.root" data-slot="picker-wheel">
|
|
68
69
|
<div :class="styles.head">
|
|
69
|
-
<span :id="labelId" :class="styles.label">{{ label }}</span>
|
|
70
|
-
<span v-if="formatValue" :class="styles.readout">{{ formatValue(live) }}</span>
|
|
71
|
-
<span v-if="hasDetail" :id="detailId" :class="styles.detail"><slot name="detail">{{ detail }}</slot></span>
|
|
70
|
+
<span :id="labelId" :class="styles.label" data-slot="field-label">{{ label }}</span>
|
|
71
|
+
<span v-if="formatValue" :class="styles.readout" data-slot="picker-wheel-value">{{ formatValue(live) }}</span>
|
|
72
|
+
<span v-if="hasDetail" :id="detailId" :class="styles.detail" data-slot="picker-wheel-detail"><slot name="detail">{{ detail }}</slot></span>
|
|
72
73
|
</div>
|
|
73
|
-
<div :class="styles.wheel" role="group" :aria-labelledby="labelId" :aria-describedby="hasDetail ? detailId : undefined">
|
|
74
|
-
<WheelColumn v-for="(c, i) in columns" :key="i" :column="c" :index="value[i]" :haptics="haptics" @
|
|
74
|
+
<div :class="styles.wheel" data-slot="picker-wheel-columns" role="group" :aria-labelledby="labelId" :aria-describedby="hasDetail ? detailId : undefined">
|
|
75
|
+
<WheelColumn v-for="(c, i) in columns" :key="i" :column="c" :index="value[i]" :haptics="haptics" @commit="onCommit(i, $event)" @shown="onShown(i, $event)" />
|
|
75
76
|
</div>
|
|
76
77
|
</div>
|
|
77
78
|
</template>
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, ref } from 'vue'
|
|
3
|
-
import { timeWheel } from '../../internal/motion/pickerWheel'
|
|
3
|
+
import { localeHourCycle, timeWheel } from '../../internal/motion/pickerWheel'
|
|
4
4
|
import PickerWheel from './PickerWheel.vue'
|
|
5
5
|
|
|
6
6
|
// PickerWheel set up for a time: hour, minute and, on a 12 hour clock, AM or PM (the Vue TimeWheel).
|
|
7
7
|
// Other props (detail, haptics) go to the PickerWheel.
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
const {
|
|
10
|
+
defaultValue = '09:00',
|
|
11
|
+
hourCycle,
|
|
12
|
+
step = 1,
|
|
13
|
+
strong = [0, 30],
|
|
14
|
+
} = defineProps<{
|
|
15
|
+
/** Visible name of the whole wheel, read by screen readers as the group's name. */
|
|
16
|
+
label: string
|
|
17
|
+
/** Starting time when there is no v-model. */
|
|
18
|
+
defaultValue?: string
|
|
19
|
+
/** 12 shows AM and PM; 24 shows hours 00 to 23. Defaults to what the browser's locale uses. */
|
|
20
|
+
hourCycle?: 12 | 24
|
|
21
|
+
/** Minutes between two rows, such as 5 or 15. */
|
|
22
|
+
step?: number
|
|
23
|
+
/** Minutes drawn stronger. Page Up and Page Down jump between them. */
|
|
24
|
+
strong?: number[]
|
|
25
|
+
}>()
|
|
26
|
+
const emit = defineEmits<{ /** The time, as "HH:mm", once the wheel comes to rest on a new one. */ valueCommit: [value: string] }>()
|
|
25
27
|
|
|
26
|
-
/** The time as "HH:mm" in 24 hours, set
|
|
28
|
+
/** The time in the band as "HH:mm" in 24 hours, set each time it changes while the wheel turns. Use v-model, or leave it out and the wheel keeps its own time. */
|
|
27
29
|
const model = defineModel<string>()
|
|
28
|
-
const local = ref(
|
|
30
|
+
const local = ref(defaultValue)
|
|
29
31
|
const value = computed({
|
|
30
32
|
get: () => model.value ?? local.value,
|
|
31
33
|
set: (next: string) => {
|
|
@@ -33,7 +35,7 @@ const value = computed({
|
|
|
33
35
|
model.value = next
|
|
34
36
|
},
|
|
35
37
|
})
|
|
36
|
-
const wheel = computed(() => timeWheel(
|
|
38
|
+
const wheel = computed(() => timeWheel(hourCycle ?? localeHourCycle(), step, strong))
|
|
37
39
|
</script>
|
|
38
40
|
|
|
39
41
|
<template>
|
|
@@ -43,7 +45,7 @@ const wheel = computed(() => timeWheel(props.hourCycle, props.minuteStep, props.
|
|
|
43
45
|
:model-value="wheel.toRows(value)"
|
|
44
46
|
:format-value="wheel.show"
|
|
45
47
|
@update:model-value="(rows) => rows && (value = wheel.toTime(rows))"
|
|
46
|
-
@
|
|
48
|
+
@value-commit="emit('valueCommit', wheel.toTime($event))"
|
|
47
49
|
>
|
|
48
50
|
<template v-for="(_, name) in $slots" #[name]><slot :name="name" /></template>
|
|
49
51
|
</PickerWheel>
|
|
@@ -9,7 +9,7 @@ import styles from './PickerWheel.module.css'
|
|
|
9
9
|
// One column of the Vue PickerWheel: its rows are the marks. A drag follows the hand; a let-go lands on a row.
|
|
10
10
|
|
|
11
11
|
const props = defineProps<{ column: WheelColumn; index: number; haptics: boolean }>()
|
|
12
|
-
const emit = defineEmits<{
|
|
12
|
+
const emit = defineEmits<{ commit: [index: number]; shown: [index: number] }>()
|
|
13
13
|
|
|
14
14
|
const n = computed(() => props.column.options.length)
|
|
15
15
|
const strong = computed(() => new Set(props.column.strong ?? []))
|
|
@@ -19,9 +19,10 @@ const wheel = wheelSteps()
|
|
|
19
19
|
// The keys, tap and wheel of one column (motion/pickerWheel.ts) on the shared scrubber.
|
|
20
20
|
const sc = useScrub(() => ({
|
|
21
21
|
...columnScrub(props.column, props.index, st, wheel),
|
|
22
|
-
onSettle: (to: number) => {
|
|
22
|
+
onSettle: (to: number, from: number) => {
|
|
23
23
|
st.rested = to
|
|
24
|
-
|
|
24
|
+
// A loop turned all the way round rests on the row it left: no news.
|
|
25
|
+
if (wrap(to, n.value) !== wrap(Math.round(from), n.value)) emit('commit', wrap(to, n.value))
|
|
25
26
|
},
|
|
26
27
|
haptics: props.haptics,
|
|
27
28
|
}))
|
|
@@ -51,6 +52,7 @@ const rows = computed(() => drumRows(sc.at.value, n.value, !!props.column.loop))
|
|
|
51
52
|
<div
|
|
52
53
|
ref="scrubEl"
|
|
53
54
|
:class="styles.column"
|
|
55
|
+
data-slot="picker-wheel-column"
|
|
54
56
|
role="spinbutton"
|
|
55
57
|
tabindex="0"
|
|
56
58
|
:aria-label="column.label"
|
|
@@ -62,9 +64,9 @@ const rows = computed(() => drumRows(sc.at.value, n.value, !!props.column.loop))
|
|
|
62
64
|
:data-moving="sc.moving.value || undefined"
|
|
63
65
|
v-on="sc.handlers"
|
|
64
66
|
>
|
|
65
|
-
<span :class="styles.band" :style="{ '--grip': grip.toFixed(3) }" aria-hidden="true" />
|
|
67
|
+
<span :class="styles.band" data-slot="picker-wheel-band" :style="{ '--grip': grip.toFixed(3) }" aria-hidden="true" />
|
|
66
68
|
<div :class="styles.drum" aria-hidden="true">
|
|
67
|
-
<span v-for="r in rows" :key="r.k" :class="styles.row" :data-strong="strong.has(r.i) || undefined" :style="{ '--d': r.d.toFixed(3), color: ink(pull(r.d, 1)) }">{{ column.options[r.i] }}</span>
|
|
69
|
+
<span v-for="r in rows" :key="r.k" :class="styles.row" data-slot="picker-wheel-row" :data-strong="strong.has(r.i) || undefined" :style="{ '--d': r.d.toFixed(3), color: ink(pull(r.d, 1)) }">{{ column.options[r.i] }}</span>
|
|
68
70
|
</div>
|
|
69
71
|
</div>
|
|
70
72
|
</template>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@layer gooee.components {
|
|
1
2
|
.panel {
|
|
2
3
|
--oy: calc(var(--gooee-shift-md) * -1);
|
|
3
4
|
z-index: var(--gooee-z-popover);
|
|
@@ -12,13 +13,13 @@
|
|
|
12
13
|
box-shadow: var(--gooee-shadow-3);
|
|
13
14
|
outline: none;
|
|
14
15
|
transform-origin: top left;
|
|
15
|
-
animation: popIn var(--gooee-motion-slow) var(--gooee-ease-
|
|
16
|
+
animation: popIn var(--gooee-motion-slow) var(--gooee-ease-morph);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
.panel[data-side="top"] { --oy: var(--gooee-shift-md); transform-origin: bottom left; }
|
|
19
20
|
|
|
20
21
|
.panel[data-state="closed"] {
|
|
21
|
-
animation: popOut var(--gooee-motion-fast) var(--gooee-ease-
|
|
22
|
+
animation: popOut var(--gooee-motion-fast) var(--gooee-ease-morph) forwards;
|
|
22
23
|
pointer-events: none;
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
color: var(--gooee-color-fg-muted);
|
|
60
61
|
font-size: var(--gooee-icon-md);
|
|
61
62
|
cursor: pointer;
|
|
62
|
-
transition: background-color var(--gooee-motion-fast) var(--gooee-ease-
|
|
63
|
+
transition: background-color var(--gooee-motion-fast) var(--gooee-ease-morph), transform var(--gooee-motion-slow) var(--gooee-ease-morph);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
/* Looks 32px, keeps a 44px touch area. */
|
|
@@ -84,3 +85,4 @@
|
|
|
84
85
|
@keyframes popOut {
|
|
85
86
|
to { opacity: 0; transform: scale(var(--gooee-pop-scale)); }
|
|
86
87
|
}
|
|
88
|
+
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from 'react'
|
|
13
13
|
import { cx } from '../../internal/cx'
|
|
14
14
|
import { useFocusTrap } from '../../internal/focus'
|
|
15
|
-
import { XIcon } from '../../
|
|
15
|
+
import { XIcon } from '../../icons/icons'
|
|
16
16
|
import { useDismiss } from '../../internal/layers'
|
|
17
17
|
import { useLiquid } from '../../internal/liquid'
|
|
18
18
|
import { mergeRefs } from '../../internal/mergeRefs'
|
|
@@ -44,12 +44,19 @@ export type PopoverProps = {
|
|
|
44
44
|
side?: Side
|
|
45
45
|
/** How the panel lines up with the trigger along that side. */
|
|
46
46
|
align?: Align
|
|
47
|
-
/**
|
|
48
|
-
|
|
47
|
+
/** Text for the popover's controls, so you can translate it. Missing keys use the English defaults. */
|
|
48
|
+
labels?: Partial<PopoverLabels>
|
|
49
49
|
/** Extra class for the panel. */
|
|
50
50
|
className?: string
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
export type PopoverLabels = {
|
|
54
|
+
/** Screen reader name for the close button. */
|
|
55
|
+
close: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const defaultLabels: PopoverLabels = { close: 'Close' }
|
|
59
|
+
|
|
53
60
|
export function Popover({
|
|
54
61
|
trigger,
|
|
55
62
|
title,
|
|
@@ -59,9 +66,10 @@ export function Popover({
|
|
|
59
66
|
onOpenChange,
|
|
60
67
|
side = 'bottom',
|
|
61
68
|
align = 'start',
|
|
62
|
-
|
|
69
|
+
labels: labelsProp,
|
|
63
70
|
className,
|
|
64
71
|
}: PopoverProps) {
|
|
72
|
+
const labels = { ...defaultLabels, ...labelsProp }
|
|
65
73
|
const id = useId()
|
|
66
74
|
const [open, setOpen] = useControllable(openProp, defaultOpen, onOpenChange)
|
|
67
75
|
const anchorRef = useRef<HTMLElement>(null)
|
|
@@ -98,17 +106,18 @@ export function Popover({
|
|
|
98
106
|
aria-labelledby={`${id}-title`}
|
|
99
107
|
tabIndex={-1}
|
|
100
108
|
className={cx(styles.panel, className)}
|
|
109
|
+
data-slot="popover-content"
|
|
101
110
|
data-state={state}
|
|
102
111
|
data-side={floating.side}
|
|
103
112
|
style={floating.style}
|
|
104
113
|
>
|
|
105
|
-
<div className={styles.head}>
|
|
106
|
-
<h2 id={`${id}-title`} className={styles.title}>{title}</h2>
|
|
107
|
-
<button type="button" className={styles.close} aria-label={
|
|
114
|
+
<div className={styles.head} data-slot="popover-header">
|
|
115
|
+
<h2 id={`${id}-title`} className={styles.title} data-slot="popover-title">{title}</h2>
|
|
116
|
+
<button type="button" className={styles.close} data-slot="popover-close" aria-label={labels.close} data-skip-initial-focus onClick={() => setOpen(false)}>
|
|
108
117
|
<XIcon />
|
|
109
118
|
</button>
|
|
110
119
|
</div>
|
|
111
|
-
<div className={styles.body}>{children}</div>
|
|
120
|
+
<div className={styles.body} data-slot="popover-body">{children}</div>
|
|
112
121
|
</div>
|
|
113
122
|
</Portal>
|
|
114
123
|
)}
|