@carbon/react 1.3.0-rc.1 → 1.4.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 (45) hide show
  1. package/es/components/Checkbox/Checkbox.Skeleton.js +5 -3
  2. package/es/components/ComposedModal/next/ComposedModal.js +11 -11
  3. package/es/components/DatePicker/DatePicker.js +264 -334
  4. package/es/components/DatePickerInput/DatePickerInput.js +141 -168
  5. package/es/components/FileUploader/FileUploader.js +3 -3
  6. package/es/components/FileUploader/FileUploaderButton.js +4 -4
  7. package/es/components/FileUploader/FileUploaderDropContainer.js +3 -3
  8. package/es/components/FormGroup/FormGroup.js +1 -2
  9. package/es/components/IconButton/index.js +2 -2
  10. package/es/components/MultiSelect/FilterableMultiSelect.js +10 -0
  11. package/es/components/MultiSelect/next/FilterableMultiSelect.js +11 -0
  12. package/es/components/RadioButton/RadioButton.js +1 -1
  13. package/es/components/Slider/Slider.js +11 -0
  14. package/es/components/StructuredList/next/StructuredList.js +19 -3
  15. package/es/components/TabContent/TabContent.js +2 -1
  16. package/es/components/Tabs/next/Tabs.js +31 -25
  17. package/es/components/UIShell/SideNav.js +1 -1
  18. package/es/index.js +3 -3
  19. package/lib/components/Checkbox/Checkbox.Skeleton.js +5 -3
  20. package/lib/components/ComposedModal/next/ComposedModal.js +11 -11
  21. package/lib/components/DatePicker/DatePicker.js +261 -331
  22. package/lib/components/DatePickerInput/DatePickerInput.js +138 -165
  23. package/lib/components/FileUploader/FileUploader.js +3 -3
  24. package/lib/components/FileUploader/FileUploaderButton.js +4 -4
  25. package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -3
  26. package/lib/components/FormGroup/FormGroup.js +1 -2
  27. package/lib/components/IconButton/index.js +1 -1
  28. package/lib/components/MultiSelect/FilterableMultiSelect.js +10 -0
  29. package/lib/components/MultiSelect/next/FilterableMultiSelect.js +11 -0
  30. package/lib/components/RadioButton/RadioButton.js +1 -1
  31. package/lib/components/Slider/Slider.js +11 -0
  32. package/lib/components/StructuredList/next/StructuredList.js +19 -3
  33. package/lib/components/TabContent/TabContent.js +2 -1
  34. package/lib/components/Tabs/next/Tabs.js +31 -25
  35. package/lib/components/UIShell/SideNav.js +1 -1
  36. package/lib/index.js +100 -100
  37. package/package.json +4 -4
  38. package/es/components/DatePicker/index.js +0 -15
  39. package/es/components/DatePicker/next/DatePicker.js +0 -562
  40. package/es/components/DatePickerInput/index.js +0 -15
  41. package/es/components/DatePickerInput/next/DatePickerInput.js +0 -244
  42. package/lib/components/DatePicker/index.js +0 -39
  43. package/lib/components/DatePicker/next/DatePicker.js +0 -573
  44. package/lib/components/DatePickerInput/index.js +0 -39
  45. package/lib/components/DatePickerInput/next/DatePickerInput.js +0 -254
