carbon-react 103.2.0 → 104.2.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.
Files changed (77) hide show
  1. package/lib/__internal__/popover/popover.component.js +2 -6
  2. package/lib/__internal__/tooltip-provider/index.d.ts +1 -0
  3. package/lib/__internal__/tooltip-provider/index.js +6 -3
  4. package/lib/components/button/button.component.d.ts +21 -1
  5. package/lib/components/button/button.component.js +63 -52
  6. package/lib/components/date/__internal__/date-formats/index.d.ts +8 -0
  7. package/lib/components/date/__internal__/date-formats/index.js +47 -0
  8. package/lib/components/date/__internal__/date-picker/date-picker.component.d.ts +3 -0
  9. package/lib/components/date/__internal__/date-picker/date-picker.component.js +154 -0
  10. package/lib/components/date/__internal__/date-picker/date-picker.d.ts +25 -0
  11. package/lib/components/date/{day-picker.style.d.ts → __internal__/date-picker/day-picker.style.d.ts} +0 -0
  12. package/lib/components/date/{day-picker.style.js → __internal__/date-picker/day-picker.style.js} +5 -1
  13. package/lib/components/date/__internal__/date-picker/index.d.ts +1 -0
  14. package/lib/{__internal__/date → components/date/__internal__/date-picker}/index.js +2 -2
  15. package/lib/components/date/{navbar → __internal__/navbar}/button.style.d.ts +0 -0
  16. package/lib/components/date/{navbar → __internal__/navbar}/button.style.js +1 -1
  17. package/lib/components/date/{navbar → __internal__/navbar}/index.d.ts +0 -0
  18. package/lib/components/date/{navbar → __internal__/navbar}/index.js +0 -0
  19. package/lib/components/date/{navbar → __internal__/navbar}/navbar.component.d.ts +0 -0
  20. package/lib/components/date/{navbar → __internal__/navbar}/navbar.component.js +10 -12
  21. package/lib/components/date/__internal__/navbar/navbar.d.ts +8 -0
  22. package/lib/components/date/{navbar → __internal__/navbar}/navbar.style.d.ts +0 -0
  23. package/lib/components/date/{navbar → __internal__/navbar}/navbar.style.js +1 -1
  24. package/lib/components/date/__internal__/utils.d.ts +19 -0
  25. package/lib/components/date/__internal__/utils.js +182 -0
  26. package/lib/components/date/{weekday → __internal__/weekday}/abbr.style.d.ts +0 -0
  27. package/lib/components/date/{weekday → __internal__/weekday}/abbr.style.js +0 -0
  28. package/lib/components/date/{weekday → __internal__/weekday}/index.d.ts +0 -0
  29. package/lib/components/date/{weekday → __internal__/weekday}/index.js +0 -0
  30. package/lib/components/date/{weekday → __internal__/weekday}/weekday.component.d.ts +0 -0
  31. package/lib/components/date/{weekday → __internal__/weekday}/weekday.component.js +0 -0
  32. package/lib/components/date/__internal__/weekday/weekday.d.ts +13 -0
  33. package/lib/components/date/{weekday → __internal__/weekday}/weekday.style.d.ts +0 -0
  34. package/lib/components/date/{weekday → __internal__/weekday}/weekday.style.js +1 -1
  35. package/lib/components/date/date.component.d.ts +27 -55
  36. package/lib/components/date/date.component.js +291 -661
  37. package/lib/components/date/date.d.ts +28 -20
  38. package/lib/components/date/date.style.js +3 -2
  39. package/lib/components/date/index.js +2 -10
  40. package/lib/components/date-range/date-range-context.d.ts +17 -0
  41. package/lib/components/date-range/date-range.component.d.ts +3 -5
  42. package/lib/components/date-range/date-range.component.js +123 -119
  43. package/lib/components/date-range/date-range.context.d.ts +3 -0
  44. package/lib/components/date-range/date-range.context.js +14 -0
  45. package/lib/components/date-range/date-range.d.ts +5 -7
  46. package/lib/components/date-range/date-range.style.js +1 -0
  47. package/lib/components/date-range/index.d.ts +1 -0
  48. package/lib/components/i18n-provider/i18n-provider.component.d.ts +1 -4
  49. package/lib/components/i18n-provider/i18n-provider.component.js +1 -4
  50. package/lib/components/icon/icon.component.js +4 -2
  51. package/lib/components/icon-button/icon-button.component.js +11 -19
  52. package/lib/components/portal/portal.js +3 -6
  53. package/lib/components/step-sequence/step-sequence-item/step-sequence-item.style.js +13 -23
  54. package/lib/components/tooltip/tooltip.component.js +7 -7
  55. package/lib/components/tooltip/tooltip.d.ts +1 -0
  56. package/lib/locales/date-fns-locales/index.d.ts +1 -0
  57. package/lib/locales/date-fns-locales/index.js +18 -0
  58. package/lib/locales/en-gb.js +3 -4
  59. package/lib/locales/locale.d.ts +3 -4
  60. package/lib/locales/pl-pl.d.ts +1 -1
  61. package/lib/locales/pl-pl.js +5 -0
  62. package/lib/style/design-tokens/carbon-scoped-tokens-provider/carbon-scoped-tokens-provider.component.d.ts +7 -5
  63. package/lib/style/design-tokens/carbon-scoped-tokens-provider/carbon-scoped-tokens-provider.component.js +11 -36
  64. package/lib/style/themes/aegean/aegean-theme.config.d.ts +1 -0
  65. package/lib/style/themes/aegean/aegean-theme.config.js +2 -1
  66. package/lib/style/themes/base/base-theme.config.d.ts +162 -93
  67. package/lib/style/themes/mint/mint-theme.config.d.ts +1 -0
  68. package/lib/style/themes/mint/mint-theme.config.js +2 -1
  69. package/lib/style/themes/sage/index.d.ts +162 -93
  70. package/package.json +6 -5
  71. package/lib/__internal__/date/date.d.ts +0 -34
  72. package/lib/__internal__/date/date.js +0 -216
  73. package/lib/__internal__/date/index.d.ts +0 -1
  74. package/lib/__spec_helper__/mock-date-helper.d.ts +0 -1
  75. package/lib/__spec_helper__/mock-date-helper.js +0 -37
  76. package/lib/components/date/date-picker.component.d.ts +0 -22
  77. package/lib/components/date/date-picker.component.js +0 -218
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "103.2.0",
3
+ "version": "104.2.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {
@@ -101,7 +101,7 @@
101
101
  "chromatic": "^6.0.5",
