@simplybusiness/mobius-datepicker 8.0.4 → 9.0.1
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/CHANGELOG.md +21 -0
- package/dist/esm/index.js +363 -54
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/meta.json +51 -66
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +25 -11
- package/dist/cjs/index.js +0 -546
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/meta.json +0 -463
- package/dist/esm/DatePickerModal-WRMRIQDP.js +0 -208
- package/dist/esm/DatePickerModal-WRMRIQDP.js.map +0 -7
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplybusiness/mobius-datepicker",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "9.0.1",
|
|
5
5
|
"description": "Mobius date picker component",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"simplyBusiness": {
|
|
11
11
|
"publishToPublicNpm": true
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "dist/esm/index.js",
|
|
15
15
|
"types": "./dist/types/index.d.ts",
|
|
16
16
|
"files": [
|
|
17
17
|
"src",
|
|
@@ -20,16 +20,29 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"types": "./dist/types/index.d.ts",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"import": "./dist/esm/index.js",
|
|
24
|
+
"default": "./dist/esm/index.js"
|
|
25
25
|
},
|
|
26
26
|
"./src/*.css": "./src/*.css"
|
|
27
27
|
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"main": "dist/esm/index.js",
|
|
30
|
+
"module": "dist/esm/index.js",
|
|
31
|
+
"types": "./dist/types/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"import": "./dist/esm/index.js",
|
|
36
|
+
"default": "./dist/esm/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./src/*.css": "./src/*.css"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
28
41
|
"scripts": {
|
|
29
42
|
"clean": "rm -rf dist",
|
|
30
43
|
"build": "yarn run -T turbo run turbo:build",
|
|
31
44
|
"prepack": "yarn run build",
|
|
32
|
-
"build
|
|
45
|
+
"turbo:build": "yarn build:esm && yarn build:types",
|
|
33
46
|
"build:esm": "build-package esm",
|
|
34
47
|
"build:types": "tsc --emitDeclarationOnly --project tsconfig.build.json",
|
|
35
48
|
"lint": "eslint",
|
|
@@ -45,8 +58,8 @@
|
|
|
45
58
|
"@eslint/compat": "^2.0.2",
|
|
46
59
|
"@eslint/eslintrc": "^3.3.3",
|
|
47
60
|
"@eslint/js": "^9.39.2",
|
|
48
|
-
"@simplybusiness/build-scripts": "^
|
|
49
|
-
"@simplybusiness/eslint-config": "^2.0.
|
|
61
|
+
"@simplybusiness/build-scripts": "^2.0.1",
|
|
62
|
+
"@simplybusiness/eslint-config": "^2.0.1",
|
|
50
63
|
"@swc/core": "^1.12.5",
|
|
51
64
|
"@swc/jest": "^0.2.39",
|
|
52
65
|
"@testing-library/dom": "^10.4.1",
|
|
@@ -83,13 +96,14 @@
|
|
|
83
96
|
"react-dom": "^19.2.0"
|
|
84
97
|
},
|
|
85
98
|
"dependencies": {
|
|
86
|
-
"@simplybusiness/icons": "^
|
|
87
|
-
"@simplybusiness/mobius": "^
|
|
99
|
+
"@simplybusiness/icons": "^5.0.1",
|
|
100
|
+
"@simplybusiness/mobius": "^8.0.1",
|
|
88
101
|
"classnames": "^2.5.1",
|
|
89
102
|
"date-fns": "^4.1.0",
|
|
90
103
|
"react-day-picker": "^9.13.0"
|
|
91
104
|
},
|
|
92
105
|
"lint-staged": {
|
|
93
106
|
"*.{js,ts,jsx,tsx}": "eslint --fix"
|
|
94
|
-
}
|
|
107
|
+
},
|
|
108
|
+
"module": "dist/esm/index.js"
|
|
95
109
|
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,546 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
-
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
|
|
33
|
-
// src/components/DatePicker/utils/dateObjToString.ts
|
|
34
|
-
var dateObjToString;
|
|
35
|
-
var init_dateObjToString = __esm({
|
|
36
|
-
"src/components/DatePicker/utils/dateObjToString.ts"() {
|
|
37
|
-
"use strict";
|
|
38
|
-
dateObjToString = (date) => {
|
|
39
|
-
const year = date.getFullYear();
|
|
40
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
41
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
42
|
-
return `${year}-${month}-${day}`;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// src/components/DatePicker/utils/formatErrorMessageText.ts
|
|
48
|
-
var import_date_fns, DEFAULT_INVALID_DATE_MESSAGE, DEFAULT_BEFORE_MIN, DEFAULT_AFTER_MAX, formatErrorMessageText;
|
|
49
|
-
var init_formatErrorMessageText = __esm({
|
|
50
|
-
"src/components/DatePicker/utils/formatErrorMessageText.ts"() {
|
|
51
|
-
"use strict";
|
|
52
|
-
import_date_fns = require("date-fns");
|
|
53
|
-
DEFAULT_INVALID_DATE_MESSAGE = "Please enter a valid date";
|
|
54
|
-
DEFAULT_BEFORE_MIN = "The date you selected is before the earliest allowed date";
|
|
55
|
-
DEFAULT_AFTER_MAX = "The date you selected is after the latest allowed date";
|
|
56
|
-
formatErrorMessageText = (actual, min, max) => {
|
|
57
|
-
const actualDate = new Date(actual);
|
|
58
|
-
const minDate = min && new Date(min);
|
|
59
|
-
const maxDate = max && new Date(max);
|
|
60
|
-
if (minDate && (0, import_date_fns.isBefore)(actualDate, minDate)) {
|
|
61
|
-
return DEFAULT_BEFORE_MIN;
|
|
62
|
-
}
|
|
63
|
-
if (maxDate && (0, import_date_fns.isAfter)(actualDate, maxDate)) {
|
|
64
|
-
return DEFAULT_AFTER_MAX;
|
|
65
|
-
}
|
|
66
|
-
return DEFAULT_INVALID_DATE_MESSAGE;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// src/components/DatePicker/utils/validateDateFormat.ts
|
|
72
|
-
var import_date_fns2, DATE_FORMAT, validateDateFormat;
|
|
73
|
-
var init_validateDateFormat = __esm({
|
|
74
|
-
"src/components/DatePicker/utils/validateDateFormat.ts"() {
|
|
75
|
-
"use strict";
|
|
76
|
-
import_date_fns2 = require("date-fns");
|
|
77
|
-
DATE_FORMAT = "yyyy-MM-dd";
|
|
78
|
-
validateDateFormat = (date) => {
|
|
79
|
-
if (date === "") {
|
|
80
|
-
return "";
|
|
81
|
-
}
|
|
82
|
-
if ((0, import_date_fns2.isMatch)(date, DATE_FORMAT)) {
|
|
83
|
-
return date;
|
|
84
|
-
}
|
|
85
|
-
throw Error(
|
|
86
|
-
`DatePicker defaultValue '${date}' is invalid. The expected format is '${DATE_FORMAT}' `
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// src/components/DatePicker/constants.ts
|
|
93
|
-
var SUNDAY_AS_NUMBER, MONDAY_AS_NUMBER, DEFAULT_LOCALE;
|
|
94
|
-
var init_constants = __esm({
|
|
95
|
-
"src/components/DatePicker/constants.ts"() {
|
|
96
|
-
"use strict";
|
|
97
|
-
SUNDAY_AS_NUMBER = 0;
|
|
98
|
-
MONDAY_AS_NUMBER = 1;
|
|
99
|
-
DEFAULT_LOCALE = "en-GB";
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// src/components/DatePicker/utils/weekdayAsOneLetter.ts
|
|
104
|
-
var weekdayAsOneLetter;
|
|
105
|
-
var init_weekdayAsOneLetter = __esm({
|
|
106
|
-
"src/components/DatePicker/utils/weekdayAsOneLetter.ts"() {
|
|
107
|
-
"use strict";
|
|
108
|
-
init_constants();
|
|
109
|
-
weekdayAsOneLetter = (date) => {
|
|
110
|
-
const locale = navigator.language || DEFAULT_LOCALE;
|
|
111
|
-
const oneLetter = date.toLocaleString(locale, {
|
|
112
|
-
weekday: "narrow"
|
|
113
|
-
});
|
|
114
|
-
return oneLetter;
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// src/components/DatePicker/utils/index.ts
|
|
120
|
-
var init_utils = __esm({
|
|
121
|
-
"src/components/DatePicker/utils/index.ts"() {
|
|
122
|
-
"use strict";
|
|
123
|
-
init_dateObjToString();
|
|
124
|
-
init_formatErrorMessageText();
|
|
125
|
-
init_validateDateFormat();
|
|
126
|
-
init_weekdayAsOneLetter();
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// src/hooks/useFocusTrap/useFocusTrap.tsx
|
|
131
|
-
function FocusTrap({ children }) {
|
|
132
|
-
const focusRef = useFocusTrap();
|
|
133
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "trap", ref: focusRef, children });
|
|
134
|
-
}
|
|
135
|
-
var import_react, import_jsx_runtime, useFocusTrap;
|
|
136
|
-
var init_useFocusTrap = __esm({
|
|
137
|
-
"src/hooks/useFocusTrap/useFocusTrap.tsx"() {
|
|
138
|
-
"use strict";
|
|
139
|
-
import_react = require("react");
|
|
140
|
-
import_jsx_runtime = require("react/jsx-runtime");
|
|
141
|
-
useFocusTrap = () => {
|
|
142
|
-
const containerRef = (0, import_react.useRef)(null);
|
|
143
|
-
(0, import_react.useEffect)(() => {
|
|
144
|
-
if (containerRef.current) {
|
|
145
|
-
const element = containerRef.current;
|
|
146
|
-
const focusableElements = containerRef.current.querySelectorAll(
|
|
147
|
-
'[tabindex="0"], .mobius-date-picker__nav-button'
|
|
148
|
-
);
|
|
149
|
-
const firstElement = focusableElements[0];
|
|
150
|
-
const lastElement = focusableElements[focusableElements.length - 1];
|
|
151
|
-
const handleTabKeyPress = (event) => {
|
|
152
|
-
if (event.key === "Tab") {
|
|
153
|
-
if (event.shiftKey && document.activeElement === firstElement) {
|
|
154
|
-
event.preventDefault();
|
|
155
|
-
lastElement.focus();
|
|
156
|
-
} else if (!event.shiftKey && document.activeElement && document.activeElement.className.indexOf(
|
|
157
|
-
"mobius-date-picker__day-button"
|
|
158
|
-
) > -1) {
|
|
159
|
-
event.preventDefault();
|
|
160
|
-
firstElement.focus();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
element.addEventListener("keydown", handleTabKeyPress);
|
|
165
|
-
return () => {
|
|
166
|
-
element.removeEventListener("keydown", handleTabKeyPress);
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
return () => {
|
|
170
|
-
};
|
|
171
|
-
}, []);
|
|
172
|
-
return containerRef;
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// src/components/DatePicker/utils/getStartWeekday.ts
|
|
178
|
-
var getStartWeekday;
|
|
179
|
-
var init_getStartWeekday = __esm({
|
|
180
|
-
"src/components/DatePicker/utils/getStartWeekday.ts"() {
|
|
181
|
-
"use strict";
|
|
182
|
-
init_constants();
|
|
183
|
-
getStartWeekday = (locale) => {
|
|
184
|
-
switch (locale || DEFAULT_LOCALE) {
|
|
185
|
-
case "en-US":
|
|
186
|
-
return SUNDAY_AS_NUMBER;
|
|
187
|
-
default:
|
|
188
|
-
return MONDAY_AS_NUMBER;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// src/components/DatePicker/utils/timezoneOffset.ts
|
|
195
|
-
function toLocal(utcDateString) {
|
|
196
|
-
const utcDate = new Date(utcDateString);
|
|
197
|
-
if (Number.isNaN(utcDate.getTime())) {
|
|
198
|
-
throw new Error("Invalid date string");
|
|
199
|
-
}
|
|
200
|
-
return new Date(utcDate.getTime() + utcDate.getTimezoneOffset() * 6e4);
|
|
201
|
-
}
|
|
202
|
-
var init_timezoneOffset = __esm({
|
|
203
|
-
"src/components/DatePicker/utils/timezoneOffset.ts"() {
|
|
204
|
-
"use strict";
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
// src/components/DatePicker/CustomComponents/CaptionLabel.tsx
|
|
209
|
-
var import_jsx_runtime2, CaptionLabel;
|
|
210
|
-
var init_CaptionLabel = __esm({
|
|
211
|
-
"src/components/DatePicker/CustomComponents/CaptionLabel.tsx"() {
|
|
212
|
-
"use strict";
|
|
213
|
-
import_jsx_runtime2 = require("react/jsx-runtime");
|
|
214
|
-
CaptionLabel = (props) => {
|
|
215
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { ...props });
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// src/components/DatePicker/CustomComponents/ChevronComponent.tsx
|
|
221
|
-
var import_icons, import_mobius, import_jsx_runtime3, ChevronComponent;
|
|
222
|
-
var init_ChevronComponent = __esm({
|
|
223
|
-
"src/components/DatePicker/CustomComponents/ChevronComponent.tsx"() {
|
|
224
|
-
"use strict";
|
|
225
|
-
import_icons = require("@simplybusiness/icons");
|
|
226
|
-
import_mobius = require("@simplybusiness/mobius");
|
|
227
|
-
import_jsx_runtime3 = require("react/jsx-runtime");
|
|
228
|
-
ChevronComponent = ({ orientation }) => {
|
|
229
|
-
if (orientation === "left") {
|
|
230
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mobius.Icon, { icon: import_icons.chevronLeft });
|
|
231
|
-
}
|
|
232
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mobius.Icon, { icon: import_icons.chevronRight });
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
// src/components/DatePicker/CustomComponents/index.tsx
|
|
238
|
-
var init_CustomComponents = __esm({
|
|
239
|
-
"src/components/DatePicker/CustomComponents/index.tsx"() {
|
|
240
|
-
"use strict";
|
|
241
|
-
init_CaptionLabel();
|
|
242
|
-
init_ChevronComponent();
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// src/components/DatePicker/DatePickerModal.tsx
|
|
247
|
-
var DatePickerModal_exports = {};
|
|
248
|
-
__export(DatePickerModal_exports, {
|
|
249
|
-
default: () => DatePickerModal_default
|
|
250
|
-
});
|
|
251
|
-
var import_mobius2, import_dedupe, import_date_fns3, import_react2, import_react_day_picker, import_jsx_runtime4, startWeekday, DatePickerModal, DatePickerModal_default;
|
|
252
|
-
var init_DatePickerModal = __esm({
|
|
253
|
-
"src/components/DatePicker/DatePickerModal.tsx"() {
|
|
254
|
-
"use strict";
|
|
255
|
-
"use client";
|
|
256
|
-
import_mobius2 = require("@simplybusiness/mobius");
|
|
257
|
-
import_dedupe = __toESM(require("classnames/dedupe"));
|
|
258
|
-
import_date_fns3 = require("date-fns");
|
|
259
|
-
import_react2 = require("react");
|
|
260
|
-
import_react_day_picker = require("react-day-picker");
|
|
261
|
-
init_useFocusTrap();
|
|
262
|
-
init_utils();
|
|
263
|
-
init_getStartWeekday();
|
|
264
|
-
init_timezoneOffset();
|
|
265
|
-
init_CustomComponents();
|
|
266
|
-
import_jsx_runtime4 = require("react/jsx-runtime");
|
|
267
|
-
startWeekday = getStartWeekday(
|
|
268
|
-
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
|
|
269
|
-
typeof navigator !== "undefined" ? navigator?.language : void 0
|
|
270
|
-
);
|
|
271
|
-
DatePickerModal = ({
|
|
272
|
-
date,
|
|
273
|
-
isOpen,
|
|
274
|
-
onSelected,
|
|
275
|
-
top,
|
|
276
|
-
min,
|
|
277
|
-
max
|
|
278
|
-
}) => {
|
|
279
|
-
const modalRef = (0, import_react2.useRef)(null);
|
|
280
|
-
const initialDate = date ? toLocal(date) : void 0;
|
|
281
|
-
const minDate = min ? toLocal(min) : void 0;
|
|
282
|
-
const maxDate = max ? toLocal(max) : void 0;
|
|
283
|
-
const hiddenId = `screen-reader-title-${(0, import_react2.useId)()}`;
|
|
284
|
-
const handleSelected = (selectedDate) => {
|
|
285
|
-
onSelected(selectedDate);
|
|
286
|
-
};
|
|
287
|
-
const handleDayPickerSelect = (selectedDate) => {
|
|
288
|
-
if (!selectedDate) return;
|
|
289
|
-
handleSelected(dateObjToString(selectedDate));
|
|
290
|
-
};
|
|
291
|
-
(0, import_mobius2.useOnClickOutside)(modalRef, () => {
|
|
292
|
-
if (modalRef.current && isOpen) {
|
|
293
|
-
handleSelected();
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
const modalClasses = (0, import_dedupe.default)("mobius-date-picker__modal", {
|
|
297
|
-
"--is-open": isOpen
|
|
298
|
-
});
|
|
299
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FocusTrap, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
300
|
-
"div",
|
|
301
|
-
{
|
|
302
|
-
ref: modalRef,
|
|
303
|
-
className: modalClasses,
|
|
304
|
-
style: { top },
|
|
305
|
-
"aria-describedby": hiddenId,
|
|
306
|
-
"data-testid": "modal-container",
|
|
307
|
-
children: [
|
|
308
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_mobius2.VisuallyHidden, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: hiddenId, children: "Please select a date from the calendar" }) }),
|
|
309
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
310
|
-
import_react_day_picker.DayPicker,
|
|
311
|
-
{
|
|
312
|
-
autoFocus: true,
|
|
313
|
-
mode: "single",
|
|
314
|
-
...minDate && { startMonth: minDate },
|
|
315
|
-
...maxDate && { endMonth: maxDate },
|
|
316
|
-
disabled: {
|
|
317
|
-
...min && { before: (0, import_date_fns3.parseISO)(min) },
|
|
318
|
-
...max && { after: (0, import_date_fns3.parseISO)(max) }
|
|
319
|
-
},
|
|
320
|
-
selected: initialDate,
|
|
321
|
-
defaultMonth: initialDate,
|
|
322
|
-
onSelect: handleDayPickerSelect,
|
|
323
|
-
pagedNavigation: true,
|
|
324
|
-
showOutsideDays: true,
|
|
325
|
-
weekStartsOn: startWeekday,
|
|
326
|
-
formatters: { formatWeekdayName: weekdayAsOneLetter },
|
|
327
|
-
components: {
|
|
328
|
-
Chevron: ChevronComponent,
|
|
329
|
-
CaptionLabel
|
|
330
|
-
},
|
|
331
|
-
classNames: {
|
|
332
|
-
root: "mobius-date-picker__root",
|
|
333
|
-
months: "mobius-date-picker__months",
|
|
334
|
-
month: "mobius-date-picker__month",
|
|
335
|
-
nav: "mobius-date-picker__nav",
|
|
336
|
-
button_previous: "mobius-date-picker__nav-button --previous",
|
|
337
|
-
button_next: "mobius-date-picker__nav-button --next",
|
|
338
|
-
month_caption: "mobius-date-picker__caption",
|
|
339
|
-
caption_label: "mobius-date-picker__caption-label",
|
|
340
|
-
month_grid: "mobius-date-picker__month-grid",
|
|
341
|
-
weekdays: "mobius-date-picker__weekdays",
|
|
342
|
-
weekday: "mobius-date-picker__weekday",
|
|
343
|
-
weeks: "mobius-date-picker__weeks",
|
|
344
|
-
week: "mobius-date-picker__week",
|
|
345
|
-
day: "mobius-date-picker__day",
|
|
346
|
-
day_button: "mobius-date-picker__day-button",
|
|
347
|
-
selected: "--is-selected",
|
|
348
|
-
disabled: "--is-disabled",
|
|
349
|
-
outside: "--is-outside",
|
|
350
|
-
hidden: "--is-hidden",
|
|
351
|
-
today: "--is-today",
|
|
352
|
-
focused: "--is-focused"
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
)
|
|
356
|
-
]
|
|
357
|
-
}
|
|
358
|
-
) });
|
|
359
|
-
};
|
|
360
|
-
DatePickerModal_default = DatePickerModal;
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
// index.tsx
|
|
365
|
-
var index_exports = {};
|
|
366
|
-
__export(index_exports, {
|
|
367
|
-
DatePicker: () => DatePicker
|
|
368
|
-
});
|
|
369
|
-
module.exports = __toCommonJS(index_exports);
|
|
370
|
-
|
|
371
|
-
// src/components/DatePicker/DatePicker.tsx
|
|
372
|
-
var import_icons2 = require("@simplybusiness/icons");
|
|
373
|
-
var import_mobius3 = require("@simplybusiness/mobius");
|
|
374
|
-
var import_dedupe2 = __toESM(require("classnames/dedupe"));
|
|
375
|
-
var import_react3 = require("react");
|
|
376
|
-
|
|
377
|
-
// src/utils/isTouchDevice.ts
|
|
378
|
-
var isTouchDevice = () => {
|
|
379
|
-
if (typeof window !== "undefined") {
|
|
380
|
-
return window.matchMedia("(hover: none), (pointer: coarse)").matches;
|
|
381
|
-
}
|
|
382
|
-
return void 0;
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
// src/components/DatePicker/DatePicker.tsx
|
|
386
|
-
init_utils();
|
|
387
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
388
|
-
var DatePickerModal2 = (0, import_react3.lazy)(() => Promise.resolve().then(() => (init_DatePickerModal(), DatePickerModal_exports)));
|
|
389
|
-
var getValidationState = (isInvalid) => {
|
|
390
|
-
if (isInvalid) {
|
|
391
|
-
return true;
|
|
392
|
-
}
|
|
393
|
-
if (isInvalid === false) {
|
|
394
|
-
return false;
|
|
395
|
-
}
|
|
396
|
-
return void 0;
|
|
397
|
-
};
|
|
398
|
-
var DatePicker = (props) => {
|
|
399
|
-
const {
|
|
400
|
-
onChange,
|
|
401
|
-
defaultValue = "",
|
|
402
|
-
isDisabled,
|
|
403
|
-
isInvalid,
|
|
404
|
-
errorMessage = "",
|
|
405
|
-
...otherProps
|
|
406
|
-
} = props;
|
|
407
|
-
const containerRef = (0, import_react3.useRef)(null);
|
|
408
|
-
const [top, setTop] = (0, import_react3.useState)(0);
|
|
409
|
-
const inputRef = (0, import_react3.useRef)(null);
|
|
410
|
-
const [isOpen, setIsOpen] = (0, import_react3.useState)(false);
|
|
411
|
-
const [textFieldVal, setTextFieldVal] = (0, import_react3.useState)(
|
|
412
|
-
validateDateFormat(defaultValue)
|
|
413
|
-
);
|
|
414
|
-
const [isValid, setIsValid] = (0, import_react3.useState)(void 0);
|
|
415
|
-
const isInvalidProp = getValidationState(isValid === false || isInvalid);
|
|
416
|
-
const errorMessageText = isInvalidProp ? formatErrorMessageText(textFieldVal, props.min, props.max) : errorMessage;
|
|
417
|
-
const touchDevice = isTouchDevice();
|
|
418
|
-
const validationClasses = (0, import_mobius3.useValidationClasses)({ isInvalid: isInvalidProp });
|
|
419
|
-
const containerClasses = (0, import_dedupe2.default)(
|
|
420
|
-
"mobius-date-picker__container",
|
|
421
|
-
{
|
|
422
|
-
"--is-disabled": isDisabled,
|
|
423
|
-
"--is-touch-device": touchDevice
|
|
424
|
-
},
|
|
425
|
-
validationClasses
|
|
426
|
-
);
|
|
427
|
-
const popoverToggleClasses = (0, import_dedupe2.default)(
|
|
428
|
-
"mobius-date-picker__field-button",
|
|
429
|
-
validationClasses
|
|
430
|
-
);
|
|
431
|
-
const validate = (0, import_react3.useCallback)(() => {
|
|
432
|
-
if (isOpen) return;
|
|
433
|
-
const isValidInput = inputRef.current?.checkValidity();
|
|
434
|
-
if (!isValidInput) {
|
|
435
|
-
setIsValid(false);
|
|
436
|
-
}
|
|
437
|
-
}, [isOpen]);
|
|
438
|
-
(0, import_react3.useEffect)(() => {
|
|
439
|
-
if (!inputRef.current) return;
|
|
440
|
-
const validatedValue = validateDateFormat(defaultValue);
|
|
441
|
-
setTextFieldVal(validatedValue);
|
|
442
|
-
inputRef.current.value = validatedValue;
|
|
443
|
-
setIsValid(true);
|
|
444
|
-
validate();
|
|
445
|
-
}, [defaultValue, validate]);
|
|
446
|
-
const togglePopoverVisibility = () => {
|
|
447
|
-
setIsValid(true);
|
|
448
|
-
setIsOpen(!isOpen);
|
|
449
|
-
};
|
|
450
|
-
const handleTextFieldChange = (event) => {
|
|
451
|
-
setTextFieldVal(event.target.value);
|
|
452
|
-
setIsValid(true);
|
|
453
|
-
};
|
|
454
|
-
const onDateSelected = (selectedDate) => {
|
|
455
|
-
if (selectedDate) {
|
|
456
|
-
setTextFieldVal(selectedDate);
|
|
457
|
-
setIsValid(true);
|
|
458
|
-
onChange?.(selectedDate);
|
|
459
|
-
}
|
|
460
|
-
inputRef.current?.focus();
|
|
461
|
-
setIsOpen(false);
|
|
462
|
-
};
|
|
463
|
-
const handleBlur = (event) => {
|
|
464
|
-
const target = event.target;
|
|
465
|
-
if (isOpen && event.relatedTarget && containerRef.current?.contains(event.relatedTarget)) {
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
validate();
|
|
469
|
-
if (!textFieldVal) {
|
|
470
|
-
setIsValid(false);
|
|
471
|
-
}
|
|
472
|
-
onChange?.(target.value);
|
|
473
|
-
};
|
|
474
|
-
const handleClick = (event) => {
|
|
475
|
-
event.preventDefault();
|
|
476
|
-
togglePopoverVisibility();
|
|
477
|
-
};
|
|
478
|
-
(0, import_react3.useEffect)(() => {
|
|
479
|
-
if (isOpen) {
|
|
480
|
-
setTop(containerRef.current?.getBoundingClientRect().height || 0);
|
|
481
|
-
setIsValid(true);
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
validate();
|
|
485
|
-
}, [isOpen, validate]);
|
|
486
|
-
if (touchDevice) {
|
|
487
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: containerClasses, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
488
|
-
import_mobius3.TextField,
|
|
489
|
-
{
|
|
490
|
-
ref: inputRef,
|
|
491
|
-
type: "date",
|
|
492
|
-
className: "mobius-date-picker",
|
|
493
|
-
onBlur: handleBlur,
|
|
494
|
-
onChange: handleTextFieldChange,
|
|
495
|
-
value: textFieldVal,
|
|
496
|
-
isDisabled,
|
|
497
|
-
isInvalid: isInvalidProp,
|
|
498
|
-
...otherProps,
|
|
499
|
-
errorMessage: errorMessage || errorMessageText
|
|
500
|
-
}
|
|
501
|
-
) });
|
|
502
|
-
}
|
|
503
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: containerClasses, ref: containerRef, children: [
|
|
504
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
505
|
-
import_mobius3.TextField,
|
|
506
|
-
{
|
|
507
|
-
ref: inputRef,
|
|
508
|
-
type: "date",
|
|
509
|
-
className: "mobius-date-picker",
|
|
510
|
-
onBlur: handleBlur,
|
|
511
|
-
onChange: handleTextFieldChange,
|
|
512
|
-
onClick: handleClick,
|
|
513
|
-
value: textFieldVal,
|
|
514
|
-
isDisabled,
|
|
515
|
-
isInvalid: isInvalidProp,
|
|
516
|
-
...otherProps,
|
|
517
|
-
errorMessage: errorMessage || errorMessageText,
|
|
518
|
-
suffixOutside: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
519
|
-
import_mobius3.Button,
|
|
520
|
-
{
|
|
521
|
-
className: popoverToggleClasses,
|
|
522
|
-
onClick: togglePopoverVisibility,
|
|
523
|
-
isDisabled,
|
|
524
|
-
size: "sm",
|
|
525
|
-
children: [
|
|
526
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mobius3.Icon, { size: "sm", icon: import_icons2.calendarDay }),
|
|
527
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mobius3.VisuallyHidden, { children: "Pick date" })
|
|
528
|
-
]
|
|
529
|
-
}
|
|
530
|
-
)
|
|
531
|
-
}
|
|
532
|
-
),
|
|
533
|
-
isOpen && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react3.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
534
|
-
DatePickerModal2,
|
|
535
|
-
{
|
|
536
|
-
date: textFieldVal,
|
|
537
|
-
isOpen,
|
|
538
|
-
top,
|
|
539
|
-
onSelected: onDateSelected,
|
|
540
|
-
min: props.min,
|
|
541
|
-
max: props.max
|
|
542
|
-
}
|
|
543
|
-
) })
|
|
544
|
-
] });
|
|
545
|
-
};
|
|
546
|
-
//# sourceMappingURL=index.js.map
|