@@ -5,27 +5,24 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { inherits as _inherits, createSuper as _createSuper, classCallCheck as _classCallCheck, defineProperty as _defineProperty, assertThisInitialized as _assertThisInitialized, createClass as _createClass, objectWithoutProperties as _objectWithoutProperties, typeof as _typeof, objectSpread2 as _objectSpread2, extends as _extends, toConsumableArray as _toConsumableArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
8
+ import { objectWithoutProperties as _objectWithoutProperties, defineProperty as _defineProperty, typeof as _typeof, objectSpread2 as _objectSpread2, extends as _extends, toConsumableArray as _toConsumableArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React__default, { Component } from 'react';
10
+ import React__default, { useRef, useEffect } from 'react';
11
11
  import cx from 'classnames';
12
12
  import flatpickr from 'flatpickr';
13
13
  import l10n from '../../node_modules/flatpickr/dist/l10n/index.js';
14
- import DatePickerInput from '../DatePickerInput/index.js';
14
+ import DatePickerInput from '../DatePickerInput/DatePickerInput.js';
15
15
  import carbonFlatpickrAppendToPlugin from './plugins/appendToPlugin.js';
16
16
  import carbonFlatpickrFixEventsPlugin from './plugins/fixEventsPlugin.js';
17
17
  import carbonFlatpickrRangePlugin from './plugins/rangePlugin.js';
18
- import { FeatureFlagContext } from '../FeatureFlags/index.js';
19
- import { PrefixContext } from '../../internal/usePrefix.js';
18
+ import { usePrefix } from '../../internal/usePrefix.js';
19
+ import { useSavedCallback } from '../../internal/useSavedCallback.js';
20
20
  import { match } from '../../internal/keyboard/match.js';
21
21
  import { ArrowDown } from '../../internal/keyboard/keys.js';
22
22
 
23
- var _excluded = ["allowInput", "appendTo", "datePickerType", "dateFormat", "locale", "minDate", "maxDate", "value", "onClose", "disable", "enable"],
24
- _excluded2 = ["dateFormat", "minDate", "maxDate", "value", "disable", "enable"],
25
- _excluded3 = ["dateFormat", "minDate", "maxDate", "value", "disable", "enable"],
26
- _excluded4 = ["allowInput", "appendTo", "children", "className", "short", "light", "datePickerType", "minDate", "maxDate", "dateFormat", "onChange", "locale", "value", "onOpen"];
23
+ var _excluded = ["allowInput", "appendTo", "children", "className", "dateFormat", "datePickerType", "disable", "enable", "inline", "light", "locale", "maxDate", "minDate", "onChange", "onClose", "onOpen", "short", "value"];
27
24
 
28
- l10n.en.weekdays.shorthand.forEach(function (day, index) {
25
+ l10n.en.weekdays.shorthand.forEach(function (_day, index) {
29
26
  var currentDay = l10n.en.weekdays.shorthand;
30
27
 
31
28
  if (currentDay[index] === 'Thu' || currentDay[index] === 'Th') {
@@ -105,358 +102,295 @@ var carbonFlatpickrMonthSelectPlugin = function carbonFlatpickrMonthSelectPlugin
105
102
  };
106
103
  };
107
104
  };
105
+ /**
106
+ * Determine if every child in a list of children has no label specified
107
+ * @param {Array<ReactElement>} children
108
+ * @returns {boolean}
109
+ */
108
110
 
109
- var DatePicker = /*#__PURE__*/function (_Component) {
110
- _inherits(DatePicker, _Component);
111
111
 
112
- var _super = _createSuper(DatePicker);
112
+ function isLabelTextEmpty(children) {
113
+ return children.every(function (child) {
114
+ return !child.props.labelText;
115
+ });
116
+ }
117
+
118
+ var rightArrowHTML = "<svg width=\"16px\" height=\"16px\" viewBox=\"0 0 16 16\">\n <polygon points=\"11,8 6,13 5.3,12.3 9.6,8 5.3,3.7 6,3 \"/>\n <rect width=\"16\" height=\"16\" style=\"fill:none\" />\n</svg>";
119
+ var leftArrowHTML = "<svg width=\"16px\" height=\"16px\" viewBox=\"0 0 16 16\">\n <polygon points=\"5,8 10,3 10.7,3.7 6.4,8 10.7,12.3 10,13 \"/>\n <rect width=\"16\" height=\"16\" style=\"fill:none\" />\n</svg>";
120
+
121
+ function updateClassNames(calendar, prefix) {
122
+ var calendarContainer = calendar.calendarContainer;
123
+ var daysContainer = calendar.days;
124
+
125
+ if (calendarContainer && daysContainer) {
126
+ // calendarContainer and daysContainer are undefined if flatpickr detects a mobile device
127
+ calendarContainer.classList.add("".concat(prefix, "--date-picker__calendar"));
128
+ calendarContainer.querySelector('.flatpickr-month').classList.add("".concat(prefix, "--date-picker__month"));
129
+ calendarContainer.querySelector('.flatpickr-weekdays').classList.add("".concat(prefix, "--date-picker__weekdays"));
130
+ calendarContainer.querySelector('.flatpickr-days').classList.add("".concat(prefix, "--date-picker__days"));
131
+ forEach.call(calendarContainer.querySelectorAll('.flatpickr-weekday'), function (item) {
132
+ var currentItem = item;
133
+ currentItem.innerHTML = currentItem.innerHTML.replace(/\s+/g, '');
134
+ currentItem.classList.add("".concat(prefix, "--date-picker__weekday"));
135
+ });
136
+ forEach.call(daysContainer.querySelectorAll('.flatpickr-day'), function (item) {
137
+ item.classList.add("".concat(prefix, "--date-picker__day"));
113
138
 
114
- function DatePicker() {
115
- var _this;
139
+ if (item.classList.contains('today') && calendar.selectedDates.length > 0) {
140
+ item.classList.add('no-border');
141
+ } else if (item.classList.contains('today') && calendar.selectedDates.length === 0) {
142
+ item.classList.remove('no-border');
143
+ }
144
+ });
145
+ }
146
+ }
147
+
148
+ function DatePicker(_ref) {
149
+ var _cx;
150
+
151
+ var allowInput = _ref.allowInput,
152
+ appendTo = _ref.appendTo,
153
+ children = _ref.children,
154
+ className = _ref.className,
155
+ _ref$dateFormat = _ref.dateFormat,
156
+ dateFormat = _ref$dateFormat === void 0 ? 'm/d/Y' : _ref$dateFormat,
157
+ datePickerType = _ref.datePickerType,
158
+ disable = _ref.disable,
159
+ enable = _ref.enable,
160
+ inline = _ref.inline,
161
+ _ref$light = _ref.light,
162
+ light = _ref$light === void 0 ? false : _ref$light,
163
+ _ref$locale = _ref.locale,
164
+ locale = _ref$locale === void 0 ? 'en' : _ref$locale,
165
+ maxDate = _ref.maxDate,
166
+ minDate = _ref.minDate,
167
+ onChange = _ref.onChange,
168
+ onClose = _ref.onClose,
169
+ onOpen = _ref.onOpen,
170
+ _ref$short = _ref.short,
171
+ short = _ref$short === void 0 ? false : _ref$short,
172
+ value = _ref.value,
173
+ rest = _objectWithoutProperties(_ref, _excluded);
174
+
175
+ var prefix = usePrefix();
176
+ var startInputField = useRef(null);
177
+ var endInputField = useRef(null);
178
+ var calendarRef = useRef(null);
179
+ var savedOnChange = useSavedCallback(onChange);
180
+ var savedOnClose = useSavedCallback(onClose);
181
+ var savedOnOpen = useSavedCallback(onOpen);
182
+ var datePickerClasses = cx("".concat(prefix, "--date-picker"), (_cx = {}, _defineProperty(_cx, "".concat(prefix, "--date-picker--short"), short), _defineProperty(_cx, "".concat(prefix, "--date-picker--light"), light), _defineProperty(_cx, "".concat(prefix, "--date-picker--simple"), datePickerType === 'simple'), _defineProperty(_cx, "".concat(prefix, "--date-picker--single"), datePickerType === 'single'), _defineProperty(_cx, "".concat(prefix, "--date-picker--range"), datePickerType === 'range'), _defineProperty(_cx, "".concat(prefix, "--date-picker--nolabel"), datePickerType === 'range' && isLabelTextEmpty(children)), _cx));
183
+ var wrapperClasses = cx("".concat(prefix, "--form-item"), _defineProperty({}, className, className));
184
+ var childrenWithProps = React__default.Children.toArray(children).map(function (child, index) {
185
+ if (index === 0 && child.type === React__default.createElement(DatePickerInput, child.props).type) {
186
+ return /*#__PURE__*/React__default.cloneElement(child, {
187
+ datePickerType: datePickerType,
188
+ ref: startInputField
189
+ });
190
+ }
116
191
 
117
- _classCallCheck(this, DatePicker);
192
+ if (index === 1 && child.type === React__default.createElement(DatePickerInput, child.props).type) {
193
+ return /*#__PURE__*/React__default.cloneElement(child, {
194
+ datePickerType: datePickerType,
195
+ ref: endInputField
196
+ });
197
+ }
118
198
 
119
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
120
- args[_key] = arguments[_key];
199
+ if (index === 0) {
200
+ return /*#__PURE__*/React__default.cloneElement(child, {
201
+ ref: startInputField
202
+ });
121
203
  }
122
204
 
123
- _this = _super.call.apply(_super, [this].concat(args));
205
+ if (index === 1) {
206
+ return /*#__PURE__*/React__default.cloneElement(child, {
207
+ ref: endInputField
208
+ });
209
+ }
210
+ });
211
+ useEffect(function () {
212
+ var _flatpickr;
124
213
 
125
- _defineProperty(_assertThisInitialized(_this), "onChange", function () {
126
- var _this$cal;
214
+ if (datePickerType !== 'single' && datePickerType !== 'range') {
215
+ return;
216
+ }
127
217
 
128
- if (_this.inputField.value === '' && (_this$cal = _this.cal) !== null && _this$cal !== void 0 && _this$cal.selectedDates.length) {
129
- _this.cal.clear();
218
+ if (startInputField.current === null) {
219
+ return;
220
+ }
130
221
 
131
- _this.cal.input.focus();
132
- }
133
- });
222
+ var onHook = function onHook(_electedDates, _dateStr, instance, prefix) {
223
+ updateClassNames(instance, prefix);
224
+ }; // Logic to determine if `enable` or `disable` will be passed down. If neither
225
+ // is provided, we return the default empty disabled array, allowing all dates.
134
226
 
135
- _defineProperty(_assertThisInitialized(_this), "addRoleAttributeToDialog", function () {
136
- if (_this.inputField) {
137
- _this.cal.calendarContainer.setAttribute('role', 'region'); // IBM EAAC requires an aria-label on a role='region'
138
227
 
228
+ var enableOrDisable = enable ? 'enable' : 'disable';
229
+ var enableOrDisableArr;
139
230
 
140
- _this.cal.calendarContainer.setAttribute('aria-label', 'calendar-container');
141
- }
142
- });
231
+ if (!enable && !disable) {
232
+ enableOrDisableArr = [];
233
+ } else if (enable) {
234
+ enableOrDisableArr = enable;
235
+ } else {
236
+ enableOrDisableArr = disable;
237
+ }
143
238
 
144
- _defineProperty(_assertThisInitialized(_this), "addKeyboardEvents", function (cal) {
145
- var initArrowDownListener = function initArrowDownListener(element) {
146
- if (element) {
147
- element.addEventListener('keydown', function (e) {
148
- if (match(e, ArrowDown)) {
149
- var calendarContainer = cal.calendarContainer,
150
- fpSelectedDateElem = cal.selectedDateElem,
151
- fptodayDateElem = cal.todayDateElem;
152
- var selectedDateElem = calendarContainer.querySelector('.selected') && fpSelectedDateElem;
153
- var todayDateElem = calendarContainer.querySelector('.today') && fptodayDateElem;
154
- (selectedDateElem || todayDateElem || calendarContainer.querySelector('.flatpickr-day[tabindex]') || calendarContainer).focus();
155
- }
156
- });
157
- element.addEventListener('change', _this.onChange);
158
- }
159
- };
239
+ var localeData;
160
240
 
161
- initArrowDownListener(_this.inputField);
162
- initArrowDownListener(_this.toInputField);
163
- });
241
+ if (_typeof(locale) === 'object') {
242
+ var location = locale.locale ? locale.locale : 'en';
243
+ localeData = _objectSpread2(_objectSpread2({}, l10n[location]), locale);
244
+ } else {
245
+ localeData = l10n[locale];
246
+ }
164
247
 
165
- _defineProperty(_assertThisInitialized(_this), "updateClassNames", function (calendar) {
166
- var calendarContainer = calendar.calendarContainer;
167
- var daysContainer = calendar.days;
168
-
169
- if (calendarContainer && daysContainer) {
170
- // calendarContainer and daysContainer are undefined if flatpickr detects a mobile device
171
- calendarContainer.classList.add("".concat(_this.context, "--date-picker__calendar"));
172
- calendarContainer.querySelector('.flatpickr-month').classList.add("".concat(_this.context, "--date-picker__month"));
173
- calendarContainer.querySelector('.flatpickr-weekdays').classList.add("".concat(_this.context, "--date-picker__weekdays"));
174
- calendarContainer.querySelector('.flatpickr-days').classList.add("".concat(_this.context, "--date-picker__days"));
175
- forEach.call(calendarContainer.querySelectorAll('.flatpickr-weekday'), function (item) {
176
- var currentItem = item;
177
- currentItem.innerHTML = currentItem.innerHTML.replace(/\s+/g, '');
178
- currentItem.classList.add("".concat(_this.context, "--date-picker__weekday"));
179
- });
180
- forEach.call(daysContainer.querySelectorAll('.flatpickr-day'), function (item) {
181
- item.classList.add("".concat(_this.context, "--date-picker__day"));
182
-
183
- if (item.classList.contains('today') && calendar.selectedDates.length > 0) {
184
- item.classList.add('no-border');
185
- } else if (item.classList.contains('today') && calendar.selectedDates.length === 0) {
186
- item.classList.remove('no-border');
187
- }
188
- });
248
+ var start = startInputField.current;
249
+ var end = endInputField.current;
250
+ var calendar = new flatpickr(start, (_flatpickr = {
251
+ inline: inline !== null && inline !== void 0 ? inline : false,
252
+ disableMobile: true,
253
+ defaultDate: value,
254
+ mode: datePickerType,
255
+ allowInput: allowInput !== null && allowInput !== void 0 ? allowInput : true,
256
+ dateFormat: dateFormat,
257
+ locale: localeData
258
+ }, _defineProperty(_flatpickr, enableOrDisable, enableOrDisableArr), _defineProperty(_flatpickr, "minDate", minDate), _defineProperty(_flatpickr, "maxDate", maxDate), _defineProperty(_flatpickr, "plugins", [datePickerType === 'range' ? new carbonFlatpickrRangePlugin({
259
+ input: endInputField.current
260
+ }) : function () {}, appendTo ? carbonFlatpickrAppendToPlugin({
261
+ appendTo: appendTo
262
+ }) : function () {}, carbonFlatpickrMonthSelectPlugin({
263
+ selectorFlatpickrMonthYearContainer: '.flatpickr-current-month',
264
+ selectorFlatpickrYearContainer: '.numInputWrapper',
265
+ selectorFlatpickrCurrentMonth: '.cur-month',
266
+ classFlatpickrCurrentMonth: 'cur-month'
267
+ }), carbonFlatpickrFixEventsPlugin({
268
+ inputFrom: startInputField.current,
269
+ inputTo: endInputField.current
270
+ })]), _defineProperty(_flatpickr, "clickOpens", true), _defineProperty(_flatpickr, "nextArrow", rightArrowHTML), _defineProperty(_flatpickr, "prevArrow", leftArrowHTML), _defineProperty(_flatpickr, "onChange", function onChange() {
271
+ if (savedOnChange) {
272
+ savedOnChange.apply(void 0, arguments);
189
273
  }
190
- });
191
-
192
- _defineProperty(_assertThisInitialized(_this), "assignInputFieldRef", function (node) {
193
- _this.inputField = !node ? null : // Child is a regular DOM node, seen in tests
194
- node.nodeType === Node.ELEMENT_NODE ? node.querySelector(".".concat(_this.context, "--date-picker__input")) : // Child is a React component
195
- node.input && node.input.nodeType === Node.ELEMENT_NODE ? node.input : null;
196
- });
197
-
198
- _defineProperty(_assertThisInitialized(_this), "assignToInputFieldRef", function (node) {
199
- _this.toInputField = !node ? null : // Child is a regular DOM node, seen in tests
200
- node.nodeType === Node.ELEMENT_NODE ? node.querySelector(".".concat(_this.context, "--date-picker__input")) : // Child is a React component
201
- node.input && node.input.nodeType === Node.ELEMENT_NODE ? node.input : null;
202
- });
203
-
204
- _defineProperty(_assertThisInitialized(_this), "isLabelTextEmpty", function (children) {
205
- return children.every(function (child) {
206
- return !child.props.labelText;
207
- });
208
- });
274
+ }), _defineProperty(_flatpickr, "onClose", savedOnClose), _defineProperty(_flatpickr, "onReady", onHook), _defineProperty(_flatpickr, "onMonthChange", onHook), _defineProperty(_flatpickr, "onYearChange", onHook), _defineProperty(_flatpickr, "onOpen", function onOpen() {
275
+ onHook.apply(void 0, arguments);
276
+ savedOnOpen.apply(void 0, arguments);
277
+ }), _defineProperty(_flatpickr, "onValueUpdate", onHook), _flatpickr));
278
+ calendarRef.current = calendar;
279
+
280
+ function handleArrowDown(event) {
281
+ if (match(event, ArrowDown)) {
282
+ var calendarContainer = calendar.calendarContainer,
283
+ fpSelectedDateElem = calendar.selectedDateElem,
284
+ fptodayDateElem = calendar.todayDateElem;
285
+ var selectedDateElem = calendarContainer.querySelector('.selected') && fpSelectedDateElem;
286
+ var todayDateElem = calendarContainer.querySelector('.today') && fptodayDateElem;
287
+ (selectedDateElem || todayDateElem || calendarContainer.querySelector('.flatpickr-day[tabindex]') || calendarContainer).focus();
288
+ }
289
+ }
209
290
 
210
- return _this;
211
- }
291
+ function handleOnChange() {
292
+ if (start.value !== '') {
293
+ return;
294
+ }
212
295
 
213
- _createClass(DatePicker, [{
214
- key: "componentDidMount",
215
- value: function componentDidMount() {
216
- var _this2 = this;
217
-
218
- var _this$props = this.props,
219
- allowInput = _this$props.allowInput,
220
- appendTo = _this$props.appendTo,
221
- datePickerType = _this$props.datePickerType,
222
- dateFormat = _this$props.dateFormat,
223
- locale = _this$props.locale,
224
- minDate = _this$props.minDate,
225
- maxDate = _this$props.maxDate,
226
- value = _this$props.value,
227
- onClose = _this$props.onClose,
228
- disable = _this$props.disable,
229
- enable = _this$props.enable,
230
- rest = _objectWithoutProperties(_this$props, _excluded);
231
-
232
- if (datePickerType === 'single' || datePickerType === 'range') {
233
- var onHook = function onHook(electedDates, dateStr, instance) {
234
- _this2.updateClassNames(instance);
235
- }; // Logic to determine if `enable` or `disable` will be passed down. If neither
236
- // is provided, we return the default empty disabled array, allowing all dates.
237
-
238
-
239
- var enableOrDisable = enable ? 'enable' : 'disable';
240
- var enableOrDisableArr;
241
-
242
- if (!enable && !disable) {
243
- enableOrDisableArr = [];
244
- } else if (enable) {
245
- enableOrDisableArr = enable;
246
- } else {
247
- enableOrDisableArr = disable;
248
- }
296
+ if (!calendar.selectedDates) {
297
+ return;
298
+ }
249
299
 
250
- var localeData;
251
-
252
- if (_typeof(locale) === 'object') {
253
- var location = locale.locale ? locale.locale : 'en';
254
- localeData = _objectSpread2(_objectSpread2({}, l10n[location]), locale);
255
- } else {
256
- localeData = l10n[locale];
257
- } // inputField ref might not be set in enzyme tests
258
-
259
-
260
- if (this.inputField) {
261
- var _rest$inline, _flatpickr;
262
-
263
- this.cal = new flatpickr(this.inputField, (_flatpickr = {
264
- inline: (_rest$inline = rest.inline) !== null && _rest$inline !== void 0 ? _rest$inline : false,
265
- disableMobile: true,
266
- defaultDate: value,
267
- mode: datePickerType,
268
- allowInput: allowInput !== null && allowInput !== void 0 ? allowInput : true,
269
- dateFormat: dateFormat,
270
- locale: localeData
271
- }, _defineProperty(_flatpickr, enableOrDisable, enableOrDisableArr), _defineProperty(_flatpickr, "minDate", minDate), _defineProperty(_flatpickr, "maxDate", maxDate), _defineProperty(_flatpickr, "plugins", [datePickerType === 'range' ? new carbonFlatpickrRangePlugin({
272
- input: this.toInputField
273
- }) : function () {}, appendTo ? carbonFlatpickrAppendToPlugin({
274
- appendTo: appendTo
275
- }) : function () {}, carbonFlatpickrMonthSelectPlugin({
276
- selectorFlatpickrMonthYearContainer: '.flatpickr-current-month',
277
- selectorFlatpickrYearContainer: '.numInputWrapper',
278
- selectorFlatpickrCurrentMonth: '.cur-month',
279
- classFlatpickrCurrentMonth: 'cur-month'
280
- }), carbonFlatpickrFixEventsPlugin({
281
- inputFrom: this.inputField,
282
- inputTo: this.toInputField
283
- })]), _defineProperty(_flatpickr, "clickOpens", true), _defineProperty(_flatpickr, "nextArrow", this.rightArrowHTML()), _defineProperty(_flatpickr, "prevArrow", this.leftArrowHTML()), _defineProperty(_flatpickr, "onChange", function onChange() {
284
- var onChange = _this2.props.onChange;
285
-
286
- if (onChange) {
287
- onChange.apply(void 0, arguments);
288
- }
289
- }), _defineProperty(_flatpickr, "onClose", onClose), _defineProperty(_flatpickr, "onReady", onHook), _defineProperty(_flatpickr, "onMonthChange", onHook), _defineProperty(_flatpickr, "onYearChange", onHook), _defineProperty(_flatpickr, "onOpen", function onOpen() {
290
- var onOpen = _this2.props.onOpen;
291
- onHook.apply(void 0, arguments);
292
-
293
- if (onOpen) {
294
- onOpen.apply(void 0, arguments);
295
- }
296
- }), _defineProperty(_flatpickr, "onValueUpdate", onHook), _flatpickr));
297
- this.addKeyboardEvents(this.cal);
298
- this.addRoleAttributeToDialog();
299
- }
300
+ if (calendar.selectedDates.length === 0) {
301
+ return;
300
302
  }
303
+
304
+ calendar.clear();
305
+ calendar.input.focus();
301
306
  }
302
- }, {
303
- key: "componentDidUpdate",
304
- value: function componentDidUpdate(_ref) {
305
- var prevDateFormat = _ref.dateFormat,
306
- prevMinDate = _ref.minDate,
307
- prevMaxDate = _ref.maxDate,
308
- prevValue = _ref.value,
309
- prevDisable = _ref.disable,
310
- prevEnable = _ref.enable,
311
- prevRest = _objectWithoutProperties(_ref, _excluded2);
312
-
313
- var _this$props2 = this.props,
314
- dateFormat = _this$props2.dateFormat,
315
- minDate = _this$props2.minDate,
316
- maxDate = _this$props2.maxDate,
317
- value = _this$props2.value,
318
- disable = _this$props2.disable,
319
- enable = _this$props2.enable,
320
- rest = _objectWithoutProperties(_this$props2, _excluded3);
321
-
322
- if (this.cal) {
323
- if (prevDateFormat !== dateFormat) {
324
- this.cal.set({
325
- dateFormat: dateFormat
326
- });
327
- }
328
307
 
329
- if (prevMinDate !== minDate) {
330
- this.cal.set('minDate', minDate);
331
- }
308
+ if (start) {
309
+ start.addEventListener('keydown', handleArrowDown);
310
+ start.addEventListener('change', handleOnChange); // Flatpickr's calendar dialog is not rendered in a landmark causing an
311
+ // error with IBM Equal Access Accessibility Checker so we add an aria
312
+ // role to the container div.
332
313
 
333
- if (prevMaxDate !== maxDate) {
334
- this.cal.set('maxDate', maxDate);
335
- }
314
+ calendar.calendarContainer.setAttribute('role', 'region'); // IBM EAAC requires an aria-label on a role='region'
336
315
 
337
- if (disable !== prevDisable) {
338
- this.cal.set('disable', disable);
339
- }
340
-
341
- if (enable !== prevEnable) {
342
- this.cal.set('enable', enable);
343
- }
316
+ calendar.calendarContainer.setAttribute('aria-label', 'calendar-container');
317
+ }
344
318
 
345
- if (rest.inline && rest.inline !== (prevRest === null || prevRest === void 0 ? void 0 : prevRest.inline)) {
346
- this.cal.set('inline', rest.inline);
347
- }
348
- } // Coordinate when the given `value` prop changes. When this happens, we
349
- // should update the calendar to the new value.
319
+ if (end) {
320
+ end.addEventListener('keydown', handleArrowDown);
321
+ end.addEventListener('change', handleOnChange);
322
+ } //component did unmount equivalent
350
323
 
351
324
 
352
- if (prevValue !== value) {
353
- if (this.cal) {
354
- this.cal.setDate(this.props.value);
355
- this.updateClassNames(this.cal);
356
- } else if (this.inputField) {
357
- this.inputField.value = this.props.value;
358
- }
359
- }
360
- }
361
- }, {
362
- key: "componentWillUnmount",
363
- value: function componentWillUnmount() {
364
- if (this.cal) {
365
- this.cal.destroy();
325
+ return function () {
326
+ // Note: if the `startInputField` ref is undefined then calendar will be
327
+ // of type: Array and `destroy` will not be defined
328
+ if (calendar && calendar.destroy) {
329
+ calendar.destroy();
366
330
  }
367
331
 
368
- if (this.inputField) {
369
- this.inputField.removeEventListener('change', this.onChange);
332
+ if (start) {
333
+ start.removeEventListener('keydown', handleArrowDown);
334
+ start.removeEventListener('change', handleOnChange);
370
335
  }
371
336
 
372
- if (this.toInputField) {
373
- this.toInputField.removeEventListener('change', this.onChange);
337
+ if (end) {
338
+ end.removeEventListener('keydown', handleArrowDown);
339
+ end.removeEventListener('change', handleOnChange);
374
340
  }
341
+ };
342
+ }, [savedOnChange, savedOnClose, savedOnOpen]); //eslint-disable-line react-hooks/exhaustive-deps
343
+
344
+ useEffect(function () {
345
+ if (calendarRef.current) {
346
+ calendarRef.current.set({
347
+ dateFormat: dateFormat
348
+ });
375
349
  }
376
- }, {
377
- key: "rightArrowHTML",
378
- value: function rightArrowHTML() {
379
- return "\n <svg width=\"16px\" height=\"16px\" viewBox=\"0 0 16 16\">\n <polygon points=\"11,8 6,13 5.3,12.3 9.6,8 5.3,3.7 6,3 \"/>\n <rect width=\"16\" height=\"16\" style=\"fill:none\" />\n </svg>";
350
+ }, [dateFormat]);
351
+ useEffect(function () {
352
+ if (calendarRef.current && minDate) {
353
+ calendarRef.current.set('minDate', minDate);
380
354
  }
381
- }, {
382
- key: "leftArrowHTML",
383
- value: function leftArrowHTML() {
384
- return "\n <svg width=\"16px\" height=\"16px\" viewBox=\"0 0 16 16\">\n <polygon points=\"5,8 10,3 10.7,3.7 6.4,8 10.7,12.3 10,13 \"/>\n <rect width=\"16\" height=\"16\" style=\"fill:none\" />\n </svg>";
355
+ }, [minDate]);
356
+ useEffect(function () {
357
+ if (calendarRef.current && maxDate) {
358
+ calendarRef.current.set('maxDate', maxDate);
385
359
  }
386
- }, {
387
- key: "render",
388
- value: function render() {
389
- var _this3 = this;
390
-
391
- return /*#__PURE__*/React__default.createElement(FeatureFlagContext.Consumer, null, function (scope) {
392
- var _classNames;
393
-
394
- var _this3$props = _this3.props;
395
- _this3$props.allowInput;
396
- _this3$props.appendTo;
397
- var children = _this3$props.children,
398
- className = _this3$props.className,
399
- short = _this3$props.short,
400
- light = _this3$props.light,
401
- datePickerType = _this3$props.datePickerType;
402
- _this3$props.minDate;
403
- _this3$props.maxDate;
404
- _this3$props.dateFormat;
405
- _this3$props.onChange;
406
- _this3$props.locale;
407
- _this3$props.value;
408
- _this3$props.onOpen;
409
- var other = _objectWithoutProperties(_this3$props, _excluded4);
410
-
411
- var enabled;
412
-
413
- if (scope.enabled) {
414
- enabled = scope.enabled('enable-v11-release');
415
- }
416
-
417
- var datePickerClasses = cx("".concat(_this3.context, "--date-picker"), [enabled ? null : className], (_classNames = {}, _defineProperty(_classNames, "".concat(_this3.context, "--date-picker--short"), short), _defineProperty(_classNames, "".concat(_this3.context, "--date-picker--light"), light), _defineProperty(_classNames, "".concat(_this3.context, "--date-picker--simple"), datePickerType === 'simple'), _defineProperty(_classNames, "".concat(_this3.context, "--date-picker--single"), datePickerType === 'single'), _defineProperty(_classNames, "".concat(_this3.context, "--date-picker--range"), datePickerType === 'range'), _defineProperty(_classNames, "".concat(_this3.context, "--date-picker--nolabel"), datePickerType === 'range' && _this3.isLabelTextEmpty(children)), _classNames));
418
- var wrapperClasses = cx("".concat(_this3.context, "--form-item"), [enabled ? className : null]);
419
- var childArray = React__default.Children.toArray(children);
420
- var childrenWithProps = childArray.map(function (child, index) {
421
- if (index === 0 && child.type === React__default.createElement(DatePickerInput, child.props).type) {
422
- return /*#__PURE__*/React__default.cloneElement(child, {
423
- datePickerType: datePickerType,
424
- ref: _this3.assignInputFieldRef
425
- });
426
- }
427
-
428
- if (index === 1 && child.type === React__default.createElement(DatePickerInput, child.props).type) {
429
- return /*#__PURE__*/React__default.cloneElement(child, {
430
- datePickerType: datePickerType,
431
- ref: _this3.assignToInputFieldRef
432
- });
433
- }
434
-
435
- if (index === 0) {
436
- return /*#__PURE__*/React__default.cloneElement(child, {
437
- ref: _this3.assignInputFieldRef
438
- });
439
- }
440
-
441
- if (index === 1) {
442
- return /*#__PURE__*/React__default.cloneElement(child, {
443
- ref: _this3.assignToInputFieldRef
444
- });
445
- }
446
- });
447
- return /*#__PURE__*/React__default.createElement("div", {
448
- className: wrapperClasses
449
- }, /*#__PURE__*/React__default.createElement("div", _extends({
450
- className: datePickerClasses
451
- }, other), childrenWithProps));
360
+ }, [maxDate]);
361
+ useEffect(function () {
362
+ if (calendarRef.current && disable) {
363
+ calendarRef.current.set('disbale', disable);
364
+ }
365
+ }, [disable]);
366
+ useEffect(function () {
367
+ if (calendarRef.current && enable) {
368
+ calendarRef.current.set('enable', enable);
369
+ }
370
+ }, [enable]);
371
+ useEffect(function () {
372
+ if (calendarRef.current && inline) {
373
+ calendarRef.current.set('inline', inline);
374
+ }
375
+ }, [inline]);
376
+ useEffect(function () {
377
+ if (calendarRef.current) {
378
+ calendarRef.current.set({
379
+ value: value
452
380
  });
381
+ updateClassNames(calendarRef.current, prefix); //for simple date picker w/o calendar; initial mount may not have value
382
+ } else if (!calendarRef.current && value) {
383
+ startInputField.current.value = value;
453
384
  }
454
- }]);
455
-
456
- return DatePicker;
457
- }(Component);
458
-
459
- _defineProperty(DatePicker, "propTypes", {
385
+ }, [value, prefix]);
386
+ return /*#__PURE__*/React__default.createElement("div", _extends({
387
+ className: wrapperClasses
388
+ }, rest), /*#__PURE__*/React__default.createElement("div", {
389
+ className: datePickerClasses
390
+ }, childrenWithProps));
391
+ }
392
+
393
+ DatePicker.propTypes = {
460
394
  /**
461
395
  * flatpickr prop passthrough. Allows the user to enter a date directly
462
396
  * into the input field
@@ -502,6 +436,11 @@ _defineProperty(DatePicker, "propTypes", {
502
436
  */
503
437
  enable: PropTypes.array,
504
438
 
439
+ /**
440
+ * The flatpickr `inline` option.
441
+ */
442
+ inline: PropTypes.bool,
443
+
505
444
  /**
506
445
  * `true` to use the light version.
507
446
  */
@@ -608,15 +547,6 @@ _defineProperty(DatePicker, "propTypes", {
608
547
  * be a date, a date number, a date string, an array of dates.
609
548
  */
610
549
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.object])), PropTypes.object, PropTypes.number])
611
- });
612
-
613
- _defineProperty(DatePicker, "defaultProps", {
614
- short: false,
615
- light: false,
616
- dateFormat: 'm/d/Y',
617
- locale: 'en'
618
- });
619
-
620
- _defineProperty(DatePicker, "contextType", PrefixContext);
550
+ };
621
551
 
622
552
  export { DatePicker as default };