@mrpelz/uikit-ish 7.8.0 → 7.9.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/dist/components/accordion/main.d.ts +12 -0
- package/dist/components/accordion/main.d.ts.map +1 -0
- package/dist/components/accordion/main.js +20 -0
- package/dist/components/accordion/main.js.map +1 -0
- package/dist/components/accordion/style.css +23 -0
- package/dist/components/action-sheet/main.d.ts +22 -15
- package/dist/components/action-sheet/main.d.ts.map +1 -1
- package/dist/components/action-sheet/main.js +86 -16
- package/dist/components/action-sheet/main.js.map +1 -1
- package/dist/components/action-sheet/props.d.ts +17 -5
- package/dist/components/action-sheet/props.d.ts.map +1 -1
- package/dist/components/action-sheet/style.css +15 -0
- package/dist/components/activity-view/main.d.ts +14 -3
- package/dist/components/activity-view/main.d.ts.map +1 -1
- package/dist/components/activity-view/main.js +19 -4
- package/dist/components/activity-view/main.js.map +1 -1
- package/dist/components/activity-view/props.d.ts +2 -10
- package/dist/components/activity-view/props.d.ts.map +1 -1
- package/dist/components/activity-view/style.css +8 -46
- package/dist/components/alert/main.d.ts +6 -4
- package/dist/components/alert/main.d.ts.map +1 -1
- package/dist/components/alert/main.js +20 -4
- package/dist/components/alert/main.js.map +1 -1
- package/dist/components/alert/props.d.ts +12 -1
- package/dist/components/alert/props.d.ts.map +1 -1
- package/dist/components/alert/style.css +13 -27
- package/dist/components/avatar/main.d.ts +5 -3
- package/dist/components/avatar/main.d.ts.map +1 -1
- package/dist/components/avatar/main.js +3 -0
- package/dist/components/avatar/main.js.map +1 -1
- package/dist/components/avatar/props.d.ts +4 -0
- package/dist/components/avatar/props.d.ts.map +1 -1
- package/dist/components/avatar/style.css +0 -6
- package/dist/components/badge/main.d.ts +2 -2
- package/dist/components/badge/main.d.ts.map +1 -1
- package/dist/components/badge/main.js +5 -5
- package/dist/components/badge/main.js.map +1 -1
- package/dist/components/badge/props.d.ts +4 -3
- package/dist/components/badge/props.d.ts.map +1 -1
- package/dist/components/badge/style.css +3 -2
- package/dist/components/button/main.d.ts.map +1 -1
- package/dist/components/button/main.js +6 -6
- package/dist/components/button/main.js.map +1 -1
- package/dist/components/button/style.css +11 -27
- package/dist/components/checkbox/style.css +2 -5
- package/dist/components/collapsible/main.d.ts +9 -0
- package/dist/components/collapsible/main.d.ts.map +1 -0
- package/dist/components/collapsible/main.js +19 -0
- package/dist/components/collapsible/main.js.map +1 -0
- package/dist/components/collapsible/style.css +23 -0
- package/dist/components/color-picker/main.d.ts +1 -1
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +40 -33
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/props.d.ts +21 -7
- package/dist/components/color-picker/props.d.ts.map +1 -1
- package/dist/components/color-picker/style.css +9 -27
- package/dist/components/contextual-menu/main.d.ts +11 -7
- package/dist/components/contextual-menu/main.d.ts.map +1 -1
- package/dist/components/contextual-menu/main.js +99 -47
- package/dist/components/contextual-menu/main.js.map +1 -1
- package/dist/components/contextual-menu/props.d.ts +17 -7
- package/dist/components/contextual-menu/props.d.ts.map +1 -1
- package/dist/components/contextual-menu/style.css +11 -8
- package/dist/components/date-picker/handle.d.ts +41 -0
- package/dist/components/date-picker/handle.d.ts.map +1 -0
- package/dist/components/date-picker/handle.js +47 -0
- package/dist/components/date-picker/handle.js.map +1 -0
- package/dist/components/date-picker/main.d.ts +31 -49
- package/dist/components/date-picker/main.d.ts.map +1 -1
- package/dist/components/date-picker/main.js +300 -139
- package/dist/components/date-picker/main.js.map +1 -1
- package/dist/components/date-picker/pager.d.ts +24 -0
- package/dist/components/date-picker/pager.d.ts.map +1 -0
- package/dist/components/date-picker/pager.js +307 -0
- package/dist/components/date-picker/pager.js.map +1 -0
- package/dist/components/date-picker/props.d.ts +93 -22
- package/dist/components/date-picker/props.d.ts.map +1 -1
- package/dist/components/date-picker/style.css +59 -71
- package/dist/components/drawer/main.d.ts +31 -0
- package/dist/components/drawer/main.d.ts.map +1 -0
- package/dist/components/drawer/main.js +74 -0
- package/dist/components/drawer/main.js.map +1 -0
- package/dist/components/drawer/props.d.ts +39 -0
- package/dist/components/drawer/props.d.ts.map +1 -0
- package/dist/components/drawer/props.js +2 -0
- package/dist/components/drawer/props.js.map +1 -0
- package/dist/components/drawer/style.css +135 -0
- package/dist/components/edit-menu/main.d.ts +7 -7
- package/dist/components/edit-menu/main.d.ts.map +1 -1
- package/dist/components/edit-menu/main.js +31 -23
- package/dist/components/edit-menu/main.js.map +1 -1
- package/dist/components/edit-menu/props.d.ts +13 -0
- package/dist/components/edit-menu/props.d.ts.map +1 -1
- package/dist/components/edit-menu/style.css +5 -7
- package/dist/components/form/main.d.ts +8 -0
- package/dist/components/form/main.d.ts.map +1 -1
- package/dist/components/form/main.js +15 -2
- package/dist/components/form/main.js.map +1 -1
- package/dist/components/form/props.d.ts +1 -2
- package/dist/components/form/props.d.ts.map +1 -1
- package/dist/components/glass/style.css +19 -4
- package/dist/components/header/main.d.ts +5 -4
- package/dist/components/header/main.d.ts.map +1 -1
- package/dist/components/header/main.js +56 -27
- package/dist/components/header/main.js.map +1 -1
- package/dist/components/header/props.d.ts +2 -3
- package/dist/components/header/props.d.ts.map +1 -1
- package/dist/components/header/style.css +62 -42
- package/dist/components/index.d.ts +26 -22
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +17 -13
- package/dist/components/index.js.map +1 -1
- package/dist/components/layout/main.d.ts +2 -2
- package/dist/components/layout/main.d.ts.map +1 -1
- package/dist/components/layout/main.js +59 -163
- package/dist/components/layout/main.js.map +1 -1
- package/dist/components/layout/props.d.ts +2 -20
- package/dist/components/layout/props.d.ts.map +1 -1
- package/dist/components/layout/style.css +18 -89
- package/dist/components/list/main.d.ts +49 -9
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +769 -208
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +165 -8
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/style.css +308 -371
- package/dist/components/list/swipe-actions-handle.d.ts +40 -0
- package/dist/components/list/swipe-actions-handle.d.ts.map +1 -0
- package/dist/components/list/swipe-actions-handle.js +51 -0
- package/dist/components/list/swipe-actions-handle.js.map +1 -0
- package/dist/components/menu/main.d.ts +31 -8
- package/dist/components/menu/main.d.ts.map +1 -1
- package/dist/components/menu/main.js +175 -39
- package/dist/components/menu/main.js.map +1 -1
- package/dist/components/menu/props.d.ts +2 -1
- package/dist/components/menu/props.d.ts.map +1 -1
- package/dist/components/menu/style.css +10 -32
- package/dist/components/navigation/main.d.ts +11 -2
- package/dist/components/navigation/main.d.ts.map +1 -1
- package/dist/components/navigation/main.js +186 -98
- package/dist/components/navigation/main.js.map +1 -1
- package/dist/components/navigation/props.d.ts +20 -3
- package/dist/components/navigation/props.d.ts.map +1 -1
- package/dist/components/navigation/style.css +24 -7
- package/dist/components/page/main.d.ts.map +1 -1
- package/dist/components/page/main.js +2 -2
- package/dist/components/page/main.js.map +1 -1
- package/dist/components/page/props.d.ts +8 -0
- package/dist/components/page/props.d.ts.map +1 -1
- package/dist/components/page/style.css +39 -1
- package/dist/components/page-control/main.d.ts +1 -1
- package/dist/components/page-control/main.d.ts.map +1 -1
- package/dist/components/page-control/main.js +59 -25
- package/dist/components/page-control/main.js.map +1 -1
- package/dist/components/page-control/props.d.ts +10 -2
- package/dist/components/page-control/props.d.ts.map +1 -1
- package/dist/components/page-control/style.css +5 -0
- package/dist/components/popover/main.d.ts +11 -6
- package/dist/components/popover/main.d.ts.map +1 -1
- package/dist/components/popover/main.js +53 -31
- package/dist/components/popover/main.js.map +1 -1
- package/dist/components/popover/props.d.ts +7 -6
- package/dist/components/popover/props.d.ts.map +1 -1
- package/dist/components/popover/style.css +45 -4
- package/dist/components/progress/main.d.ts +1 -1
- package/dist/components/progress/main.d.ts.map +1 -1
- package/dist/components/progress/main.js +108 -15
- package/dist/components/progress/main.js.map +1 -1
- package/dist/components/progress/props.d.ts +25 -5
- package/dist/components/progress/props.d.ts.map +1 -1
- package/dist/components/progress/style.css +67 -35
- package/dist/components/roll/main.d.ts +1 -1
- package/dist/components/roll/main.d.ts.map +1 -1
- package/dist/components/roll/main.js +81 -25
- package/dist/components/roll/main.js.map +1 -1
- package/dist/components/roll/props.d.ts +24 -7
- package/dist/components/roll/props.d.ts.map +1 -1
- package/dist/components/roll/style.css +1 -13
- package/dist/components/segmented/main.js +3 -3
- package/dist/components/segmented/main.js.map +1 -1
- package/dist/components/segmented/style.css +2 -14
- package/dist/components/sheet/main.d.ts +25 -15
- package/dist/components/sheet/main.d.ts.map +1 -1
- package/dist/components/sheet/main.js +57 -73
- package/dist/components/sheet/main.js.map +1 -1
- package/dist/components/sheet/props.d.ts +36 -2
- package/dist/components/sheet/props.d.ts.map +1 -1
- package/dist/components/sheet/style.css +176 -44
- package/dist/components/sidebar/style.css +13 -7
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +6 -5
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/style.css +2 -28
- package/dist/components/stepper/main.d.ts +4 -6
- package/dist/components/stepper/main.d.ts.map +1 -1
- package/dist/components/stepper/main.js +17 -11
- package/dist/components/stepper/main.js.map +1 -1
- package/dist/components/stepper/style.css +4 -8
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +16 -11
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/switch/props.d.ts +2 -2
- package/dist/components/switch/props.d.ts.map +1 -1
- package/dist/components/switch/style.css +28 -1
- package/dist/components/symbol/main.d.ts +2 -2
- package/dist/components/symbol/main.d.ts.map +1 -1
- package/dist/components/symbol/main.js +34 -27
- package/dist/components/symbol/main.js.map +1 -1
- package/dist/components/symbol/props.d.ts +39 -4
- package/dist/components/symbol/props.d.ts.map +1 -1
- package/dist/components/symbol/style.css +25 -4
- package/dist/components/tab-bar/main.d.ts.map +1 -1
- package/dist/components/tab-bar/main.js +59 -46
- package/dist/components/tab-bar/main.js.map +1 -1
- package/dist/components/tab-bar/props.d.ts +3 -3
- package/dist/components/tab-bar/props.d.ts.map +1 -1
- package/dist/components/tab-bar/style.css +24 -46
- package/dist/components/text-field/main.d.ts.map +1 -1
- package/dist/components/text-field/main.js +9 -8
- package/dist/components/text-field/main.js.map +1 -1
- package/dist/components/text-field/props.d.ts +8 -1
- package/dist/components/text-field/props.d.ts.map +1 -1
- package/dist/components/text-field/style.css +21 -55
- package/dist/components/toolbar/main.d.ts.map +1 -1
- package/dist/components/toolbar/main.js +11 -9
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/style.css +28 -22
- package/dist/components/tooltip/main.d.ts +10 -9
- package/dist/components/tooltip/main.d.ts.map +1 -1
- package/dist/components/tooltip/main.js +35 -6
- package/dist/components/tooltip/main.js.map +1 -1
- package/dist/components/tooltip/props.d.ts +2 -0
- package/dist/components/tooltip/props.d.ts.map +1 -1
- package/dist/components/tooltip/style.css +11 -11
- package/dist/components/typography/main.d.ts.map +1 -1
- package/dist/components/typography/main.js +16 -6
- package/dist/components/typography/main.js.map +1 -1
- package/dist/components/typography/props.d.ts +2 -9
- package/dist/components/typography/props.d.ts.map +1 -1
- package/dist/components/typography/style.css +0 -120
- package/dist/components/utils/main.d.ts +34 -5
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +81 -12
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/utils/props.d.ts +4 -2
- package/dist/components/utils/props.d.ts.map +1 -1
- package/dist/components/utils/style.css +29 -16
- package/dist/components/viewport/input.d.ts +23 -0
- package/dist/components/viewport/input.d.ts.map +1 -0
- package/dist/components/viewport/input.js +95 -0
- package/dist/components/viewport/input.js.map +1 -0
- package/dist/components/viewport/main.d.ts +42 -9
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +488 -66
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/padding.d.ts +50 -0
- package/dist/components/viewport/padding.d.ts.map +1 -0
- package/dist/components/viewport/padding.js +226 -0
- package/dist/components/viewport/padding.js.map +1 -0
- package/dist/components/viewport/props.d.ts +155 -7
- package/dist/components/viewport/props.d.ts.map +1 -1
- package/dist/components/viewport/style.css +172 -6
- package/dist/main.d.ts +0 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/styles.css +35 -2
- package/dist/styles.d.ts +2 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +2 -1
- package/dist/styles.js.map +1 -1
- package/package.json +6 -13
|
@@ -5,11 +5,15 @@ import '../popover/style.css';
|
|
|
5
5
|
import '../roll/style.css';
|
|
6
6
|
import '../typography/style.css';
|
|
7
7
|
import './style.css';
|
|
8
|
-
import {
|
|
8
|
+
import { Field as BaseField } from '@base-ui/react/field';
|
|
9
|
+
import { forwardRef, Fragment, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
|
|
9
10
|
import { Button } from '../button/main.js';
|
|
11
|
+
import { List, useCollapsible, useExpandedOpen } from '../list/main.js';
|
|
10
12
|
import { Popover } from '../popover/main.js';
|
|
11
13
|
import { Roll } from '../roll/main.js';
|
|
12
14
|
import { cn } from '../utils/main.js';
|
|
15
|
+
import { createHandle } from './handle.js';
|
|
16
|
+
import { useMonthPager } from './pager.js';
|
|
13
17
|
// Source: Apple iOS 26 Figma (“Date and time - Collapsed”: State=Default/
|
|
14
18
|
// Selected; “Date and time - Pickers”: Style=Inline/Compact; light and dark
|
|
15
19
|
// appearance), with Figma colors mapped to UIKit semantic colors: the
|
|
@@ -42,6 +46,12 @@ import { cn } from '../utils/main.js';
|
|
|
42
46
|
// from the sides.
|
|
43
47
|
// - The collapsed buttons are capsules (or, `buttonShape`, Figma's 6px
|
|
44
48
|
// corners).
|
|
49
|
+
// What swiping the days does (see `swipe`): a range dragged only picking
|
|
50
|
+
// one.
|
|
51
|
+
const swipeOf = (swipe, isRange) => {
|
|
52
|
+
const value = swipe ?? (isRange ? 'date-range' : 'month');
|
|
53
|
+
return value === 'date-range' && !isRange ? 'ignore' : value;
|
|
54
|
+
};
|
|
45
55
|
// Dates (local time).
|
|
46
56
|
const startOfDay = (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
47
57
|
const startOfMonth = (date) => new Date(date.getFullYear(), date.getMonth(), 1);
|
|
@@ -135,7 +145,7 @@ const useControlled = (value, defaultValue) => {
|
|
|
135
145
|
const CollapsedButton = forwardRef(({ className, shape, ...props }, ref) => (_jsx(Button.Root, { ref: ref, shape: shape === 'roundedRectangle' ? 'roundedRectangle' : 'capsule', type: "button", variant: "bordered-secondary", ...props, className: cn('uikit-date-picker-collapsed-button', className), "data-date-picker-part": "collapsed-button" })));
|
|
136
146
|
// Figma “Time”: a 52px row, the title (Body) and the time.
|
|
137
147
|
const TimeRow = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn('uikit-date-picker-time-row', className), "data-date-picker-part": "time-row", ...props })));
|
|
138
|
-
const Chevron = ({
|
|
148
|
+
const Chevron = ({ isNext }) => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "20", stroke: "currentcolor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2.4", viewBox: "0 0 12 20", width: "12", children: _jsx("path", { d: isNext ? 'M3 2l7 8-7 8' : 'M9 2l-7 8 7 8' }) }));
|
|
139
149
|
const Disclosure = () => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "0.75em", stroke: "currentcolor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 8 14", width: "0.43em", children: _jsx("path", { d: "M1.5 1.5L6.5 7l-5 5.5" }) }));
|
|
140
150
|
/** The locale's hour cycle, and whether the day period comes first. */
|
|
141
151
|
const timeFormat = (locale, cycle) => {
|
|
@@ -146,24 +156,33 @@ const timeFormat = (locale, cycle) => {
|
|
|
146
156
|
});
|
|
147
157
|
const { hourCycle = 'h23' } = format.resolvedOptions();
|
|
148
158
|
const parts = format.formatToParts(new Date(2000, 0, 1, 21, 41));
|
|
149
|
-
const
|
|
159
|
+
const isPeriodFirst = parts.findIndex(({ type }) => type === 'dayPeriod') <
|
|
150
160
|
parts.findIndex(({ type }) => type === 'hour');
|
|
151
161
|
const period = (hour) => format
|
|
152
162
|
.formatToParts(new Date(2000, 0, 1, hour))
|
|
153
163
|
.find(({ type }) => type === 'dayPeriod')?.value ?? '';
|
|
154
164
|
return {
|
|
155
165
|
hourCycle,
|
|
156
|
-
periodFirst:
|
|
166
|
+
periodFirst: isPeriodFirst && parts.some(({ type }) => type === 'dayPeriod'),
|
|
157
167
|
periods: [period(9), period(21)],
|
|
158
168
|
twelve: hourCycle === 'h11' || hourCycle === 'h12',
|
|
159
169
|
};
|
|
160
170
|
};
|
|
161
171
|
/**
|
|
162
172
|
* The time as a roll: hours, minutes and (12 hours) the day period, the
|
|
163
|
-
* numbers editable (e.g. in an expandable list row, see `DatePicker`).
|
|
173
|
+
* numbers editable (e.g. in an expandable list row, see `DatePicker.Root`).
|
|
164
174
|
*/
|
|
165
|
-
const TimeRoll = ({ hourCycle: cycle, locale, onValueChange: onChange, value, }) => {
|
|
175
|
+
const TimeRoll = ({ hourCycle: cycle, locale, max, min, onValueChange: onChange, value, }) => {
|
|
166
176
|
const date = value ?? new Date();
|
|
177
|
+
// Its day at a time, and whether that's beyond the limits.
|
|
178
|
+
const at = (hour, minute) => {
|
|
179
|
+
const next = new Date(date);
|
|
180
|
+
next.setHours(hour, minute, 0, 0);
|
|
181
|
+
return next;
|
|
182
|
+
};
|
|
183
|
+
const isBeyond = (time) => (min !== undefined && time < min) || (max !== undefined && time > max);
|
|
184
|
+
// Some of the hours' minutes (from, to) within the limits.
|
|
185
|
+
const isWithin = (from, to) => (min === undefined || to >= min) && (max === undefined || from <= max);
|
|
167
186
|
const { hourCycle, periodFirst, periods, twelve } = useMemo(() => timeFormat(locale, cycle), [cycle, locale]);
|
|
168
187
|
const numbers = useMemo(() => ({
|
|
169
188
|
hour: new Intl.NumberFormat(locale, {
|
|
@@ -172,26 +191,32 @@ const TimeRoll = ({ hourCycle: cycle, locale, onValueChange: onChange, value, })
|
|
|
172
191
|
minute: new Intl.NumberFormat(locale, { minimumIntegerDigits: 2 }),
|
|
173
192
|
}), [locale, twelve]);
|
|
174
193
|
const hours = date.getHours();
|
|
175
|
-
const
|
|
194
|
+
const isPm = hours >= 12;
|
|
176
195
|
const hourValues = twelve
|
|
177
196
|
? Array.from({ length: 12 }, (_, index) => hourCycle === 'h12' ? index + 1 : index)
|
|
178
197
|
: Array.from({ length: 24 }, (_, index) => index);
|
|
179
198
|
const twelveHour = hourCycle === 'h12' ? hours % 12 || 12 : hours % 12;
|
|
180
199
|
const shownHour = twelve ? twelveHour : hours;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
200
|
+
// Beyond the limits: the nearest within them (the roll moving back, as
|
|
201
|
+
// UIKit's).
|
|
202
|
+
const set = (hour, minute, { event }) => {
|
|
203
|
+
let next = at(hour, minute);
|
|
204
|
+
if (min !== undefined && next < min)
|
|
205
|
+
next = new Date(min);
|
|
206
|
+
if (max !== undefined && next > max)
|
|
207
|
+
next = new Date(max);
|
|
208
|
+
onChange(next, { event, reason: 'time' });
|
|
185
209
|
};
|
|
186
|
-
|
|
187
|
-
|
|
210
|
+
// A shown hour's (of the shown period, with 12 hours), as 0–23.
|
|
211
|
+
const hourOf = (hour) => twelve ? (hour % 12) + (isPm ? 12 : 0) : hour;
|
|
212
|
+
const period = (_jsxs(Roll.Column, { "aria-label": "AM/PM", value: isPm ? 'pm' : 'am', onValueChange: (next, details) => {
|
|
213
|
+
if ((next === 'pm') === isPm)
|
|
188
214
|
return;
|
|
189
|
-
set((hours + 12) % 24, date.getMinutes());
|
|
190
|
-
}, children: [_jsx(Roll.Item, { value: "am", children: periods[0] }), _jsx(Roll.Item, { value: "pm", children: periods[1] })] }));
|
|
191
|
-
return (_jsxs(Roll.Root, { children: [twelve && periodFirst ? period : null, _jsx(Roll.Column, { editable: true, align: "end", "aria-label": "Hours", value: shownHour, onValueChange: (next) => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}, children: hourValues.map((hour) => (_jsx(Roll.Item, { value: hour, children: numbers.hour.format(hour) }, hour))) }), _jsx(Roll.Column, { editable: true, align: "start", "aria-label": "Minutes", value: date.getMinutes(), onValueChange: (next) => set(hours, Number(next)), children: Array.from({ length: 60 }, (_, minute) => (_jsx(Roll.Item, { value: minute, children: numbers.minute.format(minute) }, minute))) }), twelve && !periodFirst ? period : null] }));
|
|
215
|
+
set((hours + 12) % 24, date.getMinutes(), details);
|
|
216
|
+
}, children: [_jsx(Roll.Item, { disabled: !isWithin(at(0, 0), at(11, 59)), value: "am", children: periods[0] }), _jsx(Roll.Item, { disabled: !isWithin(at(12, 0), at(23, 59)), value: "pm", children: periods[1] })] }));
|
|
217
|
+
return (_jsxs(Roll.Root, { children: [twelve && periodFirst ? period : null, _jsx(Roll.Column, { editable: true, align: "end", "aria-label": "Hours", value: shownHour, onValueChange: (next, details) => {
|
|
218
|
+
set(hourOf(Number(next)), date.getMinutes(), details);
|
|
219
|
+
}, children: hourValues.map((hour) => (_jsx(Roll.Item, { disabled: !isWithin(at(hourOf(hour), 0), at(hourOf(hour), 59)), value: hour, children: numbers.hour.format(hour) }, hour))) }), _jsx(Roll.Column, { editable: true, align: "start", "aria-label": "Minutes", value: date.getMinutes(), onValueChange: (next, details) => set(hours, Number(next), details), children: Array.from({ length: 60 }, (_, minute) => (_jsx(Roll.Item, { disabled: isBeyond(at(hours, minute)), value: minute, children: numbers.minute.format(minute) }, minute))) }), twelve && !periodFirst ? period : null] }));
|
|
195
220
|
};
|
|
196
221
|
const clampMonth = (month, min, max) => {
|
|
197
222
|
if (min && month < startOfMonth(min))
|
|
@@ -238,14 +263,16 @@ const useCalendarValue = (props) => {
|
|
|
238
263
|
setDraggedFrom,
|
|
239
264
|
setValue,
|
|
240
265
|
single,
|
|
266
|
+
// (Either.)
|
|
267
|
+
value: range ?? single,
|
|
241
268
|
};
|
|
242
269
|
};
|
|
243
270
|
/** The footer's state and actions (see `CalendarFooter`). */
|
|
244
271
|
const footerOf = ({ time, ...footer }) => {
|
|
245
272
|
if (!time)
|
|
246
273
|
return { ...footer, disabled: false };
|
|
247
|
-
const { disabled, shape, ...rest } = time;
|
|
248
|
-
return { ...footer, buttonShape: shape, disabled, time: rest };
|
|
274
|
+
const { disabled: isDisabled, shape, ...rest } = time;
|
|
275
|
+
return { ...footer, buttonShape: shape, disabled: isDisabled, time: rest };
|
|
249
276
|
};
|
|
250
277
|
/** A day's button's date (see `CalendarPanel`). */
|
|
251
278
|
const dayOf = (target) => {
|
|
@@ -281,17 +308,39 @@ const rangeReach = (fixed, selectable, hasDisabledDays, isRangeDisabled) => {
|
|
|
281
308
|
};
|
|
282
309
|
/** A range from two days, in either order. */
|
|
283
310
|
const between = (a, b) => a <= b ? { end: b, start: a } : { end: a, start: b };
|
|
311
|
+
const twoDigits = (value) => String(value).padStart(2, '0');
|
|
312
|
+
const isoDate = (date) => `${String(date.getFullYear())}-${twoDigits(date.getMonth() + 1)}-${twoDigits(date.getDate())}`;
|
|
313
|
+
const isoTime = (date) => `${twoDigits(date.getHours())}:${twoDigits(date.getMinutes())}`;
|
|
314
|
+
/**
|
|
315
|
+
* A value as a form submits it (an input's formats; a range's interval, or
|
|
316
|
+
* nothing until its end is picked).
|
|
317
|
+
*/
|
|
318
|
+
const formValueOf = (value, mode = 'date') => {
|
|
319
|
+
if (!value)
|
|
320
|
+
return '';
|
|
321
|
+
if (!(value instanceof Date)) {
|
|
322
|
+
return value.end ? `${isoDate(value.start)}/${isoDate(value.end)}` : '';
|
|
323
|
+
}
|
|
324
|
+
if (mode === 'time')
|
|
325
|
+
return isoTime(value);
|
|
326
|
+
if (mode === 'dateAndTime')
|
|
327
|
+
return `${isoDate(value)}T${isoTime(value)}`;
|
|
328
|
+
return isoDate(value);
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Its value's hidden control (Base UI's field control): submitted by its
|
|
332
|
+
* `name`, or, in a Base UI `Field`, as the field's.
|
|
333
|
+
*/
|
|
334
|
+
const FormValue = ({ form, mode, name, isOmitted = false, value }) => isOmitted ? null : (_jsx(BaseField.Control, { form: form, name: name, type: "hidden", value: formValueOf(value, mode) }));
|
|
284
335
|
/** The calendar (Figma “Style=Inline”), with an optional time row. */
|
|
285
336
|
const CalendarPanel = (props) => {
|
|
286
337
|
const { firstDayOfWeek: weekStartProp, highlighted, highlightedWeekdays = [], hourCycle, isDateDisabled, label, locale, max, min, showAdjacentMonths, time, } = props;
|
|
287
|
-
const { dragged, draggedFrom, range, setDragged, setDraggedFrom, setValue, single, } = useCalendarValue(props);
|
|
338
|
+
const { dragged, draggedFrom, range, setDragged, setDraggedFrom, setValue, single, value, } = useCalendarValue(props);
|
|
288
339
|
const today = startOfDay(new Date());
|
|
289
340
|
const [month, setMonth] = useState(() => startOfMonth(range?.start ?? single ?? today));
|
|
290
341
|
const [focused, setFocused] = useState(() => clampDay(startOfDay(range?.start ?? single ?? today), min, max));
|
|
291
342
|
const [rolled, setRolled] = useState(props.initialRoll);
|
|
292
|
-
|
|
293
|
-
const [leaving, setLeaving] = useState(undefined);
|
|
294
|
-
const leavingRef = useRef(null);
|
|
343
|
+
const swipes = swipeOf(props.swipe, Boolean(props.range));
|
|
295
344
|
const pagesRef = useRef(null);
|
|
296
345
|
const daysRef = useRef(null);
|
|
297
346
|
const focusNext = useRef(undefined);
|
|
@@ -340,60 +389,68 @@ const CalendarPanel = (props) => {
|
|
|
340
389
|
focusNext.current = undefined;
|
|
341
390
|
day.focus();
|
|
342
391
|
});
|
|
343
|
-
//
|
|
392
|
+
// The strip as high as the shown month's days (its neighbours' clipped),
|
|
393
|
+
// as they're laid out (not while hidden, e.g. in a closed row: none).
|
|
344
394
|
useLayoutEffect(() => {
|
|
345
395
|
const { current: days } = daysRef;
|
|
346
|
-
|
|
396
|
+
const { current: pages } = pagesRef;
|
|
397
|
+
if (!days || !pages)
|
|
398
|
+
return undefined;
|
|
399
|
+
const fit = () => {
|
|
400
|
+
if (days.offsetHeight === 0)
|
|
401
|
+
return;
|
|
402
|
+
height.current = days.offsetHeight;
|
|
403
|
+
pages.style.height = `${String(days.offsetHeight)}px`;
|
|
404
|
+
};
|
|
405
|
+
fit();
|
|
406
|
+
const observer = new ResizeObserver(fit);
|
|
407
|
+
observer.observe(days);
|
|
408
|
+
return () => observer.disconnect();
|
|
409
|
+
}, [month]);
|
|
410
|
+
// The months side by side, scrolled sideways (see pager.ts): turned to,
|
|
411
|
+
// by scrolling, its day focused.
|
|
412
|
+
const isPreviousDisabled = Boolean(min && addDays(startOfMonth(month), -1) < startOfDay(min));
|
|
413
|
+
const isNextDisabled = Boolean(max && startOfMonth(addMonths(month, 1)) > startOfDay(max));
|
|
414
|
+
const pager = useMonthPager({
|
|
415
|
+
// A month's neighbour, not beyond the limits (as the arrows').
|
|
416
|
+
beside: (shown, step) => {
|
|
417
|
+
const at = startOfMonth(addMonths(shown, step));
|
|
418
|
+
const last = addDays(startOfMonth(addMonths(at, 1)), -1);
|
|
419
|
+
if (min && last < startOfDay(min))
|
|
420
|
+
return undefined;
|
|
421
|
+
if (max && at > startOfDay(max))
|
|
422
|
+
return undefined;
|
|
423
|
+
return at;
|
|
424
|
+
},
|
|
425
|
+
isDraggable: swipes === 'month',
|
|
426
|
+
isInstant: rolled !== undefined,
|
|
427
|
+
month,
|
|
428
|
+
onTurn: (next, isScrolled) => {
|
|
429
|
+
setMonth(next);
|
|
430
|
+
if (isScrolled)
|
|
431
|
+
setFocused(clampDay(next, min, max));
|
|
432
|
+
},
|
|
433
|
+
pagesRef,
|
|
434
|
+
});
|
|
435
|
+
const { goTo } = pager;
|
|
436
|
+
// Months of more or fewer weeks: once settled on one (not while
|
|
437
|
+
// scrolled: a native touch drag would falter), the strip's height
|
|
438
|
+
// transitioning (between heights laid out).
|
|
439
|
+
useLayoutEffect(() => {
|
|
440
|
+
const { current: days } = daysRef;
|
|
441
|
+
const { current: pages } = pagesRef;
|
|
442
|
+
if (!days || !pages)
|
|
347
443
|
return;
|
|
348
444
|
const next = days.offsetHeight;
|
|
349
445
|
const previous = height.current;
|
|
446
|
+
if (next === 0)
|
|
447
|
+
return;
|
|
350
448
|
height.current = next;
|
|
449
|
+
pages.style.height = `${String(next)}px`;
|
|
351
450
|
if (previous === undefined || previous === next)
|
|
352
451
|
return;
|
|
353
|
-
|
|
354
|
-
days.style.overflow = 'clip';
|
|
355
|
-
const animation = days.animate([{ height: `${String(previous)}px` }, { height: `${String(next)}px` }], { duration: 300, easing: 'ease' });
|
|
356
|
-
animation.finished
|
|
357
|
-
.then(() => days.style.removeProperty('overflow'))
|
|
358
|
-
.catch(() => days.style.removeProperty('overflow'));
|
|
452
|
+
pages.animate([{ height: `${String(previous)}px` }, { height: `${String(next)}px` }], { duration: 300, easing: 'ease' });
|
|
359
453
|
}, [month, weekStart]);
|
|
360
|
-
// Months slide in from the side they're in (next: the inline end), the
|
|
361
|
-
// previous one sliding out (as iOS's).
|
|
362
|
-
const goTo = (next) => {
|
|
363
|
-
const target = startOfMonth(next);
|
|
364
|
-
const direction = Math.sign(target.getTime() - month.getTime());
|
|
365
|
-
if (direction === 0)
|
|
366
|
-
return;
|
|
367
|
-
setLeaving({ direction, month });
|
|
368
|
-
setMonth(target);
|
|
369
|
-
};
|
|
370
|
-
useLayoutEffect(() => {
|
|
371
|
-
const { current: days } = daysRef;
|
|
372
|
-
const { current: pages } = pagesRef;
|
|
373
|
-
const { current: page } = leavingRef;
|
|
374
|
-
if (!leaving || !days || !pages || !page)
|
|
375
|
-
return undefined;
|
|
376
|
-
const rtl = getComputedStyle(pages).direction === 'rtl' ? -1 : 1;
|
|
377
|
-
const shift = (fraction) => `translateX(${String(fraction * leaving.direction * rtl * 100)}%)`;
|
|
378
|
-
const options = { duration: 300, easing: 'ease' };
|
|
379
|
-
pages.style.overflow = 'clip';
|
|
380
|
-
const animations = [
|
|
381
|
-
days.animate([{ transform: shift(1) }, { transform: 'none' }], options),
|
|
382
|
-
page.animate([{ transform: 'none' }, { transform: shift(-1) }], options),
|
|
383
|
-
];
|
|
384
|
-
const [incoming] = animations;
|
|
385
|
-
incoming?.finished
|
|
386
|
-
.then(() => {
|
|
387
|
-
pages.style.removeProperty('overflow');
|
|
388
|
-
setLeaving(undefined);
|
|
389
|
-
})
|
|
390
|
-
.catch(() => undefined);
|
|
391
|
-
return () => {
|
|
392
|
-
for (const animation of animations)
|
|
393
|
-
animation.cancel();
|
|
394
|
-
pages.style.removeProperty('overflow');
|
|
395
|
-
};
|
|
396
|
-
}, [leaving]);
|
|
397
454
|
// Moved by keyboard: on past disabled days (in the direction moved), to
|
|
398
455
|
// one that can be focused.
|
|
399
456
|
const moveTo = (date) => {
|
|
@@ -411,42 +468,42 @@ const CalendarPanel = (props) => {
|
|
|
411
468
|
goTo(target);
|
|
412
469
|
focusNext.current = target;
|
|
413
470
|
};
|
|
414
|
-
const changeTime = (date) => {
|
|
471
|
+
const changeTime = (date, details) => {
|
|
415
472
|
setValue(date);
|
|
416
473
|
if (!props.range)
|
|
417
|
-
props.onValueChange?.(date);
|
|
474
|
+
props.onValueChange?.(date, details);
|
|
418
475
|
};
|
|
419
|
-
const commitRange = (next) => {
|
|
476
|
+
const commitRange = (next, details) => {
|
|
420
477
|
if (!props.range)
|
|
421
478
|
return;
|
|
422
479
|
setValue(next);
|
|
423
|
-
props.onValueChange?.(next);
|
|
480
|
+
props.onValueChange?.(next, details);
|
|
424
481
|
};
|
|
425
|
-
const select = (date,
|
|
482
|
+
const select = (date, hasTime, details) => {
|
|
426
483
|
setFocused(startOfDay(date));
|
|
427
484
|
if (props.range) {
|
|
428
485
|
// A new range, or its end (before its start: the other way round; out
|
|
429
486
|
// of the start's reach, a new range).
|
|
430
487
|
commitRange(!range || range.end || !reachable(date)
|
|
431
488
|
? { end: null, start: date }
|
|
432
|
-
: between(range.start, date));
|
|
489
|
+
: between(range.start, date), details);
|
|
433
490
|
return;
|
|
434
491
|
}
|
|
435
492
|
// Keeps the time of an earlier value (unless taking the date's).
|
|
436
493
|
const next = new Date(date);
|
|
437
|
-
if (single && !
|
|
494
|
+
if (single && !hasTime) {
|
|
438
495
|
next.setHours(single.getHours(), single.getMinutes(), 0, 0);
|
|
439
496
|
}
|
|
440
497
|
setValue(next);
|
|
441
|
-
props.onValueChange?.(next);
|
|
498
|
+
props.onValueChange?.(next, details);
|
|
442
499
|
};
|
|
443
500
|
const onKeyDown = (event) => {
|
|
444
|
-
const
|
|
501
|
+
const isRightToLeft = getComputedStyle(event.currentTarget).direction === 'rtl';
|
|
445
502
|
const column = (focused.getDay() - weekStart + 7) % 7;
|
|
446
503
|
const moves = {
|
|
447
504
|
ArrowDown: () => addDays(focused, 7),
|
|
448
|
-
ArrowLeft: () => addDays(focused,
|
|
449
|
-
ArrowRight: () => addDays(focused,
|
|
505
|
+
ArrowLeft: () => addDays(focused, isRightToLeft ? 1 : -1),
|
|
506
|
+
ArrowRight: () => addDays(focused, isRightToLeft ? -1 : 1),
|
|
450
507
|
ArrowUp: () => addDays(focused, -7),
|
|
451
508
|
End: () => addDays(focused, 6 - column),
|
|
452
509
|
Home: () => addDays(focused, -column),
|
|
@@ -462,7 +519,7 @@ const CalendarPanel = (props) => {
|
|
|
462
519
|
// Ranges are also dragged into existence: from the day pressed to the day
|
|
463
520
|
// under the pointer, picked on release (taps pick start and end).
|
|
464
521
|
const onPointerDown = (event) => {
|
|
465
|
-
if (
|
|
522
|
+
if (swipes !== 'date-range' || event.button !== 0)
|
|
466
523
|
return;
|
|
467
524
|
const from = dayOf(event.target);
|
|
468
525
|
if (!from || !enabled(from))
|
|
@@ -470,7 +527,7 @@ const CalendarPanel = (props) => {
|
|
|
470
527
|
drag.current = {
|
|
471
528
|
edge: 0,
|
|
472
529
|
from,
|
|
473
|
-
|
|
530
|
+
isMoved: false,
|
|
474
531
|
reachable: reachOf(from),
|
|
475
532
|
x: event.clientX,
|
|
476
533
|
y: event.clientY,
|
|
@@ -503,15 +560,17 @@ const CalendarPanel = (props) => {
|
|
|
503
560
|
dragging.timer = setTimeout(step, 500);
|
|
504
561
|
};
|
|
505
562
|
const onPointerMove = (event) => {
|
|
563
|
+
if (swipes !== 'date-range')
|
|
564
|
+
return;
|
|
506
565
|
const { current: dragging } = drag;
|
|
507
566
|
if (!dragging)
|
|
508
567
|
return;
|
|
509
|
-
if (!dragging.
|
|
568
|
+
if (!dragging.isMoved) {
|
|
510
569
|
if (Math.hypot(event.clientX - dragging.x, event.clientY - dragging.y) < 6) {
|
|
511
570
|
return;
|
|
512
571
|
}
|
|
513
572
|
// Moves beyond the days are its own, too (the edges, see turnPage).
|
|
514
|
-
dragging.
|
|
573
|
+
dragging.isMoved = true;
|
|
515
574
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
516
575
|
setDraggedFrom(dragging.from);
|
|
517
576
|
setDragged(between(dragging.from, dragging.from));
|
|
@@ -520,28 +579,34 @@ const CalendarPanel = (props) => {
|
|
|
520
579
|
// days, or beyond their inline end): on to the next month; before its
|
|
521
580
|
// first: back.
|
|
522
581
|
const { bottom, left, right, top } = event.currentTarget.getBoundingClientRect();
|
|
523
|
-
const
|
|
582
|
+
const isRightToLeft = getComputedStyle(event.currentTarget).direction === 'rtl';
|
|
524
583
|
const under = document.elementFromPoint(event.clientX, event.clientY);
|
|
525
584
|
const outside = under instanceof Element
|
|
526
585
|
? under.closest('[data-outside]')?.dataset.outside
|
|
527
586
|
: undefined;
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
const
|
|
532
|
-
|
|
587
|
+
const isBeyondEnd = isRightToLeft
|
|
588
|
+
? event.clientX < left
|
|
589
|
+
: event.clientX > right;
|
|
590
|
+
const isBeyondStart = isRightToLeft
|
|
591
|
+
? event.clientX > right
|
|
592
|
+
: event.clientX < left;
|
|
593
|
+
const isAfter = event.clientY > bottom || isBeyondEnd || outside === 'after';
|
|
594
|
+
const isBefore = event.clientY < top || isBeyondStart || outside === 'before';
|
|
595
|
+
turnPage(Number(isAfter) - Number(isBefore));
|
|
533
596
|
const over = dayOf(under);
|
|
534
597
|
if (!over || !selectable(over) || !dragging.reachable(over))
|
|
535
598
|
return;
|
|
536
599
|
setDragged(between(dragging.from, over));
|
|
537
600
|
setFocused(over);
|
|
538
601
|
};
|
|
539
|
-
const onPointerEnd = () => {
|
|
602
|
+
const onPointerEnd = (event) => {
|
|
603
|
+
if (swipes !== 'date-range')
|
|
604
|
+
return;
|
|
540
605
|
const { current: dragging } = drag;
|
|
541
606
|
clearTimeout(dragging?.timer);
|
|
542
607
|
drag.current = undefined;
|
|
543
608
|
setDraggedFrom(null);
|
|
544
|
-
if (!dragging?.
|
|
609
|
+
if (!dragging?.isMoved || !dragged) {
|
|
545
610
|
setDragged(null);
|
|
546
611
|
return;
|
|
547
612
|
}
|
|
@@ -551,14 +616,12 @@ const CalendarPanel = (props) => {
|
|
|
551
616
|
suppressClick.current = false;
|
|
552
617
|
});
|
|
553
618
|
setDragged(null);
|
|
554
|
-
commitRange(dragged);
|
|
619
|
+
commitRange(dragged, { event, reason: 'drag' });
|
|
555
620
|
};
|
|
556
621
|
const showMonth = (next) => {
|
|
557
622
|
goTo(next);
|
|
558
623
|
setFocused(clampDay(next, min, max));
|
|
559
624
|
};
|
|
560
|
-
const previousDisabled = Boolean(min && addDays(startOfMonth(month), -1) < startOfDay(min));
|
|
561
|
-
const nextDisabled = Boolean(max && startOfMonth(addMonths(month, 1)) > startOfDay(max));
|
|
562
625
|
const toggle = (roll) => {
|
|
563
626
|
const next = rolled === roll ? undefined : roll;
|
|
564
627
|
setRolled(next);
|
|
@@ -569,7 +632,7 @@ const CalendarPanel = (props) => {
|
|
|
569
632
|
// A day of the grid of `shown` (the month, or the one sliding out, not
|
|
570
633
|
// `interactive`): another month's is blank, or grayed out (see
|
|
571
634
|
// `showAdjacentMonths`); either is marked `data-outside`, for drags.
|
|
572
|
-
const cell = (day, shown,
|
|
635
|
+
const cell = (day, shown, isInteractive) => {
|
|
573
636
|
const outsideOf = day < shown ? 'before' : 'after';
|
|
574
637
|
const outside = day.getMonth() === shown.getMonth() ? undefined : outsideOf;
|
|
575
638
|
if (outside && !showAdjacentMonths) {
|
|
@@ -577,21 +640,24 @@ const CalendarPanel = (props) => {
|
|
|
577
640
|
}
|
|
578
641
|
// Not the adjacent months' days (nor their weekdays, see below).
|
|
579
642
|
const { attributes, dots } = highlightsOf(outside ? undefined : highlighted?.(day));
|
|
580
|
-
return (_jsxs("button", { "aria-current": isSameDay(day, today) ? 'date' : undefined, "aria-label":
|
|
581
|
-
? () => {
|
|
643
|
+
return (_jsxs("button", { "aria-current": isSameDay(day, today) ? 'date' : undefined, "aria-label": isInteractive ? formats.full.format(day) : undefined, "data-date": isInteractive ? day.getTime() : undefined, ...attributes, className: "uikit-date-picker-day", "data-date-picker-part": "day", "data-outside": outside, "data-range": rangePlace(day, range), disabled: !enabled(day), tabIndex: isInteractive && !outside && isSameDay(day, focused) ? 0 : -1, type: "button", "aria-pressed": range ? rangePlace(day, range) !== undefined : isSameDay(day, single), "data-weekday-highlighted": (!outside && highlightedWeekdays.includes(day.getDay())) || undefined, onClick: isInteractive
|
|
644
|
+
? (event) => {
|
|
582
645
|
// Another month's day: shows its month (not selected).
|
|
583
646
|
if (outside) {
|
|
584
647
|
showMonth(day);
|
|
585
648
|
return;
|
|
586
649
|
}
|
|
587
|
-
select(day);
|
|
650
|
+
select(day, false, { event, reason: 'day-press' });
|
|
588
651
|
}
|
|
589
652
|
: undefined, children: [formats.day.format(day), dots.length > 0 ? (_jsx("span", { "data-date-picker-part": "dots", children: dots.map((dot, index) => (_jsx("span", { style: dot ? { backgroundColor: dot } : undefined }, index))) })) : null] }, day.getTime()));
|
|
590
653
|
};
|
|
591
654
|
const footerContent = props.footer?.(footerOf({
|
|
592
|
-
select: (date,
|
|
655
|
+
select: (date, hasTime = false) => {
|
|
593
656
|
goTo(date);
|
|
594
|
-
select(
|
|
657
|
+
select(hasTime ? date : startOfDay(date), hasTime, {
|
|
658
|
+
event: new Event('select'),
|
|
659
|
+
reason: 'footer',
|
|
660
|
+
});
|
|
595
661
|
},
|
|
596
662
|
show: (date) => {
|
|
597
663
|
goTo(date);
|
|
@@ -606,19 +672,21 @@ const CalendarPanel = (props) => {
|
|
|
606
672
|
},
|
|
607
673
|
value: range ?? single,
|
|
608
674
|
}));
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
675
|
+
// A neighbour's page (see pager.ts): its days, not interactive.
|
|
676
|
+
const neighbour = (shown) => (_jsx("div", { inert: true, "aria-hidden": "true", className: "uikit-date-picker-weeks", "data-date-picker-part": "weeks", children: monthWeeks(shown, weekStart)
|
|
677
|
+
.flat()
|
|
678
|
+
.map((day) => cell(day, shown, false)) }, shown.getTime()));
|
|
679
|
+
return (_jsxs("div", { className: "uikit-date-picker-panel", "data-date-picker-part": "calendar", children: [_jsxs("div", { className: "uikit-date-picker-header", "data-date-picker-part": "header", children: [_jsx("h2", { "aria-live": "polite", className: "uikit-date-picker-month-title", "data-date-picker-part": "month-title", id: titleId, children: _jsxs("button", { "aria-controls": rollId, "aria-expanded": rolled === 'monthYear', className: "uikit-date-picker-title-button", "data-date-picker-part": "title-button", type: "button", onClick: () => toggle('monthYear'), children: [formats.month.format(pager.shown), _jsx(Disclosure, {})] }) }), _jsxs("div", { className: "uikit-date-picker-arrows", "data-date-picker-part": "arrows", hidden: rolled === 'monthYear', children: [_jsx(Button.Root, { "aria-label": "Previous month", className: "uikit-date-picker-arrow", "data-date-picker-part": "arrow", disabled: isPreviousDisabled, shape: "circle", onClick: () => showMonth(addMonths(pager.shown, -1)), children: _jsx(Chevron, { isNext: false }) }), _jsx(Button.Root, { "aria-label": "Next month", className: "uikit-date-picker-arrow", "data-date-picker-part": "arrow", disabled: isNextDisabled, shape: "circle", onClick: () => showMonth(addMonths(pager.shown, 1)), children: _jsx(Chevron, { isNext: true }) })] })] }), _jsxs("div", { className: "uikit-date-picker-body", "data-date-picker-part": "body", "data-rolled": rolled === undefined ? undefined : '', children: [_jsx("div", { "aria-hidden": "true", className: "uikit-date-picker-weekdays", "data-date-picker-part": "weekdays", children: weekdays.map((day) => (_jsx("abbr", { title: formats.weekdayLong.format(day), "data-weekday-highlighted": highlightedWeekdays.includes(day.getDay()) || undefined, children: formats.weekday.format(day) }, day.getDay()))) }), _jsx("div", { ref: pagesRef, className: "uikit-date-picker-pages", "data-date-picker-part": "pages", "data-swipe": swipes, children: pager.months.map((shown) => shown.getTime() === month.getTime() ? (_jsx("div", { ref: daysRef, "aria-label": label, "aria-labelledby": label ? undefined : titleId, className: "uikit-date-picker-weeks", "data-date-picker-part": "weeks", "data-swipe": swipes, role: "group", onKeyDown: onKeyDown, onPointerCancel: onPointerEnd, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerEnd, onClickCapture: (event) => {
|
|
680
|
+
if (!suppressClick.current)
|
|
681
|
+
return;
|
|
682
|
+
suppressClick.current = false;
|
|
683
|
+
event.stopPropagation();
|
|
684
|
+
}, onFocus: (event) => {
|
|
685
|
+
// The day focused (e.g. pressed): keys move on from it.
|
|
686
|
+
const day = dayOf(event.target);
|
|
687
|
+
if (day && !isSameDay(day, focused))
|
|
688
|
+
setFocused(day);
|
|
689
|
+
}, children: weeks.flat().map((day) => cell(day, month, true)) }, shown.getTime())) : (neighbour(shown))) }), rolled === undefined ? null : (_jsx("div", { className: "uikit-date-picker-overlay", "data-date-picker-part": "roll", id: rollId, children: rolled === 'monthYear' ? (_jsx(MonthYearRoll, { locale: locale, max: max, min: min, month: month, onChange: showMonth })) : (_jsx(TimeRoll, { hourCycle: hourCycle, locale: locale, max: max, min: min, value: single, onValueChange: changeTime })) }))] }), footerContent === null || footerContent === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("div", { className: "uikit-date-picker-separator", "data-date-picker-part": "separator" }), footerContent] })), _jsx(FormValue, { form: props.form, isOmitted: props.formControl === false, name: props.name, value: value })] }));
|
|
622
690
|
};
|
|
623
691
|
/** A footer row (see `CalendarProps` `footer`): Figma “Time”'s, 52px. */
|
|
624
692
|
const CalendarRow = TimeRow;
|
|
@@ -640,11 +708,14 @@ const Calendar = (props) => _jsx(CalendarPanel, { ...props });
|
|
|
640
708
|
/** The calendar's props, of the picker's (its value, and its changes). */
|
|
641
709
|
const calendarPropsOf = (props, change, value) => {
|
|
642
710
|
const shared = {
|
|
711
|
+
// (The picker renders its own.)
|
|
712
|
+
formControl: false,
|
|
643
713
|
firstDayOfWeek: props.firstDayOfWeek,
|
|
644
714
|
highlighted: props.highlighted,
|
|
645
715
|
highlightedWeekdays: props.highlightedWeekdays,
|
|
646
716
|
isDateDisabled: props.isDateDisabled,
|
|
647
717
|
showAdjacentMonths: props.showAdjacentMonths,
|
|
718
|
+
swipe: props.swipe,
|
|
648
719
|
hourCycle: props.hourCycle,
|
|
649
720
|
locale: props.locale,
|
|
650
721
|
max: props.max,
|
|
@@ -664,9 +735,9 @@ const calendarPropsOf = (props, change, value) => {
|
|
|
664
735
|
const usePickerValue = (props) => {
|
|
665
736
|
const [value, setValue] = useControlled(props.value, props.defaultValue ?? null);
|
|
666
737
|
// Only changed to the kind of value it has (a date or a range).
|
|
667
|
-
const change = (next) => {
|
|
738
|
+
const change = (next, details) => {
|
|
668
739
|
setValue(next);
|
|
669
|
-
props.onValueChange?.(next);
|
|
740
|
+
props.onValueChange?.(next, details);
|
|
670
741
|
};
|
|
671
742
|
return {
|
|
672
743
|
change,
|
|
@@ -677,18 +748,18 @@ const usePickerValue = (props) => {
|
|
|
677
748
|
/** The open picker of the compact style, and its changes. */
|
|
678
749
|
const usePickerOpen = (props) => {
|
|
679
750
|
const [open, setOpen] = useControlled(props.open, props.defaultOpen ?? null);
|
|
680
|
-
const change = (next) => {
|
|
751
|
+
const change = (next, details) => {
|
|
681
752
|
setOpen(next);
|
|
682
|
-
props.onOpenChange?.(next);
|
|
753
|
+
props.onOpenChange?.(next, details);
|
|
683
754
|
};
|
|
684
755
|
return [open, change];
|
|
685
756
|
};
|
|
686
757
|
/** The picker's default footer, with a time. */
|
|
687
758
|
const defaultFooter = (calendar) => (_jsx(CalendarTimeRow, { calendar: calendar }));
|
|
688
759
|
/** The compact style's time: its button, the roll in a popover. */
|
|
689
|
-
const TimePopover = ({ align,
|
|
760
|
+
const TimePopover = ({ align, isDisabled, label, onOpenChange, isOpen, shape, ...props }) => {
|
|
690
761
|
const popupRef = useRef(null);
|
|
691
|
-
return (_jsxs(Popover.Root, { open:
|
|
762
|
+
return (_jsxs(Popover.Root, { open: isOpen, onOpenChange: onOpenChange, children: [_jsx(Popover.Trigger, { "aria-label": "Time", disabled: isDisabled, render: _jsx(CollapsedButton, { shape: shape }), children: label }), _jsx(Popover.Portal, { children: _jsx(Popover.Positioner, { align: align, children: _jsx(Popover.Popup, { ref: popupRef, "aria-label": "Time", className: "uikit-date-picker-popup", "data-date-picker-part": "popup",
|
|
692
763
|
// The popup (not the first column: focused while the popup
|
|
693
764
|
// opens, Chrome scrolls it off its selection).
|
|
694
765
|
initialFocus: popupRef, children: _jsx("div", { className: "uikit-date-picker-time-popup", "data-date-picker-part": "time-popup", children: _jsx(TimeRoll, { ...props }) }) }) }) })] }));
|
|
@@ -707,32 +778,86 @@ const dateLabelOf = (format, range, single) => {
|
|
|
707
778
|
* time, from the time's too, with the time's roll shown (as iOS's; one
|
|
708
779
|
* popover for both).
|
|
709
780
|
*/
|
|
710
|
-
const CalendarPopover = ({ align, children, dateLabel,
|
|
781
|
+
const CalendarPopover = ({ align, children, dateLabel, isDisabled, onOpenChange, open, shape, timeLabel, }) => {
|
|
711
782
|
const dateTriggerId = useId();
|
|
712
783
|
const timeTriggerId = useId();
|
|
713
784
|
const collapsedRef = useRef(null);
|
|
714
785
|
const hasTime = timeLabel !== undefined;
|
|
715
786
|
// The time's button is the open one while the time's roll shows (however
|
|
716
787
|
// it was opened, or shown), the date's otherwise.
|
|
717
|
-
const [
|
|
788
|
+
const [isTimeShown, setIsTimeShown] = useState(open === 'time');
|
|
718
789
|
const [openBefore, setOpenBefore] = useState(open);
|
|
719
790
|
if (open !== openBefore) {
|
|
720
791
|
setOpenBefore(open);
|
|
721
|
-
|
|
792
|
+
setIsTimeShown(open === 'time');
|
|
722
793
|
}
|
|
723
794
|
// Positioned at both buttons together, whichever opened it.
|
|
724
|
-
return (_jsx("div", { ref: collapsedRef, className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: _jsxs(Popover.Root, { open: open === 'date' || (hasTime && open === 'time'), triggerId: hasTime &&
|
|
795
|
+
return (_jsx("div", { ref: collapsedRef, className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: _jsxs(Popover.Root, { open: open === 'date' || (hasTime && open === 'time'), triggerId: hasTime && isTimeShown ? timeTriggerId : dateTriggerId, onOpenChange: (isOpen, { event, reason }) => {
|
|
725
796
|
const trigger = event.target instanceof Element
|
|
726
797
|
? event.target.closest('[data-date-picker-trigger]')
|
|
727
798
|
: null;
|
|
728
799
|
const picker = trigger?.dataset.datePickerTrigger === 'time' ? 'time' : 'date';
|
|
729
|
-
onOpenChange(
|
|
730
|
-
}, children: [_jsx(Popover.Trigger, { "data-date-picker-trigger": "date", disabled:
|
|
800
|
+
onOpenChange(isOpen ? picker : null, { event, reason });
|
|
801
|
+
}, children: [_jsx(Popover.Trigger, { "data-date-picker-trigger": "date", disabled: isDisabled, id: dateTriggerId, render: _jsx(CollapsedButton, { shape: shape }), children: dateLabel }), hasTime ? (_jsx(Popover.Trigger, { "aria-label": "Time", "data-date-picker-trigger": "time", disabled: isDisabled, id: timeTriggerId, render: _jsx(CollapsedButton, { shape: shape }), children: timeLabel })) : null, _jsx(Popover.Portal, { children: _jsx(Popover.Positioner, { align: align, anchor: collapsedRef, children: _jsx(Popover.Popup, { "aria-label": hasTime ? 'Date and time' : 'Date', className: "uikit-date-picker-popup", "data-date-picker-part": "popup", children: _jsx(Fragment, { children: children(open === 'time' ? 'time' : undefined, setIsTimeShown) }, open ?? 'closed') }) }) })] }) }));
|
|
731
802
|
};
|
|
732
803
|
/** The compact style's buttons, toggling `open` (without popovers). */
|
|
733
|
-
const ToggleButtons = ({ dateLabel,
|
|
734
|
-
const toggle = (picker) => onOpenChange(open === picker ? null : picker
|
|
735
|
-
|
|
804
|
+
const ToggleButtons = ({ dateLabel, isDisabled, onOpenChange, open, shape, timeLabel }) => {
|
|
805
|
+
const toggle = (picker, event) => onOpenChange(open === picker ? null : picker, {
|
|
806
|
+
event,
|
|
807
|
+
reason: 'trigger-press',
|
|
808
|
+
});
|
|
809
|
+
// Disabled while open (`isDisabled`, or from around it: e.g. a disabled
|
|
810
|
+
// fieldset's): closed (with a handle, its rows).
|
|
811
|
+
const ref = useRef(null);
|
|
812
|
+
useLayoutEffect(() => {
|
|
813
|
+
if (open === null)
|
|
814
|
+
return;
|
|
815
|
+
const button = ref.current?.querySelector('button');
|
|
816
|
+
if (!isDisabled && !button?.matches(':disabled'))
|
|
817
|
+
return;
|
|
818
|
+
onOpenChange(null, { event: new Event('disable'), reason: 'none' });
|
|
819
|
+
});
|
|
820
|
+
return (_jsxs("div", { ref: ref, className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: [dateLabel === undefined ? null : (_jsx(CollapsedButton, { "aria-expanded": open === 'date', disabled: isDisabled, shape: shape, onClick: (event) => toggle('date', event), children: dateLabel })), timeLabel === undefined ? null : (_jsx(CollapsedButton, { "aria-expanded": open === 'time', "aria-label": "Time", disabled: isDisabled, shape: shape, onClick: (event) => toggle('time', event), children: timeLabel }))] }));
|
|
821
|
+
};
|
|
822
|
+
/**
|
|
823
|
+
* A picker in collapsible list rows (see `List.CollapsiblePanel`): closed
|
|
824
|
+
* with them. With a handle, in a collapsible (e.g. a `List.AccordionItem`,
|
|
825
|
+
* with its row and `Expandable`): open with it, opening it, closed with it
|
|
826
|
+
* (e.g. another item opening).
|
|
827
|
+
*/
|
|
828
|
+
const useListSync = (handle, open, changeOpen) => {
|
|
829
|
+
const isShown = useExpandedOpen();
|
|
830
|
+
const collapsible = useCollapsible();
|
|
831
|
+
const item = handle ? collapsible : undefined;
|
|
832
|
+
const isPickerOpen = open !== null;
|
|
833
|
+
const syncRef = useRef({
|
|
834
|
+
close: () => undefined,
|
|
835
|
+
toggleItem: () => undefined,
|
|
836
|
+
});
|
|
837
|
+
useLayoutEffect(() => {
|
|
838
|
+
syncRef.current = {
|
|
839
|
+
close: () => {
|
|
840
|
+
if (open === null)
|
|
841
|
+
return;
|
|
842
|
+
changeOpen(null, { event: new Event('close'), reason: 'none' });
|
|
843
|
+
},
|
|
844
|
+
toggleItem: () => {
|
|
845
|
+
if (!item || item.isOpen === isPickerOpen)
|
|
846
|
+
return;
|
|
847
|
+
item.setOpen(isPickerOpen, {
|
|
848
|
+
event: new Event('toggle'),
|
|
849
|
+
reason: 'none',
|
|
850
|
+
});
|
|
851
|
+
},
|
|
852
|
+
};
|
|
853
|
+
});
|
|
854
|
+
useEffect(() => {
|
|
855
|
+
if (isShown === false || item?.isOpen === false)
|
|
856
|
+
syncRef.current.close();
|
|
857
|
+
}, [isShown, item?.isOpen]);
|
|
858
|
+
useEffect(() => {
|
|
859
|
+
syncRef.current.toggleItem();
|
|
860
|
+
}, [isPickerOpen]);
|
|
736
861
|
};
|
|
737
862
|
/**
|
|
738
863
|
* A date picker (UIKit `UIDatePicker`): a date, a time or both (`mode`), or
|
|
@@ -740,7 +865,7 @@ const ToggleButtons = ({ dateLabel, disabled, onOpenChange, open, shape, timeLab
|
|
|
740
865
|
* time in a popover (or toggling `open`, without `popover`), or the
|
|
741
866
|
* calendar in place (`pickerStyle`).
|
|
742
867
|
*/
|
|
743
|
-
const
|
|
868
|
+
const Root = (props) => {
|
|
744
869
|
const { buttonShape, disabled = false, hourCycle, locale, mode = 'date', pickerStyle = 'compact', popover = true, } = props;
|
|
745
870
|
const { change, range, single } = usePickerValue(props);
|
|
746
871
|
const [open, changeOpen] = usePickerOpen(props);
|
|
@@ -751,20 +876,56 @@ const DatePicker = (props) => {
|
|
|
751
876
|
const hasDate = props.range || mode !== 'time';
|
|
752
877
|
const hasTime = !props.range && mode !== 'date';
|
|
753
878
|
const calendarProps = calendarPropsOf(props, change, range ?? single);
|
|
879
|
+
useListSync(props.handle, open, changeOpen);
|
|
880
|
+
// With a handle: its pickers, for its `Expandable`.
|
|
881
|
+
const { handle } = props;
|
|
882
|
+
useLayoutEffect(() => {
|
|
883
|
+
handle?.publish({
|
|
884
|
+
calendar: hasDate ? _jsx(CalendarPanel, { ...calendarProps }) : undefined,
|
|
885
|
+
open,
|
|
886
|
+
time: hasTime ? (_jsx(TimeRoll, { hourCycle: hourCycle, locale: locale, max: props.max, min: props.min, value: single, onValueChange: change })) : undefined,
|
|
887
|
+
});
|
|
888
|
+
});
|
|
889
|
+
useLayoutEffect(() => () => handle?.publish(undefined), [handle]);
|
|
754
890
|
// With a time, by default the Time row below.
|
|
755
891
|
const calendar = (initialRoll, onTimeShownChange) => (_jsx(CalendarPanel, { ...calendarProps, footer: props.footer ?? (hasTime ? defaultFooter : undefined), initialRoll: initialRoll, time: hasTime ? { disabled, shape: buttonShape } : undefined, onTimeShownChange: onTimeShownChange }));
|
|
756
|
-
|
|
757
|
-
|
|
892
|
+
// Its value's hidden control (see `name`), beside what it shows.
|
|
893
|
+
const formValue = (_jsx(FormValue, { form: props.form, mode: props.range ? 'date' : mode, name: props.name, value: range ?? single }));
|
|
894
|
+
if (pickerStyle === 'inline' && hasDate) {
|
|
895
|
+
return (_jsxs(_Fragment, { children: [calendar(), formValue] }));
|
|
896
|
+
}
|
|
758
897
|
const dateLabel = dateLabelOf(formats.date, range, single);
|
|
759
898
|
const timeLabel = single ? formats.time.format(single) : '–';
|
|
760
|
-
// Without popovers: buttons toggling `open` (for the app to show them
|
|
761
|
-
|
|
762
|
-
|
|
899
|
+
// Without popovers: buttons toggling `open` (for the app to show them,
|
|
900
|
+
// or, with a handle, its `Expandable`).
|
|
901
|
+
if (!popover || props.handle) {
|
|
902
|
+
return (_jsxs(_Fragment, { children: [_jsx(ToggleButtons, { dateLabel: hasDate ? dateLabel : undefined, isDisabled: disabled, open: open, shape: buttonShape, timeLabel: hasTime ? timeLabel : undefined, onOpenChange: changeOpen }), formValue] }));
|
|
763
903
|
}
|
|
764
904
|
if (!hasDate) {
|
|
765
|
-
return (
|
|
905
|
+
return (_jsxs("div", { className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: [formValue, _jsx(TimePopover, { align: props.popoverAlign, hourCycle: hourCycle, isDisabled: disabled, isOpen: open === 'time', label: timeLabel, locale: locale, max: props.max, min: props.min, shape: buttonShape, value: single, onValueChange: change, onOpenChange: (isOpen, { event, reason }) => changeOpen(isOpen ? 'time' : null, { event, reason }) })] }));
|
|
766
906
|
}
|
|
767
|
-
return (_jsx(CalendarPopover, { align: props.popoverAlign, dateLabel: dateLabel,
|
|
907
|
+
return (_jsxs(_Fragment, { children: [_jsx(CalendarPopover, { align: props.popoverAlign, dateLabel: dateLabel, isDisabled: disabled, open: open, shape: buttonShape, timeLabel: hasTime ? timeLabel : undefined, onOpenChange: changeOpen, children: (initialRoll, onTimeShownChange) => calendar(initialRoll, onTimeShownChange) }), formValue] }));
|
|
908
|
+
};
|
|
909
|
+
/**
|
|
910
|
+
* A date picker's pickers in place (see `Root` `handle`): its calendar and
|
|
911
|
+
* time roll, each in collapsible list rows (`List.CollapsiblePanel`),
|
|
912
|
+
* opened by its buttons; placed after the picker's row (as iOS's
|
|
913
|
+
* Calendar). In an `List.AccordionItem` (with its row), one of its items.
|
|
914
|
+
*/
|
|
915
|
+
const Expandable = ({ handle, }) => {
|
|
916
|
+
const { calendar, open, time } = useSyncExternalStore(handle.subscribe, handle.getSnapshot);
|
|
917
|
+
return (_jsxs(_Fragment, { children: [calendar === undefined ? null : (_jsx(List.CollapsibleRoot, { open: open === 'date', children: _jsx(List.CollapsiblePanel, { children: _jsx(List.Item, { children: _jsx(List.Span, { children: calendar }) }) }) })), time === undefined ? null : (_jsx(List.CollapsibleRoot, { open: open === 'time', children: _jsx(List.CollapsiblePanel, { children: _jsx(List.Item, { children: _jsx(List.Span, { children: time }) }) }) }))] }));
|
|
918
|
+
};
|
|
919
|
+
export { DatePickerHandle, useCreateDatePickerHandle } from './handle.js';
|
|
920
|
+
export const DatePicker = {
|
|
921
|
+
Root,
|
|
922
|
+
Expandable,
|
|
923
|
+
createHandle,
|
|
924
|
+
Calendar,
|
|
925
|
+
CalendarRow,
|
|
926
|
+
CalendarButton,
|
|
927
|
+
CalendarTimeRow,
|
|
928
|
+
CalendarMessage,
|
|
929
|
+
TimeRoll,
|
|
768
930
|
};
|
|
769
|
-
export { Calendar, CalendarButton, CalendarMessage, CalendarRow, CalendarTimeRow, DatePicker, TimeRoll, };
|
|
770
931
|
//# sourceMappingURL=main.js.map
|