@tangible/ui 0.2.14 → 0.2.15
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/components/DatePicker/DatePicker.d.ts +19 -1
- package/components/DatePicker/DatePicker.js +73 -16
- package/components/DatePicker/DateRangePicker.d.ts +19 -1
- package/components/DatePicker/DateRangePicker.js +77 -23
- package/components/DatePicker/PickerTrigger.d.ts +38 -0
- package/components/DatePicker/PickerTrigger.js +57 -0
- package/components/DatePicker/index.d.ts +3 -3
- package/components/DatePicker/index.js +2 -2
- package/components/DatePicker/types.d.ts +65 -2
- package/components/Modal/Modal.d.ts +1 -1
- package/components/Modal/Modal.js +49 -9
- package/components/Popover/Popover.js +13 -0
- package/components/index.d.ts +1 -1
- package/components/index.js +1 -1
- package/figma-tokens.json +1 -1
- package/package.json +1 -1
- package/skills/building-with-tui/SKILL.md +66 -2
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +6 -0
- package/styles/all.expanded.unlayered.css +6 -0
- package/styles/all.unlayered.css +1 -1
- package/styles/components/text-input.scss +21 -0
- package/tui-manifest.json +7 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import type { PickerTriggerProps } from './PickerTrigger';
|
|
2
3
|
/** Internal time editor: [HH : MM] [AM|PM] zoneLabel. */
|
|
3
4
|
export declare function TimeField({ value, onChange, hour12, zoneLabel, labels, }: {
|
|
4
5
|
value: Date;
|
|
@@ -7,7 +8,7 @@ export declare function TimeField({ value, onChange, hour12, zoneLabel, labels,
|
|
|
7
8
|
zoneLabel?: React.ReactNode;
|
|
8
9
|
labels: Required<import('./types').DatePickerLabels>;
|
|
9
10
|
}): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
|
|
11
|
+
declare const DatePickerRoot: React.ForwardRefExoticComponent<import("./types").CalendarBaseProps & {
|
|
11
12
|
value?: Date | null;
|
|
12
13
|
defaultValue?: Date | null;
|
|
13
14
|
onChange?: (value: Date) => void;
|
|
@@ -21,6 +22,23 @@ export declare const DatePicker: React.ForwardRefExoticComponent<import("./types
|
|
|
21
22
|
'aria-labelledby'?: string;
|
|
22
23
|
'aria-describedby'?: string;
|
|
23
24
|
'aria-invalid'?: boolean | "true" | "false";
|
|
25
|
+
children?: React.ReactNode;
|
|
24
26
|
className?: string;
|
|
25
27
|
id?: string;
|
|
26
28
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
29
|
+
/**
|
|
30
|
+
* The affordance that opens the picker. Rendered automatically when the root
|
|
31
|
+
* has no children, so `<DatePicker />` keeps working unchanged; render it
|
|
32
|
+
* explicitly to place it inside something else — a text field's suffix slot,
|
|
33
|
+
* a toolbar — and add `asChild` to supply your own element.
|
|
34
|
+
*/
|
|
35
|
+
declare function DatePickerTriggerComponent(props: PickerTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
declare namespace DatePickerTriggerComponent {
|
|
37
|
+
var displayName: string;
|
|
38
|
+
}
|
|
39
|
+
type DatePickerCompound = typeof DatePickerRoot & {
|
|
40
|
+
Trigger: typeof DatePickerTriggerComponent;
|
|
41
|
+
};
|
|
42
|
+
export declare const DatePicker: DatePickerCompound;
|
|
43
|
+
export declare const DatePickerTrigger: typeof DatePickerTriggerComponent;
|
|
44
|
+
export {};
|
|
@@ -3,13 +3,13 @@ import * as React from 'react';
|
|
|
3
3
|
import { cx } from '../../utils/cx.js';
|
|
4
4
|
import { useControllableState } from '../../utils/use-controllable-state.js';
|
|
5
5
|
import { Button } from '../Button/index.js';
|
|
6
|
-
import { Icon } from '../Icon/index.js';
|
|
7
6
|
import { IconButton } from '../IconButton/index.js';
|
|
8
|
-
import { Popover, PopoverContent
|
|
7
|
+
import { Popover, PopoverContent } from '../Popover/index.js';
|
|
9
8
|
import { SegmentedControl } from '../SegmentedControl/index.js';
|
|
10
9
|
import { Select } from '../Select/index.js';
|
|
11
10
|
import { Calendar } from './Calendar.js';
|
|
12
11
|
import { clampDay, daysInMonth, formatDay, formatDayTime, getMonthNames, withDay, resolveLocale, } from './date-utils.js';
|
|
12
|
+
import { PickerTrigger, PickerTriggerProvider } from './PickerTrigger.js';
|
|
13
13
|
import { defaultDatePickerLabels } from './types.js';
|
|
14
14
|
// =============================================================================
|
|
15
15
|
// DatePicker
|
|
@@ -73,7 +73,7 @@ export function TimeField({ value, onChange, hour12, zoneLabel, labels, }) {
|
|
|
73
73
|
setHours(next === 'pm' ? base + 12 : base);
|
|
74
74
|
}, children: [_jsx(SegmentedControl.Item, { value: "am", children: labels.am }), _jsx(SegmentedControl.Item, { value: "pm", children: labels.pm })] })), zoneLabel != null && _jsx("span", { className: "tui-date-picker__zone", children: zoneLabel })] }));
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
const DatePickerRoot = React.forwardRef(function DatePicker({ value: valueProp, defaultValue, onChange, withTime = false, hour12 = true, zoneLabel, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, disabled, labels: labelsProp, calendarLabels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, className, id, children, }, ref) {
|
|
77
77
|
const labels = { ...defaultDatePickerLabels, ...labelsProp };
|
|
78
78
|
const locale = resolveLocale(localeProp);
|
|
79
79
|
const [open, setOpen] = React.useState(false);
|
|
@@ -111,19 +111,76 @@ export const DatePicker = React.forwardRef(function DatePicker({ value: valuePro
|
|
|
111
111
|
: formatDay(value, locale)
|
|
112
112
|
: null;
|
|
113
113
|
const monthNames = getMonthNames(locale);
|
|
114
|
-
|
|
114
|
+
// A consumer who passes children but forgets the Trigger gets a picker that
|
|
115
|
+
// cannot be opened, with nothing on screen to explain it.
|
|
116
|
+
const triggerRendered = React.useRef(false);
|
|
117
|
+
const registerTrigger = React.useCallback(() => {
|
|
118
|
+
triggerRendered.current = true;
|
|
119
|
+
}, []);
|
|
120
|
+
React.useEffect(() => {
|
|
121
|
+
if (process.env.NODE_ENV === 'production')
|
|
122
|
+
return;
|
|
123
|
+
if (children != null && !triggerRendered.current) {
|
|
124
|
+
console.warn('[tui] DatePicker: children were provided but no <DatePicker.Trigger> ' +
|
|
125
|
+
'was rendered among them, so the picker cannot be opened.');
|
|
126
|
+
}
|
|
127
|
+
}, [children]);
|
|
128
|
+
const triggerContext = {
|
|
129
|
+
open,
|
|
130
|
+
disabled,
|
|
131
|
+
blockClass: 'tui-date-picker',
|
|
132
|
+
formatted,
|
|
133
|
+
placeholder: labels.placeholder,
|
|
134
|
+
labelFor: labels.trigger,
|
|
135
|
+
labelEmpty: labels.triggerEmpty,
|
|
136
|
+
valueId,
|
|
137
|
+
id,
|
|
138
|
+
ariaLabel,
|
|
139
|
+
ariaLabelledBy,
|
|
140
|
+
ariaDescribedBy,
|
|
141
|
+
ariaInvalid,
|
|
142
|
+
rootClassName: className,
|
|
143
|
+
forwardedRef: ref,
|
|
144
|
+
registerTrigger,
|
|
145
|
+
};
|
|
146
|
+
return (_jsx(PickerTriggerProvider, { value: triggerContext, children: _jsxs(Popover, { open: open,
|
|
147
|
+
// Guard the OPEN direction only. A custom trigger carries aria-disabled
|
|
148
|
+
// rather than native `disabled`, so it can still be clicked; blocking the
|
|
149
|
+
// close direction too would strand an open popover when a form disables
|
|
150
|
+
// its controls mid-submit (the bug the select family still has).
|
|
151
|
+
onOpenChange: (next) => {
|
|
152
|
+
if (next && disabled)
|
|
153
|
+
return;
|
|
154
|
+
setOpen(next);
|
|
155
|
+
}, children: [children ?? _jsx(PickerTrigger, {}), _jsxs(PopoverContent, { modal: true, side: "bottom", align: "start", className: "tui-date-picker", "aria-label": title, children: [_jsxs("div", { className: "tui-date-picker__head", children: [_jsx("span", { className: "tui-date-picker__title", children: title }), _jsx(Button, { className: "tui-date-picker__now", variant: "ghost", theme: "primary", size: "sm", label: labels.now, onClick: () => commit(clampDay(new Date(), min, max)) }), _jsx(IconButton, { className: "tui-date-picker__close", icon: "system/close", label: labels.close, variant: "ghost", size: "sm", onClick: () => setOpen(false) })] }), withTime && (_jsx(TimeField, { value: base, onChange: commit, hour12: hour12, zoneLabel: zoneLabel, labels: labels })), _jsxs("div", { className: "tui-date-picker__fields", role: "group", "aria-label": labels.dateSection, children: [_jsx("div", { className: "tui-date-picker__month", children: _jsxs(Select, { value: String(base.getMonth()), onValueChange: (m) => {
|
|
156
|
+
const next = new Date(base);
|
|
157
|
+
next.setDate(Math.min(next.getDate(), daysInMonth(new Date(next.getFullYear(), Number(m), 1))));
|
|
158
|
+
next.setMonth(Number(m));
|
|
159
|
+
commit(next);
|
|
160
|
+
}, "aria-label": labels.month, children: [_jsx(Select.Trigger, {}), _jsx(Select.Content, { children: monthNames.map((name, m) => (_jsx(Select.Option, { value: String(m), children: name }, name))) })] }) }), _jsx(NumberSegment, { className: "tui-date-picker__day-field", value: base.getDate(), min: 1, max: daysInMonth(base), pad: false, label: labels.dayOfMonth, onCommit: (d) => {
|
|
161
|
+
const next = new Date(base);
|
|
162
|
+
next.setDate(d);
|
|
163
|
+
commit(next);
|
|
164
|
+
} }), _jsx(NumberSegment, { className: "tui-date-picker__year-field", value: base.getFullYear(), min: 1, max: 9999, pad: false, label: labels.year, onCommit: (y) => {
|
|
115
165
|
const next = new Date(base);
|
|
116
|
-
next.
|
|
117
|
-
next.setMonth(Number(m));
|
|
166
|
+
next.setFullYear(y);
|
|
118
167
|
commit(next);
|
|
119
|
-
}
|
|
120
|
-
const next = new Date(base);
|
|
121
|
-
next.setDate(d);
|
|
122
|
-
commit(next);
|
|
123
|
-
} }), _jsx(NumberSegment, { className: "tui-date-picker__year-field", value: base.getFullYear(), min: 1, max: 9999, pad: false, label: labels.year, onCommit: (y) => {
|
|
124
|
-
const next = new Date(base);
|
|
125
|
-
next.setFullYear(y);
|
|
126
|
-
commit(next);
|
|
127
|
-
} })] }), _jsx(Calendar, { value: value, month: viewMonth, onMonthChange: setViewMonth, onChange: (day) => commit(withDay(value, day)), min: min, max: max, isDayDisabled: isDayDisabled, weekStartsOn: weekStartsOn, locale: locale, labels: calendarLabels })] })] }));
|
|
168
|
+
} })] }), _jsx(Calendar, { value: value, month: viewMonth, onMonthChange: setViewMonth, onChange: (day) => commit(withDay(value, day)), min: min, max: max, isDayDisabled: isDayDisabled, weekStartsOn: weekStartsOn, locale: locale, labels: calendarLabels })] })] }) }));
|
|
128
169
|
});
|
|
129
|
-
|
|
170
|
+
DatePickerRoot.displayName = 'DatePicker';
|
|
171
|
+
// =============================================================================
|
|
172
|
+
// DatePicker.Trigger
|
|
173
|
+
// =============================================================================
|
|
174
|
+
/**
|
|
175
|
+
* The affordance that opens the picker. Rendered automatically when the root
|
|
176
|
+
* has no children, so `<DatePicker />` keeps working unchanged; render it
|
|
177
|
+
* explicitly to place it inside something else — a text field's suffix slot,
|
|
178
|
+
* a toolbar — and add `asChild` to supply your own element.
|
|
179
|
+
*/
|
|
180
|
+
function DatePickerTriggerComponent(props) {
|
|
181
|
+
return _jsx(PickerTrigger, { ...props });
|
|
182
|
+
}
|
|
183
|
+
DatePickerTriggerComponent.displayName = 'DatePicker.Trigger';
|
|
184
|
+
export const DatePicker = DatePickerRoot;
|
|
185
|
+
DatePicker.Trigger = DatePickerTriggerComponent;
|
|
186
|
+
export const DatePickerTrigger = DatePickerTriggerComponent;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { DateRange } from './date-utils';
|
|
3
|
+
import type { PickerTriggerProps } from './PickerTrigger';
|
|
3
4
|
import type { DateRangePreset } from './types';
|
|
4
|
-
|
|
5
|
+
declare const DateRangePickerRoot: React.ForwardRefExoticComponent<import("./types").CalendarBaseProps & {
|
|
5
6
|
value?: DateRange | null;
|
|
6
7
|
defaultValue?: DateRange | null;
|
|
7
8
|
onChange?: (range: DateRange) => void;
|
|
@@ -14,6 +15,23 @@ export declare const DateRangePicker: React.ForwardRefExoticComponent<import("./
|
|
|
14
15
|
'aria-labelledby'?: string;
|
|
15
16
|
'aria-describedby'?: string;
|
|
16
17
|
'aria-invalid'?: boolean | "true" | "false";
|
|
18
|
+
children?: React.ReactNode;
|
|
17
19
|
className?: string;
|
|
18
20
|
id?: string;
|
|
19
21
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
22
|
+
/**
|
|
23
|
+
* The affordance that opens the picker. Rendered automatically when the root
|
|
24
|
+
* has no children, so `<DateRangePicker />` keeps working unchanged; render it
|
|
25
|
+
* explicitly to place it inside something else, and add `asChild` to supply
|
|
26
|
+
* your own element.
|
|
27
|
+
*/
|
|
28
|
+
declare function DateRangePickerTriggerComponent(props: PickerTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
declare namespace DateRangePickerTriggerComponent {
|
|
30
|
+
var displayName: string;
|
|
31
|
+
}
|
|
32
|
+
type DateRangePickerCompound = typeof DateRangePickerRoot & {
|
|
33
|
+
Trigger: typeof DateRangePickerTriggerComponent;
|
|
34
|
+
};
|
|
35
|
+
export declare const DateRangePicker: DateRangePickerCompound;
|
|
36
|
+
export declare const DateRangePickerTrigger: typeof DateRangePickerTriggerComponent;
|
|
37
|
+
export {};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { cx } from '../../utils/cx.js';
|
|
4
3
|
import { useControllableState } from '../../utils/use-controllable-state.js';
|
|
5
4
|
import { Button } from '../Button/index.js';
|
|
6
|
-
import {
|
|
7
|
-
import { Popover, PopoverContent, PopoverTrigger } from '../Popover/index.js';
|
|
5
|
+
import { Popover, PopoverContent } from '../Popover/index.js';
|
|
8
6
|
import { TextInput } from '../TextInput/index.js';
|
|
9
7
|
import { Calendar } from './Calendar.js';
|
|
10
8
|
import { addMonths, formatDay, formatDayTime, formatNumeric, isBeforeDay, isSameMonth, parseNumeric, startOfMonth, resolveLocale, } from './date-utils.js';
|
|
11
9
|
import { defaultDateRangePresets } from './presets.js';
|
|
10
|
+
import { PickerTrigger, PickerTriggerProvider } from './PickerTrigger.js';
|
|
12
11
|
import { defaultDateRangePickerLabels } from './types.js';
|
|
13
12
|
// =============================================================================
|
|
14
13
|
// DateRangePicker
|
|
@@ -21,7 +20,7 @@ import { defaultDateRangePickerLabels } from './types.js';
|
|
|
21
20
|
//
|
|
22
21
|
// =============================================================================
|
|
23
22
|
const EMPTY_RANGE = { from: null, to: null };
|
|
24
|
-
|
|
23
|
+
const DateRangePickerRoot = React.forwardRef(function DateRangePicker({ value: valueProp, defaultValue, onChange, withTime = false, presets = defaultDateRangePresets, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, disabled, labels: labelsProp, calendarLabels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, className, id, children, }, ref) {
|
|
25
24
|
const labels = { ...defaultDateRangePickerLabels, ...labelsProp };
|
|
26
25
|
const locale = resolveLocale(localeProp);
|
|
27
26
|
const [open, setOpen] = React.useState(false);
|
|
@@ -40,6 +39,12 @@ export const DateRangePicker = React.forwardRef(function DateRangePicker({ value
|
|
|
40
39
|
const [viewMonth, setViewMonth] = React.useState(() => value?.from ?? new Date());
|
|
41
40
|
// (Re)open seeds the draft and view from the committed value.
|
|
42
41
|
const handleOpenChange = (next) => {
|
|
42
|
+
// Guard the OPEN direction only. A custom trigger carries aria-disabled
|
|
43
|
+
// rather than native `disabled`, so it can still be clicked; blocking the
|
|
44
|
+
// close direction too would strand an open popover when a form disables
|
|
45
|
+
// its controls mid-submit (the bug the select family still has).
|
|
46
|
+
if (next && disabled)
|
|
47
|
+
return;
|
|
43
48
|
if (next) {
|
|
44
49
|
setDraft(value ?? EMPTY_RANGE);
|
|
45
50
|
setViewMonth(startOfMonth(value?.from ?? new Date()));
|
|
@@ -84,26 +89,75 @@ export const DateRangePicker = React.forwardRef(function DateRangePicker({ value
|
|
|
84
89
|
// Second calendar stays one month ahead; hide nav overlap by letting the
|
|
85
90
|
// left calendar own "previous" and the right own "next".
|
|
86
91
|
const showPresets = presets !== false && presets.length > 0;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
// A consumer who passes children but forgets the Trigger gets a picker that
|
|
93
|
+
// cannot be opened, with nothing on screen to explain it.
|
|
94
|
+
const triggerRendered = React.useRef(false);
|
|
95
|
+
const registerTrigger = React.useCallback(() => {
|
|
96
|
+
triggerRendered.current = true;
|
|
97
|
+
}, []);
|
|
98
|
+
React.useEffect(() => {
|
|
99
|
+
if (process.env.NODE_ENV === 'production')
|
|
100
|
+
return;
|
|
101
|
+
if (children != null && !triggerRendered.current) {
|
|
102
|
+
console.warn('[tui] DateRangePicker: children were provided but no ' +
|
|
103
|
+
'<DateRangePicker.Trigger> was rendered among them, so the picker ' +
|
|
104
|
+
'cannot be opened.');
|
|
105
|
+
}
|
|
106
|
+
}, [children]);
|
|
107
|
+
const triggerContext = {
|
|
108
|
+
open,
|
|
109
|
+
disabled,
|
|
110
|
+
blockClass: 'tui-date-range-picker',
|
|
111
|
+
formatted,
|
|
112
|
+
placeholder: labels.placeholder,
|
|
113
|
+
labelFor: labels.trigger,
|
|
114
|
+
labelEmpty: labels.triggerEmpty,
|
|
115
|
+
valueId,
|
|
116
|
+
id,
|
|
117
|
+
ariaLabel,
|
|
118
|
+
ariaLabelledBy,
|
|
119
|
+
ariaDescribedBy,
|
|
120
|
+
ariaInvalid,
|
|
121
|
+
rootClassName: className,
|
|
122
|
+
forwardedRef: ref,
|
|
123
|
+
registerTrigger,
|
|
124
|
+
};
|
|
125
|
+
return (_jsx(PickerTriggerProvider, { value: triggerContext, children: _jsxs(Popover, { open: open, onOpenChange: handleOpenChange, children: [children ?? _jsx(PickerTrigger, {}), _jsxs(PopoverContent, { modal: true, side: "bottom", align: "start", className: "tui-date-range-picker", "aria-label": labels.triggerEmpty, children: [_jsxs("div", { className: "tui-date-range-picker__body", children: [showPresets && (_jsx("div", { className: "tui-date-range-picker__presets", role: "group", "aria-label": labels.presets, children: presets.map((preset) => (_jsx(Button, { className: "tui-date-range-picker__preset", variant: "ghost", theme: "primary", size: "sm", label: preset.label, onClick: () => applyPreset(preset) }, preset.label))) })), _jsxs("div", { className: "tui-date-range-picker__main", children: [_jsxs("div", { className: "tui-date-range-picker__fields", children: [_jsx(RangeField, { label: labels.from, value: fieldText(draft.from), locale: locale, onCommit: (d) => {
|
|
126
|
+
setDraft((prev) => {
|
|
127
|
+
const next = { ...prev, from: d };
|
|
128
|
+
if (next.to && isBeforeDay(next.to, d))
|
|
129
|
+
next.to = null;
|
|
130
|
+
return next;
|
|
131
|
+
});
|
|
132
|
+
setViewMonth(startOfMonth(d));
|
|
133
|
+
} }), _jsx("span", { className: "tui-date-range-picker__fields-dash", "aria-hidden": "true", children: "-" }), _jsx(RangeField, { label: labels.to, value: fieldText(draft.to), locale: locale, onCommit: (d) => {
|
|
134
|
+
setDraft((prev) => prev.from && isBeforeDay(d, prev.from)
|
|
135
|
+
? { from: d, to: prev.from }
|
|
136
|
+
: { ...prev, to: d });
|
|
137
|
+
} })] }), _jsxs("div", { className: "tui-date-range-picker__calendars", children: [_jsx(Calendar, { className: "tui-date-range-picker__calendar", month: viewMonth, onMonthChange: (m) => {
|
|
138
|
+
// Keep the pair adjacent whichever side navigated.
|
|
139
|
+
setViewMonth(isSameMonth(m, rightMonth) ? addMonths(viewMonth, 1) : m);
|
|
140
|
+
}, onChange: pickDay, range: draft, min: min, max: max, isDayDisabled: isDayDisabled, weekStartsOn: weekStartsOn, locale: locale, labels: calendarLabels }), _jsx(Calendar, { className: "tui-date-range-picker__calendar", month: rightMonth, onMonthChange: (m) => {
|
|
141
|
+
setViewMonth(addMonths(m, -1));
|
|
142
|
+
}, onChange: pickDay, range: draft, min: min, max: max, isDayDisabled: isDayDisabled, weekStartsOn: weekStartsOn, locale: locale, labels: calendarLabels })] })] })] }), _jsxs("div", { className: "tui-date-range-picker__foot", children: [_jsx(Button, { className: "tui-date-range-picker__cancel", variant: "outline", theme: "primary", label: labels.cancel, onClick: () => setOpen(false) }), _jsx(Button, { className: "tui-date-range-picker__apply", theme: "primary", label: labels.apply, disabled: !draft.from || !draft.to, onClick: apply })] })] })] }) }));
|
|
105
143
|
});
|
|
106
|
-
|
|
144
|
+
DateRangePickerRoot.displayName = 'DateRangePicker';
|
|
145
|
+
// =============================================================================
|
|
146
|
+
// DateRangePicker.Trigger
|
|
147
|
+
// =============================================================================
|
|
148
|
+
/**
|
|
149
|
+
* The affordance that opens the picker. Rendered automatically when the root
|
|
150
|
+
* has no children, so `<DateRangePicker />` keeps working unchanged; render it
|
|
151
|
+
* explicitly to place it inside something else, and add `asChild` to supply
|
|
152
|
+
* your own element.
|
|
153
|
+
*/
|
|
154
|
+
function DateRangePickerTriggerComponent(props) {
|
|
155
|
+
return _jsx(PickerTrigger, { ...props });
|
|
156
|
+
}
|
|
157
|
+
DateRangePickerTriggerComponent.displayName = 'DateRangePicker.Trigger';
|
|
158
|
+
export const DateRangePicker = DateRangePickerRoot;
|
|
159
|
+
DateRangePicker.Trigger = DateRangePickerTriggerComponent;
|
|
160
|
+
export const DateRangePickerTrigger = DateRangePickerTriggerComponent;
|
|
107
161
|
/** Editable From/To text field: shows the formatted value, parses on commit. */
|
|
108
162
|
function RangeField({ label, value, locale, onCommit, }) {
|
|
109
163
|
const [text, setText] = React.useState(null);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type PickerTriggerContextValue = {
|
|
3
|
+
open: boolean;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
/** BEM block owning the trigger classes, e.g. `tui-date-picker`. */
|
|
6
|
+
blockClass: string;
|
|
7
|
+
/** Formatted value, or null when empty. */
|
|
8
|
+
formatted: string | null;
|
|
9
|
+
placeholder: string;
|
|
10
|
+
/** Accessible-name fallback for the default trigger when a value is set. */
|
|
11
|
+
labelFor: (formatted: string) => string;
|
|
12
|
+
/** Accessible-name fallback for the default trigger when empty. */
|
|
13
|
+
labelEmpty: string;
|
|
14
|
+
valueId: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
ariaLabel?: string;
|
|
17
|
+
ariaLabelledBy?: string;
|
|
18
|
+
ariaDescribedBy?: string;
|
|
19
|
+
ariaInvalid?: boolean | 'true' | 'false';
|
|
20
|
+
/** `className` from the picker root, which lands on whichever trigger renders. */
|
|
21
|
+
rootClassName?: string;
|
|
22
|
+
forwardedRef: React.Ref<HTMLButtonElement>;
|
|
23
|
+
/** Lets the root warn when children render without a Trigger among them. */
|
|
24
|
+
registerTrigger: () => void;
|
|
25
|
+
};
|
|
26
|
+
export declare const PickerTriggerProvider: React.Provider<PickerTriggerContextValue | null>;
|
|
27
|
+
export type PickerTriggerProps = {
|
|
28
|
+
/**
|
|
29
|
+
* Render `children` as the trigger instead of the built-in input-group
|
|
30
|
+
* button. The child owns its accessible name and receives no chrome — see
|
|
31
|
+
* this file's header for what that costs and why.
|
|
32
|
+
*/
|
|
33
|
+
asChild?: boolean;
|
|
34
|
+
/** Trigger element, used when `asChild` is set. */
|
|
35
|
+
children?: React.ReactNode;
|
|
36
|
+
className?: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function PickerTrigger({ asChild, children, className }: PickerTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { composeRefs, getElementRef } from '../../utils/compose-refs.js';
|
|
5
|
+
import { Icon } from '../Icon/index.js';
|
|
6
|
+
import { PopoverTrigger } from '../Popover/index.js';
|
|
7
|
+
const PickerTriggerContext = React.createContext(null);
|
|
8
|
+
export const PickerTriggerProvider = PickerTriggerContext.Provider;
|
|
9
|
+
export function PickerTrigger({ asChild = false, children, className }) {
|
|
10
|
+
const ctx = React.useContext(PickerTriggerContext);
|
|
11
|
+
if (!ctx) {
|
|
12
|
+
throw new Error('DatePicker.Trigger must be rendered inside a DatePicker or DateRangePicker.');
|
|
13
|
+
}
|
|
14
|
+
const { registerTrigger } = ctx;
|
|
15
|
+
React.useEffect(() => registerTrigger(), [registerTrigger]);
|
|
16
|
+
const childRef = React.useMemo(() => asChild && React.isValidElement(children)
|
|
17
|
+
? getElementRef(children)
|
|
18
|
+
: undefined, [asChild, children]);
|
|
19
|
+
// Memoised, not inlined: a fresh callback ref on every render detaches and
|
|
20
|
+
// re-attaches the node each time, and the popover re-renders per keystroke.
|
|
21
|
+
const composedRef = React.useMemo(() => composeRefs(ctx.forwardedRef, childRef), [ctx.forwardedRef, childRef]);
|
|
22
|
+
if (asChild) {
|
|
23
|
+
if (!React.isValidElement(children)) {
|
|
24
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
25
|
+
console.warn('[tui] Trigger: `asChild` needs a single React element child. ' +
|
|
26
|
+
'Falling back to the built-in trigger.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const childProps = children.props;
|
|
31
|
+
// cloneElement merges by key, and an explicit `undefined` still overrides
|
|
32
|
+
// — so only set what we actually have, or the child loses its own id and
|
|
33
|
+
// its own labels.
|
|
34
|
+
const props = { ref: composedRef };
|
|
35
|
+
if (ctx.id !== undefined)
|
|
36
|
+
props.id = ctx.id;
|
|
37
|
+
if (ctx.ariaLabel !== undefined)
|
|
38
|
+
props['aria-label'] = ctx.ariaLabel;
|
|
39
|
+
if (ctx.ariaLabelledBy !== undefined)
|
|
40
|
+
props['aria-labelledby'] = ctx.ariaLabelledBy;
|
|
41
|
+
if (ctx.ariaDescribedBy !== undefined)
|
|
42
|
+
props['aria-describedby'] = ctx.ariaDescribedBy;
|
|
43
|
+
if (ctx.ariaInvalid !== undefined)
|
|
44
|
+
props['aria-invalid'] = ctx.ariaInvalid;
|
|
45
|
+
if (ctx.disabled) {
|
|
46
|
+
props['aria-disabled'] = true;
|
|
47
|
+
props['data-disabled'] = true;
|
|
48
|
+
}
|
|
49
|
+
const merged = cx(childProps.className, ctx.rootClassName, className);
|
|
50
|
+
if (merged)
|
|
51
|
+
props.className = merged;
|
|
52
|
+
return (_jsx(PopoverTrigger, { asChild: true, children: React.cloneElement(children, props) }));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const { formatted } = ctx;
|
|
56
|
+
return (_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: composeRefs(ctx.forwardedRef), type: "button", id: ctx.id, disabled: ctx.disabled, className: cx('tui-input-group', `${ctx.blockClass}__trigger`, ctx.disabled && 'is-disabled', ctx.rootClassName, className), "aria-haspopup": "dialog", "aria-expanded": ctx.open, "aria-label": ctx.ariaLabel ?? (formatted ? ctx.labelFor(formatted) : ctx.labelEmpty), "aria-labelledby": ctx.ariaLabelledBy ? `${ctx.ariaLabelledBy} ${ctx.valueId}` : undefined, "aria-describedby": ctx.ariaDescribedBy, "aria-invalid": ctx.ariaInvalid, children: [_jsx("span", { id: ctx.valueId, className: cx(`${ctx.blockClass}__trigger-value`, !formatted && 'is-placeholder'), children: formatted ?? ctx.placeholder }), _jsx("span", { className: "tui-input-group__suffix", children: _jsx(Icon, { name: "lms/calendar", size: "sm" }) })] }) }));
|
|
57
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { Calendar } from './Calendar';
|
|
2
|
-
export { DatePicker } from './DatePicker';
|
|
3
|
-
export { DateRangePicker } from './DateRangePicker';
|
|
2
|
+
export { DatePicker, DatePickerTrigger } from './DatePicker';
|
|
3
|
+
export { DateRangePicker, DateRangePickerTrigger } from './DateRangePicker';
|
|
4
4
|
export { defaultDateRangePresets } from './presets';
|
|
5
5
|
export { addDays, addMonths, addYears, isSameDay, withDay, } from './date-utils';
|
|
6
6
|
export type { DateRange, WeekStart } from './date-utils';
|
|
7
|
-
export type { CalendarProps, CalendarLabels, DatePickerProps, DatePickerLabels, DateRangePickerProps, DateRangePickerLabels, DateRangePreset, } from './types';
|
|
7
|
+
export type { CalendarProps, CalendarLabels, DatePickerProps, DatePickerTriggerProps, DatePickerLabels, DateRangePickerProps, DateRangePickerTriggerProps, DateRangePickerLabels, DateRangePreset, } from './types';
|
|
8
8
|
export { defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Calendar } from './Calendar.js';
|
|
2
|
-
export { DatePicker } from './DatePicker.js';
|
|
3
|
-
export { DateRangePicker } from './DateRangePicker.js';
|
|
2
|
+
export { DatePicker, DatePickerTrigger } from './DatePicker.js';
|
|
3
|
+
export { DateRangePicker, DateRangePickerTrigger } from './DateRangePicker.js';
|
|
4
4
|
export { defaultDateRangePresets } from './presets.js';
|
|
5
5
|
export { addDays, addMonths, addYears, isSameDay, withDay, } from './date-utils.js';
|
|
6
6
|
export { defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './types.js';
|
|
@@ -102,7 +102,8 @@ export type DatePickerProps = CalendarBaseProps & {
|
|
|
102
102
|
* ID of the element that labels the trigger. `Field.Control` injects this,
|
|
103
103
|
* and it outranks `aria-label` per AccName 2A — which is why the trigger's
|
|
104
104
|
* own `aria-label` fallback does not have to change. The trigger's value span
|
|
105
|
-
* is appended so the current date stays audible
|
|
105
|
+
* is appended so the current date stays audible — except under `asChild`,
|
|
106
|
+
* where there is no value span and a phantom id would strip the name.
|
|
106
107
|
*/
|
|
107
108
|
'aria-labelledby'?: string;
|
|
108
109
|
/**
|
|
@@ -116,9 +117,46 @@ export type DatePickerProps = CalendarBaseProps & {
|
|
|
116
117
|
* `tui-input-group` — that is what lights the danger border.
|
|
117
118
|
*/
|
|
118
119
|
'aria-invalid'?: boolean | 'true' | 'false';
|
|
120
|
+
/**
|
|
121
|
+
* Trigger placement. Omit and the picker renders its own input-group button,
|
|
122
|
+
* exactly as before. Provide children to place the trigger yourself — inside
|
|
123
|
+
* a text field's suffix slot, a toolbar — with `<DatePicker.Trigger>` marking
|
|
124
|
+
* the spot, and `asChild` on that Trigger to supply your own element:
|
|
125
|
+
*
|
|
126
|
+
* ```tsx
|
|
127
|
+
* <DatePicker value={date} onChange={commit}>
|
|
128
|
+
* <TextInput
|
|
129
|
+
* value={text}
|
|
130
|
+
* onChange={(e) => setText(e.target.value)}
|
|
131
|
+
* suffix={
|
|
132
|
+
* <DatePicker.Trigger asChild>
|
|
133
|
+
* <IconButton icon="lms/calendar" label="Pick a date" />
|
|
134
|
+
* </DatePicker.Trigger>
|
|
135
|
+
* }
|
|
136
|
+
* />
|
|
137
|
+
* </DatePicker>
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* Children with no Trigger among them leaves the picker unopenable; a dev
|
|
141
|
+
* warning fires for that case.
|
|
142
|
+
*/
|
|
143
|
+
children?: ReactNode;
|
|
119
144
|
className?: string;
|
|
120
145
|
id?: string;
|
|
121
146
|
};
|
|
147
|
+
/**
|
|
148
|
+
* Props for `DatePicker.Trigger` / `DateRangePicker.Trigger`.
|
|
149
|
+
*
|
|
150
|
+
* `asChild` renders your own element in place of the built-in input-group
|
|
151
|
+
* button. The child then owns its accessible name (the selected value is not
|
|
152
|
+
* appended to it), receives no `tui-input-group` chrome — so a forwarded
|
|
153
|
+
* `aria-invalid` lands but paints nothing — and takes `aria-disabled` +
|
|
154
|
+
* `data-disabled` rather than a native `disabled`, since it may not be a
|
|
155
|
+
* `<button>`. It must be natively focusable and keyboard-activatable: no key
|
|
156
|
+
* handler is attached, so Enter/Space activation is whatever the child brings.
|
|
157
|
+
*/
|
|
158
|
+
export type { PickerTriggerProps as DatePickerTriggerProps } from './PickerTrigger';
|
|
159
|
+
export type { PickerTriggerProps as DateRangePickerTriggerProps } from './PickerTrigger';
|
|
122
160
|
export type DateRangePreset = {
|
|
123
161
|
label: string;
|
|
124
162
|
/** Resolve the preset against "now" so stories/tests can pin the clock. */
|
|
@@ -155,7 +193,8 @@ export type DateRangePickerProps = CalendarBaseProps & {
|
|
|
155
193
|
* ID of the element that labels the trigger. `Field.Control` injects this,
|
|
156
194
|
* and it outranks `aria-label` per AccName 2A — which is why the trigger's
|
|
157
195
|
* own `aria-label` fallback does not have to change. The trigger's value span
|
|
158
|
-
* is appended so the current date stays audible
|
|
196
|
+
* is appended so the current date stays audible — except under `asChild`,
|
|
197
|
+
* where there is no value span and a phantom id would strip the name.
|
|
159
198
|
*/
|
|
160
199
|
'aria-labelledby'?: string;
|
|
161
200
|
/**
|
|
@@ -169,6 +208,30 @@ export type DateRangePickerProps = CalendarBaseProps & {
|
|
|
169
208
|
* `tui-input-group` — that is what lights the danger border.
|
|
170
209
|
*/
|
|
171
210
|
'aria-invalid'?: boolean | 'true' | 'false';
|
|
211
|
+
/**
|
|
212
|
+
* Trigger placement. Omit and the picker renders its own input-group button,
|
|
213
|
+
* exactly as before. Provide children to place the trigger yourself — inside
|
|
214
|
+
* a text field's suffix slot, a toolbar — with `<DateRangePicker.Trigger>` marking
|
|
215
|
+
* the spot, and `asChild` on that Trigger to supply your own element:
|
|
216
|
+
*
|
|
217
|
+
* ```tsx
|
|
218
|
+
* <DateRangePicker value={range} onChange={commit}>
|
|
219
|
+
* <TextInput
|
|
220
|
+
* value={text}
|
|
221
|
+
* onChange={(e) => setText(e.target.value)}
|
|
222
|
+
* suffix={
|
|
223
|
+
* <DateRangePicker.Trigger asChild>
|
|
224
|
+
* <IconButton icon="lms/calendar" label="Pick a date range" />
|
|
225
|
+
* </DateRangePicker.Trigger>
|
|
226
|
+
* }
|
|
227
|
+
* />
|
|
228
|
+
* </DateRangePicker>
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* Children with no Trigger among them leaves the picker unopenable; a dev
|
|
232
|
+
* warning fires for that case.
|
|
233
|
+
*/
|
|
234
|
+
children?: ReactNode;
|
|
172
235
|
className?: string;
|
|
173
236
|
id?: string;
|
|
174
237
|
};
|
|
@@ -26,7 +26,7 @@ export type ModalProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'role' | 'ar
|
|
|
26
26
|
className?: string;
|
|
27
27
|
children?: React.ReactNode;
|
|
28
28
|
};
|
|
29
|
-
declare function ModalRoot({ open, onClose, size, stickyHead, stickyFoot, 'aria-labelledby': labelledBy, 'aria-describedby': describedBy, initialFocusSelector, container, showCloseButton, closeLabel, closeOnBackdropClick, closeOnEscape, preventScrollOnRestore, className, children, ...rest }: ModalProps):
|
|
29
|
+
declare function ModalRoot({ open, onClose, size, stickyHead, stickyFoot, 'aria-labelledby': labelledBy, 'aria-describedby': describedBy, initialFocusSelector, container, showCloseButton, closeLabel, closeOnBackdropClick, closeOnEscape, preventScrollOnRestore, className, children, ...rest }: ModalProps): import("react/jsx-runtime").JSX.Element | null;
|
|
30
30
|
type ModalCloseProps = {
|
|
31
31
|
label?: string;
|
|
32
32
|
className?: string;
|