@douyinfe/semi-ui 2.6.0 → 2.7.0-beta.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.
- package/button/__test__/button.test.js +7 -0
- package/button/buttonGroup.tsx +5 -2
- package/cascader/__test__/cascader.test.js +159 -81
- package/cascader/_story/cascader.stories.js +36 -23
- package/cascader/index.tsx +26 -5
- package/datePicker/_story/v2/InsetInput.jsx +104 -0
- package/datePicker/_story/v2/InsetInputE2E.jsx +69 -0
- package/datePicker/_story/v2/index.js +2 -0
- package/datePicker/dateInput.tsx +95 -9
- package/datePicker/datePicker.tsx +89 -15
- package/datePicker/index.tsx +15 -0
- package/datePicker/insetInput.tsx +76 -0
- package/datePicker/monthsGrid.tsx +14 -7
- package/dist/css/semi.css +104 -2
- package/dist/css/semi.min.css +1 -1
- package/dist/umd/semi-ui.js +902 -147
- package/dist/umd/semi-ui.js.map +1 -1
- package/dist/umd/semi-ui.min.js +1 -1
- package/dist/umd/semi-ui.min.js.map +1 -1
- package/input/_story/input.stories.js +13 -0
- package/lib/cjs/button/buttonGroup.d.ts +1 -0
- package/lib/cjs/button/buttonGroup.js +6 -2
- package/lib/cjs/cascader/index.d.ts +1 -0
- package/lib/cjs/cascader/index.js +38 -9
- package/lib/cjs/datePicker/dateInput.d.ts +9 -2
- package/lib/cjs/datePicker/dateInput.js +92 -9
- package/lib/cjs/datePicker/datePicker.d.ts +7 -2
- package/lib/cjs/datePicker/datePicker.js +123 -18
- package/lib/cjs/datePicker/index.js +24 -2
- package/lib/cjs/datePicker/insetInput.d.ts +21 -0
- package/lib/cjs/datePicker/insetInput.js +80 -0
- package/lib/cjs/datePicker/monthsGrid.js +19 -7
- package/lib/cjs/tree/index.js +5 -3
- package/lib/cjs/tree/interface.d.ts +1 -0
- package/lib/cjs/tree/nodeList.js +2 -1
- package/lib/cjs/treeSelect/index.js +7 -3
- package/lib/es/button/buttonGroup.d.ts +1 -0
- package/lib/es/button/buttonGroup.js +5 -2
- package/lib/es/cascader/index.d.ts +1 -0
- package/lib/es/cascader/index.js +35 -6
- package/lib/es/datePicker/dateInput.d.ts +9 -2
- package/lib/es/datePicker/dateInput.js +91 -9
- package/lib/es/datePicker/datePicker.d.ts +7 -2
- package/lib/es/datePicker/datePicker.js +124 -18
- package/lib/es/datePicker/index.js +20 -0
- package/lib/es/datePicker/insetInput.d.ts +21 -0
- package/lib/es/datePicker/insetInput.js +65 -0
- package/lib/es/datePicker/monthsGrid.js +19 -7
- package/lib/es/tree/index.js +5 -3
- package/lib/es/tree/interface.d.ts +1 -0
- package/lib/es/tree/nodeList.js +2 -1
- package/lib/es/treeSelect/index.js +7 -3
- package/package.json +9 -9
- package/tree/__test__/tree.test.js +87 -2
- package/tree/_story/tree.stories.js +65 -5
- package/tree/index.tsx +4 -2
- package/tree/interface.ts +1 -0
- package/tree/nodeList.tsx +2 -2
- package/treeSelect/__test__/treeSelect.test.js +28 -0
- package/treeSelect/_story/treeSelect.stories.js +55 -2
- package/treeSelect/index.tsx +11 -3
package/lib/es/cascader/index.js
CHANGED
|
@@ -9,10 +9,10 @@ import _isSet from "lodash/isSet";
|
|
|
9
9
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
10
10
|
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
11
11
|
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
12
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
12
13
|
import _Set from "@babel/runtime-corejs3/core-js-stable/set";
|
|
13
14
|
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
14
15
|
import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
|
|
15
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
16
16
|
import React, { Fragment } from 'react';
|
|
17
17
|
import ReactDOM from 'react-dom';
|
|
18
18
|
import cls from 'classnames';
|
|
@@ -210,6 +210,36 @@ class Cascader extends BaseComponent {
|
|
|
210
210
|
return /*#__PURE__*/React.createElement(React.Fragment, null, displayTag, !_isEmpty(hiddenTag) && this.renderPlusN(hiddenTag));
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
+
this.renderDisplayText = () => {
|
|
214
|
+
const {
|
|
215
|
+
displayProp,
|
|
216
|
+
separator,
|
|
217
|
+
displayRender
|
|
218
|
+
} = this.props;
|
|
219
|
+
const {
|
|
220
|
+
selectedKeys
|
|
221
|
+
} = this.state;
|
|
222
|
+
let displayText = '';
|
|
223
|
+
|
|
224
|
+
if (selectedKeys.size) {
|
|
225
|
+
const displayPath = this.foundation.getItemPropPath([...selectedKeys][0], displayProp);
|
|
226
|
+
|
|
227
|
+
if (displayRender && typeof displayRender === 'function') {
|
|
228
|
+
displayText = displayRender(displayPath);
|
|
229
|
+
} else {
|
|
230
|
+
displayText = _mapInstanceProperty(displayPath).call(displayPath, (path, index) => {
|
|
231
|
+
var _context3;
|
|
232
|
+
|
|
233
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
|
234
|
+
key: _concatInstanceProperty(_context3 = "".concat(path, "-")).call(_context3, index)
|
|
235
|
+
}, index < displayPath.length - 1 ? /*#__PURE__*/React.createElement(React.Fragment, null, path, separator) : path);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return displayText;
|
|
241
|
+
};
|
|
242
|
+
|
|
213
243
|
this.renderSelectContent = () => {
|
|
214
244
|
const {
|
|
215
245
|
placeholder,
|
|
@@ -217,7 +247,6 @@ class Cascader extends BaseComponent {
|
|
|
217
247
|
multiple
|
|
218
248
|
} = this.props;
|
|
219
249
|
const {
|
|
220
|
-
selectedKeys,
|
|
221
250
|
checkedKeys
|
|
222
251
|
} = this.state;
|
|
223
252
|
const searchable = Boolean(filterTreeNode);
|
|
@@ -232,9 +261,9 @@ class Cascader extends BaseComponent {
|
|
|
232
261
|
|
|
233
262
|
return this.renderMultipleTags();
|
|
234
263
|
} else {
|
|
235
|
-
const displayText =
|
|
264
|
+
const displayText = this.renderDisplayText();
|
|
236
265
|
const spanCls = cls({
|
|
237
|
-
["".concat(prefixcls, "-selection-placeholder")]: !displayText
|
|
266
|
+
["".concat(prefixcls, "-selection-placeholder")]: !displayText
|
|
238
267
|
});
|
|
239
268
|
return /*#__PURE__*/React.createElement("span", {
|
|
240
269
|
className: spanCls
|
|
@@ -779,7 +808,7 @@ class Cascader extends BaseComponent {
|
|
|
779
808
|
}
|
|
780
809
|
|
|
781
810
|
renderTagInput() {
|
|
782
|
-
var
|
|
811
|
+
var _context4;
|
|
783
812
|
|
|
784
813
|
const {
|
|
785
814
|
size,
|
|
@@ -799,7 +828,7 @@ class Cascader extends BaseComponent {
|
|
|
799
828
|
const tagValue = [];
|
|
800
829
|
const realKeys = this.mergeType === strings.NONE_MERGE_TYPE ? checkedKeys : resolvedCheckedKeys;
|
|
801
830
|
|
|
802
|
-
_forEachInstanceProperty(
|
|
831
|
+
_forEachInstanceProperty(_context4 = [...realKeys]).call(_context4, checkedKey => {
|
|
803
832
|
if (!_isEmpty(keyEntities[checkedKey])) {
|
|
804
833
|
tagValue.push(keyEntities[checkedKey].valuePath);
|
|
805
834
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import DateInputFoundation, { DateInputAdapter, DateInputFoundationProps, RangeType } from '@douyinfe/semi-foundation/lib/es/datePicker/inputFoundation';
|
|
3
|
+
import DateInputFoundation, { DateInputAdapter, DateInputFoundationProps, RangeType, InsetInputChangeProps, InsetInputChangeFoundationProps } from '@douyinfe/semi-foundation/lib/es/datePicker/inputFoundation';
|
|
4
4
|
import { noop } from '@douyinfe/semi-foundation/lib/es/utils/function';
|
|
5
|
-
import BaseComponent, { BaseProps } from '../_base/baseComponent';
|
|
6
5
|
import { ValueType } from '@douyinfe/semi-foundation/lib/es/datePicker/foundation';
|
|
6
|
+
import BaseComponent, { BaseProps } from '../_base/baseComponent';
|
|
7
7
|
export interface DateInputProps extends DateInputFoundationProps, BaseProps {
|
|
8
8
|
insetLabel?: React.ReactNode;
|
|
9
9
|
prefix?: React.ReactNode;
|
|
@@ -13,6 +13,8 @@ export interface DateInputProps extends DateInputFoundationProps, BaseProps {
|
|
|
13
13
|
onBlur?: (e: React.MouseEvent<HTMLInputElement>) => void;
|
|
14
14
|
onFocus?: (e: React.MouseEvent<HTMLInputElement>, rangeType?: RangeType) => void;
|
|
15
15
|
onClear?: (e: React.MouseEvent<HTMLDivElement>) => void;
|
|
16
|
+
onInsetInputChange?: (options: InsetInputChangeProps) => void;
|
|
17
|
+
value?: Date[];
|
|
16
18
|
}
|
|
17
19
|
export default class DateInput extends BaseComponent<DateInputProps, {}> {
|
|
18
20
|
static propTypes: {
|
|
@@ -39,6 +41,8 @@ export default class DateInput extends BaseComponent<DateInputProps, {}> {
|
|
|
39
41
|
rangeInputStartRef: PropTypes.Requireable<object>;
|
|
40
42
|
rangeInputEndRef: PropTypes.Requireable<object>;
|
|
41
43
|
rangeSeparator: PropTypes.Requireable<string>;
|
|
44
|
+
insetInput: PropTypes.Requireable<boolean>;
|
|
45
|
+
insetInputValue: PropTypes.Requireable<object>;
|
|
42
46
|
};
|
|
43
47
|
static defaultProps: {
|
|
44
48
|
showClear: boolean;
|
|
@@ -69,11 +73,14 @@ export default class DateInput extends BaseComponent<DateInputProps, {}> {
|
|
|
69
73
|
handleRangeInputEndKeyPress: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
70
74
|
handleRangeInputFocus: (e: React.MouseEvent<HTMLElement>, rangeType: RangeType) => void;
|
|
71
75
|
handleRangeStartFocus: React.MouseEventHandler<HTMLElement>;
|
|
76
|
+
handleInsetInputChange: (options: InsetInputChangeFoundationProps) => void;
|
|
72
77
|
getRangeInputValue: (rangeStart: string, rangeEnd: string) => string;
|
|
73
78
|
renderRangePrefix(): JSX.Element;
|
|
74
79
|
renderRangeSeparator(rangeStart: string, rangeEnd: string): JSX.Element;
|
|
75
80
|
renderRangeClearBtn(rangeStart: string, rangeEnd: string): JSX.Element;
|
|
76
81
|
renderRangeSuffix(suffix: React.ReactNode): JSX.Element;
|
|
77
82
|
renderRangeInput(rangeProps: DateInputProps): JSX.Element;
|
|
83
|
+
renderInputInset(): JSX.Element;
|
|
84
|
+
renderTriggerInput(): JSX.Element;
|
|
78
85
|
render(): JSX.Element;
|
|
79
86
|
}
|
|
@@ -15,7 +15,9 @@ var __rest = this && this.__rest || function (s, e) {
|
|
|
15
15
|
}
|
|
16
16
|
return t;
|
|
17
17
|
};
|
|
18
|
-
/* eslint-disable jsx-a11y/click-events-have-key-events
|
|
18
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
19
|
+
|
|
20
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
19
21
|
|
|
20
22
|
/* eslint-disable max-lines-per-function */
|
|
21
23
|
|
|
@@ -29,9 +31,10 @@ import DateInputFoundation from '@douyinfe/semi-foundation/lib/es/datePicker/inp
|
|
|
29
31
|
import { cssClasses, strings } from '@douyinfe/semi-foundation/lib/es/datePicker/constants';
|
|
30
32
|
import { noop } from '@douyinfe/semi-foundation/lib/es/utils/function';
|
|
31
33
|
import isNullOrUndefined from '@douyinfe/semi-foundation/lib/es/utils/isNullOrUndefined';
|
|
34
|
+
import { IconCalendar, IconCalendarClock, IconClear } from '@douyinfe/semi-icons';
|
|
32
35
|
import BaseComponent from '../_base/baseComponent';
|
|
33
36
|
import Input from '../input/index';
|
|
34
|
-
import {
|
|
37
|
+
import { InsetDateInput, InsetTimeInput } from './insetInput'; // eslint-disable-next-line @typescript-eslint/ban-types
|
|
35
38
|
|
|
36
39
|
export default class DateInput extends BaseComponent {
|
|
37
40
|
constructor(props) {
|
|
@@ -69,6 +72,10 @@ export default class DateInput extends BaseComponent {
|
|
|
69
72
|
this.handleRangeInputFocus(e, 'rangeStart');
|
|
70
73
|
};
|
|
71
74
|
|
|
75
|
+
this.handleInsetInputChange = options => {
|
|
76
|
+
this.foundation.handleInsetInputChange(options);
|
|
77
|
+
};
|
|
78
|
+
|
|
72
79
|
this.getRangeInputValue = (rangeStart, rangeEnd) => {
|
|
73
80
|
var _context, _context2;
|
|
74
81
|
|
|
@@ -117,7 +124,8 @@ export default class DateInput extends BaseComponent {
|
|
|
117
124
|
},
|
|
118
125
|
notifyTabPress: function () {
|
|
119
126
|
return _this.props.onRangeEndTabPress(...arguments);
|
|
120
|
-
}
|
|
127
|
+
},
|
|
128
|
+
notifyInsetInputChange: options => this.props.onInsetInputChange(options)
|
|
121
129
|
});
|
|
122
130
|
}
|
|
123
131
|
|
|
@@ -222,11 +230,11 @@ export default class DateInput extends BaseComponent {
|
|
|
222
230
|
const rangePlaceholder = _Array$isArray(placeholder) ? placeholder : [placeholder, placeholder];
|
|
223
231
|
const [rangeStartPlaceholder, rangeEndPlaceholder] = rangePlaceholder;
|
|
224
232
|
const inputLeftWrapperCls = cls("".concat(prefixCls, "-range-input-wrapper-start"), "".concat(prefixCls, "-range-input-wrapper"), {
|
|
225
|
-
["".concat(prefixCls, "-range-input-wrapper-active")]: rangeInputFocus === 'rangeStart',
|
|
233
|
+
["".concat(prefixCls, "-range-input-wrapper-active")]: rangeInputFocus === 'rangeStart' && !disabled,
|
|
226
234
|
["".concat(prefixCls, "-range-input-wrapper-start-with-prefix")]: this.props.prefix || this.props.insetLabel
|
|
227
235
|
});
|
|
228
236
|
const inputRightWrapperCls = cls("".concat(prefixCls, "-range-input-wrapper-end"), "".concat(prefixCls, "-range-input-wrapper"), {
|
|
229
|
-
["".concat(prefixCls, "-range-input-wrapper-active")]: rangeInputFocus === 'rangeEnd'
|
|
237
|
+
["".concat(prefixCls, "-range-input-wrapper-active")]: rangeInputFocus === 'rangeEnd' && !disabled
|
|
230
238
|
});
|
|
231
239
|
return /*#__PURE__*/React.createElement(React.Fragment, null, this.renderRangePrefix(), /*#__PURE__*/React.createElement("div", {
|
|
232
240
|
onClick: e => !disabled && this.handleRangeInputFocus(e, 'rangeStart'),
|
|
@@ -265,7 +273,70 @@ export default class DateInput extends BaseComponent {
|
|
|
265
273
|
})), this.renderRangeClearBtn(rangeStart, rangeEnd), this.renderRangeSuffix(suffix));
|
|
266
274
|
}
|
|
267
275
|
|
|
268
|
-
|
|
276
|
+
renderInputInset() {
|
|
277
|
+
const {
|
|
278
|
+
type,
|
|
279
|
+
handleInsetDateFocus,
|
|
280
|
+
handleInsetTimeFocus,
|
|
281
|
+
value,
|
|
282
|
+
insetInputValue,
|
|
283
|
+
prefixCls,
|
|
284
|
+
rangeInputStartRef,
|
|
285
|
+
rangeInputEndRef,
|
|
286
|
+
density
|
|
287
|
+
} = this.props;
|
|
288
|
+
|
|
289
|
+
const _isRangeType = _includesInstanceProperty(type).call(type, 'Range');
|
|
290
|
+
|
|
291
|
+
const newInsetInputValue = this.foundation.getInsetInputValue({
|
|
292
|
+
value,
|
|
293
|
+
insetInputValue
|
|
294
|
+
});
|
|
295
|
+
const {
|
|
296
|
+
datePlaceholder,
|
|
297
|
+
timePlaceholder
|
|
298
|
+
} = this.foundation.getInsetInputPlaceholder();
|
|
299
|
+
const insetInputWrapperCls = "".concat(prefixCls, "-inset-input-wrapper");
|
|
300
|
+
const separatorCls = "".concat(prefixCls, "-inset-input-separator");
|
|
301
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
302
|
+
className: insetInputWrapperCls,
|
|
303
|
+
"x-type": type
|
|
304
|
+
}, /*#__PURE__*/React.createElement(InsetDateInput, {
|
|
305
|
+
forwardRef: rangeInputStartRef,
|
|
306
|
+
insetInputValue: newInsetInputValue,
|
|
307
|
+
placeholder: datePlaceholder,
|
|
308
|
+
valuePath: 'monthLeft.dateInput',
|
|
309
|
+
onChange: this.handleInsetInputChange,
|
|
310
|
+
onFocus: e => handleInsetDateFocus(e, 'rangeStart')
|
|
311
|
+
}), /*#__PURE__*/React.createElement(InsetTimeInput, {
|
|
312
|
+
disabled: !newInsetInputValue.monthLeft.dateInput,
|
|
313
|
+
insetInputValue: newInsetInputValue,
|
|
314
|
+
placeholder: timePlaceholder,
|
|
315
|
+
type: type,
|
|
316
|
+
valuePath: 'monthLeft.timeInput',
|
|
317
|
+
onChange: this.handleInsetInputChange,
|
|
318
|
+
onFocus: handleInsetTimeFocus
|
|
319
|
+
}), _isRangeType && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
320
|
+
className: separatorCls
|
|
321
|
+
}, density === 'compact' ? null : '-'), /*#__PURE__*/React.createElement(InsetDateInput, {
|
|
322
|
+
forwardRef: rangeInputEndRef,
|
|
323
|
+
insetInputValue: newInsetInputValue,
|
|
324
|
+
placeholder: datePlaceholder,
|
|
325
|
+
valuePath: 'monthRight.dateInput',
|
|
326
|
+
onChange: this.handleInsetInputChange,
|
|
327
|
+
onFocus: e => handleInsetDateFocus(e, 'rangeEnd')
|
|
328
|
+
}), /*#__PURE__*/React.createElement(InsetTimeInput, {
|
|
329
|
+
disabled: !newInsetInputValue.monthRight.dateInput,
|
|
330
|
+
insetInputValue: newInsetInputValue,
|
|
331
|
+
placeholder: timePlaceholder,
|
|
332
|
+
type: type,
|
|
333
|
+
valuePath: 'monthRight.timeInput',
|
|
334
|
+
onChange: this.handleInsetInputChange,
|
|
335
|
+
onFocus: handleInsetTimeFocus
|
|
336
|
+
})));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
renderTriggerInput() {
|
|
269
340
|
const _a = this.props,
|
|
270
341
|
{
|
|
271
342
|
placeholder,
|
|
@@ -297,9 +368,11 @@ export default class DateInput extends BaseComponent {
|
|
|
297
368
|
onRangeBlur,
|
|
298
369
|
onRangeEndTabPress,
|
|
299
370
|
rangeInputFocus,
|
|
300
|
-
rangeSeparator
|
|
371
|
+
rangeSeparator,
|
|
372
|
+
insetInput,
|
|
373
|
+
insetInputValue
|
|
301
374
|
} = _a,
|
|
302
|
-
rest = __rest(_a, ["placeholder", "type", "value", "inputValue", "inputStyle", "disabled", "showClear", "inputReadOnly", "insetLabel", "validateStatus", "block", "prefixCls", "multiple", "dateFnsLocale", "onBlur", "onClear", "onFocus", "prefix", "autofocus", "size", "rangeInputStartRef", "rangeInputEndRef", "onRangeClear", "onRangeBlur", "onRangeEndTabPress", "rangeInputFocus", "rangeSeparator"]);
|
|
375
|
+
rest = __rest(_a, ["placeholder", "type", "value", "inputValue", "inputStyle", "disabled", "showClear", "inputReadOnly", "insetLabel", "validateStatus", "block", "prefixCls", "multiple", "dateFnsLocale", "onBlur", "onClear", "onFocus", "prefix", "autofocus", "size", "rangeInputStartRef", "rangeInputEndRef", "onRangeClear", "onRangeBlur", "onRangeEndTabPress", "rangeInputFocus", "rangeSeparator", "insetInput", "insetInputValue"]);
|
|
303
376
|
|
|
304
377
|
const dateIcon = /*#__PURE__*/React.createElement(IconCalendar, {
|
|
305
378
|
"aria-hidden": true
|
|
@@ -350,6 +423,13 @@ export default class DateInput extends BaseComponent {
|
|
|
350
423
|
}));
|
|
351
424
|
}
|
|
352
425
|
|
|
426
|
+
render() {
|
|
427
|
+
const {
|
|
428
|
+
insetInput
|
|
429
|
+
} = this.props;
|
|
430
|
+
return insetInput ? this.renderInputInset() : this.renderTriggerInput();
|
|
431
|
+
}
|
|
432
|
+
|
|
353
433
|
}
|
|
354
434
|
DateInput.propTypes = {
|
|
355
435
|
onClick: PropTypes.func,
|
|
@@ -374,7 +454,9 @@ DateInput.propTypes = {
|
|
|
374
454
|
rangeInputFocus: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
375
455
|
rangeInputStartRef: PropTypes.object,
|
|
376
456
|
rangeInputEndRef: PropTypes.object,
|
|
377
|
-
rangeSeparator: PropTypes.string
|
|
457
|
+
rangeSeparator: PropTypes.string,
|
|
458
|
+
insetInput: PropTypes.bool,
|
|
459
|
+
insetInputValue: PropTypes.object
|
|
378
460
|
};
|
|
379
461
|
DateInput.defaultProps = {
|
|
380
462
|
showClear: true,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import DatePickerFoundation, { DatePickerAdapter, DatePickerFoundationProps, DatePickerFoundationState, DayStatusType, PresetType, Type } from '@douyinfe/semi-foundation/lib/es/datePicker/foundation';
|
|
3
|
+
import DatePickerFoundation, { DatePickerAdapter, DatePickerFoundationProps, DatePickerFoundationState, DayStatusType, PresetType, Type, RangeType } from '@douyinfe/semi-foundation/lib/es/datePicker/foundation';
|
|
4
4
|
import BaseComponent from '../_base/baseComponent';
|
|
5
5
|
import { DateInputProps } from './dateInput';
|
|
6
6
|
import MonthsGrid, { MonthsGridProps } from './monthsGrid';
|
|
7
7
|
import { YearAndMonthProps } from './yearAndMonth';
|
|
8
8
|
import '@douyinfe/semi-foundation/lib/es/datePicker/datePicker.css';
|
|
9
9
|
import { Locale } from '../locale/interface';
|
|
10
|
-
import { RangeType } from '@douyinfe/semi-foundation/lib/es/datePicker/inputFoundation';
|
|
11
10
|
import { TimePickerProps } from '../timePicker/TimePicker';
|
|
11
|
+
import { InsetInputChangeProps } from '@douyinfe/semi-foundation/lib/es/datePicker/inputFoundation';
|
|
12
12
|
export interface DatePickerProps extends DatePickerFoundationProps {
|
|
13
13
|
'aria-describedby'?: React.AriaAttributes['aria-describedby'];
|
|
14
14
|
'aria-errormessage'?: React.AriaAttributes['aria-errormessage'];
|
|
@@ -143,6 +143,7 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
|
|
|
143
143
|
autoSwitchDate: boolean;
|
|
144
144
|
syncSwitchMonth: boolean;
|
|
145
145
|
rangeSeparator: " ~ ";
|
|
146
|
+
insetInput: boolean;
|
|
146
147
|
};
|
|
147
148
|
triggerElRef: React.MutableRefObject<HTMLElement>;
|
|
148
149
|
panelRef: React.RefObject<HTMLDivElement>;
|
|
@@ -171,6 +172,7 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
|
|
|
171
172
|
renderQuickControls(): JSX.Element;
|
|
172
173
|
handleOpenPanel: () => void;
|
|
173
174
|
handleInputChange: DatePickerFoundation['handleInputChange'];
|
|
175
|
+
handleInsetInputChange: (options: InsetInputChangeProps) => void;
|
|
174
176
|
handleInputComplete: DatePickerFoundation['handleInputComplete'];
|
|
175
177
|
handleInputBlur: DateInputProps['onBlur'];
|
|
176
178
|
handleInputFocus: DatePickerFoundation['handleInputFocus'];
|
|
@@ -181,6 +183,9 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
|
|
|
181
183
|
handleRangeInputClear: DatePickerFoundation['handleRangeInputClear'];
|
|
182
184
|
handleRangeEndTabPress: DatePickerFoundation['handleRangeEndTabPress'];
|
|
183
185
|
isAnotherPanelHasOpened: (currentRangeInput: RangeType) => boolean;
|
|
186
|
+
handleInsetDateFocus: (e: React.FocusEvent, rangeType: 'rangeStart' | 'rangeEnd') => void;
|
|
187
|
+
handleInsetTimeFocus: () => void;
|
|
188
|
+
handlePanelVisibleChange: (visible: boolean) => void;
|
|
184
189
|
renderInner(extraProps?: Partial<DatePickerProps>): JSX.Element;
|
|
185
190
|
handleConfirm: (e: React.MouseEvent) => void;
|
|
186
191
|
handleCancel: (e: React.MouseEvent) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _isEqual from "lodash/isEqual";
|
|
1
2
|
import _isFunction from "lodash/isFunction";
|
|
2
3
|
import _get from "lodash/get";
|
|
3
4
|
import _isDate from "lodash/isDate";
|
|
@@ -12,6 +13,10 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
|
|
|
12
13
|
/* eslint-disable jsx-a11y/click-events-have-key-events,jsx-a11y/interactive-supports-focus */
|
|
13
14
|
|
|
14
15
|
/* eslint-disable max-len */
|
|
16
|
+
|
|
17
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
18
|
+
|
|
19
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
15
20
|
import React from 'react';
|
|
16
21
|
import classnames from 'classnames';
|
|
17
22
|
import PropTypes from 'prop-types';
|
|
@@ -65,6 +70,8 @@ export default class DatePicker extends BaseComponent {
|
|
|
65
70
|
return _this.foundation.handleInputChange(...arguments);
|
|
66
71
|
};
|
|
67
72
|
|
|
73
|
+
this.handleInsetInputChange = options => this.foundation.handleInsetInputChange(options);
|
|
74
|
+
|
|
68
75
|
this.handleInputComplete = v => this.foundation.handleInputComplete(v);
|
|
69
76
|
|
|
70
77
|
this.handleInputBlur = e => this.foundation.handleInputBlur(_get(e, 'nativeEvent.target.value'), e);
|
|
@@ -93,6 +100,30 @@ export default class DatePicker extends BaseComponent {
|
|
|
93
100
|
}
|
|
94
101
|
};
|
|
95
102
|
|
|
103
|
+
this.handleInsetDateFocus = (e, rangeType) => {
|
|
104
|
+
const monthGridFoundation = _get(this, 'monthGrid.current.foundation');
|
|
105
|
+
|
|
106
|
+
if (monthGridFoundation) {
|
|
107
|
+
monthGridFoundation.showDatePanel(strings.PANEL_TYPE_LEFT);
|
|
108
|
+
monthGridFoundation.showDatePanel(strings.PANEL_TYPE_RIGHT);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.handleInputFocus(e, rangeType);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
this.handleInsetTimeFocus = () => {
|
|
115
|
+
const monthGridFoundation = _get(this, 'monthGrid.current.foundation');
|
|
116
|
+
|
|
117
|
+
if (monthGridFoundation) {
|
|
118
|
+
monthGridFoundation.showTimePicker(strings.PANEL_TYPE_LEFT);
|
|
119
|
+
monthGridFoundation.showTimePicker(strings.PANEL_TYPE_RIGHT);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
this.handlePanelVisibleChange = visible => {
|
|
124
|
+
this.foundation.handlePanelVisibleChange(visible);
|
|
125
|
+
};
|
|
126
|
+
|
|
96
127
|
this.handleConfirm = e => this.foundation.handleConfirm();
|
|
97
128
|
|
|
98
129
|
this.handleCancel = e => this.foundation.handleCancel();
|
|
@@ -116,19 +147,43 @@ export default class DatePicker extends BaseComponent {
|
|
|
116
147
|
dropdownStyle,
|
|
117
148
|
density,
|
|
118
149
|
topSlot,
|
|
119
|
-
bottomSlot
|
|
150
|
+
bottomSlot,
|
|
151
|
+
insetInput,
|
|
152
|
+
type,
|
|
153
|
+
format,
|
|
154
|
+
rangeSeparator
|
|
120
155
|
} = this.props;
|
|
156
|
+
const {
|
|
157
|
+
insetInputValue,
|
|
158
|
+
value
|
|
159
|
+
} = this.state;
|
|
121
160
|
const wrapCls = classnames(cssClasses.PREFIX, {
|
|
122
161
|
[cssClasses.PANEL_YAM]: this.adapter.typeIsYearOrMonth(),
|
|
123
162
|
["".concat(cssClasses.PREFIX, "-compact")]: density === 'compact'
|
|
124
163
|
}, dropdownClassName);
|
|
164
|
+
const insetInputProps = {
|
|
165
|
+
dateFnsLocale,
|
|
166
|
+
format,
|
|
167
|
+
insetInputValue,
|
|
168
|
+
rangeSeparator,
|
|
169
|
+
type,
|
|
170
|
+
value: value,
|
|
171
|
+
handleInsetDateFocus: this.handleInsetDateFocus,
|
|
172
|
+
handleInsetTimeFocus: this.handleInsetTimeFocus,
|
|
173
|
+
onInsetInputChange: this.handleInsetInputChange,
|
|
174
|
+
rangeInputStartRef: this.rangeInputStartRef,
|
|
175
|
+
rangeInputEndRef: this.rangeInputEndRef,
|
|
176
|
+
density
|
|
177
|
+
};
|
|
125
178
|
return /*#__PURE__*/React.createElement("div", {
|
|
126
179
|
ref: this.panelRef,
|
|
127
180
|
className: wrapCls,
|
|
128
181
|
style: dropdownStyle
|
|
129
182
|
}, topSlot && /*#__PURE__*/React.createElement("div", {
|
|
130
183
|
className: "".concat(cssClasses.PREFIX, "-topSlot")
|
|
131
|
-
}, topSlot),
|
|
184
|
+
}, topSlot), insetInput && /*#__PURE__*/React.createElement(DateInput, _Object$assign({}, insetInputProps, {
|
|
185
|
+
insetInput: true
|
|
186
|
+
})), this.adapter.typeIsYearOrMonth() ? this.renderYearMonthPanel(locale, localeCode) : this.renderMonthGrid(locale, localeCode, dateFnsLocale), this.renderQuickControls(), bottomSlot && /*#__PURE__*/React.createElement("div", {
|
|
132
187
|
className: "".concat(cssClasses.PREFIX, "-bottomSlot")
|
|
133
188
|
}, bottomSlot), this.renderFooter(locale, localeCode));
|
|
134
189
|
};
|
|
@@ -192,7 +247,8 @@ export default class DatePicker extends BaseComponent {
|
|
|
192
247
|
position: position,
|
|
193
248
|
visible: panelShow,
|
|
194
249
|
stopPropagation: stopPropagation,
|
|
195
|
-
spacing: spacing
|
|
250
|
+
spacing: spacing,
|
|
251
|
+
onVisibleChange: this.handlePanelVisibleChange
|
|
196
252
|
}, children);
|
|
197
253
|
};
|
|
198
254
|
|
|
@@ -205,7 +261,9 @@ export default class DatePicker extends BaseComponent {
|
|
|
205
261
|
prevTimeZone: null,
|
|
206
262
|
motionEnd: false,
|
|
207
263
|
rangeInputFocus: undefined,
|
|
208
|
-
autofocus: props.autoFocus || this.isRangeType(props.type, props.triggerRender) && (props.open || props.defaultOpen)
|
|
264
|
+
autofocus: props.autoFocus || this.isRangeType(props.type, props.triggerRender) && (props.open || props.defaultOpen),
|
|
265
|
+
insetInputValue: null,
|
|
266
|
+
triggerDisabled: undefined
|
|
209
267
|
};
|
|
210
268
|
this.adapter.setCache('cachedSelectedValue', null);
|
|
211
269
|
this.triggerElRef = /*#__PURE__*/React.createRef();
|
|
@@ -308,6 +366,17 @@ export default class DatePicker extends BaseComponent {
|
|
|
308
366
|
inputValue
|
|
309
367
|
});
|
|
310
368
|
},
|
|
369
|
+
updateInsetInputValue: insetInputValue => {
|
|
370
|
+
const {
|
|
371
|
+
insetInput
|
|
372
|
+
} = this.props;
|
|
373
|
+
|
|
374
|
+
if (insetInput && !_isEqual(insetInputValue, this.state.insetInputValue)) {
|
|
375
|
+
this.setState({
|
|
376
|
+
insetInputValue
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
},
|
|
311
380
|
needConfirm: () => {
|
|
312
381
|
var _context;
|
|
313
382
|
|
|
@@ -382,7 +451,38 @@ export default class DatePicker extends BaseComponent {
|
|
|
382
451
|
}
|
|
383
452
|
},
|
|
384
453
|
couldPanelClosed: () => this.focusRecordsRef.current.rangeStart && this.focusRecordsRef.current.rangeEnd,
|
|
385
|
-
isEventTarget: e => e && e.target === e.currentTarget
|
|
454
|
+
isEventTarget: e => e && e.target === e.currentTarget,
|
|
455
|
+
setInsetInputFocus: () => {
|
|
456
|
+
const {
|
|
457
|
+
rangeInputFocus
|
|
458
|
+
} = this.state;
|
|
459
|
+
|
|
460
|
+
switch (rangeInputFocus) {
|
|
461
|
+
case 'rangeEnd':
|
|
462
|
+
if (document.activeElement !== this.rangeInputEndRef.current) {
|
|
463
|
+
const inputEndNode = _get(this, 'rangeInputEndRef.current');
|
|
464
|
+
|
|
465
|
+
inputEndNode && inputEndNode.focus();
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
break;
|
|
469
|
+
|
|
470
|
+
case 'rangeStart':
|
|
471
|
+
default:
|
|
472
|
+
if (document.activeElement !== this.rangeInputStartRef.current) {
|
|
473
|
+
const inputStartNode = _get(this, 'rangeInputStartRef.current');
|
|
474
|
+
|
|
475
|
+
inputStartNode && inputStartNode.focus();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
setTriggerDisabled: disabled => {
|
|
482
|
+
this.setState({
|
|
483
|
+
triggerDisabled: disabled
|
|
484
|
+
});
|
|
485
|
+
}
|
|
386
486
|
});
|
|
387
487
|
}
|
|
388
488
|
|
|
@@ -440,7 +540,8 @@ export default class DatePicker extends BaseComponent {
|
|
|
440
540
|
syncSwitchMonth,
|
|
441
541
|
onPanelChange,
|
|
442
542
|
timeZone,
|
|
443
|
-
triggerRender
|
|
543
|
+
triggerRender,
|
|
544
|
+
insetInput
|
|
444
545
|
} = this.props;
|
|
445
546
|
const {
|
|
446
547
|
value,
|
|
@@ -488,7 +589,8 @@ export default class DatePicker extends BaseComponent {
|
|
|
488
589
|
onPanelChange: onPanelChange,
|
|
489
590
|
timeZone: timeZone,
|
|
490
591
|
focusRecordsRef: this.focusRecordsRef,
|
|
491
|
-
triggerRender: triggerRender
|
|
592
|
+
triggerRender: triggerRender,
|
|
593
|
+
insetInput: insetInput
|
|
492
594
|
});
|
|
493
595
|
}
|
|
494
596
|
|
|
@@ -524,20 +626,23 @@ export default class DatePicker extends BaseComponent {
|
|
|
524
626
|
triggerRender,
|
|
525
627
|
size,
|
|
526
628
|
inputReadOnly,
|
|
527
|
-
rangeSeparator
|
|
629
|
+
rangeSeparator,
|
|
630
|
+
insetInput
|
|
528
631
|
} = this.props;
|
|
529
632
|
const {
|
|
530
633
|
value,
|
|
531
634
|
inputValue,
|
|
532
|
-
rangeInputFocus
|
|
635
|
+
rangeInputFocus,
|
|
636
|
+
triggerDisabled
|
|
533
637
|
} = this.state; // This class is not needed when triggerRender is function
|
|
534
638
|
|
|
535
639
|
const isRangeType = this.isRangeType(type, triggerRender);
|
|
640
|
+
const inputDisabled = disabled || insetInput && triggerDisabled;
|
|
536
641
|
const inputCls = classnames("".concat(cssClasses.PREFIX, "-input"), {
|
|
537
642
|
["".concat(cssClasses.PREFIX, "-range-input")]: isRangeType,
|
|
538
643
|
[_concatInstanceProperty(_context3 = "".concat(cssClasses.PREFIX, "-range-input-")).call(_context3, size)]: isRangeType && size,
|
|
539
|
-
["".concat(cssClasses.PREFIX, "-range-input-active")]: isRangeType && rangeInputFocus && !
|
|
540
|
-
["".concat(cssClasses.PREFIX, "-range-input-disabled")]: isRangeType &&
|
|
644
|
+
["".concat(cssClasses.PREFIX, "-range-input-active")]: isRangeType && rangeInputFocus && !inputDisabled,
|
|
645
|
+
["".concat(cssClasses.PREFIX, "-range-input-disabled")]: isRangeType && inputDisabled,
|
|
541
646
|
[_concatInstanceProperty(_context4 = "".concat(cssClasses.PREFIX, "-range-input-")).call(_context4, validateStatus)]: isRangeType && validateStatus
|
|
542
647
|
});
|
|
543
648
|
const phText = placeholder || locale.placeholder[type]; // i18n
|
|
@@ -545,9 +650,9 @@ export default class DatePicker extends BaseComponent {
|
|
|
545
650
|
|
|
546
651
|
const props = _Object$assign(_Object$assign({}, extraProps), {
|
|
547
652
|
placeholder: phText,
|
|
548
|
-
disabled,
|
|
653
|
+
disabled: inputDisabled,
|
|
549
654
|
inputValue,
|
|
550
|
-
value,
|
|
655
|
+
value: value,
|
|
551
656
|
onChange: this.handleInputChange,
|
|
552
657
|
onEnterPress: this.handleInputComplete,
|
|
553
658
|
// TODO: remove in next major version
|
|
@@ -560,7 +665,7 @@ export default class DatePicker extends BaseComponent {
|
|
|
560
665
|
format,
|
|
561
666
|
multiple,
|
|
562
667
|
validateStatus,
|
|
563
|
-
inputReadOnly,
|
|
668
|
+
inputReadOnly: inputReadOnly || insetInput,
|
|
564
669
|
// onClick: this.handleOpenPanel,
|
|
565
670
|
onBlur: this.handleInputBlur,
|
|
566
671
|
onFocus: this.handleInputFocus,
|
|
@@ -569,13 +674,13 @@ export default class DatePicker extends BaseComponent {
|
|
|
569
674
|
size,
|
|
570
675
|
autofocus: this.state.autofocus,
|
|
571
676
|
dateFnsLocale,
|
|
572
|
-
rangeInputStartRef: this.rangeInputStartRef,
|
|
573
|
-
rangeInputEndRef: this.rangeInputEndRef,
|
|
574
677
|
rangeInputFocus,
|
|
575
678
|
rangeSeparator,
|
|
576
679
|
onRangeBlur: this.handleRangeInputBlur,
|
|
577
680
|
onRangeClear: this.handleRangeInputClear,
|
|
578
|
-
onRangeEndTabPress: this.handleRangeEndTabPress
|
|
681
|
+
onRangeEndTabPress: this.handleRangeEndTabPress,
|
|
682
|
+
rangeInputStartRef: insetInput ? null : this.rangeInputStartRef,
|
|
683
|
+
rangeInputEndRef: insetInput ? null : this.rangeInputEndRef
|
|
579
684
|
});
|
|
580
685
|
|
|
581
686
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -723,5 +828,6 @@ DatePicker.defaultProps = {
|
|
|
723
828
|
spacing: numbers.SPACING,
|
|
724
829
|
autoSwitchDate: true,
|
|
725
830
|
syncSwitchMonth: false,
|
|
726
|
-
rangeSeparator: strings.DEFAULT_SEPARATOR_RANGE
|
|
831
|
+
rangeSeparator: strings.DEFAULT_SEPARATOR_RANGE,
|
|
832
|
+
insetInput: false
|
|
727
833
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
2
2
|
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/trim";
|
|
3
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
4
|
import React from 'react';
|
|
4
5
|
import { forwardStatics } from '@douyinfe/semi-foundation/lib/es/utils/object';
|
|
6
|
+
import { numbers, strings } from '@douyinfe/semi-foundation/lib/es/datePicker/constants';
|
|
5
7
|
import DatePicker from './datePicker';
|
|
6
8
|
import ConfigContext from '../configProvider/context';
|
|
7
9
|
import LocaleConsumer from '../locale/localeConsumer';
|
|
@@ -29,6 +31,24 @@ export default forwardStatics( /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
29
31
|
propsObj.rangeSeparator = " ".concat(_trimInstanceProperty(rangeSeparator).call(rangeSeparator), " ");
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
if (propsObj.insetInput) {
|
|
35
|
+
var _context;
|
|
36
|
+
|
|
37
|
+
if (!propsObj.position) {
|
|
38
|
+
propsObj.position = strings.POSITION_INLINE_INPUT;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* When insetInput is `true` and `position` includes `over`, use 1px `spacing` to solve the problem of border-radius leakage in the upper left corner
|
|
42
|
+
*
|
|
43
|
+
* @see https://user-images.githubusercontent.com/26477537/158817185-126a5f33-41f7-414a-8e36-8d1be2dda5cd.png
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if (_includesInstanceProperty(_context = propsObj.position).call(_context, 'Over') && !propsObj.spacing) {
|
|
48
|
+
propsObj.spacing = numbers.SPACING_INSET_INPUT;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
return /*#__PURE__*/React.createElement(ConfigContext.Consumer, null, _ref => {
|
|
33
53
|
let {
|
|
34
54
|
timeZone
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InsetInputValue, Type, InsetInputChangeFoundationProps } from '@douyinfe/semi-foundation/lib/es/datePicker/inputFoundation';
|
|
2
|
+
import { InputProps } from '../input';
|
|
3
|
+
export interface InsetDateInputProps {
|
|
4
|
+
forwardRef: InputProps['forwardRef'];
|
|
5
|
+
insetInputValue: InsetInputValue;
|
|
6
|
+
placeholder: string;
|
|
7
|
+
valuePath: string;
|
|
8
|
+
onChange: (options: InsetInputChangeFoundationProps) => void;
|
|
9
|
+
onFocus: InputProps['onFocus'];
|
|
10
|
+
}
|
|
11
|
+
export interface InsetTimeInputProps {
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
insetInputValue: InsetInputValue;
|
|
14
|
+
placeholder: string;
|
|
15
|
+
valuePath: string;
|
|
16
|
+
type: Type;
|
|
17
|
+
onChange: (options: InsetInputChangeFoundationProps) => void;
|
|
18
|
+
onFocus: InputProps['onFocus'];
|
|
19
|
+
}
|
|
20
|
+
export declare function InsetDateInput(props: InsetDateInputProps): JSX.Element;
|
|
21
|
+
export declare function InsetTimeInput(props: InsetTimeInputProps): JSX.Element;
|