@rc-component/select 1.1.4 → 1.2.0-alpha.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/assets/index.css +63 -0
- package/assets/index.less +1 -0
- package/assets/patch.less +83 -0
- package/es/BaseSelect/index.d.ts +14 -3
- package/es/BaseSelect/index.js +137 -200
- package/es/OptionList.js +3 -3
- package/es/Select.d.ts +1 -1
- package/es/Select.js +5 -9
- package/es/SelectInput/Affix.d.ts +5 -0
- package/es/SelectInput/Affix.js +12 -0
- package/es/SelectInput/Content/MultipleContent.d.ts +4 -0
- package/es/SelectInput/Content/MultipleContent.js +152 -0
- package/es/SelectInput/Content/Placeholder.d.ts +5 -0
- package/es/SelectInput/Content/Placeholder.js +21 -0
- package/es/SelectInput/Content/SingleContent.d.ts +4 -0
- package/es/SelectInput/Content/SingleContent.js +98 -0
- package/es/SelectInput/Content/index.d.ts +6 -0
- package/es/SelectInput/Content/index.js +37 -0
- package/es/SelectInput/Input.d.ts +20 -0
- package/es/SelectInput/Input.js +214 -0
- package/es/SelectInput/context.d.ts +6 -0
- package/es/SelectInput/context.js +6 -0
- package/es/SelectInput/index.d.ts +39 -0
- package/es/SelectInput/index.js +189 -0
- package/es/SelectTrigger.d.ts +1 -0
- package/es/SelectTrigger.js +5 -3
- package/es/TransBtn.d.ts +10 -0
- package/es/TransBtn.js +12 -2
- package/es/hooks/useAllowClear.d.ts +8 -7
- package/es/hooks/useAllowClear.js +21 -23
- package/es/hooks/useBaseProps.d.ts +1 -0
- package/es/hooks/useComponents.d.ts +12 -0
- package/es/hooks/useComponents.js +23 -0
- package/es/hooks/useOpen.d.ts +15 -0
- package/es/hooks/useOpen.js +76 -0
- package/es/hooks/useSearchConfig.d.ts +2 -2
- package/es/hooks/useSearchConfig.js +3 -3
- package/es/hooks/useSelectTriggerControl.d.ts +1 -1
- package/es/hooks/useSelectTriggerControl.js +16 -21
- package/es/utils/keyUtil.js +4 -0
- package/lib/BaseSelect/index.d.ts +14 -3
- package/lib/BaseSelect/index.js +137 -201
- package/lib/OptionList.js +3 -3
- package/lib/Select.d.ts +1 -1
- package/lib/Select.js +5 -9
- package/lib/SelectInput/Affix.d.ts +5 -0
- package/lib/{hooks/useLayoutEffect.js → SelectInput/Affix.js} +11 -16
- package/lib/SelectInput/Content/MultipleContent.d.ts +4 -0
- package/lib/{Selector/MultipleSelector.js → SelectInput/Content/MultipleContent.js} +71 -104
- package/lib/SelectInput/Content/Placeholder.d.ts +5 -0
- package/lib/SelectInput/Content/Placeholder.js +29 -0
- package/lib/SelectInput/Content/SingleContent.d.ts +4 -0
- package/lib/SelectInput/Content/SingleContent.js +107 -0
- package/lib/SelectInput/Content/index.d.ts +6 -0
- package/lib/SelectInput/Content/index.js +46 -0
- package/lib/SelectInput/Input.d.ts +20 -0
- package/lib/SelectInput/Input.js +223 -0
- package/lib/SelectInput/context.d.ts +6 -0
- package/lib/SelectInput/context.js +15 -0
- package/lib/SelectInput/index.d.ts +39 -0
- package/lib/SelectInput/index.js +198 -0
- package/lib/SelectTrigger.d.ts +1 -0
- package/lib/SelectTrigger.js +5 -3
- package/lib/TransBtn.d.ts +10 -0
- package/lib/TransBtn.js +12 -3
- package/lib/hooks/useAllowClear.d.ts +8 -7
- package/lib/hooks/useAllowClear.js +21 -24
- package/lib/hooks/useBaseProps.d.ts +1 -0
- package/lib/hooks/useComponents.d.ts +12 -0
- package/lib/hooks/{useDelayReset.js → useComponents.js} +21 -30
- package/lib/hooks/useOpen.d.ts +15 -0
- package/lib/hooks/useOpen.js +82 -0
- package/lib/hooks/useSearchConfig.d.ts +2 -2
- package/lib/hooks/useSearchConfig.js +3 -3
- package/lib/hooks/useSelectTriggerControl.d.ts +1 -1
- package/lib/hooks/useSelectTriggerControl.js +16 -21
- package/lib/utils/keyUtil.js +4 -0
- package/package.json +5 -4
- package/es/Selector/Input.d.ts +0 -27
- package/es/Selector/Input.js +0 -61
- package/es/Selector/MultipleSelector.d.ts +0 -16
- package/es/Selector/MultipleSelector.js +0 -185
- package/es/Selector/SingleSelector.d.ts +0 -8
- package/es/Selector/SingleSelector.js +0 -104
- package/es/Selector/index.d.ts +0 -83
- package/es/Selector/index.js +0 -189
- package/es/hooks/useDelayReset.d.ts +0 -5
- package/es/hooks/useDelayReset.js +0 -33
- package/es/hooks/useLayoutEffect.d.ts +0 -5
- package/es/hooks/useLayoutEffect.js +0 -17
- package/lib/Selector/Input.d.ts +0 -27
- package/lib/Selector/Input.js +0 -70
- package/lib/Selector/MultipleSelector.d.ts +0 -16
- package/lib/Selector/SingleSelector.d.ts +0 -8
- package/lib/Selector/SingleSelector.js +0 -113
- package/lib/Selector/index.d.ts +0 -83
- package/lib/Selector/index.js +0 -196
- package/lib/hooks/useDelayReset.d.ts +0 -5
- package/lib/hooks/useLayoutEffect.d.ts +0 -5
|
@@ -0,0 +1,223 @@
|
|
|
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 _clsx = require("clsx");
|
|
9
|
+
var _context = require("./context");
|
|
10
|
+
var _useLayoutEffect = _interopRequireDefault(require("@rc-component/util/lib/hooks/useLayoutEffect"));
|
|
11
|
+
var _useBaseProps = _interopRequireDefault(require("../hooks/useBaseProps"));
|
|
12
|
+
var _ref = require("@rc-component/util/lib/ref");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
const Input = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
17
|
+
const {
|
|
18
|
+
onChange,
|
|
19
|
+
onKeyDown,
|
|
20
|
+
onBlur,
|
|
21
|
+
style,
|
|
22
|
+
syncWidth,
|
|
23
|
+
value,
|
|
24
|
+
className,
|
|
25
|
+
autoComplete,
|
|
26
|
+
...restProps
|
|
27
|
+
} = props;
|
|
28
|
+
const {
|
|
29
|
+
prefixCls,
|
|
30
|
+
mode,
|
|
31
|
+
onSearch,
|
|
32
|
+
onSearchSubmit,
|
|
33
|
+
onInputBlur,
|
|
34
|
+
autoFocus,
|
|
35
|
+
tokenWithEnter,
|
|
36
|
+
components: {
|
|
37
|
+
input: InputComponent = 'input'
|
|
38
|
+
}
|
|
39
|
+
} = (0, _context.useSelectInputContext)();
|
|
40
|
+
const {
|
|
41
|
+
id,
|
|
42
|
+
classNames,
|
|
43
|
+
styles,
|
|
44
|
+
open,
|
|
45
|
+
activeDescendantId,
|
|
46
|
+
role,
|
|
47
|
+
disabled
|
|
48
|
+
} = (0, _useBaseProps.default)() || {};
|
|
49
|
+
const inputCls = (0, _clsx.clsx)(`${prefixCls}-input`, classNames?.input, className);
|
|
50
|
+
|
|
51
|
+
// Used to handle input method composition status
|
|
52
|
+
const compositionStatusRef = React.useRef(false);
|
|
53
|
+
|
|
54
|
+
// Used to handle paste content, similar to original Selector implementation
|
|
55
|
+
const pastedTextRef = React.useRef(null);
|
|
56
|
+
|
|
57
|
+
// ============================== Refs ==============================
|
|
58
|
+
const inputRef = React.useRef(null);
|
|
59
|
+
React.useImperativeHandle(ref, () => inputRef.current);
|
|
60
|
+
|
|
61
|
+
// ============================== Data ==============================
|
|
62
|
+
// Handle input changes
|
|
63
|
+
const handleChange = event => {
|
|
64
|
+
let {
|
|
65
|
+
value: nextVal
|
|
66
|
+
} = event.target;
|
|
67
|
+
|
|
68
|
+
// Handle pasted text with tokenWithEnter, similar to original Selector implementation
|
|
69
|
+
if (tokenWithEnter && pastedTextRef.current && /[\r\n]/.test(pastedTextRef.current)) {
|
|
70
|
+
// CRLF will be treated as a single space for input element
|
|
71
|
+
const replacedText = pastedTextRef.current.replace(/[\r\n]+$/, '').replace(/\r\n/g, ' ').replace(/[\r\n]/g, ' ');
|
|
72
|
+
nextVal = nextVal.replace(replacedText, pastedTextRef.current);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Reset pasted text reference
|
|
76
|
+
pastedTextRef.current = null;
|
|
77
|
+
|
|
78
|
+
// Call onSearch callback
|
|
79
|
+
if (onSearch) {
|
|
80
|
+
onSearch(nextVal, true, compositionStatusRef.current);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Call original onChange callback
|
|
84
|
+
onChange?.(event);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// ============================ Keyboard ============================
|
|
88
|
+
// Handle keyboard events
|
|
89
|
+
const handleKeyDown = event => {
|
|
90
|
+
const {
|
|
91
|
+
key
|
|
92
|
+
} = event;
|
|
93
|
+
const {
|
|
94
|
+
value: nextVal
|
|
95
|
+
} = event.currentTarget;
|
|
96
|
+
|
|
97
|
+
// Handle Enter key submission - referencing Selector implementation
|
|
98
|
+
if (key === 'Enter' && mode === 'tags' && !compositionStatusRef.current && onSearchSubmit) {
|
|
99
|
+
onSearchSubmit(nextVal);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Call original onKeyDown callback
|
|
103
|
+
onKeyDown?.(event);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Handle blur events
|
|
107
|
+
const handleBlur = event => {
|
|
108
|
+
// Call onInputBlur callback
|
|
109
|
+
onInputBlur?.();
|
|
110
|
+
|
|
111
|
+
// Call original onBlur callback
|
|
112
|
+
onBlur?.(event);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Handle input method composition start
|
|
116
|
+
const handleCompositionStart = () => {
|
|
117
|
+
compositionStatusRef.current = true;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Handle input method composition end
|
|
121
|
+
const handleCompositionEnd = event => {
|
|
122
|
+
compositionStatusRef.current = false;
|
|
123
|
+
|
|
124
|
+
// Trigger search when input method composition ends, similar to original Selector
|
|
125
|
+
if (mode !== 'combobox') {
|
|
126
|
+
const {
|
|
127
|
+
value: nextVal
|
|
128
|
+
} = event.currentTarget;
|
|
129
|
+
onSearch?.(nextVal, true, false);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Handle paste events to track pasted content
|
|
134
|
+
const handlePaste = event => {
|
|
135
|
+
const {
|
|
136
|
+
clipboardData
|
|
137
|
+
} = event;
|
|
138
|
+
const pastedValue = clipboardData?.getData('text');
|
|
139
|
+
pastedTextRef.current = pastedValue || '';
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// ============================= Width ==============================
|
|
143
|
+
const [widthCssVar, setWidthCssVar] = React.useState(undefined);
|
|
144
|
+
|
|
145
|
+
// When syncWidth is enabled, adjust input width based on content
|
|
146
|
+
(0, _useLayoutEffect.default)(() => {
|
|
147
|
+
const input = inputRef.current;
|
|
148
|
+
if (syncWidth && input) {
|
|
149
|
+
input.style.width = '0px';
|
|
150
|
+
const scrollWidth = input.scrollWidth;
|
|
151
|
+
setWidthCssVar(scrollWidth);
|
|
152
|
+
|
|
153
|
+
// Reset input style
|
|
154
|
+
input.style.width = '';
|
|
155
|
+
}
|
|
156
|
+
}, [syncWidth, value]);
|
|
157
|
+
|
|
158
|
+
// ============================= Render =============================
|
|
159
|
+
// Extract shared input props
|
|
160
|
+
const sharedInputProps = {
|
|
161
|
+
id,
|
|
162
|
+
type: mode === 'combobox' ? 'text' : 'search',
|
|
163
|
+
...restProps,
|
|
164
|
+
ref: inputRef,
|
|
165
|
+
style: {
|
|
166
|
+
...styles?.input,
|
|
167
|
+
...style,
|
|
168
|
+
'--select-input-width': widthCssVar
|
|
169
|
+
},
|
|
170
|
+
autoFocus,
|
|
171
|
+
autoComplete: autoComplete || 'off',
|
|
172
|
+
className: inputCls,
|
|
173
|
+
disabled,
|
|
174
|
+
value: value || '',
|
|
175
|
+
onChange: handleChange,
|
|
176
|
+
onKeyDown: handleKeyDown,
|
|
177
|
+
onBlur: handleBlur,
|
|
178
|
+
onPaste: handlePaste,
|
|
179
|
+
onCompositionStart: handleCompositionStart,
|
|
180
|
+
onCompositionEnd: handleCompositionEnd,
|
|
181
|
+
// Accessibility attributes
|
|
182
|
+
role: role || 'combobox',
|
|
183
|
+
'aria-expanded': open || false,
|
|
184
|
+
'aria-haspopup': 'listbox',
|
|
185
|
+
'aria-owns': `${id}_list`,
|
|
186
|
+
'aria-autocomplete': 'list',
|
|
187
|
+
'aria-controls': `${id}_list`,
|
|
188
|
+
'aria-activedescendant': open ? activeDescendantId : undefined
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// Handle different InputComponent types
|
|
192
|
+
if ( /*#__PURE__*/React.isValidElement(InputComponent)) {
|
|
193
|
+
// If InputComponent is a ReactElement, use cloneElement with merged props
|
|
194
|
+
const existingProps = InputComponent.props || {};
|
|
195
|
+
|
|
196
|
+
// Start with shared props as base
|
|
197
|
+
const mergedProps = {
|
|
198
|
+
...sharedInputProps,
|
|
199
|
+
...existingProps
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// Batch update function calls
|
|
203
|
+
Object.keys(existingProps).forEach(key => {
|
|
204
|
+
const existingValue = existingProps[key];
|
|
205
|
+
if (typeof existingValue === 'function') {
|
|
206
|
+
// Merge event handlers
|
|
207
|
+
mergedProps[key] = (...args) => {
|
|
208
|
+
existingValue(...args);
|
|
209
|
+
sharedInputProps[key]?.(...args);
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Update ref
|
|
215
|
+
mergedProps.ref = (0, _ref.composeRef)(InputComponent.ref, sharedInputProps.ref);
|
|
216
|
+
return /*#__PURE__*/React.cloneElement(InputComponent, mergedProps);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// If InputComponent is a component type, render normally
|
|
220
|
+
const Component = InputComponent;
|
|
221
|
+
return /*#__PURE__*/React.createElement(Component, sharedInputProps);
|
|
222
|
+
});
|
|
223
|
+
var _default = exports.default = Input;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { SelectInputProps } from '.';
|
|
3
|
+
export type ContentContextProps = SelectInputProps;
|
|
4
|
+
declare const SelectInputContext: React.Context<SelectInputProps>;
|
|
5
|
+
export declare function useSelectInputContext(): SelectInputProps;
|
|
6
|
+
export default SelectInputContext;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.useSelectInputContext = useSelectInputContext;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
const SelectInputContext = /*#__PURE__*/React.createContext(null);
|
|
12
|
+
function useSelectInputContext() {
|
|
13
|
+
return React.useContext(SelectInputContext);
|
|
14
|
+
}
|
|
15
|
+
var _default = exports.default = SelectInputContext;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { DisplayValueType, Mode, RenderNode } from '../interface';
|
|
3
|
+
import type { ComponentsConfig } from '../hooks/useComponents';
|
|
4
|
+
export interface SelectInputRef {
|
|
5
|
+
focus: (options?: FocusOptions) => void;
|
|
6
|
+
blur: () => void;
|
|
7
|
+
nativeElement: HTMLDivElement;
|
|
8
|
+
}
|
|
9
|
+
export interface SelectInputProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'prefix'> {
|
|
10
|
+
prefixCls: string;
|
|
11
|
+
prefix?: React.ReactNode;
|
|
12
|
+
suffix?: React.ReactNode;
|
|
13
|
+
clearIcon?: React.ReactNode;
|
|
14
|
+
removeIcon?: RenderNode;
|
|
15
|
+
multiple?: boolean;
|
|
16
|
+
displayValues: DisplayValueType[];
|
|
17
|
+
placeholder?: React.ReactNode;
|
|
18
|
+
searchValue?: string;
|
|
19
|
+
activeValue?: string;
|
|
20
|
+
mode?: Mode;
|
|
21
|
+
autoClearSearchValue?: boolean;
|
|
22
|
+
onSearch?: (searchText: string, fromTyping: boolean, isCompositing: boolean) => void;
|
|
23
|
+
onSearchSubmit?: (searchText: string) => void;
|
|
24
|
+
onInputBlur?: () => void;
|
|
25
|
+
onClearMouseDown?: React.MouseEventHandler<HTMLElement>;
|
|
26
|
+
onInputKeyDown?: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
27
|
+
onSelectorRemove?: (value: DisplayValueType) => void;
|
|
28
|
+
maxLength?: number;
|
|
29
|
+
autoFocus?: boolean;
|
|
30
|
+
/** Check if `tokenSeparators` contains `\n` or `\r\n` */
|
|
31
|
+
tokenWithEnter?: boolean;
|
|
32
|
+
className?: string;
|
|
33
|
+
style?: React.CSSProperties;
|
|
34
|
+
focused?: boolean;
|
|
35
|
+
components: ComponentsConfig;
|
|
36
|
+
children?: React.ReactElement;
|
|
37
|
+
}
|
|
38
|
+
declare const _default: React.ForwardRefExoticComponent<SelectInputProps & React.RefAttributes<SelectInputRef>>;
|
|
39
|
+
export default _default;
|
|
@@ -0,0 +1,198 @@
|
|
|
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 _Affix = _interopRequireDefault(require("./Affix"));
|
|
9
|
+
var _Content = _interopRequireDefault(require("./Content"));
|
|
10
|
+
var _context = _interopRequireDefault(require("./context"));
|
|
11
|
+
var _useBaseProps = _interopRequireDefault(require("../hooks/useBaseProps"));
|
|
12
|
+
var _util = require("@rc-component/util");
|
|
13
|
+
var _KeyCode = _interopRequireDefault(require("@rc-component/util/lib/KeyCode"));
|
|
14
|
+
var _keyUtil = require("../utils/keyUtil");
|
|
15
|
+
var _clsx = require("clsx");
|
|
16
|
+
var _findDOMNode = require("@rc-component/util/lib/Dom/findDOMNode");
|
|
17
|
+
var _ref = require("@rc-component/util/lib/ref");
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
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); }
|
|
20
|
+
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; }
|
|
21
|
+
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); }
|
|
22
|
+
const DEFAULT_OMIT_PROPS = ['value', 'onChange', 'removeIcon', 'placeholder', 'maxTagCount', 'maxTagTextLength', 'maxTagPlaceholder', 'choiceTransitionName', 'onInputKeyDown', 'onPopupScroll', 'tabIndex', 'activeValue', 'onSelectorRemove', 'focused'];
|
|
23
|
+
var _default = exports.default = /*#__PURE__*/React.forwardRef(function SelectInput(props, ref) {
|
|
24
|
+
const {
|
|
25
|
+
// Style
|
|
26
|
+
prefixCls,
|
|
27
|
+
className,
|
|
28
|
+
style,
|
|
29
|
+
// UI
|
|
30
|
+
prefix,
|
|
31
|
+
suffix,
|
|
32
|
+
clearIcon,
|
|
33
|
+
children,
|
|
34
|
+
// Data
|
|
35
|
+
multiple,
|
|
36
|
+
displayValues,
|
|
37
|
+
placeholder,
|
|
38
|
+
mode,
|
|
39
|
+
// Search
|
|
40
|
+
searchValue,
|
|
41
|
+
onSearch,
|
|
42
|
+
onSearchSubmit,
|
|
43
|
+
onInputBlur,
|
|
44
|
+
// Input
|
|
45
|
+
maxLength,
|
|
46
|
+
autoFocus,
|
|
47
|
+
// Events
|
|
48
|
+
onMouseDown,
|
|
49
|
+
onBlur,
|
|
50
|
+
onClearMouseDown,
|
|
51
|
+
onInputKeyDown,
|
|
52
|
+
onSelectorRemove,
|
|
53
|
+
// Token handling
|
|
54
|
+
tokenWithEnter,
|
|
55
|
+
// Components
|
|
56
|
+
components,
|
|
57
|
+
...restProps
|
|
58
|
+
} = props;
|
|
59
|
+
const {
|
|
60
|
+
triggerOpen,
|
|
61
|
+
toggleOpen,
|
|
62
|
+
showSearch,
|
|
63
|
+
disabled,
|
|
64
|
+
loading,
|
|
65
|
+
classNames,
|
|
66
|
+
styles
|
|
67
|
+
} = (0, _useBaseProps.default)();
|
|
68
|
+
const rootRef = React.useRef(null);
|
|
69
|
+
const inputRef = React.useRef(null);
|
|
70
|
+
|
|
71
|
+
// Handle keyboard events similar to original Selector
|
|
72
|
+
const onInternalInputKeyDown = (0, _util.useEvent)(event => {
|
|
73
|
+
const {
|
|
74
|
+
which
|
|
75
|
+
} = event;
|
|
76
|
+
|
|
77
|
+
// Compatible with multiple lines in TextArea
|
|
78
|
+
const isTextAreaElement = inputRef.current instanceof HTMLTextAreaElement;
|
|
79
|
+
|
|
80
|
+
// Prevent default behavior for up/down arrows when dropdown is open
|
|
81
|
+
if (!isTextAreaElement && triggerOpen && (which === _KeyCode.default.UP || which === _KeyCode.default.DOWN)) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Call the original onInputKeyDown callback
|
|
86
|
+
if (onInputKeyDown) {
|
|
87
|
+
onInputKeyDown(event);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Move within the text box for TextArea
|
|
91
|
+
if (isTextAreaElement && !triggerOpen && ~[_KeyCode.default.UP, _KeyCode.default.DOWN, _KeyCode.default.LEFT, _KeyCode.default.RIGHT].indexOf(which)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Open dropdown when a valid open key is pressed
|
|
96
|
+
if ((0, _keyUtil.isValidateOpenKey)(which)) {
|
|
97
|
+
toggleOpen(true);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// ====================== Refs ======================
|
|
102
|
+
React.useImperativeHandle(ref, () => {
|
|
103
|
+
return {
|
|
104
|
+
focus: options => {
|
|
105
|
+
// Focus the inner input if available, otherwise fall back to root div.
|
|
106
|
+
(inputRef.current || rootRef.current).focus?.(options);
|
|
107
|
+
},
|
|
108
|
+
blur: () => {
|
|
109
|
+
(inputRef.current || rootRef.current).blur?.();
|
|
110
|
+
},
|
|
111
|
+
nativeElement: rootRef.current
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ====================== Open ======================
|
|
116
|
+
const onInternalMouseDown = (0, _util.useEvent)(event => {
|
|
117
|
+
if (!disabled) {
|
|
118
|
+
if (event.target !== (0, _findDOMNode.getDOM)(inputRef.current)) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Check if we should prevent closing when clicking on selector
|
|
123
|
+
// Don't close if: open && not multiple && (combobox mode || showSearch)
|
|
124
|
+
const shouldPreventClose = triggerOpen && !multiple && (mode === 'combobox' || showSearch);
|
|
125
|
+
if (!event.nativeEvent._select_lazy) {
|
|
126
|
+
inputRef.current?.focus();
|
|
127
|
+
|
|
128
|
+
// Only toggle open if we should not prevent close
|
|
129
|
+
if (!shouldPreventClose) {
|
|
130
|
+
toggleOpen();
|
|
131
|
+
}
|
|
132
|
+
} else if (triggerOpen) {
|
|
133
|
+
// Lazy should also close when click clear icon
|
|
134
|
+
toggleOpen(false);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
onMouseDown?.(event);
|
|
138
|
+
});
|
|
139
|
+
const onInternalBlur = event => {
|
|
140
|
+
toggleOpen(false);
|
|
141
|
+
onBlur?.(event);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// =================== Components ===================
|
|
145
|
+
const {
|
|
146
|
+
root: RootComponent
|
|
147
|
+
} = components;
|
|
148
|
+
|
|
149
|
+
// ===================== Render =====================
|
|
150
|
+
const domProps = (0, _util.omit)(restProps, DEFAULT_OMIT_PROPS);
|
|
151
|
+
|
|
152
|
+
// Create context value with wrapped callbacks
|
|
153
|
+
const contextValue = {
|
|
154
|
+
...props,
|
|
155
|
+
onInputKeyDown: onInternalInputKeyDown
|
|
156
|
+
};
|
|
157
|
+
if (RootComponent) {
|
|
158
|
+
if ( /*#__PURE__*/React.isValidElement(RootComponent)) {
|
|
159
|
+
return /*#__PURE__*/React.cloneElement(RootComponent, {
|
|
160
|
+
...domProps,
|
|
161
|
+
ref: (0, _ref.composeRef)(RootComponent.ref, rootRef)
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return /*#__PURE__*/React.createElement(RootComponent, _extends({}, domProps, {
|
|
165
|
+
ref: rootRef
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
return /*#__PURE__*/React.createElement(_context.default.Provider, {
|
|
169
|
+
value: contextValue
|
|
170
|
+
}, /*#__PURE__*/React.createElement("div", _extends({}, domProps, {
|
|
171
|
+
// Style
|
|
172
|
+
ref: rootRef,
|
|
173
|
+
className: className,
|
|
174
|
+
style: style
|
|
175
|
+
// Mouse Events
|
|
176
|
+
,
|
|
177
|
+
onMouseDown: onInternalMouseDown,
|
|
178
|
+
onBlur: onInternalBlur
|
|
179
|
+
}), /*#__PURE__*/React.createElement(_Affix.default, {
|
|
180
|
+
className: (0, _clsx.clsx)(`${prefixCls}-prefix`, classNames?.prefix),
|
|
181
|
+
style: styles?.prefix
|
|
182
|
+
}, prefix), /*#__PURE__*/React.createElement(_Content.default, {
|
|
183
|
+
ref: inputRef
|
|
184
|
+
}), /*#__PURE__*/React.createElement(_Affix.default, {
|
|
185
|
+
className: (0, _clsx.clsx)(`${prefixCls}-suffix`, {
|
|
186
|
+
[`${prefixCls}-suffix-loading`]: loading
|
|
187
|
+
}, classNames?.suffix),
|
|
188
|
+
style: styles?.suffix
|
|
189
|
+
}, suffix), clearIcon && /*#__PURE__*/React.createElement(_Affix.default, {
|
|
190
|
+
className: (0, _clsx.clsx)(`${prefixCls}-clear`, classNames?.clear),
|
|
191
|
+
style: styles?.clear,
|
|
192
|
+
onMouseDown: e => {
|
|
193
|
+
// Mark to tell not trigger open or focus
|
|
194
|
+
e.nativeEvent._select_lazy = true;
|
|
195
|
+
onClearMouseDown?.(e);
|
|
196
|
+
}
|
|
197
|
+
}, clearIcon), children));
|
|
198
|
+
});
|
package/lib/SelectTrigger.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface SelectTriggerProps {
|
|
|
24
24
|
empty: boolean;
|
|
25
25
|
onPopupVisibleChange?: (visible: boolean) => void;
|
|
26
26
|
onPopupMouseEnter: () => void;
|
|
27
|
+
onPopupMouseDown: React.MouseEventHandler<HTMLDivElement>;
|
|
27
28
|
}
|
|
28
29
|
declare const RefSelectTrigger: React.ForwardRefExoticComponent<SelectTriggerProps & React.RefAttributes<RefTriggerProps>>;
|
|
29
30
|
export default RefSelectTrigger;
|
package/lib/SelectTrigger.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _trigger = _interopRequireDefault(require("@rc-component/trigger"));
|
|
8
|
-
var
|
|
8
|
+
var _clsx = require("clsx");
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
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
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; }
|
|
@@ -74,6 +74,7 @@ const SelectTrigger = (props, ref) => {
|
|
|
74
74
|
empty,
|
|
75
75
|
onPopupVisibleChange,
|
|
76
76
|
onPopupMouseEnter,
|
|
77
|
+
onPopupMouseDown,
|
|
77
78
|
...restProps
|
|
78
79
|
} = props;
|
|
79
80
|
|
|
@@ -124,14 +125,15 @@ const SelectTrigger = (props, ref) => {
|
|
|
124
125
|
motionName: mergedTransitionName
|
|
125
126
|
},
|
|
126
127
|
popup: /*#__PURE__*/React.createElement("div", {
|
|
127
|
-
onMouseEnter: onPopupMouseEnter
|
|
128
|
+
onMouseEnter: onPopupMouseEnter,
|
|
129
|
+
onMouseDown: onPopupMouseDown
|
|
128
130
|
}, popupNode),
|
|
129
131
|
ref: triggerPopupRef,
|
|
130
132
|
stretch: stretch,
|
|
131
133
|
popupAlign: popupAlign,
|
|
132
134
|
popupVisible: visible,
|
|
133
135
|
getPopupContainer: getPopupContainer,
|
|
134
|
-
popupClassName: (0,
|
|
136
|
+
popupClassName: (0, _clsx.clsx)(popupClassName, {
|
|
135
137
|
[`${popupPrefixCls}-empty`]: empty
|
|
136
138
|
}),
|
|
137
139
|
popupStyle: mergedPopupStyle,
|
package/lib/TransBtn.d.ts
CHANGED
|
@@ -9,5 +9,15 @@ export interface TransBtnProps {
|
|
|
9
9
|
onClick?: React.MouseEventHandler<HTMLSpanElement>;
|
|
10
10
|
children?: React.ReactNode;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Small wrapper for Select icons (clear/arrow/etc.).
|
|
14
|
+
* Prevents default mousedown to avoid blurring or caret moves, and
|
|
15
|
+
* renders a custom icon or a fallback icon span.
|
|
16
|
+
*
|
|
17
|
+
* DOM structure:
|
|
18
|
+
* <span className={className} ...>
|
|
19
|
+
* { icon || <span className={`${className}-icon`}>{children}</span> }
|
|
20
|
+
* </span>
|
|
21
|
+
*/
|
|
12
22
|
declare const TransBtn: React.FC<TransBtnProps>;
|
|
13
23
|
export default TransBtn;
|
package/lib/TransBtn.js
CHANGED
|
@@ -5,10 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
-
var
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
var _clsx = require("clsx");
|
|
10
9
|
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
10
|
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; }
|
|
11
|
+
/**
|
|
12
|
+
* Small wrapper for Select icons (clear/arrow/etc.).
|
|
13
|
+
* Prevents default mousedown to avoid blurring or caret moves, and
|
|
14
|
+
* renders a custom icon or a fallback icon span.
|
|
15
|
+
*
|
|
16
|
+
* DOM structure:
|
|
17
|
+
* <span className={className} ...>
|
|
18
|
+
* { icon || <span className={`${className}-icon`}>{children}</span> }
|
|
19
|
+
* </span>
|
|
20
|
+
*/
|
|
12
21
|
const TransBtn = props => {
|
|
13
22
|
const {
|
|
14
23
|
className,
|
|
@@ -35,7 +44,7 @@ const TransBtn = props => {
|
|
|
35
44
|
onClick: onClick,
|
|
36
45
|
"aria-hidden": true
|
|
37
46
|
}, icon !== undefined ? icon : /*#__PURE__*/React.createElement("span", {
|
|
38
|
-
className: (0,
|
|
47
|
+
className: (0, _clsx.clsx)(className.split(/\s+/).map(cls => `${cls}-icon`))
|
|
39
48
|
}, children));
|
|
40
49
|
};
|
|
41
50
|
var _default = exports.default = TransBtn;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { DisplayValueType, Mode
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export
|
|
4
|
-
clearIcon?: RenderNode;
|
|
5
|
-
}, clearIcon?: RenderNode, disabled?: boolean, mergedSearchValue?: string, mode?: Mode) => {
|
|
1
|
+
import type { DisplayValueType, Mode } from '../interface';
|
|
2
|
+
import type React from 'react';
|
|
3
|
+
export interface AllowClearConfig {
|
|
6
4
|
allowClear: boolean;
|
|
7
|
-
clearIcon: React.
|
|
8
|
-
}
|
|
5
|
+
clearIcon: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const useAllowClear: (prefixCls: string, displayValues: DisplayValueType[], allowClear?: boolean | {
|
|
8
|
+
clearIcon?: React.ReactNode;
|
|
9
|
+
}, clearIcon?: React.ReactNode, disabled?: boolean, mergedSearchValue?: string, mode?: Mode) => AllowClearConfig;
|
|
@@ -4,31 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useAllowClear = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
const useAllowClear = (prefixCls, displayValues, allowClear, clearIcon, disabled = false, mergedSearchValue, mode) => {
|
|
9
|
+
// Convert boolean to object first
|
|
10
|
+
const allowClearConfig = (0, _react.useMemo)(() => {
|
|
11
|
+
if (typeof allowClear === 'boolean') {
|
|
12
|
+
return {
|
|
13
|
+
allowClear
|
|
14
|
+
};
|
|
14
15
|
}
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
16
|
+
if (allowClear && typeof allowClear === 'object') {
|
|
17
|
+
return allowClear;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
onMouseDown: onClearMouseDown,
|
|
30
|
-
customizeIcon: mergedClearIcon
|
|
31
|
-
}, "\xD7")
|
|
32
|
-
};
|
|
19
|
+
return {
|
|
20
|
+
allowClear: false
|
|
21
|
+
};
|
|
22
|
+
}, [allowClear]);
|
|
23
|
+
return (0, _react.useMemo)(() => {
|
|
24
|
+
const mergedAllowClear = !disabled && allowClearConfig.allowClear !== false && (displayValues.length || mergedSearchValue) && !(mode === 'combobox' && mergedSearchValue === '');
|
|
25
|
+
return {
|
|
26
|
+
allowClear: mergedAllowClear,
|
|
27
|
+
clearIcon: mergedAllowClear ? allowClearConfig.clearIcon || clearIcon || '×' : null
|
|
28
|
+
};
|
|
29
|
+
}, [allowClearConfig, clearIcon, disabled, displayValues.length, mergedSearchValue, mode]);
|
|
33
30
|
};
|
|
34
31
|
exports.useAllowClear = useAllowClear;
|
|
@@ -8,6 +8,7 @@ export interface BaseSelectContextProps extends BaseSelectProps {
|
|
|
8
8
|
triggerOpen: boolean;
|
|
9
9
|
multiple: boolean;
|
|
10
10
|
toggleOpen: (open?: boolean) => void;
|
|
11
|
+
role?: React.AriaRole;
|
|
11
12
|
}
|
|
12
13
|
export declare const BaseSelectContext: React.Context<BaseSelectContextProps>;
|
|
13
14
|
export default function useBaseProps(): BaseSelectContextProps;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { SelectInputRef, SelectInputProps } from '../SelectInput';
|
|
3
|
+
import type { BaseSelectProps } from '../BaseSelect';
|
|
4
|
+
export interface ComponentsConfig {
|
|
5
|
+
root?: React.ComponentType<any> | string | React.ReactElement;
|
|
6
|
+
input?: React.ComponentType<any> | string | React.ReactElement;
|
|
7
|
+
}
|
|
8
|
+
export interface FilledComponentsConfig {
|
|
9
|
+
root: React.ForwardRefExoticComponent<SelectInputProps & React.RefAttributes<SelectInputRef>>;
|
|
10
|
+
input: React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> | (React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement | HTMLTextAreaElement>)>;
|
|
11
|
+
}
|
|
12
|
+
export default function useComponents(components?: ComponentsConfig, getInputElement?: BaseSelectProps['getInputElement'], getRawInputElement?: BaseSelectProps['getRawInputElement']): ComponentsConfig;
|