carbon-react 103.2.0 → 104.0.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.
- package/lib/components/date/__internal__/date-formats/index.d.ts +8 -0
- package/lib/components/date/__internal__/date-formats/index.js +47 -0
- package/lib/components/date/__internal__/date-picker/date-picker.component.d.ts +3 -0
- package/lib/components/date/__internal__/date-picker/date-picker.component.js +154 -0
- package/lib/components/date/__internal__/date-picker/date-picker.d.ts +25 -0
- package/lib/components/date/{day-picker.style.d.ts → __internal__/date-picker/day-picker.style.d.ts} +0 -0
- package/lib/components/date/{day-picker.style.js → __internal__/date-picker/day-picker.style.js} +5 -1
- package/lib/components/date/__internal__/date-picker/index.d.ts +1 -0
- package/lib/{__internal__/date → components/date/__internal__/date-picker}/index.js +2 -2
- package/lib/components/date/{navbar → __internal__/navbar}/button.style.d.ts +0 -0
- package/lib/components/date/{navbar → __internal__/navbar}/button.style.js +1 -1
- package/lib/components/date/{navbar → __internal__/navbar}/index.d.ts +0 -0
- package/lib/components/date/{navbar → __internal__/navbar}/index.js +0 -0
- package/lib/components/date/{navbar → __internal__/navbar}/navbar.component.d.ts +0 -0
- package/lib/components/date/{navbar → __internal__/navbar}/navbar.component.js +10 -12
- package/lib/components/date/__internal__/navbar/navbar.d.ts +8 -0
- package/lib/components/date/{navbar → __internal__/navbar}/navbar.style.d.ts +0 -0
- package/lib/components/date/{navbar → __internal__/navbar}/navbar.style.js +1 -1
- package/lib/components/date/__internal__/utils.d.ts +19 -0
- package/lib/components/date/__internal__/utils.js +182 -0
- package/lib/components/date/{weekday → __internal__/weekday}/abbr.style.d.ts +0 -0
- package/lib/components/date/{weekday → __internal__/weekday}/abbr.style.js +0 -0
- package/lib/components/date/{weekday → __internal__/weekday}/index.d.ts +0 -0
- package/lib/components/date/{weekday → __internal__/weekday}/index.js +0 -0
- package/lib/components/date/{weekday → __internal__/weekday}/weekday.component.d.ts +0 -0
- package/lib/components/date/{weekday → __internal__/weekday}/weekday.component.js +0 -0
- package/lib/components/date/__internal__/weekday/weekday.d.ts +13 -0
- package/lib/components/date/{weekday → __internal__/weekday}/weekday.style.d.ts +0 -0
- package/lib/components/date/{weekday → __internal__/weekday}/weekday.style.js +1 -1
- package/lib/components/date/date.component.d.ts +27 -55
- package/lib/components/date/date.component.js +291 -661
- package/lib/components/date/date.d.ts +28 -20
- package/lib/components/date/date.style.js +3 -2
- package/lib/components/date/index.js +2 -10
- package/lib/components/date-range/date-range-context.d.ts +17 -0
- package/lib/components/date-range/date-range.component.d.ts +3 -5
- package/lib/components/date-range/date-range.component.js +123 -119
- package/lib/components/date-range/date-range.context.d.ts +3 -0
- package/lib/components/date-range/date-range.context.js +14 -0
- package/lib/components/date-range/date-range.d.ts +5 -7
- package/lib/components/date-range/date-range.style.js +1 -0
- package/lib/components/date-range/index.d.ts +1 -0
- package/lib/components/i18n-provider/i18n-provider.component.d.ts +1 -4
- package/lib/components/i18n-provider/i18n-provider.component.js +1 -4
- package/lib/locales/date-fns-locales/index.d.ts +1 -0
- package/lib/locales/date-fns-locales/index.js +18 -0
- package/lib/locales/en-gb.js +3 -4
- package/lib/locales/locale.d.ts +3 -4
- package/lib/locales/pl-pl.d.ts +1 -1
- package/lib/locales/pl-pl.js +5 -0
- package/package.json +3 -3
- package/lib/__internal__/date/date.d.ts +0 -34
- package/lib/__internal__/date/date.js +0 -216
- package/lib/__internal__/date/index.d.ts +0 -1
- package/lib/__spec_helper__/mock-date-helper.d.ts +0 -1
- package/lib/__spec_helper__/mock-date-helper.js +0 -37
- package/lib/components/date/date-picker.component.d.ts +0 -22
- package/lib/components/date/date-picker.component.js +0 -218
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _locale = require("date-fns/locale");
|
|
8
|
+
|
|
9
|
+
Object.keys(_locale).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _locale[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _locale[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
package/lib/locales/en-gb.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _dateFnsLocales = require("./date-fns-locales");
|
|
9
|
+
|
|
8
10
|
const isSingular = count => (typeof count === "string" ? parseInt(count) : count) === 1;
|
|
9
11
|
|
|
10
12
|
var _default = {
|
|
@@ -24,10 +26,7 @@ var _default = {
|
|
|
24
26
|
yes: () => "Yes"
|
|
25
27
|
},
|
|
26
28
|
date: {
|
|
27
|
-
|
|
28
|
-
inputs: () => ["DDMMYYYY", "DDMMYY", "DD/MM/YYYY", "DD/MM/YY", "MMDDYYYY", "MMDDYY", "MM/DD/YYYY", "MM/DD/YY", "DDMMM", "DD/MMM", "DDMM", "DD/MM", "YYYYMMDD", "YYYY/MM/DD", "D/MM/YYYY", "D/M/YYYY", "D/MM/YY", "D/M/YY", "DD/M/YYYY", "DD/M/YY", "DD/M/YY", "D/MMM/YYYY", "DD/MMM/YYYY", "DD/MMM/YY", "D/MMMM/YYYY", "DD/MMMM/YYYY", "DD/MMMM/YY", "MMM/YYYY", "MMM/YY", "MMMM/YYYY", "MMMM/YY", "Do/MMM/YYYY", "Do/MMM/YY", "Do/M/YYYY", "Do/M/YY", "Do/MM/YYYY", "Do/MM/YY", "Do/MMMM/YYYY", "Do/MMMM/YY", "MMMM/Do/YYYY", "MMMM/Do/YY", "MMMM/Do", "MMM/Do/YYYY", "MMM/Do/YY", "MMM/Do", "Do/MMM", "D/MMM", "D/MM", "D/M", "Do/MMMM", "Do/MM", "Do/M", "D/MMMM", "DD/MMMM", "DD/MMM", "DD/M", "MMM", "MMMM", "DD", "Do", "D"],
|
|
29
|
-
javascript: () => "DD/MM/YYYY"
|
|
30
|
-
}
|
|
29
|
+
dateFnsLocale: () => _dateFnsLocales.enGB
|
|
31
30
|
},
|
|
32
31
|
errors: {
|
|
33
32
|
messages: {
|
package/lib/locales/locale.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Locale as DateFnsLocale } from "date-fns";
|
|
2
|
+
|
|
1
3
|
interface Locale {
|
|
2
4
|
locale: () => string;
|
|
3
5
|
actions: {
|
|
@@ -15,10 +17,7 @@ interface Locale {
|
|
|
15
17
|
yes: () => string;
|
|
16
18
|
};
|
|
17
19
|
date: {
|
|
18
|
-
|
|
19
|
-
inputs: () => string[];
|
|
20
|
-
javascript: () => string;
|
|
21
|
-
};
|
|
20
|
+
dateFnsLocale: () => DateFnsLocale;
|
|
22
21
|
};
|
|
23
22
|
errors: {
|
|
24
23
|
messages: {
|
package/lib/locales/pl-pl.d.ts
CHANGED
package/lib/locales/pl-pl.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _dateFnsLocales = require("./date-fns-locales");
|
|
9
|
+
|
|
8
10
|
const isSingular = count => (typeof count === "string" ? parseInt(count) : count) === 1;
|
|
9
11
|
|
|
10
12
|
var _default = {
|
|
@@ -23,6 +25,9 @@ var _default = {
|
|
|
23
25
|
no: () => "Nie",
|
|
24
26
|
yes: () => "Tak"
|
|
25
27
|
},
|
|
28
|
+
date: {
|
|
29
|
+
dateFnsLocale: () => _dateFnsLocales.pl
|
|
30
|
+
},
|
|
26
31
|
errors: {
|
|
27
32
|
messages: {
|
|
28
33
|
formSummary:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "104.0.0",
|
|
4
4
|
"description": "A library of reusable React components for easily building user interfaces.",
|
|
5
5
|
"engineStrict": true,
|
|
6
6
|
"engines": {
|
|
@@ -161,15 +161,15 @@
|
|
|
161
161
|
"@types/styled-system": "^5.1.11",
|
|
162
162
|
"classnames": "~2.2.6",
|
|
163
163
|
"crypto-js": "~3.3.0",
|
|
164
|
+
"date-fns": "^2.26.0",
|
|
164
165
|
"dotenv": "^10.0.0",
|
|
165
166
|
"immutable": "~3.8.2",
|
|
166
167
|
"invariant": "^2.2.4",
|
|
167
168
|
"lodash": "^4.17.20",
|
|
168
|
-
"moment": "~2.20.1",
|
|
169
169
|
"node-fetch": "^2.6.1",
|
|
170
170
|
"polished": "^4.0.5",
|
|
171
171
|
"prop-types": "^15.7.2",
|
|
172
|
-
"react-day-picker": "~
|
|
172
|
+
"react-day-picker": "~7.4.10",
|
|
173
173
|
"react-dnd": "^10.0.2",
|
|
174
174
|
"react-dnd-html5-backend": "^10.0.2",
|
|
175
175
|
"react-is": "^17.0.2",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
interface Locale {
|
|
2
|
-
locale: string;
|
|
3
|
-
formats: string[];
|
|
4
|
-
format: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
interface FormatDateToCurrentLocaleArgs extends Locale {
|
|
8
|
-
value: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface IsValidDateArgs extends FormatDateToCurrentLocaleArgs {
|
|
12
|
-
options?: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface FormatValueArgs extends IsValidDateArgs {
|
|
16
|
-
formatTo?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface WithinRangeArgs extends FormatDateToCurrentLocaleArgs {
|
|
20
|
-
limit: number;
|
|
21
|
-
units: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface DateHelper {
|
|
25
|
-
sanitizeDateInput: (value: string) => string;
|
|
26
|
-
isValidDate: (params: IsValidDateArgs) => boolean;
|
|
27
|
-
formatValue: (params: FormatValueArgs) => string;
|
|
28
|
-
stringToDate: (value: string) => Date;
|
|
29
|
-
formatDateString: (value: string, formatTo?: string) => string;
|
|
30
|
-
todayFormatted: (format?: string) => string;
|
|
31
|
-
weekdaysMinified: (locale: string) => string[];
|
|
32
|
-
withinRange: (params: WithinRangeArgs) => boolean;
|
|
33
|
-
formatDateToCurrentLocale: (params: FormatDateToCurrentLocaleArgs) => string;
|
|
34
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _moment = _interopRequireDefault(require("moment"));
|
|
9
|
-
|
|
10
|
-
require("moment/min/locales");
|
|
11
|
-
|
|
12
|
-
var _lodash = require("lodash");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
const isoDateFormat = "YYYY-MM-DD";
|
|
17
|
-
/**
|
|
18
|
-
* DateHelper used to encapsulate the date parsing library into a single helper
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const DateHelper = {
|
|
22
|
-
/**
|
|
23
|
-
* Sanitizes all valid date separators ( . - 'whitespace' ) replacing them
|
|
24
|
-
* with a slash
|
|
25
|
-
*
|
|
26
|
-
* This allows us to compare against one separator in the i18n string. DD/MM/YYYY
|
|
27
|
-
*
|
|
28
|
-
* @method sanitizeDateInput
|
|
29
|
-
* @return {String} sanitized input
|
|
30
|
-
*/
|
|
31
|
-
sanitizeDateInput: value => {
|
|
32
|
-
if (!value) {
|
|
33
|
-
return "";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return value.replace(/[-.\s]/g, "/").toLowerCase();
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Determines if date is valid
|
|
41
|
-
*
|
|
42
|
-
* @param {String} value - value to validate
|
|
43
|
-
* @param {Object} options Override Moment JS options
|
|
44
|
-
* @return {Boolean}
|
|
45
|
-
*/
|
|
46
|
-
isValidDate: ({
|
|
47
|
-
value,
|
|
48
|
-
options = {},
|
|
49
|
-
locale,
|
|
50
|
-
formats,
|
|
51
|
-
format
|
|
52
|
-
}) => {
|
|
53
|
-
return DateHelper._parseDate({
|
|
54
|
-
value,
|
|
55
|
-
options,
|
|
56
|
-
locale,
|
|
57
|
-
formats,
|
|
58
|
-
format
|
|
59
|
-
}).isValid();
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Formats the given value to a specified format
|
|
64
|
-
*
|
|
65
|
-
* @method formatValue
|
|
66
|
-
* @param {String} val current value
|
|
67
|
-
* @param {String} formatTo Desired format
|
|
68
|
-
* @param {Object} options Override Moment JS options
|
|
69
|
-
* @return {String} formatted date
|
|
70
|
-
*/
|
|
71
|
-
formatValue: ({
|
|
72
|
-
value,
|
|
73
|
-
formatTo = isoDateFormat,
|
|
74
|
-
options = {},
|
|
75
|
-
locale,
|
|
76
|
-
formats,
|
|
77
|
-
format
|
|
78
|
-
}) => {
|
|
79
|
-
const date = DateHelper._parseDate({
|
|
80
|
-
value,
|
|
81
|
-
options,
|
|
82
|
-
locale,
|
|
83
|
-
formats,
|
|
84
|
-
format
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
return date.isValid() ? date.format(formatTo) : value;
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Convert a value such as '2017-08-23' into a Javascript Date object
|
|
92
|
-
*
|
|
93
|
-
* @method stringToDate
|
|
94
|
-
* @param {String} value current value e.g. 2017-08-23
|
|
95
|
-
* @return {Object} The Date object
|
|
96
|
-
*/
|
|
97
|
-
stringToDate: value => (0, _moment.default)(value).toDate(),
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Formats the given date string to the specified format
|
|
101
|
-
* Moment will not format the standard Javascript Date string format
|
|
102
|
-
*
|
|
103
|
-
* @method formatDateString
|
|
104
|
-
* @param {String} value current value e.g. Wed Aug 23 2017 12:00:00 GMT+0100 (BST)
|
|
105
|
-
* @param {String} formatTo Desired format e.g. YYYY-MM-DD
|
|
106
|
-
* @return {String} formatted date
|
|
107
|
-
*/
|
|
108
|
-
formatDateString: (value, formatTo = isoDateFormat) => {
|
|
109
|
-
return (0, _moment.default)(new Date(value).getTime()).format(formatTo);
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Returns todays date formatted
|
|
114
|
-
*
|
|
115
|
-
* @param {String} format - format of date
|
|
116
|
-
* @return {Moment}
|
|
117
|
-
*/
|
|
118
|
-
todayFormatted: (format = isoDateFormat) => {
|
|
119
|
-
return (0, _moment.default)().format(format);
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Returns an array of days of the week by locale minified
|
|
124
|
-
* Mo, Tu, We, Th, Fr, Sa, Su
|
|
125
|
-
*
|
|
126
|
-
* @param {String} locale - defaulted to I18n.locale
|
|
127
|
-
* @return {Array}
|
|
128
|
-
*/
|
|
129
|
-
weekdaysMinified: locale => {
|
|
130
|
-
return _moment.default.localeData(locale)._weekdaysMin;
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @param {String} value - the date to test
|
|
135
|
-
* @param {Number} limit - the upper and lower bounds
|
|
136
|
-
* @param {String} units - defaulted to days
|
|
137
|
-
* @return {Boolean}
|
|
138
|
-
*/
|
|
139
|
-
withinRange: ({
|
|
140
|
-
value,
|
|
141
|
-
limit,
|
|
142
|
-
units,
|
|
143
|
-
locale,
|
|
144
|
-
formats,
|
|
145
|
-
format
|
|
146
|
-
}) => {
|
|
147
|
-
const momentValue = DateHelper._parseDate({
|
|
148
|
-
value,
|
|
149
|
-
locale,
|
|
150
|
-
formats,
|
|
151
|
-
format
|
|
152
|
-
}),
|
|
153
|
-
today = (0, _moment.default)();
|
|
154
|
-
|
|
155
|
-
const difference = Math.abs(today.diff(momentValue, units));
|
|
156
|
-
return difference < limit;
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Default options to pass to moment js
|
|
161
|
-
*
|
|
162
|
-
* @private
|
|
163
|
-
* formats - given accepted formats
|
|
164
|
-
* locale - current locale
|
|
165
|
-
* strict - moment js strict mode
|
|
166
|
-
*/
|
|
167
|
-
_defaultMomentOptions: (locale, formats) => {
|
|
168
|
-
return {
|
|
169
|
-
locale,
|
|
170
|
-
formats,
|
|
171
|
-
strict: true
|
|
172
|
-
};
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Parses date into moment
|
|
177
|
-
* Note when sanitizing dates formats must contain '/' for separators
|
|
178
|
-
*
|
|
179
|
-
* @private
|
|
180
|
-
* @param {String} value - value to parse
|
|
181
|
-
* @param {Object} options Override Moment JS options
|
|
182
|
-
* @return {Moment}
|
|
183
|
-
*/
|
|
184
|
-
_parseDate({
|
|
185
|
-
value,
|
|
186
|
-
options,
|
|
187
|
-
locale,
|
|
188
|
-
formats = [],
|
|
189
|
-
format
|
|
190
|
-
}) {
|
|
191
|
-
const opts = (0, _lodash.merge)(DateHelper._defaultMomentOptions(locale, formats), options, {
|
|
192
|
-
locale,
|
|
193
|
-
formats,
|
|
194
|
-
format
|
|
195
|
-
});
|
|
196
|
-
return (0, _moment.default)(value, [format, isoDateFormat, ...opts.formats], opts.locale, opts.strict);
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
formatDateToCurrentLocale({
|
|
200
|
-
value,
|
|
201
|
-
locale,
|
|
202
|
-
formats,
|
|
203
|
-
format
|
|
204
|
-
}) {
|
|
205
|
-
return DateHelper.formatValue({
|
|
206
|
-
value,
|
|
207
|
-
formatTo: format,
|
|
208
|
-
locale,
|
|
209
|
-
formats,
|
|
210
|
-
format
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
};
|
|
215
|
-
var _default = DateHelper;
|
|
216
|
-
exports.default = _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { "/home/runner/work/carbon/carbon/src/__internal__/date/date" as default } from "./date";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _moment = _interopRequireDefault(require("moment"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Replaces today date with specified in the argument of the "set" method.
|
|
9
|
-
* Ensures that the UTC time is returned regardless of the local time.
|
|
10
|
-
*/
|
|
11
|
-
jest.mock("../__internal__/date", () => {
|
|
12
|
-
const _DateHelper = jest.requireActual("../__internal__/date");
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
__esModule: true,
|
|
16
|
-
default: (() => {
|
|
17
|
-
const mockTodayDate = "1-1-2019";
|
|
18
|
-
const isoDateFormat = "YYYY-MM-DD";
|
|
19
|
-
const MockedDateHelper = { ..._DateHelper.default
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
MockedDateHelper._parseDate = (value, options) => _DateHelper.default._parseDate(value, options).utc();
|
|
23
|
-
|
|
24
|
-
MockedDateHelper.stringToDate = value => (0, _moment.default)(value).utc().toDate();
|
|
25
|
-
|
|
26
|
-
MockedDateHelper.todayFormatted = (format = isoDateFormat) => {
|
|
27
|
-
return (0, _moment.default)(mockTodayDate).utc().format(format);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
MockedDateHelper.formatDateString = (value, formatTo = isoDateFormat) => {
|
|
31
|
-
return (0, _moment.default)(new Date(value).getTime()).utc().format(formatTo);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return MockedDateHelper;
|
|
35
|
-
})()
|
|
36
|
-
};
|
|
37
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export default DatePicker;
|
|
2
|
-
declare function DatePicker({ inputElement, inputDate, handleDateSelect, minDate, maxDate, selectedDate, disablePortal, }: {
|
|
3
|
-
inputElement: any;
|
|
4
|
-
inputDate: any;
|
|
5
|
-
handleDateSelect: any;
|
|
6
|
-
minDate: any;
|
|
7
|
-
maxDate: any;
|
|
8
|
-
selectedDate: any;
|
|
9
|
-
disablePortal: any;
|
|
10
|
-
}): JSX.Element;
|
|
11
|
-
declare namespace DatePicker {
|
|
12
|
-
namespace propTypes {
|
|
13
|
-
const minDate: PropTypes.Requireable<string>;
|
|
14
|
-
const maxDate: PropTypes.Requireable<string>;
|
|
15
|
-
const disablePortal: PropTypes.Requireable<boolean>;
|
|
16
|
-
const inputDate: PropTypes.Requireable<string>;
|
|
17
|
-
const inputElement: PropTypes.Validator<object>;
|
|
18
|
-
const selectedDate: PropTypes.Requireable<string | object>;
|
|
19
|
-
const handleDateSelect: PropTypes.Requireable<(...args: any[]) => any>;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
import PropTypes from "prop-types";
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
|
-
var _moment = _interopRequireDefault(require("react-day-picker/moment"));
|
|
13
|
-
|
|
14
|
-
var _reactDayPicker = _interopRequireDefault(require("react-day-picker"));
|
|
15
|
-
|
|
16
|
-
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
17
|
-
|
|
18
|
-
var _popover = _interopRequireDefault(require("../../__internal__/popover"));
|
|
19
|
-
|
|
20
|
-
var _date = _interopRequireDefault(require("../../__internal__/date"));
|
|
21
|
-
|
|
22
|
-
var _useLocale = _interopRequireDefault(require("../../hooks/__internal__/useLocale"));
|
|
23
|
-
|
|
24
|
-
var _navbar = _interopRequireDefault(require("./navbar"));
|
|
25
|
-
|
|
26
|
-
var _weekday = _interopRequireDefault(require("./weekday"));
|
|
27
|
-
|
|
28
|
-
var _dayPicker = _interopRequireDefault(require("./day-picker.style"));
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
33
|
-
|
|
34
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
-
|
|
36
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
37
|
-
|
|
38
|
-
const DatePicker = ({
|
|
39
|
-
inputElement,
|
|
40
|
-
inputDate,
|
|
41
|
-
handleDateSelect,
|
|
42
|
-
minDate,
|
|
43
|
-
maxDate,
|
|
44
|
-
selectedDate,
|
|
45
|
-
disablePortal
|
|
46
|
-
}) => {
|
|
47
|
-
const l = (0, _useLocale.default)();
|
|
48
|
-
const locale = l.locale();
|
|
49
|
-
const formats = l.date.formats.inputs();
|
|
50
|
-
const format = l.date.formats.javascript();
|
|
51
|
-
const [lastValidDate, setLastValidDate] = (0, _react.useState)(_date.default.formatDateString(new Date().toString()));
|
|
52
|
-
const [localeData, setLocaleData] = (0, _react.useState)({
|
|
53
|
-
locale,
|
|
54
|
-
formats,
|
|
55
|
-
format
|
|
56
|
-
});
|
|
57
|
-
const ref = (0, _react.useRef)(null);
|
|
58
|
-
const popoverModifiers = (0, _react.useMemo)(() => [{
|
|
59
|
-
name: "offset",
|
|
60
|
-
options: {
|
|
61
|
-
offset: [0, 3]
|
|
62
|
-
}
|
|
63
|
-
}, {
|
|
64
|
-
name: "preventOverflow",
|
|
65
|
-
options: {
|
|
66
|
-
mainAxis: false
|
|
67
|
-
}
|
|
68
|
-
}], []);
|
|
69
|
-
(0, _react.useEffect)(() => {
|
|
70
|
-
if (localeData.format === format && (0, _isEqual.default)(localeData.formats, formats) && localeData.locale === locale) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
setLocaleData({
|
|
75
|
-
locale,
|
|
76
|
-
formats,
|
|
77
|
-
format
|
|
78
|
-
});
|
|
79
|
-
}, [localeData.format, localeData.formats, localeData.locale, format, formats, locale]);
|
|
80
|
-
(0, _react.useEffect)(() => {
|
|
81
|
-
let monthDate;
|
|
82
|
-
|
|
83
|
-
const isoFormattedInputDate = _date.default.formatValue({
|
|
84
|
-
value: inputDate,
|
|
85
|
-
...localeData
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (isDateValid(isoFormattedInputDate)) {
|
|
89
|
-
monthDate = new Date(isoFormattedInputDate);
|
|
90
|
-
setLastValidDate(isoFormattedInputDate);
|
|
91
|
-
} else {
|
|
92
|
-
monthDate = new Date(lastValidDate);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
ref.current.showMonth(monthDate);
|
|
96
|
-
}, [inputDate, lastValidDate, localeData]);
|
|
97
|
-
|
|
98
|
-
const handleDayClick = (date, modifiers) => {
|
|
99
|
-
if (!modifiers.disabled) {
|
|
100
|
-
handleDateSelect(date);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const datePickerProps = {
|
|
105
|
-
disabledDays: getDisabledDays(minDate, maxDate, localeData),
|
|
106
|
-
enableOutsideDays: true,
|
|
107
|
-
fixedWeeks: true,
|
|
108
|
-
initialMonth: selectedDate || undefined,
|
|
109
|
-
inline: true,
|
|
110
|
-
locale: l.locale(),
|
|
111
|
-
localeUtils: _moment.default,
|
|
112
|
-
navbarElement: /*#__PURE__*/_react.default.createElement(_navbar.default, null),
|
|
113
|
-
onDayClick: handleDayClick,
|
|
114
|
-
selectedDays: selectedDate || undefined,
|
|
115
|
-
weekdayElement: weekdayElementProps => {
|
|
116
|
-
const {
|
|
117
|
-
className,
|
|
118
|
-
weekday,
|
|
119
|
-
localeUtils
|
|
120
|
-
} = weekdayElementProps;
|
|
121
|
-
const weekdayLong = localeUtils.formatWeekdayLong(weekday, l.locale());
|
|
122
|
-
const weekdayShort = localeUtils.formatWeekdayShort(weekday, l.locale());
|
|
123
|
-
return /*#__PURE__*/_react.default.createElement(_weekday.default, {
|
|
124
|
-
className: className,
|
|
125
|
-
title: weekdayLong
|
|
126
|
-
}, weekdayShort);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
return /*#__PURE__*/_react.default.createElement(_popover.default, {
|
|
130
|
-
placement: "bottom-start",
|
|
131
|
-
reference: inputElement,
|
|
132
|
-
modifiers: popoverModifiers,
|
|
133
|
-
disablePortal: disablePortal
|
|
134
|
-
}, /*#__PURE__*/_react.default.createElement(_dayPicker.default, null, /*#__PURE__*/_react.default.createElement(_reactDayPicker.default, _extends({}, datePickerProps, {
|
|
135
|
-
ref: ref
|
|
136
|
-
}))));
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
DatePicker.propTypes = {
|
|
140
|
-
/** Minimum possible date */
|
|
141
|
-
minDate: _propTypes.default.string,
|
|
142
|
-
|
|
143
|
-
/** Maximum possible date */
|
|
144
|
-
maxDate: _propTypes.default.string,
|
|
145
|
-
|
|
146
|
-
/** Boolean to toggle where DatePicker is rendered in relation to the Date Input */
|
|
147
|
-
disablePortal: _propTypes.default.bool,
|
|
148
|
-
|
|
149
|
-
/* The string value in the date input */
|
|
150
|
-
inputDate: _propTypes.default.string,
|
|
151
|
-
|
|
152
|
-
/** Element that the DatePicker will be displayed under */
|
|
153
|
-
inputElement: _propTypes.default.object.isRequired,
|
|
154
|
-
|
|
155
|
-
/** Currently selected date */
|
|
156
|
-
selectedDate: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.string]),
|
|
157
|
-
|
|
158
|
-
/** Callback to set selected date */
|
|
159
|
-
handleDateSelect: _propTypes.default.func
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Checks if date can be transformed to native js Date object
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
function isDateValid(string) {
|
|
166
|
-
const date = new Date(string);
|
|
167
|
-
return date.toString() !== "Invalid Date";
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Returns the disabled array of days specified by props maxDate and minDate
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
function getDisabledDays(minDate, maxDate, {
|
|
175
|
-
locale,
|
|
176
|
-
formats,
|
|
177
|
-
format
|
|
178
|
-
}) {
|
|
179
|
-
const days = [];
|
|
180
|
-
|
|
181
|
-
if (!minDate && !maxDate) {
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (minDate && checkIsoFormatAndLength(minDate, locale, formats, format)) {
|
|
186
|
-
days.push({
|
|
187
|
-
before: _date.default.stringToDate(minDate)
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (maxDate && checkIsoFormatAndLength(maxDate, locale, formats, format)) {
|
|
192
|
-
days.push({
|
|
193
|
-
after: _date.default.stringToDate(maxDate)
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return days;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function checkIsoFormatAndLength(date, locale, formats, format) {
|
|
201
|
-
if (date.length !== 10 || !_date.default.isValidDate({
|
|
202
|
-
value: date,
|
|
203
|
-
options: {
|
|
204
|
-
defaultValue: "YYYY-MM-DD"
|
|
205
|
-
},
|
|
206
|
-
locale,
|
|
207
|
-
formats,
|
|
208
|
-
format
|
|
209
|
-
})) {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const array = date.split("-");
|
|
214
|
-
return array.length === 3 && array[0].length === 4 && array[1].length === 2 && array[2].length === 2;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
var _default = DatePicker;
|
|
218
|
-
exports.default = _default;
|