@modoock/components 2.0.0 → 2.1.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.
@@ -0,0 +1,93 @@
1
+ import { type ReactNode } from "react";
2
+ import { type DateRangeValue } from "./date-picker";
3
+ import { type Column } from "./table";
4
+ export type { DateRangeValue };
5
+ export type AgendaView = "month" | "week" | "list";
6
+ export type AgendaEventStatus = "planned" | "confirmed" | "completed" | "cancelled" | "delayed" | (string & {});
7
+ export interface AgendaEvent {
8
+ id: string;
9
+ /** Main label shown on chips / list (patient, titre…). */
10
+ title: string;
11
+ startAt: Date | string;
12
+ endAt?: Date | string;
13
+ status?: AgendaEventStatus;
14
+ /** Secondary line (praticien, lieu…). */
15
+ subtitle?: string;
16
+ /** Free category label (type de créneau…). */
17
+ kind?: string;
18
+ /** Extra fields for custom list columns / filters. */
19
+ meta?: Record<string, unknown>;
20
+ }
21
+ export interface AgendaStatusOption {
22
+ value: string;
23
+ label: string;
24
+ }
25
+ export interface AgendaStatusStyle {
26
+ /** Classes for the event chip / week block. */
27
+ event: string;
28
+ /** Left accent strip on chips (falls back to `dot`). */
29
+ accent?: string;
30
+ /** Classes for the legend dot. */
31
+ dot: string;
32
+ /** Badge variant when shown as a badge. */
33
+ badge?: "default" | "primary" | "success" | "warning" | "danger" | "info";
34
+ }
35
+ export interface AgendaProps {
36
+ events: AgendaEvent[];
37
+ view: AgendaView;
38
+ onViewChange: (view: AgendaView) => void;
39
+ /** Visible period anchor (any day inside the month / week). */
40
+ anchorDate: Date;
41
+ onAnchorDateChange: (date: Date) => void;
42
+ onSelectEvent: (event: AgendaEvent) => void;
43
+ /** Empty day / slot click — typically open a create form. */
44
+ onCreateSlot?: (start: Date) => void;
45
+ /** Controlled free-text search. */
46
+ searchQuery?: string;
47
+ onSearchChange?: (query: string) => void;
48
+ searchPlaceholder?: string;
49
+ /**
50
+ * Extra filter controls rendered after the search field.
51
+ * Compose with Select / SelectFilter / DatePicker — the bar wraps cleanly.
52
+ */
53
+ filters?: ReactNode;
54
+ /** Override status catalogue (legend + default styles). */
55
+ statusOptions?: AgendaStatusOption[];
56
+ /** Merge / override chip styles keyed by status value. */
57
+ statusStyles?: Partial<Record<string, AgendaStatusStyle>>;
58
+ /** Optional period label override (defaults to French month / week range). */
59
+ periodLabel?: string;
60
+ weekStartHour?: number;
61
+ weekEndHour?: number;
62
+ weekSlotMinutes?: number;
63
+ maxEventsPerDay?: number;
64
+ listPageSize?: number;
65
+ /** Extra columns appended to the list view (after Date / Titre). */
66
+ listExtraColumns?: Column<AgendaListRow>[];
67
+ /**
68
+ * Controlled date range for list view filtering.
69
+ * Defaults to the month of `anchorDate` when omitted.
70
+ */
71
+ listRange?: DateRangeValue;
72
+ onListRangeChange?: (range: DateRangeValue) => void;
73
+ className?: string;
74
+ emptyMessage?: string;
75
+ }
76
+ /** Row shape exposed to custom list columns. */
77
+ export interface AgendaListRow {
78
+ id: string;
79
+ startAt: Date;
80
+ endAt: Date | null;
81
+ title: string;
82
+ subtitle: string;
83
+ kind: string;
84
+ status: string;
85
+ event: AgendaEvent;
86
+ }
87
+ export declare const AGENDA_STATUS_OPTIONS: AgendaStatusOption[];
88
+ /**
89
+ * Multi-view agenda: month grid, week time grid, and paginated list.
90
+ * Filters stay open-ended via the `filters` slot; search is optional.
91
+ */
92
+ export default function Agenda({ events, view, onViewChange, anchorDate, onAnchorDateChange, onSelectEvent, onCreateSlot, searchQuery, onSearchChange, searchPlaceholder, filters, statusOptions, statusStyles, periodLabel, weekStartHour, weekEndHour, weekSlotMinutes, maxEventsPerDay, listPageSize, listExtraColumns, listRange: listRangeProp, onListRangeChange, className, emptyMessage, }: AgendaProps): import("react").JSX.Element;
93
+ //# sourceMappingURL=agenda.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agenda.d.ts","sourceRoot":"","sources":["../components/ui/agenda.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,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E,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,IAAI,CAAC;IACd,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,WAAW,CAAC;CACpB;AAMD,eAAO,MAAM,qBAAqB,EAAE,kBAAkB,EAMrD,CAAC;AAmmCF;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAC7B,MAAM,EACN,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,cAAc,EACd,iBAAiC,EACjC,OAAO,EACP,aAAqC,EACrC,YAAY,EACZ,WAAW,EACX,aAAiB,EACjB,WAAgB,EAChB,eAAoB,EACpB,eAAmB,EACnB,YAAiB,EACjB,gBAAgB,EAChB,SAAS,EAAE,aAAa,EACxB,iBAAiB,EACjB,SAAc,EACd,YAAoD,GACrD,EAAE,WAAW,+BA+Gb"}
package/dist/agenda.js ADDED
@@ -0,0 +1,581 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useEffect, useMemo, useState, } from "react";
4
+ import Badge from "./badge";
5
+ import ClickableButton from "./button";
6
+ import { DateRangePicker } from "./date-picker";
7
+ import Icon from "./icon";
8
+ import Input from "./input";
9
+ import Modal from "./modal";
10
+ import Table from "./table";
11
+ /* ------------------------------------------------------------------ */
12
+ /* Defaults */
13
+ /* ------------------------------------------------------------------ */
14
+ export const AGENDA_STATUS_OPTIONS = [
15
+ { value: "planned", label: "Planifié" },
16
+ { value: "confirmed", label: "Confirmé" },
17
+ { value: "completed", label: "Terminé" },
18
+ { value: "cancelled", label: "Annulé" },
19
+ { value: "delayed", label: "Reporté" },
20
+ ];
21
+ const DEFAULT_STATUS_STYLES = {
22
+ planned: {
23
+ event: "bg-info-light text-info-foreground",
24
+ accent: "bg-info",
25
+ dot: "bg-info",
26
+ badge: "info",
27
+ },
28
+ confirmed: {
29
+ event: "bg-primary-light text-primary",
30
+ accent: "bg-primary",
31
+ dot: "bg-primary",
32
+ badge: "primary",
33
+ },
34
+ completed: {
35
+ event: "bg-success-light text-success-foreground",
36
+ accent: "bg-success",
37
+ dot: "bg-success",
38
+ badge: "success",
39
+ },
40
+ cancelled: {
41
+ event: "bg-danger-light text-danger-foreground",
42
+ accent: "bg-danger",
43
+ dot: "bg-danger",
44
+ badge: "danger",
45
+ },
46
+ delayed: {
47
+ event: "bg-warning-light text-warning-foreground",
48
+ accent: "bg-warning",
49
+ dot: "bg-warning",
50
+ badge: "warning",
51
+ },
52
+ };
53
+ const VIEW_TABS = [
54
+ { value: "month", label: "Mois" },
55
+ { value: "week", label: "Semaine" },
56
+ { value: "list", label: "Liste" },
57
+ ];
58
+ const WEEKDAY_HEADERS = ["Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"];
59
+ const MONTH_FORMAT = new Intl.DateTimeFormat("fr-FR", {
60
+ month: "long",
61
+ year: "numeric",
62
+ });
63
+ const WEEKDAY_SHORT = new Intl.DateTimeFormat("fr-FR", { weekday: "short" });
64
+ const DAY_LONG = new Intl.DateTimeFormat("fr-FR", {
65
+ weekday: "long",
66
+ day: "numeric",
67
+ month: "long",
68
+ year: "numeric",
69
+ });
70
+ const TIME_FORMAT = new Intl.DateTimeFormat("fr-FR", {
71
+ hour: "2-digit",
72
+ minute: "2-digit",
73
+ });
74
+ const DATETIME_FORMAT = new Intl.DateTimeFormat("fr-FR", {
75
+ day: "2-digit",
76
+ month: "2-digit",
77
+ year: "numeric",
78
+ hour: "2-digit",
79
+ minute: "2-digit",
80
+ });
81
+ /* ------------------------------------------------------------------ */
82
+ /* Date helpers */
83
+ /* ------------------------------------------------------------------ */
84
+ function toDate(value) {
85
+ return value instanceof Date ? value : new Date(value);
86
+ }
87
+ function startOfDay(date) {
88
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
89
+ }
90
+ function dayKey(date) {
91
+ const y = date.getFullYear();
92
+ const m = String(date.getMonth() + 1).padStart(2, "0");
93
+ const d = String(date.getDate()).padStart(2, "0");
94
+ return `${y}-${m}-${d}`;
95
+ }
96
+ function isSameDay(a, b) {
97
+ return dayKey(a) === dayKey(b);
98
+ }
99
+ function isToday(date) {
100
+ return isSameDay(date, new Date());
101
+ }
102
+ function addDays(date, days) {
103
+ const next = new Date(date);
104
+ next.setDate(next.getDate() + days);
105
+ return next;
106
+ }
107
+ function addMonths(date, months) {
108
+ return new Date(date.getFullYear(), date.getMonth() + months, 1);
109
+ }
110
+ function addWeeks(date, weeks) {
111
+ return addDays(date, weeks * 7);
112
+ }
113
+ function startOfWeek(date) {
114
+ const d = startOfDay(date);
115
+ const offset = (d.getDay() + 6) % 7;
116
+ return addDays(d, -offset);
117
+ }
118
+ function getWeekDays(anchor) {
119
+ const start = startOfWeek(anchor);
120
+ return Array.from({ length: 7 }, (_, i) => addDays(start, i));
121
+ }
122
+ function layoutMonthGrid(anchor) {
123
+ const first = new Date(anchor.getFullYear(), anchor.getMonth(), 1);
124
+ const start = startOfWeek(first);
125
+ return Array.from({ length: 42 }, (_, i) => addDays(start, i));
126
+ }
127
+ function isInDisplayedMonth(date, anchor) {
128
+ return (date.getFullYear() === anchor.getFullYear() &&
129
+ date.getMonth() === anchor.getMonth());
130
+ }
131
+ function formatEventTime(value) {
132
+ return TIME_FORMAT.format(toDate(value));
133
+ }
134
+ function monthRange(anchor) {
135
+ return {
136
+ from: new Date(anchor.getFullYear(), anchor.getMonth(), 1),
137
+ to: new Date(anchor.getFullYear(), anchor.getMonth() + 1, 0),
138
+ };
139
+ }
140
+ function shiftRangeByMonths(range, months) {
141
+ const from = range.from
142
+ ? new Date(range.from.getFullYear(), range.from.getMonth() + months, range.from.getDate())
143
+ : null;
144
+ const to = range.to
145
+ ? new Date(range.to.getFullYear(), range.to.getMonth() + months, range.to.getDate())
146
+ : null;
147
+ return { from, to };
148
+ }
149
+ function endOfDay(date) {
150
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
151
+ }
152
+ function eventInRange(event, range) {
153
+ const t = toDate(event.startAt).getTime();
154
+ if (range.from && t < startOfDay(range.from).getTime())
155
+ return false;
156
+ if (range.to && t > endOfDay(range.to).getTime())
157
+ return false;
158
+ return Boolean(range.from || range.to);
159
+ }
160
+ function defaultPeriodLabel(view, anchor, listRange) {
161
+ if (view === "week") {
162
+ const days = getWeekDays(anchor);
163
+ const from = days[0];
164
+ const to = days[6];
165
+ const sameMonth = from.getMonth() === to.getMonth();
166
+ const fromLabel = new Intl.DateTimeFormat("fr-FR", {
167
+ day: "numeric",
168
+ month: sameMonth ? undefined : "short",
169
+ }).format(from);
170
+ const toLabel = new Intl.DateTimeFormat("fr-FR", {
171
+ day: "numeric",
172
+ month: "short",
173
+ year: "numeric",
174
+ }).format(to);
175
+ return `${fromLabel} – ${toLabel}`;
176
+ }
177
+ if (view === "list" && listRange?.from && listRange?.to) {
178
+ const sameMonth = listRange.from.getMonth() === listRange.to.getMonth() &&
179
+ listRange.from.getFullYear() === listRange.to.getFullYear();
180
+ if (sameMonth &&
181
+ listRange.from.getDate() === 1 &&
182
+ listRange.to.getDate() ===
183
+ new Date(listRange.to.getFullYear(), listRange.to.getMonth() + 1, 0).getDate()) {
184
+ return MONTH_FORMAT.format(listRange.from);
185
+ }
186
+ const fmt = new Intl.DateTimeFormat("fr-FR", {
187
+ day: "numeric",
188
+ month: "short",
189
+ year: "numeric",
190
+ });
191
+ return `${fmt.format(listRange.from)} – ${fmt.format(listRange.to)}`;
192
+ }
193
+ return MONTH_FORMAT.format(anchor);
194
+ }
195
+ function groupEventsByDay(events) {
196
+ const map = new Map();
197
+ for (const event of events) {
198
+ const key = dayKey(toDate(event.startAt));
199
+ const list = map.get(key);
200
+ if (list)
201
+ list.push(event);
202
+ else
203
+ map.set(key, [event]);
204
+ }
205
+ for (const list of map.values()) {
206
+ list.sort((a, b) => toDate(a.startAt).getTime() - toDate(b.startAt).getTime());
207
+ }
208
+ return map;
209
+ }
210
+ function minutesSinceMidnight(date) {
211
+ return date.getHours() * 60 + date.getMinutes();
212
+ }
213
+ function entryWeekPosition(event, startHour, endHour) {
214
+ const start = toDate(event.startAt);
215
+ const end = event.endAt
216
+ ? toDate(event.endAt)
217
+ : new Date(start.getTime() + 60 * 60 * 1000);
218
+ const dayStart = startHour * 60;
219
+ const dayEnd = endHour * 60;
220
+ const span = Math.max(1, dayEnd - dayStart);
221
+ const top = Math.max(0, minutesSinceMidnight(start) - dayStart);
222
+ const bottom = Math.min(dayEnd, minutesSinceMidnight(end)) - dayStart;
223
+ const height = Math.max(28, bottom - top);
224
+ return {
225
+ topPct: (top / span) * 100,
226
+ heightPct: (height / span) * 100,
227
+ };
228
+ }
229
+ function resolveStyle(status, overrides) {
230
+ const key = status ?? "planned";
231
+ const base = overrides?.[key] ??
232
+ DEFAULT_STATUS_STYLES[key] ?? {
233
+ event: "bg-surface-muted text-foreground",
234
+ accent: "bg-muted-foreground",
235
+ dot: "bg-muted-foreground",
236
+ badge: "default",
237
+ };
238
+ return { ...base, accent: base.accent ?? base.dot };
239
+ }
240
+ function statusLabel(status, options) {
241
+ if (!status)
242
+ return "";
243
+ return options.find((o) => o.value === status)?.label ?? status;
244
+ }
245
+ /* ------------------------------------------------------------------ */
246
+ /* Shared UI pieces */
247
+ /* ------------------------------------------------------------------ */
248
+ function EmptyPeriod({ message }) {
249
+ return (_jsxs("div", { className: "flex flex-col items-center justify-center gap-inline rounded-large border border-dashed border-border bg-surface px-card py-section text-center", children: [_jsx(Icon, { name: "CalendarOff", variant: "muted", size: "large", "aria-hidden": "true" }), _jsx("p", { className: "text-body text-muted-foreground", children: message })] }));
250
+ }
251
+ function StatusLegend({ options, statusStyles, }) {
252
+ return (_jsxs("div", { className: "flex flex-wrap items-center gap-component border-t border-border px-component py-control text-small text-muted-foreground", children: [_jsx("span", { className: "text-label text-foreground", children: "L\u00E9gende" }), options.map((opt) => {
253
+ const style = resolveStyle(opt.value, statusStyles);
254
+ return (_jsxs("span", { className: "inline-flex items-center gap-micro", children: [_jsx("span", { className: `size-2 shrink-0 rounded-full ${style.dot}`, "aria-hidden": "true" }), opt.label] }, opt.value));
255
+ })] }));
256
+ }
257
+ function EventChip({ event, onSelect, statusStyles, }) {
258
+ const style = resolveStyle(event.status, statusStyles);
259
+ return (_jsxs("button", { type: "button", onClick: (e) => {
260
+ e.preventDefault();
261
+ e.stopPropagation();
262
+ onSelect(event);
263
+ }, className: `flex w-full items-stretch overflow-hidden rounded-small text-left transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${style.event}`, title: `${formatEventTime(event.startAt)} — ${event.title}`, children: [_jsx("span", { className: `w-0.5 shrink-0 ${style.accent}`, "aria-hidden": "true" }), _jsxs("span", { className: "min-w-0 flex-1 truncate px-1.5 py-0.5 text-[10px] leading-tight", children: [_jsx("span", { className: "font-semibold tabular-nums", children: formatEventTime(event.startAt) }), " ", _jsx("span", { className: "opacity-90", children: event.title })] })] }));
264
+ }
265
+ function DayEventsModal({ open, title, events, onClose, onSelectEvent, statusOptions, statusStyles, }) {
266
+ if (!open)
267
+ return null;
268
+ return (_jsx(Modal, { open: open, title: title, onClose: onClose, secondaryAction: { label: "Fermer", onClick: onClose }, children: _jsx("ul", { className: "flex flex-col gap-inline", children: events.map((event) => {
269
+ const style = resolveStyle(event.status, statusStyles);
270
+ const label = statusLabel(event.status, statusOptions);
271
+ return (_jsx("li", { children: _jsxs("button", { type: "button", onClick: () => {
272
+ onClose();
273
+ onSelectEvent(event);
274
+ }, className: "flex w-full items-start gap-inline rounded-large border border-border bg-surface px-component py-control text-left transition-colors hover:border-primary hover:bg-primary-light/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary", children: [_jsx("span", { className: `mt-1 size-2.5 shrink-0 rounded-full ${style.dot}`, "aria-hidden": "true" }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "flex flex-wrap items-center gap-inline", children: [_jsxs("span", { className: "inline-flex items-center gap-micro text-body-medium text-foreground", children: [_jsx(Icon, { name: "Clock", size: "small", variant: "muted", "aria-hidden": "true" }), formatEventTime(event.startAt), event.endAt
275
+ ? ` – ${formatEventTime(event.endAt)}`
276
+ : ""] }), label ? (_jsx(Badge, { variant: style.badge ?? "default", children: label })) : null] }), _jsx("span", { className: "mt-micro block text-body text-foreground", children: event.title }), (event.subtitle || event.kind) && (_jsx("span", { className: "mt-micro block text-small text-muted-foreground", children: [event.kind, event.subtitle].filter(Boolean).join(" · ") }))] }), _jsx(Icon, { name: "ChevronRight", size: "small", variant: "muted", "aria-hidden": "true", className: "mt-1 shrink-0" })] }) }, event.id));
277
+ }) }) }));
278
+ }
279
+ /** View switcher — same visual language as Tabs. */
280
+ function ViewSwitcher({ view, onViewChange, }) {
281
+ return (_jsx("div", { role: "tablist", "aria-label": "Vue agenda", className: "inline-flex max-w-full items-center gap-micro overflow-x-auto rounded-large bg-surface-muted p-micro", children: VIEW_TABS.map((tab) => {
282
+ const active = view === tab.value;
283
+ return (_jsx(ClickableButton, { type: "button", variant: "bare", role: "tab", "aria-selected": active, onClick: () => onViewChange(tab.value), className: `whitespace-nowrap rounded-large px-component py-inline text-body-medium focus-visible:ring-primary ${active
284
+ ? "bg-surface text-primary shadow-sm"
285
+ : "bg-transparent text-muted-foreground hover:text-foreground"}`, children: tab.label }, tab.value));
286
+ }) }));
287
+ }
288
+ function PeriodNav({ view, periodLabel, onShift, onToday, }) {
289
+ const prevLabel = view === "week"
290
+ ? "Semaine précédente"
291
+ : view === "list"
292
+ ? "Période précédente"
293
+ : "Mois précédent";
294
+ const nextLabel = view === "week"
295
+ ? "Semaine suivante"
296
+ : view === "list"
297
+ ? "Période suivante"
298
+ : "Mois suivant";
299
+ return (_jsxs("div", { className: "flex flex-wrap items-center gap-inline", children: [_jsxs("div", { className: "flex items-center gap-micro", children: [_jsx(ClickableButton, { type: "button", variant: "secondary", size: "icon", "aria-label": prevLabel, onClick: () => onShift(-1), children: _jsx(Icon, { name: "ChevronLeft", "aria-hidden": "true" }) }), _jsx(ClickableButton, { type: "button", variant: "secondary", size: "icon", "aria-label": nextLabel, onClick: () => onShift(1), children: _jsx(Icon, { name: "ChevronRight", "aria-hidden": "true" }) })] }), _jsx("h3", { className: "min-w-0 text-component-title capitalize text-foreground", children: periodLabel }), _jsx(ClickableButton, { type: "button", variant: "ghost", size: "sm", onClick: onToday, children: "Aujourd'hui" })] }));
300
+ }
301
+ function AgendaToolbar({ view, onViewChange, anchorDate, onAnchorDateChange, periodLabel, searchQuery, onSearchChange, searchPlaceholder, filters, listRange, onListRangeChange, }) {
302
+ const shift = (direction) => {
303
+ if (view === "week") {
304
+ onAnchorDateChange(addWeeks(anchorDate, direction));
305
+ return;
306
+ }
307
+ if (view === "list") {
308
+ const next = shiftRangeByMonths(listRange, direction);
309
+ onListRangeChange(next);
310
+ if (next.from)
311
+ onAnchorDateChange(next.from);
312
+ return;
313
+ }
314
+ onAnchorDateChange(addMonths(anchorDate, direction));
315
+ };
316
+ const goToday = () => {
317
+ const today = new Date();
318
+ onAnchorDateChange(today);
319
+ if (view === "list")
320
+ onListRangeChange(monthRange(today));
321
+ };
322
+ const showFilters = Boolean(onSearchChange || filters || view === "list");
323
+ return (_jsxs("div", { className: "flex flex-col gap-component", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-component", children: [_jsx(PeriodNav, { view: view, periodLabel: periodLabel, onShift: shift, onToday: goToday }), _jsx(ViewSwitcher, { view: view, onViewChange: onViewChange })] }), showFilters ? (_jsxs("div", { className: "flex flex-wrap items-end gap-inline rounded-large border border-border bg-surface p-component", children: [view === "list" ? (_jsx("div", { className: "min-w-[16rem] w-[18rem]", children: _jsx(DateRangePicker, { label: "P\u00E9riode", value: listRange, onChange: onListRangeChange, placeholder: "Du\u2026 au\u2026" }) })) : null, onSearchChange ? (_jsx("div", { className: "min-w-[14rem] flex-1 basis-[14rem]", children: _jsx(Input, { type: "search", label: "Recherche", value: searchQuery ?? "", onChange: (e) => onSearchChange(e.target.value), placeholder: searchPlaceholder, autoComplete: "off", clearable: true, onClear: () => onSearchChange(""), icon: _jsx(Icon, { name: "Search" }) }) })) : null, filters] })) : null] }));
324
+ }
325
+ /* ------------------------------------------------------------------ */
326
+ /* Month */
327
+ /* ------------------------------------------------------------------ */
328
+ function MonthView({ events, anchorDate, onSelectEvent, onCreateSlot, maxEventsPerDay, statusOptions, statusStyles, }) {
329
+ const [mounted, setMounted] = useState(false);
330
+ const [dayDialog, setDayDialog] = useState({
331
+ open: false,
332
+ title: "",
333
+ events: [],
334
+ });
335
+ useEffect(() => {
336
+ setMounted(true);
337
+ }, []);
338
+ const byDay = useMemo(() => groupEventsByDay(events), [events]);
339
+ const cells = useMemo(() => layoutMonthGrid(anchorDate), [anchorDate]);
340
+ const openDay = (date, dayEvents) => {
341
+ if (dayEvents.length === 0) {
342
+ if (!onCreateSlot)
343
+ return;
344
+ const start = new Date(date);
345
+ start.setHours(9, 0, 0, 0);
346
+ onCreateSlot(start);
347
+ return;
348
+ }
349
+ if (dayEvents.length === 1) {
350
+ onSelectEvent(dayEvents[0]);
351
+ return;
352
+ }
353
+ setDayDialog({
354
+ open: true,
355
+ title: DAY_LONG.format(date),
356
+ events: dayEvents,
357
+ });
358
+ };
359
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "overflow-hidden rounded-large border border-border bg-surface", children: [_jsx("div", { className: "grid grid-cols-7 border-b border-border bg-surface-muted", children: WEEKDAY_HEADERS.map((label) => (_jsx("div", { className: "px-inline py-control text-center text-label uppercase tracking-wide text-muted-foreground", children: label }, label))) }), _jsx("div", { className: "grid grid-cols-7", children: cells.map((cellDate, cellIndex) => {
360
+ const key = dayKey(cellDate);
361
+ const dayEvents = byDay.get(key) ?? [];
362
+ const inMonth = isInDisplayedMonth(cellDate, anchorDate);
363
+ const today = isToday(cellDate);
364
+ const visible = dayEvents.slice(0, maxEventsPerDay);
365
+ const extra = dayEvents.length - maxEventsPerDay;
366
+ const canCreate = dayEvents.length === 0 && Boolean(onCreateSlot);
367
+ return (_jsxs("div", { role: "button", tabIndex: inMonth ? 0 : -1, "aria-label": canCreate
368
+ ? `${cellDate.getDate()} — ajouter un créneau`
369
+ : `${cellDate.getDate()}, ${dayEvents.length} événement${dayEvents.length > 1 ? "s" : ""}`, onClick: () => openDay(cellDate, dayEvents), onKeyDown: (e) => {
370
+ if (e.key === "Enter" || e.key === " ") {
371
+ e.preventDefault();
372
+ openDay(cellDate, dayEvents);
373
+ }
374
+ }, className: `group relative flex min-h-[6.5rem] flex-col gap-micro border-b border-r border-border p-inline transition-colors last:border-r-0 focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary ${inMonth
375
+ ? "bg-surface hover:bg-surface-muted/60"
376
+ : "bg-surface-muted/40 text-muted-foreground"} ${cellIndex % 7 === 6 ? "border-r-0" : ""}`, children: [_jsxs("div", { className: "flex items-center justify-between gap-micro", children: [_jsx("span", { className: `inline-flex size-7 items-center justify-center rounded-full text-small ${today
377
+ ? "bg-primary font-semibold text-primary-foreground"
378
+ : inMonth
379
+ ? "font-medium text-foreground"
380
+ : "text-muted-foreground"}`, children: cellDate.getDate() }), canCreate ? (_jsx("span", { className: "pointer-events-none inline-flex size-6 items-center justify-center rounded-small text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100", children: _jsx(Icon, { name: "Plus", size: "small", "aria-hidden": "true" }) })) : dayEvents.length > 0 ? (_jsx("span", { className: "text-[10px] tabular-nums text-muted-foreground", children: dayEvents.length })) : null] }), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-micro", children: [mounted &&
381
+ visible.map((event) => (_jsx(EventChip, { event: event, onSelect: onSelectEvent, statusStyles: statusStyles }, event.id))), mounted && extra > 0 ? (_jsxs("button", { type: "button", onClick: (e) => {
382
+ e.stopPropagation();
383
+ openDay(cellDate, dayEvents);
384
+ }, className: "rounded-small px-1 py-0.5 text-left text-[10px] font-medium text-primary hover:bg-primary-light focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary", children: ["+", extra, " autre", extra > 1 ? "s" : ""] })) : null] })] }, `${key}-${cellIndex}`));
385
+ }) }), _jsx(StatusLegend, { options: statusOptions, statusStyles: statusStyles })] }), _jsx(DayEventsModal, { open: dayDialog.open, title: dayDialog.title, events: dayDialog.events, onClose: () => setDayDialog((d) => ({ ...d, open: false })), onSelectEvent: onSelectEvent, statusOptions: statusOptions, statusStyles: statusStyles })] }));
386
+ }
387
+ /* ------------------------------------------------------------------ */
388
+ /* Week */
389
+ /* ------------------------------------------------------------------ */
390
+ function WeekView({ events, anchorDate, onSelectEvent, onCreateSlot, weekStartHour, weekEndHour, weekSlotMinutes, statusOptions, statusStyles, }) {
391
+ const [mounted, setMounted] = useState(false);
392
+ useEffect(() => {
393
+ setMounted(true);
394
+ }, []);
395
+ const weekDays = useMemo(() => getWeekDays(anchorDate), [anchorDate]);
396
+ const byDay = useMemo(() => groupEventsByDay(events), [events]);
397
+ const slotCount = Math.max(1, ((weekEndHour - weekStartHour) * 60) / weekSlotMinutes);
398
+ const hourLabels = Array.from({ length: slotCount }, (_, i) => {
399
+ const min = weekStartHour * 60 + i * weekSlotMinutes;
400
+ const h = Math.floor(min / 60);
401
+ const m = min % 60;
402
+ return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
403
+ });
404
+ const now = new Date();
405
+ const showNowLine = weekDays.some((d) => isToday(d)) &&
406
+ minutesSinceMidnight(now) >= weekStartHour * 60 &&
407
+ minutesSinceMidnight(now) <= weekEndHour * 60;
408
+ const nowTopPct = showNowLine
409
+ ? ((minutesSinceMidnight(now) - weekStartHour * 60) /
410
+ Math.max(1, (weekEndHour - weekStartHour) * 60)) *
411
+ 100
412
+ : 0;
413
+ const handleColumnClick = (day, event) => {
414
+ if (!onCreateSlot)
415
+ return;
416
+ if (event.target.closest("button"))
417
+ return;
418
+ const rect = event.currentTarget.getBoundingClientRect();
419
+ const y = event.clientY - rect.top;
420
+ const pct = Math.max(0, Math.min(1, y / rect.height));
421
+ const minutes = weekStartHour * 60 +
422
+ Math.round((pct * (weekEndHour - weekStartHour) * 60) / weekSlotMinutes) *
423
+ weekSlotMinutes;
424
+ const start = new Date(day);
425
+ start.setHours(Math.floor(minutes / 60), minutes % 60, 0, 0);
426
+ onCreateSlot(start);
427
+ };
428
+ return (_jsxs("div", { className: "overflow-hidden rounded-large border border-border bg-surface", children: [_jsx("div", { className: "overflow-x-auto", children: _jsxs("div", { className: "min-w-[52rem]", children: [_jsxs("div", { className: "grid grid-cols-[3.75rem_repeat(7,1fr)] border-b border-border bg-surface-muted", children: [_jsx("div", { "aria-hidden": "true" }), weekDays.map((d) => {
429
+ const today = isToday(d);
430
+ return (_jsxs("div", { className: "border-l border-border px-inline py-control text-center", children: [_jsx("p", { className: "text-label uppercase text-muted-foreground", children: WEEKDAY_SHORT.format(d).replace(".", "") }), _jsx("p", { className: `mx-auto mt-micro inline-flex size-8 items-center justify-center rounded-full text-body-medium ${today
431
+ ? "bg-primary font-semibold text-primary-foreground"
432
+ : "text-foreground"}`, children: d.getDate() })] }, dayKey(d)));
433
+ })] }), _jsxs("div", { className: "relative grid grid-cols-[3.75rem_repeat(7,1fr)]", children: [_jsx("div", { className: "border-r border-border", children: hourLabels.map((label, i) => (_jsx("div", { className: "flex h-8 items-start justify-end border-b border-border/50 pr-inline pt-0.5 text-[10px] tabular-nums text-muted-foreground", children: i % 2 === 0 ? label : "" }, label))) }), weekDays.map((d) => {
434
+ const dayEvents = byDay.get(dayKey(d)) ?? [];
435
+ return (_jsxs("div", { className: `relative border-l border-border ${onCreateSlot ? "cursor-pointer" : ""}`, style: { height: `${slotCount * 2}rem` }, onClick: (e) => handleColumnClick(d, e), title: onCreateSlot
436
+ ? "Cliquer pour ajouter un créneau"
437
+ : undefined, children: [Array.from({ length: slotCount }).map((_, i) => (_jsx("div", { className: "absolute right-0 left-0 border-b border-border/40", style: {
438
+ top: `${(i / slotCount) * 100}%`,
439
+ height: `${100 / slotCount}%`,
440
+ } }, i))), showNowLine && isToday(d) ? (_jsx("div", { className: "pointer-events-none absolute right-0 left-0 z-[2] border-t-2 border-danger", style: { top: `${nowTopPct}%` }, "aria-hidden": "true", children: _jsx("span", { className: "absolute -left-1 -top-1.5 size-2.5 rounded-full bg-danger" }) })) : null, mounted &&
441
+ dayEvents.map((event) => {
442
+ const { topPct, heightPct } = entryWeekPosition(event, weekStartHour, weekEndHour);
443
+ const style = resolveStyle(event.status, statusStyles);
444
+ return (_jsxs("button", { type: "button", onClick: (e) => {
445
+ e.stopPropagation();
446
+ onSelectEvent(event);
447
+ }, className: `absolute right-1 left-1 z-[1] flex overflow-hidden rounded-small text-left shadow-sm transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${style.event}`, style: {
448
+ top: `${topPct}%`,
449
+ height: `${heightPct}%`,
450
+ minHeight: "1.35rem",
451
+ }, title: `${formatEventTime(event.startAt)} ${event.title}`, children: [_jsx("span", { className: `w-0.5 shrink-0 ${style.accent}`, "aria-hidden": "true" }), _jsxs("span", { className: "min-w-0 flex-1 overflow-hidden px-1 py-0.5", children: [_jsx("span", { className: "block text-[10px] font-semibold tabular-nums", children: formatEventTime(event.startAt) }), _jsx("span", { className: "block truncate text-[10px]", children: event.title })] })] }, event.id));
452
+ })] }, dayKey(d)));
453
+ })] })] }) }), _jsx(StatusLegend, { options: statusOptions, statusStyles: statusStyles })] }));
454
+ }
455
+ /* ------------------------------------------------------------------ */
456
+ /* List */
457
+ /* ------------------------------------------------------------------ */
458
+ function ListView({ events, onSelectEvent, listPageSize, listExtraColumns, statusOptions, statusStyles, emptyMessage, }) {
459
+ const rows = useMemo(() => [...events]
460
+ .sort((a, b) => toDate(a.startAt).getTime() - toDate(b.startAt).getTime())
461
+ .map((event) => ({
462
+ id: event.id,
463
+ startAt: toDate(event.startAt),
464
+ endAt: event.endAt ? toDate(event.endAt) : null,
465
+ title: event.title,
466
+ subtitle: event.subtitle ?? "",
467
+ kind: event.kind ?? "",
468
+ status: event.status ?? "",
469
+ event,
470
+ })), [events]);
471
+ const columns = useMemo(() => {
472
+ const base = [
473
+ {
474
+ key: "startAt",
475
+ label: "Date / heure",
476
+ sortable: true,
477
+ render: (row) => (_jsxs("span", { className: "inline-flex items-center gap-inline text-body-medium", children: [_jsx(Icon, { name: "Clock", size: "small", variant: "muted", "aria-hidden": "true" }), DATETIME_FORMAT.format(row.startAt)] })),
478
+ },
479
+ {
480
+ key: "title",
481
+ label: "Titre",
482
+ sortable: true,
483
+ render: (row) => (_jsxs("span", { className: "flex min-w-0 flex-col", children: [_jsx("span", { className: "text-body-medium text-foreground", children: row.title }), row.subtitle ? (_jsx("span", { className: "text-small text-muted-foreground", children: row.subtitle })) : null] })),
484
+ },
485
+ {
486
+ key: "kind",
487
+ label: "Type",
488
+ sortable: true,
489
+ className: "text-muted-foreground",
490
+ render: (row) => row.kind || "—",
491
+ },
492
+ {
493
+ key: "status",
494
+ label: "Statut",
495
+ sortable: true,
496
+ render: (row) => {
497
+ const style = resolveStyle(row.status, statusStyles);
498
+ const label = statusOptions.find((o) => o.value === row.status)?.label ??
499
+ row.status ??
500
+ "—";
501
+ return _jsx(Badge, { variant: style.badge ?? "default", children: label });
502
+ },
503
+ },
504
+ ];
505
+ return listExtraColumns ? [...base, ...listExtraColumns] : base;
506
+ }, [listExtraColumns, statusOptions, statusStyles]);
507
+ if (events.length === 0) {
508
+ return _jsx(EmptyPeriod, { message: emptyMessage });
509
+ }
510
+ return (_jsx(Table, { columns: columns, data: rows, rowsPerPage: listPageSize, emptyMessage: emptyMessage, getRowKey: (row) => row.id, cardActions: {
511
+ row: (row) => [
512
+ {
513
+ label: "Voir",
514
+ icon: "Eye",
515
+ onSelect: () => onSelectEvent(row.event),
516
+ },
517
+ ],
518
+ } }));
519
+ }
520
+ /* ------------------------------------------------------------------ */
521
+ /* Agenda */
522
+ /* ------------------------------------------------------------------ */
523
+ /**
524
+ * Multi-view agenda: month grid, week time grid, and paginated list.
525
+ * Filters stay open-ended via the `filters` slot; search is optional.
526
+ */
527
+ export default function Agenda({ events, view, onViewChange, anchorDate, onAnchorDateChange, onSelectEvent, onCreateSlot, searchQuery, onSearchChange, searchPlaceholder = "Rechercher…", filters, statusOptions = AGENDA_STATUS_OPTIONS, statusStyles, periodLabel, weekStartHour = 8, weekEndHour = 20, weekSlotMinutes = 30, maxEventsPerDay = 3, listPageSize = 10, listExtraColumns, listRange: listRangeProp, onListRangeChange, className = "", emptyMessage = "Aucun événement pour cette période.", }) {
528
+ const [internalListRange, setInternalListRange] = useState(() => listRangeProp ?? monthRange(anchorDate));
529
+ const listRange = listRangeProp ?? internalListRange;
530
+ const setListRange = (range) => {
531
+ if (!listRangeProp)
532
+ setInternalListRange(range);
533
+ onListRangeChange?.(range);
534
+ if (range.from)
535
+ onAnchorDateChange(range.from);
536
+ };
537
+ // Keep uncontrolled range aligned when the user changes month outside list view.
538
+ useEffect(() => {
539
+ if (listRangeProp)
540
+ return;
541
+ if (view !== "list")
542
+ setInternalListRange(monthRange(anchorDate));
543
+ }, [anchorDate, view, listRangeProp]);
544
+ const label = periodLabel ?? defaultPeriodLabel(view, anchorDate, listRange);
545
+ const filteredEvents = useMemo(() => {
546
+ const q = searchQuery?.trim().toLowerCase();
547
+ if (!q)
548
+ return events;
549
+ return events.filter((event) => {
550
+ const haystack = [event.title, event.subtitle, event.kind, event.status]
551
+ .filter(Boolean)
552
+ .join(" ")
553
+ .toLowerCase();
554
+ return haystack.includes(q);
555
+ });
556
+ }, [events, searchQuery]);
557
+ const periodEvents = useMemo(() => {
558
+ if (view === "week") {
559
+ const days = getWeekDays(anchorDate);
560
+ const from = startOfDay(days[0]).getTime();
561
+ const to = addDays(startOfDay(days[6]), 1).getTime();
562
+ return filteredEvents.filter((e) => {
563
+ const t = toDate(e.startAt).getTime();
564
+ return t >= from && t < to;
565
+ });
566
+ }
567
+ if (view === "list") {
568
+ if (listRange.from || listRange.to) {
569
+ return filteredEvents.filter((e) => eventInRange(e, listRange));
570
+ }
571
+ // Incomplete range: fall back to the anchor month.
572
+ }
573
+ const y = anchorDate.getFullYear();
574
+ const m = anchorDate.getMonth();
575
+ return filteredEvents.filter((e) => {
576
+ const d = toDate(e.startAt);
577
+ return d.getFullYear() === y && d.getMonth() === m;
578
+ });
579
+ }, [filteredEvents, view, anchorDate, listRange]);
580
+ return (_jsxs("div", { className: `flex flex-col gap-component ${className}`.trim(), children: [_jsx(AgendaToolbar, { view: view, onViewChange: onViewChange, anchorDate: anchorDate, onAnchorDateChange: onAnchorDateChange, periodLabel: label, searchQuery: searchQuery, onSearchChange: onSearchChange, searchPlaceholder: searchPlaceholder, filters: filters, listRange: listRange, onListRangeChange: setListRange }), view === "month" && (_jsx(MonthView, { events: periodEvents, anchorDate: anchorDate, onSelectEvent: onSelectEvent, onCreateSlot: onCreateSlot, maxEventsPerDay: maxEventsPerDay, statusOptions: statusOptions, statusStyles: statusStyles })), view === "week" && (_jsx(WeekView, { events: periodEvents, anchorDate: anchorDate, onSelectEvent: onSelectEvent, onCreateSlot: onCreateSlot, weekStartHour: weekStartHour, weekEndHour: weekEndHour, weekSlotMinutes: weekSlotMinutes, statusOptions: statusOptions, statusStyles: statusStyles })), view === "list" && (_jsx(ListView, { events: periodEvents, onSelectEvent: onSelectEvent, listPageSize: listPageSize, listExtraColumns: listExtraColumns, statusOptions: statusOptions, statusStyles: statusStyles, emptyMessage: emptyMessage }))] }));
581
+ }
@@ -0,0 +1,47 @@
1
+ export type DateRangeValue = {
2
+ from: Date | null;
3
+ to: Date | null;
4
+ };
5
+ interface FieldChromeProps {
6
+ label?: string;
7
+ required?: boolean;
8
+ disabled?: boolean;
9
+ error?: string;
10
+ helper?: string;
11
+ className?: string;
12
+ }
13
+ interface DatePickerBaseProps extends FieldChromeProps {
14
+ minDate?: Date;
15
+ maxDate?: Date;
16
+ placeholder?: string;
17
+ clearable?: boolean;
18
+ }
19
+ export interface DatePickerProps extends DatePickerBaseProps {
20
+ value: Date | null;
21
+ onChange: (value: Date | null) => void;
22
+ }
23
+ export interface DateTimePickerProps extends DatePickerBaseProps {
24
+ value: Date | null;
25
+ onChange: (value: Date | null) => void;
26
+ }
27
+ export interface DateRangePickerProps extends DatePickerBaseProps {
28
+ value: DateRangeValue;
29
+ onChange: (value: DateRangeValue) => void;
30
+ }
31
+ /**
32
+ * Single-date picker.
33
+ * Trigger matches Select/Input (`ds-input`); calendar opens below.
34
+ */
35
+ export declare function DatePicker({ label, value, onChange, placeholder, minDate, maxDate, disabled, required, error, helper, clearable, className, }: DatePickerProps): import("react").JSX.Element;
36
+ /**
37
+ * Date and time picker.
38
+ * Day selection updates the date; time is confirmed via the time field.
39
+ */
40
+ export declare function DateTimePicker({ label, value, onChange, placeholder, minDate, maxDate, disabled, required, error, helper, clearable, className, }: DateTimePickerProps): import("react").JSX.Element;
41
+ /**
42
+ * Date range picker (from → to).
43
+ * First click sets the start; second click sets the end.
44
+ */
45
+ export declare function DateRangePicker({ label, value, onChange, placeholder, minDate, maxDate, disabled, required, error, helper, clearable, className, }: DateRangePickerProps): import("react").JSX.Element;
46
+ export {};
47
+ //# sourceMappingURL=date-picker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../components/ui/date-picker.tsx"],"names":[],"mappings":"AAkBA,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,EAAE,EAAE,IAAI,GAAG,IAAI,CAAC;CACjB,CAAC;AAEF,UAAU,gBAAgB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,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AAO,EACP,OAAO,EACP,QAAgB,EAChB,QAAgB,EAChB,KAAK,EACL,MAAM,EACN,SAAgB,EAChB,SAAc,GACf,EAAE,oBAAoB,+BA4GtB"}
@@ -0,0 +1,327 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useMemo, useRef, useState, } from "react";
4
+ import Icon from "./icon";
5
+ import ClickableButton from "./button";
6
+ /* ------------------------------------------------------------------ */
7
+ /* Locale helpers (French UI copy) */
8
+ /* ------------------------------------------------------------------ */
9
+ const WEEKDAY_LABELS = ["Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"];
10
+ const DATE_FORMAT = new Intl.DateTimeFormat("fr-FR", {
11
+ day: "2-digit",
12
+ month: "2-digit",
13
+ year: "numeric",
14
+ });
15
+ const DATETIME_FORMAT = new Intl.DateTimeFormat("fr-FR", {
16
+ day: "2-digit",
17
+ month: "2-digit",
18
+ year: "numeric",
19
+ hour: "2-digit",
20
+ minute: "2-digit",
21
+ });
22
+ const MONTH_TITLE_FORMAT = new Intl.DateTimeFormat("fr-FR", {
23
+ month: "long",
24
+ year: "numeric",
25
+ });
26
+ function startOfDay(date) {
27
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
28
+ }
29
+ function isSameDay(a, b) {
30
+ if (!a || !b)
31
+ return false;
32
+ return (a.getFullYear() === b.getFullYear() &&
33
+ a.getMonth() === b.getMonth() &&
34
+ a.getDate() === b.getDate());
35
+ }
36
+ function isBeforeDay(a, b) {
37
+ return startOfDay(a).getTime() < startOfDay(b).getTime();
38
+ }
39
+ function isAfterDay(a, b) {
40
+ return startOfDay(a).getTime() > startOfDay(b).getTime();
41
+ }
42
+ function clampToBounds(date, minDate, maxDate) {
43
+ let next = date;
44
+ if (minDate && isBeforeDay(next, minDate))
45
+ next = startOfDay(minDate);
46
+ if (maxDate && isAfterDay(next, maxDate))
47
+ next = startOfDay(maxDate);
48
+ return next;
49
+ }
50
+ function withTime(date, hours, minutes) {
51
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), hours, minutes, 0, 0);
52
+ }
53
+ function formatTimeValue(date) {
54
+ return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
55
+ }
56
+ function parseTimeValue(value) {
57
+ const match = /^(\d{2}):(\d{2})$/.exec(value);
58
+ if (!match)
59
+ return null;
60
+ const hours = Number(match[1]);
61
+ const minutes = Number(match[2]);
62
+ if (hours > 23 || minutes > 59)
63
+ return null;
64
+ return { hours, minutes };
65
+ }
66
+ function formatRangeLabel(value) {
67
+ if (!value.from && !value.to)
68
+ return null;
69
+ if (value.from && value.to) {
70
+ return `${DATE_FORMAT.format(value.from)} – ${DATE_FORMAT.format(value.to)}`;
71
+ }
72
+ if (value.from)
73
+ return `${DATE_FORMAT.format(value.from)} – …`;
74
+ return `… – ${DATE_FORMAT.format(value.to)}`;
75
+ }
76
+ /* ------------------------------------------------------------------ */
77
+ /* Field chrome */
78
+ /* ------------------------------------------------------------------ */
79
+ const LABEL_CLASS = "mb-inline flex items-center gap-micro text-label text-muted-foreground";
80
+ function RequiredMark() {
81
+ return (_jsx("span", { "aria-hidden": "true", className: "text-danger", children: "*" }));
82
+ }
83
+ function FieldFeedback({ id, error }) {
84
+ if (!error)
85
+ return null;
86
+ return (_jsxs("p", { id: id, className: "flex items-start gap-micro text-small text-danger-foreground [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0", children: [_jsx(Icon, { name: "CircleAlert", variant: "danger", "aria-hidden": "true" }), _jsx("span", { children: error })] }));
87
+ }
88
+ function useDismissibleOpen() {
89
+ const [open, setOpen] = useState(false);
90
+ const rootRef = useRef(null);
91
+ useEffect(() => {
92
+ if (!open)
93
+ return;
94
+ const close = () => setOpen(false);
95
+ const focusTrigger = () => {
96
+ rootRef.current
97
+ ?.querySelector("button[aria-haspopup]")
98
+ ?.focus();
99
+ };
100
+ const isOutside = (target) => target instanceof Node && !rootRef.current?.contains(target);
101
+ const onPointerDown = (event) => {
102
+ if (isOutside(event.target))
103
+ close();
104
+ };
105
+ const onKeyDown = (event) => {
106
+ if (event.key !== "Escape")
107
+ return;
108
+ event.preventDefault();
109
+ event.stopPropagation();
110
+ focusTrigger();
111
+ close();
112
+ };
113
+ const onFocusIn = (event) => {
114
+ if (isOutside(event.target))
115
+ close();
116
+ };
117
+ document.addEventListener("pointerdown", onPointerDown, true);
118
+ document.addEventListener("keydown", onKeyDown, true);
119
+ document.addEventListener("focusin", onFocusIn);
120
+ return () => {
121
+ document.removeEventListener("pointerdown", onPointerDown, true);
122
+ document.removeEventListener("keydown", onKeyDown, true);
123
+ document.removeEventListener("focusin", onFocusIn);
124
+ };
125
+ }, [open]);
126
+ return { open, setOpen, rootRef };
127
+ }
128
+ /* ------------------------------------------------------------------ */
129
+ /* Calendar grid */
130
+ /* ------------------------------------------------------------------ */
131
+ function buildMonthCells(viewMonth) {
132
+ const year = viewMonth.getFullYear();
133
+ const month = viewMonth.getMonth();
134
+ const first = new Date(year, month, 1);
135
+ // Monday-first: JS getDay() is 0=Sun … 6=Sat
136
+ const startOffset = (first.getDay() + 6) % 7;
137
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
138
+ const cells = [];
139
+ for (let i = 0; i < startOffset; i += 1)
140
+ cells.push(null);
141
+ for (let day = 1; day <= daysInMonth; day += 1) {
142
+ cells.push(new Date(year, month, day));
143
+ }
144
+ while (cells.length % 7 !== 0)
145
+ cells.push(null);
146
+ return cells;
147
+ }
148
+ function Calendar({ viewMonth, onViewMonthChange, onSelectDay, isSelected, isInRange, isRangeStart, isRangeEnd, minDate, maxDate, footer, }) {
149
+ const cells = useMemo(() => buildMonthCells(viewMonth), [viewMonth]);
150
+ const title = MONTH_TITLE_FORMAT.format(viewMonth);
151
+ const today = startOfDay(new Date());
152
+ const goMonth = (delta) => {
153
+ onViewMonthChange(new Date(viewMonth.getFullYear(), viewMonth.getMonth() + delta, 1));
154
+ };
155
+ return (_jsxs("div", { className: "w-[17.5rem] p-3", children: [_jsxs("div", { className: "mb-2 flex items-center justify-between gap-2", children: [_jsx("button", { type: "button", "aria-label": "Mois pr\u00E9c\u00E9dent", onClick: () => goMonth(-1), className: "flex size-8 items-center justify-center rounded-small text-muted-foreground transition-colors hover:bg-surface-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary [&_svg]:size-[var(--icon-small)]", children: _jsx(Icon, { name: "ChevronLeft", "aria-hidden": "true" }) }), _jsx("p", { className: "text-sm font-medium capitalize text-foreground", children: title }), _jsx("button", { type: "button", "aria-label": "Mois suivant", onClick: () => goMonth(1), className: "flex size-8 items-center justify-center rounded-small text-muted-foreground transition-colors hover:bg-surface-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary [&_svg]:size-[var(--icon-small)]", children: _jsx(Icon, { name: "ChevronRight", "aria-hidden": "true" }) })] }), _jsx("div", { className: "mb-1 grid grid-cols-7 gap-0.5", children: WEEKDAY_LABELS.map((label) => (_jsx("div", { className: "flex h-8 items-center justify-center text-xs font-medium text-muted-foreground", children: label }, label))) }), _jsx("div", { className: "grid grid-cols-7 gap-0.5", role: "grid", "aria-label": title, children: cells.map((day, index) => {
156
+ if (!day) {
157
+ return _jsx("div", { className: "h-8" }, `empty-${index}`);
158
+ }
159
+ const disabled = (minDate ? isBeforeDay(day, minDate) : false) ||
160
+ (maxDate ? isAfterDay(day, maxDate) : false);
161
+ const selected = isSelected(day);
162
+ const inRange = isInRange?.(day) ?? false;
163
+ const rangeStart = isRangeStart?.(day) ?? false;
164
+ const rangeEnd = isRangeEnd?.(day) ?? false;
165
+ const isToday = isSameDay(day, today);
166
+ let dayClass = "relative flex h-8 w-full items-center justify-center rounded-small text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary";
167
+ if (disabled) {
168
+ dayClass += " cursor-not-allowed text-muted-foreground/40";
169
+ }
170
+ else if (selected || rangeStart || rangeEnd) {
171
+ dayClass +=
172
+ " bg-primary text-primary-foreground hover:bg-primary-hover";
173
+ }
174
+ else if (inRange) {
175
+ dayClass += " bg-primary-light text-primary hover:bg-primary-muted";
176
+ }
177
+ else {
178
+ dayClass +=
179
+ " text-foreground hover:bg-surface-muted";
180
+ }
181
+ if (isToday && !selected && !rangeStart && !rangeEnd) {
182
+ dayClass += " font-semibold ring-1 ring-inset ring-primary/40";
183
+ }
184
+ return (_jsx("button", { type: "button", role: "gridcell", disabled: disabled, "aria-selected": selected || rangeStart || rangeEnd, "aria-current": isToday ? "date" : undefined, onClick: () => onSelectDay(day), className: dayClass, children: day.getDate() }, day.toISOString()));
185
+ }) }), footer ? _jsx("div", { className: "mt-3 border-t border-border pt-3", children: footer }) : null] }));
186
+ }
187
+ /* ------------------------------------------------------------------ */
188
+ /* Trigger + shell */
189
+ /* ------------------------------------------------------------------ */
190
+ function DateFieldShell({ label, required, disabled, error, helper, className = "", open, onOpenChange, display, placeholder, clearable, hasValue, onClear, children, rootRef, }) {
191
+ const generatedId = useId();
192
+ const helperId = useId();
193
+ const errorId = useId();
194
+ const describedBy = [error ? errorId : helper ? helperId : undefined]
195
+ .filter(Boolean)
196
+ .join(" ") || undefined;
197
+ return (_jsxs("div", { ref: rootRef, className: `relative w-full ${className}`.trim(), children: [label ? (_jsxs("label", { className: LABEL_CLASS, children: [_jsx("span", { className: "truncate", children: label }), required ? _jsx(RequiredMark, {}) : null] })) : null, _jsxs("div", { className: "relative", children: [_jsx("button", { type: "button", id: generatedId, disabled: disabled, "aria-haspopup": "dialog", "aria-expanded": open, "aria-invalid": Boolean(error) || undefined, "aria-required": required || undefined, "aria-describedby": describedBy, onClick: () => onOpenChange(!open), className: `ds-input flex cursor-pointer items-center justify-between gap-2 text-left disabled:cursor-not-allowed [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0 ${clearable && hasValue && !disabled ? "pr-16" : "pr-9"} ${error
198
+ ? "border-danger hover:border-danger focus:border-danger"
199
+ : ""}`, children: _jsx("span", { className: `min-w-0 flex-1 truncate ${display ? "text-foreground" : "text-muted-foreground"}`, children: display ?? placeholder }) }), _jsxs("span", { className: "pointer-events-none absolute right-3 top-1/2 flex -translate-y-1/2 items-center gap-inline text-muted-foreground [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0", children: [clearable && hasValue && !disabled ? (_jsx("button", { type: "button", "aria-label": "Effacer la valeur", disabled: disabled, onClick: onClear, className: "pointer-events-auto flex items-center rounded-small transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary", children: _jsx(Icon, { name: "X", "aria-hidden": "true" }) })) : null, _jsx(Icon, { name: "Calendar", "aria-hidden": "true" })] }), open ? (_jsx("div", { role: "dialog", "aria-modal": "false", className: "absolute top-full z-50 mt-1 overflow-hidden rounded-medium border border-border bg-surface shadow-lg", children: children })) : null] }), (error || helper) && (_jsx("div", { className: "mt-inline", children: error ? (_jsx(FieldFeedback, { id: errorId, error: error })) : helper ? (_jsx("p", { id: helperId, className: "text-small text-muted-foreground", children: helper })) : null }))] }));
200
+ }
201
+ function initialViewMonth(value, fallback) {
202
+ const source = value ?? fallback ?? new Date();
203
+ return new Date(source.getFullYear(), source.getMonth(), 1);
204
+ }
205
+ /* ------------------------------------------------------------------ */
206
+ /* DatePicker — single date */
207
+ /* ------------------------------------------------------------------ */
208
+ /**
209
+ * Single-date picker.
210
+ * Trigger matches Select/Input (`ds-input`); calendar opens below.
211
+ */
212
+ export function DatePicker({ label, value, onChange, placeholder = "Sélectionner une date…", minDate, maxDate, disabled = false, required = false, error, helper, clearable = true, className = "", }) {
213
+ const { open, setOpen, rootRef } = useDismissibleOpen();
214
+ const [viewMonth, setViewMonth] = useState(() => initialViewMonth(value));
215
+ useEffect(() => {
216
+ if (open)
217
+ setViewMonth(initialViewMonth(value));
218
+ }, [open, value]);
219
+ const handleSelect = (day) => {
220
+ const next = clampToBounds(startOfDay(day), minDate, maxDate);
221
+ onChange(next);
222
+ setOpen(false);
223
+ };
224
+ return (_jsx(DateFieldShell, { rootRef: rootRef, label: label, required: required, disabled: disabled, error: error, helper: helper, className: className, open: open, onOpenChange: setOpen, display: value ? DATE_FORMAT.format(value) : null, placeholder: placeholder, clearable: clearable, hasValue: Boolean(value), onClear: () => onChange(null), children: _jsx(Calendar, { viewMonth: viewMonth, onViewMonthChange: setViewMonth, onSelectDay: handleSelect, isSelected: (day) => isSameDay(day, value), minDate: minDate, maxDate: maxDate, footer: _jsxs("div", { className: "flex justify-between gap-2", children: [_jsx(ClickableButton, { type: "button", variant: "ghost", size: "sm", onClick: () => {
225
+ onChange(null);
226
+ setOpen(false);
227
+ }, children: "Effacer" }), _jsx(ClickableButton, { type: "button", variant: "secondary", size: "sm", onClick: () => handleSelect(clampToBounds(startOfDay(new Date()), minDate, maxDate)), children: "Aujourd'hui" })] }) }) }));
228
+ }
229
+ /* ------------------------------------------------------------------ */
230
+ /* DateTimePicker — date + time */
231
+ /* ------------------------------------------------------------------ */
232
+ /**
233
+ * Date and time picker.
234
+ * Day selection updates the date; time is confirmed via the time field.
235
+ */
236
+ export function DateTimePicker({ label, value, onChange, placeholder = "Sélectionner une date et une heure…", minDate, maxDate, disabled = false, required = false, error, helper, clearable = true, className = "", }) {
237
+ const { open, setOpen, rootRef } = useDismissibleOpen();
238
+ const [viewMonth, setViewMonth] = useState(() => initialViewMonth(value));
239
+ const [draftDate, setDraftDate] = useState(value);
240
+ const [timeText, setTimeText] = useState(() => value ? formatTimeValue(value) : "09:00");
241
+ useEffect(() => {
242
+ if (!open)
243
+ return;
244
+ setViewMonth(initialViewMonth(value));
245
+ setDraftDate(value);
246
+ setTimeText(value ? formatTimeValue(value) : "09:00");
247
+ }, [open, value]);
248
+ const apply = (day, time) => {
249
+ const parsed = parseTimeValue(time) ?? { hours: 0, minutes: 0 };
250
+ const next = withTime(clampToBounds(day, minDate, maxDate), parsed.hours, parsed.minutes);
251
+ onChange(next);
252
+ };
253
+ const handleSelectDay = (day) => {
254
+ setDraftDate(day);
255
+ apply(day, timeText);
256
+ };
257
+ const handleTimeChange = (nextTime) => {
258
+ setTimeText(nextTime);
259
+ if (draftDate && parseTimeValue(nextTime)) {
260
+ apply(draftDate, nextTime);
261
+ }
262
+ };
263
+ return (_jsx(DateFieldShell, { rootRef: rootRef, label: label, required: required, disabled: disabled, error: error, helper: helper, className: className, open: open, onOpenChange: setOpen, display: value ? DATETIME_FORMAT.format(value) : null, placeholder: placeholder, clearable: clearable, hasValue: Boolean(value), onClear: () => onChange(null), children: _jsx(Calendar, { viewMonth: viewMonth, onViewMonthChange: setViewMonth, onSelectDay: handleSelectDay, isSelected: (day) => isSameDay(day, draftDate), minDate: minDate, maxDate: maxDate, footer: _jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("label", { className: "flex items-center justify-between gap-2 text-label text-muted-foreground", children: [_jsx("span", { children: "Heure" }), _jsx("input", { type: "time", value: timeText, onChange: (event) => handleTimeChange(event.target.value), className: "ds-input w-auto py-1.5", "aria-label": "Heure" })] }), _jsxs("div", { className: "flex justify-between gap-2", children: [_jsx(ClickableButton, { type: "button", variant: "ghost", size: "sm", onClick: () => {
264
+ onChange(null);
265
+ setOpen(false);
266
+ }, children: "Effacer" }), _jsx(ClickableButton, { type: "button", variant: "primary", size: "sm", disabled: !draftDate, onClick: () => {
267
+ if (!draftDate)
268
+ return;
269
+ apply(draftDate, timeText);
270
+ setOpen(false);
271
+ }, children: "Appliquer" })] })] }) }) }));
272
+ }
273
+ /* ------------------------------------------------------------------ */
274
+ /* DateRangePicker — from / to */
275
+ /* ------------------------------------------------------------------ */
276
+ /**
277
+ * Date range picker (from → to).
278
+ * First click sets the start; second click sets the end.
279
+ */
280
+ export function DateRangePicker({ label, value, onChange, placeholder = "Sélectionner une période…", minDate, maxDate, disabled = false, required = false, error, helper, clearable = true, className = "", }) {
281
+ const { open, setOpen, rootRef } = useDismissibleOpen();
282
+ const [viewMonth, setViewMonth] = useState(() => initialViewMonth(value.from, value.to));
283
+ const [draft, setDraft] = useState(value);
284
+ useEffect(() => {
285
+ if (!open)
286
+ return;
287
+ setViewMonth(initialViewMonth(value.from, value.to));
288
+ setDraft(value);
289
+ }, [open, value]);
290
+ const handleSelectDay = (day) => {
291
+ const nextDay = clampToBounds(startOfDay(day), minDate, maxDate);
292
+ // First click (or reset after a complete range): set "from".
293
+ if (!draft.from || (draft.from && draft.to)) {
294
+ setDraft({ from: nextDay, to: null });
295
+ return;
296
+ }
297
+ // Second click: if before start, swap; otherwise complete the draft range.
298
+ // Stay open until Appliquer confirms.
299
+ if (isBeforeDay(nextDay, draft.from)) {
300
+ setDraft({ from: nextDay, to: draft.from });
301
+ return;
302
+ }
303
+ setDraft({ from: draft.from, to: nextDay });
304
+ };
305
+ const inRange = (day) => {
306
+ if (!draft.from || !draft.to)
307
+ return false;
308
+ return !isBeforeDay(day, draft.from) && !isAfterDay(day, draft.to) &&
309
+ !isSameDay(day, draft.from) &&
310
+ !isSameDay(day, draft.to);
311
+ };
312
+ return (_jsx(DateFieldShell, { rootRef: rootRef, label: label, required: required, disabled: disabled, error: error, helper: helper, className: className, open: open, onOpenChange: setOpen, display: formatRangeLabel(value), placeholder: placeholder, clearable: clearable, hasValue: Boolean(value.from || value.to), onClear: () => onChange({ from: null, to: null }), children: _jsx(Calendar, { viewMonth: viewMonth, onViewMonthChange: setViewMonth, onSelectDay: handleSelectDay, isSelected: () => false, isRangeStart: (day) => isSameDay(day, draft.from), isRangeEnd: (day) => isSameDay(day, draft.to), isInRange: inRange, minDate: minDate, maxDate: maxDate, footer: _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("p", { className: "text-small text-muted-foreground", children: !draft.from
313
+ ? "Choisissez la date de début."
314
+ : !draft.to
315
+ ? "Choisissez la date de fin."
316
+ : `${DATE_FORMAT.format(draft.from)} – ${DATE_FORMAT.format(draft.to)}` }), _jsxs("div", { className: "flex justify-between gap-2", children: [_jsx(ClickableButton, { type: "button", variant: "ghost", size: "sm", onClick: () => {
317
+ const empty = { from: null, to: null };
318
+ setDraft(empty);
319
+ onChange(empty);
320
+ setOpen(false);
321
+ }, children: "Effacer" }), _jsx(ClickableButton, { type: "button", variant: "primary", size: "sm", disabled: !draft.from || !draft.to, onClick: () => {
322
+ if (!draft.from || !draft.to)
323
+ return;
324
+ onChange(draft);
325
+ setOpen(false);
326
+ }, children: "Appliquer" })] })] }) }) }));
327
+ }
package/dist/index.d.ts CHANGED
@@ -21,4 +21,8 @@ export { default as Stepper } from "./stepper";
21
21
  export type { StepperStepState } from "./stepper";
