baseui 0.0.0-next-6acb60a → 0.0.0-next-5f5cc24

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.
@@ -47,18 +47,6 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
47
47
 
48
48
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
49
49
 
50
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
51
-
52
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
53
-
54
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
55
-
56
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
57
-
58
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
59
-
60
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
61
-
62
50
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
63
51
 
64
52
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -81,8 +69,44 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
81
69
 
82
70
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
83
71
 
72
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
73
+
74
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
75
+
76
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
77
+
78
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
79
+
80
+ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
81
+
82
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
83
+
84
84
  var DEFAULT_DATE_FORMAT = 'yyyy/MM/dd';
85
85
  exports.DEFAULT_DATE_FORMAT = DEFAULT_DATE_FORMAT;
86
+ var INPUT_DELIMITER = ' – ';
87
+
88
+ var combineSeparatedInputs = function combineSeparatedInputs(newInputValue) {
89
+ var prevCombinedInputValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
90
+ var separatedInput = arguments.length > 2 ? arguments[2] : undefined;
91
+ var inputValue = newInputValue;
92
+
93
+ var _prevCombinedInputVal = prevCombinedInputValue.split(INPUT_DELIMITER),
94
+ _prevCombinedInputVal2 = _slicedToArray(_prevCombinedInputVal, 2),
95
+ _prevCombinedInputVal3 = _prevCombinedInputVal2[0],
96
+ prevStartDate = _prevCombinedInputVal3 === void 0 ? '' : _prevCombinedInputVal3,
97
+ _prevCombinedInputVal4 = _prevCombinedInputVal2[1],
98
+ prevEndDate = _prevCombinedInputVal4 === void 0 ? '' : _prevCombinedInputVal4;
99
+
100
+ if (separatedInput === 'startDate' && prevEndDate) {
101
+ inputValue = "".concat(inputValue, " \u2013 ").concat(prevEndDate);
102
+ }
103
+
104
+ if (separatedInput === 'endDate') {
105
+ inputValue = "".concat(prevStartDate, " \u2013 ").concat(inputValue);
106
+ }
107
+
108
+ return inputValue;
109
+ };
86
110
 
