kaleido-ui 0.2.7 → 0.2.8

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.
@@ -0,0 +1,235 @@
1
+ "use client";
2
+ import {
3
+ Popover,
4
+ PopoverContent,
5
+ PopoverTrigger
6
+ } from "./chunk-CRMLYZIX.js";
7
+ import {
8
+ fieldSurface
9
+ } from "./chunk-TKRMGN7J.js";
10
+ import {
11
+ GlyphButton
12
+ } from "./chunk-JY3H7ZAI.js";
13
+ import {
14
+ IconGlyph
15
+ } from "./chunk-YQQ7GDLZ.js";
16
+ import {
17
+ ChevronLeft,
18
+ ChevronRight,
19
+ Event
20
+ } from "./chunk-XXH4TYKZ.js";
21
+ import {
22
+ cn
23
+ } from "./chunk-PMGIJMRO.js";
24
+
25
+ // src/web/components/date-picker.tsx
26
+ import * as React from "react";
27
+ import { jsx, jsxs } from "react/jsx-runtime";
28
+ var pad = (n) => String(n).padStart(2, "0");
29
+ var toIso = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
30
+ function parseIso(value) {
31
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value ?? "");
32
+ if (!m) return null;
33
+ const d = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
34
+ return toIso(d) === value ? d : null;
35
+ }
36
+ var addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
37
+ var startOfMonth = (d) => new Date(d.getFullYear(), d.getMonth(), 1);
38
+ function DatePicker({
39
+ value,
40
+ onChange,
41
+ placeholder = "Select a date",
42
+ min,
43
+ max,
44
+ disabled,
45
+ locale = "en-US",
46
+ weekStartsOn = 1,
47
+ id,
48
+ previousMonthLabel = "Previous month",
49
+ nextMonthLabel = "Next month",
50
+ clearLabel = "Clear",
51
+ todayLabel = "Today",
52
+ className,
53
+ ...rest
54
+ }) {
55
+ const selected = parseIso(value);
56
+ const minDate = parseIso(min);
57
+ const maxDate = parseIso(max);
58
+ const [open, setOpen] = React.useState(false);
59
+ const [focused, setFocused] = React.useState(() => selected ?? /* @__PURE__ */ new Date());
60
+ const gridRef = React.useRef(null);
61
+ const wantFocus = React.useRef(false);
62
+ const inRange = (d) => !(minDate && d < minDate) && !(maxDate && d > maxDate);
63
+ const handleOpenChange = (next) => {
64
+ if (next) {
65
+ setFocused(selected ?? /* @__PURE__ */ new Date());
66
+ wantFocus.current = true;
67
+ }
68
+ setOpen(next);
69
+ };
70
+ React.useEffect(() => {
71
+ if (!open || !wantFocus.current) return;
72
+ gridRef.current?.querySelector('button[tabindex="0"]')?.focus();
73
+ }, [open, focused]);
74
+ const month = startOfMonth(focused);
75
+ const lead = (month.getDay() - weekStartsOn + 7) % 7;
76
+ const gridStart = addDays(month, -lead);
77
+ const days = Array.from({ length: 42 }, (_, i) => addDays(gridStart, i));
78
+ const rows = [0, 1, 2, 3, 4, 5].filter((r) => days.slice(r * 7, r * 7 + 7).some((d) => d.getMonth() === month.getMonth()));
79
+ const monthFmt = new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" });
80
+ const weekdayLong = new Intl.DateTimeFormat(locale, { weekday: "long" });
81
+ const weekdayShort = new Intl.DateTimeFormat(locale, { weekday: "short" });
82
+ const dayFull = new Intl.DateTimeFormat(locale, { dateStyle: "full" });
83
+ const triggerFmt = new Intl.DateTimeFormat(locale, { dateStyle: "medium" });
84
+ const heads = Array.from({ length: 7 }, (_, i) => addDays(gridStart, i));
85
+ const move = (next) => {
86
+ wantFocus.current = true;
87
+ setFocused(next);
88
+ };
89
+ const shiftMonth = (delta) => {
90
+ const last = new Date(focused.getFullYear(), focused.getMonth() + delta + 1, 0).getDate();
91
+ move(new Date(focused.getFullYear(), focused.getMonth() + delta, Math.min(focused.getDate(), last)));
92
+ };
93
+ const choose = (d) => {
94
+ if (!inRange(d)) return;
95
+ onChange(toIso(d));
96
+ setOpen(false);
97
+ };
98
+ const onKeyDown = (event) => {
99
+ const step = {
100
+ ArrowLeft: () => addDays(focused, -1),
101
+ ArrowRight: () => addDays(focused, 1),
102
+ ArrowUp: () => addDays(focused, -7),
103
+ ArrowDown: () => addDays(focused, 7),
104
+ Home: () => addDays(focused, -((focused.getDay() - weekStartsOn + 7) % 7)),
105
+ End: () => addDays(focused, 6 - (focused.getDay() - weekStartsOn + 7) % 7)
106
+ };
107
+ if (event.key === "PageUp" || event.key === "PageDown") {
108
+ event.preventDefault();
109
+ shiftMonth(event.key === "PageUp" ? -1 : 1);
110
+ return;
111
+ }
112
+ const next = step[event.key]?.();
113
+ if (next) {
114
+ event.preventDefault();
115
+ move(next);
116
+ }
117
+ };
118
+ const todayIso = toIso(/* @__PURE__ */ new Date());
119
+ return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
120
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
121
+ "button",
122
+ {
123
+ type: "button",
124
+ id,
125
+ disabled,
126
+ "aria-label": rest["aria-label"],
127
+ "data-slot": "date-picker-trigger",
128
+ className: cn(
129
+ "flex h-12 w-full items-center justify-between gap-3 px-4 py-3 text-left text-body",
130
+ fieldSurface,
131
+ !selected && "text-muted-foreground",
132
+ className
133
+ ),
134
+ children: [
135
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: selected ? triggerFmt.format(selected) : placeholder }),
136
+ /* @__PURE__ */ jsx(IconGlyph, { glyph: Event, "aria-hidden": "true", className: "shrink-0 text-secondary-content" })
137
+ ]
138
+ }
139
+ ) }),
140
+ /* @__PURE__ */ jsx(
141
+ PopoverContent,
142
+ {
143
+ align: "start",
144
+ className: "w-auto p-3",
145
+ onOpenAutoFocus: (event) => event.preventDefault(),
146
+ children: /* @__PURE__ */ jsxs("div", { "data-slot": "date-picker", className: "flex flex-col gap-2", children: [
147
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
148
+ /* @__PURE__ */ jsx(GlyphButton, { size: "sm", icon: ChevronLeft, label: previousMonthLabel, onClick: () => shiftMonth(-1) }),
149
+ /* @__PURE__ */ jsx("p", { "aria-live": "polite", className: "m-0 text-caption font-semibold text-foreground", children: monthFmt.format(month) }),
150
+ /* @__PURE__ */ jsx(GlyphButton, { size: "sm", icon: ChevronRight, label: nextMonthLabel, onClick: () => shiftMonth(1) })
151
+ ] }),
152
+ /* @__PURE__ */ jsxs(
153
+ "div",
154
+ {
155
+ ref: gridRef,
156
+ role: "grid",
157
+ "aria-label": monthFmt.format(month),
158
+ onKeyDown,
159
+ className: "flex flex-col gap-1",
160
+ children: [
161
+ /* @__PURE__ */ jsx("div", { role: "row", className: "grid grid-cols-7", children: heads.map((d) => /* @__PURE__ */ jsx(
162
+ "span",
163
+ {
164
+ role: "columnheader",
165
+ "aria-label": weekdayLong.format(d),
166
+ className: "py-1 text-center text-mini font-medium uppercase tracking-eyebrow text-muted-foreground",
167
+ children: weekdayShort.format(d).slice(0, 2)
168
+ },
169
+ d.getDay()
170
+ )) }),
171
+ rows.map((r) => /* @__PURE__ */ jsx("div", { role: "row", className: "grid grid-cols-7 gap-1", children: days.slice(r * 7, r * 7 + 7).map((d) => {
172
+ const iso = toIso(d);
173
+ const outside = d.getMonth() !== month.getMonth();
174
+ const isSelected = iso === value;
175
+ const isFocused = iso === toIso(focused);
176
+ const enabled = inRange(d);
177
+ return /* @__PURE__ */ jsx("span", { role: "gridcell", "aria-selected": isSelected, children: /* @__PURE__ */ jsx(
178
+ "button",
179
+ {
180
+ type: "button",
181
+ tabIndex: isFocused ? 0 : -1,
182
+ disabled: !enabled,
183
+ "aria-label": dayFull.format(d),
184
+ "aria-current": iso === todayIso ? "date" : void 0,
185
+ "data-date": iso,
186
+ onClick: () => choose(d),
187
+ className: cn(
188
+ "size-9 rounded-xl text-caption tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-30",
189
+ isSelected ? "bg-primary font-semibold text-primary-foreground shadow-button-primary" : cn(
190
+ "hover:bg-foreground/10",
191
+ outside ? "text-foreground/55" : "text-foreground",
192
+ iso === todayIso && "font-semibold text-brand"
193
+ )
194
+ ),
195
+ children: d.getDate()
196
+ }
197
+ ) }, iso);
198
+ }) }, r))
199
+ ]
200
+ }
201
+ ),
202
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
203
+ /* @__PURE__ */ jsx(
204
+ "button",
205
+ {
206
+ type: "button",
207
+ disabled: !selected,
208
+ onClick: () => {
209
+ onChange("");
210
+ setOpen(false);
211
+ },
212
+ className: "rounded-lg px-2 py-1 text-caption font-medium text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:opacity-40",
213
+ children: clearLabel
214
+ }
215
+ ),
216
+ /* @__PURE__ */ jsx(
217
+ "button",
218
+ {
219
+ type: "button",
220
+ disabled: !inRange(parseIso(todayIso)),
221
+ onClick: () => choose(parseIso(todayIso)),
222
+ className: "rounded-lg px-2 py-1 text-caption font-medium text-brand focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:opacity-40",
223
+ children: todayLabel
224
+ }
225
+ )
226
+ ] })
227
+ ] })
228
+ }
229
+ )
230
+ ] });
231
+ }
232
+
233
+ export {
234
+ DatePicker
235
+ };
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  ActivityList
4
- } from "../chunk-S2ICIIH2.js";
4
+ } from "../chunk-STH4BGSE.js";
5
+ import "../chunk-2NCH2ZDU.js";
5
6
  import "../chunk-AP7Q2FCS.js";
