@rc-component/select 1.2.0-alpha.1 → 1.2.0-alpha.3

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.
@@ -3,7 +3,7 @@ import type { ScrollConfig, ScrollTo } from 'rc-virtual-list/lib/List';
3
3
  import * as React from 'react';
4
4
  import type { DisplayInfoType, DisplayValueType, Mode, Placement, RawValueType, RenderDOMFunc, RenderNode } from '../interface';
5
5
  import type { ComponentsConfig } from '../hooks/useComponents';
6
- export type BaseSelectSemanticName = 'prefix' | 'suffix' | 'input' | 'clear';
6
+ export type BaseSelectSemanticName = 'prefix' | 'suffix' | 'input' | 'clear' | 'placeholder' | 'content' | 'item' | 'itemContent' | 'itemRemove';
7
7
  /**
8
8
  * ZombieJ:
9
9
  * We are currently refactoring the semantic structure of the component. Changelog:
@@ -318,7 +318,9 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
318
318
  }
319
319
  }
320
320
  if (!disabled) {
321
- triggerOpen(false);
321
+ triggerOpen(false, {
322
+ lazy: true
323
+ });
322
324
  onBlur?.(event);
323
325
  }
324
326
  };
@@ -331,7 +333,9 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
331
333
  // We should give focus back to selector if clicked item is not focusable
332
334
  if (popupElement?.contains(target) && triggerOpen) {
333
335
  // Tell `open` not to close since it's safe in the popup
334
- triggerOpen(true, true);
336
+ triggerOpen(true, {
337
+ ignoreNext: true
338
+ });
335
339
  }
336
340
  onMouseDown?.(event, ...restArgs);
337
341
  };
@@ -35,7 +35,9 @@ export default /*#__PURE__*/React.forwardRef(function MultipleContent({
35
35
  tagRender: tagRenderFromContext,
36
36
  maxTagPlaceholder: maxTagPlaceholderFromContext,
37
37
  maxTagTextLength,
38
- maxTagCount
38
+ maxTagCount,
39
+ classNames,
40
+ styles
39
41
  } = useBaseProps();
40
42
  const selectionItemPrefixCls = `${prefixCls}-selection-item`;
41
43
 
@@ -65,11 +67,14 @@ export default /*#__PURE__*/React.forwardRef(function MultipleContent({
65
67
  title: getTitle(item),
66
68
  className: clsx(selectionItemPrefixCls, {
67
69
  [`${selectionItemPrefixCls}-disabled`]: itemDisabled
68
- })
70
+ }, classNames?.item),
71
+ style: styles?.item
69
72
  }, /*#__PURE__*/React.createElement("span", {
70
- className: `${selectionItemPrefixCls}-content`
73
+ className: clsx(`${selectionItemPrefixCls}-content`, classNames?.itemContent),
74
+ style: styles?.itemContent
71
75
  }, content), closable && /*#__PURE__*/React.createElement(TransBtn, {
72
- className: `${selectionItemPrefixCls}-remove`,
76
+ className: clsx(`${selectionItemPrefixCls}-remove`, classNames?.itemRemove),
77
+ style: styles?.itemRemove,
73
78
  onMouseDown: onPreventMouseDown,
74
79
  onClick: onClose,
75
80
  customizeIcon: removeIcon
@@ -131,6 +136,8 @@ export default /*#__PURE__*/React.forwardRef(function MultipleContent({
131
136
  // ======================= Render =======================
132
137
  return /*#__PURE__*/React.createElement(Overflow, {
133
138
  prefixCls: `${prefixCls}-content`,
139
+ className: classNames?.content,
140
+ style: styles?.content,
134
141
  prefix: !displayValues.length && (!searchValue || !triggerOpen) ? /*#__PURE__*/React.createElement(Placeholder, null) : null,
135
142
  data: displayValues,
136
143
  renderItem: renderItem,
@@ -1,11 +1,17 @@
1
1
  import * as React from 'react';
2
+ import { clsx } from 'clsx';
2
3
  import { useSelectInputContext } from "../context";
4
+ import useBaseProps from "../../hooks/useBaseProps";
3
5
  export default function Placeholder(props) {
4
6
  const {
5
7
  prefixCls,
6
8
  placeholder,
7
9
  displayValues
8
10
  } = useSelectInputContext();
11
+ const {
12
+ classNames,
13
+ styles
14
+ } = useBaseProps();
9
15
  const {
10
16
  show = true
11
17
  } = props;
@@ -13,9 +19,10 @@ export default function Placeholder(props) {
13
19
  return null;
14
20
  }
15
21
  return /*#__PURE__*/React.createElement("div", {
16
- className: `${prefixCls}-placeholder`,
22
+ className: clsx(`${prefixCls}-placeholder`, classNames?.placeholder),
17
23
  style: {
18
- visibility: show ? 'visible' : 'hidden'
24
+ visibility: show ? 'visible' : 'hidden',
25
+ ...styles?.placeholder
19
26
  }
20
27
  }, placeholder);
21
28
  }
@@ -21,7 +21,9 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
21
21
  const {
22
22
  triggerOpen,
23
23
  title: rootTitle,
24
- showSearch
24
+ showSearch,
25
+ classNames,
26
+ styles
25
27
  } = useBaseProps();
26
28
  const selectContext = React.useContext(SelectContext);
27
29
  const [inputChanged, setInputChanged] = React.useState(false);
@@ -81,7 +83,8 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
81
83
  }
82
84
  }, [combobox, activeValue]);
83
85
  return /*#__PURE__*/React.createElement("div", {
84
- className: `${prefixCls}-content`
86
+ className: clsx(`${prefixCls}-content`, classNames?.content),
87
+ style: styles?.content
85
88
  }, displayValue ? /*#__PURE__*/React.createElement("div", optionProps, displayValue.label) : /*#__PURE__*/React.createElement(Placeholder, {
86
89
  show: !mergedSearchValue
87
90
  }), /*#__PURE__*/React.createElement(Input, _extends({
@@ -2,7 +2,10 @@
2
2
  * Trigger by latest open call, if nextOpen is undefined, means toggle.
3
3
  * ignoreNext will skip next call in the macro task queue.
4
4
  */
5
- export type TriggerOpenType = (nextOpen?: boolean, ignoreNext?: boolean) => void;
5
+ export type TriggerOpenType = (nextOpen?: boolean, config?: {
6
+ ignoreNext?: boolean;
7
+ lazy?: boolean;
8
+ }) => void;
6
9
  /**
7
10
  * When `open` is controlled, follow the controlled value;
8
11
  * Otherwise use uncontrolled logic.
@@ -48,27 +48,33 @@ export default function useOpen(propOpen, onOpen, postOpen) {
48
48
  }
49
49
  internalSetOpen(nextOpen);
50
50
  });
51
- const toggleOpen = useEvent((nextOpen, ignoreNext = false) => {
51
+ const toggleOpen = useEvent((nextOpen, config = {}) => {
52
+ const {
53
+ ignoreNext = false,
54
+ lazy = false
55
+ } = config;
52
56
  taskIdRef.current += 1;
53
57
  const id = taskIdRef.current;
54
58
  const nextOpenVal = typeof nextOpen === 'boolean' ? nextOpen : !mergedOpen;
55
59
 
56
60
  // Since `mergedOpen` is post-processed, we need to check if the value really changed
57
- if (nextOpenVal) {
58
- triggerEvent(true);
61
+ if (nextOpenVal || !lazy) {
62
+ if (!taskLockRef.current) {
63
+ triggerEvent(nextOpenVal);
59
64
 
60
- // Lock if needed
61
- if (ignoreNext) {
62
- taskLockRef.current = ignoreNext;
63
- macroTask(() => {
64
- taskLockRef.current = false;
65
- }, 2);
65
+ // Lock if needed
66
+ if (ignoreNext) {
67
+ taskLockRef.current = ignoreNext;
68
+ macroTask(() => {
69
+ taskLockRef.current = false;
70
+ }, 2);
71
+ }
66
72
  }
67
73
  return;
68
74
  }
69
75
  macroTask(() => {
70
76
  if (id === taskIdRef.current && !taskLockRef.current) {
71
- triggerEvent(false);
77
+ triggerEvent(nextOpenVal);
72
78
  }
73
79
  });
74
80
  });
@@ -3,7 +3,7 @@ import type { ScrollConfig, ScrollTo } from 'rc-virtual-list/lib/List';
3
3
  import * as React from 'react';
4
4
  import type { DisplayInfoType, DisplayValueType, Mode, Placement, RawValueType, RenderDOMFunc, RenderNode } from '../interface';
5
5
  import type { ComponentsConfig } from '../hooks/useComponents';
6
- export type BaseSelectSemanticName = 'prefix' | 'suffix' | 'input' | 'clear';
6
+ export type BaseSelectSemanticName = 'prefix' | 'suffix' | 'input' | 'clear' | 'placeholder' | 'content' | 'item' | 'itemContent' | 'itemRemove';
7
7
  /**
8
8
  * ZombieJ:
9
9
  * We are currently refactoring the semantic structure of the component. Changelog:
@@ -327,7 +327,9 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
327
327
  }
328
328
  }
329
329
  if (!disabled) {
330
- triggerOpen(false);
330
+ triggerOpen(false, {
331
+ lazy: true
332
+ });
331
333
  onBlur?.(event);
332
334
  }
333
335
  };
@@ -340,7 +342,9 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
340
342
  // We should give focus back to selector if clicked item is not focusable
341
343
  if (popupElement?.contains(target) && triggerOpen) {
342
344
  // Tell `open` not to close since it's safe in the popup
343
- triggerOpen(true, true);
345
+ triggerOpen(true, {
346
+ ignoreNext: true
347
+ });
344
348
  }
345
349
  onMouseDown?.(event, ...restArgs);
346
350
  };
@@ -44,7 +44,9 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function Multiple
44
44
  tagRender: tagRenderFromContext,
45
45
  maxTagPlaceholder: maxTagPlaceholderFromContext,
46
46
  maxTagTextLength,
47
- maxTagCount
47
+ maxTagCount,
48
+ classNames,
49
+ styles
48
50
  } = (0, _useBaseProps.default)();
49
51
  const selectionItemPrefixCls = `${prefixCls}-selection-item`;
50
52
 
@@ -74,11 +76,14 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function Multiple
74
76
  title: (0, _commonUtil.getTitle)(item),
75
77
  className: (0, _clsx.clsx)(selectionItemPrefixCls, {
76
78
  [`${selectionItemPrefixCls}-disabled`]: itemDisabled
77
- })
79
+ }, classNames?.item),
80
+ style: styles?.item
78
81
  }, /*#__PURE__*/React.createElement("span", {
79
- className: `${selectionItemPrefixCls}-content`
82
+ className: (0, _clsx.clsx)(`${selectionItemPrefixCls}-content`, classNames?.itemContent),
83
+ style: styles?.itemContent
80
84
  }, content), closable && /*#__PURE__*/React.createElement(_TransBtn.default, {
81
- className: `${selectionItemPrefixCls}-remove`,
85
+ className: (0, _clsx.clsx)(`${selectionItemPrefixCls}-remove`, classNames?.itemRemove),
86
+ style: styles?.itemRemove,
82
87
  onMouseDown: onPreventMouseDown,
83
88
  onClick: onClose,
84
89
  customizeIcon: removeIcon
@@ -140,6 +145,8 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function Multiple
140
145
  // ======================= Render =======================
141
146
  return /*#__PURE__*/React.createElement(_rcOverflow.default, {
142
147
  prefixCls: `${prefixCls}-content`,
148
+ className: classNames?.content,
149
+ style: styles?.content,
143
150
  prefix: !displayValues.length && (!searchValue || !triggerOpen) ? /*#__PURE__*/React.createElement(_Placeholder.default, null) : null,
144
151
  data: displayValues,
145
152
  renderItem: renderItem,
@@ -5,7 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = Placeholder;
7
7
  var React = _interopRequireWildcard(require("react"));
8
+ var _clsx = require("clsx");
8
9
  var _context = require("../context");
10
+ var _useBaseProps = _interopRequireDefault(require("../../hooks/useBaseProps"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
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); }
10
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; }
11
14
  function Placeholder(props) {
@@ -14,6 +17,10 @@ function Placeholder(props) {
14
17
  placeholder,
15
18
  displayValues
16
19
  } = (0, _context.useSelectInputContext)();
20
+ const {
21
+ classNames,
22
+ styles
23
+ } = (0, _useBaseProps.default)();
17
24
  const {
18
25
  show = true
19
26
  } = props;
@@ -21,9 +28,10 @@ function Placeholder(props) {
21
28
  return null;
22
29
  }
23
30
  return /*#__PURE__*/React.createElement("div", {
24
- className: `${prefixCls}-placeholder`,
31
+ className: (0, _clsx.clsx)(`${prefixCls}-placeholder`, classNames?.placeholder),
25
32
  style: {
26
- visibility: show ? 'visible' : 'hidden'
33
+ visibility: show ? 'visible' : 'hidden',
34
+ ...styles?.placeholder
27
35
  }
28
36
  }, placeholder);
29
37
  }
@@ -30,7 +30,9 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
30
30
  const {
31
31
  triggerOpen,
32
32
  title: rootTitle,
33
- showSearch
33
+ showSearch,
34
+ classNames,
35
+ styles
34
36
  } = (0, _useBaseProps.default)();
35
37
  const selectContext = React.useContext(_SelectContext.default);
36
38
  const [inputChanged, setInputChanged] = React.useState(false);
@@ -90,7 +92,8 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
90
92
  }
91
93
  }, [combobox, activeValue]);
92
94
  return /*#__PURE__*/React.createElement("div", {
93
- className: `${prefixCls}-content`
95
+ className: (0, _clsx.clsx)(`${prefixCls}-content`, classNames?.content),
96
+ style: styles?.content
94
97
  }, displayValue ? /*#__PURE__*/React.createElement("div", optionProps, displayValue.label) : /*#__PURE__*/React.createElement(_Placeholder.default, {
95
98
  show: !mergedSearchValue
96
99
  }), /*#__PURE__*/React.createElement(_Input.default, _extends({
@@ -2,7 +2,10 @@
2
2
  * Trigger by latest open call, if nextOpen is undefined, means toggle.
3
3
  * ignoreNext will skip next call in the macro task queue.
4
4
  */
5
- export type TriggerOpenType = (nextOpen?: boolean, ignoreNext?: boolean) => void;
5
+ export type TriggerOpenType = (nextOpen?: boolean, config?: {
6
+ ignoreNext?: boolean;
7
+ lazy?: boolean;
8
+ }) => void;
6
9
  /**
7
10
  * When `open` is controlled, follow the controlled value;
8
11
  * Otherwise use uncontrolled logic.
@@ -54,27 +54,33 @@ function useOpen(propOpen, onOpen, postOpen) {
54
54
  }
55
55
  internalSetOpen(nextOpen);
56
56
  });
57
- const toggleOpen = (0, _util.useEvent)((nextOpen, ignoreNext = false) => {
57
+ const toggleOpen = (0, _util.useEvent)((nextOpen, config = {}) => {
58
+ const {
59
+ ignoreNext = false,
60
+ lazy = false
61
+ } = config;
58
62
  taskIdRef.current += 1;
59
63
  const id = taskIdRef.current;
60
64
  const nextOpenVal = typeof nextOpen === 'boolean' ? nextOpen : !mergedOpen;
61
65
 
62
66
  // Since `mergedOpen` is post-processed, we need to check if the value really changed
63
- if (nextOpenVal) {
64
- triggerEvent(true);
67
+ if (nextOpenVal || !lazy) {
68
+ if (!taskLockRef.current) {
69
+ triggerEvent(nextOpenVal);
65
70
 
66
- // Lock if needed
67
- if (ignoreNext) {
68
- taskLockRef.current = ignoreNext;
69
- macroTask(() => {
70
- taskLockRef.current = false;
71
- }, 2);
71
+ // Lock if needed
72
+ if (ignoreNext) {
73
+ taskLockRef.current = ignoreNext;
74
+ macroTask(() => {
75
+ taskLockRef.current = false;
76
+ }, 2);
77
+ }
72
78
  }
73
79
  return;
74
80
  }
75
81
  macroTask(() => {
76
82
  if (id === taskIdRef.current && !taskLockRef.current) {
77
- triggerEvent(false);
83
+ triggerEvent(nextOpenVal);
78
84
  }
79
85
  });
80
86
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/select",
3
- "version": "1.2.0-alpha.1",
3
+ "version": "1.2.0-alpha.3",
4
4
  "description": "React Select",
5
5
  "engines": {
6
6
  "node": ">=8.x"