87
111
  var Datepicker = /*#__PURE__*/function (_React$Component) {
88
112
  _inherits(Datepicker, _React$Component);
@@ -246,7 +270,8 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
246
270
  var _this$props2 = _this.props,
247
271
  formatString = _this$props2.formatString,
248
272
  mask = _this$props2.mask,
249
- range = _this$props2.range;
273
+ range = _this$props2.range,
274
+ separateRangeInputs = _this$props2.separateRangeInputs;
250
275
 
251
276
  if (mask === null) {
252
277
  return null;
@@ -258,7 +283,7 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
258
283
 
259
284
  var normalizedFormatString = _this.normalizeDashes(formatString);
260
285
 
261
- if (formatString) {
286
+ if (formatString && !separateRangeInputs) {
262
287
  if (range) {
263
288
  return "".concat(normalizedFormatString, " \u2013 ").concat(normalizedFormatString).replace(/[a-z]/gi, '9');
264
289
  } else {
@@ -266,15 +291,15 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
266
291
  }
267
292
  }
268
293
 
269
- if (range) {
294
+ if (range && !separateRangeInputs) {
270
295
  return '9999/99/99 – 9999/99/99';
271
296
  }
272
297
 
273
298
  return '9999/99/99';
274
299
  });
275
300
 
276
- _defineProperty(_assertThisInitialized(_this), "handleInputChange", function (event) {
277
- var inputValue = event.currentTarget.value;
301
+ _defineProperty(_assertThisInitialized(_this), "handleInputChange", function (event, separatedInput) {
302
+ var inputValue = _this.props.range && _this.props.separateRangeInputs ? combineSeparatedInputs(event.currentTarget.value, _this.state.inputValue, separatedInput) : event.currentTarget.value;
278
303
 
279
304
  var mask = _this.getMask();
280
305
 
@@ -307,7 +332,7 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
307
332
  };
308
333
 
309
334
  if (_this.props.range && typeof _this.props.displayValueAtRangeIndex !== 'number') {
310
- var _this$normalizeDashes = _this.normalizeDashes(inputValue).split(' – '),
335
+ var _this$normalizeDashes = _this.normalizeDashes(inputValue).split(INPUT_DELIMITER),
311
336
  _this$normalizeDashes2 = _slicedToArray(_this$normalizeDashes, 2),
312
337
  left = _this$normalizeDashes2[0],
313
338
  right = _this$normalizeDashes2[1];
@@ -473,7 +498,7 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
473
498
  } else if (Array.isArray(date)) {
474
499
  return date.map(function (day) {
475
500
  return format(day);
476
- }).join(' – ');
501
+ }).join(INPUT_DELIMITER);
477
502
  } else {
478
503
  return format(date);
479
504
  }
@@ -488,8 +513,8 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
488
513
  }
489
514
  }
490
515
  }, {
491
- key: "render",
492
- value: function render() {
516
+ key: "renderInputComponent",
517
+ value: function renderInputComponent(locale, separatedInput) {
493
518
  var _this3 = this;
494
519
 
495
520
  var _this$props$overrides = this.props.overrides,
@@ -500,6 +525,55 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
500
525
  InputComponent = _getOverrides2[0],
501
526
  inputProps = _getOverrides2[1];
502
527
 
528
+ var placeholder = this.props.placeholder || this.props.placeholder === '' ? this.props.placeholder : this.props.range && !this.props.separateRangeInputs ? 'YYYY/MM/DD – YYYY/MM/DD' : 'YYYY/MM/DD';
529
+
530
+ var _split = (this.state.inputValue || '').split(INPUT_DELIMITER),
531
+ _split2 = _slicedToArray(_split, 2),
532
+ _split2$ = _split2[0],
533
+ startDate = _split2$ === void 0 ? '' : _split2$,
534
+ _split2$2 = _split2[1],
535
+ endDate = _split2$2 === void 0 ? '' : _split2$2;
536
+
537
+ var value = separatedInput === 'startDate' ? startDate : separatedInput === 'endDate' ? endDate : this.state.inputValue;
538
+
539
+ var onChange = function onChange(event) {
540
+ return _this3.handleInputChange(event, separatedInput);
541
+ };
542
+
543
+ return /*#__PURE__*/React.createElement(InputComponent, _extends({
544
+ "aria-disabled": this.props.disabled,
545
+ "aria-label": this.props['aria-label'] || (this.props.range ? locale.datepicker.ariaLabelRange : locale.datepicker.ariaLabel),
546
+ error: this.props.error,
547
+ positive: this.props.positive,
548
+ "aria-describedby": this.props['aria-describedby'],
549
+ "aria-labelledby": this.props['aria-labelledby'],
550
+ "aria-required": this.props.required || null,
551
+ disabled: this.props.disabled,
552
+ size: this.props.size,
553
+ value: value,
554
+ onFocus: this.open,
555
+ onBlur: this.handleInputBlur,
556
+ onKeyDown: this.handleKeyDown,
557
+ onChange: onChange,
558
+ placeholder: placeholder,
559
+ mask: this.getMask(),
560
+ required: this.props.required,
561
+ clearable: this.props.clearable
562
+ }, inputProps));
563
+ }
564
+ }, {
565
+ key: "render",
566
+ value: function render() {
567
+ var _this4 = this;
568
+
569
+ var _this$props4 = this.props,
570
+ _this$props4$override = _this$props4.overrides,
571
+ overrides = _this$props4$override === void 0 ? {} : _this$props4$override,
572
+ _this$props4$startDat = _this$props4.startDateLabel,
573
+ startDateLabel = _this$props4$startDat === void 0 ? 'Start Date' : _this$props4$startDat,
574
+ _this$props4$endDateL = _this$props4.endDateLabel,
575
+ endDateLabel = _this$props4$endDateL === void 0 ? 'End Date' : _this$props4$endDateL;
576
+
503
577
  var _getOverrides3 = (0, _overrides.getOverrides)(overrides.Popover, _index2.Popover),
504
578
  _getOverrides4 = _slicedToArray(_getOverrides3, 2),
505
579
  PopoverComponent = _getOverrides4[0],
@@ -510,44 +584,41 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
510
584
  InputWrapper = _getOverrides6[0],
511
585
  inputWrapperProps = _getOverrides6[1];
512
586
 
513
- var placeholder = this.props.placeholder || this.props.placeholder === '' ? this.props.placeholder : this.props.range ? 'YYYY/MM/DD – YYYY/MM/DD' : 'YYYY/MM/DD';
587
+ var _getOverrides7 = (0, _overrides.getOverrides)(overrides.StartDate, _styledComponents.StyledStartDate),
588
+ _getOverrides8 = _slicedToArray(_getOverrides7, 2),
589
+ StartDate = _getOverrides8[0],
590
+ startDateProps = _getOverrides8[1];
591
+
592
+ var _getOverrides9 = (0, _overrides.getOverrides)(overrides.EndDate, _styledComponents.StyledEndDate),
593
+ _getOverrides10 = _slicedToArray(_getOverrides9, 2),
594
+ EndDate = _getOverrides10[0],
595
+ endDateProps = _getOverrides10[1];
596
+
597
+ var _getOverrides11 = (0, _overrides.getOverrides)(overrides.InputLabel, _styledComponents.StyledInputLabel),
598
+ _getOverrides12 = _slicedToArray(_getOverrides11, 2),
599
+ InputLabel = _getOverrides12[0],
600
+ inputLabelProps = _getOverrides12[1];
601
+
514
602
  return /*#__PURE__*/React.createElement(_index3.LocaleContext.Consumer, null, function (locale) {
515
603
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PopoverComponent, _extends({
516
604
  focusLock: false,
517
- mountNode: _this3.props.mountNode,
605
+ mountNode: _this4.props.mountNode,
518
606
  placement: _index2.PLACEMENT.bottom,
519
- isOpen: _this3.state.isOpen,
520
- onClickOutside: _this3.close,
521
- onEsc: _this3.handleEsc,
607
+ isOpen: _this4.state.isOpen,
608
+ onClickOutside: _this4.close,
609
+ onEsc: _this4.handleEsc,
522
610
  content: /*#__PURE__*/React.createElement(_calendar.default, _extends({
523
- adapter: _this3.props.adapter,
524
- autoFocusCalendar: _this3.state.calendarFocused,
611
+ adapter: _this4.props.adapter,
612
+ autoFocusCalendar: _this4.state.calendarFocused,
525
613
  trapTabbing: true,
526
- value: _this3.props.value
527
- }, _this3.props, {
528
- onChange: _this3.onChange
614
+ value: _this4.props.value
615
+ }, _this4.props, {
616
+ onChange: _this4.onChange
529
617
  }))
530
- }, popoverProps), /*#__PURE__*/React.createElement(InputWrapper, inputWrapperProps, /*#__PURE__*/React.createElement(InputComponent, _extends({
531
- "aria-disabled": _this3.props.disabled,
532
- "aria-label": _this3.props['aria-label'] || (_this3.props.range ? locale.datepicker.ariaLabelRange : locale.datepicker.ariaLabel),
533
- error: _this3.props.error,
534
- positive: _this3.props.positive,
535
- "aria-describedby": _this3.props['aria-describedby'],
536
- "aria-labelledby": _this3.props['aria-labelledby'],
537
- "aria-required": _this3.props.required || null,
538
- disabled: _this3.props.disabled,
539
- size: _this3.props.size,
540
- value: _this3.state.inputValue,
541
- onFocus: _this3.open,
542
- onBlur: _this3.handleInputBlur,
543
- onKeyDown: _this3.handleKeyDown,
544
- onChange: _this3.handleInputChange,
545
- placeholder: placeholder,
546
- mask: _this3.getMask(),
547
- required: _this3.props.required,
548
- clearable: _this3.props.clearable
549
- }, inputProps)))), /*#__PURE__*/React.createElement("p", {
550
- id: _this3.props['aria-describedby'],
618
+ }, popoverProps), /*#__PURE__*/React.createElement(InputWrapper, _extends({}, inputWrapperProps, {
619
+ $separateRangeInputs: _this4.props.range && _this4.props.separateRangeInputs
620
+ }), _this4.props.range && _this4.props.separateRangeInputs ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StartDate, startDateProps, /*#__PURE__*/React.createElement(InputLabel, inputLabelProps, startDateLabel), _this4.renderInputComponent(locale, 'startDate')), /*#__PURE__*/React.createElement(EndDate, endDateProps, /*#__PURE__*/React.createElement(InputLabel, inputLabelProps, endDateLabel), _this4.renderInputComponent(locale, 'endDate'))) : /*#__PURE__*/React.createElement(React.Fragment, null, _this4.renderInputComponent(locale)))), /*#__PURE__*/React.createElement("p", {
621
+ id: _this4.props['aria-describedby'],
551
622
  style: {
552
623
  position: 'fixed',
553
624
  width: '0px',
@@ -577,17 +648,17 @@ var Datepicker = /*#__PURE__*/function (_React$Component) {
577
648
  clipPath: 'inset(100%)'
578
649
  }
579
650
  }, // No date selected
580
- !_this3.props.value || Array.isArray(_this3.props.value) && !_this3.props.value.length ? '' : // Date selected in a non-range picker
581
- !Array.isArray(_this3.props.value) ? (0, _i18nInterpolation.default)(locale.datepicker.selectedDate, {
582
- date: _this3.state.inputValue || ''
651
+ !_this4.props.value || Array.isArray(_this4.props.value) && !_this4.props.value.length ? '' : // Date selected in a non-range picker
652
+ !Array.isArray(_this4.props.value) ? (0, _i18nInterpolation.default)(locale.datepicker.selectedDate, {
653
+ date: _this4.state.inputValue || ''
583
654
  }) : // Start and end dates are selected in a range picker
584
- _this3.props.value.length > 1 ? (0, _i18nInterpolation.default)(locale.datepicker.selectedDateRange, {
585
- startDate: _this3.formatDisplayValue(_this3.props.value[0]),
586
- endDate: _this3.formatDisplayValue( // $FlowFixMe
587
- _this3.props.value[1])
655
+ _this4.props.value.length > 1 ? (0, _i18nInterpolation.default)(locale.datepicker.selectedDateRange, {
656
+ startDate: _this4.formatDisplayValue(_this4.props.value[0]),
657
+ endDate: _this4.formatDisplayValue( // $FlowFixMe
658
+ _this4.props.value[1])
588
659
  }) : // A single date selected in a range picker
589
660
  "".concat((0, _i18nInterpolation.default)(locale.datepicker.selectedDate, {
590
- date: _this3.formatDisplayValue(_this3.props.value[0])
661
+ date: _this4.formatDisplayValue(_this4.props.value[0])
591
662
  }), " ").concat(locale.datepicker.selectSecondDatePrompt)));
592
663
  });
593
664
  }
@@ -13,10 +13,38 @@ import Calendar from './calendar.js';
13
13
  import {getOverrides} from '../helpers/overrides.js';
14
14
  import getInterpolatedString from '../helpers/i18n-interpolation.js';
15
15
  import {LocaleContext} from '../locale/index.js';
16
- import {StyledInputWrapper} from './styled-components.js';
16
+ import {
17
+ StyledInputWrapper,
18
+ StyledInputLabel,
19
+ StyledStartDate,
20
+ StyledEndDate,
21
+ } from './styled-components.js';
17
22
  import type {DatepickerPropsT} from './types.js';
18
23
  import DateHelpers from './utils/date-helpers.js';
19
24
  import dateFnsAdapter from './utils/date-fns-adapter.js';
25
+ import type {LocaleT} from '../locale/types.js';
26
+
27
+ export const DEFAULT_DATE_FORMAT = 'yyyy/MM/dd';
28
+
29
+ const INPUT_DELIMITER = ' – ';
30
+
31
+ const combineSeparatedInputs = (
32
+ newInputValue,
33
+ prevCombinedInputValue = '',
34
+ separatedInput,
35
+ ) => {
36
+ let inputValue = newInputValue;
37
+ const [prevStartDate = '', prevEndDate = ''] = prevCombinedInputValue.split(
38
+ INPUT_DELIMITER,
39
+ );
40
+ if (separatedInput === 'startDate' && prevEndDate) {
41
+ inputValue = `${inputValue} – ${prevEndDate}`;
42
+ }
43
+ if (separatedInput === 'endDate') {
44
+ inputValue = `${prevStartDate} – ${inputValue}`;
45
+ }
46
+ return inputValue;
47
+ };
20
48
 
21
49
  type StateT = {|
22
50
  calendarFocused: boolean,
@@ -25,7 +53,6 @@ type StateT = {|
25
53
  lastActiveElm: ?HTMLElement,
26
54
  inputValue?: string,
27
55
  |};
28
- export const DEFAULT_DATE_FORMAT = 'yyyy/MM/dd';
29
56
 
30
57
  export default class Datepicker<T = Date> extends React.Component<
31
58
  DatepickerPropsT<T>,
@@ -128,7 +155,7 @@ export default class Datepicker<T = Date> extends React.Component<
128
155
  } else if (Array.isArray(date) && !date[0] && !date[1]) {
129
156
  return '';
130
157
  } else if (Array.isArray(date)) {
131
- return date.map(day => format(day)).join(' – ');
158
+ return date.map(day => format(day)).join(INPUT_DELIMITER);
132
159
  } else {
133
160
  return format(date);
134
161
  }
@@ -197,7 +224,7 @@ export default class Datepicker<T = Date> extends React.Component<
197
224
  };
198
225
 
199
226
  getMask = () => {
200
- const {formatString, mask, range} = this.props;
227
+ const {formatString, mask, range, separateRangeInputs} = this.props;
201
228
 
202
229
  if (mask === null) {
203
230
  return null;
@@ -208,7 +235,7 @@ export default class Datepicker<T = Date> extends React.Component<
208
235
  }
209
236
 
210
237
  const normalizedFormatString = this.normalizeDashes(formatString);
211
- if (formatString) {
238
+ if (formatString && !separateRangeInputs) {
212
239
  if (range) {
213
240
  return `${normalizedFormatString} – ${normalizedFormatString}`.replace(
214
241
  /[a-z]/gi,
@@ -219,15 +246,26 @@ export default class Datepicker<T = Date> extends React.Component<
219
246
  }
220
247
  }
221
248
 
222
- if (range) {
249
+ if (range && !separateRangeInputs) {
223
250
  return '9999/99/99 – 9999/99/99';
224
251
  }
225
252
 
226
253
  return '9999/99/99';
227
254
  };
228
255
 
229
- handleInputChange = (event: SyntheticInputEvent<HTMLInputElement>) => {
230
- const inputValue = event.currentTarget.value;
256
+ handleInputChange = (
257
+ event: SyntheticInputEvent<HTMLInputElement>,
258
+ separatedInput?: 'startDate' | 'endDate',
259
+ ) => {
260
+ const inputValue =
261
+ this.props.range && this.props.separateRangeInputs
262
+ ? combineSeparatedInputs(
263
+ event.currentTarget.value,
264
+ this.state.inputValue,
265
+ separatedInput,
266
+ )
267
+ : event.currentTarget.value;
268
+
231
269
  const mask = this.getMask();
232
270
 
233
271
  if (
@@ -265,7 +303,9 @@ export default class Datepicker<T = Date> extends React.Component<
265
303
  this.props.range &&
266
304
  typeof this.props.displayValueAtRangeIndex !== 'number'
267
305
  ) {
268
- const [left, right] = this.normalizeDashes(inputValue).split(' – ');
306
+ const [left, right] = this.normalizeDashes(inputValue).split(
307
+ INPUT_DELIMITER,
308
+ );
269
309
 
270
310
  let startDate = this.dateHelpers.date(left);
271
311
  let endDate = this.dateHelpers.date(right);
@@ -391,12 +431,73 @@ export default class Datepicker<T = Date> extends React.Component<
391
431
  }
392
432
  }
393
433
 
394
- render() {
434
+ renderInputComponent(
435
+ locale: LocaleT,
436
+ separatedInput?: 'startDate' | 'endDate',
437
+ ) {
395
438
  const {overrides = {}} = this.props;
439
+
396
440
  const [InputComponent, inputProps] = getOverrides(
397
441
  overrides.Input,
398
442
  MaskedInput,
399
443
  );
444
+
445
+ const placeholder =
446
+ this.props.placeholder || this.props.placeholder === ''
447
+ ? this.props.placeholder
448
+ : this.props.range && !this.props.separateRangeInputs
449
+ ? 'YYYY/MM/DD – YYYY/MM/DD'
450
+ : 'YYYY/MM/DD';
451
+
452
+ const [startDate = '', endDate = ''] = (this.state.inputValue || '').split(
453
+ INPUT_DELIMITER,
454
+ );
455
+
456
+ const value =
457
+ separatedInput === 'startDate'
458
+ ? startDate
459
+ : separatedInput === 'endDate'
460
+ ? endDate
461
+ : this.state.inputValue;
462
+
463
+ const onChange = event => this.handleInputChange(event, separatedInput);
464
+
465
+ return (
466
+ <InputComponent
467
+ aria-disabled={this.props.disabled}
468
+ aria-label={
469
+ this.props['aria-label'] ||
470
+ (this.props.range
471
+ ? locale.datepicker.ariaLabelRange
472
+ : locale.datepicker.ariaLabel)
473
+ }
474
+ error={this.props.error}
475
+ positive={this.props.positive}
476
+ aria-describedby={this.props['aria-describedby']}
477
+ aria-labelledby={this.props['aria-labelledby']}
478
+ aria-required={this.props.required || null}
479
+ disabled={this.props.disabled}
480
+ size={this.props.size}
481
+ value={value}
482
+ onFocus={this.open}
483
+ onBlur={this.handleInputBlur}
484
+ onKeyDown={this.handleKeyDown}
485
+ onChange={onChange}
486
+ placeholder={placeholder}
487
+ mask={this.getMask()}
488
+ required={this.props.required}
489
+ clearable={this.props.clearable}
490
+ {...inputProps}
491
+ />
492
+ );
493
+ }
494
+
495
+ render() {
496
+ const {
497
+ overrides = {},
498
+ startDateLabel = 'Start Date',
499
+ endDateLabel = 'End Date',
500
+ } = this.props;
400
501
  const [PopoverComponent, popoverProps] = getOverrides(
401
502
  overrides.Popover,
402
503
  Popover,
@@ -405,13 +506,18 @@ export default class Datepicker<T = Date> extends React.Component<
405
506
  overrides.InputWrapper,
406
507
  StyledInputWrapper,
407
508
  );
408
-
409
- const placeholder =
410
- this.props.placeholder || this.props.placeholder === ''
411
- ? this.props.placeholder
412
- : this.props.range
413
- ? 'YYYY/MM/DD – YYYY/MM/DD'
414
- : 'YYYY/MM/DD';
509
+ const [StartDate, startDateProps] = getOverrides(
510
+ overrides.StartDate,
511
+ StyledStartDate,
512
+ );
513
+ const [EndDate, endDateProps] = getOverrides(
514
+ overrides.EndDate,
515
+ StyledEndDate,
516
+ );
517
+ const [InputLabel, inputLabelProps] = getOverrides(
518
+ overrides.InputLabel,
519
+ StyledInputLabel,
520
+ );
415
521
 
416
522
  return (
417
523
  <LocaleContext.Consumer>
@@ -436,33 +542,31 @@ export default class Datepicker<T = Date> extends React.Component<
436
542
  }
437
543
  {...popoverProps}
438
544
  >
439
- <InputWrapper {...inputWrapperProps}>
440
- <InputComponent
441
- aria-disabled={this.props.disabled}
442
- aria-label={
443
- this.props['aria-label'] ||
444
- (this.props.range
445
- ? locale.datepicker.ariaLabelRange
446
- : locale.datepicker.ariaLabel)
447
- }
448
- error={this.props.error}
449
- positive={this.props.positive}
450
- aria-describedby={this.props['aria-describedby']}
451
- aria-labelledby={this.props['aria-labelledby']}
452
- aria-required={this.props.required || null}
453
- disabled={this.props.disabled}
454
- size={this.props.size}
455
- value={this.state.inputValue}
456
- onFocus={this.open}
457
- onBlur={this.handleInputBlur}
458
- onKeyDown={this.handleKeyDown}
459
- onChange={this.handleInputChange}
460
- placeholder={placeholder}
461
- mask={this.getMask()}
462
- required={this.props.required}
463
- clearable={this.props.clearable}
464
- {...inputProps}
465
- />
545
+ {}
546
+ <InputWrapper
547
+ {...inputWrapperProps}
548
+ $separateRangeInputs={
549
+ this.props.range && this.props.separateRangeInputs
550
+ }
551
+ >
552
+ {this.props.range && this.props.separateRangeInputs ? (
553
+ <>
554
+ <StartDate {...startDateProps}>
555
+ <InputLabel {...inputLabelProps}>
556
+ {startDateLabel}
557
+ </InputLabel>
558
+ {this.renderInputComponent(locale, 'startDate')}
559
+ </StartDate>
560
+ <EndDate {...endDateProps}>
561
+ <InputLabel {...inputLabelProps}>
562
+ {endDateLabel}
563
+ </InputLabel>
564
+ {this.renderInputComponent(locale, 'endDate')}
565
+ </EndDate>
566
+ </>
567
+ ) : (
568
+ <>{this.renderInputComponent(locale)}</>
569
+ )}
466
570
  </InputWrapper>
467
571
  </PopoverComponent>
468
572
  <p
@@ -148,6 +148,9 @@ export interface DatepickerOverrides<T> {
148
148
  Input?: Override<T>;
149
149
  InputWrapper?: Override<T>;
150
150
  Popover?: Override<T>;
151
+ StartDate?: Override<T>;
152
+ EndDate?: Override<T>;
153
+ InputLabel?: Override<T>;
151
154
  }
152
155
  export type DatepickerProps = CalendarProps & {
153
156
  'aria-label'?: string;
@@ -166,6 +169,9 @@ export type DatepickerProps = CalendarProps & {
166
169
  mask?: string | null;
167
170
  mountNode?: HTMLElement;
168
171
  onClose?: () => any;
172
+ separateRangeInputs?: boolean;
173
+ startDateLabel?: string;
174
+ endDateLabel?: string;
169
175
  };
170
176
  export interface DatepickerState {
171
177
  calendarFocused: boolean;