6
7
  import "../chunk-GZZ5KVON.js";
7
- import "../chunk-2NCH2ZDU.js";
8
8
  import "../chunk-UZ4LWR4X.js";
9
9
  import "../chunk-A3XHFJ6J.js";
10
10
  import "../chunk-CZPNI33A.js";
@@ -5,8 +5,8 @@ import {
5
5
  import "../../chunk-IJHTXDKP.js";
6
6
  import "../../chunk-TCFHH5TE.js";
7
7
  import "../../chunk-UHXOPILM.js";
8
- import "../../chunk-CRMLYZIX.js";
9
8
  import "../../chunk-HVKSBEZN.js";
9
+ import "../../chunk-CRMLYZIX.js";
10
10
  import "../../chunk-VM6AGMYO.js";
11
11
  import "../../chunk-CBE7BT3M.js";
12
12
  import "../../chunk-DCUAE6PX.js";
@@ -5,8 +5,8 @@ import {
5
5
  import "../../chunk-IJHTXDKP.js";
6
6
  import "../../chunk-TCFHH5TE.js";
7
7
  import "../../chunk-UHXOPILM.js";
8
- import "../../chunk-CRMLYZIX.js";
9
8
  import "../../chunk-HVKSBEZN.js";
9
+ import "../../chunk-CRMLYZIX.js";
10
10
  import "../../chunk-VM6AGMYO.js";
11
11
  import "../../chunk-CBE7BT3M.js";
12
12
  import "../../chunk-DCUAE6PX.js";
@@ -27,8 +27,8 @@ import {
27
27
  } from "../../chunk-IJHTXDKP.js";
28
28
  import "../../chunk-TCFHH5TE.js";
29
29
  import "../../chunk-UHXOPILM.js";
30
- import "../../chunk-CRMLYZIX.js";
31
30
  import "../../chunk-HVKSBEZN.js";
31
+ import "../../chunk-CRMLYZIX.js";
32
32
  import "../../chunk-VM6AGMYO.js";
33
33
  import "../../chunk-CBE7BT3M.js";
34
34
  import "../../chunk-DCUAE6PX.js";
@@ -6,8 +6,8 @@ import {
6
6
  import "../../chunk-IJHTXDKP.js";
7
7
  import "../../chunk-TCFHH5TE.js";
8
8
  import "../../chunk-UHXOPILM.js";
9
- import "../../chunk-CRMLYZIX.js";
10
9
  import "../../chunk-HVKSBEZN.js";
10
+ import "../../chunk-CRMLYZIX.js";
11
11
  import "../../chunk-VM6AGMYO.js";
12
12
  import "../../chunk-CBE7BT3M.js";
13
13
  import "../../chunk-DCUAE6PX.js";
@@ -1,15 +1,5 @@
1
1
  "use client";
2
2
  import "../../chunk-LOGZGZWN.js";
3
- import {
4
- Sparkline
5
- } from "../../chunk-HP25HN7Q.js";
6
- import {
7
- BarList
8
- } from "../../chunk-C7GGZCRO.js";
9
- import {
10
- DonutChart,
11
- foldSegments
12
- } from "../../chunk-E3YQSYXF.js";
13
3
  import {
14
4
  AreaChart,
15
5
  LineChart
@@ -23,9 +13,19 @@ import {
23
13
  import {
24
14
  ScatterChart
25
15
  } from "../../chunk-2OINBKHY.js";
16
+ import {
17
+ Sparkline
18
+ } from "../../chunk-HP25HN7Q.js";
26
19
  import {
27
20
  BarChart
28
21
  } from "../../chunk-UG3GFYTP.js";
22
+ import {
23
+ BarList
24
+ } from "../../chunk-C7GGZCRO.js";
25
+ import {
26
+ DonutChart,
27
+ foldSegments
28
+ } from "../../chunk-E3YQSYXF.js";
29
29
  import {
30
30
  ChartFrame,
31
31
  ChartLegend,
@@ -37,8 +37,8 @@ import {
37
37
  } from "../../chunk-IJHTXDKP.js";
38
38
  import "../../chunk-TCFHH5TE.js";
39
39
  import "../../chunk-UHXOPILM.js";
40
- import "../../chunk-CRMLYZIX.js";
41
40
  import "../../chunk-HVKSBEZN.js";
41
+ import "../../chunk-CRMLYZIX.js";
42
42
  import "../../chunk-VM6AGMYO.js";
43
43
  import "../../chunk-CBE7BT3M.js";
44
44
  import "../../chunk-DCUAE6PX.js";
@@ -6,8 +6,8 @@ import {
6
6
  import "../../chunk-IJHTXDKP.js";
7
7
  import "../../chunk-TCFHH5TE.js";
8
8
  import "../../chunk-UHXOPILM.js";
9
- import "../../chunk-CRMLYZIX.js";
10
9
  import "../../chunk-HVKSBEZN.js";
10
+ import "../../chunk-CRMLYZIX.js";
11
11
  import "../../chunk-VM6AGMYO.js";
12
12
  import "../../chunk-CBE7BT3M.js";
13
13
  import "../../chunk-DCUAE6PX.js";
@@ -5,8 +5,8 @@ import {
5
5
  import "../../chunk-IJHTXDKP.js";
6
6
  import "../../chunk-TCFHH5TE.js";
7
7
  import "../../chunk-UHXOPILM.js";
8
- import "../../chunk-CRMLYZIX.js";
9
8
  import "../../chunk-HVKSBEZN.js";
9
+ import "../../chunk-CRMLYZIX.js";
10
10
  import "../../chunk-VM6AGMYO.js";
11
11
  import "../../chunk-CBE7BT3M.js";
12
12
  import "../../chunk-DCUAE6PX.js";
@@ -5,8 +5,8 @@ import {
5
5
  import "../../chunk-IJHTXDKP.js";
6
6
  import "../../chunk-TCFHH5TE.js";
7
7
  import "../../chunk-UHXOPILM.js";
8
- import "../../chunk-CRMLYZIX.js";
9
8
  import "../../chunk-HVKSBEZN.js";
9
+ import "../../chunk-CRMLYZIX.js";
10
10
  import "../../chunk-VM6AGMYO.js";
11
11
  import "../../chunk-CBE7BT3M.js";
12
12
  import "../../chunk-DCUAE6PX.js";
@@ -5,8 +5,8 @@ import {
5
5
  import "../../chunk-IJHTXDKP.js";
6
6
  import "../../chunk-TCFHH5TE.js";
7
7
  import "../../chunk-UHXOPILM.js";
8
- import "../../chunk-CRMLYZIX.js";
9
8
  import "../../chunk-HVKSBEZN.js";
9
+ import "../../chunk-CRMLYZIX.js";
10
10
  import "../../chunk-VM6AGMYO.js";
11
11
  import "../../chunk-CBE7BT3M.js";
12
12
  import "../../chunk-DCUAE6PX.js";
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import {
3
+ DatePicker
4
+ } from "../chunk-X7AOMP24.js";
5
+ import "../chunk-CRMLYZIX.js";
6
+ import "../chunk-TKRMGN7J.js";
7
+ import "../chunk-JY3H7ZAI.js";
8
+ import "../chunk-OWSKP527.js";
9
+ import "../chunk-YQQ7GDLZ.js";
10
+ import "../chunk-XXH4TYKZ.js";
11
+ import "../chunk-PMGIJMRO.js";
12
+ export {
13
+ DatePicker
14
+ };
@@ -7,8 +7,8 @@ import {
7
7
  import "../chunk-IJHTXDKP.js";
8
8
  import "../chunk-TCFHH5TE.js";
9
9
  import "../chunk-UHXOPILM.js";
10
- import "../chunk-CRMLYZIX.js";
11
10
  import "../chunk-HVKSBEZN.js";
11
+ import "../chunk-CRMLYZIX.js";
12
12
  import "../chunk-VM6AGMYO.js";
13
13
  import "../chunk-CBE7BT3M.js";
14
14
  import "../chunk-DCUAE6PX.js";