102
102
  "commitizen": "^4.2.4",
103
103
  "conventional-changelog-conventionalcommits": "^4.5.0",
104
- "core-js": "^3.1.4",
104
+ "core-js": "^3.20.3",
105
105
  "cpy-cli": "^3.1.1",
106
106
  "cross-env": "^5.2.0",
107
107
  "cypress": "^9.2.0",
@@ -112,6 +112,7 @@
112
112
  "cypress-real-events": "^1.6.0",
113
113
  "cypress-storybook": "^0.5.1",
114
114
  "cz-conventional-changelog": "^3.3.0",
115
+ "date-fns-tz": "^1.2.2",
115
116
  "draft-js": "^0.11.7",
116
117
  "enzyme": "^3.3.0",
117
118
  "enzyme-adapter-react-16": "^1.14.0",
@@ -155,21 +156,21 @@
155
156
  "dependencies": {
156
157
  "@octokit/rest": "^18.12.0",
157
158
  "@popperjs/core": "^2.9.0",
158
- "@sage/design-tokens": "^1.87.1",
159
+ "@sage/design-tokens": "^1.89.0",
159
160
  "@styled-system/prop-types": "^5.1.5",
160
161
  "@tippyjs/react": "^4.2.5",
161
162
  "@types/styled-system": "^5.1.11",
162
163
  "classnames": "~2.2.6",
163
164
  "crypto-js": "~3.3.0",
165
+ "date-fns": "^2.26.0",
164
166
  "dotenv": "^10.0.0",
165
167
  "immutable": "~3.8.2",
166
168
  "invariant": "^2.2.4",
167
169
  "lodash": "^4.17.20",
168
- "moment": "~2.20.1",
169
170
  "node-fetch": "^2.6.1",
170
171
  "polished": "^4.0.5",
171
172
  "prop-types": "^15.7.2",
172
- "react-day-picker": "~6.1.1",
173
+ "react-day-picker": "~7.4.10",
173
174
  "react-dnd": "^10.0.2",
174
175
  "react-dnd-html5-backend": "^10.0.2",
175
176
  "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;