@simplybusiness/mobius-datepicker 9.0.1 → 9.0.3

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