@donotdev/components 0.1.1 → 0.1.42
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/LICENSE.md +1 -1
- package/README.md +2 -2
- package/dist/CodeContent-JLL6BLG2.js +2 -0
- package/dist/advanced/Code/CodeContent.d.ts.map +1 -1
- package/dist/advanced/Code/CodeContent.js +2 -3
- package/dist/advanced/ImageGallery/ImageGallery.d.ts +7 -1
- package/dist/advanced/ImageGallery/ImageGallery.d.ts.map +1 -1
- package/dist/advanced/ImageGallery/ImageGallery.js +52 -3
- package/dist/advanced/JsonViewer/JsonViewer.js +11 -11
- package/dist/advanced/Reveal/Reveal.d.ts.map +1 -1
- package/dist/advanced/Reveal/Reveal.js +4 -4
- package/dist/advanced/Roadmap/RoadmapContent.d.ts.map +1 -1
- package/dist/advanced/Roadmap/RoadmapContent.js +2 -2
- package/dist/atomic/Alert/index.d.ts.map +1 -1
- package/dist/atomic/Alert/index.js +1 -1
- package/dist/atomic/Button/index.d.ts +2 -2
- package/dist/atomic/Button/index.js +1 -1
- package/dist/atomic/CallToAction/index.d.ts +2 -0
- package/dist/atomic/CallToAction/index.d.ts.map +1 -1
- package/dist/atomic/CallToAction/index.js +2 -2
- package/dist/atomic/Card/index.d.ts +101 -2
- package/dist/atomic/Card/index.d.ts.map +1 -1
- package/dist/atomic/Card/index.js +87 -9
- package/dist/atomic/Checkbox/index.d.ts +2 -2
- package/dist/atomic/Checkbox/index.d.ts.map +1 -1
- package/dist/atomic/Checkbox/index.js +6 -4
- package/dist/atomic/ColorPicker/index.d.ts.map +1 -1
- package/dist/atomic/ColorPicker/index.js +7 -7
- package/dist/atomic/Combobox/index.d.ts +2 -0
- package/dist/atomic/Combobox/index.d.ts.map +1 -1
- package/dist/atomic/Combobox/index.js +36 -21
- package/dist/atomic/CopyToClipboard/index.d.ts.map +1 -1
- package/dist/atomic/CopyToClipboard/index.js +3 -3
- package/dist/atomic/DatePicker/index.d.ts +54 -0
- package/dist/atomic/DatePicker/index.d.ts.map +1 -0
- package/dist/atomic/DatePicker/index.js +377 -0
- package/dist/atomic/DateTimePicker/index.d.ts +54 -0
- package/dist/atomic/DateTimePicker/index.d.ts.map +1 -0
- package/dist/atomic/DateTimePicker/index.js +460 -0
- package/dist/atomic/FileButton/index.d.ts.map +1 -1
- package/dist/atomic/FileButton/index.js +3 -3
- package/dist/atomic/HeroSection/index.d.ts.map +1 -1
- package/dist/atomic/HeroSection/index.js +5 -1
- package/dist/atomic/Icons/Icon.d.ts.map +1 -1
- package/dist/atomic/Icons/Icon.js +3 -11
- package/dist/atomic/Icons/Partner/SupabaseIcon.d.ts.map +1 -1
- package/dist/atomic/Label/FloatingLabel.d.ts.map +1 -1
- package/dist/atomic/Label/FloatingLabel.js +2 -5
- package/dist/atomic/Label/index.d.ts.map +1 -1
- package/dist/atomic/Label/index.js +1 -5
- package/dist/atomic/Pagination/index.js +3 -3
- package/dist/atomic/PinInput/index.d.ts +92 -0
- package/dist/atomic/PinInput/index.d.ts.map +1 -0
- package/dist/atomic/PinInput/index.js +156 -0
- package/dist/atomic/RangeInput/index.d.ts.map +1 -1
- package/dist/atomic/RangeInput/index.js +1 -2
- package/dist/atomic/Rating/index.d.ts.map +1 -1
- package/dist/atomic/Rating/index.js +5 -5
- package/dist/atomic/Table/index.d.ts +35 -1
- package/dist/atomic/Table/index.d.ts.map +1 -1
- package/dist/atomic/Table/index.js +27 -0
- package/dist/atomic/Tooltip/index.js +5 -5
- package/dist/atomic/TreeView/index.js +1 -1
- package/dist/atomic/index.d.ts +6 -0
- package/dist/atomic/index.d.ts.map +1 -1
- package/dist/atomic/index.js +3 -0
- package/dist/chunk-6UB4NXNR.js +3 -0
- package/dist/index.js +5 -5
- package/dist/styles/index.css +737 -98
- package/dist/symbol-index.json +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/date.d.ts +46 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +130 -0
- package/dist/utils/imageRetry.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/guidelines/API_REFERENCE.md +0 -0
- package/guidelines/COMPONENTS.md +0 -0
- package/package.json +1 -1
- package/dist/CodeContent-JP5FNGFV.js +0 -2
- package/dist/chunk-ZCLMEZ46.js +0 -3
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// packages/components/src/atomic/DatePicker/index.tsx
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview DatePicker component
|
|
5
|
+
* @description Accessible date picker with segmented input (DD/MM/YYYY),
|
|
6
|
+
* calendar popover, and automatic mobile native fallback.
|
|
7
|
+
*
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @since 0.0.1
|
|
10
|
+
* @author AMBROISE PARK Consulting
|
|
11
|
+
*/
|
|
12
|
+
import { Fragment, useEffect, useId, useRef, useState } from 'react';
|
|
13
|
+
import { CalendarDays } from 'lucide-react';
|
|
14
|
+
import Calendar from '../Calendar';
|
|
15
|
+
import Icon from '../Icons/Icon';
|
|
16
|
+
import { FloatingLabel } from '../Label';
|
|
17
|
+
import { PopoverPrimitive, PopoverTrigger, PopoverContent, } from '../Popover/PopoverPrimitive';
|
|
18
|
+
import { cn } from '../../utils/helpers';
|
|
19
|
+
import { DATE_SEGMENT_BASE, clampDay, getDaysInMonth, getLocaleInfo, parseAnyDate, parseISODate, resolveLocale, toDate, toISODate, } from '../../utils/date';
|
|
20
|
+
import './DatePicker.css';
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Component
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
/**
|
|
25
|
+
* Accessible date picker with segmented keyboard input, calendar popover,
|
|
26
|
+
* and automatic mobile native fallback.
|
|
27
|
+
*
|
|
28
|
+
* - Desktop: segmented DD/MM/YYYY input with up/down increment, auto-advance
|
|
29
|
+
* - Mobile: native `<input type="date">` (OS picker is better on touch)
|
|
30
|
+
* - Keyboard: Arrow keys between segments, Up/Down to change values, paste-aware
|
|
31
|
+
* - ARIA: spinbutton pattern per segment, full screen reader support
|
|
32
|
+
*
|
|
33
|
+
* @component
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* <DatePicker label="Date de naissance" value={date} onChange={setDate} />
|
|
37
|
+
* <DatePicker label="Début" min="2024-01-01" required />
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function DatePicker({ value, onChange, label, min, max, required = false, disabled = false, locale, className, id: idProp, name, ref, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'data-variant': dataVariant, }) {
|
|
41
|
+
const generatedId = useId();
|
|
42
|
+
const id = idProp ?? generatedId;
|
|
43
|
+
const resolvedLocale = resolveLocale(locale);
|
|
44
|
+
const { order, separator } = getLocaleInfo(resolvedLocale);
|
|
45
|
+
// Normalize min/max to Date
|
|
46
|
+
const minDate = min ? toDate(min) : undefined;
|
|
47
|
+
const maxDate = max ? toDate(max) : undefined;
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// State
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
const [segments, setSegments] = useState(() => {
|
|
52
|
+
if (value)
|
|
53
|
+
return parseISODate(value);
|
|
54
|
+
return { day: null, month: null, year: null };
|
|
55
|
+
});
|
|
56
|
+
const [popoverOpen, setPopoverOpen] = useState(false);
|
|
57
|
+
const [liveText, setLiveText] = useState('');
|
|
58
|
+
// Refs
|
|
59
|
+
const segmentRefs = useRef([null, null, null]);
|
|
60
|
+
const typeBuffer = useRef('');
|
|
61
|
+
const containerRef = useRef(null);
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Sync from controlled value
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (value === undefined)
|
|
67
|
+
return;
|
|
68
|
+
if (value === null) {
|
|
69
|
+
setSegments({ day: null, month: null, year: null });
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
setSegments(parseISODate(value));
|
|
73
|
+
}
|
|
74
|
+
}, [value]);
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Segment configs (dynamic max for day based on month/year)
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
const currentYear = new Date().getFullYear();
|
|
79
|
+
const segmentConfigs = order.map((type) => {
|
|
80
|
+
const base = DATE_SEGMENT_BASE[type];
|
|
81
|
+
let segMax;
|
|
82
|
+
if (type === 'day') {
|
|
83
|
+
segMax = getDaysInMonth(segments.month, segments.year);
|
|
84
|
+
}
|
|
85
|
+
else if (type === 'month') {
|
|
86
|
+
segMax = 12;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
segMax = maxDate ? maxDate.getFullYear() : currentYear + 10;
|
|
90
|
+
}
|
|
91
|
+
return { ...base, max: segMax };
|
|
92
|
+
});
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// Value emission
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
function announceLive(date) {
|
|
97
|
+
setLiveText(date.toLocaleDateString(resolvedLocale, {
|
|
98
|
+
weekday: 'long',
|
|
99
|
+
year: 'numeric',
|
|
100
|
+
month: 'long',
|
|
101
|
+
day: 'numeric',
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
function emitISO(segs) {
|
|
105
|
+
if (segs.day != null && segs.month != null && segs.year != null) {
|
|
106
|
+
const clamped = clampDay(segs.day, segs.month, segs.year);
|
|
107
|
+
let date = new Date(segs.year, segs.month - 1, clamped);
|
|
108
|
+
if (minDate && date < minDate)
|
|
109
|
+
date = minDate;
|
|
110
|
+
if (maxDate && date > maxDate)
|
|
111
|
+
date = maxDate;
|
|
112
|
+
onChange?.(toISODate(date));
|
|
113
|
+
announceLive(date);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function commitSegments(newSegs) {
|
|
117
|
+
setSegments(newSegs);
|
|
118
|
+
if (newSegs.day != null && newSegs.month != null && newSegs.year != null) {
|
|
119
|
+
emitISO(newSegs);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function commitSegment(type, newValue, segIndex, advance = false) {
|
|
123
|
+
const newSegs = { ...segments, [type]: newValue };
|
|
124
|
+
// Auto-clamp day when month/year changes
|
|
125
|
+
if ((type === 'month' || type === 'year') && newSegs.day != null) {
|
|
126
|
+
newSegs.day = clampDay(newSegs.day, newSegs.month, newSegs.year);
|
|
127
|
+
}
|
|
128
|
+
setSegments(newSegs);
|
|
129
|
+
// Emit if all filled
|
|
130
|
+
if (newSegs.day != null && newSegs.month != null && newSegs.year != null) {
|
|
131
|
+
emitISO(newSegs);
|
|
132
|
+
}
|
|
133
|
+
else if (newValue === null &&
|
|
134
|
+
segments.day != null &&
|
|
135
|
+
segments.month != null &&
|
|
136
|
+
segments.year != null) {
|
|
137
|
+
onChange?.(null);
|
|
138
|
+
setLiveText('');
|
|
139
|
+
}
|
|
140
|
+
if (advance && segIndex < order.length - 1) {
|
|
141
|
+
typeBuffer.current = '';
|
|
142
|
+
segmentRefs.current[segIndex + 1]?.focus();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
// Focus management
|
|
147
|
+
// ---------------------------------------------------------------------------
|
|
148
|
+
function handleFocus() {
|
|
149
|
+
typeBuffer.current = '';
|
|
150
|
+
}
|
|
151
|
+
function handleBlur(e) {
|
|
152
|
+
if (typeBuffer.current) {
|
|
153
|
+
const segType = e.currentTarget.dataset.type;
|
|
154
|
+
const config = segmentConfigs.find((c) => c.type === segType);
|
|
155
|
+
if (config) {
|
|
156
|
+
let val = Number(typeBuffer.current);
|
|
157
|
+
if (segType === 'year' && val >= 0 && val <= 99)
|
|
158
|
+
val += 2000;
|
|
159
|
+
val = Math.max(config.min, Math.min(val, config.max));
|
|
160
|
+
const idx = order.indexOf(segType);
|
|
161
|
+
commitSegment(segType, val, idx);
|
|
162
|
+
}
|
|
163
|
+
typeBuffer.current = '';
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function handleContainerClick(e) {
|
|
167
|
+
if (e.target.closest('[role="spinbutton"], button'))
|
|
168
|
+
return;
|
|
169
|
+
const firstEmpty = order.findIndex((type) => segments[type] == null);
|
|
170
|
+
const targetIndex = firstEmpty >= 0 ? firstEmpty : 0;
|
|
171
|
+
segmentRefs.current[targetIndex]?.focus();
|
|
172
|
+
}
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
// Keyboard handling
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
function handleKeyDown(e, config, index) {
|
|
177
|
+
const { type, min: segMin, max: segMax, digits } = config;
|
|
178
|
+
const currentValue = segments[type];
|
|
179
|
+
switch (e.key) {
|
|
180
|
+
case 'ArrowUp': {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
typeBuffer.current = '';
|
|
183
|
+
const next = currentValue == null
|
|
184
|
+
? segMin
|
|
185
|
+
: currentValue >= segMax
|
|
186
|
+
? segMin
|
|
187
|
+
: currentValue + 1;
|
|
188
|
+
commitSegment(type, next, index);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case 'ArrowDown': {
|
|
192
|
+
e.preventDefault();
|
|
193
|
+
typeBuffer.current = '';
|
|
194
|
+
const next = currentValue == null
|
|
195
|
+
? segMax
|
|
196
|
+
: currentValue <= segMin
|
|
197
|
+
? segMax
|
|
198
|
+
: currentValue - 1;
|
|
199
|
+
commitSegment(type, next, index);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case 'ArrowRight': {
|
|
203
|
+
e.preventDefault();
|
|
204
|
+
if (index < order.length - 1) {
|
|
205
|
+
typeBuffer.current = '';
|
|
206
|
+
segmentRefs.current[index + 1]?.focus();
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
case 'ArrowLeft': {
|
|
211
|
+
e.preventDefault();
|
|
212
|
+
if (index > 0) {
|
|
213
|
+
typeBuffer.current = '';
|
|
214
|
+
segmentRefs.current[index - 1]?.focus();
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case 'Home': {
|
|
219
|
+
e.preventDefault();
|
|
220
|
+
typeBuffer.current = '';
|
|
221
|
+
commitSegment(type, segMin, index);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case 'End': {
|
|
225
|
+
e.preventDefault();
|
|
226
|
+
typeBuffer.current = '';
|
|
227
|
+
commitSegment(type, segMax, index);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case 'Backspace': {
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
typeBuffer.current = '';
|
|
233
|
+
commitSegment(type, null, index);
|
|
234
|
+
if (index > 0) {
|
|
235
|
+
segmentRefs.current[index - 1]?.focus();
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
case 'Delete': {
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
typeBuffer.current = '';
|
|
242
|
+
commitSegment(type, null, index);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case 'Tab': {
|
|
246
|
+
if (typeBuffer.current) {
|
|
247
|
+
let val = Number(typeBuffer.current);
|
|
248
|
+
if (type === 'year' && val >= 0 && val <= 99)
|
|
249
|
+
val += 2000;
|
|
250
|
+
val = Math.max(segMin, Math.min(val, segMax));
|
|
251
|
+
commitSegment(type, val, index);
|
|
252
|
+
typeBuffer.current = '';
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
default: {
|
|
257
|
+
if (e.key >= '0' && e.key <= '9') {
|
|
258
|
+
e.preventDefault();
|
|
259
|
+
const buffer = typeBuffer.current + e.key;
|
|
260
|
+
const num = Number(buffer);
|
|
261
|
+
if (buffer.length >= digits) {
|
|
262
|
+
const clamped = Math.max(segMin, Math.min(num, segMax));
|
|
263
|
+
typeBuffer.current = '';
|
|
264
|
+
commitSegment(type, clamped, index, true);
|
|
265
|
+
}
|
|
266
|
+
else if (num * 10 > segMax) {
|
|
267
|
+
const clamped = Math.max(segMin, Math.min(num, segMax));
|
|
268
|
+
typeBuffer.current = '';
|
|
269
|
+
commitSegment(type, clamped, index, true);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
typeBuffer.current = buffer;
|
|
273
|
+
e.currentTarget.textContent = buffer;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// ---------------------------------------------------------------------------
|
|
281
|
+
// Paste handling
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
function handlePaste(e) {
|
|
284
|
+
e.preventDefault();
|
|
285
|
+
const text = e.clipboardData.getData('text/plain');
|
|
286
|
+
const date = parseAnyDate(text);
|
|
287
|
+
if (date) {
|
|
288
|
+
const newSegs = {
|
|
289
|
+
day: date.getDate(),
|
|
290
|
+
month: date.getMonth() + 1,
|
|
291
|
+
year: date.getFullYear(),
|
|
292
|
+
};
|
|
293
|
+
commitSegments(newSegs);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// ---------------------------------------------------------------------------
|
|
297
|
+
// Calendar selection
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
function handleCalendarSelect(date) {
|
|
300
|
+
if (date) {
|
|
301
|
+
const newSegs = {
|
|
302
|
+
day: date.getDate(),
|
|
303
|
+
month: date.getMonth() + 1,
|
|
304
|
+
year: date.getFullYear(),
|
|
305
|
+
};
|
|
306
|
+
setSegments(newSegs);
|
|
307
|
+
onChange?.(toISODate(date));
|
|
308
|
+
announceLive(date);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
setSegments({ day: null, month: null, year: null });
|
|
312
|
+
onChange?.(null);
|
|
313
|
+
setLiveText('');
|
|
314
|
+
}
|
|
315
|
+
setPopoverOpen(false);
|
|
316
|
+
}
|
|
317
|
+
// ---------------------------------------------------------------------------
|
|
318
|
+
// Native input handler (mobile)
|
|
319
|
+
// ---------------------------------------------------------------------------
|
|
320
|
+
function handleNativeChange(e) {
|
|
321
|
+
const val = e.target.value;
|
|
322
|
+
if (val) {
|
|
323
|
+
const [y, m, d] = val.split('-').map(Number);
|
|
324
|
+
const newSegs = { day: d, month: m, year: y };
|
|
325
|
+
setSegments(newSegs);
|
|
326
|
+
onChange?.(val);
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
setSegments({ day: null, month: null, year: null });
|
|
330
|
+
onChange?.(null);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
// ---------------------------------------------------------------------------
|
|
334
|
+
// Computed values
|
|
335
|
+
// ---------------------------------------------------------------------------
|
|
336
|
+
const dateValue = segments.day != null && segments.month != null && segments.year != null
|
|
337
|
+
? new Date(segments.year, segments.month - 1, segments.day)
|
|
338
|
+
: undefined;
|
|
339
|
+
const isoValue = dateValue ? toISODate(dateValue) : '';
|
|
340
|
+
const disabledDays = [];
|
|
341
|
+
if (minDate)
|
|
342
|
+
disabledDays.push({ before: minDate });
|
|
343
|
+
if (maxDate)
|
|
344
|
+
disabledDays.push({ after: maxDate });
|
|
345
|
+
// ---------------------------------------------------------------------------
|
|
346
|
+
// Render
|
|
347
|
+
// ---------------------------------------------------------------------------
|
|
348
|
+
const segmentedInput = (_jsx("div", { className: "dndev-datepicker-custom", children: _jsxs(PopoverPrimitive, { open: popoverOpen, onOpenChange: setPopoverOpen, modal: true, children: [_jsxs("div", { className: "dndev-datepicker-field", role: "group", "aria-label": label || 'Date', "data-bare": label ? true : undefined, "data-disabled": disabled || undefined, "data-variant": dataVariant, "aria-invalid": ariaInvalid || undefined, onClick: handleContainerClick, children: [_jsx("div", { className: "dndev-datepicker-segments", children: segmentConfigs.map((config, i) => (_jsxs(Fragment, { children: [i > 0 && (_jsx("span", { className: "dndev-datepicker-separator", "aria-hidden": "true", children: separator })), _jsx("span", { role: "spinbutton", tabIndex: disabled ? -1 : 0, "aria-valuenow": segments[config.type] ?? undefined, "aria-valuemin": config.min, "aria-valuemax": config.max, "aria-label": config.ariaLabel, "data-type": config.type, "data-placeholder": segments[config.type] == null || undefined, className: "dndev-datepicker-segment", onKeyDown: (e) => handleKeyDown(e, config, i), onFocus: handleFocus, onBlur: handleBlur, onPaste: handlePaste, ref: (el) => {
|
|
349
|
+
segmentRefs.current[i] = el;
|
|
350
|
+
}, children: segments[config.type] != null
|
|
351
|
+
? String(segments[config.type]).padStart(config.digits, '0')
|
|
352
|
+
: config.placeholder })] }, config.type))) }), _jsx(PopoverTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "dndev-datepicker-calendar-btn dndev-inline-action-btn", disabled: disabled, "aria-label": "Ouvrir le calendrier", tabIndex: disabled ? -1 : 0, children: _jsx(Icon, { icon: CalendarDays, className: "dndev-size-md", ariaHidden: true }) }) })] }), _jsx(PopoverContent, { align: "end", sideOffset: 4, className: "dndev-floating dndev-datepicker-popover", onCloseAutoFocus: (e) => {
|
|
353
|
+
e.preventDefault();
|
|
354
|
+
segmentRefs.current[0]?.focus();
|
|
355
|
+
}, children: _jsx(Calendar, { mode: 'single',
|
|
356
|
+
selected: dateValue,
|
|
357
|
+
onSelect: handleCalendarSelect,
|
|
358
|
+
defaultMonth: dateValue ?? minDate,
|
|
359
|
+
...(disabledDays.length > 0 ? { disabled: disabledDays } : {}),
|
|
360
|
+
...(minDate
|
|
361
|
+
? {
|
|
362
|
+
startMonth: new Date(minDate.getFullYear(), minDate.getMonth()),
|
|
363
|
+
}
|
|
364
|
+
: {}),
|
|
365
|
+
...(maxDate
|
|
366
|
+
? {
|
|
367
|
+
endMonth: new Date(maxDate.getFullYear(), maxDate.getMonth()),
|
|
368
|
+
}
|
|
369
|
+
: {}) }) })] }) }));
|
|
370
|
+
const nativeInput = (_jsx("input", { type: "date", className: "dndev-datepicker-native dndev-input", value: isoValue, onChange: handleNativeChange, min: minDate ? toISODate(minDate) : undefined, max: maxDate ? toISODate(maxDate) : undefined, required: required, disabled: disabled, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid || undefined }));
|
|
371
|
+
const content = (_jsxs("div", { ref: ref ?? containerRef, id: id, className: cn('dndev-datepicker', className), "aria-describedby": ariaDescribedBy, "data-disabled": disabled || undefined, children: [segmentedInput, nativeInput, name && _jsx("input", { type: "hidden", name: name, value: isoValue }), _jsx("div", { className: "dndev-datepicker-live", role: "status", "aria-live": "polite", children: liveText })] }));
|
|
372
|
+
if (label) {
|
|
373
|
+
return (_jsx(FloatingLabel, { htmlFor: id, label: label, disabled: disabled, required: required, children: content }));
|
|
374
|
+
}
|
|
375
|
+
return content;
|
|
376
|
+
}
|
|
377
|
+
export default DatePicker;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Ref } from 'react';
|
|
2
|
+
import './DateTimePicker.css';
|
|
3
|
+
/** Props for the DateTimePicker component. */
|
|
4
|
+
export interface DateTimePickerProps {
|
|
5
|
+
/** ISO 8601 datetime string (YYYY-MM-DDTHH:MM) or null */
|
|
6
|
+
value?: string | null;
|
|
7
|
+
/** Emits ISO datetime string (YYYY-MM-DDTHH:MM) or null */
|
|
8
|
+
onChange?: (datetime: string | null) => void;
|
|
9
|
+
/** FloatingLabel text */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Minimum selectable datetime (ISO string or Date) */
|
|
12
|
+
min?: string | Date;
|
|
13
|
+
/** Maximum selectable datetime (ISO string or Date) */
|
|
14
|
+
max?: string | Date;
|
|
15
|
+
/** Whether the field is required */
|
|
16
|
+
required?: boolean;
|
|
17
|
+
/** Whether the field is disabled */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** BCP 47 locale for segment order. Default: navigator.language or 'fr-FR' */
|
|
20
|
+
locale?: string;
|
|
21
|
+
/** Additional CSS classes */
|
|
22
|
+
className?: string;
|
|
23
|
+
/** Element id */
|
|
24
|
+
id?: string;
|
|
25
|
+
/** HTML name attribute for form submission */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** React 19 native ref */
|
|
28
|
+
ref?: Ref<HTMLDivElement>;
|
|
29
|
+
/** ARIA describedby for error/helper association */
|
|
30
|
+
'aria-describedby'?: string;
|
|
31
|
+
/** ARIA invalid for error state */
|
|
32
|
+
'aria-invalid'?: boolean;
|
|
33
|
+
/** data-variant for styling (e.g., 'destructive') */
|
|
34
|
+
'data-variant'?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Accessible datetime picker with segmented keyboard input, calendar popover,
|
|
38
|
+
* and automatic mobile native fallback.
|
|
39
|
+
*
|
|
40
|
+
* - Desktop: segmented DD/MM/YYYY HH:MM input with up/down increment, auto-advance
|
|
41
|
+
* - Mobile: native `<input type="datetime-local">` (OS picker is better on touch)
|
|
42
|
+
* - Keyboard: Arrow keys between segments, Up/Down to change values, paste-aware
|
|
43
|
+
* - ARIA: spinbutton pattern per segment, full screen reader support
|
|
44
|
+
*
|
|
45
|
+
* @component
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* <DateTimePicker label="Début" value={datetime} onChange={setDatetime} />
|
|
49
|
+
* <DateTimePicker label="Événement" min="2024-01-01T00:00" required />
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function DateTimePicker({ value, onChange, label, min, max, required, disabled, locale, className, id: idProp, name, ref, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'data-variant': dataVariant, }: DateTimePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
53
|
+
export default DateTimePicker;
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/atomic/DateTimePicker/index.tsx"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAiC,GAAG,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,sBAAsB,CAAC;AAsB9B,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC7C,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1B,oDAAoD;IACpD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mCAAmC;IACnC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qDAAqD;IACrD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AA2CD;;;;;;;;;;;;;;;GAeG;AACH,iBAAS,cAAc,CAAC,EACtB,KAAK,EACL,QAAQ,EACR,KAAK,EACL,GAAG,EACH,GAAG,EACH,QAAgB,EAChB,QAAgB,EAChB,MAAM,EACN,SAAS,EACT,EAAE,EAAE,MAAM,EACV,IAAI,EACJ,GAAG,EACH,kBAAkB,EAAE,eAAe,EACnC,cAAc,EAAE,WAAW,EAC3B,cAAc,EAAE,WAAW,GAC5B,EAAE,mBAAmB,2CAylBrB;AAED,eAAe,cAAc,CAAC"}
|