22
22
  export { default as Accordion } from "./accordion";
23
23
  export type { AccordionItem } from "./accordion";
24
+ export { DatePicker, DateTimePicker, DateRangePicker } from "./date-picker";
25
+ export type { DatePickerProps, DateTimePickerProps, DateRangePickerProps, DateRangeValue, } from "./date-picker";
26
+ export { default as Agenda, AGENDA_STATUS_OPTIONS } from "./agenda";
27
+ export type { AgendaProps, AgendaEvent, AgendaView, AgendaEventStatus, AgendaStatusOption, AgendaStatusStyle, AgendaListRow, DateRangeValue as AgendaDateRangeValue, } from "./agenda";
24
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../components/ui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AACtD,YAAY,EACV,oBAAoB,EACpB,aAAa,EACb,UAAU,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAAC,OAAO,IAAI,KAAK,EAAC,MAAM,SAAS,CAAC;AACzC,YAAY,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,MA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AAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5E,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACpE,YAAY,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,cAAc,IAAI,oBAAoB,GACvC,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -10,3 +10,5 @@ export { default as Loader } from "./loader";
10
10
  export { default as MetricBar } from "./metric-bar";
11
11
  export { default as Stepper } from "./stepper";
12
12
  export { default as Accordion } from "./accordion";
