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
@@ -1,35 +1,43 @@
1
1
  import * as React from "react";
2
+ import { DayPickerProps } from "react-day-picker";
2
3
  import { TextboxProps } from "../textbox/textbox";
3
4
 
4
- export interface DateInputProps extends TextboxProps {
5
- /** Identifier used for testing purposes, applied to the root element of the component. */
6
- "data-component"?: string;
7
- /** Identifier used for testing purposes, applied to the root element of the component. */
8
- "data-element"?: string;
9
- /** Identifier used for testing purposes, applied to the root element of the component. */
10
- "data-role"?: string;
5
+ export interface DateInputProps
6
+ extends Omit<
7
+ TextboxProps,
8
+ | "value"
9
+ | "formattedValue"
10
+ | "rawValue"
11
+ | "onChange"
12
+ | "onMouseDown"
13
+ | "onChangeDeferred"
14
+ | "deferTimeout"
15
+ | "children"
16
+ | "leftChildren"
17
+ | "placeholder"
18
+ | "iconOnClick"
19
+ | "iconOnMouseDown"
20
+ | "enforceCharacterLimit"
21
+ | "characterLimit"
22
+ | "warnOverLimit"
23
+ | "iconTabIndex"
24
+ > {
11
25
  /** Boolean to allow the input to have an empty value */
12
26
  allowEmptyValue?: boolean;
13
- /** Automatically focus on component mount */
14
- autoFocus?: boolean;
15
27
  /** Boolean to toggle where DatePicker is rendered in relation to the Date Input */
16
28
  disablePortal?: boolean;
17
29
  /** Minimum possible date YYYY-MM-DD */
18
30
  minDate?: string;
19
31
  /** Maximum possible date YYYY-MM-DD */
20
32
  maxDate?: string;
21
- /** Name of the input */
22
- name?: string;
23
- /** Specify a callback triggered on blur */
24
- onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
25
- /** Specify a callback triggered on focus */
26
- onFocus?: (ev: React.FocusEvent<HTMLInputElement>) => void;
27
- /** The current date YYYY-MM-DD */
28
- value?: string;
29
- /** Overrides the default tooltip position */
30
- tooltipPosition?: "top" | "bottom" | "left" | "right";
33
+ /** Specify a callback triggered on change */
34
+ onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;
35
+ /** The current date string */
36
+ value: string;
37
+ /** Pass any props that match the DayPickerProps interface to override default behaviors */
38
+ pickerProps?: DayPickerProps;
31
39
  }
32
40
 
33
- declare class DateInput extends React.Component<DateInputProps> {}
41
+ declare function DateInput(props: DateInputProps): JSX.Element;
34
42
 
35
43
  export default DateInput;
@@ -29,14 +29,15 @@ const StyledDateInput = _styledComponents.default.div`
29
29
  flex: none;
30
30
  width: ${({
31
31
  size
32
- }) => size ? datePickerWidth[size] : "135px"};
32
+ }) => datePickerWidth[size]};
33
33
  }
34
34
  `;
35
35
  StyledDateInput.propTypes = {
36
36
  size: _propTypes.default.oneOf(["small", "medium", "large"])
37
37
  };
38
38
  StyledDateInput.defaultProps = {
39
- theme: _base.default
39
+ theme: _base.default,
40
+ size: "medium"
40
41
  };
41
42
  var _default = StyledDateInput;
42
43
  exports.default = _default;
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "BaseDateInput", {
7
- enumerable: true,
8
- get: function () {
9
- return _date.BaseDateInput;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "default", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -16,8 +10,6 @@ Object.defineProperty(exports, "default", {
16
10
  }
17
11
  });
18
12
 
19
- var _date = _interopRequireWildcard(require("./date.component"));
20
-
21
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
13
+ var _date = _interopRequireDefault(require("./date.component"));
22
14
 
23
- 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; }
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,17 @@
1
+ import * as React from "react";
2
+
3
+ interface DateInputRefMap {
4
+ isBlurBlocked: { current: boolean };
5
+ setOpen: null | ((open: boolean) => void);
6
+ }
7
+
8
+ export interface DateRangeContextProps {
9
+ inputRefMap: {
10
+ start: DateInputRefMap;
11
+ end: DateInputRefMap;
12
+ };
13
+ setInputRefMap: (newState: DateInputRefMap) => void;
14
+ }
15
+
16
+ declare const DateRangeContext: React.Context<DateRangeContextProps>;
17
+ export default DateRangeContext;
@@ -1,7 +1,6 @@
1
1
  export default DateRange;
2
- declare function DateRange({ defaultValue, endDateProps, id, labelsInline, name, onBlur, onChange, startDateProps, tooltipPosition, validationOnLabel, value, ...rest }: {
2
+ declare function DateRange({ endDateProps, id, labelsInline, name, onBlur, onChange, startDateProps, tooltipPosition, validationOnLabel, value, ...rest }: {
3
3
  [x: string]: any;
4
- defaultValue: any;
5
4
  endDateProps?: {} | undefined;
6
5
  id: any;
7
6
  labelsInline: any;
@@ -16,10 +15,9 @@ declare function DateRange({ defaultValue, endDateProps, id, labelsInline, name,
16
15
  declare namespace DateRange {
17
16
  namespace propTypes {
18
17
  const endLabel: PropTypes.Requireable<string>;
19
- const onChange: PropTypes.Requireable<(...args: any[]) => any>;
18
+ const onChange: PropTypes.Validator<(...args: any[]) => any>;
20
19
  const onBlur: PropTypes.Requireable<(...args: any[]) => any>;
21
- const value: PropTypes.Requireable<(string | null | undefined)[]>;
22
- const defaultValue: PropTypes.Requireable<(string | null | undefined)[]>;
20
+ const value: PropTypes.Validator<(string | null | undefined)[]>;
23
21
  const startError: PropTypes.Requireable<string | boolean>;
24
22
  const startWarning: PropTypes.Requireable<string | boolean>;
25
23
  const startInfo: PropTypes.Requireable<string | boolean>;
@@ -11,17 +11,23 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _propTypes2 = _interopRequireDefault(require("@styled-system/prop-types"));
13
13
 
14
+ var _utils = require("../date/__internal__/utils");
15
+
14
16
  var _date = _interopRequireDefault(require("../date"));
15
17
 
16
- var _utils = require("../../style/utils");
18
+ var _utils2 = require("../../style/utils");
17
19
 
18
20
  var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tags/tags"));
19
21
 
20
22
  var _dateRange = _interopRequireDefault(require("./date-range.style"));
21
23
 
22
- var _date2 = _interopRequireDefault(require("../../__internal__/date"));
24
+ var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
25
+
26
+ var _useLocale = _interopRequireDefault(require("../../hooks/__internal__/useLocale"));
27
+
28
+ var _dateFormats = _interopRequireDefault(require("../date/__internal__/date-formats"));
23
29
 
24
- var _i18nContext = _interopRequireDefault(require("../../__internal__/i18n-context"));
30
+ var _dateRange2 = _interopRequireDefault(require("./date-range.context"));
25
31
 
26
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
33
 
@@ -31,10 +37,9 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
31
37
 
32
38
  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); }
33
39
 
34
- const marginPropTypes = (0, _utils.filterStyledSystemMarginProps)(_propTypes2.default.space);
40
+ const marginPropTypes = (0, _utils2.filterStyledSystemMarginProps)(_propTypes2.default.space);
35
41
 
36
42
  const DateRange = ({
37
- defaultValue,
38
43
  endDateProps = {},
39
44
  id,
40
45
  labelsInline,
@@ -47,84 +52,61 @@ const DateRange = ({
47
52
  value,
48
53
  ...rest
49
54
  }) => {
55
+ const l = (0, _useLocale.default)();
56
+ const {
57
+ dateFnsLocale
58
+ } = l.date;
50
59
  const {
51
- locale,
52
- date
53
- } = (0, _react.useContext)(_i18nContext.default);
54
- const format = date.formats.javascript();
55
- const formats = date.formats.inputs();
56
- const localeData = (0, _react.useMemo)(() => ({
57
- locale: locale(),
58
- formats,
59
60
  format
60
- }), [format, formats, locale]);
61
+ } = (0, _react.useMemo)(() => (0, _dateFormats.default)(dateFnsLocale()), [dateFnsLocale]);
61
62
  const inlineLabelWidth = 40;
63
+ const [lastChangedDate, setLastChangedDate] = (0, _react.useState)("");
64
+ const computedValue = (0, _react.useCallback)(valueString => {
65
+ if ((0, _utils.checkISOFormatAndLength)(valueString)) {
66
+ return (0, _utils.formattedValue)(format, (0, _utils.parseISODate)(valueString));
67
+ }
62
68
 
63
- const today = _date2.default.todayFormatted();
64
-
65
- const isControlled = value !== undefined;
66
- const startDateInputRef = (0, _react.useRef)();
67
- const endDateInputRef = (0, _react.useRef)();
68
- /** The startDate value */
69
-
69
+ return valueString;
70
+ }, [format]);
70
71
  const getStartDate = (0, _react.useCallback)(() => {
71
72
  const {
72
73
  value: startValue
73
74
  } = startDateProps;
74
- const computedValue = isControlled ? value : defaultValue;
75
- return startValue || computedValue ? computedValue[0] : undefined;
76
- }, [defaultValue, isControlled, startDateProps, value]);
77
- /** The endDate value */
78
-
75
+ return computedValue(startValue || value[0]);
76
+ }, [startDateProps, value, computedValue]);
79
77
  const getEndDate = (0, _react.useCallback)(() => {
80
78
  const {
81
79
  value: endValue
82
80
  } = endDateProps;
83
- const computedValue = isControlled ? value : defaultValue;
84
- return endValue || computedValue ? computedValue[1] : undefined;
85
- }, [defaultValue, isControlled, endDateProps, value]);
81
+ return computedValue(endValue || value[1]);
82
+ }, [endDateProps, value, computedValue]);
83
+ const [inputRefMap, setInputRefMap] = (0, _react.useState)({
84
+ start: {
85
+ isBlurBlocked: {
86
+ current: false
87
+ },
88
+ setOpen: null
89
+ },
90
+ end: {
91
+ isBlurBlocked: {
92
+ current: false
93
+ },
94
+ setOpen: null
95
+ }
96
+ });
97
+
98
+ function isEmptyValue(allowEmpty, inputValue) {
99
+ return allowEmpty && !inputValue.length;
100
+ }
101
+
86
102
  const [startDateValue, setStartDateValue] = (0, _react.useState)({
87
- formattedValue: _date2.default.formatDateToCurrentLocale({
88
- value: getStartDate(),
89
- ...localeData
90
- }),
91
- rawValue: _date2.default.formatValue({
92
- value: getStartDate() || (startDateProps.allowEmptyValue ? "" : today),
93
- ...localeData
94
- })
103
+ formattedValue: getStartDate(),
104
+ rawValue: isEmptyValue(startDateProps.allowEmptyValue, getStartDate()) ? "" : (0, _utils.formatToISO)(format, getStartDate())
95
105
  });
96
106
  const [endDateValue, setEndDateValue] = (0, _react.useState)({
97
- formattedValue: _date2.default.formatDateToCurrentLocale({
98
- value: getEndDate(),
99
- ...localeData
100
- }),
101
- rawValue: _date2.default.formatValue({
102
- value: getEndDate() || (endDateProps.allowEmptyValue ? "" : today),
103
- ...localeData
104
- })
107
+ formattedValue: getEndDate(),
108
+ rawValue: isEmptyValue(endDateProps.allowEmptyValue, getEndDate()) ? "" : (0, _utils.formatToISO)(format, getEndDate())
105
109
  });
106
- const updateValues = (0, _react.useCallback)(() => {
107
- setStartDateValue({
108
- formattedValue: _date2.default.formatDateToCurrentLocale({
109
- value: getStartDate(),
110
- ...localeData
111
- }),
112
- rawValue: _date2.default.formatValue({
113
- value: getStartDate() || (startDateProps.allowEmptyValue ? "" : today),
114
- ...localeData
115
- })
116
- });
117
- setEndDateValue({
118
- formattedValue: _date2.default.formatDateToCurrentLocale({
119
- value: getEndDate(),
120
- ...localeData
121
- }),
122
- rawValue: _date2.default.formatValue({
123
- value: getEndDate() || (endDateProps.allowEmptyValue ? "" : today),
124
- ...localeData
125
- })
126
- });
127
- }, [getEndDate, getStartDate, endDateProps, startDateProps, localeData, today]);
128
110
 
129
111
  function usePrevious(arg) {
130
112
  const ref = (0, _react.useRef)();
@@ -136,16 +118,28 @@ const DateRange = ({
136
118
 
137
119
  const previousValue = usePrevious(value);
138
120
  (0, _react.useEffect)(() => {
121
+ const updateValues = () => {
122
+ setStartDateValue({
123
+ formattedValue: getStartDate(),
124
+ rawValue: isEmptyValue(startDateProps.allowEmptyValue, getStartDate()) ? "" : (0, _utils.formatToISO)(format, getStartDate())
125
+ });
126
+ setEndDateValue({
127
+ formattedValue: getEndDate(),
128
+ rawValue: isEmptyValue(endDateProps.allowEmptyValue, getEndDate()) ? "" : (0, _utils.formatToISO)(format, getEndDate())
129
+ });
130
+ };
131
+
139
132
  const hasPreviousValues = previousValue === null || previousValue === void 0 ? void 0 : previousValue.length;
140
- const hasUpdated = isControlled && hasPreviousValues && (value[0] !== previousValue[0] || value[1] !== previousValue[1]);
133
+ const hasUpdated = hasPreviousValues && (value[0] !== previousValue[0] || value[1] !== previousValue[1]);
141
134
 
142
135
  if (hasUpdated) {
143
136
  updateValues();
144
137
  }
145
- }, [value, previousValue, updateValues, isControlled]);
138
+ }, [value, previousValue, endDateProps.allowEmptyValue, format, getEndDate, getStartDate, startDateProps.allowEmptyValue]);
146
139
  const buildCustomEvent = (0, _react.useCallback)((changedDate, newValue) => {
147
- const startValue = changedDate === "startDate" && newValue ? newValue : startDateValue;
148
- const endValue = changedDate === "endDate" && newValue ? newValue : endDateValue;
140
+ const startValue = changedDate === "start" && newValue ? newValue : startDateValue;
141
+ const endValue = changedDate === "end" && newValue ? newValue : endDateValue;
142
+ setLastChangedDate(changedDate);
149
143
  return {
150
144
  target: { ...(name && {
151
145
  name
@@ -159,7 +153,7 @@ const DateRange = ({
159
153
  }, [endDateValue, id, name, startDateValue]);
160
154
 
161
155
  const handleOnChange = (changedDate, ev) => {
162
- if (changedDate === "startDate") {
156
+ if (changedDate === "start") {
163
157
  setStartDateValue({ ...ev.target.value
164
158
  });
165
159
  } else {
@@ -167,98 +161,113 @@ const DateRange = ({
167
161
  });
168
162
  }
169
163
 
170
- if (onChange) {
171
- const event = buildCustomEvent(changedDate, ev.target.value);
172
- onChange(event);
173
- }
164
+ const event = buildCustomEvent(changedDate, ev.target.value);
165
+ onChange(event);
174
166
  };
175
167
 
176
168
  const startDateOnChange = ev => {
177
- handleOnChange("startDate", ev);
169
+ handleOnChange("start", ev);
178
170
  };
179
171
 
180
172
  const endDateOnChange = ev => {
181
- handleOnChange("endDate", ev);
173
+ handleOnChange("end", ev);
182
174
  };
183
175
 
184
- const isBlurBlocked = () => {
185
- var _startDateInputRef$cu, _startDateInputRef$cu2, _endDateInputRef$curr, _endDateInputRef$curr2;
186
-
187
- const startBlocked = (startDateInputRef === null || startDateInputRef === void 0 ? void 0 : (_startDateInputRef$cu = startDateInputRef.current) === null || _startDateInputRef$cu === void 0 ? void 0 : _startDateInputRef$cu.isBlurBlocked) || (startDateInputRef === null || startDateInputRef === void 0 ? void 0 : (_startDateInputRef$cu2 = startDateInputRef.current) === null || _startDateInputRef$cu2 === void 0 ? void 0 : _startDateInputRef$cu2.inputFocusedViaPicker);
188
- const endBlocked = (endDateInputRef === null || endDateInputRef === void 0 ? void 0 : (_endDateInputRef$curr = endDateInputRef.current) === null || _endDateInputRef$curr === void 0 ? void 0 : _endDateInputRef$curr.isBlurBlocked) || (endDateInputRef === null || endDateInputRef === void 0 ? void 0 : (_endDateInputRef$curr2 = endDateInputRef.current) === null || _endDateInputRef$curr2 === void 0 ? void 0 : _endDateInputRef$curr2.inputFocusedViaPicker);
189
- return startBlocked || endBlocked;
176
+ const updateInputMap = newState => {
177
+ setInputRefMap(prev => {
178
+ return { ...prev,
179
+ ...newState
180
+ };
181
+ });
190
182
  };
191
183
 
192
- const handleOnBlur = () => {
184
+ const isBlurBlocked = () => inputRefMap.start.isBlurBlocked.current || inputRefMap.end.isBlurBlocked.current;
185
+
186
+ const handleOnBlur = ev => {
193
187
  if (isBlurBlocked()) {
194
188
  return;
195
189
  }
196
190
 
197
191
  if (onBlur) {
198
- const event = buildCustomEvent();
192
+ const event = buildCustomEvent(lastChangedDate, ev.target.value);
199
193
  onBlur(event);
200
194
  }
201
195
  };
202
196
 
203
- const blockBlur = blockId => {
204
- if (blockId === "start") {
205
- startDateInputRef.current.isBlurBlocked = true;
206
- startDateInputRef.current.inputFocusedViaPicker = true;
207
- } else {
208
- endDateInputRef.current.isBlurBlocked = true;
209
- endDateInputRef.current.inputFocusedViaPicker = true;
210
- }
197
+ const closePicker = activeInput => {
198
+ inputRefMap[activeInput].setOpen(false);
199
+ inputRefMap[activeInput].isBlurBlocked.current = false;
211
200
  };
212
201
 
213
- const focusStart = () => {
214
- blockBlur("start");
215
- endDateInputRef.current.closeDatePicker();
202
+ const handleOnKeyDown = (ev, activeInput) => {
203
+ if (_events.default.isTabKey(ev) && _events.default.isShiftKey(ev)) {
204
+ if (activeInput === "start") {
205
+ inputRefMap.start.isBlurBlocked.current = false;
206
+ } else {
207
+ inputRefMap.start.isBlurBlocked.current = true;
208
+ }
209
+ } else if (_events.default.isTabKey(ev)) {
210
+ if (activeInput === "end") {
211
+ inputRefMap.end.isBlurBlocked.current = false;
212
+ } else {
213
+ inputRefMap.end.isBlurBlocked.current = true;
214
+ }
215
+ }
216
216
  };
217
217
 
218
- const focusEnd = () => {
219
- blockBlur("end");
220
- startDateInputRef.current.closeDatePicker();
218
+ const handleFocus = inputName => {
219
+ closePicker(inputName);
220
+ setLastChangedDate(inputName === "start" ? "end" : "start");
221
221
  };
222
222
 
223
223
  const dateProps = propsKey => {
224
224
  const props = propsKey === "start" ? startDateProps : endDateProps;
225
225
  const {
226
- rawValue
226
+ formattedValue: inputValue
227
227
  } = propsKey === "start" ? startDateValue : endDateValue;
228
228
  const onChangeCallback = propsKey === "start" ? startDateOnChange : endDateOnChange;
229
229
  return {
230
230
  label: rest[`${propsKey}Label`],
231
231
  labelInline: labelsInline,
232
- value: rawValue,
232
+ value: inputValue,
233
233
  error: rest[`${propsKey}Error`],
234
234
  warning: rest[`${propsKey}Warning`],
235
235
  info: rest[`${propsKey}Info`],
236
236
  validationOnLabel,
237
237
  onBlur: handleOnBlur,
238
238
  onChange: onChangeCallback,
239
+ onKeyDown: ev => handleOnKeyDown(ev, propsKey),
239
240
  ...props
240
241
  };
241
242
  };
242
243
 
243
244
  return /*#__PURE__*/_react.default.createElement(_dateRange.default, _extends({}, (0, _tags.default)("date-range", rest), {
244
245
  labelsInline: labelsInline
245
- }, (0, _utils.filterStyledSystemMarginProps)(rest)), /*#__PURE__*/_react.default.createElement(_date.default, _extends({}, dateProps("start"), {
246
- onFocus: focusStart,
246
+ }, (0, _utils2.filterStyledSystemMarginProps)(rest)), /*#__PURE__*/_react.default.createElement(_dateRange2.default.Provider, {
247
+ value: {
248
+ inputRefMap,
249
+ setInputRefMap: updateInputMap
250
+ }
251
+ }, /*#__PURE__*/_react.default.createElement(_date.default, _extends({}, dateProps("start"), {
252
+ onFocus: () => handleFocus("end"),
247
253
  "data-element": "start-date",
248
- ref: startDateInputRef,
249
254
  labelWidth: inlineLabelWidth // Textbox only applies this when labelsInLine prop is true
250
255
  ,
251
256
  tooltipPosition: tooltipPosition
252
257
  })), /*#__PURE__*/_react.default.createElement(_date.default, _extends({}, dateProps("end"), {
253
- onFocus: focusEnd,
258
+ onFocus: () => handleFocus("start"),
254
259
  "data-element": "end-date",
255
- ref: endDateInputRef,
256
260
  labelWidth: inlineLabelWidth // Textbox only applies this when labelsInLine prop is true
257
261
  ,
258
262
  tooltipPosition: tooltipPosition
259
- })));
263
+ }))));
260
264
  };
261
265
 
266
+ const dateInputPropTypes = { // eslint-disable-next-line react/forbid-foreign-prop-types
267
+ ..._date.default.propTypes,
268
+ onChange: _propTypes.default.func,
269
+ value: _propTypes.default.string
270
+ };
262
271
  DateRange.propTypes = {
263
272
  /** Filtered styled system margin props */
264
273
  ...marginPropTypes,
@@ -269,16 +278,13 @@ DateRange.propTypes = {
269
278
  endLabel: _propTypes.default.string,
270
279
 
271
280
  /** Custom callback - receives array of startDate and endDate */
272
- onChange: _propTypes.default.func,
281
+ onChange: _propTypes.default.func.isRequired,
273
282
 
274
283
  /** Custom callback - receives array of startDate and endDate */
275
284
  onBlur: _propTypes.default.func,
276
285
 
277
286
  /** An array containing the value of startDate and endDate */
278
- value: _propTypes.default.arrayOf(_propTypes.default.string),
279
-
280
- /* The default value of the input if it's meant to be used as an uncontrolled component */
281
- defaultValue: _propTypes.default.arrayOf(_propTypes.default.string),
287
+ value: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
282
288
 
283
289
  /** Indicate that error has occurred on start date
284
290
  Pass string to display icon, tooltip and red border
@@ -321,14 +327,12 @@ DateRange.propTypes = {
321
327
  /** Display labels inline */
322
328
  labelsInline: _propTypes.default.bool,
323
329
 
324
- /** Props for the child start Date component */
325
- startDateProps: _propTypes.default.shape({ ..._date.default.propTypes,
326
- value: _propTypes.default.string
330
+ /** Props for the child start Date component. For more information see the Date component's [prop table](https://carbon.sage.com/iframe.html?id=date-input--default-story&viewMode=docs#props) */
331
+ startDateProps: _propTypes.default.shape({ ...dateInputPropTypes
327
332
  }),
328
333
 
329
- /** Props for the child end Date component */
330
- endDateProps: _propTypes.default.shape({ ..._date.default.propTypes,
331
- value: _propTypes.default.string
334
+ /** Props for the child end Date component. For more information see the Date component's [prop table](https://carbon.sage.com/iframe.html?id=date-input--default-story&viewMode=docs#props) */
335
+ endDateProps: _propTypes.default.shape({ ...dateInputPropTypes
332
336
  }),
333
337
 
334
338
  /** An optional string prop to provide a name to the component */
@@ -0,0 +1,3 @@
1
+ declare var _default: React.Context<{}>;
2
+ export default _default;
3
+ import React from "react";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var _default = /*#__PURE__*/_react.default.createContext({});
13
+
14
+ exports.default = _default;
@@ -2,15 +2,15 @@ import * as React from "react";
2
2
  import { MarginProps } from "styled-system";
3
3
  import { DateInputProps } from "../date/date";
4
4
 
5
- export interface DateRangeChangeEvent {
5
+ interface DateRangeChangeEvent {
6
6
  target: {
7
7
  value: [
8
8
  {
9
- formattedValue: number;
9
+ formattedValue: string;
10
10
  rawValue: string;
11
11
  },
12
12
  {
13
- formattedValue: number;
13
+ formattedValue: string;
14
14
  rawValue: string;
15
15
  }
16
16
  ];
@@ -18,8 +18,6 @@ export interface DateRangeChangeEvent {
18
18
  }
19
19
 
20
20
  export interface DateRangeProps extends MarginProps {
21
- /* The default value of the input if it's meant to be used as an uncontrolled component */
22
- defaultValue?: string[];
23
21
  /** Props for the child end Date component */
24
22
  endDateProps?: DateInputProps;
25
23
  /** Optional label for endDate field */
@@ -49,7 +47,7 @@ export interface DateRangeProps extends MarginProps {
49
47
  /** An optional string prop to provide a name to the component */
50
48
  name?: string;
51
49
  /** Specify a callback triggered on change */
52
- onChange?: (ev: DateRangeChangeEvent) => void;
50
+ onChange: (ev: DateRangeChangeEvent) => void;
53
51
  /** Specify a callback triggered on blur */
54
52
  onBlur?: (ev: DateRangeChangeEvent) => void;
55
53
  /** Props for the child start Date component */
@@ -74,7 +72,7 @@ export interface DateRangeProps extends MarginProps {
74
72
  */
75
73
  startInfo?: boolean | string;
76
74
  /** An array containing the value of startDate and endDate */
77
- value?: string[];
75
+ value: string[];
78
76
  /** When true, validation icons will be placed on labels instead of being placed on the inputs */
79
77
  validationOnLabel?: boolean;
80
78
  /** Overrides the default tooltip position */
@@ -21,6 +21,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
21
21
 
22
22
  const StyledDateRange = _styledComponents.default.div`
23
23
  ${_styledSystem.margin}
24
+
24
25
  & ${_date.default} {
25
26
  width: auto;
26
27
  display: inline-block;
@@ -1 +1,2 @@
1
1
  export { default } from "./date-range";
2
+ export { default as DateRangeContext } from "./date-range-context";
@@ -26,10 +26,7 @@ declare namespace I18nProvider {
26
26
  yes: PropTypes.Requireable<(...args: any[]) => any>;
27
27
  }>>;
28
28
  date: PropTypes.Requireable<PropTypes.InferProps<{
29
- formats: PropTypes.Requireable<PropTypes.InferProps<{
30
- inputs: PropTypes.Requireable<(...args: any[]) => any>;
31
- javascript: PropTypes.Requireable<(...args: any[]) => any>;
32
- }>>;
29
+ dateFnsLocale: PropTypes.Requireable<(...args: any[]) => any>;
33
30
  }>>;
34
31
  errors: PropTypes.Requireable<PropTypes.InferProps<{
35
32
  messages: PropTypes.Requireable<PropTypes.InferProps<{
@@ -46,10 +46,7 @@ I18nProvider.propTypes = {
46
46
  yes: _propTypes.default.func
47
47
  }),
48
48
  date: _propTypes.default.shape({
49
- formats: _propTypes.default.shape({
50
- inputs: _propTypes.default.func,
51
- javascript: _propTypes.default.func
52
- })
49
+ dateFnsLocale: _propTypes.default.func
53
50
  }),
54
51
  errors: _propTypes.default.shape({
55
52
  messages: _propTypes.default.shape({