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