13
+ export { DatePicker, DateTimePicker, DateRangePicker } from "./date-picker";
14
+ export { default as Agenda, AGENDA_STATUS_OPTIONS } from "./agenda";
package/dist/tab.js CHANGED
@@ -16,9 +16,9 @@ export default function Tabs({ tabs, defaultValue, onChange, children, panelClas
16
16
  setActiveTab(value);
17
17
  onChange?.(value);
18
18
  };
19
- return (_jsxs("div", { className: "flex h-full min-h-0 w-full flex-col", children: [_jsx("div", { role: "tablist", className: "inline-flex max-w-full items-center gap-micro overflow-x-auto rounded-medium bg-surface-muted p-micro", children: tabs.map((tab) => {
19
+ return (_jsxs("div", { className: "flex h-full min-h-0 w-full flex-col", children: [_jsx("div", { role: "tablist", className: "inline-flex max-w-full items-center gap-micro overflow-x-auto rounded-large bg-surface-muted p-micro", children: tabs.map((tab) => {
20
20
  const isActive = activeTab === tab.value;
21
- return (_jsx(ClickableButton, { type: "button", variant: "bare", role: "tab", "aria-selected": isActive, "aria-current": isActive ? "page" : undefined, onClick: () => handleSelect(tab.value), className: `whitespace-nowrap rounded-small px-component py-inline text-body-medium focus-visible:ring-primary ${isActive
21
+ return (_jsx(ClickableButton, { type: "button", variant: "bare", role: "tab", "aria-selected": isActive, "aria-current": isActive ? "page" : undefined, onClick: () => handleSelect(tab.value), className: `whitespace-nowrap rounded-large px-component py-inline text-body-medium focus-visible:ring-primary ${isActive
22
22
  ? "bg-surface text-primary shadow-sm"
23
23
  : "bg-transparent text-muted-foreground hover:text-foreground"}`, children: tab.label }, tab.value));
24
24
  }) }), children && _jsx("div", { className: panelClassName, children: children(activeTab) })] }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modoock/components",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Modoock source components for internal projects.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",