@sereno-ds/ui 0.25.7 → 0.27.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/forms/DatePicker.d.ts +48 -0
- package/dist/forms/DatePicker.js +237 -0
- package/dist/forms/DatePicker.js.map +1 -0
- package/dist/forms/DateTimePicker.d.ts +27 -3
- package/dist/forms/DateTimePicker.js +70 -394
- package/dist/forms/DateTimePicker.js.map +1 -1
- package/dist/forms/Select.js +1 -31
- package/dist/forms/Select.js.map +1 -1
- package/dist/forms/_internal/CalendarGrid.d.ts +47 -0
- package/dist/forms/_internal/CalendarGrid.js +434 -0
- package/dist/forms/_internal/CalendarGrid.js.map +1 -0
- package/dist/forms/_internal/fieldBoxStyle.d.ts +14 -0
- package/dist/forms/_internal/fieldBoxStyle.js +37 -0
- package/dist/forms/_internal/fieldBoxStyle.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface DatePickerProps {
|
|
4
|
+
label?: string;
|
|
5
|
+
hint?: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
/** Defaults to the `locale`-appropriate text ("Selecionar data" / "Pick a date"). */
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
size?: 'sm' | 'md' | 'lg';
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Controlled value, ISO "YYYY-MM-DD". */
|
|
13
|
+
value?: string;
|
|
14
|
+
/** Uncontrolled initial value, ISO "YYYY-MM-DD". */
|
|
15
|
+
defaultValue?: string;
|
|
16
|
+
onChange?: (value: string) => void;
|
|
17
|
+
/** Earliest selectable date, ISO "YYYY-MM-DD" — every day before it is unavailable. */
|
|
18
|
+
min?: string;
|
|
19
|
+
/** Latest selectable date, ISO "YYYY-MM-DD" — every day after it is unavailable. */
|
|
20
|
+
max?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
containerStyle?: React.CSSProperties;
|
|
23
|
+
/** aria-label for the clear (×) button. Defaults to the `locale`-appropriate text. */
|
|
24
|
+
clearLabel?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The real Sereno product always renders pt-BR — this only exists so the
|
|
27
|
+
* docs showcase can demo an English-speaking consumer without forking the
|
|
28
|
+
* component. Default stays `'pt-BR'`.
|
|
29
|
+
*/
|
|
30
|
+
locale?: 'pt-BR' | 'en';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Field for picking a single date — no time, no slots (`DateTimePicker`'s
|
|
34
|
+
* job). A text-field-styled trigger showing the selected date opens a
|
|
35
|
+
* popover with the same calendar grid `DateTimePicker` uses (roving
|
|
36
|
+
* tabindex, month/year jump — see `./_internal/CalendarGrid`), so the two
|
|
37
|
+
* share every bit of calendar behavior (SS-243).
|
|
38
|
+
*
|
|
39
|
+
* Value contract matches the rest of the forms package: `value` /
|
|
40
|
+
* `defaultValue` + `onChange(value)`, a plain ISO "YYYY-MM-DD" string —
|
|
41
|
+
* drops in wherever `<input type="date">` would go, but themed instead of
|
|
42
|
+
* the browser's own, and in pt-BR by default (the real Sereno product
|
|
43
|
+
* always uses it; `locale="en"` exists only for docs/demo purposes). A
|
|
44
|
+
* clear (×) button appears once a value is set.
|
|
45
|
+
*/
|
|
46
|
+
declare function DatePicker({ label, hint, error, required, placeholder, size, disabled, value, defaultValue, onChange, min, max, id, containerStyle, clearLabel, locale, }: DatePickerProps): React.JSX.Element;
|
|
47
|
+
|
|
48
|
+
export { DatePicker, type DatePickerProps };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Calendar as CalendarIcon, X } from "lucide-react";
|
|
5
|
+
import { sx } from "../_internal/style";
|
|
6
|
+
import { Field } from "../_internal/Field";
|
|
7
|
+
import { CalendarGrid } from "./_internal/CalendarGrid";
|
|
8
|
+
import { fieldBoxStyle } from "./_internal/fieldBoxStyle";
|
|
9
|
+
const TEXT = {
|
|
10
|
+
"pt-BR": { placeholder: "Selecionar data", dialogLabel: "Escolher data", clearLabel: "Limpar data" },
|
|
11
|
+
en: { placeholder: "Pick a date", dialogLabel: "Choose a date", clearLabel: "Clear date" }
|
|
12
|
+
};
|
|
13
|
+
function parseISO(iso) {
|
|
14
|
+
if (!iso) return null;
|
|
15
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
|
|
16
|
+
if (!m) return null;
|
|
17
|
+
return { year: Number(m[1]), month: Number(m[2]) - 1, day: Number(m[3]) };
|
|
18
|
+
}
|
|
19
|
+
function toISO(year, month, day) {
|
|
20
|
+
return `${String(year).padStart(4, "0")}-${String(month + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
|
|
21
|
+
}
|
|
22
|
+
function formatDisplay(iso, locale) {
|
|
23
|
+
const d = parseISO(iso);
|
|
24
|
+
if (!d) return iso;
|
|
25
|
+
return new Intl.DateTimeFormat(locale === "en" ? "en-US" : "pt-BR", { day: "2-digit", month: "2-digit", year: "numeric" }).format(
|
|
26
|
+
new Date(d.year, d.month, d.day)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function daysIn(year, month) {
|
|
30
|
+
return new Date(year, month + 1, 0).getDate();
|
|
31
|
+
}
|
|
32
|
+
function unavailableForMonth(year, month, min, max) {
|
|
33
|
+
if (!min && !max) return [];
|
|
34
|
+
const minD = parseISO(min);
|
|
35
|
+
const maxD = parseISO(max);
|
|
36
|
+
const out = [];
|
|
37
|
+
const total = daysIn(year, month);
|
|
38
|
+
for (let day = 1; day <= total; day++) {
|
|
39
|
+
if (minD && year * 372 + month * 31 + day < minD.year * 372 + minD.month * 31 + minD.day) {
|
|
40
|
+
out.push(day);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (maxD && year * 372 + month * 31 + day > maxD.year * 372 + maxD.month * 31 + maxD.day) {
|
|
44
|
+
out.push(day);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
function DatePicker({
|
|
50
|
+
label,
|
|
51
|
+
hint,
|
|
52
|
+
error,
|
|
53
|
+
required,
|
|
54
|
+
placeholder,
|
|
55
|
+
size = "md",
|
|
56
|
+
disabled = false,
|
|
57
|
+
value,
|
|
58
|
+
defaultValue,
|
|
59
|
+
onChange,
|
|
60
|
+
min,
|
|
61
|
+
max,
|
|
62
|
+
id,
|
|
63
|
+
containerStyle,
|
|
64
|
+
clearLabel,
|
|
65
|
+
locale = "pt-BR"
|
|
66
|
+
}) {
|
|
67
|
+
const copy = TEXT[locale];
|
|
68
|
+
const [inner, setInner] = React.useState(defaultValue ?? "");
|
|
69
|
+
const iso = value !== void 0 ? value : inner;
|
|
70
|
+
const parsed = parseISO(iso);
|
|
71
|
+
const now = React.useMemo(() => /* @__PURE__ */ new Date(), []);
|
|
72
|
+
const [open, setOpen] = React.useState(false);
|
|
73
|
+
const [viewYear, setViewYear] = React.useState(parsed?.year ?? now.getFullYear());
|
|
74
|
+
const [viewMonth, setViewMonth] = React.useState(parsed?.month ?? now.getMonth());
|
|
75
|
+
const rootRef = React.useRef(null);
|
|
76
|
+
const triggerRef = React.useRef(null);
|
|
77
|
+
const generatedId = React.useId();
|
|
78
|
+
const rid = id || generatedId;
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
if (!open) return;
|
|
81
|
+
const onDown = (e) => {
|
|
82
|
+
if (rootRef.current && !rootRef.current.contains(e.target)) {
|
|
83
|
+
setOpen(false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const onKey = (e) => {
|
|
87
|
+
if (e.key === "Escape") {
|
|
88
|
+
setOpen(false);
|
|
89
|
+
triggerRef.current?.focus();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
document.addEventListener("pointerdown", onDown, true);
|
|
93
|
+
document.addEventListener("keydown", onKey, true);
|
|
94
|
+
return () => {
|
|
95
|
+
document.removeEventListener("pointerdown", onDown, true);
|
|
96
|
+
document.removeEventListener("keydown", onKey, true);
|
|
97
|
+
};
|
|
98
|
+
}, [open]);
|
|
99
|
+
const openPopover = () => {
|
|
100
|
+
if (disabled) return;
|
|
101
|
+
setViewYear(parsed?.year ?? now.getFullYear());
|
|
102
|
+
setViewMonth(parsed?.month ?? now.getMonth());
|
|
103
|
+
setOpen(true);
|
|
104
|
+
};
|
|
105
|
+
const commit = (day) => {
|
|
106
|
+
const next = toISO(viewYear, viewMonth, day);
|
|
107
|
+
if (value === void 0) setInner(next);
|
|
108
|
+
onChange?.(next);
|
|
109
|
+
setOpen(false);
|
|
110
|
+
triggerRef.current?.focus();
|
|
111
|
+
};
|
|
112
|
+
const clear = () => {
|
|
113
|
+
if (value === void 0) setInner("");
|
|
114
|
+
onChange?.("");
|
|
115
|
+
triggerRef.current?.focus();
|
|
116
|
+
};
|
|
117
|
+
const unavailable = React.useMemo(() => unavailableForMonth(viewYear, viewMonth, min, max), [viewYear, viewMonth, min, max]);
|
|
118
|
+
return /* @__PURE__ */ jsx(Field, { label, hint, error, required, htmlFor: rid, style: containerStyle, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, style: { position: "relative", width: "100%" }, children: [
|
|
119
|
+
/* @__PURE__ */ jsxs("div", { style: fieldBoxStyle(size, !!error, open, disabled), children: [
|
|
120
|
+
/* @__PURE__ */ jsxs(
|
|
121
|
+
"button",
|
|
122
|
+
{
|
|
123
|
+
ref: triggerRef,
|
|
124
|
+
id: rid,
|
|
125
|
+
type: "button",
|
|
126
|
+
disabled,
|
|
127
|
+
"aria-haspopup": "dialog",
|
|
128
|
+
"aria-expanded": open,
|
|
129
|
+
onClick: () => open ? setOpen(false) : openPopover(),
|
|
130
|
+
style: sx({
|
|
131
|
+
flex: 1,
|
|
132
|
+
minWidth: 0,
|
|
133
|
+
display: "flex",
|
|
134
|
+
alignItems: "center",
|
|
135
|
+
gap: "var(--space-2)",
|
|
136
|
+
border: "none",
|
|
137
|
+
background: "transparent",
|
|
138
|
+
padding: 0,
|
|
139
|
+
font: "inherit",
|
|
140
|
+
color: "inherit",
|
|
141
|
+
cursor: "inherit",
|
|
142
|
+
textAlign: "left"
|
|
143
|
+
}),
|
|
144
|
+
children: [
|
|
145
|
+
/* @__PURE__ */ jsx(CalendarIcon, { size: 16, strokeWidth: 1.75, style: { flex: "0 0 auto", opacity: 0.7 } }),
|
|
146
|
+
/* @__PURE__ */ jsx(
|
|
147
|
+
"span",
|
|
148
|
+
{
|
|
149
|
+
style: sx({
|
|
150
|
+
flex: 1,
|
|
151
|
+
textAlign: "left",
|
|
152
|
+
overflow: "hidden",
|
|
153
|
+
textOverflow: "ellipsis",
|
|
154
|
+
whiteSpace: "nowrap",
|
|
155
|
+
color: iso ? "inherit" : "var(--text-muted)"
|
|
156
|
+
}),
|
|
157
|
+
children: iso ? formatDisplay(iso, locale) : placeholder ?? copy.placeholder
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
),
|
|
163
|
+
iso && !disabled && /* @__PURE__ */ jsx(
|
|
164
|
+
"button",
|
|
165
|
+
{
|
|
166
|
+
type: "button",
|
|
167
|
+
"aria-label": clearLabel ?? copy.clearLabel,
|
|
168
|
+
onClick: (e) => {
|
|
169
|
+
e.stopPropagation();
|
|
170
|
+
clear();
|
|
171
|
+
},
|
|
172
|
+
style: sx({
|
|
173
|
+
flex: "0 0 auto",
|
|
174
|
+
display: "inline-flex",
|
|
175
|
+
alignItems: "center",
|
|
176
|
+
justifyContent: "center",
|
|
177
|
+
marginRight: -4,
|
|
178
|
+
padding: 4,
|
|
179
|
+
border: "none",
|
|
180
|
+
borderRadius: "var(--radius-sm)",
|
|
181
|
+
background: "transparent",
|
|
182
|
+
color: "var(--text-muted)",
|
|
183
|
+
cursor: "pointer"
|
|
184
|
+
}),
|
|
185
|
+
children: /* @__PURE__ */ jsx(X, { size: 14, strokeWidth: 2 })
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
] }),
|
|
189
|
+
open && /* @__PURE__ */ jsx(
|
|
190
|
+
"div",
|
|
191
|
+
{
|
|
192
|
+
role: "dialog",
|
|
193
|
+
"aria-label": label || copy.dialogLabel,
|
|
194
|
+
tabIndex: -1,
|
|
195
|
+
style: sx({
|
|
196
|
+
position: "absolute",
|
|
197
|
+
top: "calc(100% + 6px)",
|
|
198
|
+
left: 0,
|
|
199
|
+
right: 0,
|
|
200
|
+
// The 7-column grid needs some floor width to stay readable —
|
|
201
|
+
// a narrow field (e.g. a compact "Data" next to "Motivo")
|
|
202
|
+
// would otherwise squeeze it. `left`/`right: 0` already
|
|
203
|
+
// matches the trigger's own width for anything wider.
|
|
204
|
+
minWidth: 272,
|
|
205
|
+
zIndex: 20,
|
|
206
|
+
background: "var(--bg-surface)",
|
|
207
|
+
border: "var(--border-width-hairline) solid var(--border-default)",
|
|
208
|
+
borderRadius: "var(--radius-md)",
|
|
209
|
+
boxShadow: "var(--shadow-lg)",
|
|
210
|
+
padding: "var(--space-3)",
|
|
211
|
+
outline: "none"
|
|
212
|
+
}),
|
|
213
|
+
children: /* @__PURE__ */ jsx(
|
|
214
|
+
CalendarGrid,
|
|
215
|
+
{
|
|
216
|
+
year: viewYear,
|
|
217
|
+
month: viewMonth,
|
|
218
|
+
selectedDate: parsed && parsed.year === viewYear && parsed.month === viewMonth ? parsed.day : void 0,
|
|
219
|
+
unavailable,
|
|
220
|
+
onMonthChange: (y, m) => {
|
|
221
|
+
setViewYear(y);
|
|
222
|
+
setViewMonth(m);
|
|
223
|
+
},
|
|
224
|
+
onSelectDate: commit,
|
|
225
|
+
squareCells: true,
|
|
226
|
+
trimEmptyRows: true,
|
|
227
|
+
locale
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
] }) });
|
|
233
|
+
}
|
|
234
|
+
export {
|
|
235
|
+
DatePicker
|
|
236
|
+
};
|
|
237
|
+
//# sourceMappingURL=DatePicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/forms/DatePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Calendar as CalendarIcon, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nconst TEXT = {\n 'pt-BR': { placeholder: 'Selecionar data', dialogLabel: 'Escolher data', clearLabel: 'Limpar data' },\n en: { placeholder: 'Pick a date', dialogLabel: 'Choose a date', clearLabel: 'Clear date' },\n} as const;\n\nexport interface DatePickerProps {\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n /** Defaults to the `locale`-appropriate text (\"Selecionar data\" / \"Pick a date\"). */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Controlled value, ISO \"YYYY-MM-DD\". */\n value?: string;\n /** Uncontrolled initial value, ISO \"YYYY-MM-DD\". */\n defaultValue?: string;\n onChange?: (value: string) => void;\n /** Earliest selectable date, ISO \"YYYY-MM-DD\" — every day before it is unavailable. */\n min?: string;\n /** Latest selectable date, ISO \"YYYY-MM-DD\" — every day after it is unavailable. */\n max?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** aria-label for the clear (×) button. Defaults to the `locale`-appropriate text. */\n clearLabel?: string;\n /**\n * The real Sereno product always renders pt-BR — this only exists so the\n * docs showcase can demo an English-speaking consumer without forking the\n * component. Default stays `'pt-BR'`.\n */\n locale?: 'pt-BR' | 'en';\n}\n\ninterface YMD {\n year: number;\n month: number;\n day: number;\n}\n\nfunction parseISO(iso: string | undefined): YMD | null {\n if (!iso) return null;\n const m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(iso);\n if (!m) return null;\n return { year: Number(m[1]), month: Number(m[2]) - 1, day: Number(m[3]) };\n}\n\nfunction toISO(year: number, month: number, day: number): string {\n return `${String(year).padStart(4, '0')}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;\n}\n\nfunction formatDisplay(iso: string, locale: 'pt-BR' | 'en'): string {\n const d = parseISO(iso);\n if (!d) return iso;\n return new Intl.DateTimeFormat(locale === 'en' ? 'en-US' : 'pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(\n new Date(d.year, d.month, d.day),\n );\n}\n\nfunction daysIn(year: number, month: number): number {\n return new Date(year, month + 1, 0).getDate();\n}\n\n/** Every day of (year, month) that falls before `min` or after `max`. */\nfunction unavailableForMonth(year: number, month: number, min?: string, max?: string): number[] {\n if (!min && !max) return [];\n const minD = parseISO(min);\n const maxD = parseISO(max);\n const out: number[] = [];\n const total = daysIn(year, month);\n for (let day = 1; day <= total; day++) {\n if (minD && year * 372 + month * 31 + day < minD.year * 372 + minD.month * 31 + minD.day) {\n out.push(day);\n continue;\n }\n if (maxD && year * 372 + month * 31 + day > maxD.year * 372 + maxD.month * 31 + maxD.day) {\n out.push(day);\n }\n }\n return out;\n}\n\n/**\n * Field for picking a single date — no time, no slots (`DateTimePicker`'s\n * job). A text-field-styled trigger showing the selected date opens a\n * popover with the same calendar grid `DateTimePicker` uses (roving\n * tabindex, month/year jump — see `./_internal/CalendarGrid`), so the two\n * share every bit of calendar behavior (SS-243).\n *\n * Value contract matches the rest of the forms package: `value` /\n * `defaultValue` + `onChange(value)`, a plain ISO \"YYYY-MM-DD\" string —\n * drops in wherever `<input type=\"date\">` would go, but themed instead of\n * the browser's own, and in pt-BR by default (the real Sereno product\n * always uses it; `locale=\"en\"` exists only for docs/demo purposes). A\n * clear (×) button appears once a value is set.\n */\nexport function DatePicker({\n label,\n hint,\n error,\n required,\n placeholder,\n size = 'md',\n disabled = false,\n value,\n defaultValue,\n onChange,\n min,\n max,\n id,\n containerStyle,\n clearLabel,\n locale = 'pt-BR',\n}: DatePickerProps) {\n const copy = TEXT[locale];\n const [inner, setInner] = React.useState(defaultValue ?? '');\n const iso = value !== undefined ? value : inner;\n const parsed = parseISO(iso);\n const now = React.useMemo(() => new Date(), []);\n\n const [open, setOpen] = React.useState(false);\n // The month currently shown in the popover — resets to the value's month\n // (or today's) every time the popover opens, via the conditional mount\n // below; CalendarGrid itself only takes year/month as its *initial* view.\n const [viewYear, setViewYear] = React.useState(parsed?.year ?? now.getFullYear());\n const [viewMonth, setViewMonth] = React.useState(parsed?.month ?? now.getMonth());\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const generatedId = React.useId();\n const rid = id || generatedId;\n\n // A plain `position: absolute` child of `rootRef` (itself `position:\n // relative`) — the same \"inline\" strategy Select's panel uses for its\n // common case, and the same one DateTimePicker's own month/year popover\n // already uses. The browser glues it to the trigger through *any* scroll\n // (page or a nested overflow container) for free — no JS measuring\n // position, no listening for scroll/resize, and critically, it never has\n // to close on scroll the way a `position: fixed` popover computed once\n // would (that was tried first here and didn't hold up — see PR history).\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: PointerEvent) => {\n if (rootRef.current && !rootRef.current.contains(e.target as Node)) {\n setOpen(false);\n }\n };\n const onKey = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n setOpen(false);\n triggerRef.current?.focus();\n }\n };\n document.addEventListener('pointerdown', onDown, true);\n document.addEventListener('keydown', onKey, true);\n return () => {\n document.removeEventListener('pointerdown', onDown, true);\n document.removeEventListener('keydown', onKey, true);\n };\n }, [open]);\n\n const openPopover = () => {\n if (disabled) return;\n setViewYear(parsed?.year ?? now.getFullYear());\n setViewMonth(parsed?.month ?? now.getMonth());\n setOpen(true);\n };\n\n const commit = (day: number) => {\n const next = toISO(viewYear, viewMonth, day);\n if (value === undefined) setInner(next);\n onChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n };\n\n const clear = () => {\n if (value === undefined) setInner('');\n onChange?.('');\n triggerRef.current?.focus();\n };\n\n const unavailable = React.useMemo(() => unavailableForMonth(viewYear, viewMonth, min, max), [viewYear, viewMonth, min, max]);\n\n return (\n <Field label={label} hint={hint} error={error} required={required} htmlFor={rid} style={containerStyle}>\n <div ref={rootRef} style={{ position: 'relative', width: '100%' }}>\n {/* The bordered box lives on this wrapper `div`, not on a `<button>`\n — the open-trigger and the clear (×) button are real, independent\n sibling buttons inside it, since a button can't nest another. */}\n <div style={fieldBoxStyle(size, !!error, open, disabled)}>\n <button\n ref={triggerRef}\n id={rid}\n type=\"button\"\n disabled={disabled}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={() => (open ? setOpen(false) : openPopover())}\n style={sx({\n flex: 1,\n minWidth: 0,\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n border: 'none',\n background: 'transparent',\n padding: 0,\n font: 'inherit',\n color: 'inherit',\n cursor: 'inherit',\n textAlign: 'left',\n })}\n >\n <CalendarIcon size={16} strokeWidth={1.75} style={{ flex: '0 0 auto', opacity: 0.7 }} />\n <span\n style={sx({\n flex: 1,\n textAlign: 'left',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n color: iso ? 'inherit' : 'var(--text-muted)',\n })}\n >\n {iso ? formatDisplay(iso, locale) : (placeholder ?? copy.placeholder)}\n </span>\n </button>\n {iso && !disabled && (\n <button\n type=\"button\"\n aria-label={clearLabel ?? copy.clearLabel}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n style={sx({\n flex: '0 0 auto',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n marginRight: -4,\n padding: 4,\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n color: 'var(--text-muted)',\n cursor: 'pointer',\n })}\n >\n <X size={14} strokeWidth={2} />\n </button>\n )}\n </div>\n\n {open && (\n <div\n role=\"dialog\"\n aria-label={label || copy.dialogLabel}\n tabIndex={-1}\n style={sx({\n position: 'absolute',\n top: 'calc(100% + 6px)',\n left: 0,\n right: 0,\n // The 7-column grid needs some floor width to stay readable —\n // a narrow field (e.g. a compact \"Data\" next to \"Motivo\")\n // would otherwise squeeze it. `left`/`right: 0` already\n // matches the trigger's own width for anything wider.\n minWidth: 272,\n zIndex: 20,\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: 'var(--space-3)',\n outline: 'none',\n })}\n >\n <CalendarGrid\n year={viewYear}\n month={viewMonth}\n selectedDate={parsed && parsed.year === viewYear && parsed.month === viewMonth ? parsed.day : undefined}\n unavailable={unavailable}\n onMonthChange={(y, m) => {\n setViewYear(y);\n setViewMonth(m);\n }}\n onSelectDate={commit}\n squareCells\n trimEmptyRows\n locale={locale}\n />\n </div>\n )}\n </div>\n </Field>\n );\n}\n"],"mappings":";AAyMU,SAuBE,KAvBF;AAvMV,YAAY,WAAW;AACvB,SAAS,YAAY,cAAc,SAAS;AAC5C,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAE9B,MAAM,OAAO;AAAA,EACX,SAAS,EAAE,aAAa,mBAAmB,aAAa,iBAAiB,YAAY,cAAc;AAAA,EACnG,IAAI,EAAE,aAAa,eAAe,aAAa,iBAAiB,YAAY,aAAa;AAC3F;AAsCA,SAAS,SAAS,KAAqC;AACrD,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,IAAI,4BAA4B,KAAK,GAAG;AAC9C,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,EAAE,MAAM,OAAO,EAAE,CAAC,CAAC,GAAG,OAAO,OAAO,EAAE,CAAC,CAAC,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC,CAAC,EAAE;AAC1E;AAEA,SAAS,MAAM,MAAc,OAAe,KAAqB;AAC/D,SAAO,GAAG,OAAO,IAAI,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,OAAO,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OAAO,SAAS,YAAY,OAAO,UAAU,YAAY,OAAO,MAAM;AAAA,YAC9F;AAAA,YACA,eAAe,CAAC,GAAG,MAAM;AACvB,0BAAY,CAAC;AACb,2BAAa,CAAC;AAAA,YAChB;AAAA,YACA,cAAc;AAAA,YACd,aAAW;AAAA,YACX,eAAa;AAAA,YACb;AAAA;AAAA,QACF;AAAA;AAAA,IACF;AAAA,KAEJ,GACF;AAEJ;","names":[]}
|
|
@@ -2,11 +2,18 @@ import * as React from 'react';
|
|
|
2
2
|
|
|
3
3
|
interface TimeSlot {
|
|
4
4
|
value: string;
|
|
5
|
+
/** Hard-blocked — unclickable regardless of `capacity`/`booked`. */
|
|
5
6
|
disabled?: boolean;
|
|
7
|
+
/** Total spots this slot holds — a group session, a class. Omit for a
|
|
8
|
+
* plain 1:1 slot with no capacity tracking (the original contract). */
|
|
9
|
+
capacity?: number;
|
|
10
|
+
/** How many are already booked into it. */
|
|
11
|
+
booked?: number;
|
|
6
12
|
}
|
|
7
13
|
/**
|
|
8
14
|
* Month calendar plus available time slots — the heart of the public booking flow.
|
|
9
|
-
* Day names and month names render in pt-BR
|
|
15
|
+
* Day names and month names render in pt-BR by default — the real Sereno
|
|
16
|
+
* product always uses it; `locale="en"` exists only for docs/demo purposes.
|
|
10
17
|
*
|
|
11
18
|
* The header navigates: ‹ / › step the month, and the centred title opens a
|
|
12
19
|
* popover to jump straight to a month or year. `year` / `month` set the *initial*
|
|
@@ -20,6 +27,10 @@ interface TimeSlot {
|
|
|
20
27
|
* month. An `unavailable` day stays focusable (`aria-disabled`, not the
|
|
21
28
|
* native `disabled` — a disabled button can't receive focus at all) so the
|
|
22
29
|
* cursor can still land on it, just not select it.
|
|
30
|
+
*
|
|
31
|
+
* The calendar body itself (header + day grid) is `./_internal/CalendarGrid`
|
|
32
|
+
* — shared with `DatePicker` (SS-243), which wraps the same grid in a
|
|
33
|
+
* trigger+popover shell instead of this component's always-visible card.
|
|
23
34
|
*/
|
|
24
35
|
interface DateTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
25
36
|
/** Initial year. Defaults to the current year. */
|
|
@@ -29,7 +40,13 @@ interface DateTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
|
|
|
29
40
|
/** Selected day-of-month. The highlight only shows in the month it was picked
|
|
30
41
|
* in — navigating away and back to a *different* month never re-highlights it. */
|
|
31
42
|
selectedDate?: number;
|
|
32
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Slot labels ("09:00") or `TimeSlot` objects. A slot with `capacity` set
|
|
45
|
+
* shows "booked/capacity" and switches to a full/overbook-warning look
|
|
46
|
+
* once reached (SS-64) — still pickable unless also `disabled`, since a
|
|
47
|
+
* full slot and a *blocked* one are different things: the first is a
|
|
48
|
+
* deliberate "yes, overbook it" the caller can still choose to allow.
|
|
49
|
+
*/
|
|
33
50
|
times?: (string | TimeSlot)[];
|
|
34
51
|
selectedTime?: string;
|
|
35
52
|
/** Day numbers with no availability — struck through and unclickable. */
|
|
@@ -44,8 +61,15 @@ interface DateTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
|
|
|
44
61
|
* grid even. It's the caller's job to scope this (e.g. future days only).
|
|
45
62
|
*/
|
|
46
63
|
renderDay?: (day: number) => React.ReactNode;
|
|
64
|
+
/** Defaults to the `locale`-appropriate label ("Horários disponíveis" / "Available times"). */
|
|
47
65
|
timeLabel?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The real Sereno product always renders pt-BR — this only exists so the
|
|
68
|
+
* docs showcase can demo an English-speaking consumer without forking the
|
|
69
|
+
* component. Default stays `'pt-BR'`.
|
|
70
|
+
*/
|
|
71
|
+
locale?: 'pt-BR' | 'en';
|
|
48
72
|
}
|
|
49
|
-
declare function DateTimePicker({ year, month, selectedDate, times, selectedTime, unavailable, onSelectDate, onSelectTime, onMonthChange, renderDay, timeLabel, style, ...rest }: DateTimePickerProps): React.JSX.Element;
|
|
73
|
+
declare function DateTimePicker({ year, month, selectedDate, times, selectedTime, unavailable, onSelectDate, onSelectTime, onMonthChange, renderDay, timeLabel, locale, style, ...rest }: DateTimePickerProps): React.JSX.Element;
|
|
50
74
|
|
|
51
75
|
export { DateTimePicker, type DateTimePickerProps, type TimeSlot };
|