baseui 0.0.0-next-18f6cb4 → 0.0.0-next-e7d1f7c

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyledWeekdayHeader = exports.StyledDayLabel = exports.StyledDay = exports.StyledWeek = exports.StyledMonth = exports.StyledNextButton = exports.StyledPrevButton = exports.StyledMonthYearSelectIconContainer = exports.StyledMonthYearSelectButton = exports.StyledMonthHeader = exports.StyledCalendarHeader = exports.StyledSelectorContainer = exports.StyledCalendarContainer = exports.StyledMonthContainer = exports.StyledRoot = exports.StyledInputWrapper = void 0;
6
+ exports.StyledWeekdayHeader = exports.StyledDayLabel = exports.StyledDay = exports.StyledWeek = exports.StyledMonth = exports.StyledNextButton = exports.StyledPrevButton = exports.StyledMonthYearSelectIconContainer = exports.StyledMonthYearSelectButton = exports.StyledMonthHeader = exports.StyledCalendarHeader = exports.StyledSelectorContainer = exports.StyledCalendarContainer = exports.StyledMonthContainer = exports.StyledRoot = exports.StyledEndDate = exports.StyledStartDate = exports.StyledInputLabel = exports.StyledInputWrapper = void 0;
7
7
 
8
8
  var _index = require("../styles/index.js");
9
9
 
@@ -22,7 +22,36 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
22
22
  /**
23
23
  * Main component container element
24
24
  */
