@apdesign/web-react 1.2.0 → 1.3.1

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.
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { RangePickerHandle } from './interface';
3
- declare const PickerComponent: React.ForwardRefExoticComponent<import("./interface").BaseRangePickerProps & import("../_util/type").Omit<import("./interface").PickerProps, "onChange" | "onSelect" | "inputProps" | "onOk" | "defaultPickerValue" | "pickerValue" | "onPickerValueChange"> & React.RefAttributes<RangePickerHandle>>;
3
+ declare const PickerComponent: React.ForwardRefExoticComponent<import("./interface").BaseRangePickerProps & import("../_util/type").Omit<import("./interface").PickerProps, "onChange" | "onSelect" | "onOk" | "defaultPickerValue" | "pickerValue" | "onPickerValueChange" | "inputProps"> & React.RefAttributes<RangePickerHandle>>;
4
4
  export default PickerComponent;
@@ -6,7 +6,7 @@ export declare type HotkeyInfo = {
6
6
  type: 'sibling' | 'generation' | 'enter';
7
7
  };
8
8
  export declare type ResetHotkeyInfo = (activeKey?: string) => void;
9
- declare const MenuContext: import("react").Context<Pick<MenuProps, "collapse" | "mode" | "triggerProps" | "inDropdown" | "theme" | "levelIndent" | "icons" | "autoScrollIntoView" | "selectedKeys" | "openKeys" | "scrollConfig" | "tooltipProps"> & {
9
+ declare const MenuContext: import("react").Context<Pick<MenuProps, "collapse" | "inDropdown" | "theme" | "mode" | "levelIndent" | "icons" | "autoScrollIntoView" | "selectedKeys" | "openKeys" | "scrollConfig" | "triggerProps" | "tooltipProps"> & {
10
10
  id?: string;
11
11
  prefixCls?: string;
12
12
  onClickMenuItem?: (key: string, event: any) => void;
@@ -55,6 +55,12 @@ export interface SelectProps extends SelectViewCommonProps {
55
55
  * @en Whether to embed label in value, turn the format of value from string to `{ value: string, label: ReactNode }`
56
56
  */
57
57
  labelInValue?: boolean;
58
+ /**
59
+ * @zh 是否开启快速单选模式。开启后,由于需要最后点击确定或者取消来选择,单个选项变化的事件 onSelect 和 onDeselect 将无效
60
+ * @en Whether to enable quick single selection mode. When enabled, the onSelect and onDeselect events will be invalid because the selection needs to be confirmed or canceled at the end.
61
+ * @defaultValue true
62
+ */
63
+ isQuickSingleSelectMode?: boolean;
58
64
  /**
59
65
  * @zh 是否根据输入的值筛选数据。如果传入函数的话,接收 `inputValue` 和 `option` 两个参数,当option符合筛选条件时,返回 `true`,反之返回 `false`。
60
66
  * @en If it's true, filter options by input value. If it's a function, filter options base on the function.
@@ -245,6 +251,8 @@ export interface OptionProps extends Omit<HTMLAttributes<HTMLLIElement>, 'classN
245
251
  extra?: any;
246
252
  isSelectOption?: boolean;
247
253
  _isMultipleMode?: boolean;
254
+ _isMultipleQuickSelectMode?: boolean;
255
+ _onSingleQuickSelect?: (value: OptionProps['value']) => void;
248
256
  _isUserCreatedOption?: boolean;
249
257
  _isUserCreatingOption?: boolean;
250
258
  _valueActive?: OptionProps['value'];
@@ -20,13 +20,30 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  }
21
21
  return t;
22
22
  };
23
- import React from 'react';
23
+ var __read = (this && this.__read) || function (o, n) {
24
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
25
+ if (!m) return o;
26
+ var i = m.call(o), r, ar = [], e;
27
+ try {
28
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
+ }
30
+ catch (error) { e = { error: error }; }
31
+ finally {
32
+ try {
33
+ if (r && !r.done && (m = i["return"])) m.call(i);
34
+ }
35
+ finally { if (e) throw e.error; }
36
+ }
37
+ return ar;
38
+ };
39
+ import React, { useState } from 'react';
24
40
  import cs from '../_util/classNames';
25
41
  import Checkbox from '../Checkbox';
26
42
  import omit from '../_util/omit';
27
43
  function Option(props, ref) {
28
44
  var _a, _b;
29
- var style = props.style, className = props.className, wrapperClassName = props.wrapperClassName, disabled = props.disabled, prefixCls = props.prefixCls, rtl = props.rtl, propValue = props.value, propChildren = props.children, _isMultipleMode = props._isMultipleMode, _isUserCreatedOption = props._isUserCreatedOption, _isUserCreatingOption = props._isUserCreatingOption, _valueActive = props._valueActive, _valueSelect = props._valueSelect, _onMouseEnter = props._onMouseEnter, _onMouseLeave = props._onMouseLeave, _onClick = props._onClick, rest = __rest(props, ["style", "className", "wrapperClassName", "disabled", "prefixCls", "rtl", "value", "children", "_isMultipleMode", "_isUserCreatedOption", "_isUserCreatingOption", "_valueActive", "_valueSelect", "_onMouseEnter", "_onMouseLeave", "_onClick"]);
45
+ var style = props.style, className = props.className, wrapperClassName = props.wrapperClassName, disabled = props.disabled, prefixCls = props.prefixCls, rtl = props.rtl, propValue = props.value, propChildren = props.children, _isMultipleMode = props._isMultipleMode, _isMultipleQuickSelectMode = props._isMultipleQuickSelectMode, _onSingleQuickSelect = props._onSingleQuickSelect, _isUserCreatedOption = props._isUserCreatedOption, _isUserCreatingOption = props._isUserCreatingOption, _valueActive = props._valueActive, _valueSelect = props._valueSelect, _onMouseEnter = props._onMouseEnter, _onMouseLeave = props._onMouseLeave, _onClick = props._onClick, rest = __rest(props, ["style", "className", "wrapperClassName", "disabled", "prefixCls", "rtl", "value", "children", "_isMultipleMode", "_isMultipleQuickSelectMode", "_onSingleQuickSelect", "_isUserCreatedOption", "_isUserCreatingOption", "_valueActive", "_valueSelect", "_onMouseEnter", "_onMouseLeave", "_onClick"]);
46
+ var _c = __read(useState(false), 2), isHovering = _c[0], setIsHovering = _c[1];
30
47
  var value = 'value' in props ? propValue : "" + propChildren;
31
48
  var childNode = 'children' in props ? propChildren : "" + propValue;
32
49
  var isChecked = _isMultipleMode
@@ -61,9 +78,34 @@ function Option(props, ref) {
61
78
  return (React.createElement("li", __assign({}, wrapperProps, { className: cs(prefixCls + "-option-wrapper", (_b = {},
62
79
  _b[prefixCls + "-option-wrapper-selected"] = isChecked,
63
80
  _b[prefixCls + "-option-wrapper-disabled"] = disabled,
64
- _b), wrapperClassName) }),
81
+ _b), wrapperClassName) }, (_isMultipleQuickSelectMode && {
82
+ // TODO: 这个等主题处理好了要改成 css ,包括以下内联样式
83
+ onMouseEnter: function () { return setIsHovering(true); },
84
+ onMouseLeave: function () { return setIsHovering(false); },
85
+ style: {
86
+ position: 'relative',
87
+ },
88
+ })),
65
89
  React.createElement(Checkbox, { "aria-hidden": "true", className: prefixCls + "-checkbox", checked: isChecked, disabled: disabled, onChange: optionLabelProps.onClick }),
66
- React.createElement("span", __assign({}, optionLabelProps), childNode)));
90
+ React.createElement("div", { style: {
91
+ display: 'flex',
92
+ flex: 1,
93
+ alignItems: 'center',
94
+ overflow: 'hidden',
95
+ } },
96
+ React.createElement("span", __assign({}, optionLabelProps), childNode),
97
+ _isMultipleQuickSelectMode && !disabled && (React.createElement("span", { style: {
98
+ display: isHovering ? 'inline' : 'none',
99
+ flex: 0,
100
+ backgroundColor: 'rgb(var(--primary-6))',
101
+ cursor: 'pointer',
102
+ color: 'white',
103
+ padding: '7px',
104
+ paddingLeft: '20px',
105
+ marginLeft: '-20px',
106
+ clipPath: 'polygon(12px 50%, 0% 0%, 100% 0%, 100% 100%, 0% 100%)',
107
+ whiteSpace: 'nowrap',
108
+ }, onClick: function () { return _onSingleQuickSelect === null || _onSingleQuickSelect === void 0 ? void 0 : _onSingleQuickSelect(value); } }, "\u4EC5\u7B5B\u9009\u6B64\u9879")))));
67
109
  }
68
110
  return (React.createElement("li", __assign({}, wrapperProps, optionLabelProps), childNode));
69
111
  }
@@ -62,6 +62,7 @@ import { ConfigContext } from '../ConfigProvider';
62
62
  import useMergeValue from '../_util/hooks/useMergeValue';
63
63
  import omit from '../_util/omit';
64
64
  import useMergeProps from '../_util/hooks/useMergeProps';
65
+ import { Button } from '../index';
65
66
  import useId from '../_util/hooks/useId';
66
67
  // 用户创建中的option的origin标识
67
68
  var USER_CREATING_OPTION_ORIGIN = 'userCreatingOption';
@@ -70,13 +71,14 @@ var defaultProps = {
70
71
  bordered: true,
71
72
  filterOption: true,
72
73
  unmountOnExit: true,
74
+ isQuickSingleSelectMode: true,
73
75
  defaultActiveFirstOption: true,
74
76
  };
75
77
  var triggerPopupAlign = { bottom: 4 };
76
78
  function Select(baseProps, ref) {
77
79
  var _a = useContext(ConfigContext), getPrefixCls = _a.getPrefixCls, renderEmpty = _a.renderEmpty, componentConfig = _a.componentConfig, rtl = _a.rtl;
78
80
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Select);
79
- var children = props.children, renderFormat = props.renderFormat, defaultActiveFirstOption = props.defaultActiveFirstOption, disabled = props.disabled, unmountOnExit = props.unmountOnExit, notFoundContent = props.notFoundContent, showSearch = props.showSearch, tokenSeparators = props.tokenSeparators, options = props.options, filterOption = props.filterOption, labelInValue = props.labelInValue, getPopupContainer = props.getPopupContainer, trigger = props.trigger, triggerElement = props.triggerElement, triggerProps = props.triggerProps, dropdownRender = props.dropdownRender, dropdownMenuStyle = props.dropdownMenuStyle, dropdownMenuClassName = props.dropdownMenuClassName, virtualListProps = props.virtualListProps,
81
+ var children = props.children, renderFormat = props.renderFormat, defaultActiveFirstOption = props.defaultActiveFirstOption, disabled = props.disabled, unmountOnExit = props.unmountOnExit, notFoundContent = props.notFoundContent, showSearch = props.showSearch, tokenSeparators = props.tokenSeparators, options = props.options, filterOption = props.filterOption, labelInValue = props.labelInValue, getPopupContainer = props.getPopupContainer, isQuickSingleSelectMode = props.isQuickSingleSelectMode, trigger = props.trigger, triggerElement = props.triggerElement, triggerProps = props.triggerProps, dropdownRender = props.dropdownRender, dropdownMenuStyle = props.dropdownMenuStyle, dropdownMenuClassName = props.dropdownMenuClassName, virtualListProps = props.virtualListProps,
80
82
  // events
81
83
  onChange = props.onChange, onSelect = props.onSelect, onDeselect = props.onDeselect, onClear = props.onClear, onSearch = props.onSearch, onFocus = props.onFocus, onBlur = props.onBlur, onPopupScroll = props.onPopupScroll, onVisibleChange = props.onVisibleChange, onInputValueChange = props.onInputValueChange, onPaste = props.onPaste, onKeyDown = props.onKeyDown;
82
84
  // TODO 兼容逻辑,3.0 移除 tags 模式
@@ -88,35 +90,44 @@ function Select(baseProps, ref) {
88
90
  }
89
91
  var prefixCls = getPrefixCls('select');
90
92
  var isMultipleMode = mode === 'multiple';
93
+ var isMultipleQuickSelectMode = isMultipleMode && isQuickSingleSelectMode;
91
94
  // TODO: 统一 useMergeValue 函数的表现
92
95
  var _b = __read(useState(getValidValue(props.defaultValue, isMultipleMode, labelInValue)), 2), stateValue = _b[0], setValue = _b[1];
93
- var value = 'value' in props ? getValidValue(props.value, isMultipleMode, labelInValue) : stateValue;
94
- var _c = __read(useMergeValue('', {
96
+ var _c = __read(useState('value' in props
97
+ ? getValidValue(props.value, isMultipleMode, labelInValue)
98
+ : getValidValue(props.defaultValue, isMultipleMode, labelInValue)), 2), stateProxyValue = _c[0], setProxyValue = _c[1];
99
+ var value = 'value' in props && !isMultipleQuickSelectMode
100
+ ? getValidValue(props.value, isMultipleMode, labelInValue)
101
+ : isMultipleQuickSelectMode
102
+ ? stateProxyValue
103
+ : stateValue;
104
+ var valueForInputShow = 'value' in props ? getValidValue(props.value, isMultipleMode, labelInValue) : stateValue;
105
+ var _d = __read(useMergeValue('', {
95
106
  value: 'inputValue' in props ? props.inputValue || '' : undefined,
96
- }), 3), inputValue = _c[0], setInputValue = _c[1], stateInputValue = _c[2];
97
- var _d = __read(useMergeValue(false, {
107
+ }), 3), inputValue = _d[0], setInputValue = _d[1], stateInputValue = _d[2];
108
+ var _e = __read(useMergeValue(false, {
98
109
  defaultValue: props.defaultPopupVisible,
99
110
  value: 'popupVisible' in props
100
111
  ? props.popupVisible
101
112
  : triggerProps && 'popupVisible' in triggerProps
102
113
  ? triggerProps.popupVisible
103
114
  : undefined,
104
- }), 2), popupVisible = _d[0], setPopupVisible = _d[1];
115
+ }), 2), popupVisible = _e[0], setPopupVisible = _e[1];
105
116
  // allowCreate 时,用户正在创建的选项值
106
- var _e = __read(useState(null), 2), userCreatingOption = _e[0], setUserCreatingOption = _e[1];
117
+ var _f = __read(useState(null), 2), userCreatingOption = _f[0], setUserCreatingOption = _f[1];
107
118
  // allowCreate 时,由用户输入而扩展到选项中的值
108
- var _f = __read(useState([]), 2), userCreatedOptions = _f[0], setUserCreatedOptions = _f[1];
119
+ var _g = __read(useState([]), 2), userCreatedOptions = _g[0], setUserCreatedOptions = _g[1];
109
120
  // 具有选中态或者 hover 态的 option 的 value
110
- var _g = __read(useState(isArray(value) ? value[0] : value), 2), valueActive = _g[0], setValueActive = _g[1];
121
+ var _h = __read(useState(isArray(value) ? value[0] : value), 2), valueActive = _h[0], setValueActive = _h[1];
111
122
  // 缓存较为耗时的 flatChildren 的结果
112
- var _h = useMemo(function () {
123
+ var _j = useMemo(function () {
113
124
  return flatChildren({ children: children, options: options, filterOption: filterOption }, {
114
125
  prefixCls: prefixCls,
115
126
  inputValue: inputValue,
116
127
  userCreatedOptions: userCreatedOptions,
117
128
  userCreatingOption: userCreatingOption,
118
129
  });
119
- }, [children, options, filterOption, inputValue, userCreatingOption, userCreatedOptions]), childrenList = _h.childrenList, optionInfoMap = _h.optionInfoMap, optionValueList = _h.optionValueList, optionIndexListForArrowKey = _h.optionIndexListForArrowKey, hasOptGroup = _h.hasOptGroup, hasComplexLabelInOptions = _h.hasComplexLabelInOptions;
130
+ }, [children, options, filterOption, inputValue, userCreatingOption, userCreatedOptions]), childrenList = _j.childrenList, optionInfoMap = _j.optionInfoMap, optionValueList = _j.optionValueList, optionIndexListForArrowKey = _j.optionIndexListForArrowKey, hasOptGroup = _j.hasOptGroup, hasComplexLabelInOptions = _j.hasComplexLabelInOptions;
120
131
  // ref
121
132
  var refWrapper = useRef(null);
122
133
  var refTrigger = useRef(null);
@@ -194,10 +205,12 @@ function Select(baseProps, ref) {
194
205
  if (isMultipleMode) {
195
206
  if (!Array.isArray(value)) {
196
207
  setValue(value === undefined ? [] : [value]);
208
+ setProxyValue(value === undefined ? [] : [value]);
197
209
  }
198
210
  }
199
211
  else if (Array.isArray(value)) {
200
212
  setValue(value.length === 0 ? undefined : value[0]);
213
+ setProxyValue(value.length === 0 ? undefined : value[0]);
201
214
  }
202
215
  }, [isMultipleMode, value]);
203
216
  // 选项下拉框显示/隐藏时的一些自动行为
@@ -371,21 +384,60 @@ function Select(baseProps, ref) {
371
384
  onChange(paramsForCallback.value, paramsForCallback.option);
372
385
  }
373
386
  };
374
- // 多选时,选择/取消选择一个选项
375
- var checkOption = function (optionValue, operation) {
387
+ var tryUpdateProxySelectValue = function (value) {
388
+ setProxyValue(value);
389
+ };
390
+ // 多选时,选择/取消选择一个选项。 fromTag 为 true 时,表示从input tag标签触发取消选择
391
+ var checkOption = function (optionValue, operation, fromTag) {
392
+ if (fromTag === void 0) { fromTag = false; }
376
393
  // 取消选中时不需要检查option是否存在,因为可能已被外部剔除了此选项
377
394
  if (operation === 'remove' || (operation === 'add' && optionInfoMap.get(optionValue))) {
378
395
  var newValue = operation === 'add'
379
396
  ? value.concat(optionValue)
380
397
  : value.filter(function (v) { return v !== optionValue; });
381
398
  var callbackToTrigger = operation === 'add' ? onSelect : onDeselect;
382
- tryUpdateSelectValue(newValue);
383
399
  if (typeof callbackToTrigger === 'function') {
384
400
  var paramsForCallback = getValueAndOptionForCallback(optionValue, false);
385
401
  callbackToTrigger(paramsForCallback.value, paramsForCallback.option);
386
402
  }
403
+ // 如果是快速单选模式,更新代理值
404
+ if (isMultipleQuickSelectMode) {
405
+ tryUpdateProxySelectValue(newValue);
406
+ if (fromTag) {
407
+ if (popupVisible) {
408
+ tryUpdatePopupVisible(false);
409
+ var _newValue = operation === 'add'
410
+ ? stateValue.concat(optionValue)
411
+ : stateValue.filter(function (v) { return v !== optionValue; });
412
+ tryUpdateSelectValue(_newValue);
413
+ setProxyValue(_newValue);
414
+ }
415
+ else {
416
+ tryUpdateSelectValue(newValue);
417
+ }
418
+ }
419
+ }
420
+ else {
421
+ tryUpdateSelectValue(newValue);
422
+ }
387
423
  }
388
424
  };
425
+ // 多选时,确定
426
+ var confirmCheck = function () {
427
+ tryUpdateSelectValue(stateProxyValue);
428
+ tryUpdatePopupVisible(false);
429
+ };
430
+ // 多选时,取消
431
+ var cancelCheck = function () {
432
+ tryUpdateProxySelectValue(stateValue);
433
+ tryUpdatePopupVisible(false);
434
+ };
435
+ // 多选时候快速只选一个
436
+ var handleSingleQuickSelect = function (optionValue) {
437
+ tryUpdatePopupVisible(false);
438
+ tryUpdateProxySelectValue([optionValue]);
439
+ tryUpdateSelectValue([optionValue]);
440
+ };
389
441
  var handleOptionClick = function (optionValue, disabled) {
390
442
  if (disabled) {
391
443
  return;
@@ -457,41 +509,53 @@ function Select(baseProps, ref) {
457
509
  var needForbidVirtual = needMeasureLongestItem && hasComplexLabelInOptions;
458
510
  var mergedNotFoundContent = 'notFoundContent' in props ? notFoundContent : renderEmpty('Select');
459
511
  // 选项列表元素
460
- var eleOptionList = childrenList.length ? (React.createElement(VirtualList, __assign({ id: instancePopupID, role: "listbox", style: dropdownMenuStyle, className: cs(prefixCls + "-popup-inner", dropdownMenuClassName), ref: refWrapper, data: childrenList, height: null, isStaticItemHeight: !hasOptGroup, measureLongestItem: needMeasureLongestItem, itemKey: function (child) { return child.props._key; }, onMouseDown: preventDefaultEvent, onMouseMove: function () {
461
- refKeyboardArrowDirection.current = null;
462
- }, onScroll: function (e) { return onPopupScroll && onPopupScroll(e.target); } }, virtualListProps, { threshold: needForbidVirtual ? null : virtualListProps === null || virtualListProps === void 0 ? void 0 : virtualListProps.threshold }), function (child) {
463
- var _a;
464
- if (isSelectOptGroup(child)) {
465
- return React.createElement(child.type, __assign({}, child.props, { prefixCls: prefixCls }));
466
- }
467
- if (isSelectOption(child)) {
468
- var optionValue = (_a = child.props) === null || _a === void 0 ? void 0 : _a.value;
469
- var userCreatingOptionValue = isObject(userCreatingOption)
470
- ? userCreatingOption.value
471
- : userCreatingOption;
472
- var userCreatedOptionValues = userCreatedOptions.map(function (op) {
473
- return isObject(op) ? op.value : op;
474
- });
475
- var optionProps = {
476
- prefixCls: prefixCls,
477
- rtl: rtl,
478
- _valueActive: valueActive,
479
- _valueSelect: value,
480
- _isMultipleMode: isMultipleMode,
481
- _isUserCreatingOption: allowCreate && userCreatingOptionValue === optionValue,
482
- _isUserCreatedOption: allowCreate && userCreatedOptionValues.indexOf(optionValue) > -1,
483
- _onClick: handleOptionClick,
484
- _onMouseEnter: function (value) {
485
- refKeyboardArrowDirection.current === null && setValueActive(value);
486
- },
487
- _onMouseLeave: function () {
488
- refKeyboardArrowDirection.current === null && setValueActive(undefined);
489
- },
490
- };
491
- return child && React.createElement(child.type, __assign({}, child.props, optionProps));
492
- }
493
- return child;
494
- })) : null;
512
+ var eleOptionList = childrenList.length ? (React.createElement(React.Fragment, null,
513
+ React.createElement(VirtualList, __assign({ id: instancePopupID, role: "listbox", style: dropdownMenuStyle, className: cs(prefixCls + "-popup-inner", dropdownMenuClassName), ref: refWrapper, data: childrenList, height: null, isStaticItemHeight: !hasOptGroup, measureLongestItem: needMeasureLongestItem, itemKey: function (child) { return child.props._key; }, onMouseDown: preventDefaultEvent, onMouseMove: function () {
514
+ refKeyboardArrowDirection.current = null;
515
+ }, onScroll: function (e) { return onPopupScroll && onPopupScroll(e.target); } }, virtualListProps, { threshold: needForbidVirtual ? null : virtualListProps === null || virtualListProps === void 0 ? void 0 : virtualListProps.threshold }), function (child) {
516
+ var _a;
517
+ if (isSelectOptGroup(child)) {
518
+ return React.createElement(child.type, __assign({}, child.props, { prefixCls: prefixCls }));
519
+ }
520
+ if (isSelectOption(child)) {
521
+ var optionValue = (_a = child.props) === null || _a === void 0 ? void 0 : _a.value;
522
+ var userCreatingOptionValue = isObject(userCreatingOption)
523
+ ? userCreatingOption.value
524
+ : userCreatingOption;
525
+ var userCreatedOptionValues = userCreatedOptions.map(function (op) {
526
+ return isObject(op) ? op.value : op;
527
+ });
528
+ var optionProps = {
529
+ prefixCls: prefixCls,
530
+ rtl: rtl,
531
+ _valueActive: valueActive,
532
+ _valueSelect: value,
533
+ _isMultipleMode: isMultipleMode,
534
+ _isMultipleQuickSelectMode: isMultipleQuickSelectMode,
535
+ _onSingleQuickSelect: handleSingleQuickSelect,
536
+ _isUserCreatingOption: allowCreate && userCreatingOptionValue === optionValue,
537
+ _isUserCreatedOption: allowCreate && userCreatedOptionValues.indexOf(optionValue) > -1,
538
+ _onClick: handleOptionClick,
539
+ _onMouseEnter: function (value) {
540
+ refKeyboardArrowDirection.current === null && setValueActive(value);
541
+ },
542
+ _onMouseLeave: function () {
543
+ refKeyboardArrowDirection.current === null && setValueActive(undefined);
544
+ },
545
+ };
546
+ return child && React.createElement(child.type, __assign({}, child.props, optionProps));
547
+ }
548
+ return child;
549
+ }),
550
+ isMultipleQuickSelectMode && (React.createElement("div", { style: {
551
+ display: 'flex',
552
+ justifyContent: 'flex-end',
553
+ gap: 12,
554
+ padding: '8px 16px 4px',
555
+ borderTop: '1px solid var(--color-fill-3)',
556
+ } },
557
+ React.createElement(Button, { size: "mini", onClick: cancelCheck }, "\u53D6\u6D88"),
558
+ React.createElement(Button, { type: "primary", size: "mini", onClick: confirmCheck }, "\u786E\u5B9A"))))) : null;
495
559
  // Avoid drop-down box jitter when user is creating a selection
496
560
  var isUserCreating = allowCreate && inputValue;
497
561
  // Dropdown-placeholder when there is no options
@@ -579,7 +643,7 @@ function Select(baseProps, ref) {
579
643
  // Option Items
580
644
  onRemoveCheckedItem: function (_, index, event) {
581
645
  event.stopPropagation();
582
- checkOption(value[index], 'remove');
646
+ checkOption(value[index], 'remove', true);
583
647
  },
584
648
  onClear: function (event) {
585
649
  event.stopPropagation();
@@ -617,7 +681,12 @@ function Select(baseProps, ref) {
617
681
  });
618
682
  }, [hotkeyHandler, optionInfoMap, valueActive, getOptionInfoByValue, scrollIntoView]);
619
683
  var renderView = function (eleView) {
620
- return (React.createElement(Trigger, __assign({ ref: function (ref) { return (refTrigger.current = ref); }, popup: renderPopup, trigger: trigger, disabled: disabled, getPopupContainer: getPopupContainer, classNames: "slideDynamicOrigin", autoAlignPopupWidth: true, popupAlign: triggerPopupAlign, popupVisible: popupVisible, unmountOnExit: unmountOnExit, onVisibleChange: tryUpdatePopupVisible, __onExit: function () {
684
+ return (React.createElement(Trigger, __assign({ ref: function (ref) { return (refTrigger.current = ref); }, popup: renderPopup, trigger: trigger, disabled: disabled, getPopupContainer: getPopupContainer, classNames: "slideDynamicOrigin", autoAlignPopupWidth: true, popupAlign: triggerPopupAlign, popupVisible: popupVisible, unmountOnExit: unmountOnExit, onVisibleChange: function (visible) {
685
+ if (visible === false && isMultipleQuickSelectMode) {
686
+ setProxyValue(stateValue);
687
+ }
688
+ tryUpdatePopupVisible(visible);
689
+ }, __onExit: function () {
621
690
  refPopupExiting.current = true;
622
691
  }, __onExited: function () {
623
692
  refPopupExiting.current = false;
@@ -629,7 +698,7 @@ function Select(baseProps, ref) {
629
698
  : triggerElement;
630
699
  return (React.createElement(ResizeObserver, { onResize: function () { return refTrigger.current.updatePopupPosition(); } }, usedTriggerElement !== undefined && usedTriggerElement !== null ? (renderView(usedTriggerElement)) : (React.createElement(SelectView, __assign({}, props, selectViewEventHandlers, { ref: refSelectView,
631
700
  // state
632
- value: value, inputValue: inputValue, popupVisible: popupVisible,
701
+ value: valueForInputShow, inputValue: inputValue, popupVisible: popupVisible,
633
702
  // other
634
703
  rtl: rtl, prefixCls: prefixCls, allowCreate: !!allowCreate, ariaControls: instancePopupID, isEmptyValue: isNoOptionSelected, isMultiple: isMultipleMode, onSort: tryUpdateSelectValue, renderText: function (value) {
635
704
  var option = getOptionInfoByValue(value);
package/es/index.d.ts CHANGED
@@ -139,4 +139,4 @@ export type { WatermarkProps } from './Watermark/interface';
139
139
  export { default as Watermark } from './Watermark';
140
140
  export type { ImageProps, ImagePreviewProps, ImagePreviewActionProps, ImagePreviewGroupProps } from './Image/interface';
141
141
  export { default as Image } from './Image';
142
- export declare const version = "1.2.0";
142
+ export declare const version = "1.3.1";
package/es/index.js CHANGED
@@ -69,4 +69,4 @@ export { default as Upload } from './Upload';
69
69
  export { default as Mentions } from './Mentions';
70
70
  export { default as Watermark } from './Watermark';
71
71
  export { default as Image } from './Image';
72
- export var version = '1.2.0';
72
+ export var version = '1.3.1';
@@ -55,6 +55,12 @@ export interface SelectProps extends SelectViewCommonProps {
55
55
  * @en Whether to embed label in value, turn the format of value from string to `{ value: string, label: ReactNode }`
56
56
  */
57
57
  labelInValue?: boolean;
58
+ /**
59
+ * @zh 是否开启快速单选模式。开启后,由于需要最后点击确定或者取消来选择,单个选项变化的事件 onSelect 和 onDeselect 将无效
60
+ * @en Whether to enable quick single selection mode. When enabled, the onSelect and onDeselect events will be invalid because the selection needs to be confirmed or canceled at the end.
61
+ * @defaultValue true
62
+ */
63
+ isQuickSingleSelectMode?: boolean;
58
64
  /**
59
65
  * @zh 是否根据输入的值筛选数据。如果传入函数的话,接收 `inputValue` 和 `option` 两个参数,当option符合筛选条件时,返回 `true`,反之返回 `false`。
60
66
  * @en If it's true, filter options by input value. If it's a function, filter options base on the function.
@@ -245,6 +251,8 @@ export interface OptionProps extends Omit<HTMLAttributes<HTMLLIElement>, 'classN
245
251
  extra?: any;
246
252
  isSelectOption?: boolean;
247
253
  _isMultipleMode?: boolean;
254
+ _isMultipleQuickSelectMode?: boolean;
255
+ _onSingleQuickSelect?: (value: OptionProps['value']) => void;
248
256
  _isUserCreatedOption?: boolean;
249
257
  _isUserCreatingOption?: boolean;
250
258
  _valueActive?: OptionProps['value'];
@@ -10,6 +10,25 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
13
32
  var __rest = (this && this.__rest) || function (s, e) {
14
33
  var t = {};
15
34
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -21,17 +40,34 @@ var __rest = (this && this.__rest) || function (s, e) {
21
40
  }
22
41
  return t;
23
42
  };
43
+ var __read = (this && this.__read) || function (o, n) {
44
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
45
+ if (!m) return o;
46
+ var i = m.call(o), r, ar = [], e;
47
+ try {
48
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
49
+ }
50
+ catch (error) { e = { error: error }; }
51
+ finally {
52
+ try {
53
+ if (r && !r.done && (m = i["return"])) m.call(i);
54
+ }
55
+ finally { if (e) throw e.error; }
56
+ }
57
+ return ar;
58
+ };
24
59
  var __importDefault = (this && this.__importDefault) || function (mod) {
25
60
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
61
  };
27
62
  Object.defineProperty(exports, "__esModule", { value: true });
28
- var react_1 = __importDefault(require("react"));
63
+ var react_1 = __importStar(require("react"));
29
64
  var classNames_1 = __importDefault(require("../_util/classNames"));
30
65
  var Checkbox_1 = __importDefault(require("../Checkbox"));
31
66
  var omit_1 = __importDefault(require("../_util/omit"));
32
67
  function Option(props, ref) {
33
68
  var _a, _b;
34
- var style = props.style, className = props.className, wrapperClassName = props.wrapperClassName, disabled = props.disabled, prefixCls = props.prefixCls, rtl = props.rtl, propValue = props.value, propChildren = props.children, _isMultipleMode = props._isMultipleMode, _isUserCreatedOption = props._isUserCreatedOption, _isUserCreatingOption = props._isUserCreatingOption, _valueActive = props._valueActive, _valueSelect = props._valueSelect, _onMouseEnter = props._onMouseEnter, _onMouseLeave = props._onMouseLeave, _onClick = props._onClick, rest = __rest(props, ["style", "className", "wrapperClassName", "disabled", "prefixCls", "rtl", "value", "children", "_isMultipleMode", "_isUserCreatedOption", "_isUserCreatingOption", "_valueActive", "_valueSelect", "_onMouseEnter", "_onMouseLeave", "_onClick"]);
69
+ var style = props.style, className = props.className, wrapperClassName = props.wrapperClassName, disabled = props.disabled, prefixCls = props.prefixCls, rtl = props.rtl, propValue = props.value, propChildren = props.children, _isMultipleMode = props._isMultipleMode, _isMultipleQuickSelectMode = props._isMultipleQuickSelectMode, _onSingleQuickSelect = props._onSingleQuickSelect, _isUserCreatedOption = props._isUserCreatedOption, _isUserCreatingOption = props._isUserCreatingOption, _valueActive = props._valueActive, _valueSelect = props._valueSelect, _onMouseEnter = props._onMouseEnter, _onMouseLeave = props._onMouseLeave, _onClick = props._onClick, rest = __rest(props, ["style", "className", "wrapperClassName", "disabled", "prefixCls", "rtl", "value", "children", "_isMultipleMode", "_isMultipleQuickSelectMode", "_onSingleQuickSelect", "_isUserCreatedOption", "_isUserCreatingOption", "_valueActive", "_valueSelect", "_onMouseEnter", "_onMouseLeave", "_onClick"]);
70
+ var _c = __read((0, react_1.useState)(false), 2), isHovering = _c[0], setIsHovering = _c[1];
35
71
  var value = 'value' in props ? propValue : "" + propChildren;
36
72
  var childNode = 'children' in props ? propChildren : "" + propValue;
37
73
  var isChecked = _isMultipleMode
@@ -66,9 +102,34 @@ function Option(props, ref) {
66
102
  return (react_1.default.createElement("li", __assign({}, wrapperProps, { className: (0, classNames_1.default)(prefixCls + "-option-wrapper", (_b = {},
67
103
  _b[prefixCls + "-option-wrapper-selected"] = isChecked,
68
104
  _b[prefixCls + "-option-wrapper-disabled"] = disabled,
69
- _b), wrapperClassName) }),
105
+ _b), wrapperClassName) }, (_isMultipleQuickSelectMode && {
106
+ // TODO: 这个等主题处理好了要改成 css ,包括以下内联样式
107
+ onMouseEnter: function () { return setIsHovering(true); },
108
+ onMouseLeave: function () { return setIsHovering(false); },
109
+ style: {
110
+ position: 'relative',
111
+ },
112
+ })),
70
113
  react_1.default.createElement(Checkbox_1.default, { "aria-hidden": "true", className: prefixCls + "-checkbox", checked: isChecked, disabled: disabled, onChange: optionLabelProps.onClick }),
71
- react_1.default.createElement("span", __assign({}, optionLabelProps), childNode)));
114
+ react_1.default.createElement("div", { style: {
115
+ display: 'flex',
116
+ flex: 1,
117
+ alignItems: 'center',
118
+ overflow: 'hidden',
119
+ } },
120
+ react_1.default.createElement("span", __assign({}, optionLabelProps), childNode),
121
+ _isMultipleQuickSelectMode && !disabled && (react_1.default.createElement("span", { style: {
122
+ display: isHovering ? 'inline' : 'none',
123
+ flex: 0,
124
+ backgroundColor: 'rgb(var(--primary-6))',
125
+ cursor: 'pointer',
126
+ color: 'white',
127
+ padding: '7px',
128
+ paddingLeft: '20px',
129
+ marginLeft: '-20px',
130
+ clipPath: 'polygon(12px 50%, 0% 0%, 100% 0%, 100% 100%, 0% 100%)',
131
+ whiteSpace: 'nowrap',
132
+ }, onClick: function () { return _onSingleQuickSelect === null || _onSingleQuickSelect === void 0 ? void 0 : _onSingleQuickSelect(value); } }, "\u4EC5\u7B5B\u9009\u6B64\u9879")))));
72
133
  }
73
134
  return (react_1.default.createElement("li", __assign({}, wrapperProps, optionLabelProps), childNode));
74
135
  }