@sereno-ds/ui 0.38.0 → 0.40.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/_internal/srOnly.d.ts +10 -0
- package/dist/_internal/srOnly.js +15 -0
- package/dist/_internal/srOnly.js.map +1 -0
- package/dist/core/ActionCard.d.ts +33 -0
- package/dist/core/ActionCard.js +91 -0
- package/dist/core/ActionCard.js.map +1 -0
- package/dist/core/Badge.d.ts +7 -1
- package/dist/core/Badge.js +9 -8
- package/dist/core/Badge.js.map +1 -1
- package/dist/core/Divider.d.ts +28 -0
- package/dist/core/Divider.js +28 -0
- package/dist/core/Divider.js.map +1 -0
- package/dist/core/StatCard.d.ts +40 -0
- package/dist/core/StatCard.js +79 -0
- package/dist/core/StatCard.js.map +1 -0
- package/dist/core/StatusDot.d.ts +36 -0
- package/dist/core/StatusDot.js +32 -0
- package/dist/core/StatusDot.js.map +1 -0
- package/dist/forms/CalendarLegend.d.ts +28 -0
- package/dist/forms/CalendarLegend.js +56 -0
- package/dist/forms/CalendarLegend.js.map +1 -0
- package/dist/forms/DatePicker.d.ts +21 -0
- package/dist/forms/DatePicker.js +8 -0
- package/dist/forms/DatePicker.js.map +1 -1
- package/dist/forms/DateTimePicker.d.ts +19 -3
- package/dist/forms/DateTimePicker.js +4 -0
- package/dist/forms/DateTimePicker.js.map +1 -1
- package/dist/forms/_internal/CalendarGrid.d.ts +13 -4
- package/dist/forms/_internal/CalendarGrid.js +25 -7
- package/dist/forms/_internal/CalendarGrid.js.map +1 -1
- package/dist/forms/_internal/calendarDots.d.ts +51 -0
- package/dist/forms/_internal/calendarDots.js +32 -0
- package/dist/forms/_internal/calendarDots.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { sx } from "../_internal/style.js";
|
|
4
|
+
import { Typography } from "../core/Typography.js";
|
|
5
|
+
import { dotStyle, TODAY_RING } from "./_internal/calendarDots.js";
|
|
6
|
+
const RING = 12;
|
|
7
|
+
function Swatch({ dot, outline }) {
|
|
8
|
+
const tone = typeof dot === "string" ? dot : "brand";
|
|
9
|
+
const dotEl = dot ? /* @__PURE__ */ jsx("span", { style: dotStyle(tone) }) : null;
|
|
10
|
+
if (!outline) return dotEl;
|
|
11
|
+
return /* @__PURE__ */ jsx(
|
|
12
|
+
"span",
|
|
13
|
+
{
|
|
14
|
+
style: sx({
|
|
15
|
+
display: "inline-flex",
|
|
16
|
+
alignItems: "center",
|
|
17
|
+
justifyContent: "center",
|
|
18
|
+
width: RING,
|
|
19
|
+
height: RING,
|
|
20
|
+
flex: "0 0 auto",
|
|
21
|
+
borderRadius: "var(--radius-xs)",
|
|
22
|
+
boxShadow: TODAY_RING
|
|
23
|
+
}),
|
|
24
|
+
children: dotEl
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
function CalendarLegend({ items, style, ...rest }) {
|
|
29
|
+
return /* @__PURE__ */ jsx(
|
|
30
|
+
"ul",
|
|
31
|
+
{
|
|
32
|
+
role: "list",
|
|
33
|
+
...rest,
|
|
34
|
+
style: sx({
|
|
35
|
+
display: "flex",
|
|
36
|
+
flexWrap: "wrap",
|
|
37
|
+
alignItems: "center",
|
|
38
|
+
justifyContent: "center",
|
|
39
|
+
gap: "var(--space-1) var(--space-4)",
|
|
40
|
+
listStyle: "none",
|
|
41
|
+
margin: 0,
|
|
42
|
+
padding: "var(--space-1) var(--space-2)",
|
|
43
|
+
...style
|
|
44
|
+
}),
|
|
45
|
+
children: items.map((item, i) => /* @__PURE__ */ jsxs("li", { style: sx({ display: "inline-flex", alignItems: "center", gap: 6 }), children: [
|
|
46
|
+
item.dot || item.outline ? /* @__PURE__ */ jsx("span", { "aria-hidden": true, style: sx({ display: "inline-flex" }), children: /* @__PURE__ */ jsx(Swatch, { dot: item.dot, outline: item.outline }) }) : null,
|
|
47
|
+
/* @__PURE__ */ jsx(Typography, { as: "span", variant: "caption", color: "secondary", children: item.label })
|
|
48
|
+
] }, i))
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
CalendarLegend.displayName = "CalendarLegend";
|
|
53
|
+
export {
|
|
54
|
+
CalendarLegend
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=CalendarLegend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/forms/CalendarLegend.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { Typography } from '../core/Typography';\nimport { dotStyle, TODAY_RING, type CalendarDotTone } from './_internal/calendarDots';\n\nexport interface CalendarLegendItem {\n label: string;\n /**\n * The filled dot the calendar draws under a day (`dayDots`). `true` is the primary color; a\n * tone picks the status color the same way `dayDots` does.\n */\n dot?: boolean | CalendarDotTone;\n /** The thin ring the calendar draws around today. Together with `dot`, the dot sits inside the ring. */\n outline?: boolean;\n}\n\nexport interface CalendarLegendProps extends Omit<React.HTMLAttributes<HTMLUListElement>, 'children'> {\n /** One entry per thing the calendar marks. An item with neither `dot` nor `outline` is just its label. */\n items: CalendarLegendItem[];\n}\n\nconst RING = 12;\n\nfunction Swatch({ dot, outline }: Pick<CalendarLegendItem, 'dot' | 'outline'>) {\n const tone: CalendarDotTone = typeof dot === 'string' ? dot : 'brand';\n const dotEl = dot ? <span style={dotStyle(tone)} /> : null;\n if (!outline) return dotEl;\n return (\n <span\n style={sx({\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: RING,\n height: RING,\n flex: '0 0 auto',\n borderRadius: 'var(--radius-xs)',\n boxShadow: TODAY_RING,\n })}\n >\n {dotEl}\n </span>\n );\n}\n\n/**\n * The footer that explains what a calendar marks (`dayDots`, today's ring), so the screens that\n * show one explain it the same way. Draws the same dot and ring the calendar does, from the\n * same functions. Put it right under the `DateTimePicker`; it wraps on a narrow screen.\n */\nexport function CalendarLegend({ items, style, ...rest }: CalendarLegendProps) {\n return (\n <ul\n // `list-style: none` makes Safari drop the list semantics; the role keeps them.\n role=\"list\"\n {...rest}\n style={sx({\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 'var(--space-1) var(--space-4)',\n listStyle: 'none',\n margin: 0,\n padding: 'var(--space-1) var(--space-2)',\n ...style,\n })}\n >\n {items.map((item, i) => (\n <li key={i} style={sx({ display: 'inline-flex', alignItems: 'center', gap: 6 })}>\n {item.dot || item.outline ? (\n <span aria-hidden style={sx({ display: 'inline-flex' })}>\n <Swatch dot={item.dot} outline={item.outline} />\n </span>\n ) : null}\n <Typography as=\"span\" variant=\"caption\" color=\"secondary\">\n {item.label}\n </Typography>\n </li>\n ))}\n </ul>\n );\n}\n\nCalendarLegend.displayName = 'CalendarLegend';\n"],"mappings":";AA2BsB,cA4Cd,YA5Cc;AAxBtB,SAAS,UAAU;AACnB,SAAS,kBAAkB;AAC3B,SAAS,UAAU,kBAAwC;AAkB3D,MAAM,OAAO;AAEb,SAAS,OAAO,EAAE,KAAK,QAAQ,GAAgD;AAC7E,QAAM,OAAwB,OAAO,QAAQ,WAAW,MAAM;AAC9D,QAAM,QAAQ,MAAM,oBAAC,UAAK,OAAO,SAAS,IAAI,GAAG,IAAK;AACtD,MAAI,CAAC,QAAS,QAAO;AACrB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,GAAG;AAAA,QACR,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,cAAc;AAAA,QACd,WAAW;AAAA,MACb,CAAC;AAAA,MAEA;AAAA;AAAA,EACH;AAEJ;AAOO,SAAS,eAAe,EAAE,OAAO,OAAO,GAAG,KAAK,GAAwB;AAC7E,SACE;AAAA,IAAC;AAAA;AAAA,MAEC,MAAK;AAAA,MACJ,GAAG;AAAA,MACJ,OAAO,GAAG;AAAA,QACR,SAAS;AAAA,QACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,KAAK;AAAA,QACL,WAAW;AAAA,QACX,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,GAAG;AAAA,MACL,CAAC;AAAA,MAEA,gBAAM,IAAI,CAAC,MAAM,MAChB,qBAAC,QAAW,OAAO,GAAG,EAAE,SAAS,eAAe,YAAY,UAAU,KAAK,EAAE,CAAC,GAC3E;AAAA,aAAK,OAAO,KAAK,UAChB,oBAAC,UAAK,eAAW,MAAC,OAAO,GAAG,EAAE,SAAS,cAAc,CAAC,GACpD,8BAAC,UAAO,KAAK,KAAK,KAAK,SAAS,KAAK,SAAS,GAChD,IACE;AAAA,QACJ,oBAAC,cAAW,IAAG,QAAO,SAAQ,WAAU,OAAM,aAC3C,eAAK,OACR;AAAA,WARO,CAST,CACD;AAAA;AAAA,EACH;AAEJ;AAEA,eAAe,cAAc;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { CalendarDayContext, CalendarDayDots } from './_internal/calendarDots.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Imperative handle exposed via `ref` - there's no single native element
|
|
@@ -35,6 +36,26 @@ interface DatePickerProps {
|
|
|
35
36
|
min?: string;
|
|
36
37
|
/** Latest selectable date, ISO "YYYY-MM-DD". The mirror image of `min`: later days are struck through and later months and years cannot be reached. */
|
|
37
38
|
max?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Fires when the month on screen changes (the arrows, or the month / year popover), with the
|
|
41
|
+
* new year and the 0-indexed month. Not when the popover opens: it opens on the month of the
|
|
42
|
+
* value, or on the current one. Refresh `dayDots` / `renderDay` here.
|
|
43
|
+
*/
|
|
44
|
+
onMonthChange?: (year: number, month: number) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Content under each day number (a count, a note), the same as `DateTimePicker`'s. The second
|
|
47
|
+
* argument says whether the day is `selected`, `today` or `unavailable`. When set, the day cells
|
|
48
|
+
* grow taller to hold it.
|
|
49
|
+
*/
|
|
50
|
+
renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* The days that get a dot under their number, the same as `DateTimePicker`'s: day numbers
|
|
53
|
+
* (`[3, 17]`), or an object keyed by day number for a per-dot `tone` or `label`. Day numbers of
|
|
54
|
+
* the month on screen, so refresh them in `onMonthChange`.
|
|
55
|
+
*/
|
|
56
|
+
dayDots?: CalendarDayDots;
|
|
57
|
+
/** What a screen reader says for a dot with no `label` of its own. Defaults to the `locale`-appropriate text. */
|
|
58
|
+
dayDotLabel?: string;
|
|
38
59
|
id?: string;
|
|
39
60
|
containerStyle?: React.CSSProperties;
|
|
40
61
|
/** aria-label for the clear (×) button. Defaults to the `locale`-appropriate text. */
|
package/dist/forms/DatePicker.js
CHANGED
|
@@ -32,6 +32,10 @@ const DatePicker = React.forwardRef(function DatePicker2({
|
|
|
32
32
|
onChange,
|
|
33
33
|
min,
|
|
34
34
|
max,
|
|
35
|
+
onMonthChange,
|
|
36
|
+
renderDay,
|
|
37
|
+
dayDots,
|
|
38
|
+
dayDotLabel,
|
|
35
39
|
id,
|
|
36
40
|
containerStyle,
|
|
37
41
|
clearLabel,
|
|
@@ -196,7 +200,11 @@ const DatePicker = React.forwardRef(function DatePicker2({
|
|
|
196
200
|
onMonthChange: (y, m) => {
|
|
197
201
|
setViewYear(y);
|
|
198
202
|
setViewMonth(m);
|
|
203
|
+
onMonthChange?.(y, m);
|
|
199
204
|
},
|
|
205
|
+
renderDay,
|
|
206
|
+
dayDots,
|
|
207
|
+
dayDotLabel,
|
|
200
208
|
onSelectDate: commit,
|
|
201
209
|
squareCells: true,
|
|
202
210
|
trimEmptyRows: true,
|
|
@@ -1 +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 { fieldA11y } from '../_internal/fieldA11y';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport { parseISODate as parseISO, toISODate as toISO } from './_internal/calendarRange';\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\n/**\n * Imperative handle exposed via `ref` - there's no single native element\n * underneath (the trigger is a `<button>`, the value a plain ISO string in\n * React state), so `ref` can't hand back something `.value`-readable the way\n * a real `<input>` would. `focus()` is real and covers `setFocus()`-on-error;\n * reading the current value still means the `value`/`onChange` props, not the\n * ref. `onChange(value: string)` also isn't a `ChangeEvent`, so a plain\n * `{...register(name)}` spread won't work regardless - use `Controller`.\n */\nexport interface DatePickerHandle {\n focus: () => void;\n}\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 /**\n * Earliest selectable date, ISO \"YYYY-MM-DD\". Every day before it is struck through, and the\n * calendar cannot be navigated to an earlier month or year (the previous-month arrow disables,\n * PageUp and the arrow keys stop at the edge, the month / year popover disables what is out of\n * range). An initial value or month before it opens on `min`'s month.\n */\n min?: string;\n /** Latest selectable date, ISO \"YYYY-MM-DD\". The mirror image of `min`: later days are struck through and later months and years cannot be reached. */\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 /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\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\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 const DatePicker = React.forwardRef<DatePickerHandle, DatePickerProps>(function DatePicker(\n {\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 preserveHelperSpace,\n },\n ref,\n) {\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 React.useImperativeHandle(ref, () => ({ focus: () => triggerRef.current?.focus() }), []);\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\n return (\n <Field label={label} hint={hint} error={error} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\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 // Ties the trigger to the hint / error line below, so they are read when it takes focus.\n {...fieldA11y(rid, { hint, error })}\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 min={min}\n max={max}\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\nDatePicker.displayName = 'DatePicker';\n"],"mappings":";AA6LU,SAyBE,KAzBF;AA3LV,YAAY,WAAW;AACvB,SAAS,YAAY,cAAc,SAAS;AAC5C,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB,UAAU,aAAa,aAAa;AAC7D,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;AAqDA,SAAS,cAAc,KAAa,QAAgC;AAClE,QAAM,IAAI,SAAS,GAAG;AACtB,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,IAAI,KAAK,eAAe,WAAW,OAAO,UAAU,SAAS,EAAE,KAAK,WAAW,OAAO,WAAW,MAAM,UAAU,CAAC,EAAE;AAAA,IACzH,IAAI,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;AAAA,EACjC;AACF;AAgBO,MAAM,aAAa,MAAM,WAA8C,SAASA,YACrF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP,W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UACd,WAAW;AAAA,UACX,SAAS;AAAA,UACT,SAAS;AAAA,QACX,CAAC;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACC,MAAM;AAAA,YACN,OAAO;AAAA,YACP,cAAc,UAAU,OAAO,SAAS,YAAY,OAAO,UAAU,YAAY,OAAO,MAAM;AAAA,YAC9F;AAAA,YACA;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,CAAC;AAED,WAAW,cAAc;","names":["DatePicker"]}
|
|
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 { fieldA11y } from '../_internal/fieldA11y';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport type { CalendarDayContext, CalendarDayDots } from './_internal/calendarDots';\nimport { parseISODate as parseISO, toISODate as toISO } from './_internal/calendarRange';\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\n/**\n * Imperative handle exposed via `ref` - there's no single native element\n * underneath (the trigger is a `<button>`, the value a plain ISO string in\n * React state), so `ref` can't hand back something `.value`-readable the way\n * a real `<input>` would. `focus()` is real and covers `setFocus()`-on-error;\n * reading the current value still means the `value`/`onChange` props, not the\n * ref. `onChange(value: string)` also isn't a `ChangeEvent`, so a plain\n * `{...register(name)}` spread won't work regardless - use `Controller`.\n */\nexport interface DatePickerHandle {\n focus: () => void;\n}\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 /**\n * Earliest selectable date, ISO \"YYYY-MM-DD\". Every day before it is struck through, and the\n * calendar cannot be navigated to an earlier month or year (the previous-month arrow disables,\n * PageUp and the arrow keys stop at the edge, the month / year popover disables what is out of\n * range). An initial value or month before it opens on `min`'s month.\n */\n min?: string;\n /** Latest selectable date, ISO \"YYYY-MM-DD\". The mirror image of `min`: later days are struck through and later months and years cannot be reached. */\n max?: string;\n /**\n * Fires when the month on screen changes (the arrows, or the month / year popover), with the\n * new year and the 0-indexed month. Not when the popover opens: it opens on the month of the\n * value, or on the current one. Refresh `dayDots` / `renderDay` here.\n */\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Content under each day number (a count, a note), the same as `DateTimePicker`'s. The second\n * argument says whether the day is `selected`, `today` or `unavailable`. When set, the day cells\n * grow taller to hold it.\n */\n renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;\n /**\n * The days that get a dot under their number, the same as `DateTimePicker`'s: day numbers\n * (`[3, 17]`), or an object keyed by day number for a per-dot `tone` or `label`. Day numbers of\n * the month on screen, so refresh them in `onMonthChange`.\n */\n dayDots?: CalendarDayDots;\n /** What a screen reader says for a dot with no `label` of its own. Defaults to the `locale`-appropriate text. */\n dayDotLabel?: 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 /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\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\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 const DatePicker = React.forwardRef<DatePickerHandle, DatePickerProps>(function DatePicker(\n {\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 onMonthChange,\n renderDay,\n dayDots,\n dayDotLabel,\n id,\n containerStyle,\n clearLabel,\n locale = 'pt-BR',\n preserveHelperSpace,\n },\n ref,\n) {\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 React.useImperativeHandle(ref, () => ({ focus: () => triggerRef.current?.focus() }), []);\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\n return (\n <Field label={label} hint={hint} error={error} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\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 // Ties the trigger to the hint / error line below, so they are read when it takes focus.\n {...fieldA11y(rid, { hint, error })}\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 min={min}\n max={max}\n onMonthChange={(y, m) => {\n setViewYear(y);\n setViewMonth(m);\n onMonthChange?.(y, m);\n }}\n renderDay={renderDay}\n dayDots={dayDots}\n dayDotLabel={dayDotLabel}\n onSelectDate={commit}\n squareCells\n trimEmptyRows\n locale={locale}\n />\n </div>\n )}\n </div>\n </Field>\n );\n});\n\nDatePicker.displayName = 'DatePicker';\n"],"mappings":";AAsNU,SAyBE,KAzBF;AApNV,YAAY,WAAW;AACvB,SAAS,YAAY,cAAc,SAAS;AAC5C,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB,UAAU,aAAa,aAAa;AAC7D,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;AAyEA,SAAS,cAAc,KAAa,QAAgC;AAClE,QAAM,IAAI,SAAS,GAAG;AACtB,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,IAAI,KAAK,eAAe,WAAW,OAAO,UAAU,SAAS,EAAE,KAAK,WAAW,OAAO,WAAW,MAAM,UAAU,CAAC,EAAE;AAAA,IACzH,IAAI,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;AAAA,EACjC;AACF;AAgBO,MAAM,aAAa,MAAM,WAA8C,SAASA,YACrF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACC,MAAM;AAAA,YACN,OAAO;AAAA,YACP,cAAc,UAAU,OAAO,SAAS,YAAY,OAAO,UAAU,YAAY,OAAO,MAAM;AAAA,YAC9F;AAAA,YACA;AAAA,YACA,eAAe,CAAC,GAAG,MAAM;AACvB,0BAAY,CAAC;AACb,2BAAa,CAAC;AACd,8BAAgB,GAAG,CAAC;AAAA,YACtB;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,cAAc;AAAA,YACd,aAAW;AAAA,YACX,eAAa;AAAA,YACb;AAAA;AAAA,QACF;AAAA;AAAA,IACF;AAAA,KAEJ,GACF;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["DatePicker"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { CalendarDayContext, CalendarDayDots } from './_internal/calendarDots.js';
|
|
3
|
+
export { CalendarDayDot, CalendarDotTone } from './_internal/calendarDots.js';
|
|
2
4
|
|
|
3
5
|
interface TimeSlot {
|
|
4
6
|
value: string;
|
|
@@ -67,11 +69,25 @@ interface DateTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
|
|
|
67
69
|
/** Fires whenever the visible month changes (arrows or the month/year popover). */
|
|
68
70
|
onMonthChange?: (year: number, month: number) => void;
|
|
69
71
|
/**
|
|
70
|
-
* Extra content under each day number - a count badge, a
|
|
72
|
+
* Extra content under each day number - a count badge, a note, etc. Return
|
|
71
73
|
* `null` for days with nothing to show. When set, every cell grows to keep the
|
|
72
74
|
* grid even. It's the caller's job to scope this (e.g. future days only).
|
|
75
|
+
* The second argument says what the calendar already knows about the day: whether it is
|
|
76
|
+
* `selected` (painted with the primary color, so content there needs `--interactive-primary-fg`),
|
|
77
|
+
* `today`, or `unavailable`.
|
|
73
78
|
*/
|
|
74
|
-
renderDay?: (day: number) => React.ReactNode;
|
|
79
|
+
renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;
|
|
80
|
+
/**
|
|
81
|
+
* The days that get a dot under their number, for "something happens this day": a list of day
|
|
82
|
+
* numbers (`[3, 17]`), or an object keyed by day number when a dot needs its own `tone` or
|
|
83
|
+
* `label` (`{ 3: { tone: 'warning' } }`). The calendar places the dot and turns it to
|
|
84
|
+
* `--interactive-primary-fg` on the selected day, so nothing has to be redone in `renderDay`.
|
|
85
|
+
* Day numbers of the month on screen, like `unavailable`: refresh them in `onMonthChange`.
|
|
86
|
+
* Shares the slot under the number with `renderDay`, and grows the cells the same way.
|
|
87
|
+
*/
|
|
88
|
+
dayDots?: CalendarDayDots;
|
|
89
|
+
/** What a screen reader says for a dot with no `label` of its own, after the day number. Defaults to the `locale`-appropriate text ("com marcador" / "marked"). */
|
|
90
|
+
dayDotLabel?: string;
|
|
75
91
|
/** Defaults to the `locale`-appropriate label ("Horários disponíveis" / "Available times"). */
|
|
76
92
|
timeLabel?: string;
|
|
77
93
|
/**
|
|
@@ -92,4 +108,4 @@ interface DateTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
|
|
|
92
108
|
*/
|
|
93
109
|
declare const DateTimePicker: React.ForwardRefExoticComponent<DateTimePickerProps & React.RefAttributes<HTMLDivElement>>;
|
|
94
110
|
|
|
95
|
-
export { DateTimePicker, type DateTimePickerProps, type TimeSlot };
|
|
111
|
+
export { CalendarDayContext, CalendarDayDots, DateTimePicker, type DateTimePickerProps, type TimeSlot };
|
|
@@ -32,6 +32,8 @@ const DateTimePicker = React.forwardRef(function DateTimePicker2({
|
|
|
32
32
|
onSelectTime,
|
|
33
33
|
onMonthChange,
|
|
34
34
|
renderDay,
|
|
35
|
+
dayDots,
|
|
36
|
+
dayDotLabel,
|
|
35
37
|
timeLabel,
|
|
36
38
|
locale = "pt-BR",
|
|
37
39
|
style,
|
|
@@ -67,6 +69,8 @@ const DateTimePicker = React.forwardRef(function DateTimePicker2({
|
|
|
67
69
|
onSelectDate,
|
|
68
70
|
onMonthChange,
|
|
69
71
|
renderDay,
|
|
72
|
+
dayDots,
|
|
73
|
+
dayDotLabel,
|
|
70
74
|
locale
|
|
71
75
|
}
|
|
72
76
|
),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forms/DateTimePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { CalendarGrid } from './_internal/CalendarGrid';\n\nconst TEXT = {\n 'pt-BR': {\n timeLabel: 'Horários disponíveis',\n full: 'Lotado',\n fullInline: 'lotado',\n available: 'Disponível',\n vagas: (booked: number, capacity: number) => `${booked} de ${capacity} vagas`,\n },\n en: {\n timeLabel: 'Available times',\n full: 'Full',\n fullInline: 'full',\n available: 'Available',\n vagas: (booked: number, capacity: number) => `${booked} of ${capacity} spots`,\n },\n} as const;\n\nexport interface TimeSlot {\n value: string;\n /** Hard-blocked - unclickable regardless of `capacity`/`booked`. */\n disabled?: boolean;\n /** Total spots this slot holds - a group session, a class. Omit for a\n * plain 1:1 slot with no capacity tracking (the original contract). */\n capacity?: number;\n /** How many are already booked into it. */\n booked?: number;\n}\n\n/**\n * Month calendar plus available time slots - the heart of the public booking flow.\n * Day names and month names render in pt-BR by default - the real Sereno\n * product always uses it; `locale=\"en\"` exists only for docs/demo purposes.\n *\n * The header navigates: ‹ / › step the month, and the centred title opens a\n * popover to jump straight to a month or year. `year` / `month` set the *initial*\n * view; the component then owns it. Pass `onMonthChange` to react to navigation\n * (e.g. fetch the new month's availability).\n *\n * The day grid uses roving tabindex (SS-228) - only one cell is ever in the\n * Tab order, so Tab enters/leaves it in one stop instead of one per day.\n * Arrow keys move by day/week and cross month boundaries on overflow;\n * Home/End move within the current week row; PageUp/PageDown step the\n * month. An `unavailable` day stays focusable (`aria-disabled`, not the\n * native `disabled` - a disabled button can't receive focus at all) so the\n * cursor can still land on it, just not select it.\n *\n * The calendar body itself (header + day grid) is `./_internal/CalendarGrid`,\n * shared with `DatePicker` (SS-243), which wraps the same grid in a\n * trigger+popover shell instead of this component's always-visible card.\n */\nexport interface DateTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {\n /** Initial year. Defaults to the current year. */\n year?: number;\n /** Initial month, 0-indexed. Defaults to the current month. */\n month?: number;\n /** Selected day-of-month. The highlight only shows in the month it was picked\n * in - navigating away and back to a *different* month never re-highlights it. */\n selectedDate?: number;\n /**\n * Slot labels (\"09:00\") or `TimeSlot` objects. A slot with `capacity` set\n * shows \"booked/capacity\" and switches to a full/overbook-warning look\n * once reached (SS-64) - still pickable unless also `disabled`, since a\n * full slot and a *blocked* one are different things: the first is a\n * deliberate \"yes, overbook it\" the caller can still choose to allow.\n */\n times?: (string | TimeSlot)[];\n selectedTime?: string;\n /** Day numbers with no availability - struck through and unclickable. */\n unavailable?: number[];\n /**\n * Earliest date, ISO \"YYYY-MM-DD\" (the same prop `DatePicker` has). The calendar cannot be\n * navigated to an earlier month or year: the previous-month arrow disables, PageUp and the\n * arrow keys stop at the edge, and the month / year popover disables what is out of range.\n * Every earlier day is struck through on its own, merged with `unavailable`, so there is no\n * need to work out the past days. If `year` / `month` start outside the range they are moved\n * to the nearest month inside it, and `onMonthChange` reports that month at mount.\n */\n min?: string;\n /** Latest date, ISO \"YYYY-MM-DD\". The mirror image of `min`. */\n max?: string;\n onSelectDate?: (day: number) => void;\n onSelectTime?: (time: string) => void;\n /** Fires whenever the visible month changes (arrows or the month/year popover). */\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Extra content under each day number - a count badge, a dot, etc. Return\n * `null` for days with nothing to show. When set, every cell grows to keep the\n * grid even. It's the caller's job to scope this (e.g. future days only).\n */\n renderDay?: (day: number) => React.ReactNode;\n /** Defaults to the `locale`-appropriate label (\"Horários disponíveis\" / \"Available times\"). */\n timeLabel?: 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\n/**\n * `ref` reaches the root `<div>` - plain DOM access (measuring, scrolling\n * into view), not a form value. This isn't a single-value field: the day and\n * the time are two separate, parent-owned selections (`selectedDate` /\n * `selectedTime` + their own `onSelectDate` / `onSelectTime` callbacks), so\n * there's no one \"value\" for `react-hook-form` to register. Register the\n * date and the time as two separate fields at the call site instead (see\n * `DatePicker` for a single-value date field with the same calendar).\n */\nexport const DateTimePicker = React.forwardRef<HTMLDivElement, DateTimePickerProps>(function DateTimePicker(\n {\n year,\n month,\n selectedDate,\n times = [],\n selectedTime,\n unavailable = [],\n min,\n max,\n onSelectDate,\n onSelectTime,\n onMonthChange,\n renderDay,\n timeLabel,\n locale = 'pt-BR',\n style,\n ...rest\n },\n ref,\n) {\n const copy = TEXT[locale];\n const label = timeLabel ?? copy.timeLabel;\n // If any slot in the list tracks capacity, plain slots grow the same\n // two-line layout with a generic \"available\" filler instead of leaving a\n // shorter, blank-looking card next to its neighbors (SS-64 follow-up).\n const anyCapacity = times.some((s) => typeof s === 'object' && s.capacity !== undefined);\n return (\n <div\n ref={ref}\n {...rest}\n style={sx({\n position: 'relative',\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-card)',\n padding: 'var(--space-4)',\n boxShadow: 'var(--shadow-sm)',\n ...style,\n })}\n >\n <CalendarGrid\n year={year}\n month={month}\n selectedDate={selectedDate}\n unavailable={unavailable}\n min={min}\n max={max}\n onSelectDate={onSelectDate}\n onMonthChange={onMonthChange}\n renderDay={renderDay}\n locale={locale}\n />\n {times.length > 0 && (\n <div style={sx({ marginTop: 'var(--space-4)', paddingTop: 'var(--space-4)', borderTop: 'var(--border-width-hairline) solid var(--border-subtle)' })}>\n <div\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-xs)',\n fontWeight: 'var(--weight-semibold)',\n color: 'var(--text-secondary)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n marginBottom: 'var(--space-3)',\n })}\n >\n {label}\n </div>\n <div style={sx({ display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(76px,1fr))', gap: 'var(--space-2)' })}>\n {times.map((slot) => {\n const val = typeof slot === 'string' ? slot : slot.value;\n const dis = typeof slot === 'object' && slot.disabled;\n const capacity = typeof slot === 'object' ? slot.capacity : undefined;\n const booked = typeof slot === 'object' ? (slot.booked ?? 0) : 0;\n const hasOwnCapacity = capacity !== undefined;\n // Full ≠ blocked: a full slot is still pickable (a deliberate\n // overbook) unless the caller *also* set `disabled` - that's\n // the actual hard \"no\" (SS-64).\n const full = hasOwnCapacity && booked >= capacity;\n const sel = selectedTime === val;\n // A slot with no capacity of its own still grows the two-line\n // layout when a *sibling* slot tracks capacity, so the row\n // reads consistently instead of one short card among tall ones.\n const showSecondLine = hasOwnCapacity || anyCapacity;\n const secondLine = hasOwnCapacity ? (full ? copy.full : copy.vagas(booked, capacity)) : copy.available;\n return (\n <button\n key={val}\n type=\"button\"\n disabled={dis}\n aria-label={hasOwnCapacity ? `${val}, ${full ? copy.fullInline + ', ' : ''}${copy.vagas(booked, capacity)}` : undefined}\n onClick={() => onSelectTime && onSelectTime(val)}\n className=\"sereno-dtp-time\"\n style={sx({\n height: showSecondLine ? 'auto' : 'var(--control-height-md)',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 2,\n padding: showSecondLine ? 'var(--space-2) 0' : 0,\n borderRadius: 'var(--radius-control)',\n cursor: dis ? 'not-allowed' : 'pointer',\n border:\n 'var(--border-width-hairline) solid ' +\n (sel ? 'transparent' : full && !dis ? 'var(--interactive-warning)' : 'var(--border-default)'),\n background: sel\n ? 'var(--interactive-accent)'\n : dis\n ? 'var(--interactive-disabled-bg)'\n : full\n ? 'var(--status-warning-bg)'\n : 'var(--bg-surface)',\n color: sel\n ? 'var(--interactive-accent-fg)'\n : dis\n ? 'var(--interactive-disabled-fg)'\n : full\n ? 'var(--status-warning-fg)'\n : 'var(--text-primary)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n fontWeight: 'var(--weight-semibold)',\n transition: 'var(--transition-control)',\n // Not inline outline:none - see .sereno-dtp-time in styles.css.\n })}\n >\n <span aria-hidden={hasOwnCapacity}>{val}</span>\n {showSecondLine && (\n <span\n aria-hidden={hasOwnCapacity}\n style={sx({\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-medium)',\n color: sel ? 'inherit' : full ? 'var(--status-warning-fg)' : 'var(--text-muted)',\n opacity: sel ? 0.85 : 1,\n })}\n >\n {secondLine}\n </span>\n )}\n </button>\n );\n })}\n </div>\n </div>\n )}\n </div>\n );\n});\n\nDateTimePicker.displayName = 'DateTimePicker';\n"],"mappings":";AA4JM,cA6CU,YA7CV;AA1JN,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAE7B,MAAM,OAAO;AAAA,EACX,SAAS;AAAA,IACP,WAAW;AAAA,IACX,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,OAAO,CAAC,QAAgB,aAAqB,GAAG,MAAM,OAAO,QAAQ;AAAA,EACvE;AAAA,EACA,IAAI;AAAA,IACF,WAAW;AAAA,IACX,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,OAAO,CAAC,QAAgB,aAAqB,GAAG,MAAM,OAAO,QAAQ;AAAA,EACvE;AACF;AA8FO,MAAM,iBAAiB,MAAM,WAAgD,SAASA,gBAC3F;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ,CAAC;AAAA,EACT;AAAA,EACA,cAAc,CAAC;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,OAAO,KAAK,MAAM;AACxB,QAAM,QAAQ,aAAa,KAAK;AAIhC,QAAM,cAAc,MAAM,KAAK,CAAC,MAAM,OAA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,cAAc;","names":["DateTimePicker"]}
|
|
1
|
+
{"version":3,"sources":["../../src/forms/DateTimePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport type { CalendarDayContext, CalendarDayDots } from './_internal/calendarDots';\n\nexport type { CalendarDayContext, CalendarDayDot, CalendarDayDots, CalendarDotTone } from './_internal/calendarDots';\n\nconst TEXT = {\n 'pt-BR': {\n timeLabel: 'Horários disponíveis',\n full: 'Lotado',\n fullInline: 'lotado',\n available: 'Disponível',\n vagas: (booked: number, capacity: number) => `${booked} de ${capacity} vagas`,\n },\n en: {\n timeLabel: 'Available times',\n full: 'Full',\n fullInline: 'full',\n available: 'Available',\n vagas: (booked: number, capacity: number) => `${booked} of ${capacity} spots`,\n },\n} as const;\n\nexport interface TimeSlot {\n value: string;\n /** Hard-blocked - unclickable regardless of `capacity`/`booked`. */\n disabled?: boolean;\n /** Total spots this slot holds - a group session, a class. Omit for a\n * plain 1:1 slot with no capacity tracking (the original contract). */\n capacity?: number;\n /** How many are already booked into it. */\n booked?: number;\n}\n\n/**\n * Month calendar plus available time slots - the heart of the public booking flow.\n * Day names and month names render in pt-BR by default - the real Sereno\n * product always uses it; `locale=\"en\"` exists only for docs/demo purposes.\n *\n * The header navigates: ‹ / › step the month, and the centred title opens a\n * popover to jump straight to a month or year. `year` / `month` set the *initial*\n * view; the component then owns it. Pass `onMonthChange` to react to navigation\n * (e.g. fetch the new month's availability).\n *\n * The day grid uses roving tabindex (SS-228) - only one cell is ever in the\n * Tab order, so Tab enters/leaves it in one stop instead of one per day.\n * Arrow keys move by day/week and cross month boundaries on overflow;\n * Home/End move within the current week row; PageUp/PageDown step the\n * month. An `unavailable` day stays focusable (`aria-disabled`, not the\n * native `disabled` - a disabled button can't receive focus at all) so the\n * cursor can still land on it, just not select it.\n *\n * The calendar body itself (header + day grid) is `./_internal/CalendarGrid`,\n * shared with `DatePicker` (SS-243), which wraps the same grid in a\n * trigger+popover shell instead of this component's always-visible card.\n */\nexport interface DateTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {\n /** Initial year. Defaults to the current year. */\n year?: number;\n /** Initial month, 0-indexed. Defaults to the current month. */\n month?: number;\n /** Selected day-of-month. The highlight only shows in the month it was picked\n * in - navigating away and back to a *different* month never re-highlights it. */\n selectedDate?: number;\n /**\n * Slot labels (\"09:00\") or `TimeSlot` objects. A slot with `capacity` set\n * shows \"booked/capacity\" and switches to a full/overbook-warning look\n * once reached (SS-64) - still pickable unless also `disabled`, since a\n * full slot and a *blocked* one are different things: the first is a\n * deliberate \"yes, overbook it\" the caller can still choose to allow.\n */\n times?: (string | TimeSlot)[];\n selectedTime?: string;\n /** Day numbers with no availability - struck through and unclickable. */\n unavailable?: number[];\n /**\n * Earliest date, ISO \"YYYY-MM-DD\" (the same prop `DatePicker` has). The calendar cannot be\n * navigated to an earlier month or year: the previous-month arrow disables, PageUp and the\n * arrow keys stop at the edge, and the month / year popover disables what is out of range.\n * Every earlier day is struck through on its own, merged with `unavailable`, so there is no\n * need to work out the past days. If `year` / `month` start outside the range they are moved\n * to the nearest month inside it, and `onMonthChange` reports that month at mount.\n */\n min?: string;\n /** Latest date, ISO \"YYYY-MM-DD\". The mirror image of `min`. */\n max?: string;\n onSelectDate?: (day: number) => void;\n onSelectTime?: (time: string) => void;\n /** Fires whenever the visible month changes (arrows or the month/year popover). */\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Extra content under each day number - a count badge, a note, etc. Return\n * `null` for days with nothing to show. When set, every cell grows to keep the\n * grid even. It's the caller's job to scope this (e.g. future days only).\n * The second argument says what the calendar already knows about the day: whether it is\n * `selected` (painted with the primary color, so content there needs `--interactive-primary-fg`),\n * `today`, or `unavailable`.\n */\n renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;\n /**\n * The days that get a dot under their number, for \"something happens this day\": a list of day\n * numbers (`[3, 17]`), or an object keyed by day number when a dot needs its own `tone` or\n * `label` (`{ 3: { tone: 'warning' } }`). The calendar places the dot and turns it to\n * `--interactive-primary-fg` on the selected day, so nothing has to be redone in `renderDay`.\n * Day numbers of the month on screen, like `unavailable`: refresh them in `onMonthChange`.\n * Shares the slot under the number with `renderDay`, and grows the cells the same way.\n */\n dayDots?: CalendarDayDots;\n /** What a screen reader says for a dot with no `label` of its own, after the day number. Defaults to the `locale`-appropriate text (\"com marcador\" / \"marked\"). */\n dayDotLabel?: string;\n /** Defaults to the `locale`-appropriate label (\"Horários disponíveis\" / \"Available times\"). */\n timeLabel?: 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\n/**\n * `ref` reaches the root `<div>` - plain DOM access (measuring, scrolling\n * into view), not a form value. This isn't a single-value field: the day and\n * the time are two separate, parent-owned selections (`selectedDate` /\n * `selectedTime` + their own `onSelectDate` / `onSelectTime` callbacks), so\n * there's no one \"value\" for `react-hook-form` to register. Register the\n * date and the time as two separate fields at the call site instead (see\n * `DatePicker` for a single-value date field with the same calendar).\n */\nexport const DateTimePicker = React.forwardRef<HTMLDivElement, DateTimePickerProps>(function DateTimePicker(\n {\n year,\n month,\n selectedDate,\n times = [],\n selectedTime,\n unavailable = [],\n min,\n max,\n onSelectDate,\n onSelectTime,\n onMonthChange,\n renderDay,\n dayDots,\n dayDotLabel,\n timeLabel,\n locale = 'pt-BR',\n style,\n ...rest\n },\n ref,\n) {\n const copy = TEXT[locale];\n const label = timeLabel ?? copy.timeLabel;\n // If any slot in the list tracks capacity, plain slots grow the same\n // two-line layout with a generic \"available\" filler instead of leaving a\n // shorter, blank-looking card next to its neighbors (SS-64 follow-up).\n const anyCapacity = times.some((s) => typeof s === 'object' && s.capacity !== undefined);\n return (\n <div\n ref={ref}\n {...rest}\n style={sx({\n position: 'relative',\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-card)',\n padding: 'var(--space-4)',\n boxShadow: 'var(--shadow-sm)',\n ...style,\n })}\n >\n <CalendarGrid\n year={year}\n month={month}\n selectedDate={selectedDate}\n unavailable={unavailable}\n min={min}\n max={max}\n onSelectDate={onSelectDate}\n onMonthChange={onMonthChange}\n renderDay={renderDay}\n dayDots={dayDots}\n dayDotLabel={dayDotLabel}\n locale={locale}\n />\n {times.length > 0 && (\n <div style={sx({ marginTop: 'var(--space-4)', paddingTop: 'var(--space-4)', borderTop: 'var(--border-width-hairline) solid var(--border-subtle)' })}>\n <div\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-xs)',\n fontWeight: 'var(--weight-semibold)',\n color: 'var(--text-secondary)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n marginBottom: 'var(--space-3)',\n })}\n >\n {label}\n </div>\n <div style={sx({ display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(76px,1fr))', gap: 'var(--space-2)' })}>\n {times.map((slot) => {\n const val = typeof slot === 'string' ? slot : slot.value;\n const dis = typeof slot === 'object' && slot.disabled;\n const capacity = typeof slot === 'object' ? slot.capacity : undefined;\n const booked = typeof slot === 'object' ? (slot.booked ?? 0) : 0;\n const hasOwnCapacity = capacity !== undefined;\n // Full ≠ blocked: a full slot is still pickable (a deliberate\n // overbook) unless the caller *also* set `disabled` - that's\n // the actual hard \"no\" (SS-64).\n const full = hasOwnCapacity && booked >= capacity;\n const sel = selectedTime === val;\n // A slot with no capacity of its own still grows the two-line\n // layout when a *sibling* slot tracks capacity, so the row\n // reads consistently instead of one short card among tall ones.\n const showSecondLine = hasOwnCapacity || anyCapacity;\n const secondLine = hasOwnCapacity ? (full ? copy.full : copy.vagas(booked, capacity)) : copy.available;\n return (\n <button\n key={val}\n type=\"button\"\n disabled={dis}\n aria-label={hasOwnCapacity ? `${val}, ${full ? copy.fullInline + ', ' : ''}${copy.vagas(booked, capacity)}` : undefined}\n onClick={() => onSelectTime && onSelectTime(val)}\n className=\"sereno-dtp-time\"\n style={sx({\n height: showSecondLine ? 'auto' : 'var(--control-height-md)',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 2,\n padding: showSecondLine ? 'var(--space-2) 0' : 0,\n borderRadius: 'var(--radius-control)',\n cursor: dis ? 'not-allowed' : 'pointer',\n border:\n 'var(--border-width-hairline) solid ' +\n (sel ? 'transparent' : full && !dis ? 'var(--interactive-warning)' : 'var(--border-default)'),\n background: sel\n ? 'var(--interactive-accent)'\n : dis\n ? 'var(--interactive-disabled-bg)'\n : full\n ? 'var(--status-warning-bg)'\n : 'var(--bg-surface)',\n color: sel\n ? 'var(--interactive-accent-fg)'\n : dis\n ? 'var(--interactive-disabled-fg)'\n : full\n ? 'var(--status-warning-fg)'\n : 'var(--text-primary)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n fontWeight: 'var(--weight-semibold)',\n transition: 'var(--transition-control)',\n // Not inline outline:none - see .sereno-dtp-time in styles.css.\n })}\n >\n <span aria-hidden={hasOwnCapacity}>{val}</span>\n {showSecondLine && (\n <span\n aria-hidden={hasOwnCapacity}\n style={sx({\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-medium)',\n color: sel ? 'inherit' : full ? 'var(--status-warning-fg)' : 'var(--text-muted)',\n opacity: sel ? 0.85 : 1,\n })}\n >\n {secondLine}\n </span>\n )}\n </button>\n );\n })}\n </div>\n </div>\n )}\n </div>\n );\n});\n\nDateTimePicker.displayName = 'DateTimePicker';\n"],"mappings":";AA+KM,cA+CU,YA/CV;AA7KN,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAK7B,MAAM,OAAO;AAAA,EACX,SAAS;AAAA,IACP,WAAW;AAAA,IACX,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,OAAO,CAAC,QAAgB,aAAqB,GAAG,MAAM,OAAO,QAAQ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AY,MACR,8BACA,MACE,mCACA,OACE,6BACA;AAAA,kBACR,OAAO,MACH,iCACA,MACE,mCACA,OACE,6BACA;AAAA,kBACR,YAAY;AAAA,kBACZ,UAAU;AAAA,kBACV,YAAY;AAAA,kBACZ,YAAY;AAAA;AAAA,gBAEd,CAAC;AAAA,gBAED;AAAA,sCAAC,UAAK,eAAa,gBAAiB,eAAI;AAAA,kBACvC,kBACC;AAAA,oBAAC;AAAA;AAAA,sBACC,eAAa;AAAA,sBACb,OAAO,GAAG;AAAA,wBACR,UAAU;AAAA,wBACV,YAAY;AAAA,wBACZ,OAAO,MAAM,YAAY,OAAO,6BAA6B;AAAA,wBAC7D,SAAS,MAAM,OAAO;AAAA,sBACxB,CAAC;AAAA,sBAEA;AAAA;AAAA,kBACH;AAAA;AAAA;AAAA,cApDG;AAAA,YAsDP;AAAA,UAEJ,CAAC,GACH;AAAA,WACF;AAAA;AAAA;AAAA,EAEJ;AAEJ,CAAC;AAED,eAAe,cAAc;","names":["DateTimePicker"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { CalendarDayContext, CalendarDayDots } from './calendarDots.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The month calendar body - header (‹ / › month nav + a month/year jump
|
|
@@ -27,13 +28,21 @@ interface CalendarGridProps {
|
|
|
27
28
|
max?: string;
|
|
28
29
|
onSelectDate?: (day: number) => void;
|
|
29
30
|
onMonthChange?: (year: number, month: number) => void;
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Content under each day number. The second argument says what the calendar knows about the
|
|
33
|
+
* day (selected, today, unavailable), so the content can follow it without redoing the logic.
|
|
34
|
+
*/
|
|
35
|
+
renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;
|
|
36
|
+
/** The days that get a dot under their number (see `CalendarDayDots`). Shares the slot under the number with `renderDay`. */
|
|
37
|
+
dayDots?: CalendarDayDots;
|
|
38
|
+
/** What a screen reader says for a dot that has no `label` of its own. Defaults to the `locale`-appropriate text. */
|
|
39
|
+
dayDotLabel?: string;
|
|
31
40
|
/**
|
|
32
41
|
* Day cells are perfect squares (`aspect-ratio`) instead of a fixed pixel
|
|
33
42
|
* height - `DatePicker` (SS-243) opts into this since its popover can be
|
|
34
43
|
* narrower than `DateTimePicker`'s own card, where a fixed height was
|
|
35
|
-
* already tuned and shipped. Ignored when `renderDay` is set -
|
|
36
|
-
* always needs the extra fixed height for its own content.
|
|
44
|
+
* already tuned and shipped. Ignored when `renderDay` or `dayDots` is set -
|
|
45
|
+
* that case always needs the extra fixed height for its own content.
|
|
37
46
|
*/
|
|
38
47
|
squareCells?: boolean;
|
|
39
48
|
/**
|
|
@@ -51,6 +60,6 @@ interface CalendarGridProps {
|
|
|
51
60
|
*/
|
|
52
61
|
locale?: 'pt-BR' | 'en';
|
|
53
62
|
}
|
|
54
|
-
declare function CalendarGrid({ year, month, selectedDate, unavailable, min, max, onSelectDate, onMonthChange, renderDay, squareCells, trimEmptyRows, locale, }: CalendarGridProps): React.JSX.Element;
|
|
63
|
+
declare function CalendarGrid({ year, month, selectedDate, unavailable, min, max, onSelectDate, onMonthChange, renderDay, dayDots, dayDotLabel, squareCells, trimEmptyRows, locale, }: CalendarGridProps): React.JSX.Element;
|
|
55
64
|
|
|
56
65
|
export { CalendarGrid, type CalendarGridProps };
|
|
@@ -3,8 +3,10 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { ChevronDown, ChevronLeft, ChevronRight } from "lucide-react";
|
|
5
5
|
import { sx } from "../../_internal/style.js";
|
|
6
|
+
import { srOnlyStyle } from "../../_internal/srOnly.js";
|
|
6
7
|
import { IconButton } from "../../core/IconButton.js";
|
|
7
8
|
import { calendarRange, clampIndex, isDayOutside, yearWindowStart } from "./calendarRange.js";
|
|
9
|
+
import { dotFor, dotStyle, TODAY_RING } from "./calendarDots.js";
|
|
8
10
|
const I18N = {
|
|
9
11
|
"pt-BR": {
|
|
10
12
|
dow: ["D", "S", "T", "Q", "Q", "S", "S"],
|
|
@@ -16,7 +18,8 @@ const I18N = {
|
|
|
16
18
|
prevYears: "Anos anteriores",
|
|
17
19
|
nextYear: "Pr\xF3ximo ano",
|
|
18
20
|
nextYears: "Pr\xF3ximos anos",
|
|
19
|
-
pickerLabel: "Escolher m\xEAs e ano"
|
|
21
|
+
pickerLabel: "Escolher m\xEAs e ano",
|
|
22
|
+
marked: "com marcador"
|
|
20
23
|
},
|
|
21
24
|
en: {
|
|
22
25
|
dow: ["S", "M", "T", "W", "T", "F", "S"],
|
|
@@ -28,7 +31,8 @@ const I18N = {
|
|
|
28
31
|
prevYears: "Previous years",
|
|
29
32
|
nextYear: "Next year",
|
|
30
33
|
nextYears: "Next years",
|
|
31
|
-
pickerLabel: "Choose month and year"
|
|
34
|
+
pickerLabel: "Choose month and year",
|
|
35
|
+
marked: "marked"
|
|
32
36
|
}
|
|
33
37
|
};
|
|
34
38
|
function daysIn(y, m) {
|
|
@@ -44,6 +48,8 @@ function CalendarGrid({
|
|
|
44
48
|
onSelectDate,
|
|
45
49
|
onMonthChange,
|
|
46
50
|
renderDay,
|
|
51
|
+
dayDots,
|
|
52
|
+
dayDotLabel,
|
|
47
53
|
squareCells = false,
|
|
48
54
|
trimEmptyRows = false,
|
|
49
55
|
locale = "pt-BR"
|
|
@@ -68,8 +74,8 @@ function CalendarGrid({
|
|
|
68
74
|
const gridRef = React.useRef(null);
|
|
69
75
|
const [activeDay, setActiveDay] = React.useState(() => {
|
|
70
76
|
if (selectedDate) return selectedDate;
|
|
71
|
-
const
|
|
72
|
-
let day =
|
|
77
|
+
const todayIndex2 = now.getFullYear() * 12 + now.getMonth();
|
|
78
|
+
let day = todayIndex2 === initialIndex ? now.getDate() : 1;
|
|
73
79
|
if (range.min && initialIndex === range.minIndex) day = Math.max(day, range.min.day);
|
|
74
80
|
if (range.max && initialIndex === range.maxIndex) day = Math.min(day, range.max.day);
|
|
75
81
|
return day;
|
|
@@ -122,7 +128,9 @@ function CalendarGrid({
|
|
|
122
128
|
if (trimEmptyRows) {
|
|
123
129
|
while (cells.length > 7 && cells.slice(-7).every((c) => c === null)) cells.length -= 7;
|
|
124
130
|
}
|
|
125
|
-
const
|
|
131
|
+
const hasSlot = !!renderDay || dayDots !== void 0;
|
|
132
|
+
const cellSizing = hasSlot ? { height: 48 } : squareCells ? { aspectRatio: "1" } : { height: 38 };
|
|
133
|
+
const todayIndex = now.getFullYear() * 12 + now.getMonth();
|
|
126
134
|
const years = Array.from({ length: 12 }, (_, i) => yearBase + i);
|
|
127
135
|
const rovingDay = Math.min(Math.max(1, activeDay), total);
|
|
128
136
|
const onGridKeyDown = (e) => {
|
|
@@ -400,13 +408,16 @@ function CalendarGrid({
|
|
|
400
408
|
if (d === null) return /* @__PURE__ */ jsx("span", { "aria-hidden": true, style: cellSizing }, i);
|
|
401
409
|
const off = unavailable.includes(d) || isDayOutside(range, viewIndex, d);
|
|
402
410
|
const sel = selectedDate === d && viewIndex === selectionIndex;
|
|
403
|
-
const
|
|
411
|
+
const today = viewIndex === todayIndex && d === now.getDate();
|
|
412
|
+
const extra = renderDay?.(d, { selected: sel, today, unavailable: off });
|
|
413
|
+
const dot = dotFor(dayDots, d);
|
|
404
414
|
return /* @__PURE__ */ jsxs(
|
|
405
415
|
"button",
|
|
406
416
|
{
|
|
407
417
|
type: "button",
|
|
408
418
|
"data-day": d,
|
|
409
419
|
"aria-disabled": off || void 0,
|
|
420
|
+
"aria-current": today ? "date" : void 0,
|
|
410
421
|
tabIndex: d === rovingDay ? 0 : -1,
|
|
411
422
|
"aria-pressed": sel,
|
|
412
423
|
onClick: () => {
|
|
@@ -432,6 +443,9 @@ function CalendarGrid({
|
|
|
432
443
|
fontSize: "var(--text-sm)",
|
|
433
444
|
fontWeight: sel ? "var(--weight-bold)" : "var(--weight-medium)",
|
|
434
445
|
textDecoration: off ? "line-through" : "none",
|
|
446
|
+
// Today is told apart by a thin inset ring (also `aria-current` above). Not when it
|
|
447
|
+
// is the selected day: the primary fill already says which day it is.
|
|
448
|
+
boxShadow: today && !sel ? TODAY_RING : void 0,
|
|
435
449
|
transition: "var(--transition-control)"
|
|
436
450
|
// Not inline outline:none - that would always beat the
|
|
437
451
|
// .sereno-dtp-days:focus-visible rule below no matter what
|
|
@@ -441,7 +455,11 @@ function CalendarGrid({
|
|
|
441
455
|
}),
|
|
442
456
|
children: [
|
|
443
457
|
/* @__PURE__ */ jsx("span", { children: d }),
|
|
444
|
-
|
|
458
|
+
hasSlot ? /* @__PURE__ */ jsxs("span", { style: sx({ display: "flex", gap: 4, minHeight: 12, lineHeight: 1 }), children: [
|
|
459
|
+
extra,
|
|
460
|
+
dot ? /* @__PURE__ */ jsx("span", { "aria-hidden": true, style: sx({ ...dotStyle(dot.tone, { selected: sel, unavailable: off }), alignSelf: "center" }) }) : null
|
|
461
|
+
] }) : null,
|
|
462
|
+
dot ? /* @__PURE__ */ jsx("span", { style: srOnlyStyle, children: dot.label ?? dayDotLabel ?? t.marked }) : null
|
|
445
463
|
]
|
|
446
464
|
},
|
|
447
465
|
i
|