@simplybusiness/mobius-datepicker 9.0.1 → 9.0.2

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,463 @@
1
+ {
2
+ "inputs": {
3
+ "src/utils/isTouchDevice.ts": {
4
+ "bytes": 199,
5
+ "imports": [],
6
+ "format": "esm"
7
+ },
8
+ "src/components/DatePicker/utils/dateObjToString.ts": {
9
+ "bytes": 289,
10
+ "imports": [],
11
+ "format": "esm"
12
+ },
13
+ "src/components/DatePicker/utils/formatErrorMessageText.ts": {
14
+ "bytes": 740,
15
+ "imports": [
16
+ {
17
+ "path": "date-fns",
18
+ "kind": "import-statement",
19
+ "external": true
20
+ }
21
+ ],
22
+ "format": "esm"
23
+ },
24
+ "src/components/DatePicker/utils/validateDateFormat.ts": {
25
+ "bytes": 366,
26
+ "imports": [
27
+ {
28
+ "path": "date-fns",
29
+ "kind": "import-statement",
30
+ "external": true
31
+ }
32
+ ],
33
+ "format": "esm"
34
+ },
35
+ "src/components/DatePicker/constants.ts": {
36
+ "bytes": 109,
37
+ "imports": [],
38
+ "format": "esm"
39
+ },
40
+ "src/components/DatePicker/utils/weekdayAsOneLetter.ts": {
41
+ "bytes": 258,
42
+ "imports": [
43
+ {
44
+ "path": "src/components/DatePicker/constants.ts",
45
+ "kind": "import-statement",
46
+ "original": "../constants"
47
+ }
48
+ ],
49
+ "format": "esm"
50
+ },
51
+ "src/components/DatePicker/utils/index.ts": {
52
+ "bytes": 153,
53
+ "imports": [
54
+ {
55
+ "path": "src/components/DatePicker/utils/dateObjToString.ts",
56
+ "kind": "import-statement",
57
+ "original": "./dateObjToString"
58
+ },
59
+ {
60
+ "path": "src/components/DatePicker/utils/formatErrorMessageText.ts",
61
+ "kind": "import-statement",
62
+ "original": "./formatErrorMessageText"
63
+ },
64
+ {
65
+ "path": "src/components/DatePicker/utils/validateDateFormat.ts",
66
+ "kind": "import-statement",
67
+ "original": "./validateDateFormat"
68
+ },
69
+ {
70
+ "path": "src/components/DatePicker/utils/weekdayAsOneLetter.ts",
71
+ "kind": "import-statement",
72
+ "original": "./weekdayAsOneLetter"
73
+ }
74
+ ],
75
+ "format": "esm"
76
+ },
77
+ "src/hooks/useFocusTrap/useFocusTrap.tsx": {
78
+ "bytes": 1599,
79
+ "imports": [
80
+ {
81
+ "path": "react",
82
+ "kind": "import-statement",
83
+ "external": true
84
+ },
85
+ {
86
+ "path": "react/jsx-runtime",
87
+ "kind": "import-statement",
88
+ "external": true
89
+ }
90
+ ],
91
+ "format": "esm"
92
+ },
93
+ "src/components/DatePicker/utils/getStartWeekday.ts": {
94
+ "bytes": 460,
95
+ "imports": [
96
+ {
97
+ "path": "src/components/DatePicker/constants.ts",
98
+ "kind": "import-statement",
99
+ "original": "../constants"
100
+ }
101
+ ],
102
+ "format": "esm"
103
+ },
104
+ "src/components/DatePicker/utils/timezoneOffset.ts": {
105
+ "bytes": 610,
106
+ "imports": [],
107
+ "format": "esm"
108
+ },
109
+ "src/components/DatePicker/CustomComponents/CaptionLabel.tsx": {
110
+ "bytes": 314,
111
+ "imports": [
112
+ {
113
+ "path": "react",
114
+ "kind": "import-statement",
115
+ "external": true
116
+ },
117
+ {
118
+ "path": "react/jsx-runtime",
119
+ "kind": "import-statement",
120
+ "external": true
121
+ }
122
+ ],
123
+ "format": "esm"
124
+ },
125
+ "src/components/DatePicker/CustomComponents/ChevronComponent.tsx": {
126
+ "bytes": 396,
127
+ "imports": [
128
+ {
129
+ "path": "@simplybusiness/icons",
130
+ "kind": "import-statement",
131
+ "external": true
132
+ },
133
+ {
134
+ "path": "@simplybusiness/mobius",
135
+ "kind": "import-statement",
136
+ "external": true
137
+ },
138
+ {
139
+ "path": "react/jsx-runtime",
140
+ "kind": "import-statement",
141
+ "external": true
142
+ }
143
+ ],
144
+ "format": "esm"
145
+ },
146
+ "src/components/DatePicker/CustomComponents/index.tsx": {
147
+ "bytes": 68,
148
+ "imports": [
149
+ {
150
+ "path": "src/components/DatePicker/CustomComponents/CaptionLabel.tsx",
151
+ "kind": "import-statement",
152
+ "original": "./CaptionLabel"
153
+ },
154
+ {
155
+ "path": "src/components/DatePicker/CustomComponents/ChevronComponent.tsx",
156
+ "kind": "import-statement",
157
+ "original": "./ChevronComponent"
158
+ }
159
+ ],
160
+ "format": "esm"
161
+ },
162
+ "src/components/DatePicker/DatePickerModal.tsx": {
163
+ "bytes": 3988,
164
+ "imports": [
165
+ {
166
+ "path": "@simplybusiness/mobius",
167
+ "kind": "import-statement",
168
+ "external": true
169
+ },
170
+ {
171
+ "path": "classnames/dedupe",
172
+ "kind": "import-statement",
173
+ "external": true
174
+ },
175
+ {
176
+ "path": "date-fns",
177
+ "kind": "import-statement",
178
+ "external": true
179
+ },
180
+ {
181
+ "path": "react",
182
+ "kind": "import-statement",
183
+ "external": true
184
+ },
185
+ {
186
+ "path": "react-day-picker",
187
+ "kind": "import-statement",
188
+ "external": true
189
+ },
190
+ {
191
+ "path": "src/hooks/useFocusTrap/useFocusTrap.tsx",
192
+ "kind": "import-statement",
193
+ "original": "../../hooks/useFocusTrap/useFocusTrap"
194
+ },
195
+ {
196
+ "path": "src/components/DatePicker/utils/index.ts",
197
+ "kind": "import-statement",
198
+ "original": "./utils"
199
+ },
200
+ {
201
+ "path": "src/components/DatePicker/utils/getStartWeekday.ts",
202
+ "kind": "import-statement",
203
+ "original": "./utils/getStartWeekday"
204
+ },
205
+ {
206
+ "path": "src/components/DatePicker/utils/timezoneOffset.ts",
207
+ "kind": "import-statement",
208
+ "original": "./utils/timezoneOffset"
209
+ },
210
+ {
211
+ "path": "src/components/DatePicker/CustomComponents/index.tsx",
212
+ "kind": "import-statement",
213
+ "original": "./CustomComponents"
214
+ },
215
+ {
216
+ "path": "react/jsx-runtime",
217
+ "kind": "import-statement",
218
+ "external": true
219
+ }
220
+ ],
221
+ "format": "esm"
222
+ },
223
+ "src/components/DatePicker/DatePicker.tsx": {
224
+ "bytes": 6361,
225
+ "imports": [
226
+ {
227
+ "path": "@simplybusiness/icons",
228
+ "kind": "import-statement",
229
+ "external": true
230
+ },
231
+ {
232
+ "path": "@simplybusiness/mobius",
233
+ "kind": "import-statement",
234
+ "external": true
235
+ },
236
+ {
237
+ "path": "classnames/dedupe",
238
+ "kind": "import-statement",
239
+ "external": true
240
+ },
241
+ {
242
+ "path": "react",
243
+ "kind": "import-statement",
244
+ "external": true
245
+ },
246
+ {
247
+ "path": "src/utils/isTouchDevice.ts",
248
+ "kind": "import-statement",
249
+ "original": "../../utils/isTouchDevice"
250
+ },
251
+ {
252
+ "path": "src/components/DatePicker/utils/index.ts",
253
+ "kind": "import-statement",
254
+ "original": "./utils"
255
+ },
256
+ {
257
+ "path": "src/components/DatePicker/DatePickerModal.tsx",
258
+ "kind": "dynamic-import",
259
+ "original": "./DatePickerModal"
260
+ },
261
+ {
262
+ "path": "react/jsx-runtime",
263
+ "kind": "import-statement",
264
+ "external": true
265
+ }
266
+ ],
267
+ "format": "esm"
268
+ },
269
+ "src/components/DatePicker/index.tsx": {
270
+ "bytes": 30,
271
+ "imports": [
272
+ {
273
+ "path": "src/components/DatePicker/DatePicker.tsx",
274
+ "kind": "import-statement",
275
+ "original": "./DatePicker"
276
+ }
277
+ ],
278
+ "format": "esm"
279
+ },
280
+ "src/index.tsx": {
281
+ "bytes": 41,
282
+ "imports": [
283
+ {
284
+ "path": "src/components/DatePicker/index.tsx",
285
+ "kind": "import-statement",
286
+ "original": "./components/DatePicker"
287
+ }
288
+ ],
289
+ "format": "esm"
290
+ },
291
+ "index.tsx": {
292
+ "bytes": 23,
293
+ "imports": [
294
+ {
295
+ "path": "src/index.tsx",
296
+ "kind": "import-statement",
297
+ "original": "./src"
298
+ }
299
+ ],
300
+ "format": "esm"
301
+ }
302
+ },
303
+ "outputs": {
304
+ "dist/cjs/index.js.map": {
305
+ "imports": [],
306
+ "exports": [],
307
+ "inputs": {},
308
+ "bytes": 25892
309
+ },
310
+ "dist/cjs/index.js": {
311
+ "imports": [
312
+ {
313
+ "path": "date-fns",
314
+ "kind": "require-call",
315
+ "external": true
316
+ },
317
+ {
318
+ "path": "date-fns",
319
+ "kind": "require-call",
320
+ "external": true
321
+ },
322
+ {
323
+ "path": "react",
324
+ "kind": "require-call",
325
+ "external": true
326
+ },
327
+ {
328
+ "path": "react/jsx-runtime",
329
+ "kind": "require-call",
330
+ "external": true
331
+ },
332
+ {
333
+ "path": "react/jsx-runtime",
334
+ "kind": "require-call",
335
+ "external": true
336
+ },
337
+ {
338
+ "path": "@simplybusiness/icons",
339
+ "kind": "require-call",
340
+ "external": true
341
+ },
342
+ {
343
+ "path": "@simplybusiness/mobius",
344
+ "kind": "require-call",
345
+ "external": true
346
+ },
347
+ {
348
+ "path": "react/jsx-runtime",
349
+ "kind": "require-call",
350
+ "external": true
351
+ },
352
+ {
353
+ "path": "@simplybusiness/mobius",
354
+ "kind": "require-call",
355
+ "external": true
356
+ },
357
+ {
358
+ "path": "classnames/dedupe",
359
+ "kind": "require-call",
360
+ "external": true
361
+ },
362
+ {
363
+ "path": "date-fns",
364
+ "kind": "require-call",
365
+ "external": true
366
+ },
367
+ {
368
+ "path": "react",
369
+ "kind": "require-call",
370
+ "external": true
371
+ },
372
+ {
373
+ "path": "react-day-picker",
374
+ "kind": "require-call",
375
+ "external": true
376
+ },
377
+ {
378
+ "path": "react/jsx-runtime",
379
+ "kind": "require-call",
380
+ "external": true
381
+ },
382
+ {
383
+ "path": "@simplybusiness/icons",
384
+ "kind": "require-call",
385
+ "external": true
386
+ },
387
+ {
388
+ "path": "@simplybusiness/mobius",
389
+ "kind": "require-call",
390
+ "external": true
391
+ },
392
+ {
393
+ "path": "classnames/dedupe",
394
+ "kind": "require-call",
395
+ "external": true
396
+ },
397
+ {
398
+ "path": "react",
399
+ "kind": "require-call",
400
+ "external": true
401
+ },
402
+ {
403
+ "path": "react/jsx-runtime",
404
+ "kind": "require-call",
405
+ "external": true
406
+ }
407
+ ],
408
+ "exports": [],
409
+ "entryPoint": "index.tsx",
410
+ "inputs": {
411
+ "src/components/DatePicker/utils/dateObjToString.ts": {
412
+ "bytesInOutput": 386
413
+ },
414
+ "src/components/DatePicker/utils/formatErrorMessageText.ts": {
415
+ "bytesInOutput": 991
416
+ },
417
+ "src/components/DatePicker/utils/validateDateFormat.ts": {
418
+ "bytesInOutput": 569
419
+ },
420
+ "src/components/DatePicker/constants.ts": {
421
+ "bytesInOutput": 240
422
+ },
423
+ "src/components/DatePicker/utils/weekdayAsOneLetter.ts": {
424
+ "bytesInOutput": 389
425
+ },
426
+ "src/components/DatePicker/utils/index.ts": {
427
+ "bytesInOutput": 225
428
+ },
429
+ "src/hooks/useFocusTrap/useFocusTrap.tsx": {
430
+ "bytesInOutput": 1742
431
+ },
432
+ "src/components/DatePicker/utils/getStartWeekday.ts": {
433
+ "bytesInOutput": 365
434
+ },
435
+ "src/components/DatePicker/utils/timezoneOffset.ts": {
436
+ "bytesInOutput": 360
437
+ },
438
+ "src/components/DatePicker/CustomComponents/CaptionLabel.tsx": {
439
+ "bytesInOutput": 339
440
+ },
441
+ "src/components/DatePicker/CustomComponents/ChevronComponent.tsx": {
442
+ "bytesInOutput": 700
443
+ },
444
+ "src/components/DatePicker/CustomComponents/index.tsx": {
445
+ "bytesInOutput": 177
446
+ },
447
+ "src/components/DatePicker/DatePickerModal.tsx": {
448
+ "bytesInOutput": 4810
449
+ },
450
+ "index.tsx": {
451
+ "bytesInOutput": 131
452
+ },
453
+ "src/components/DatePicker/DatePicker.tsx": {
454
+ "bytesInOutput": 5372
455
+ },
456
+ "src/utils/isTouchDevice.ts": {
457
+ "bytesInOutput": 165
458
+ }
459
+ },
460
+ "bytes": 19358
461
+ }
462
+ }
463
+ }
@@ -0,0 +1,208 @@
1
+ "use client";
2
+
3
+ // src/components/DatePicker/DatePickerModal.tsx
4
+ import { VisuallyHidden, useOnClickOutside } from "@simplybusiness/mobius";
5
+ import classNames from "classnames/dedupe";
6
+ import { parseISO } from "date-fns";
7
+ import { useId, useRef as useRef2 } from "react";
8
+ import { DayPicker } from "react-day-picker";
9
+
10
+ // src/hooks/useFocusTrap/useFocusTrap.tsx
11
+ import { useEffect, useRef } from "react";
12
+ import { jsx } from "react/jsx-runtime";
13
+ var useFocusTrap = () => {
14
+ const containerRef = useRef(null);
15
+ useEffect(() => {
16
+ if (containerRef.current) {
17
+ const element = containerRef.current;
18
+ const focusableElements = containerRef.current.querySelectorAll(
19
+ '[tabindex="0"], .mobius-date-picker__nav-button'
20
+ );
21
+ const firstElement = focusableElements[0];
22
+ const lastElement = focusableElements[focusableElements.length - 1];
23
+ const handleTabKeyPress = (event) => {
24
+ if (event.key === "Tab") {
25
+ if (event.shiftKey && document.activeElement === firstElement) {
26
+ event.preventDefault();
27
+ lastElement.focus();
28
+ } else if (!event.shiftKey && document.activeElement && document.activeElement.className.indexOf(
29
+ "mobius-date-picker__day-button"
30
+ ) > -1) {
31
+ event.preventDefault();
32
+ firstElement.focus();
33
+ }
34
+ }
35
+ };
36
+ element.addEventListener("keydown", handleTabKeyPress);
37
+ return () => {
38
+ element.removeEventListener("keydown", handleTabKeyPress);
39
+ };
40
+ }
41
+ return () => {
42
+ };
43
+ }, []);
44
+ return containerRef;
45
+ };
46
+ function FocusTrap({ children }) {
47
+ const focusRef = useFocusTrap();
48
+ return /* @__PURE__ */ jsx("div", { className: "trap", ref: focusRef, children });
49
+ }
50
+
51
+ // src/components/DatePicker/utils/dateObjToString.ts
52
+ var dateObjToString = (date) => {
53
+ const year = date.getFullYear();
54
+ const month = String(date.getMonth() + 1).padStart(2, "0");
55
+ const day = String(date.getDate()).padStart(2, "0");
56
+ return `${year}-${month}-${day}`;
57
+ };
58
+
59
+ // src/components/DatePicker/constants.ts
60
+ var SUNDAY_AS_NUMBER = 0;
61
+ var MONDAY_AS_NUMBER = 1;
62
+ var DEFAULT_LOCALE = "en-GB";
63
+
64
+ // src/components/DatePicker/utils/weekdayAsOneLetter.ts
65
+ var weekdayAsOneLetter = (date) => {
66
+ const locale = navigator.language || DEFAULT_LOCALE;
67
+ const oneLetter = date.toLocaleString(locale, {
68
+ weekday: "narrow"
69
+ });
70
+ return oneLetter;
71
+ };
72
+
73
+ // src/components/DatePicker/utils/getStartWeekday.ts
74
+ var getStartWeekday = (locale) => {
75
+ switch (locale || DEFAULT_LOCALE) {
76
+ case "en-US":
77
+ return SUNDAY_AS_NUMBER;
78
+ default:
79
+ return MONDAY_AS_NUMBER;
80
+ }
81
+ };
82
+
83
+ // src/components/DatePicker/utils/timezoneOffset.ts
84
+ function toLocal(utcDateString) {
85
+ const utcDate = new Date(utcDateString);
86
+ if (Number.isNaN(utcDate.getTime())) {
87
+ throw new Error("Invalid date string");
88
+ }
89
+ return new Date(utcDate.getTime() + utcDate.getTimezoneOffset() * 6e4);
90
+ }
91
+
92
+ // src/components/DatePicker/CustomComponents/CaptionLabel.tsx
93
+ import { jsx as jsx2 } from "react/jsx-runtime";
94
+ var CaptionLabel = (props) => {
95
+ return /* @__PURE__ */ jsx2("h2", { ...props });
96
+ };
97
+
98
+ // src/components/DatePicker/CustomComponents/ChevronComponent.tsx
99
+ import { chevronLeft, chevronRight } from "@simplybusiness/icons";
100
+ import { Icon } from "@simplybusiness/mobius";
101
+ import { jsx as jsx3 } from "react/jsx-runtime";
102
+ var ChevronComponent = ({ orientation }) => {
103
+ if (orientation === "left") {
104
+ return /* @__PURE__ */ jsx3(Icon, { icon: chevronLeft });
105
+ }
106
+ return /* @__PURE__ */ jsx3(Icon, { icon: chevronRight });
107
+ };
108
+
109
+ // src/components/DatePicker/DatePickerModal.tsx
110
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
111
+ var startWeekday = getStartWeekday(
112
+ // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
113
+ typeof navigator !== "undefined" ? navigator?.language : void 0
114
+ );
115
+ var DatePickerModal = ({
116
+ date,
117
+ isOpen,
118
+ onSelected,
119
+ top,
120
+ min,
121
+ max
122
+ }) => {
123
+ const modalRef = useRef2(null);
124
+ const initialDate = date ? toLocal(date) : void 0;
125
+ const minDate = min ? toLocal(min) : void 0;
126
+ const maxDate = max ? toLocal(max) : void 0;
127
+ const hiddenId = `screen-reader-title-${useId()}`;
128
+ const handleSelected = (selectedDate) => {
129
+ onSelected(selectedDate);
130
+ };
131
+ const handleDayPickerSelect = (selectedDate) => {
132
+ if (!selectedDate) return;
133
+ handleSelected(dateObjToString(selectedDate));
134
+ };
135
+ useOnClickOutside(modalRef, () => {
136
+ if (modalRef.current && isOpen) {
137
+ handleSelected();
138
+ }
139
+ });
140
+ const modalClasses = classNames("mobius-date-picker__modal", {
141
+ "--is-open": isOpen
142
+ });
143
+ return /* @__PURE__ */ jsx4(FocusTrap, { children: /* @__PURE__ */ jsxs(
144
+ "div",
145
+ {
146
+ ref: modalRef,
147
+ className: modalClasses,
148
+ style: { top },
149
+ "aria-describedby": hiddenId,
150
+ "data-testid": "modal-container",
151
+ children: [
152
+ /* @__PURE__ */ jsx4(VisuallyHidden, { children: /* @__PURE__ */ jsx4("div", { id: hiddenId, children: "Please select a date from the calendar" }) }),
153
+ /* @__PURE__ */ jsx4(
154
+ DayPicker,
155
+ {
156
+ autoFocus: true,
157
+ mode: "single",
158
+ ...minDate && { startMonth: minDate },
159
+ ...maxDate && { endMonth: maxDate },
160
+ disabled: {
161
+ ...min && { before: parseISO(min) },
162
+ ...max && { after: parseISO(max) }
163
+ },
164
+ selected: initialDate,
165
+ defaultMonth: initialDate,
166
+ onSelect: handleDayPickerSelect,
167
+ pagedNavigation: true,
168
+ showOutsideDays: true,
169
+ weekStartsOn: startWeekday,
170
+ formatters: { formatWeekdayName: weekdayAsOneLetter },
171
+ components: {
172
+ Chevron: ChevronComponent,
173
+ CaptionLabel
174
+ },
175
+ classNames: {
176
+ root: "mobius-date-picker__root",
177
+ months: "mobius-date-picker__months",
178
+ month: "mobius-date-picker__month",
179
+ nav: "mobius-date-picker__nav",
180
+ button_previous: "mobius-date-picker__nav-button --previous",
181
+ button_next: "mobius-date-picker__nav-button --next",
182
+ month_caption: "mobius-date-picker__caption",
183
+ caption_label: "mobius-date-picker__caption-label",
184
+ month_grid: "mobius-date-picker__month-grid",
185
+ weekdays: "mobius-date-picker__weekdays",
186
+ weekday: "mobius-date-picker__weekday",
187
+ weeks: "mobius-date-picker__weeks",
188
+ week: "mobius-date-picker__week",
189
+ day: "mobius-date-picker__day",
190
+ day_button: "mobius-date-picker__day-button",
191
+ selected: "--is-selected",
192
+ disabled: "--is-disabled",
193
+ outside: "--is-outside",
194
+ hidden: "--is-hidden",
195
+ today: "--is-today",
196
+ focused: "--is-focused"
197
+ }
198
+ }
199
+ )
200
+ ]
201
+ }
202
+ ) });
203
+ };
204
+ var DatePickerModal_default = DatePickerModal;
205
+ export {
206
+ DatePickerModal_default as default
207
+ };
208
+ //# sourceMappingURL=DatePickerModal-WRMRIQDP.js.map