@xeonr/platform-ui 1.11.0 → 1.12.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/auth/AuthCode.d.ts +48 -0
- package/dist/auth/AuthCode.d.ts.map +1 -0
- package/dist/auth/AuthCode.js +197 -0
- package/dist/auth/AuthCode.js.map +1 -0
- package/dist/auth/AuthConsent.d.ts +69 -0
- package/dist/auth/AuthConsent.d.ts.map +1 -0
- package/dist/auth/AuthConsent.js +155 -0
- package/dist/auth/AuthConsent.js.map +1 -0
- package/dist/auth/AuthControls.d.ts +133 -0
- package/dist/auth/AuthControls.d.ts.map +1 -0
- package/dist/auth/AuthControls.js +379 -0
- package/dist/auth/AuthControls.js.map +1 -0
- package/dist/auth/AuthPanel.d.ts +106 -0
- package/dist/auth/AuthPanel.d.ts.map +1 -0
- package/dist/auth/AuthPanel.js +317 -0
- package/dist/auth/AuthPanel.js.map +1 -0
- package/dist/auth.d.ts +5 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +15 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kit/Anchored.js +109 -109
- package/dist/kit/Anchored.js.map +1 -1
- package/dist/kit/ApiKeyForm.js +73 -73
- package/dist/kit/ApiKeyForm.js.map +1 -1
- package/dist/kit/ApiKeys.js +144 -144
- package/dist/kit/ApiKeys.js.map +1 -1
- package/dist/kit/Badge.js +45 -45
- package/dist/kit/Badge.js.map +1 -1
- package/dist/kit/Blocks.d.ts.map +1 -1
- package/dist/kit/Blocks.js +103 -102
- package/dist/kit/Blocks.js.map +1 -1
- package/dist/kit/Board.js +54 -54
- package/dist/kit/Board.js.map +1 -1
- package/dist/kit/Button.d.ts +3 -3
- package/dist/kit/Button.d.ts.map +1 -1
- package/dist/kit/Button.js +55 -50
- package/dist/kit/Button.js.map +1 -1
- package/dist/kit/Card.d.ts.map +1 -1
- package/dist/kit/Card.js +36 -29
- package/dist/kit/Card.js.map +1 -1
- package/dist/kit/ChartFrame.js +54 -54
- package/dist/kit/ChartFrame.js.map +1 -1
- package/dist/kit/ChartTypes.js +215 -215
- package/dist/kit/ChartTypes.js.map +1 -1
- package/dist/kit/Charts.js +605 -605
- package/dist/kit/Charts.js.map +1 -1
- package/dist/kit/Checkbox.js +16 -16
- package/dist/kit/Checkbox.js.map +1 -1
- package/dist/kit/Chip.js +21 -21
- package/dist/kit/Chip.js.map +1 -1
- package/dist/kit/Choice.js +24 -24
- package/dist/kit/Choice.js.map +1 -1
- package/dist/kit/CodeEditor.js +25 -25
- package/dist/kit/CodeEditor.js.map +1 -1
- package/dist/kit/Color.js +74 -74
- package/dist/kit/Color.js.map +1 -1
- package/dist/kit/Combobox.js +67 -67
- package/dist/kit/Combobox.js.map +1 -1
- package/dist/kit/CommandPalette.d.ts.map +1 -1
- package/dist/kit/CommandPalette.js +96 -86
- package/dist/kit/CommandPalette.js.map +1 -1
- package/dist/kit/Comment.js +7 -7
- package/dist/kit/Comment.js.map +1 -1
- package/dist/kit/Controls.js +122 -122
- package/dist/kit/Controls.js.map +1 -1
- package/dist/kit/DataGrid.js +97 -97
- package/dist/kit/DataGrid.js.map +1 -1
- package/dist/kit/DataTable.d.ts.map +1 -1
- package/dist/kit/DataTable.js +196 -195
- package/dist/kit/DataTable.js.map +1 -1
- package/dist/kit/DatePicker.js +242 -242
- package/dist/kit/DatePicker.js.map +1 -1
- package/dist/kit/Drawer.d.ts.map +1 -1
- package/dist/kit/Drawer.js +15 -14
- package/dist/kit/Drawer.js.map +1 -1
- package/dist/kit/Dropzone.js +80 -80
- package/dist/kit/Dropzone.js.map +1 -1
- package/dist/kit/Editable.d.ts.map +1 -1
- package/dist/kit/Editable.js +130 -129
- package/dist/kit/Editable.js.map +1 -1
- package/dist/kit/EmptyState.d.ts.map +1 -1
- package/dist/kit/EmptyState.js +14 -13
- package/dist/kit/EmptyState.js.map +1 -1
- package/dist/kit/EntityHeader.d.ts.map +1 -1
- package/dist/kit/EntityHeader.js +17 -16
- package/dist/kit/EntityHeader.js.map +1 -1
- package/dist/kit/Facet.js +52 -52
- package/dist/kit/Facet.js.map +1 -1
- package/dist/kit/FacetRail.js +91 -91
- package/dist/kit/FacetRail.js.map +1 -1
- package/dist/kit/Forbidden.js +7 -7
- package/dist/kit/Forbidden.js.map +1 -1
- package/dist/kit/Form.d.ts.map +1 -1
- package/dist/kit/Form.js +144 -143
- package/dist/kit/Form.js.map +1 -1
- package/dist/kit/Graph.js +429 -429
- package/dist/kit/Graph.js.map +1 -1
- package/dist/kit/GroupedMultiSelect.js +115 -115
- package/dist/kit/GroupedMultiSelect.js.map +1 -1
- package/dist/kit/Icon.d.ts +2 -0
- package/dist/kit/Icon.d.ts.map +1 -1
- package/dist/kit/Icon.js +3 -1
- package/dist/kit/Icon.js.map +1 -1
- package/dist/kit/JumpList.js +11 -11
- package/dist/kit/JumpList.js.map +1 -1
- package/dist/kit/KV.js +6 -6
- package/dist/kit/KV.js.map +1 -1
- package/dist/kit/Layout.js +5 -5
- package/dist/kit/Layout.js.map +1 -1
- package/dist/kit/List.js +74 -74
- package/dist/kit/List.js.map +1 -1
- package/dist/kit/LogView.js +68 -68
- package/dist/kit/LogView.js.map +1 -1
- package/dist/kit/Markdown.js +37 -37
- package/dist/kit/Markdown.js.map +1 -1
- package/dist/kit/Marker.js +42 -42
- package/dist/kit/Marker.js.map +1 -1
- package/dist/kit/Menu.js +128 -128
- package/dist/kit/Menu.js.map +1 -1
- package/dist/kit/Modal.d.ts.map +1 -1
- package/dist/kit/Modal.js +86 -75
- package/dist/kit/Modal.js.map +1 -1
- package/dist/kit/MultiCombobox.js +157 -157
- package/dist/kit/MultiCombobox.js.map +1 -1
- package/dist/kit/PageHeader.d.ts.map +1 -1
- package/dist/kit/PageHeader.js +8 -7
- package/dist/kit/PageHeader.js.map +1 -1
- package/dist/kit/Panel.d.ts.map +1 -1
- package/dist/kit/Panel.js +33 -14
- package/dist/kit/Panel.js.map +1 -1
- package/dist/kit/Picker.js +159 -159
- package/dist/kit/Picker.js.map +1 -1
- package/dist/kit/PipelineFlow.js +86 -86
- package/dist/kit/PipelineFlow.js.map +1 -1
- package/dist/kit/Popover.js +67 -67
- package/dist/kit/Popover.js.map +1 -1
- package/dist/kit/Range.js +76 -76
- package/dist/kit/Range.js.map +1 -1
- package/dist/kit/Reorder.js +95 -95
- package/dist/kit/Reorder.js.map +1 -1
- package/dist/kit/Search.js +27 -27
- package/dist/kit/Search.js.map +1 -1
- package/dist/kit/Secret.js +26 -26
- package/dist/kit/Secret.js.map +1 -1
- package/dist/kit/Skeleton.js +14 -14
- package/dist/kit/Skeleton.js.map +1 -1
- package/dist/kit/Sparkline.js +51 -51
- package/dist/kit/Sparkline.js.map +1 -1
- package/dist/kit/Spectrum.js +163 -163
- package/dist/kit/Spectrum.js.map +1 -1
- package/dist/kit/Splash.js +3 -3
- package/dist/kit/Splash.js.map +1 -1
- package/dist/kit/Split.js +13 -13
- package/dist/kit/Split.js.map +1 -1
- package/dist/kit/SplitButton.d.ts.map +1 -1
- package/dist/kit/SplitButton.js +8 -6
- package/dist/kit/SplitButton.js.map +1 -1
- package/dist/kit/Stat.d.ts.map +1 -1
- package/dist/kit/Stat.js +61 -60
- package/dist/kit/Stat.js.map +1 -1
- package/dist/kit/Stepper.js +22 -22
- package/dist/kit/Stepper.js.map +1 -1
- package/dist/kit/TabStrip.js +68 -68
- package/dist/kit/TabStrip.js.map +1 -1
- package/dist/kit/Text.js +63 -63
- package/dist/kit/Text.js.map +1 -1
- package/dist/kit/Toast.js +29 -29
- package/dist/kit/Toast.js.map +1 -1
- package/dist/kit/Tooltip.js +83 -83
- package/dist/kit/Tooltip.js.map +1 -1
- package/dist/kit/Trace.js +33 -33
- package/dist/kit/Trace.js.map +1 -1
- package/dist/kit/Upload.js +88 -88
- package/dist/kit/Upload.js.map +1 -1
- package/dist/theme/ThemeProvider.d.ts +17 -1
- package/dist/theme/ThemeProvider.d.ts.map +1 -1
- package/dist/theme/ThemeProvider.js +40 -4
- package/dist/theme/ThemeProvider.js.map +1 -1
- package/dist/theme/ThemeScope.d.ts +9 -1
- package/dist/theme/ThemeScope.d.ts.map +1 -1
- package/dist/theme/ThemeScope.js +11 -4
- package/dist/theme/ThemeScope.js.map +1 -1
- package/dist/theme/tokens.d.ts +48 -0
- package/dist/theme/tokens.d.ts.map +1 -1
- package/dist/theme/tokens.js +167 -3
- package/dist/theme/tokens.js.map +1 -1
- package/package.json +8 -2
- package/scripts/stable-styled-ids.mjs +75 -0
package/dist/kit/DatePicker.js
CHANGED
|
@@ -11,36 +11,36 @@ import { chipCss } from "./Chip.js";
|
|
|
11
11
|
const pad = (n) => String(n).padStart(2, "0");
|
|
12
12
|
/** The local calendar day a Date falls on, as `YYYY-MM-DD`. */
|
|
13
13
|
export function toDayKey(d) {
|
|
14
|
-
|
|
14
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
15
15
|
}
|
|
16
16
|
/** `YYYY-MM-DD` as local midnight, or null if it is not one. Any other Date-parsable string is read and truncated to its local day. */
|
|
17
17
|
export function fromDayKey(s) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
if (!s)
|
|
19
|
+
return null;
|
|
20
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
|
21
|
+
if (m)
|
|
22
|
+
return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
|
|
23
|
+
const d = new Date(s);
|
|
24
|
+
return Number.isNaN(+d) ? null : new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
25
25
|
}
|
|
26
|
-
const asKey = (d) => d === undefined ? null : typeof d === "string" ?
|
|
26
|
+
const asKey = (d) => d === undefined ? null : typeof d === "string" ? fromDayKey(d) ? toDayKey(fromDayKey(d)) : null : toDayKey(d);
|
|
27
27
|
const addDays = (k, n) => {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const d = fromDayKey(k);
|
|
29
|
+
return toDayKey(new Date(d.getFullYear(), d.getMonth(), d.getDate() + n));
|
|
30
30
|
};
|
|
31
31
|
const addMonths = (k, n) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const d = fromDayKey(k);
|
|
33
|
+
const target = new Date(d.getFullYear(), d.getMonth() + n, 1);
|
|
34
|
+
const last = new Date(target.getFullYear(), target.getMonth() + 1, 0).getDate();
|
|
35
|
+
return toDayKey(new Date(target.getFullYear(), target.getMonth(), Math.min(d.getDate(), last)));
|
|
36
36
|
};
|
|
37
37
|
const monthOf = (k) => k.slice(0, 7);
|
|
38
38
|
/* ------------------------------------------------------------------ Calendar */
|
|
39
|
-
const CalWrap = styled.div `
|
|
39
|
+
const CalWrap = styled.div.withConfig({ componentId: "sc-p5dwkk-0" })`
|
|
40
40
|
width: 252px;
|
|
41
41
|
user-select: none;
|
|
42
42
|
`;
|
|
43
|
-
const CalHead = styled.div `
|
|
43
|
+
const CalHead = styled.div.withConfig({ componentId: "sc-p5dwkk-1" })`
|
|
44
44
|
display: flex;
|
|
45
45
|
align-items: center;
|
|
46
46
|
justify-content: space-between;
|
|
@@ -50,11 +50,11 @@ const CalHead = styled.div `
|
|
|
50
50
|
color: ${v.text};
|
|
51
51
|
button:disabled { opacity: 0.35; cursor: not-allowed; background: transparent; }
|
|
52
52
|
`;
|
|
53
|
-
const Week = styled.div `
|
|
53
|
+
const Week = styled.div.withConfig({ componentId: "sc-p5dwkk-2" })`
|
|
54
54
|
display: grid;
|
|
55
55
|
grid-template-columns: repeat(7, 36px);
|
|
56
56
|
`;
|
|
57
|
-
const Weekday = styled.span `
|
|
57
|
+
const Weekday = styled.span.withConfig({ componentId: "sc-p5dwkk-3" })`
|
|
58
58
|
height: 26px;
|
|
59
59
|
display: grid;
|
|
60
60
|
place-items: center;
|
|
@@ -62,13 +62,13 @@ const Weekday = styled.span `
|
|
|
62
62
|
font-weight: 600;
|
|
63
63
|
color: ${v.faint};
|
|
64
64
|
`;
|
|
65
|
-
const Cell = styled.div `
|
|
65
|
+
const Cell = styled.div.withConfig({ componentId: "sc-p5dwkk-4" })`
|
|
66
66
|
padding: 1px 0;
|
|
67
|
-
${(p) => p.$band === "mid" && css
|
|
68
|
-
${(p) => p.$band === "start" && css
|
|
69
|
-
${(p) => p.$band === "end" && css
|
|
67
|
+
${(p) => p.$band === "mid" && css`background: ${v.brand12};`}
|
|
68
|
+
${(p) => p.$band === "start" && css`background: linear-gradient(to right, transparent 50%, ${v.brand12} 50%);`}
|
|
69
|
+
${(p) => p.$band === "end" && css`background: linear-gradient(to left, transparent 50%, ${v.brand12} 50%);`}
|
|
70
70
|
`;
|
|
71
|
-
const Day = styled.button `
|
|
71
|
+
const Day = styled.button.withConfig({ componentId: "sc-p5dwkk-5" })`
|
|
72
72
|
width: 36px;
|
|
73
73
|
height: 32px;
|
|
74
74
|
display: grid;
|
|
@@ -76,14 +76,14 @@ const Day = styled.button `
|
|
|
76
76
|
border-radius: ${v.rCtl};
|
|
77
77
|
font-size: 12px;
|
|
78
78
|
font-variant-numeric: tabular-nums;
|
|
79
|
-
color: ${(p) =>
|
|
80
|
-
border: 1px solid ${(p) =>
|
|
79
|
+
color: ${(p) => p.$outside ? v.faint : v.text};
|
|
80
|
+
border: 1px solid ${(p) => p.$today ? v.line2 : "transparent"};
|
|
81
81
|
transition: background 0.12s ease;
|
|
82
82
|
&:hover:not(:disabled) { background: ${v.hover}; }
|
|
83
83
|
&:disabled { opacity: 0.35; cursor: not-allowed; text-decoration: line-through; }
|
|
84
84
|
&:focus-visible { box-shadow: ${v.ring}; border-radius: ${v.rCtl}; }
|
|
85
85
|
${(p) => p.$edge &&
|
|
86
|
-
|
|
86
|
+
css`
|
|
87
87
|
background: ${v.grad};
|
|
88
88
|
color: ${v.onBrand};
|
|
89
89
|
border-color: transparent;
|
|
@@ -98,93 +98,93 @@ const Day = styled.button `
|
|
|
98
98
|
* Shift, a year), Home/End the week's ends, Enter or Space picks.
|
|
99
99
|
*/
|
|
100
100
|
export function Calendar(props) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
};
|
|
159
|
-
const go = step[e.key];
|
|
160
|
-
if (go) {
|
|
161
|
-
e.preventDefault();
|
|
162
|
-
keyed.current = true;
|
|
163
|
-
let next = go();
|
|
164
|
-
if (lo && next < lo)
|
|
165
|
-
next = lo;
|
|
166
|
-
if (hi && next > hi)
|
|
167
|
-
next = hi;
|
|
168
|
-
setFocus(next);
|
|
169
|
-
if (range && from && !to)
|
|
170
|
-
setHover(next);
|
|
171
|
-
}
|
|
172
|
-
else if (e.key === "Enter" || e.key === " ") {
|
|
173
|
-
e.preventDefault();
|
|
174
|
-
pick(focus);
|
|
175
|
-
}
|
|
101
|
+
const { min, max, isDisabled, weekStartsOn = 1, locale, autoFocus } = props;
|
|
102
|
+
const range = props.mode === "range";
|
|
103
|
+
const from = range ? props.value[0] : props.value;
|
|
104
|
+
const to = range ? props.value[1] : props.value;
|
|
105
|
+
const lo = asKey(min);
|
|
106
|
+
const hi = asKey(max);
|
|
107
|
+
const today = toDayKey(new Date());
|
|
108
|
+
const off = (k) => !!lo && k < lo || !!hi && k > hi || !!isDisabled?.(k);
|
|
109
|
+
const initial = to ?? from ?? (hi && today > hi ? hi : lo && today < lo ? lo : today);
|
|
110
|
+
const [focus, setFocus] = useState(initial);
|
|
111
|
+
const [hover, setHover] = useState(null);
|
|
112
|
+
const month = monthOf(focus);
|
|
113
|
+
const grid = useRef(null);
|
|
114
|
+
const keyed = useRef(!!autoFocus);
|
|
115
|
+
// the focused day follows the keyboard; the DOM focus follows it once the keyboard has been used
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!keyed.current)
|
|
118
|
+
return;
|
|
119
|
+
grid.current?.querySelector(`[data-day="${focus}"]`)?.focus();
|
|
120
|
+
}, [focus]);
|
|
121
|
+
const first = fromDayKey(`${month}-01`);
|
|
122
|
+
const lead = (first.getDay() - weekStartsOn + 7) % 7;
|
|
123
|
+
const start = toDayKey(new Date(first.getFullYear(), first.getMonth(), 1 - lead));
|
|
124
|
+
const weeks = Array.from({ length: 6 }, (_, w) => Array.from({ length: 7 }, (_, d) => addDays(start, w * 7 + d)));
|
|
125
|
+
const weekdays = weeks[0].map((k) => fromDayKey(k).toLocaleDateString(locale, { weekday: "short" }).slice(0, 2));
|
|
126
|
+
const title = first.toLocaleDateString(locale, { month: "long", year: "numeric" });
|
|
127
|
+
const prevMonthLast = toDayKey(new Date(first.getFullYear(), first.getMonth(), 0));
|
|
128
|
+
const nextMonthFirst = toDayKey(new Date(first.getFullYear(), first.getMonth() + 1, 1));
|
|
129
|
+
const canPrev = !lo || prevMonthLast >= lo;
|
|
130
|
+
const canNext = !hi || nextMonthFirst <= hi;
|
|
131
|
+
const pick = (k) => {
|
|
132
|
+
if (off(k))
|
|
133
|
+
return;
|
|
134
|
+
setFocus(k);
|
|
135
|
+
if (props.mode !== "range") {
|
|
136
|
+
props.onChange(k);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const [a, b] = props.value;
|
|
140
|
+
if (!a || b)
|
|
141
|
+
props.onChange([k, null]);else
|
|
142
|
+
|
|
143
|
+
props.onChange(k < a ? [k, a] : [a, k]);
|
|
144
|
+
};
|
|
145
|
+
// the band a range draws, previewed under the pointer while half-picked
|
|
146
|
+
const bandTo = range && from && !to && hover ? hover : to;
|
|
147
|
+
const [bLo, bHi] = from && bandTo ? bandTo < from ? [bandTo, from] : [from, bandTo] : [null, null];
|
|
148
|
+
const onKey = (e) => {
|
|
149
|
+
const step = {
|
|
150
|
+
ArrowLeft: () => addDays(focus, -1),
|
|
151
|
+
ArrowRight: () => addDays(focus, 1),
|
|
152
|
+
ArrowUp: () => addDays(focus, -7),
|
|
153
|
+
ArrowDown: () => addDays(focus, 7),
|
|
154
|
+
PageUp: () => addMonths(focus, e.shiftKey ? -12 : -1),
|
|
155
|
+
PageDown: () => addMonths(focus, e.shiftKey ? 12 : 1),
|
|
156
|
+
Home: () => addDays(focus, -((fromDayKey(focus).getDay() - weekStartsOn + 7) % 7)),
|
|
157
|
+
End: () => addDays(focus, 6 - (fromDayKey(focus).getDay() - weekStartsOn + 7) % 7)
|
|
176
158
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
159
|
+
const go = step[e.key];
|
|
160
|
+
if (go) {
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
keyed.current = true;
|
|
163
|
+
let next = go();
|
|
164
|
+
if (lo && next < lo)
|
|
165
|
+
next = lo;
|
|
166
|
+
if (hi && next > hi)
|
|
167
|
+
next = hi;
|
|
168
|
+
setFocus(next);
|
|
169
|
+
if (range && from && !to)
|
|
170
|
+
setHover(next);
|
|
171
|
+
} else
|
|
172
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
pick(focus);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
return _jsxs(CalWrap, { children: [_jsxs(CalHead, { children: [_jsx(IconButton, { "$size": 26, "aria-label": "Previous month", disabled: !canPrev, onClick: () => setFocus(addMonths(focus, -1) < (lo ?? "") ? lo : addMonths(focus, -1)), children: _jsx(Icon, { name: "chevron-left" }) }), _jsx("span", { "aria-live": "polite", children: title }), _jsx(IconButton, { "$size": 26, "aria-label": "Next month", disabled: !canNext, onClick: () => setFocus(hi && addMonths(focus, 1) > hi ? hi : addMonths(focus, 1)), children: _jsx(Icon, { name: "chevron-right" }) })] }), _jsxs("div", { ref: grid, role: "grid", "aria-label": title, "aria-multiselectable": range || undefined, onKeyDown: onKey, onMouseLeave: () => setHover(null), children: [_jsx(Week, { role: "row", children: weekdays.map((w, i) => _jsx(Weekday, { role: "columnheader", children: w }, i)) }), weeks.map((week) => _jsx(Week, { role: "row", children: week.map((k) => {
|
|
178
|
+
const edge = k === from || k === to;
|
|
179
|
+
const inBand = !!bLo && !!bHi && k >= bLo && k <= bHi && bLo !== bHi;
|
|
180
|
+
const band = !inBand ? "none" : k === bLo ? "start" : k === bHi ? "end" : "mid";
|
|
181
|
+
const selected = edge || !!from && !!to && k > from && k < to;
|
|
182
|
+
const date = fromDayKey(k);
|
|
183
|
+
return _jsx(Cell, { role: "gridcell", "aria-selected": selected, "$band": band, children: _jsx(Day, { type: "button", "data-day": k, tabIndex: k === focus ? 0 : -1, disabled: off(k), "aria-label": date.toLocaleDateString(locale, { weekday: "long", day: "numeric", month: "long", year: "numeric" }), "aria-current": k === today ? "date" : undefined, "$edge": edge, "$outside": monthOf(k) !== month, "$today": k === today, onMouseEnter: () => setHover(k), onFocus: () => setFocus(k), onClick: () => pick(k), children: date.getDate() }) }, k);
|
|
184
|
+
}) }, week[0]))] })] });
|
|
185
185
|
}
|
|
186
186
|
/* ------------------------------------------------------------------ DatePicker */
|
|
187
|
-
const FieldBox = styled.div `
|
|
187
|
+
const FieldBox = styled.div.withConfig({ componentId: "sc-p5dwkk-6" })`
|
|
188
188
|
display: flex;
|
|
189
189
|
align-items: center;
|
|
190
190
|
width: 100%;
|
|
@@ -192,12 +192,12 @@ const FieldBox = styled.div `
|
|
|
192
192
|
height: 32px;
|
|
193
193
|
border-radius: ${v.rCtl};
|
|
194
194
|
background: ${v.field};
|
|
195
|
-
border: 1px solid ${(p) =>
|
|
196
|
-
${(p) => p.$open && css
|
|
197
|
-
${(p) => p.$disabled && css
|
|
198
|
-
&:focus-within { border-color: ${(p) =>
|
|
195
|
+
border: 1px solid ${(p) => p.$invalid ? v.danger : p.$open ? v.brand55 : v.fieldLine};
|
|
196
|
+
${(p) => p.$open && css`box-shadow: 0 0 0 3px ${p.$invalid ? v.dangerBg : v.brand08};`}
|
|
197
|
+
${(p) => p.$disabled && css`opacity: 0.55;`}
|
|
198
|
+
&:focus-within { border-color: ${(p) => p.$invalid ? v.danger : v.brand55}; }
|
|
199
199
|
`;
|
|
200
|
-
const FieldBtn = styled.button `
|
|
200
|
+
const FieldBtn = styled.button.withConfig({ componentId: "sc-p5dwkk-7" })`
|
|
201
201
|
flex: 1 1 auto;
|
|
202
202
|
min-width: 0;
|
|
203
203
|
height: 100%;
|
|
@@ -207,45 +207,45 @@ const FieldBtn = styled.button `
|
|
|
207
207
|
padding: 0 10px;
|
|
208
208
|
text-align: left;
|
|
209
209
|
font-size: 12.5px;
|
|
210
|
-
color: ${(p) =>
|
|
210
|
+
color: ${(p) => p.$placeholder ? v.faint : v.text};
|
|
211
211
|
&:focus-visible { box-shadow: none; }
|
|
212
212
|
&:disabled { cursor: not-allowed; }
|
|
213
213
|
> .val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
214
214
|
> svg { flex: none; color: ${v.faint}; font-size: 12px; }
|
|
215
215
|
`;
|
|
216
|
-
const ChipBox = styled.span `
|
|
216
|
+
const ChipBox = styled.span.withConfig({ componentId: "sc-p5dwkk-8" })`
|
|
217
217
|
${chipCss}
|
|
218
218
|
padding: 0;
|
|
219
219
|
gap: 0;
|
|
220
220
|
cursor: default;
|
|
221
221
|
&:has(button:focus-visible) { box-shadow: ${v.ring}; }
|
|
222
222
|
`;
|
|
223
|
-
const ChipBtn = styled.button `
|
|
223
|
+
const ChipBtn = styled.button.withConfig({ componentId: "sc-p5dwkk-9" })`
|
|
224
224
|
display: inline-flex;
|
|
225
225
|
align-items: center;
|
|
226
226
|
gap: 6px;
|
|
227
227
|
height: 100%;
|
|
228
228
|
padding: 0 10px;
|
|
229
|
-
border-radius:
|
|
229
|
+
border-radius: ${v.rPill};
|
|
230
230
|
font: inherit;
|
|
231
231
|
color: inherit;
|
|
232
232
|
&:focus-visible { box-shadow: none; }
|
|
233
233
|
&:disabled { cursor: not-allowed; }
|
|
234
234
|
svg { font-size: 11px; }
|
|
235
235
|
`;
|
|
236
|
-
const ClearBtn = styled.button `
|
|
236
|
+
const ClearBtn = styled.button.withConfig({ componentId: "sc-p5dwkk-10" })`
|
|
237
237
|
flex: none;
|
|
238
238
|
display: inline-grid;
|
|
239
239
|
place-items: center;
|
|
240
240
|
width: 22px;
|
|
241
241
|
height: 22px;
|
|
242
|
-
margin: ${(p) =>
|
|
243
|
-
border-radius: ${(p) =>
|
|
242
|
+
margin: ${(p) => p.$chip ? "0 3px 0 -6px" : "0 5px 0 0"};
|
|
243
|
+
border-radius: ${(p) => p.$chip ? "50%" : `min(6px, ${v.rCtl})`};
|
|
244
244
|
color: ${v.faint};
|
|
245
245
|
font-size: 10px;
|
|
246
246
|
&:hover { color: ${v.text}; background: ${v.hover}; }
|
|
247
247
|
`;
|
|
248
|
-
const Panel = styled.div `
|
|
248
|
+
const Panel = styled.div.withConfig({ componentId: "sc-p5dwkk-11" })`
|
|
249
249
|
display: flex;
|
|
250
250
|
align-items: flex-start;
|
|
251
251
|
gap: 12px;
|
|
@@ -263,7 +263,7 @@ const Panel = styled.div `
|
|
|
263
263
|
min-width: 160px;
|
|
264
264
|
}
|
|
265
265
|
`;
|
|
266
|
-
const Presets = styled.div `
|
|
266
|
+
const Presets = styled.div.withConfig({ componentId: "sc-p5dwkk-12" })`
|
|
267
267
|
display: flex;
|
|
268
268
|
flex-direction: column;
|
|
269
269
|
gap: 2px;
|
|
@@ -284,31 +284,31 @@ const Presets = styled.div `
|
|
|
284
284
|
&[aria-pressed="true"] { background: ${v.brand12}; color: ${v.brand}; }
|
|
285
285
|
}
|
|
286
286
|
`;
|
|
287
|
-
const Foot = styled.div `
|
|
287
|
+
const Foot = styled.div.withConfig({ componentId: "sc-p5dwkk-13" })`
|
|
288
288
|
display: flex;
|
|
289
289
|
justify-content: space-between;
|
|
290
290
|
align-items: center;
|
|
291
291
|
margin-top: 8px;
|
|
292
292
|
font-size: 11px;
|
|
293
293
|
color: ${v.faint};
|
|
294
|
-
> button { font-size: 11.5px; font-weight: 600; color: ${v.muted}; padding: 3px 6px; border-radius: 6px; }
|
|
294
|
+
> button { font-size: 11.5px; font-weight: 600; color: ${v.muted}; padding: 3px 6px; border-radius: min(6px, ${v.rCtl}); }
|
|
295
295
|
> button:hover { color: ${v.text}; background: ${v.hover}; }
|
|
296
296
|
`;
|
|
297
297
|
const dayLabel = (k, locale) => fromDayKey(k).toLocaleDateString(locale, { day: "numeric", month: "short", year: "numeric" });
|
|
298
298
|
const monthLabel = (d, locale, year = true) => d.toLocaleDateString(locale, year ? { month: "long", year: "numeric" } : { month: "long" });
|
|
299
299
|
/** "March 2026" / "March – May 2026" for a range of whole calendar months, else null. */
|
|
300
300
|
function describeMonths(a, b, locale) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
301
|
+
const from = fromDayKey(a);
|
|
302
|
+
const to = fromDayKey(b);
|
|
303
|
+
if (!from || !to || from > to || from.getDate() !== 1)
|
|
304
|
+
return null;
|
|
305
|
+
// the day after `to` is the 1st: `to` is the last day of its month
|
|
306
|
+
if (new Date(to.getFullYear(), to.getMonth(), to.getDate() + 1).getDate() !== 1)
|
|
307
|
+
return null;
|
|
308
|
+
const sameYear = from.getFullYear() === to.getFullYear();
|
|
309
|
+
if (sameYear && from.getMonth() === to.getMonth())
|
|
310
|
+
return monthLabel(from, locale);
|
|
311
|
+
return `${monthLabel(from, locale, !sameYear)} – ${monthLabel(to, locale)}`;
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
314
314
|
* The default caption for a range: "3 Mar 2026 – 9 Mar 2026", "From 3 Mar 2026",
|
|
@@ -316,21 +316,21 @@ function describeMonths(a, b, locale) {
|
|
|
316
316
|
* `{ months: true }` a whole calendar month reads "March 2026".
|
|
317
317
|
*/
|
|
318
318
|
export function describeDateRange([a, b], opts) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
319
|
+
const { locale, months } = typeof opts === "string" ? { locale: opts, months: false } : opts ?? {};
|
|
320
|
+
if (a && b && months) {
|
|
321
|
+
const m = describeMonths(a, b, locale);
|
|
322
|
+
if (m)
|
|
323
|
+
return m;
|
|
324
|
+
}
|
|
325
|
+
if (a && b)
|
|
326
|
+
return a === b ? dayLabel(a, locale) : `${dayLabel(a, locale)} – ${dayLabel(b, locale)}`;
|
|
327
|
+
if (a)
|
|
328
|
+
return `From ${dayLabel(a, locale)}`;
|
|
329
|
+
if (b)
|
|
330
|
+
return `Until ${dayLabel(b, locale)}`;
|
|
331
|
+
return null;
|
|
332
332
|
}
|
|
333
|
-
const presetValue = (p) =>
|
|
333
|
+
const presetValue = (p) => typeof p.value === "function" ? p.value() : p.value;
|
|
334
334
|
/**
|
|
335
335
|
* DatePicker: a day, or a range of days, picked from a Calendar that opens
|
|
336
336
|
* from a trigger. The `field` variant is a form control (it goes red inside a
|
|
@@ -344,95 +344,95 @@ const presetValue = (p) => (typeof p.value === "function" ? p.value() : p.value)
|
|
|
344
344
|
* for a range that is still being drawn.
|
|
345
345
|
*/
|
|
346
346
|
export function DatePicker(props) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
};
|
|
387
|
-
document.addEventListener("mousedown", onDown, true);
|
|
388
|
-
return () => document.removeEventListener("mousedown", onDown, true);
|
|
389
|
-
}, [open]);
|
|
390
|
-
const clear = () => {
|
|
391
|
-
if (props.mode === "range")
|
|
392
|
-
props.onChange([null, null]);
|
|
393
|
-
else
|
|
394
|
-
props.onChange(null);
|
|
395
|
-
setDraft([null, null]);
|
|
396
|
-
};
|
|
397
|
-
const common = { min: props.min, max: props.max, isDisabled: props.isDisabled, weekStartsOn: props.weekStartsOn, locale };
|
|
398
|
-
const calendar = props.mode === "range" ? (_jsx(Calendar, { ...common, mode: "range", autoFocus: true, value: draft, onChange: (r) => {
|
|
399
|
-
setDraft(r);
|
|
400
|
-
if (r[0] && r[1]) {
|
|
401
|
-
props.onChange(r);
|
|
402
|
-
close(true);
|
|
403
|
-
}
|
|
404
|
-
} })) : (_jsx(Calendar, { ...common, autoFocus: true, value: props.value, onChange: (d) => { props.onChange(d); close(true); } }));
|
|
405
|
-
const presets = props.presets?.length ? (_jsx(Presets, { role: "group", "aria-label": "Shortcuts", children: props.mode === "range"
|
|
406
|
-
? props.presets.map((p) => {
|
|
407
|
-
const val = presetValue(p);
|
|
408
|
-
return (_jsx("button", { type: "button", "aria-pressed": val[0] === props.value[0] && val[1] === props.value[1], onClick: () => { props.onChange(val); close(true); }, children: p.label }, p.label));
|
|
409
|
-
})
|
|
410
|
-
: props.presets.map((p) => {
|
|
411
|
-
const val = presetValue(p);
|
|
412
|
-
return (_jsx("button", { type: "button", "aria-pressed": val === props.value, onClick: () => { props.onChange(val); close(true); }, children: p.label }, p.label));
|
|
413
|
-
}) })) : null;
|
|
414
|
-
const half = range && open && draft[0] && !draft[1];
|
|
415
|
-
const triggerProps = {
|
|
416
|
-
ref: trigger,
|
|
417
|
-
type: "button",
|
|
418
|
-
id: id,
|
|
419
|
-
disabled,
|
|
420
|
-
"aria-label": label,
|
|
421
|
-
"aria-haspopup": "dialog",
|
|
422
|
-
"aria-expanded": open,
|
|
423
|
-
"aria-controls": open ? panelId : undefined,
|
|
424
|
-
"aria-invalid": field?.invalid || undefined,
|
|
425
|
-
"aria-describedby": field?.describedBy,
|
|
426
|
-
onClick: () => (open ? close(false) : show()),
|
|
427
|
-
onKeyDown: (e) => { if (e.key === "ArrowDown" && !open) {
|
|
428
|
-
e.preventDefault();
|
|
429
|
-
show();
|
|
430
|
-
} },
|
|
347
|
+
const { clearable = true, disabled, label, id, variant = "field", icon = "calendar", side, align, aside, name, locale } = props;
|
|
348
|
+
const range = props.mode === "range";
|
|
349
|
+
const field = useField();
|
|
350
|
+
const [open, setOpen] = useState(false);
|
|
351
|
+
const [draft, setDraft] = useState([null, null]);
|
|
352
|
+
const wrap = useRef(null);
|
|
353
|
+
const layer = useRef(null);
|
|
354
|
+
const trigger = useRef(null);
|
|
355
|
+
const panelId = useId();
|
|
356
|
+
const empty = range ? !props.value[0] && !props.value[1] : !props.value;
|
|
357
|
+
const caption = empty ?
|
|
358
|
+
props.placeholder ?? (range ? "Any time" : "Pick a date") :
|
|
359
|
+
props.mode === "range" ?
|
|
360
|
+
props.format ? props.format(props.value) : describeDateRange(props.value, { locale, months: props.months }) :
|
|
361
|
+
props.format ? props.format(props.value) : dayLabel(props.value, locale);
|
|
362
|
+
// focus goes back to the trigger after the panel has gone (asked for here, done in an effect)
|
|
363
|
+
const [refocus, setRefocus] = useState(0);
|
|
364
|
+
useEffect(() => {if (refocus)
|
|
365
|
+
trigger.current?.focus();}, [refocus]);
|
|
366
|
+
const close = (back) => {
|
|
367
|
+
setOpen(false);
|
|
368
|
+
if (back)
|
|
369
|
+
setRefocus((n) => n + 1);
|
|
370
|
+
};
|
|
371
|
+
const show = () => {
|
|
372
|
+
if (disabled)
|
|
373
|
+
return;
|
|
374
|
+
if (props.mode === "range")
|
|
375
|
+
setDraft(props.value);
|
|
376
|
+
setOpen(true);
|
|
377
|
+
};
|
|
378
|
+
useEscapeLayer(open, () => close(true));
|
|
379
|
+
useEffect(() => {
|
|
380
|
+
if (!open)
|
|
381
|
+
return;
|
|
382
|
+
const onDown = (e) => {
|
|
383
|
+
const t = e.target;
|
|
384
|
+
if (!wrap.current?.contains(t) && !layer.current?.contains(t))
|
|
385
|
+
setOpen(false);
|
|
431
386
|
};
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
387
|
+
document.addEventListener("mousedown", onDown, true);
|
|
388
|
+
return () => document.removeEventListener("mousedown", onDown, true);
|
|
389
|
+
}, [open]);
|
|
390
|
+
const clear = () => {
|
|
391
|
+
if (props.mode === "range")
|
|
392
|
+
props.onChange([null, null]);else
|
|
393
|
+
|
|
394
|
+
props.onChange(null);
|
|
395
|
+
setDraft([null, null]);
|
|
396
|
+
};
|
|
397
|
+
const common = { min: props.min, max: props.max, isDisabled: props.isDisabled, weekStartsOn: props.weekStartsOn, locale };
|
|
398
|
+
const calendar = props.mode === "range" ? _jsx(Calendar, { ...common, mode: "range", autoFocus: true, value: draft, onChange: (r) => {
|
|
399
|
+
setDraft(r);
|
|
400
|
+
if (r[0] && r[1]) {
|
|
401
|
+
props.onChange(r);
|
|
402
|
+
close(true);
|
|
403
|
+
}
|
|
404
|
+
} }) : _jsx(Calendar, { ...common, autoFocus: true, value: props.value, onChange: (d) => {props.onChange(d);close(true);} });
|
|
405
|
+
const presets = props.presets?.length ? _jsx(Presets, { role: "group", "aria-label": "Shortcuts", children: props.mode === "range" ?
|
|
406
|
+
props.presets.map((p) => {
|
|
407
|
+
const val = presetValue(p);
|
|
408
|
+
return _jsx("button", { type: "button", "aria-pressed": val[0] === props.value[0] && val[1] === props.value[1], onClick: () => {props.onChange(val);close(true);}, children: p.label }, p.label);
|
|
409
|
+
}) :
|
|
410
|
+
props.presets.map((p) => {
|
|
411
|
+
const val = presetValue(p);
|
|
412
|
+
return _jsx("button", { type: "button", "aria-pressed": val === props.value, onClick: () => {props.onChange(val);close(true);}, children: p.label }, p.label);
|
|
413
|
+
}) }) : null;
|
|
414
|
+
const half = range && open && draft[0] && !draft[1];
|
|
415
|
+
const triggerProps = {
|
|
416
|
+
ref: trigger,
|
|
417
|
+
type: "button",
|
|
418
|
+
id: id,
|
|
419
|
+
disabled,
|
|
420
|
+
"aria-label": label,
|
|
421
|
+
"aria-haspopup": "dialog",
|
|
422
|
+
"aria-expanded": open,
|
|
423
|
+
"aria-controls": open ? panelId : undefined,
|
|
424
|
+
"aria-invalid": field?.invalid || undefined,
|
|
425
|
+
"aria-describedby": field?.describedBy,
|
|
426
|
+
onClick: () => open ? close(false) : show(),
|
|
427
|
+
onKeyDown: (e) => {if (e.key === "ArrowDown" && !open) {
|
|
428
|
+
e.preventDefault();
|
|
429
|
+
show();
|
|
430
|
+
}}
|
|
431
|
+
};
|
|
432
|
+
const clearBtn = clearable && !empty && !disabled ? _jsx(ClearBtn, { type: "button", "$chip": variant === "chip", "aria-label": range ? "Clear dates" : "Clear date", onClick: (e) => {e.stopPropagation();clear();}, children: _jsx(Icon, { name: "close" }) }) : null;
|
|
433
|
+
const hidden = name !== undefined ?
|
|
434
|
+
_jsx("input", { type: "hidden", name: name, value: range ? `${props.value[0] ?? ""}/${props.value[1] ?? ""}` : props.value ?? "" }) :
|
|
435
|
+
null;
|
|
436
|
+
return _jsxs("div", { ref: wrap, style: { display: variant === "chip" ? "inline-flex" : "block", minWidth: 0 }, children: [variant === "chip" ? _jsxs(ChipBox, { "$on": !empty || open, children: [_jsxs(ChipBtn, { ...triggerProps, children: [_jsx(Icon, { name: icon }), _jsx("span", { children: caption })] }), clearBtn] }) : _jsxs(FieldBox, { "$open": open, "$invalid": !!field?.invalid, "$disabled": !!disabled, children: [_jsxs(FieldBtn, { ...triggerProps, "$placeholder": empty, children: [_jsx(Icon, { name: icon }), _jsx("span", { className: "val", children: caption })] }), clearBtn] }), hidden, open ? _jsx(Anchored, { anchor: wrap, align: align ?? "left", side: side, gap: 5, layerRef: layer, children: _jsxs(Panel, { id: panelId, role: "dialog", "aria-label": label ?? (range ? "Choose dates" : "Choose a date"), children: [presets, _jsxs("div", { children: [calendar, range ? _jsxs(Foot, { children: [_jsx("span", { "aria-live": "polite", children: half ? "Pick the last day" : draft[0] ? "" : "Pick the first day" }), !empty || draft[0] ? _jsx("button", { type: "button", onClick: () => {clear();}, children: "Clear" }) : null] }) : null] }), aside ? _jsx("div", { className: "side", children: aside(() => close(true)) }) : null] }) }) : null] });
|
|
437
437
|
}
|
|
438
|
-
//# sourceMappingURL=DatePicker.js.map
|
|
438
|
+
//# sourceMappingURL=DatePicker.js.map
|