@rc-component/select 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +191 -0
  3. package/assets/index.css +306 -0
  4. package/assets/index.less +397 -0
  5. package/es/BaseSelect/Polite.d.ts +7 -0
  6. package/es/BaseSelect/Polite.js +26 -0
  7. package/es/BaseSelect/index.d.ts +118 -0
  8. package/es/BaseSelect/index.js +569 -0
  9. package/es/OptGroup.d.ts +12 -0
  10. package/es/OptGroup.js +6 -0
  11. package/es/Option.d.ts +14 -0
  12. package/es/Option.js +6 -0
  13. package/es/OptionList.d.ts +10 -0
  14. package/es/OptionList.js +379 -0
  15. package/es/Select.d.ts +114 -0
  16. package/es/Select.js +480 -0
  17. package/es/SelectContext.d.ts +23 -0
  18. package/es/SelectContext.js +6 -0
  19. package/es/SelectTrigger.d.ts +30 -0
  20. package/es/SelectTrigger.js +138 -0
  21. package/es/Selector/Input.d.ts +27 -0
  22. package/es/Selector/Input.js +114 -0
  23. package/es/Selector/MultipleSelector.d.ts +16 -0
  24. package/es/Selector/MultipleSelector.js +185 -0
  25. package/es/Selector/SingleSelector.d.ts +8 -0
  26. package/es/Selector/SingleSelector.js +104 -0
  27. package/es/Selector/index.d.ts +85 -0
  28. package/es/Selector/index.js +184 -0
  29. package/es/TransBtn.d.ts +12 -0
  30. package/es/TransBtn.js +30 -0
  31. package/es/hooks/useAllowClear.d.ts +8 -0
  32. package/es/hooks/useAllowClear.js +26 -0
  33. package/es/hooks/useBaseProps.d.ts +13 -0
  34. package/es/hooks/useBaseProps.js +10 -0
  35. package/es/hooks/useCache.d.ts +7 -0
  36. package/es/hooks/useCache.js +40 -0
  37. package/es/hooks/useDelayReset.d.ts +5 -0
  38. package/es/hooks/useDelayReset.js +24 -0
  39. package/es/hooks/useFilterOptions.d.ts +3 -0
  40. package/es/hooks/useFilterOptions.js +57 -0
  41. package/es/hooks/useId.d.ts +5 -0
  42. package/es/hooks/useId.js +29 -0
  43. package/es/hooks/useLayoutEffect.d.ts +5 -0
  44. package/es/hooks/useLayoutEffect.js +17 -0
  45. package/es/hooks/useLock.d.ts +7 -0
  46. package/es/hooks/useLock.js +27 -0
  47. package/es/hooks/useOptions.d.ts +12 -0
  48. package/es/hooks/useOptions.js +45 -0
  49. package/es/hooks/useRefFunc.d.ts +5 -0
  50. package/es/hooks/useRefFunc.js +14 -0
  51. package/es/hooks/useSelectTriggerControl.d.ts +1 -0
  52. package/es/hooks/useSelectTriggerControl.js +27 -0
  53. package/es/index.d.ts +10 -0
  54. package/es/index.js +7 -0
  55. package/es/interface.d.ts +23 -0
  56. package/es/interface.js +1 -0
  57. package/es/utils/__mocks__/platformUtil.d.ts +1 -0
  58. package/es/utils/__mocks__/platformUtil.js +3 -0
  59. package/es/utils/commonUtil.d.ts +9 -0
  60. package/es/utils/commonUtil.js +32 -0
  61. package/es/utils/keyUtil.d.ts +2 -0
  62. package/es/utils/keyUtil.js +16 -0
  63. package/es/utils/legacyUtil.d.ts +3 -0
  64. package/es/utils/legacyUtil.js +44 -0
  65. package/es/utils/platformUtil.d.ts +1 -0
  66. package/es/utils/platformUtil.js +4 -0
  67. package/es/utils/valueUtil.d.ts +24 -0
  68. package/es/utils/valueUtil.js +128 -0
  69. package/es/utils/warningPropsUtil.d.ts +4 -0
  70. package/es/utils/warningPropsUtil.js +119 -0
  71. package/lib/BaseSelect/Polite.d.ts +7 -0
  72. package/lib/BaseSelect/Polite.js +34 -0
  73. package/lib/BaseSelect/index.d.ts +118 -0
  74. package/lib/BaseSelect/index.js +579 -0
  75. package/lib/OptGroup.d.ts +12 -0
  76. package/lib/OptGroup.js +12 -0
  77. package/lib/Option.d.ts +14 -0
  78. package/lib/Option.js +12 -0
  79. package/lib/OptionList.d.ts +10 -0
  80. package/lib/OptionList.js +387 -0
  81. package/lib/Select.d.ts +114 -0
  82. package/lib/Select.js +487 -0
  83. package/lib/SelectContext.d.ts +23 -0
  84. package/lib/SelectContext.js +13 -0
  85. package/lib/SelectTrigger.d.ts +30 -0
  86. package/lib/SelectTrigger.js +147 -0
  87. package/lib/Selector/Input.d.ts +27 -0
  88. package/lib/Selector/Input.js +123 -0
  89. package/lib/Selector/MultipleSelector.d.ts +16 -0
  90. package/lib/Selector/MultipleSelector.js +194 -0
  91. package/lib/Selector/SingleSelector.d.ts +8 -0
  92. package/lib/Selector/SingleSelector.js +113 -0
  93. package/lib/Selector/index.d.ts +85 -0
  94. package/lib/Selector/index.js +191 -0
  95. package/lib/TransBtn.d.ts +12 -0
  96. package/lib/TransBtn.js +39 -0
  97. package/lib/hooks/useAllowClear.d.ts +8 -0
  98. package/lib/hooks/useAllowClear.js +34 -0
  99. package/lib/hooks/useBaseProps.d.ts +13 -0
  100. package/lib/hooks/useBaseProps.js +19 -0
  101. package/lib/hooks/useCache.d.ts +7 -0
  102. package/lib/hooks/useCache.js +49 -0
  103. package/lib/hooks/useDelayReset.d.ts +5 -0
  104. package/lib/hooks/useDelayReset.js +31 -0
  105. package/lib/hooks/useFilterOptions.d.ts +3 -0
  106. package/lib/hooks/useFilterOptions.js +66 -0
  107. package/lib/hooks/useId.d.ts +5 -0
  108. package/lib/hooks/useId.js +40 -0
  109. package/lib/hooks/useLayoutEffect.d.ts +5 -0
  110. package/lib/hooks/useLayoutEffect.js +25 -0
  111. package/lib/hooks/useLock.d.ts +7 -0
  112. package/lib/hooks/useLock.js +34 -0
  113. package/lib/hooks/useOptions.d.ts +12 -0
  114. package/lib/hooks/useOptions.js +52 -0
  115. package/lib/hooks/useRefFunc.d.ts +5 -0
  116. package/lib/hooks/useRefFunc.js +21 -0
  117. package/lib/hooks/useSelectTriggerControl.d.ts +1 -0
  118. package/lib/hooks/useSelectTriggerControl.js +35 -0
  119. package/lib/index.d.ts +10 -0
  120. package/lib/index.js +37 -0
  121. package/lib/interface.d.ts +23 -0
  122. package/lib/interface.js +5 -0
  123. package/lib/utils/__mocks__/platformUtil.d.ts +1 -0
  124. package/lib/utils/__mocks__/platformUtil.js +9 -0
  125. package/lib/utils/commonUtil.d.ts +9 -0
  126. package/lib/utils/commonUtil.js +42 -0
  127. package/lib/utils/keyUtil.d.ts +2 -0
  128. package/lib/utils/keyUtil.js +22 -0
  129. package/lib/utils/legacyUtil.d.ts +3 -0
  130. package/lib/utils/legacyUtil.js +53 -0
  131. package/lib/utils/platformUtil.d.ts +1 -0
  132. package/lib/utils/platformUtil.js +10 -0
  133. package/lib/utils/valueUtil.d.ts +24 -0
  134. package/lib/utils/valueUtil.js +140 -0
  135. package/lib/utils/warningPropsUtil.d.ts +4 -0
  136. package/lib/utils/warningPropsUtil.js +129 -0
  137. package/package.json +86 -0
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _trigger = _interopRequireDefault(require("@rc-component/trigger"));
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var React = _interopRequireWildcard(require("react"));
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
14
+ const getBuiltInPlacements = popupMatchSelectWidth => {
15
+ // Enable horizontal overflow auto-adjustment when a custom dropdown width is provided
16
+ const adjustX = popupMatchSelectWidth === true ? 0 : 1;
17
+ return {
18
+ bottomLeft: {
19
+ points: ['tl', 'bl'],
20
+ offset: [0, 4],
21
+ overflow: {
22
+ adjustX,
23
+ adjustY: 1
24
+ },
25
+ htmlRegion: 'scroll'
26
+ },
27
+ bottomRight: {
28
+ points: ['tr', 'br'],
29
+ offset: [0, 4],
30
+ overflow: {
31
+ adjustX,
32
+ adjustY: 1
33
+ },
34
+ htmlRegion: 'scroll'
35
+ },
36
+ topLeft: {
37
+ points: ['bl', 'tl'],
38
+ offset: [0, -4],
39
+ overflow: {
40
+ adjustX,
41
+ adjustY: 1
42
+ },
43
+ htmlRegion: 'scroll'
44
+ },
45
+ topRight: {
46
+ points: ['br', 'tr'],
47
+ offset: [0, -4],
48
+ overflow: {
49
+ adjustX,
50
+ adjustY: 1
51
+ },
52
+ htmlRegion: 'scroll'
53
+ }
54
+ };
55
+ };
56
+ const SelectTrigger = (props, ref) => {
57
+ const {
58
+ prefixCls,
59
+ disabled,
60
+ visible,
61
+ children,
62
+ popupElement,
63
+ animation,
64
+ transitionName,
65
+ popupStyle,
66
+ popupClassName,
67
+ direction = 'ltr',
68
+ placement,
69
+ builtinPlacements,
70
+ popupMatchSelectWidth,
71
+ popupRender,
72
+ popupAlign,
73
+ getPopupContainer,
74
+ empty,
75
+ getTriggerDOMNode,
76
+ onPopupVisibleChange,
77
+ onPopupMouseEnter,
78
+ ...restProps
79
+ } = props;
80
+
81
+ // We still use `dropdown` className to keep compatibility
82
+ // This is used for:
83
+ // 1. Styles
84
+ // 2. Animation
85
+ // 3. Theme customization
86
+ // Please do not modify this since it's a breaking change
87
+ const popupPrefixCls = `${prefixCls}-dropdown`;
88
+ let popupNode = popupElement;
89
+ if (popupRender) {
90
+ popupNode = popupRender(popupElement);
91
+ }
92
+ const mergedBuiltinPlacements = React.useMemo(() => builtinPlacements || getBuiltInPlacements(popupMatchSelectWidth), [builtinPlacements, popupMatchSelectWidth]);
93
+
94
+ // ===================== Motion ======================
95
+ const mergedTransitionName = animation ? `${popupPrefixCls}-${animation}` : transitionName;
96
+
97
+ // =================== Popup Width ===================
98
+ const isNumberPopupWidth = typeof popupMatchSelectWidth === 'number';
99
+ const stretch = React.useMemo(() => {
100
+ if (isNumberPopupWidth) {
101
+ return null;
102
+ }
103
+ return popupMatchSelectWidth === false ? 'minWidth' : 'width';
104
+ }, [popupMatchSelectWidth, isNumberPopupWidth]);
105
+ let mergedPopupStyle = popupStyle;
106
+ if (isNumberPopupWidth) {
107
+ mergedPopupStyle = {
108
+ ...popupStyle,
109
+ width: popupMatchSelectWidth
110
+ };
111
+ }
112
+
113
+ // ======================= Ref =======================
114
+ const triggerPopupRef = React.useRef(null);
115
+ React.useImperativeHandle(ref, () => ({
116
+ getPopupElement: () => triggerPopupRef.current?.popupElement
117
+ }));
118
+ return /*#__PURE__*/React.createElement(_trigger.default, _extends({}, restProps, {
119
+ showAction: onPopupVisibleChange ? ['click'] : [],
120
+ hideAction: onPopupVisibleChange ? ['click'] : [],
121
+ popupPlacement: placement || (direction === 'rtl' ? 'bottomRight' : 'bottomLeft'),
122
+ builtinPlacements: mergedBuiltinPlacements,
123
+ prefixCls: popupPrefixCls,
124
+ popupMotion: {
125
+ motionName: mergedTransitionName
126
+ },
127
+ popup: /*#__PURE__*/React.createElement("div", {
128
+ onMouseEnter: onPopupMouseEnter
129
+ }, popupNode),
130
+ ref: triggerPopupRef,
131
+ stretch: stretch,
132
+ popupAlign: popupAlign,
133
+ popupVisible: visible,
134
+ getPopupContainer: getPopupContainer,
135
+ popupClassName: (0, _classnames.default)(popupClassName, {
136
+ [`${popupPrefixCls}-empty`]: empty
137
+ }),
138
+ popupStyle: mergedPopupStyle,
139
+ getTriggerDOMNode: getTriggerDOMNode,
140
+ onPopupVisibleChange: onPopupVisibleChange
141
+ }), children);
142
+ };
143
+ const RefSelectTrigger = /*#__PURE__*/React.forwardRef(SelectTrigger);
144
+ if (process.env.NODE_ENV !== 'production') {
145
+ RefSelectTrigger.displayName = 'SelectTrigger';
146
+ }
147
+ var _default = exports.default = RefSelectTrigger;
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ type InputRef = HTMLInputElement | HTMLTextAreaElement;
3
+ interface InputProps {
4
+ prefixCls: string;
5
+ id: string;
6
+ inputElement: React.ReactElement;
7
+ disabled: boolean;
8
+ autoFocus: boolean;
9
+ autoComplete: string;
10
+ editable: boolean;
11
+ activeDescendantId?: string;
12
+ value: string;
13
+ maxLength?: number;
14
+ open: boolean;
15
+ tabIndex: number;
16
+ /** Pass accessibility props to input */
17
+ attrs: Record<string, unknown>;
18
+ onKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
19
+ onMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
20
+ onChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
21
+ onPaste: React.ClipboardEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
22
+ onBlur: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
23
+ onCompositionStart: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
24
+ onCompositionEnd: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
25
+ }
26
+ declare const RefInput: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<InputRef>>;
27
+ export default RefInput;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var _ref = require("@rc-component/util/lib/ref");
10
+ var _warning = require("@rc-component/util/lib/warning");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ const Input = (props, ref) => {
15
+ const {
16
+ prefixCls,
17
+ id,
18
+ inputElement,
19
+ disabled,
20
+ tabIndex,
21
+ autoFocus,
22
+ autoComplete,
23
+ editable,
24
+ activeDescendantId,
25
+ value,
26
+ maxLength,
27
+ onKeyDown,
28
+ onMouseDown,
29
+ onChange,
30
+ onPaste,
31
+ onCompositionStart,
32
+ onCompositionEnd,
33
+ onBlur,
34
+ open,
35
+ attrs
36
+ } = props;
37
+ let inputNode = inputElement || /*#__PURE__*/React.createElement("input", null);
38
+ const {
39
+ ref: originRef,
40
+ props: originProps
41
+ } = inputNode;
42
+ const {
43
+ onKeyDown: onOriginKeyDown,
44
+ onChange: onOriginChange,
45
+ onMouseDown: onOriginMouseDown,
46
+ onCompositionStart: onOriginCompositionStart,
47
+ onCompositionEnd: onOriginCompositionEnd,
48
+ onBlur: onOriginBlur,
49
+ style
50
+ } = originProps;
51
+ (0, _warning.warning)(!('maxLength' in inputNode.props), `Passing 'maxLength' to input element directly may not work because input in BaseSelect is controlled.`);
52
+ inputNode = /*#__PURE__*/React.cloneElement(inputNode, {
53
+ type: 'search',
54
+ ...originProps,
55
+ // Override over origin props
56
+ id,
57
+ ref: (0, _ref.composeRef)(ref, originRef),
58
+ disabled,
59
+ tabIndex,
60
+ autoComplete: autoComplete || 'off',
61
+ autoFocus,
62
+ className: (0, _classnames.default)(`${prefixCls}-selection-search-input`, inputNode?.props?.className),
63
+ role: 'combobox',
64
+ 'aria-expanded': open || false,
65
+ 'aria-haspopup': 'listbox',
66
+ 'aria-owns': `${id}_list`,
67
+ 'aria-autocomplete': 'list',
68
+ 'aria-controls': `${id}_list`,
69
+ 'aria-activedescendant': open ? activeDescendantId : undefined,
70
+ ...attrs,
71
+ value: editable ? value : '',
72
+ maxLength,
73
+ readOnly: !editable,
74
+ unselectable: !editable ? 'on' : null,
75
+ style: {
76
+ ...style,
77
+ opacity: editable ? null : 0
78
+ },
79
+ onKeyDown: event => {
80
+ onKeyDown(event);
81
+ if (onOriginKeyDown) {
82
+ onOriginKeyDown(event);
83
+ }
84
+ },
85
+ onMouseDown: event => {
86
+ onMouseDown(event);
87
+ if (onOriginMouseDown) {
88
+ onOriginMouseDown(event);
89
+ }
90
+ },
91
+ onChange: event => {
92
+ onChange(event);
93
+ if (onOriginChange) {
94
+ onOriginChange(event);
95
+ }
96
+ },
97
+ onCompositionStart(event) {
98
+ onCompositionStart(event);
99
+ if (onOriginCompositionStart) {
100
+ onOriginCompositionStart(event);
101
+ }
102
+ },
103
+ onCompositionEnd(event) {
104
+ onCompositionEnd(event);
105
+ if (onOriginCompositionEnd) {
106
+ onOriginCompositionEnd(event);
107
+ }
108
+ },
109
+ onPaste,
110
+ onBlur(event) {
111
+ onBlur(event);
112
+ if (onOriginBlur) {
113
+ onOriginBlur(event);
114
+ }
115
+ }
116
+ });
117
+ return inputNode;
118
+ };
119
+ const RefInput = /*#__PURE__*/React.forwardRef(Input);
120
+ if (process.env.NODE_ENV !== 'production') {
121
+ RefInput.displayName = 'Input';
122
+ }
123
+ var _default = exports.default = RefInput;
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import type { InnerSelectorProps } from '.';
3
+ import type { DisplayValueType, RenderNode, CustomTagProps } from '../BaseSelect';
4
+ interface SelectorProps extends InnerSelectorProps {
5
+ removeIcon?: RenderNode;
6
+ maxTagCount?: number | 'responsive';
7
+ maxTagTextLength?: number;
8
+ maxTagPlaceholder?: React.ReactNode | ((omittedValues: DisplayValueType[]) => React.ReactNode);
9
+ tokenSeparators?: string[];
10
+ tagRender?: (props: CustomTagProps) => React.ReactElement;
11
+ onToggleOpen: (open?: boolean) => void;
12
+ choiceTransitionName?: string;
13
+ onRemove: (value: DisplayValueType) => void;
14
+ }
15
+ declare const SelectSelector: React.FC<SelectorProps>;
16
+ export default SelectSelector;
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var React = _react;
9
+ var _classnames = _interopRequireDefault(require("classnames"));
10
+ var _pickAttrs = _interopRequireDefault(require("@rc-component/util/lib/pickAttrs"));
11
+ var _rcOverflow = _interopRequireDefault(require("rc-overflow"));
12
+ var _TransBtn = _interopRequireDefault(require("../TransBtn"));
13
+ var _Input = _interopRequireDefault(require("./Input"));
14
+ var _useLayoutEffect = _interopRequireDefault(require("../hooks/useLayoutEffect"));
15
+ var _commonUtil = require("../utils/commonUtil");
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+ function itemKey(value) {
20
+ return value.key ?? value.value;
21
+ }
22
+ const onPreventMouseDown = event => {
23
+ event.preventDefault();
24
+ event.stopPropagation();
25
+ };
26
+ const SelectSelector = props => {
27
+ const {
28
+ id,
29
+ prefixCls,
30
+ values,
31
+ open,
32
+ searchValue,
33
+ autoClearSearchValue,
34
+ inputRef,
35
+ placeholder,
36
+ disabled,
37
+ mode,
38
+ showSearch,
39
+ autoFocus,
40
+ autoComplete,
41
+ activeDescendantId,
42
+ tabIndex,
43
+ removeIcon,
44
+ maxTagCount,
45
+ maxTagTextLength,
46
+ maxTagPlaceholder = omittedValues => `+ ${omittedValues.length} ...`,
47
+ tagRender,
48
+ onToggleOpen,
49
+ onRemove,
50
+ onInputChange,
51
+ onInputPaste,
52
+ onInputKeyDown,
53
+ onInputMouseDown,
54
+ onInputCompositionStart,
55
+ onInputCompositionEnd,
56
+ onInputBlur
57
+ } = props;
58
+ const measureRef = React.useRef(null);
59
+ const [inputWidth, setInputWidth] = (0, _react.useState)(0);
60
+ const [focused, setFocused] = (0, _react.useState)(false);
61
+ const selectionPrefixCls = `${prefixCls}-selection`;
62
+
63
+ // ===================== Search ======================
64
+ const inputValue = open || mode === 'multiple' && autoClearSearchValue === false || mode === 'tags' ? searchValue : '';
65
+ const inputEditable = mode === 'tags' || mode === 'multiple' && autoClearSearchValue === false || showSearch && (open || focused);
66
+
67
+ // We measure width and set to the input immediately
68
+ (0, _useLayoutEffect.default)(() => {
69
+ setInputWidth(measureRef.current.scrollWidth);
70
+ }, [inputValue]);
71
+
72
+ // ===================== Render ======================
73
+ // >>> Render Selector Node. Includes Item & Rest
74
+ const defaultRenderSelector = (item, content, itemDisabled, closable, onClose) => /*#__PURE__*/React.createElement("span", {
75
+ title: (0, _commonUtil.getTitle)(item),
76
+ className: (0, _classnames.default)(`${selectionPrefixCls}-item`, {
77
+ [`${selectionPrefixCls}-item-disabled`]: itemDisabled
78
+ })
79
+ }, /*#__PURE__*/React.createElement("span", {
80
+ className: `${selectionPrefixCls}-item-content`
81
+ }, content), closable && /*#__PURE__*/React.createElement(_TransBtn.default, {
82
+ className: `${selectionPrefixCls}-item-remove`,
83
+ onMouseDown: onPreventMouseDown,
84
+ onClick: onClose,
85
+ customizeIcon: removeIcon
86
+ }, "\xD7"));
87
+ const customizeRenderSelector = (value, content, itemDisabled, closable, onClose, isMaxTag, info) => {
88
+ const onMouseDown = e => {
89
+ onPreventMouseDown(e);
90
+ onToggleOpen(!open);
91
+ };
92
+ return /*#__PURE__*/React.createElement("span", {
93
+ onMouseDown: onMouseDown
94
+ }, tagRender({
95
+ label: content,
96
+ value,
97
+ index: info?.index,
98
+ disabled: itemDisabled,
99
+ closable,
100
+ onClose,
101
+ isMaxTag: !!isMaxTag
102
+ }));
103
+ };
104
+ const renderItem = (valueItem, info) => {
105
+ const {
106
+ disabled: itemDisabled,
107
+ label,
108
+ value
109
+ } = valueItem;
110
+ const closable = !disabled && !itemDisabled;
111
+ let displayLabel = label;
112
+ if (typeof maxTagTextLength === 'number') {
113
+ if (typeof label === 'string' || typeof label === 'number') {
114
+ const strLabel = String(displayLabel);
115
+ if (strLabel.length > maxTagTextLength) {
116
+ displayLabel = `${strLabel.slice(0, maxTagTextLength)}...`;
117
+ }
118
+ }
119
+ }
120
+ const onClose = event => {
121
+ if (event) {
122
+ event.stopPropagation();
123
+ }
124
+ onRemove(valueItem);
125
+ };
126
+ return typeof tagRender === 'function' ? customizeRenderSelector(value, displayLabel, itemDisabled, closable, onClose, undefined, info) : defaultRenderSelector(valueItem, displayLabel, itemDisabled, closable, onClose);
127
+ };
128
+ const renderRest = omittedValues => {
129
+ // https://github.com/ant-design/ant-design/issues/48930
130
+ if (!values.length) {
131
+ return null;
132
+ }
133
+ const content = typeof maxTagPlaceholder === 'function' ? maxTagPlaceholder(omittedValues) : maxTagPlaceholder;
134
+ return typeof tagRender === 'function' ? customizeRenderSelector(undefined, content, false, false, undefined, true) : defaultRenderSelector({
135
+ title: content
136
+ }, content, false);
137
+ };
138
+
139
+ // >>> Input Node
140
+ const inputNode = /*#__PURE__*/React.createElement("div", {
141
+ className: `${selectionPrefixCls}-search`,
142
+ style: {
143
+ width: inputWidth
144
+ },
145
+ onFocus: () => {
146
+ setFocused(true);
147
+ },
148
+ onBlur: () => {
149
+ setFocused(false);
150
+ }
151
+ }, /*#__PURE__*/React.createElement(_Input.default, {
152
+ ref: inputRef,
153
+ open: open,
154
+ prefixCls: prefixCls,
155
+ id: id,
156
+ inputElement: null,
157
+ disabled: disabled,
158
+ autoFocus: autoFocus,
159
+ autoComplete: autoComplete,
160
+ editable: inputEditable,
161
+ activeDescendantId: activeDescendantId,
162
+ value: inputValue,
163
+ onKeyDown: onInputKeyDown,
164
+ onMouseDown: onInputMouseDown,
165
+ onChange: onInputChange,
166
+ onPaste: onInputPaste,
167
+ onCompositionStart: onInputCompositionStart,
168
+ onCompositionEnd: onInputCompositionEnd,
169
+ onBlur: onInputBlur,
170
+ tabIndex: tabIndex,
171
+ attrs: (0, _pickAttrs.default)(props, true)
172
+ }), /*#__PURE__*/React.createElement("span", {
173
+ ref: measureRef,
174
+ className: `${selectionPrefixCls}-search-mirror`,
175
+ "aria-hidden": true
176
+ }, inputValue, "\xA0"));
177
+
178
+ // >>> Selections
179
+ const selectionNode = /*#__PURE__*/React.createElement(_rcOverflow.default, {
180
+ prefixCls: `${selectionPrefixCls}-overflow`,
181
+ data: values,
182
+ renderItem: renderItem,
183
+ renderRest: renderRest,
184
+ suffix: inputNode,
185
+ itemKey: itemKey,
186
+ maxCount: maxTagCount
187
+ });
188
+ return /*#__PURE__*/React.createElement("span", {
189
+ className: `${selectionPrefixCls}-wrap`
190
+ }, selectionNode, !values.length && !inputValue && /*#__PURE__*/React.createElement("span", {
191
+ className: `${selectionPrefixCls}-placeholder`
192
+ }, placeholder));
193
+ };
194
+ var _default = exports.default = SelectSelector;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import type { InnerSelectorProps } from '.';
3
+ interface SelectorProps extends InnerSelectorProps {
4
+ inputElement: React.ReactElement;
5
+ activeValue: string;
6
+ }
7
+ declare const SingleSelector: React.FC<SelectorProps>;
8
+ export default SingleSelector;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _pickAttrs = _interopRequireDefault(require("@rc-component/util/lib/pickAttrs"));
9
+ var _Input = _interopRequireDefault(require("./Input"));
10
+ var _commonUtil = require("../utils/commonUtil");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ const SingleSelector = props => {
15
+ const {
16
+ inputElement,
17
+ prefixCls,
18
+ id,
19
+ inputRef,
20
+ disabled,
21
+ autoFocus,
22
+ autoComplete,
23
+ activeDescendantId,
24
+ mode,
25
+ open,
26
+ values,
27
+ placeholder,
28
+ tabIndex,
29
+ showSearch,
30
+ searchValue,
31
+ activeValue,
32
+ maxLength,
33
+ onInputKeyDown,
34
+ onInputMouseDown,
35
+ onInputChange,
36
+ onInputPaste,
37
+ onInputCompositionStart,
38
+ onInputCompositionEnd,
39
+ onInputBlur,
40
+ title
41
+ } = props;
42
+ const [inputChanged, setInputChanged] = React.useState(false);
43
+ const combobox = mode === 'combobox';
44
+ const inputEditable = combobox || showSearch;
45
+ const item = values[0];
46
+ let inputValue = searchValue || '';
47
+ if (combobox && activeValue && !inputChanged) {
48
+ inputValue = activeValue;
49
+ }
50
+ React.useEffect(() => {
51
+ if (combobox) {
52
+ setInputChanged(false);
53
+ }
54
+ }, [combobox, activeValue]);
55
+
56
+ // Not show text when closed expect combobox mode
57
+ const hasTextInput = mode !== 'combobox' && !open && !showSearch ? false : !!inputValue;
58
+
59
+ // Get title of selection item
60
+ const selectionTitle = title === undefined ? (0, _commonUtil.getTitle)(item) : title;
61
+ const placeholderNode = React.useMemo(() => {
62
+ if (item) {
63
+ return null;
64
+ }
65
+ return /*#__PURE__*/React.createElement("span", {
66
+ className: `${prefixCls}-selection-placeholder`,
67
+ style: hasTextInput ? {
68
+ visibility: 'hidden'
69
+ } : undefined
70
+ }, placeholder);
71
+ }, [item, hasTextInput, placeholder, prefixCls]);
72
+ return /*#__PURE__*/React.createElement("span", {
73
+ className: `${prefixCls}-selection-wrap`
74
+ }, /*#__PURE__*/React.createElement("span", {
75
+ className: `${prefixCls}-selection-search`
76
+ }, /*#__PURE__*/React.createElement(_Input.default, {
77
+ ref: inputRef,
78
+ prefixCls: prefixCls,
79
+ id: id,
80
+ open: open,
81
+ inputElement: inputElement,
82
+ disabled: disabled,
83
+ autoFocus: autoFocus,
84
+ autoComplete: autoComplete,
85
+ editable: inputEditable,
86
+ activeDescendantId: activeDescendantId,
87
+ value: inputValue,
88
+ onKeyDown: onInputKeyDown,
89
+ onMouseDown: onInputMouseDown,
90
+ onChange: e => {
91
+ setInputChanged(true);
92
+ onInputChange(e);
93
+ },
94
+ onPaste: onInputPaste,
95
+ onCompositionStart: onInputCompositionStart,
96
+ onCompositionEnd: onInputCompositionEnd,
97
+ onBlur: onInputBlur,
98
+ tabIndex: tabIndex,
99
+ attrs: (0, _pickAttrs.default)(props, true),
100
+ maxLength: combobox ? maxLength : undefined
101
+ })), !combobox && item ? /*#__PURE__*/React.createElement("span", {
102
+ className: `${prefixCls}-selection-item`,
103
+ title: selectionTitle
104
+ // 当 Select 已经选中选项时,还需 selection 隐藏但留在原地占位
105
+ // https://github.com/ant-design/ant-design/issues/27688
106
+ // https://github.com/ant-design/ant-design/issues/41530
107
+ ,
108
+ style: hasTextInput ? {
109
+ visibility: 'hidden'
110
+ } : undefined
111
+ }, item.label) : null, placeholderNode);
112
+ };
113
+ var _default = exports.default = SingleSelector;