25
- var StyledInputWrapper = (0, _index.styled)('div', function () {
25
+ var StyledInputWrapper = (0, _index.styled)('div', function (props) {
26
+ var $separateRangeInputs = props.$separateRangeInputs;
27
+ return _objectSpread({
28
+ width: '100%'
29
+ }, $separateRangeInputs ? {
30
+ display: 'flex',
31
+ justifyContent: 'center'
32
+ } : {});
33
+ });
34
+ exports.StyledInputWrapper = StyledInputWrapper;
35
+ StyledInputWrapper.displayName = "StyledInputWrapper";
36
+ var StyledInputLabel = (0, _index.styled)('div', function (_ref) {
37
+ var $theme = _ref.$theme;
38
+ return _objectSpread(_objectSpread({}, $theme.typography.LabelMedium), {}, {
39
+ marginBottom: $theme.sizing.scale300
40
+ });
41
+ });
42
+ exports.StyledInputLabel = StyledInputLabel;
43
+ StyledInputLabel.displayName = "StyledInputLabel";
44
+ var StyledStartDate = (0, _index.styled)('div', function (_ref2) {
45
+ var $theme = _ref2.$theme;
46
+ return {
47
+ width: '100%',
48
+ marginRight: $theme.sizing.scale300
49
+ };
50
+ });
51
+ exports.StyledStartDate = StyledStartDate;
52
+ StyledStartDate.displayName = "StyledStartDate";
53
+ var StyledEndDate = (0, _index.styled)('div', function (_ref3) {
54
+ var $theme = _ref3.$theme;
26
55
  return {
27
56
  width: '100%'
28
57
  };
@@ -31,8 +60,8 @@ var StyledInputWrapper = (0, _index.styled)('div', function () {
31
60
  * Main component container element
32
61
  */
33
62
 
34
- exports.StyledInputWrapper = StyledInputWrapper;
35
- StyledInputWrapper.displayName = "StyledInputWrapper";
63
+ exports.StyledEndDate = StyledEndDate;
64
+ StyledEndDate.displayName = "StyledEndDate";
36
65
  var StyledRoot = (0, _index.styled)('div', function (props) {
37
66
  var _props$$theme = props.$theme,
38
67
  typography = _props$$theme.typography,
@@ -71,8 +100,8 @@ var StyledCalendarContainer = (0, _index.styled)('div', function (props) {
71
100
  });
72
101
  exports.StyledCalendarContainer = StyledCalendarContainer;
73
102
  StyledCalendarContainer.displayName = "StyledCalendarContainer";
74
- var StyledSelectorContainer = (0, _index.styled)('div', function (_ref) {
75
- var $theme = _ref.$theme;
103
+ var StyledSelectorContainer = (0, _index.styled)('div', function (_ref4) {
104
+ var $theme = _ref4.$theme;
76
105
  var textAlign = $theme.direction === 'rtl' ? 'right' : 'left';
77
106
  return {
78
107
  marginBottom: $theme.sizing.scale600,
@@ -146,10 +175,10 @@ var StyledMonthYearSelectIconContainer = (0, _index.styled)('span', function (pr
146
175
  exports.StyledMonthYearSelectIconContainer = StyledMonthYearSelectIconContainer;
147
176
  StyledMonthYearSelectIconContainer.displayName = "StyledMonthYearSelectIconContainer";
148
177
 
149
- function getArrowBtnStyle(_ref3) {
150
- var $theme = _ref3.$theme,
151
- $disabled = _ref3.$disabled,
152
- $isFocusVisible = _ref3.$isFocusVisible;
178
+ function getArrowBtnStyle(_ref6) {
179
+ var $theme = _ref6.$theme,
180
+ $disabled = _ref6.$disabled,
181
+ $isFocusVisible = _ref6.$isFocusVisible;
153
182
  return {
154
183
  boxSizing: 'border-box',
155
184
  color: $disabled ? $theme.colors.calendarHeaderForegroundDisabled : $theme.colors.calendarHeaderForeground,
@@ -199,16 +228,16 @@ exports.StyledWeek = StyledWeek;
199
228
  StyledWeek.displayName = "StyledWeek";
200
229
 
201
230
  function generateDayStyles(defaultCode, defaultStyle) {
202
- var _ref4;
231
+ var _ref7;
203
232
 
204
233
  var codeForSM = defaultCode.substr(0, 12) + '1' + defaultCode.substr(12 + 1);
205
234
  var codeForEM = defaultCode.substr(0, 13) + '1' + defaultCode.substr(13 + 1);
206
- return _ref4 = {}, _defineProperty(_ref4, defaultCode, defaultStyle), _defineProperty(_ref4, codeForSM, defaultStyle), _defineProperty(_ref4, codeForEM, defaultStyle), _ref4;
235
+ return _ref7 = {}, _defineProperty(_ref7, defaultCode, defaultStyle), _defineProperty(_ref7, codeForSM, defaultStyle), _defineProperty(_ref7, codeForEM, defaultStyle), _ref7;
207
236
  } // eslint-disable-next-line flowtype/no-weak-types
208
237
 
209
238
 
210
- function getDayStyles(code, _ref5) {
211
- var colors = _ref5.colors;
239
+ function getDayStyles(code, _ref8) {
240
+ var colors = _ref8.colors;
212
241
  var undefinedDayStyle = {
213
242
  ':before': {
214
243
  content: null
@@ -13,7 +13,31 @@ import {ORIENTATION} from './constants.js';
13
13
  /**
14
14
  * Main component container element
15
15
  */
16
- export const StyledInputWrapper = styled<SharedStylePropsT>('div', () => ({
16
+ export const StyledInputWrapper = styled<{
17
+ ...SharedStylePropsT,
18
+ $separateRangeInputs: boolean,
19
+ }>('div', props => {
20
+ const {$separateRangeInputs} = props;
21
+
22
+ return {
23
+ width: '100%',
24
+ ...($separateRangeInputs
25
+ ? {display: 'flex', justifyContent: 'center'}
26
+ : {}),
27
+ };
28
+ });
29
+
30
+ export const StyledInputLabel = styled<{}>('div', ({$theme}) => ({
31
+ ...$theme.typography.LabelMedium,
32
+ marginBottom: $theme.sizing.scale300,
33
+ }));
34
+
35
+ export const StyledStartDate = styled<{}>('div', ({$theme}) => ({
36
+ width: '100%',
37
+ marginRight: $theme.sizing.scale300,
38
+ }));
39
+
40
+ export const StyledEndDate = styled<{}>('div', ({$theme}) => ({
17
41
  width: '100%',
18
42
  }));
19
43
 
@@ -57,6 +57,9 @@ export type DatepickerOverridesT = {
57
57
  InputWrapper?: OverrideT,
58
58
  /** Override for reused Popover component. Popover is **not a styled element** but a react component that can be replaced */
59
59
  Popover?: OverrideT,
60
+ StartDate?: OverrideT,
61
+ EndDate?: OverrideT,
62
+ InputLabel?: OverrideT,
60
63
  };
61
64
 
62
65
  export type DayPropsT<T = Date> = {
@@ -220,6 +223,10 @@ export type DatepickerPropsT<T = Date> = CalendarPropsT<T> & {
220
223
  /** Called when calendar is closed */
221
224
  onClose?: () => mixed,
222
225
  mask?: string | null,
226
+ /** Determines if startDate and endDate should be separated into two input fields. Ignored if `range` is not true. */
227
+ separateRangeInputs?: boolean,
228
+ startDateLabel?: string,
229
+ endDateLabel?: string,
223
230
  };
224
231
 
225
232
  export type SharedStylePropsT = {
@@ -15,10 +15,27 @@ import Calendar from './calendar.js';
15
15
  import { getOverrides } from '../helpers/overrides.js';
16
16
  import getInterpolatedString from '../helpers/i18n-interpolation.js';
17
17
  import { LocaleContext } from '../locale/index.js';
18
- import { StyledInputWrapper } from './styled-components.js';
18
+ import { StyledInputWrapper, StyledInputLabel, StyledStartDate, StyledEndDate } from './styled-components.js';
19
19
  import DateHelpers from './utils/date-helpers.js';
20
20
  import dateFnsAdapter from './utils/date-fns-adapter.js';
21
21
  export const DEFAULT_DATE_FORMAT = 'yyyy/MM/dd';
22
+ const INPUT_DELIMITER = ' – ';
23
+
24
+ const combineSeparatedInputs = (newInputValue, prevCombinedInputValue = '', separatedInput) => {
25
+ let inputValue = newInputValue;
26
+ const [prevStartDate = '', prevEndDate = ''] = prevCombinedInputValue.split(INPUT_DELIMITER);
27
+
28
+ if (separatedInput === 'startDate' && prevEndDate) {
29
+ inputValue = `${inputValue} – ${prevEndDate}`;
30
+ }
31
+
32
+ if (separatedInput === 'endDate') {
33
+ inputValue = `${prevStartDate} – ${inputValue}`;
34
+ }
35
+
36
+ return inputValue;
37
+ };
38
+
22
39
  export default class Datepicker extends React.Component {
23
40
  constructor(props) {
24
41
  super(props);
@@ -164,7 +181,8 @@ export default class Datepicker extends React.Component {
164
181
  const {
165
182
  formatString,
166
183
  mask,
167
- range
184
+ range,
185
+ separateRangeInputs
168
186
  } = this.props;
169
187
 
170
188
  if (mask === null) {
@@ -177,7 +195,7 @@ export default class Datepicker extends React.Component {
177
195
 
178
196
  const normalizedFormatString = this.normalizeDashes(formatString);
179
197
 
180
- if (formatString) {
198
+ if (formatString && !separateRangeInputs) {
181
199
  if (range) {
182
200
  return `${normalizedFormatString} – ${normalizedFormatString}`.replace(/[a-z]/gi, '9');
183
201
  } else {
@@ -185,15 +203,15 @@ export default class Datepicker extends React.Component {
185
203
  }
186
204
  }
187
205
 
188
- if (range) {
206
+ if (range && !separateRangeInputs) {
189
207
  return '9999/99/99 – 9999/99/99';
190
208
  }
191
209
 
192
210
  return '9999/99/99';
193
211
  });
194
212
 
195
- _defineProperty(this, "handleInputChange", event => {
196
- const inputValue = event.currentTarget.value;
213
+ _defineProperty(this, "handleInputChange", (event, separatedInput) => {
214
+ const inputValue = this.props.range && this.props.separateRangeInputs ? combineSeparatedInputs(event.currentTarget.value, this.state.inputValue, separatedInput) : event.currentTarget.value;
197
215
  const mask = this.getMask();
198
216
 
199
217
  if (typeof mask === 'string' && inputValue === mask.replace(/9/g, ' ') || inputValue.length === 0) {
@@ -224,7 +242,7 @@ export default class Datepicker extends React.Component {
224
242
  };
225
243
 
226
244
  if (this.props.range && typeof this.props.displayValueAtRangeIndex !== 'number') {
227
- const [left, right] = this.normalizeDashes(inputValue).split(' – ');
245
+ const [left, right] = this.normalizeDashes(inputValue).split(INPUT_DELIMITER);
228
246
  let startDate = this.dateHelpers.date(left);
229
247
  let endDate = this.dateHelpers.date(right);
230
248
 
@@ -372,7 +390,7 @@ export default class Datepicker extends React.Component {
372
390
  } else if (Array.isArray(date) && !date[0] && !date[1]) {
373
391
  return '';
374
392
  } else if (Array.isArray(date)) {
375
- return date.map(day => format(day)).join(' – ');
393
+ return date.map(day => format(day)).join(INPUT_DELIMITER);
376
394
  } else {
377
395
  return format(date);
378
396
  }
@@ -386,14 +404,50 @@ export default class Datepicker extends React.Component {
386
404
  }
387
405
  }
388
406
 
389
- render() {
407
+ renderInputComponent(locale, separatedInput) {
390
408
  const {
391
409
  overrides = {}
392
410
  } = this.props;
393
411
  const [InputComponent, inputProps] = getOverrides(overrides.Input, MaskedInput);
412
+ const 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';
413
+ const [startDate = '', endDate = ''] = (this.state.inputValue || '').split(INPUT_DELIMITER);
414
+ const value = separatedInput === 'startDate' ? startDate : separatedInput === 'endDate' ? endDate : this.state.inputValue;
415
+
416
+ const onChange = event => this.handleInputChange(event, separatedInput);
417
+
418
+ return /*#__PURE__*/React.createElement(InputComponent, _extends({
419
+ "aria-disabled": this.props.disabled,
420
+ "aria-label": this.props['aria-label'] || (this.props.range ? locale.datepicker.ariaLabelRange : locale.datepicker.ariaLabel),
421
+ error: this.props.error,
422
+ positive: this.props.positive,
423
+ "aria-describedby": this.props['aria-describedby'],
424
+ "aria-labelledby": this.props['aria-labelledby'],
425
+ "aria-required": this.props.required || null,
426
+ disabled: this.props.disabled,
427
+ size: this.props.size,
428
+ value: value,
429
+ onFocus: this.open,
430
+ onBlur: this.handleInputBlur,
431
+ onKeyDown: this.handleKeyDown,
432
+ onChange: onChange,
433
+ placeholder: placeholder,
434
+ mask: this.getMask(),
435
+ required: this.props.required,
436
+ clearable: this.props.clearable
437
+ }, inputProps));
438
+ }
439
+
440
+ render() {
441
+ const {
442
+ overrides = {},
443
+ startDateLabel = 'Start Date',
444
+ endDateLabel = 'End Date'
445
+ } = this.props;
394
446
  const [PopoverComponent, popoverProps] = getOverrides(overrides.Popover, Popover);
395
447
  const [InputWrapper, inputWrapperProps] = getOverrides(overrides.InputWrapper, StyledInputWrapper);
396
- const placeholder = this.props.placeholder || this.props.placeholder === '' ? this.props.placeholder : this.props.range ? 'YYYY/MM/DD – YYYY/MM/DD' : 'YYYY/MM/DD';
448
+ const [StartDate, startDateProps] = getOverrides(overrides.StartDate, StyledStartDate);
449
+ const [EndDate, endDateProps] = getOverrides(overrides.EndDate, StyledEndDate);
450
+ const [InputLabel, inputLabelProps] = getOverrides(overrides.InputLabel, StyledInputLabel);
397
451
  return /*#__PURE__*/React.createElement(LocaleContext.Consumer, null, locale => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PopoverComponent, _extends({
398
452
  focusLock: false,
399
453
  mountNode: this.props.mountNode,
@@ -409,26 +463,9 @@ export default class Datepicker extends React.Component {
409
463
  }, this.props, {
410
464
  onChange: this.onChange
411
465
  }))
412
- }, popoverProps), /*#__PURE__*/React.createElement(InputWrapper, inputWrapperProps, /*#__PURE__*/React.createElement(InputComponent, _extends({
413
- "aria-disabled": this.props.disabled,
414
- "aria-label": this.props['aria-label'] || (this.props.range ? locale.datepicker.ariaLabelRange : locale.datepicker.ariaLabel),
415
- error: this.props.error,
416
- positive: this.props.positive,
417
- "aria-describedby": this.props['aria-describedby'],
418
- "aria-labelledby": this.props['aria-labelledby'],
419
- "aria-required": this.props.required || null,
420
- disabled: this.props.disabled,
421
- size: this.props.size,
422
- value: this.state.inputValue,
423
- onFocus: this.open,
424
- onBlur: this.handleInputBlur,
425
- onKeyDown: this.handleKeyDown,
426
- onChange: this.handleInputChange,
427
- placeholder: placeholder,
428
- mask: this.getMask(),
429
- required: this.props.required,
430
- clearable: this.props.clearable
431
- }, inputProps)))), /*#__PURE__*/React.createElement("p", {
466
+ }, popoverProps), /*#__PURE__*/React.createElement(InputWrapper, _extends({}, inputWrapperProps, {
467
+ $separateRangeInputs: this.props.range && this.props.separateRangeInputs
468
+ }), this.props.range && this.props.separateRangeInputs ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StartDate, startDateProps, /*#__PURE__*/React.createElement(InputLabel, inputLabelProps, startDateLabel), this.renderInputComponent(locale, 'startDate')), /*#__PURE__*/React.createElement(EndDate, endDateProps, /*#__PURE__*/React.createElement(InputLabel, inputLabelProps, endDateLabel), this.renderInputComponent(locale, 'endDate'))) : /*#__PURE__*/React.createElement(React.Fragment, null, this.renderInputComponent(locale)))), /*#__PURE__*/React.createElement("p", {
432
469
  id: this.props['aria-describedby'],
433
470
  style: {
434
471
  position: 'fixed',
@@ -11,14 +11,42 @@ import { ORIENTATION } from './constants.js';
11
11
  * Main component container element
12
12
  */
13
13
 
14
- export const StyledInputWrapper = styled('div', () => ({
14
+ export const StyledInputWrapper = styled('div', props => {
15
+ const {
16
+ $separateRangeInputs
17
+ } = props;
18
+ return {
19
+ width: '100%',
20
+ ...($separateRangeInputs ? {
21
+ display: 'flex',
22
+ justifyContent: 'center'
23
+ } : {})
24
+ };
25
+ });
26
+ StyledInputWrapper.displayName = "StyledInputWrapper";
27
+ export const StyledInputLabel = styled('div', ({
28
+ $theme
29
+ }) => ({ ...$theme.typography.LabelMedium,
30
+ marginBottom: $theme.sizing.scale300
31
+ }));
32
+ StyledInputLabel.displayName = "StyledInputLabel";
33
+ export const StyledStartDate = styled('div', ({
34
+ $theme
35
+ }) => ({
36
+ width: '100%',
37
+ marginRight: $theme.sizing.scale300
38
+ }));
39
+ StyledStartDate.displayName = "StyledStartDate";
40
+ export const StyledEndDate = styled('div', ({
41
+ $theme
42
+ }) => ({
15
43
  width: '100%'
16
44
  }));
17
45
  /**
18
46
  * Main component container element
19
47
  */
20
48
 
21
- StyledInputWrapper.displayName = "StyledInputWrapper";
49
+ StyledEndDate.displayName = "StyledEndDate";
22
50
  export const StyledRoot = styled('div', props => {
23
51
  const {
24
52
  $theme: {
@@ -25,6 +25,10 @@ class StatefulContainer extends React.Component {
25
25
  this.props.onBlur(e);
26
26
  }
27
27
 
28
+ if (this.props.focusLock || this.props.autoFocus) {
29
+ return;
30
+ }
31
+
28
32
  this.close();
29
33
  });
30
34