@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.
Files changed (99) hide show
  1. package/assets/index.css +63 -0
  2. package/assets/index.less +1 -0
  3. package/assets/patch.less +83 -0
  4. package/es/BaseSelect/index.d.ts +14 -3
  5. package/es/BaseSelect/index.js +137 -200
  6. package/es/OptionList.js +3 -3
  7. package/es/Select.d.ts +1 -1
  8. package/es/Select.js +5 -9
  9. package/es/SelectInput/Affix.d.ts +5 -0
  10. package/es/SelectInput/Affix.js +12 -0
  11. package/es/SelectInput/Content/MultipleContent.d.ts +4 -0
  12. package/es/SelectInput/Content/MultipleContent.js +152 -0
  13. package/es/SelectInput/Content/Placeholder.d.ts +5 -0
  14. package/es/SelectInput/Content/Placeholder.js +21 -0
  15. package/es/SelectInput/Content/SingleContent.d.ts +4 -0
  16. package/es/SelectInput/Content/SingleContent.js +98 -0
  17. package/es/SelectInput/Content/index.d.ts +6 -0
  18. package/es/SelectInput/Content/index.js +37 -0
  19. package/es/SelectInput/Input.d.ts +20 -0
  20. package/es/SelectInput/Input.js +214 -0
  21. package/es/SelectInput/context.d.ts +6 -0
  22. package/es/SelectInput/context.js +6 -0
  23. package/es/SelectInput/index.d.ts +39 -0
  24. package/es/SelectInput/index.js +189 -0
  25. package/es/SelectTrigger.d.ts +1 -0
  26. package/es/SelectTrigger.js +5 -3
  27. package/es/TransBtn.d.ts +10 -0
  28. package/es/TransBtn.js +12 -2
  29. package/es/hooks/useAllowClear.d.ts +8 -7
  30. package/es/hooks/useAllowClear.js +21 -23
  31. package/es/hooks/useBaseProps.d.ts +1 -0
  32. package/es/hooks/useComponents.d.ts +12 -0
  33. package/es/hooks/useComponents.js +23 -0
  34. package/es/hooks/useOpen.d.ts +15 -0
  35. package/es/hooks/useOpen.js +76 -0
  36. package/es/hooks/useSearchConfig.d.ts +2 -2
  37. package/es/hooks/useSearchConfig.js +3 -3
  38. package/es/hooks/useSelectTriggerControl.d.ts +1 -1
  39. package/es/hooks/useSelectTriggerControl.js +16 -21
  40. package/es/utils/keyUtil.js +4 -0
  41. package/lib/BaseSelect/index.d.ts +14 -3
  42. package/lib/BaseSelect/index.js +137 -201
  43. package/lib/OptionList.js +3 -3
  44. package/lib/Select.d.ts +1 -1
  45. package/lib/Select.js +5 -9
  46. package/lib/SelectInput/Affix.d.ts +5 -0
  47. package/lib/{hooks/useLayoutEffect.js → SelectInput/Affix.js} +11 -16
  48. package/lib/SelectInput/Content/MultipleContent.d.ts +4 -0
  49. package/lib/{Selector/MultipleSelector.js → SelectInput/Content/MultipleContent.js} +71 -104
  50. package/lib/SelectInput/Content/Placeholder.d.ts +5 -0
  51. package/lib/SelectInput/Content/Placeholder.js +29 -0
  52. package/lib/SelectInput/Content/SingleContent.d.ts +4 -0
  53. package/lib/SelectInput/Content/SingleContent.js +107 -0
  54. package/lib/SelectInput/Content/index.d.ts +6 -0
  55. package/lib/SelectInput/Content/index.js +46 -0
  56. package/lib/SelectInput/Input.d.ts +20 -0
  57. package/lib/SelectInput/Input.js +223 -0
  58. package/lib/SelectInput/context.d.ts +6 -0
  59. package/lib/SelectInput/context.js +15 -0
  60. package/lib/SelectInput/index.d.ts +39 -0
  61. package/lib/SelectInput/index.js +198 -0
  62. package/lib/SelectTrigger.d.ts +1 -0
  63. package/lib/SelectTrigger.js +5 -3
  64. package/lib/TransBtn.d.ts +10 -0
  65. package/lib/TransBtn.js +12 -3
  66. package/lib/hooks/useAllowClear.d.ts +8 -7
  67. package/lib/hooks/useAllowClear.js +21 -24
  68. package/lib/hooks/useBaseProps.d.ts +1 -0
  69. package/lib/hooks/useComponents.d.ts +12 -0
  70. package/lib/hooks/{useDelayReset.js → useComponents.js} +21 -30
  71. package/lib/hooks/useOpen.d.ts +15 -0
  72. package/lib/hooks/useOpen.js +82 -0
  73. package/lib/hooks/useSearchConfig.d.ts +2 -2
  74. package/lib/hooks/useSearchConfig.js +3 -3
  75. package/lib/hooks/useSelectTriggerControl.d.ts +1 -1
  76. package/lib/hooks/useSelectTriggerControl.js +16 -21
  77. package/lib/utils/keyUtil.js +4 -0
  78. package/package.json +5 -4
  79. package/es/Selector/Input.d.ts +0 -27
  80. package/es/Selector/Input.js +0 -61
  81. package/es/Selector/MultipleSelector.d.ts +0 -16
  82. package/es/Selector/MultipleSelector.js +0 -185
  83. package/es/Selector/SingleSelector.d.ts +0 -8
  84. package/es/Selector/SingleSelector.js +0 -104
  85. package/es/Selector/index.d.ts +0 -83
  86. package/es/Selector/index.js +0 -189
  87. package/es/hooks/useDelayReset.d.ts +0 -5
  88. package/es/hooks/useDelayReset.js +0 -33
  89. package/es/hooks/useLayoutEffect.d.ts +0 -5
  90. package/es/hooks/useLayoutEffect.js +0 -17
  91. package/lib/Selector/Input.d.ts +0 -27
  92. package/lib/Selector/Input.js +0 -70
  93. package/lib/Selector/MultipleSelector.d.ts +0 -16
  94. package/lib/Selector/SingleSelector.d.ts +0 -8
  95. package/lib/Selector/SingleSelector.js +0 -113
  96. package/lib/Selector/index.d.ts +0 -83
  97. package/lib/Selector/index.js +0 -196
  98. package/lib/hooks/useDelayReset.d.ts +0 -5
  99. package/lib/hooks/useLayoutEffect.d.ts +0 -5
