@sereno-ds/ui 0.25.6 → 0.26.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/core/Card.d.ts +1 -1
- package/dist/core/Card.js +17 -2
- package/dist/core/Card.js.map +1 -1
- package/dist/forms/DatePicker.d.ts +37 -0
- package/dist/forms/DatePicker.js +182 -0
- package/dist/forms/DatePicker.js.map +1 -0
- package/dist/forms/DateTimePicker.d.ts +4 -0
- package/dist/forms/DateTimePicker.js +13 -385
- 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 +41 -0
- package/dist/forms/_internal/CalendarGrid.js +409 -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/dist/navigation/BottomNav.js +2 -1
- package/dist/navigation/BottomNav.js.map +1 -1
- package/dist/styles.css +9 -0
- package/package.json +1 -1
package/dist/core/Card.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
10
10
|
selected?: boolean;
|
|
11
11
|
children?: React.ReactNode;
|
|
12
12
|
}
|
|
13
|
-
declare function Card({ padding, elevation, interactive, selected, children, style, ...rest }: CardProps): React.JSX.Element;
|
|
13
|
+
declare function Card({ padding, elevation, interactive, selected, children, style, onClick, onKeyDown, ...rest }: CardProps): React.JSX.Element;
|
|
14
14
|
|
|
15
15
|
export { Card, type CardProps };
|
package/dist/core/Card.js
CHANGED
|
@@ -4,24 +4,39 @@ import { sx } from "../_internal/style";
|
|
|
4
4
|
import { useInteract } from "./Button";
|
|
5
5
|
const PADS = { none: 0, sm: "var(--space-3)", md: "var(--space-4)", lg: "var(--space-5)" };
|
|
6
6
|
const DROP = { none: "", sm: "var(--shadow-xs)", md: "var(--shadow-md)", lg: "var(--shadow-lg)" };
|
|
7
|
-
function Card({ padding = "md", elevation = "sm", interactive = false, selected = false, children, style, ...rest }) {
|
|
7
|
+
function Card({ padding = "md", elevation = "sm", interactive = false, selected = false, children, style, onClick, onKeyDown, ...rest }) {
|
|
8
8
|
const st = useInteract(!interactive);
|
|
9
9
|
const lifted = interactive && st.hover;
|
|
10
|
+
const clickable = interactive && !!onClick;
|
|
10
11
|
const ring = selected ? "0 0 0 1.5px var(--border-brand)" : "0 0 0 1px " + (st.hover ? "var(--border-strong)" : "var(--border-default)");
|
|
11
12
|
const drop = selected ? "var(--shadow-md)" : lifted ? elevation === "lg" ? "var(--shadow-lg)" : "var(--shadow-md)" : DROP[elevation];
|
|
12
13
|
return /* @__PURE__ */ jsx(
|
|
13
14
|
"div",
|
|
14
15
|
{
|
|
15
16
|
...interactive ? st.handlers : {},
|
|
17
|
+
role: clickable ? "button" : void 0,
|
|
18
|
+
tabIndex: clickable ? 0 : void 0,
|
|
19
|
+
onClick,
|
|
20
|
+
onKeyDown: clickable ? (e) => {
|
|
21
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
onClick(e);
|
|
24
|
+
}
|
|
25
|
+
onKeyDown?.(e);
|
|
26
|
+
} : onKeyDown,
|
|
16
27
|
...rest,
|
|
17
28
|
style: sx({
|
|
18
29
|
background: "var(--bg-surface)",
|
|
19
30
|
borderRadius: "var(--radius-card)",
|
|
20
31
|
padding: PADS[padding],
|
|
21
|
-
boxShadow: [ring, drop].filter(Boolean).join(", "),
|
|
32
|
+
boxShadow: [ring, drop, clickable && st.focus ? "var(--focus-ring)" : null].filter(Boolean).join(", "),
|
|
22
33
|
transform: lifted && !st.press ? "translateY(var(--hover-lift))" : interactive && st.press ? "scale(var(--press-scale))" : "none",
|
|
23
34
|
transition: "var(--transition-control)",
|
|
24
35
|
cursor: interactive ? "pointer" : "default",
|
|
36
|
+
// outline:none is safe here (unlike the CSS-class pattern elsewhere in
|
|
37
|
+
// this package) — it pairs with the JS-driven boxShadow ring above,
|
|
38
|
+
// the same useInteract-based substitute Button/IconButton already use.
|
|
39
|
+
outline: clickable ? "none" : void 0,
|
|
25
40
|
...style
|
|
26
41
|
}),
|
|
27
42
|
children
|
package/dist/core/Card.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/Card.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { useInteract } from './Button';\n\n/** Neutral surface container: a crisp 1px ring + optional soft lift + 14px radius. The base of every list row and panel. */\nexport interface CardProps extends React.HTMLAttributes<HTMLDivElement> {\n padding?: 'none' | 'sm' | 'md' | 'lg';\n elevation?: 'none' | 'sm' | 'md' | 'lg';\n /** Adds hover lift, press scale and pointer cursor. */\n interactive?: boolean;\n /** Brand-coloured ring for a chosen option. */\n selected?: boolean;\n children?: React.ReactNode;\n}\n\nconst PADS = { none: 0, sm: 'var(--space-3)', md: 'var(--space-4)', lg: 'var(--space-5)' } as const;\n// The edge is a box-shadow ring (pixel-crisp at any radius), with the elevation\n// drop-shadow layered beneath it — never a real `border` fighting the shadow.\nconst DROP = { none: '', sm: 'var(--shadow-xs)', md: 'var(--shadow-md)', lg: 'var(--shadow-lg)' } as const;\n\nexport function Card({ padding = 'md', elevation = 'sm', interactive = false, selected = false, children, style, ...rest }: CardProps) {\n const st = useInteract(!interactive);\n const lifted = interactive && st.hover;\n\n const ring = selected ? '0 0 0 1.5px var(--border-brand)' : '0 0 0 1px ' + (st.hover ? 'var(--border-strong)' : 'var(--border-default)');\n const drop = selected ? 'var(--shadow-md)' : lifted ? (elevation === 'lg' ? 'var(--shadow-lg)' : 'var(--shadow-md)') : DROP[elevation];\n\n return (\n <div\n {...(interactive ? st.handlers : {})}\n {...rest}\n style={sx({\n background: 'var(--bg-surface)',\n borderRadius: 'var(--radius-card)',\n padding: PADS[padding],\n boxShadow: [ring, drop].filter(Boolean).join(', '),\n transform: lifted && !st.press ? 'translateY(var(--hover-lift))' : interactive && st.press ? 'scale(var(--press-scale))' : 'none',\n transition: 'var(--transition-control)',\n cursor: interactive ? 'pointer' : 'default',\n ...style,\n })}\n >\n {children}\n </div>\n );\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/core/Card.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { useInteract } from './Button';\n\n/** Neutral surface container: a crisp 1px ring + optional soft lift + 14px radius. The base of every list row and panel. */\nexport interface CardProps extends React.HTMLAttributes<HTMLDivElement> {\n padding?: 'none' | 'sm' | 'md' | 'lg';\n elevation?: 'none' | 'sm' | 'md' | 'lg';\n /** Adds hover lift, press scale and pointer cursor. */\n interactive?: boolean;\n /** Brand-coloured ring for a chosen option. */\n selected?: boolean;\n children?: React.ReactNode;\n}\n\nconst PADS = { none: 0, sm: 'var(--space-3)', md: 'var(--space-4)', lg: 'var(--space-5)' } as const;\n// The edge is a box-shadow ring (pixel-crisp at any radius), with the elevation\n// drop-shadow layered beneath it — never a real `border` fighting the shadow.\nconst DROP = { none: '', sm: 'var(--shadow-xs)', md: 'var(--shadow-md)', lg: 'var(--shadow-lg)' } as const;\n\nexport function Card({ padding = 'md', elevation = 'sm', interactive = false, selected = false, children, style, onClick, onKeyDown, ...rest }: CardProps) {\n const st = useInteract(!interactive);\n const lifted = interactive && st.hover;\n // A Card only needs real button semantics (SS-228) when it owns its own\n // onClick — `interactive` alone (no onClick) means it's just borrowing the\n // hover/press visual inside an already-interactive wrapper (e.g. the\n // landing page's Cards inside a <Link>), and giving it a tabIndex there\n // would nest one focusable control inside another.\n const clickable = interactive && !!onClick;\n\n const ring = selected ? '0 0 0 1.5px var(--border-brand)' : '0 0 0 1px ' + (st.hover ? 'var(--border-strong)' : 'var(--border-default)');\n const drop = selected ? 'var(--shadow-md)' : lifted ? (elevation === 'lg' ? 'var(--shadow-lg)' : 'var(--shadow-md)') : DROP[elevation];\n\n return (\n <div\n {...(interactive ? st.handlers : {})}\n role={clickable ? 'button' : undefined}\n tabIndex={clickable ? 0 : undefined}\n onClick={onClick}\n onKeyDown={\n clickable\n ? (e) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n // Not a real MouseEvent — every onClick in this codebase ignores\n // the event argument, so the cast is safe in practice.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above\n onClick(e as any);\n }\n onKeyDown?.(e);\n }\n : onKeyDown\n }\n {...rest}\n style={sx({\n background: 'var(--bg-surface)',\n borderRadius: 'var(--radius-card)',\n padding: PADS[padding],\n boxShadow: [ring, drop, clickable && st.focus ? 'var(--focus-ring)' : null].filter(Boolean).join(', '),\n transform: lifted && !st.press ? 'translateY(var(--hover-lift))' : interactive && st.press ? 'scale(var(--press-scale))' : 'none',\n transition: 'var(--transition-control)',\n cursor: interactive ? 'pointer' : 'default',\n // outline:none is safe here (unlike the CSS-class pattern elsewhere in\n // this package) — it pairs with the JS-driven boxShadow ring above,\n // the same useInteract-based substitute Button/IconButton already use.\n outline: clickable ? 'none' : undefined,\n ...style,\n })}\n >\n {children}\n </div>\n );\n}\n"],"mappings":";AAoCI;AAjCJ,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAa5B,MAAM,OAAO,EAAE,MAAM,GAAG,IAAI,kBAAkB,IAAI,kBAAkB,IAAI,iBAAiB;AAGzF,MAAM,OAAO,EAAE,MAAM,IAAI,IAAI,oBAAoB,IAAI,oBAAoB,IAAI,mBAAmB;AAEzF,SAAS,KAAK,EAAE,UAAU,MAAM,YAAY,MAAM,cAAc,OAAO,WAAW,OAAO,UAAU,OAAO,SAAS,WAAW,GAAG,KAAK,GAAc;AACzJ,QAAM,KAAK,YAAY,CAAC,WAAW;AACnC,QAAM,SAAS,eAAe,GAAG;AAMjC,QAAM,YAAY,eAAe,CAAC,CAAC;AAEnC,QAAM,OAAO,WAAW,oCAAoC,gBAAgB,GAAG,QAAQ,yBAAyB;AAChH,QAAM,OAAO,WAAW,qBAAqB,SAAU,cAAc,OAAO,qBAAqB,qBAAsB,KAAK,SAAS;AAErI,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAI,cAAc,GAAG,WAAW,CAAC;AAAA,MAClC,MAAM,YAAY,WAAW;AAAA,MAC7B,UAAU,YAAY,IAAI;AAAA,MAC1B;AAAA,MACA,WACE,YACI,CAAC,MAAM;AACL,YAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,KAAK;AACtC,YAAE,eAAe;AAIjB,kBAAQ,CAAQ;AAAA,QAClB;AACA,oBAAY,CAAC;AAAA,MACf,IACA;AAAA,MAEL,GAAG;AAAA,MACJ,OAAO,GAAG;AAAA,QACR,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,SAAS,KAAK,OAAO;AAAA,QACrB,WAAW,CAAC,MAAM,MAAM,aAAa,GAAG,QAAQ,sBAAsB,IAAI,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;AAAA,QACrG,WAAW,UAAU,CAAC,GAAG,QAAQ,kCAAkC,eAAe,GAAG,QAAQ,8BAA8B;AAAA,QAC3H,YAAY;AAAA,QACZ,QAAQ,cAAc,YAAY;AAAA;AAAA;AAAA;AAAA,QAIlC,SAAS,YAAY,SAAS;AAAA,QAC9B,GAAG;AAAA,MACL,CAAC;AAAA,MAEA;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface DatePickerProps {
|
|
4
|
+
label?: string;
|
|
5
|
+
hint?: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
size?: 'sm' | 'md' | 'lg';
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Controlled value, ISO "YYYY-MM-DD". */
|
|
12
|
+
value?: string;
|
|
13
|
+
/** Uncontrolled initial value, ISO "YYYY-MM-DD". */
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
onChange?: (value: string) => void;
|
|
16
|
+
/** Earliest selectable date, ISO "YYYY-MM-DD" — every day before it is unavailable. */
|
|
17
|
+
min?: string;
|
|
18
|
+
/** Latest selectable date, ISO "YYYY-MM-DD" — every day after it is unavailable. */
|
|
19
|
+
max?: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
containerStyle?: React.CSSProperties;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Field for picking a single date — no time, no slots (`DateTimePicker`'s
|
|
25
|
+
* job). A text-field-styled trigger showing the selected date opens a
|
|
26
|
+
* popover with the same calendar grid `DateTimePicker` uses (roving
|
|
27
|
+
* tabindex, month/year jump — see `./_internal/CalendarGrid`), so the two
|
|
28
|
+
* share every bit of calendar behavior (SS-243).
|
|
29
|
+
*
|
|
30
|
+
* Value contract matches the rest of the forms package: `value` /
|
|
31
|
+
* `defaultValue` + `onChange(value)`, a plain ISO "YYYY-MM-DD" string —
|
|
32
|
+
* drops in wherever `<input type="date">` would go, but themed and in
|
|
33
|
+
* pt-BR instead of the browser's own (English, unstyled) date picker.
|
|
34
|
+
*/
|
|
35
|
+
declare function DatePicker({ label, hint, error, required, placeholder, size, disabled, value, defaultValue, onChange, min, max, id, containerStyle, }: DatePickerProps): React.JSX.Element;
|
|
36
|
+
|
|
37
|
+
export { DatePicker, type DatePickerProps };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Calendar as CalendarIcon } 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
|
+
function parseISO(iso) {
|
|
10
|
+
if (!iso) return null;
|
|
11
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
|
|
12
|
+
if (!m) return null;
|
|
13
|
+
return { year: Number(m[1]), month: Number(m[2]) - 1, day: Number(m[3]) };
|
|
14
|
+
}
|
|
15
|
+
function toISO(year, month, day) {
|
|
16
|
+
return `${String(year).padStart(4, "0")}-${String(month + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
|
|
17
|
+
}
|
|
18
|
+
function formatDisplay(iso) {
|
|
19
|
+
const d = parseISO(iso);
|
|
20
|
+
if (!d) return iso;
|
|
21
|
+
return new Intl.DateTimeFormat("pt-BR", { day: "2-digit", month: "2-digit", year: "numeric" }).format(new Date(d.year, d.month, d.day));
|
|
22
|
+
}
|
|
23
|
+
function daysIn(year, month) {
|
|
24
|
+
return new Date(year, month + 1, 0).getDate();
|
|
25
|
+
}
|
|
26
|
+
function unavailableForMonth(year, month, min, max) {
|
|
27
|
+
if (!min && !max) return [];
|
|
28
|
+
const minD = parseISO(min);
|
|
29
|
+
const maxD = parseISO(max);
|
|
30
|
+
const out = [];
|
|
31
|
+
const total = daysIn(year, month);
|
|
32
|
+
for (let day = 1; day <= total; day++) {
|
|
33
|
+
if (minD && year * 372 + month * 31 + day < minD.year * 372 + minD.month * 31 + minD.day) {
|
|
34
|
+
out.push(day);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (maxD && year * 372 + month * 31 + day > maxD.year * 372 + maxD.month * 31 + maxD.day) {
|
|
38
|
+
out.push(day);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function DatePicker({
|
|
44
|
+
label,
|
|
45
|
+
hint,
|
|
46
|
+
error,
|
|
47
|
+
required,
|
|
48
|
+
placeholder = "Selecionar data",
|
|
49
|
+
size = "md",
|
|
50
|
+
disabled = false,
|
|
51
|
+
value,
|
|
52
|
+
defaultValue,
|
|
53
|
+
onChange,
|
|
54
|
+
min,
|
|
55
|
+
max,
|
|
56
|
+
id,
|
|
57
|
+
containerStyle
|
|
58
|
+
}) {
|
|
59
|
+
const [inner, setInner] = React.useState(defaultValue ?? "");
|
|
60
|
+
const iso = value !== void 0 ? value : inner;
|
|
61
|
+
const parsed = parseISO(iso);
|
|
62
|
+
const now = React.useMemo(() => /* @__PURE__ */ new Date(), []);
|
|
63
|
+
const [open, setOpen] = React.useState(false);
|
|
64
|
+
const [viewYear, setViewYear] = React.useState(parsed?.year ?? now.getFullYear());
|
|
65
|
+
const [viewMonth, setViewMonth] = React.useState(parsed?.month ?? now.getMonth());
|
|
66
|
+
const rootRef = React.useRef(null);
|
|
67
|
+
const triggerRef = React.useRef(null);
|
|
68
|
+
const generatedId = React.useId();
|
|
69
|
+
const rid = id || generatedId;
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (!open) return;
|
|
72
|
+
const onDown = (e) => {
|
|
73
|
+
if (rootRef.current && !rootRef.current.contains(e.target)) {
|
|
74
|
+
setOpen(false);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const onKey = (e) => {
|
|
78
|
+
if (e.key === "Escape") {
|
|
79
|
+
setOpen(false);
|
|
80
|
+
triggerRef.current?.focus();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
document.addEventListener("pointerdown", onDown, true);
|
|
84
|
+
document.addEventListener("keydown", onKey, true);
|
|
85
|
+
return () => {
|
|
86
|
+
document.removeEventListener("pointerdown", onDown, true);
|
|
87
|
+
document.removeEventListener("keydown", onKey, true);
|
|
88
|
+
};
|
|
89
|
+
}, [open]);
|
|
90
|
+
const openPopover = () => {
|
|
91
|
+
if (disabled) return;
|
|
92
|
+
setViewYear(parsed?.year ?? now.getFullYear());
|
|
93
|
+
setViewMonth(parsed?.month ?? now.getMonth());
|
|
94
|
+
setOpen(true);
|
|
95
|
+
};
|
|
96
|
+
const commit = (day) => {
|
|
97
|
+
const next = toISO(viewYear, viewMonth, day);
|
|
98
|
+
if (value === void 0) setInner(next);
|
|
99
|
+
onChange?.(next);
|
|
100
|
+
setOpen(false);
|
|
101
|
+
triggerRef.current?.focus();
|
|
102
|
+
};
|
|
103
|
+
const unavailable = React.useMemo(() => unavailableForMonth(viewYear, viewMonth, min, max), [viewYear, viewMonth, min, max]);
|
|
104
|
+
return /* @__PURE__ */ jsx(Field, { label, hint, error, required, htmlFor: rid, style: containerStyle, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, style: { position: "relative", width: "100%" }, children: [
|
|
105
|
+
/* @__PURE__ */ jsxs(
|
|
106
|
+
"button",
|
|
107
|
+
{
|
|
108
|
+
ref: triggerRef,
|
|
109
|
+
id: rid,
|
|
110
|
+
type: "button",
|
|
111
|
+
disabled,
|
|
112
|
+
"aria-haspopup": "dialog",
|
|
113
|
+
"aria-expanded": open,
|
|
114
|
+
onClick: () => open ? setOpen(false) : openPopover(),
|
|
115
|
+
style: fieldBoxStyle(size, !!error, open, disabled),
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ jsx(CalendarIcon, { size: 16, strokeWidth: 1.75, style: { flex: "0 0 auto", opacity: 0.7 } }),
|
|
118
|
+
/* @__PURE__ */ jsx(
|
|
119
|
+
"span",
|
|
120
|
+
{
|
|
121
|
+
style: sx({
|
|
122
|
+
flex: 1,
|
|
123
|
+
textAlign: "left",
|
|
124
|
+
overflow: "hidden",
|
|
125
|
+
textOverflow: "ellipsis",
|
|
126
|
+
whiteSpace: "nowrap",
|
|
127
|
+
color: iso ? "inherit" : "var(--text-muted)"
|
|
128
|
+
}),
|
|
129
|
+
children: iso ? formatDisplay(iso) : placeholder
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
open && /* @__PURE__ */ jsx(
|
|
136
|
+
"div",
|
|
137
|
+
{
|
|
138
|
+
role: "dialog",
|
|
139
|
+
"aria-label": label || "Escolher data",
|
|
140
|
+
tabIndex: -1,
|
|
141
|
+
style: sx({
|
|
142
|
+
position: "absolute",
|
|
143
|
+
top: "calc(100% + 6px)",
|
|
144
|
+
left: 0,
|
|
145
|
+
right: 0,
|
|
146
|
+
// The 7-column grid needs some floor width to stay readable —
|
|
147
|
+
// a narrow field (e.g. a compact "Data" next to "Motivo")
|
|
148
|
+
// would otherwise squeeze it. `left`/`right: 0` already
|
|
149
|
+
// matches the trigger's own width for anything wider.
|
|
150
|
+
minWidth: 272,
|
|
151
|
+
zIndex: 20,
|
|
152
|
+
background: "var(--bg-surface)",
|
|
153
|
+
border: "var(--border-width-hairline) solid var(--border-default)",
|
|
154
|
+
borderRadius: "var(--radius-md)",
|
|
155
|
+
boxShadow: "var(--shadow-lg)",
|
|
156
|
+
padding: "var(--space-3)",
|
|
157
|
+
outline: "none"
|
|
158
|
+
}),
|
|
159
|
+
children: /* @__PURE__ */ jsx(
|
|
160
|
+
CalendarGrid,
|
|
161
|
+
{
|
|
162
|
+
year: viewYear,
|
|
163
|
+
month: viewMonth,
|
|
164
|
+
selectedDate: parsed && parsed.year === viewYear && parsed.month === viewMonth ? parsed.day : void 0,
|
|
165
|
+
unavailable,
|
|
166
|
+
onMonthChange: (y, m) => {
|
|
167
|
+
setViewYear(y);
|
|
168
|
+
setViewMonth(m);
|
|
169
|
+
},
|
|
170
|
+
onSelectDate: commit,
|
|
171
|
+
squareCells: true,
|
|
172
|
+
trimEmptyRows: true
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
] }) });
|
|
178
|
+
}
|
|
179
|
+
export {
|
|
180
|
+
DatePicker
|
|
181
|
+
};
|
|
182
|
+
//# 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 } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nexport interface DatePickerProps {\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\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}\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): string {\n const d = parseISO(iso);\n if (!d) return iso;\n return new Intl.DateTimeFormat('pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(new Date(d.year, d.month, d.day));\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 and in\n * pt-BR instead of the browser's own (English, unstyled) date picker.\n */\nexport function DatePicker({\n label,\n hint,\n error,\n required,\n placeholder = 'Selecionar data',\n size = 'md',\n disabled = false,\n value,\n defaultValue,\n onChange,\n min,\n max,\n id,\n containerStyle,\n}: DatePickerProps) {\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 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 <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={fieldBoxStyle(size, !!error, open, disabled)}\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) : placeholder}\n </span>\n </button>\n\n {open && (\n <div\n role=\"dialog\"\n aria-label={label || 'Escolher data'}\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 />\n </div>\n )}\n </div>\n </Field>\n );\n}\n"],"mappings":";AA0KQ,SAUE,KAVF;AAxKR,YAAY,WAAW;AACvB,SAAS,YAAY,oBAAoB;AACzC,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AA6B9B,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,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,OAAO,GAAG,EAAE,SAAS,GAAG,GAAG,CAAC;AAC/G;AAEA,SAAS,cAAc,KAAqB;AAC1C,QAAM,IAAI,SAAS,GAAG;AACtB,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,IAAI,KAAK,eAAe,SAAS,EAAE,KAAK,WAAW,OAAO,WAAW,MAAM,UAAU,CAAC,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,EAAE,OAAO,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AC9F;AAAA,YACA,eAAe,CAAC,GAAG,MAAM;AACvB,0BAAY,CAAC;AACb,2BAAa,CAAC;AAAA,YAChB;AAAA,YACA,cAAc;AAAA,YACd,aAAW;AAAA,YACX,eAAa;AAAA;AAAA,QACf;AAAA;AAAA,IACF;AAAA,KAEJ,GACF;AAEJ;","names":[]}
|
|
@@ -20,6 +20,10 @@ interface TimeSlot {
|
|
|
20
20
|
* month. An `unavailable` day stays focusable (`aria-disabled`, not the
|
|
21
21
|
* native `disabled` — a disabled button can't receive focus at all) so the
|
|
22
22
|
* cursor can still land on it, just not select it.
|
|
23
|
+
*
|
|
24
|
+
* The calendar body itself (header + day grid) is `./_internal/CalendarGrid`
|
|
25
|
+
* — shared with `DatePicker` (SS-243), which wraps the same grid in a
|
|
26
|
+
* trigger+popover shell instead of this component's always-visible card.
|
|
23
27
|
*/
|
|
24
28
|
interface DateTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
25
29
|
/** Initial year. Defaults to the current year. */
|