@passui/react 0.1.44 → 0.1.46
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 +57 -46
- package/dist/types/src/components/accordion/accordion.d.ts +1 -1
- package/dist/types/src/components/breadcrumb/breadcrumb.d.ts +1 -1
- package/dist/types/src/components/inline-disclosure/inline-disclosure.d.ts +1 -1
- package/dist/types/src/components/popover/anchored-surface.d.ts +5 -1
- package/dist/types/src/components/popover/index.d.ts +41 -0
- package/dist/types/src/components/popover/popover-content.d.ts +32 -0
- package/dist/types/src/components/popover/popover-root.d.ts +22 -0
- package/dist/types/src/components/popover/popover-trigger.d.ts +23 -0
- package/dist/types/src/components/stepper/rolling-digit.d.ts +1 -1
- package/dist/types/src/components/table/table.d.ts +1 -1
- package/dist/types/src/components/view-controller/view-controller.d.ts +2 -2
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/machines/popover.machine.d.ts +30 -0
- package/package.json +307 -307
- package/src/appearance/index.ts +2 -2
- package/src/appearance/platform.tsx +76 -60
- package/src/appearance/theme.tsx +409 -377
- package/src/components/accordion/accordion.tsx +58 -49
- package/src/components/ambient/ambient.tsx +25 -25
- package/src/components/ambient/index.ts +1 -1
- package/src/components/aspect-ratio/aspect-ratio.tsx +21 -16
- package/src/components/breadcrumb/breadcrumb.tsx +63 -57
- package/src/components/button/button-styles.ts +39 -32
- package/src/components/button/button.tsx +91 -84
- package/src/components/button/icon-button.tsx +27 -25
- package/src/components/button/pending-spinner.tsx +8 -8
- package/src/components/button/use-pending-indicator.ts +11 -11
- package/src/components/chip/chip.tsx +35 -30
- package/src/components/code-block/code-block.tsx +40 -39
- package/src/components/combo-box/combo-box.tsx +5 -5
- package/src/components/command/command.tsx +124 -94
- package/src/components/compact-date-picker/calendar-month.ts +75 -53
- package/src/components/compact-date-picker/compact-date-picker.tsx +308 -289
- package/src/components/compact-time-picker/compact-time-picker.tsx +288 -281
- package/src/components/compact-time-picker/time-value.ts +32 -29
- package/src/components/content-unavailable-view/content-unavailable-view.tsx +64 -48
- package/src/components/content-view/content-view.tsx +168 -159
- package/src/components/content-view/index.ts +1 -1
- package/src/components/context-menu/conceal-menu-source.ts +25 -25
- package/src/components/context-menu/context-menu-host.tsx +439 -398
- package/src/components/context-menu/context-menu-store.ts +125 -123
- package/src/components/context-menu/menu-navigation.ts +25 -18
- package/src/components/context-menu/menu-position.ts +33 -29
- package/src/components/context-menu/menu-reveal.ts +32 -32
- package/src/components/context-menu/use-context-menu.ts +63 -56
- package/src/components/conversation/conversation.tsx +265 -263
- package/src/components/conversation/index.ts +1 -1
- package/src/components/date-picker/date-picker.tsx +95 -94
- package/src/components/date-picker/date-value.ts +20 -10
- package/src/components/dialog/dialog-host.tsx +105 -103
- package/src/components/dialog/dialog-store.ts +37 -36
- package/src/components/dialog/dialog.tsx +192 -179
- package/src/components/dialog/index.ts +1 -1
- package/src/components/disclosure-group/disclosure-group.tsx +93 -86
- package/src/components/divider/divider.tsx +24 -22
- package/src/components/inline-disclosure/inline-disclosure.tsx +40 -36
- package/src/components/keyboard-shortcut/keyboard-shortcut.tsx +23 -19
- package/src/components/labeled-content/labeled-content.tsx +68 -68
- package/src/components/locale-switcher/index.ts +1 -1
- package/src/components/locale-switcher/locale-switcher.tsx +279 -251
- package/src/components/menu/menu.tsx +75 -58
- package/src/components/morph/index.ts +2 -2
- package/src/components/morph/morph.tsx +227 -201
- package/src/components/morph/use-morph-disclosure.ts +19 -19
- package/src/components/one-time-code/one-time-code.tsx +216 -200
- package/src/components/picker/picker-trigger.ts +16 -13
- package/src/components/picker/picker.tsx +371 -345
- package/src/components/popover/anchored-surface.tsx +253 -229
- package/src/components/popover/index.ts +50 -0
- package/src/components/popover/popover-content.tsx +334 -0
- package/src/components/popover/popover-fit.ts +58 -53
- package/src/components/popover/popover-root.tsx +97 -0
- package/src/components/popover/popover-trigger.tsx +71 -0
- package/src/components/profile-image/profile-image.tsx +80 -64
- package/src/components/progress-view/progress-view.tsx +61 -59
- package/src/components/progress-view/use-liquid-progress.ts +38 -38
- package/src/components/radio-group/radio-group.tsx +71 -68
- package/src/components/search-field/expanding-search-field.tsx +191 -177
- package/src/components/search-field/search-field.tsx +59 -50
- package/src/components/search-list/search-list.tsx +246 -236
- package/src/components/section/section.tsx +58 -58
- package/src/components/secure-field/secure-field.tsx +3 -3
- package/src/components/segmented-control/segmented-control.tsx +136 -136
- package/src/components/sheet/modal-environment.ts +71 -64
- package/src/components/sheet/sheet-portal.tsx +58 -53
- package/src/components/sheet/sheet.tsx +146 -141
- package/src/components/sheet/use-sheet-focus.ts +97 -82
- package/src/components/sidebar/sidebar.tsx +78 -78
- package/src/components/skeleton/skeleton.tsx +30 -21
- package/src/components/slider/slider.tsx +113 -104
- package/src/components/slosh-slider/liquid-step.ts +32 -31
- package/src/components/slosh-slider/slosh-slider.tsx +265 -228
- package/src/components/stat-tile/index.ts +1 -1
- package/src/components/stat-tile/stat-tile.tsx +79 -68
- package/src/components/status-indicator/status-indicator.tsx +40 -37
- package/src/components/stepper/rolling-digit.tsx +82 -68
- package/src/components/stepper/stepper.tsx +122 -113
- package/src/components/swatch-picker/swatch-picker.tsx +120 -120
- package/src/components/tab-bar/tab-bar.tsx +149 -148
- package/src/components/tab-view/tab-view.tsx +140 -137
- package/src/components/table/table.tsx +117 -98
- package/src/components/text-editor/text-editor.tsx +34 -29
- package/src/components/text-field/text-field.tsx +182 -180
- package/src/components/toast/toast-store.ts +127 -115
- package/src/components/toast/toaster.tsx +361 -347
- package/src/components/toggle/toggle.tsx +297 -282
- package/src/components/tooltip/tooltip-host.tsx +157 -150
- package/src/components/view-controller/index.ts +1 -1
- package/src/components/view-controller/view-controller.tsx +64 -53
- package/src/components/wake-slider/wake-slider.tsx +220 -205
- package/src/hooks/scroll/minimize-decision.ts +11 -7
- package/src/hooks/use-anchored-disclosure.ts +19 -19
- package/src/hooks/use-anchored-placement.ts +29 -25
- package/src/hooks/use-dismiss.ts +33 -29
- package/src/hooks/use-floating-dismiss.ts +24 -22
- package/src/hooks/use-media-query.ts +67 -60
- package/src/hooks/use-minimize-on-scroll.ts +69 -60
- package/src/hooks/use-visual-viewport.ts +63 -63
- package/src/hooks/viewport/types.ts +16 -16
- package/src/hooks/viewport/viewport-metrics.ts +16 -10
- package/src/icons/icons.tsx +440 -328
- package/src/index.ts +91 -91
- package/src/lib/anchored-placement.ts +70 -65
- package/src/lib/class-names.ts +14 -13
- package/src/lib/clipboard.ts +8 -7
- package/src/lib/date.ts +61 -60
- package/src/lib/floating-layers.ts +39 -24
- package/src/lib/haptics.ts +10 -10
- package/src/lib/language.ts +9 -9
- package/src/lib/range-value.ts +27 -21
- package/src/lib/screen-edges.ts +33 -30
- package/src/lib/shapes.ts +38 -34
- package/src/machines/popover.machine.ts +51 -0
- package/src/motion/transitions.ts +46 -43
- package/src/styles/code-block.css +69 -43
- package/src/styles/motion-controls.css +393 -191
- package/src/tokens.ts +1 -1
- package/dist/types/src/components/popover/popover.d.ts +0 -21
- package/src/components/popover/popover.tsx +0 -322
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { useAnchoredDisclosure } from "../../hooks/use-anchored-disclosure"
|
|
2
|
-
import { AnchoredSurface } from "../popover/anchored-surface"
|
|
3
|
-
import { type KeyboardEvent, useEffect, useId, useRef } from "react"
|
|
4
|
-
import { createPortal } from "react-dom"
|
|
5
|
-
import { ClockIcon } from "../../icons/icons"
|
|
6
|
-
import { cn } from "../../lib/class-names"
|
|
7
|
-
import { haptic } from "../../lib/haptics"
|
|
8
|
-
import { pickerTriggerStyle, type PickerSize } from "../picker/picker-trigger"
|
|
1
|
+
import { useAnchoredDisclosure } from "../../hooks/use-anchored-disclosure";
|
|
2
|
+
import { AnchoredSurface } from "../popover/anchored-surface";
|
|
3
|
+
import { type KeyboardEvent, useEffect, useId, useRef } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { ClockIcon } from "../../icons/icons";
|
|
6
|
+
import { cn } from "../../lib/class-names";
|
|
7
|
+
import { haptic } from "../../lib/haptics";
|
|
8
|
+
import { pickerTriggerStyle, type PickerSize } from "../picker/picker-trigger";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from "./time-value"
|
|
10
|
+
formatTime,
|
|
11
|
+
fromTwelveHours,
|
|
12
|
+
minuteChoices,
|
|
13
|
+
parseTime,
|
|
14
|
+
type TimeOfDay,
|
|
15
|
+
toTwelveHours,
|
|
16
|
+
usesTwelveHours,
|
|
17
|
+
} from "./time-value";
|
|
18
18
|
|
|
19
19
|
export interface CompactTimePickerProps {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
/** `HH:MM` on a 24 hour clock, or "" when no time is chosen. */
|
|
21
|
+
value: string;
|
|
22
|
+
onChange: (value: string) => void;
|
|
23
|
+
/** Names the button and the panel for assistive technology. */
|
|
24
|
+
label: string;
|
|
25
|
+
locale: string;
|
|
26
|
+
/** Minutes offered, in steps; an exact time already chosen is kept. */
|
|
27
|
+
minuteStep?: number;
|
|
28
|
+
/** Shown when no time is chosen. */
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
labels: { hour: string; minute: string; period: string };
|
|
31
|
+
className?: string;
|
|
32
|
+
/** Prevents opening the time panel. @default false */
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/** Trigger button density; matches Picker's sm | md | lg. @default "md" */
|
|
35
|
+
size?: PickerSize;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -41,274 +41,281 @@ export interface CompactTimePickerProps {
|
|
|
41
41
|
* reads (12 hours with AM and PM, or 24).
|
|
42
42
|
*/
|
|
43
43
|
export function CompactTimePicker({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
value,
|
|
45
|
+
onChange,
|
|
46
|
+
label,
|
|
47
|
+
locale,
|
|
48
|
+
minuteStep = 5,
|
|
49
|
+
placeholder,
|
|
50
|
+
labels,
|
|
51
|
+
className,
|
|
52
|
+
disabled = false,
|
|
53
|
+
size = "md",
|
|
54
54
|
}: CompactTimePickerProps) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
const panel = useAnchoredDisclosure(disabled);
|
|
56
|
+
const { open } = panel;
|
|
57
|
+
const trigger = useRef<HTMLButtonElement>(null);
|
|
58
|
+
const panelId = useId();
|
|
59
|
+
const chosen = parseTime(value);
|
|
60
|
+
const shown = chosen
|
|
61
|
+
? new Intl.DateTimeFormat(locale, {
|
|
62
|
+
hour: "numeric",
|
|
63
|
+
minute: "2-digit",
|
|
64
|
+
timeZone: "UTC",
|
|
65
|
+
}).format(new Date(Date.UTC(2000, 0, 1, chosen.hour, chosen.minute)))
|
|
66
|
+
: (placeholder ?? "");
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<button
|
|
71
|
+
ref={trigger}
|
|
72
|
+
type="button"
|
|
73
|
+
aria-label={chosen ? `${label}, ${shown}` : label}
|
|
74
|
+
aria-haspopup="dialog"
|
|
75
|
+
aria-expanded={open && !disabled}
|
|
76
|
+
aria-controls={open && !disabled ? panelId : undefined}
|
|
77
|
+
disabled={disabled}
|
|
78
|
+
onClick={() => panel.toggle()}
|
|
79
|
+
className={pickerTriggerStyle(className, size)}
|
|
80
|
+
>
|
|
81
|
+
<span
|
|
82
|
+
className={cn(
|
|
83
|
+
"min-w-0 grow truncate tabular-nums",
|
|
84
|
+
!chosen && "text-label-tertiary",
|
|
85
|
+
)}
|
|
86
|
+
>
|
|
87
|
+
{shown}
|
|
88
|
+
</span>
|
|
89
|
+
<ClockIcon size={16} className="text-label-tertiary shrink-0" />
|
|
90
|
+
</button>
|
|
91
|
+
{typeof document !== "undefined" &&
|
|
92
|
+
createPortal(
|
|
93
|
+
panel.mounted && trigger.current ? (
|
|
94
|
+
<TimeColumns
|
|
95
|
+
open={open}
|
|
96
|
+
onExited={panel.onExited}
|
|
97
|
+
id={panelId}
|
|
98
|
+
anchor={trigger.current}
|
|
99
|
+
label={label}
|
|
100
|
+
locale={locale}
|
|
101
|
+
time={
|
|
102
|
+
chosen ?? {
|
|
103
|
+
hour: 9,
|
|
104
|
+
minute: 0,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
minuteStep={minuteStep}
|
|
108
|
+
labels={labels}
|
|
109
|
+
onChange={(next) => {
|
|
110
|
+
haptic("selection");
|
|
111
|
+
onChange(formatTime(next));
|
|
112
|
+
}}
|
|
113
|
+
onClose={(restoreFocus) => {
|
|
114
|
+
panel.close();
|
|
115
|
+
if (restoreFocus)
|
|
116
|
+
trigger.current?.focus({ preventScroll: true });
|
|
117
|
+
}}
|
|
118
|
+
/>
|
|
119
|
+
) : null,
|
|
120
|
+
document.body,
|
|
121
|
+
)}
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
interface ColumnItem {
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
key: number;
|
|
128
|
+
text: string;
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
function TimeColumns({
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
open,
|
|
133
|
+
onExited,
|
|
134
|
+
id,
|
|
135
|
+
anchor,
|
|
136
|
+
label,
|
|
137
|
+
locale,
|
|
138
|
+
time,
|
|
139
|
+
minuteStep,
|
|
140
|
+
labels,
|
|
141
|
+
onChange,
|
|
142
|
+
onClose,
|
|
142
143
|
}: {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
144
|
+
open: boolean;
|
|
145
|
+
onExited: () => void;
|
|
146
|
+
id: string;
|
|
147
|
+
anchor: HTMLElement;
|
|
148
|
+
label: string;
|
|
149
|
+
locale: string;
|
|
150
|
+
time: TimeOfDay;
|
|
151
|
+
minuteStep: number;
|
|
152
|
+
labels: CompactTimePickerProps["labels"];
|
|
153
|
+
onChange: (time: TimeOfDay) => void;
|
|
154
|
+
onClose: (restoreFocus: boolean) => void;
|
|
154
155
|
}) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
const root = useRef<HTMLDivElement>(null);
|
|
157
|
+
const twelve = usesTwelveHours(locale);
|
|
158
|
+
const number = new Intl.NumberFormat(locale, {
|
|
159
|
+
minimumIntegerDigits: 2,
|
|
160
|
+
});
|
|
161
|
+
const plain = new Intl.NumberFormat(locale);
|
|
162
|
+
const clock = toTwelveHours(time.hour);
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
164
|
+
const hours: ColumnItem[] = twelve
|
|
165
|
+
? [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((hour) => ({
|
|
166
|
+
key: hour,
|
|
167
|
+
text: plain.format(hour),
|
|
168
|
+
}))
|
|
169
|
+
: Array.from({ length: 24 }, (_, hour) => ({
|
|
170
|
+
key: hour,
|
|
171
|
+
text: number.format(hour),
|
|
172
|
+
}));
|
|
173
|
+
const minutes = minuteChoices(minuteStep, time.minute).map((minute) => ({
|
|
174
|
+
key: minute,
|
|
175
|
+
text: number.format(minute),
|
|
176
|
+
}));
|
|
177
|
+
// The locale's own words for morning and afternoon.
|
|
178
|
+
const periodName = (pm: boolean) =>
|
|
179
|
+
new Intl.DateTimeFormat(locale, {
|
|
180
|
+
hour: "numeric",
|
|
181
|
+
hour12: true,
|
|
182
|
+
timeZone: "UTC",
|
|
183
|
+
})
|
|
184
|
+
.formatToParts(new Date(Date.UTC(2000, 0, 1, pm ? 13 : 1)))
|
|
185
|
+
.find((part) => part.type === "dayPeriod")?.value ?? (pm ? "PM" : "AM");
|
|
186
|
+
const periods = [
|
|
187
|
+
{ key: 0, text: periodName(false) },
|
|
188
|
+
{ key: 1, text: periodName(true) },
|
|
189
|
+
];
|
|
189
190
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
191
|
+
return (
|
|
192
|
+
<AnchoredSurface
|
|
193
|
+
open={open}
|
|
194
|
+
onExited={onExited}
|
|
195
|
+
ref={root}
|
|
196
|
+
anchor={anchor}
|
|
197
|
+
width={twelve ? 240 : 180}
|
|
198
|
+
needed={280}
|
|
199
|
+
onClose={onClose}
|
|
200
|
+
id={id}
|
|
201
|
+
role="dialog"
|
|
202
|
+
aria-label={label}
|
|
203
|
+
contentClassName="flex-row gap-1 overflow-hidden p-2"
|
|
204
|
+
onKeyDown={(event) => {
|
|
205
|
+
if (event.key !== "Escape") return;
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
event.stopPropagation();
|
|
208
|
+
onClose(true);
|
|
209
|
+
}}
|
|
210
|
+
>
|
|
211
|
+
<Column
|
|
212
|
+
label={labels.hour}
|
|
213
|
+
items={hours}
|
|
214
|
+
selected={twelve ? clock.hour : time.hour}
|
|
215
|
+
autoFocus
|
|
216
|
+
onSelect={(hour) =>
|
|
217
|
+
onChange({
|
|
218
|
+
...time,
|
|
219
|
+
hour: twelve ? fromTwelveHours(hour, clock.pm) : hour,
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
/>
|
|
223
|
+
<Column
|
|
224
|
+
label={labels.minute}
|
|
225
|
+
items={minutes}
|
|
226
|
+
selected={time.minute}
|
|
227
|
+
onSelect={(minute) => onChange({ ...time, minute })}
|
|
228
|
+
/>
|
|
229
|
+
{twelve && (
|
|
230
|
+
<Column
|
|
231
|
+
label={labels.period}
|
|
232
|
+
items={periods}
|
|
233
|
+
selected={clock.pm ? 1 : 0}
|
|
234
|
+
onSelect={(period) =>
|
|
235
|
+
onChange({
|
|
236
|
+
...time,
|
|
237
|
+
hour: fromTwelveHours(clock.hour, period === 1),
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
/>
|
|
241
|
+
)}
|
|
242
|
+
</AnchoredSurface>
|
|
243
|
+
);
|
|
243
244
|
}
|
|
244
245
|
|
|
245
246
|
/** One scrolling column of choices; Up and Down move through it. */
|
|
246
247
|
function Column({
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
248
|
+
label,
|
|
249
|
+
items,
|
|
250
|
+
selected,
|
|
251
|
+
autoFocus = false,
|
|
252
|
+
onSelect,
|
|
252
253
|
}: {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
254
|
+
label: string;
|
|
255
|
+
items: ColumnItem[];
|
|
256
|
+
selected: number;
|
|
257
|
+
autoFocus?: boolean;
|
|
258
|
+
onSelect: (key: number) => void;
|
|
258
259
|
}) {
|
|
259
|
-
|
|
260
|
+
const list = useRef<HTMLDivElement>(null);
|
|
260
261
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
// The chosen item starts in the middle of the column, then follows changes.
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
const element = list.current?.querySelector<HTMLElement>(
|
|
265
|
+
`[data-key="${selected}"]`,
|
|
266
|
+
);
|
|
267
|
+
element?.scrollIntoView({ block: "center" });
|
|
268
|
+
if (autoFocus && list.current?.contains(document.activeElement) === false)
|
|
269
|
+
element?.focus();
|
|
270
|
+
}, [selected, autoFocus]);
|
|
267
271
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
272
|
+
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
273
|
+
const step =
|
|
274
|
+
event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0;
|
|
275
|
+
if (!step) return;
|
|
276
|
+
event.preventDefault();
|
|
277
|
+
const index = items.findIndex((item) => item.key === selected);
|
|
278
|
+
const next = items[(index + step + items.length) % items.length];
|
|
279
|
+
if (!next) return;
|
|
280
|
+
onSelect(next.key);
|
|
281
|
+
requestAnimationFrame(() =>
|
|
282
|
+
list.current
|
|
283
|
+
?.querySelector<HTMLElement>(`[data-key="${next.key}"]`)
|
|
284
|
+
?.focus(),
|
|
285
|
+
);
|
|
286
|
+
};
|
|
280
287
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
288
|
+
return (
|
|
289
|
+
<div
|
|
290
|
+
ref={list}
|
|
291
|
+
role="listbox"
|
|
292
|
+
aria-label={label}
|
|
293
|
+
onKeyDown={onKeyDown}
|
|
294
|
+
className="flex max-h-56 flex-1 snap-y snap-mandatory [scrollbar-width:none] flex-col overflow-y-auto overscroll-contain py-[5.25rem]"
|
|
295
|
+
>
|
|
296
|
+
{items.map((item) => {
|
|
297
|
+
const isSelected = item.key === selected;
|
|
298
|
+
return (
|
|
299
|
+
<button
|
|
300
|
+
key={item.key}
|
|
301
|
+
type="button"
|
|
302
|
+
role="option"
|
|
303
|
+
data-key={item.key}
|
|
304
|
+
aria-selected={isSelected}
|
|
305
|
+
tabIndex={isSelected ? 0 : -1}
|
|
306
|
+
onClick={() => onSelect(item.key)}
|
|
307
|
+
className={cn(
|
|
308
|
+
"text-title3 flex h-11 shrink-0 snap-center items-center justify-center rounded-xl tabular-nums transition-colors",
|
|
309
|
+
"focus-visible:ring-accent/70 focus-visible:ring-2 focus-visible:outline-none",
|
|
310
|
+
isSelected
|
|
311
|
+
? "bg-fill text-label font-semibold"
|
|
312
|
+
: "text-label-secondary hover:bg-fill/60",
|
|
313
|
+
)}
|
|
314
|
+
>
|
|
315
|
+
{item.text}
|
|
316
|
+
</button>
|
|
317
|
+
);
|
|
318
|
+
})}
|
|
319
|
+
</div>
|
|
320
|
+
);
|
|
314
321
|
}
|