@@ -1,83 +0,0 @@
1
- /**
2
- * Cursor rule:
3
- * 1. Only `showSearch` enabled
4
- * 2. Only `open` is `true`
5
- * 3. When typing, set `open` to `true` which hit rule of 2
6
- *
7
- * Accessibility:
8
- * - https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html
9
- */
10
- import type { ScrollTo } from 'rc-virtual-list/lib/List';
11
- import * as React from 'react';
12
- import type { CustomTagProps, DisplayValueType, Mode, RenderNode } from '../BaseSelect';
13
- export interface InnerSelectorProps {
14
- prefixCls: string;
15
- id: string;
16
- mode: Mode;
17
- title?: string;
18
- inputRef: React.Ref<HTMLInputElement | HTMLTextAreaElement>;
19
- placeholder?: React.ReactNode;
20
- disabled?: boolean;
21
- autoFocus?: boolean;
22
- autoComplete?: string;
23
- values: DisplayValueType[];
24
- showSearch?: boolean;
25
- searchValue: string;
26
- autoClearSearchValue?: boolean;
27
- activeDescendantId?: string;
28
- open: boolean;
29
- tabIndex?: number;
30
- maxLength?: number;
31
- onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
32
- onInputMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
33
- onInputChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
34
- onInputPaste: React.ClipboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
35
- onInputCompositionStart: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
36
- onInputCompositionEnd: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
37
- onInputBlur: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
38
- }
39
- export interface RefSelectorProps {
40
- focus: (options?: FocusOptions) => void;
41
- blur: () => void;
42
- scrollTo?: ScrollTo;
43
- nativeElement: HTMLDivElement;
44
- }
45
- export interface SelectorProps {
46
- prefixClassName: string;
47
- prefixStyle: React.CSSProperties;
48
- id: string;
49
- prefixCls: string;
50
- showSearch?: boolean;
51
- open: boolean;
52
- /** Display in the Selector value, it's not same as `value` prop */
53
- values: DisplayValueType[];
54
- mode: Mode;
55
- searchValue: string;
56
- activeValue: string;
57
- autoClearSearchValue: boolean;
58
- inputElement: JSX.Element;
59
- maxLength?: number;
60
- autoFocus?: boolean;
61
- activeDescendantId?: string;
62
- tabIndex?: number;
63
- disabled?: boolean;
64
- placeholder?: React.ReactNode;
65
- removeIcon?: RenderNode;
66
- prefix?: React.ReactNode;
67
- maxTagCount?: number | 'responsive';
68
- maxTagTextLength?: number;
69
- maxTagPlaceholder?: React.ReactNode | ((omittedValues: DisplayValueType[]) => React.ReactNode);
70
- tagRender?: (props: CustomTagProps) => React.ReactElement;
71
- /** Check if `tokenSeparators` contains `\n` or `\r\n` */
72
- tokenWithEnter?: boolean;
73
- choiceTransitionName?: string;
74
- onToggleOpen: (open?: boolean) => void;
75
- /** `onSearch` returns go next step boolean to check if need do toggle open */
76
- onSearch: (searchText: string, fromTyping: boolean, isCompositing: boolean) => boolean;
77
- onSearchSubmit?: (searchText: string) => void;
78
- onRemove: (value: DisplayValueType) => void;
79
- onInputKeyDown?: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
80
- onInputBlur?: () => void;
81
- }
82
- declare const ForwardSelector: React.ForwardRefExoticComponent<SelectorProps & React.RefAttributes<RefSelectorProps>>;
83
- export default ForwardSelector;
@@ -1,196 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _KeyCode = _interopRequireDefault(require("@rc-component/util/lib/KeyCode"));
8
- var _react = _interopRequireWildcard(require("react"));
9
- var React = _react;
10
- var _useLock = _interopRequireDefault(require("../hooks/useLock"));
11
- var _keyUtil = require("../utils/keyUtil");
12
- var _MultipleSelector = _interopRequireDefault(require("./MultipleSelector"));
13
- var _SingleSelector = _interopRequireDefault(require("./SingleSelector"));
14
- var _classnames = _interopRequireDefault(require("classnames"));
15
- 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); }
16
- 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; }
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
- 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); } /**
19
- * Cursor rule:
20
- * 1. Only `showSearch` enabled
21
- * 2. Only `open` is `true`
22
- * 3. When typing, set `open` to `true` which hit rule of 2
23
- *
24
- * Accessibility:
25
- * - https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html
26
- */
27
- const Selector = (props, ref) => {
28
- const inputRef = (0, _react.useRef)(null);
29
- const compositionStatusRef = (0, _react.useRef)(false);
30
- const {
31
- prefixClassName,
32
- prefixStyle,
33
- prefixCls,
34
- open,
35
- mode,
36
- showSearch,
37
- tokenWithEnter,
38
- disabled,
39
- prefix,
40
- autoClearSearchValue,
41
- onSearch,
42
- onSearchSubmit,
43
- onToggleOpen,
44
- onInputKeyDown,
45
- onInputBlur
46
- } = props;
47
-
48
- // ======================= Ref =======================
49
- const containerRef = React.useRef(null);
50
- React.useImperativeHandle(ref, () => ({
51
- focus: options => {
52
- inputRef.current.focus(options);
53
- },
54
- blur: () => {
55
- inputRef.current.blur();
56
- },
57
- nativeElement: containerRef.current
58
- }));
59
-
60
- // ====================== Input ======================
61
- const [getInputMouseDown, setInputMouseDown] = (0, _useLock.default)(0);
62
- const onInternalInputKeyDown = event => {
63
- const {
64
- which
65
- } = event;
66
-
67
- // Compatible with multiple lines in TextArea
68
- const isTextAreaElement = inputRef.current instanceof HTMLTextAreaElement;
69
- if (!isTextAreaElement && open && (which === _KeyCode.default.UP || which === _KeyCode.default.DOWN)) {
70
- event.preventDefault();
71
- }
72
- if (onInputKeyDown) {
73
- onInputKeyDown(event);
74
- }
75
- if (which === _KeyCode.default.ENTER && mode === 'tags' && !compositionStatusRef.current && !open) {
76
- // When menu isn't open, OptionList won't trigger a value change
77
- // So when enter is pressed, the tag's input value should be emitted here to let selector know
78
- onSearchSubmit?.(event.target.value);
79
- }
80
- // Move within the text box
81
- if (isTextAreaElement && !open && ~[_KeyCode.default.UP, _KeyCode.default.DOWN, _KeyCode.default.LEFT, _KeyCode.default.RIGHT].indexOf(which)) {
82
- return;
83
- }
84
- if ((0, _keyUtil.isValidateOpenKey)(which)) {
85
- onToggleOpen(true);
86
- }
87
- };
88
-
89
- /**
90
- * We can not use `findDOMNode` sine it will get warning,
91
- * have to use timer to check if is input element.
92
- */
93
- const onInternalInputMouseDown = () => {
94
- setInputMouseDown(true);
95
- };
96
-
97
- // When paste come, ignore next onChange
98
- const pastedTextRef = (0, _react.useRef)(null);
99
- const triggerOnSearch = value => {
100
- if (onSearch(value, true, compositionStatusRef.current) !== false) {
101
- onToggleOpen(true);
102
- }
103
- };
104
- const onInputCompositionStart = () => {
105
- compositionStatusRef.current = true;
106
- };
107
- const onInputCompositionEnd = e => {
108
- compositionStatusRef.current = false;
109
-
110
- // Trigger search again to support `tokenSeparators` with typewriting
111
- if (mode !== 'combobox') {
112
- triggerOnSearch(e.target.value);
113
- }
114
- };
115
- const onInputChange = event => {
116
- let {
117
- target: {
118
- value
119
- }
120
- } = event;
121
-
122
- // Pasted text should replace back to origin content
123
- if (tokenWithEnter && pastedTextRef.current && /[\r\n]/.test(pastedTextRef.current)) {
124
- // CRLF will be treated as a single space for input element
125
- const replacedText = pastedTextRef.current.replace(/[\r\n]+$/, '').replace(/\r\n/g, ' ').replace(/[\r\n]/g, ' ');
126
- value = value.replace(replacedText, pastedTextRef.current);
127
- }
128
- pastedTextRef.current = null;
129
- triggerOnSearch(value);
130
- };
131
- const onInputPaste = e => {
132
- const {
133
- clipboardData
134
- } = e;
135
- const value = clipboardData?.getData('text');
136
- pastedTextRef.current = value || '';
137
- };
138
- const onClick = ({
139
- target
140
- }) => {
141
- if (target !== inputRef.current) {
142
- // Should focus input if click the selector
143
- const isIE = document.body.style.msTouchAction !== undefined;
144
- if (isIE) {
145
- setTimeout(() => {
146
- inputRef.current.focus();
147
- });
148
- } else {
149
- inputRef.current.focus();
150
- }
151
- }
152
- };
153
- const onMouseDown = event => {
154
- const inputMouseDown = getInputMouseDown();
155
-
156
- // when mode is combobox and it is disabled, don't prevent default behavior
157
- // https://github.com/ant-design/ant-design/issues/37320
158
- // https://github.com/ant-design/ant-design/issues/48281
159
- if (event.target !== inputRef.current && !inputMouseDown && !(mode === 'combobox' && disabled)) {
160
- event.preventDefault();
161
- }
162
- if (mode !== 'combobox' && (!showSearch || !inputMouseDown) || !open) {
163
- if (open && autoClearSearchValue !== false) {
164
- onSearch('', true, false);
165
- }
166
- onToggleOpen();
167
- }
168
- };
169
-
170
- // ================= Inner Selector ==================
171
- const sharedProps = {
172
- inputRef,
173
- onInputKeyDown: onInternalInputKeyDown,
174
- onInputMouseDown: onInternalInputMouseDown,
175
- onInputChange,
176
- onInputPaste,
177
- onInputCompositionStart,
178
- onInputCompositionEnd,
179
- onInputBlur
180
- };
181
- const selectNode = mode === 'multiple' || mode === 'tags' ? /*#__PURE__*/React.createElement(_MultipleSelector.default, _extends({}, props, sharedProps)) : /*#__PURE__*/React.createElement(_SingleSelector.default, _extends({}, props, sharedProps));
182
- return /*#__PURE__*/React.createElement("div", {
183
- ref: containerRef,
184
- className: `${prefixCls}-selector`,
185
- onClick: onClick,
186
- onMouseDown: onMouseDown
187
- }, prefix && /*#__PURE__*/React.createElement("div", {
188
- className: (0, _classnames.default)(`${prefixCls}-prefix`, prefixClassName),
189
- style: prefixStyle
190
- }, prefix), selectNode);
191
- };
192
- const ForwardSelector = /*#__PURE__*/React.forwardRef(Selector);
193
- if (process.env.NODE_ENV !== 'production') {
194
- ForwardSelector.displayName = 'Selector';
195
- }
196
- var _default = exports.default = ForwardSelector;
@@ -1,5 +0,0 @@
1
- /**
2
- * Similar with `useLock`, but this hook will always execute last value.
3
- * When set to `true`, it will keep `true` for a short time even if `false` is set.
4
- */
5
- export default function useDelayReset(timeout?: number): [boolean, (val: boolean, callback?: () => void) => void, () => void];
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Wrap `React.useLayoutEffect` which will not throw warning message in test env
4
- */
5
- export default function useLayoutEffect(effect: React.EffectCallback, deps?: React.DependencyList): void;