@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,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.warningNullOptions = warningNullOptions;
8
+ var _toArray = _interopRequireDefault(require("@rc-component/util/lib/Children/toArray"));
9
+ var _warning = _interopRequireWildcard(require("@rc-component/util/lib/warning"));
10
+ var React = _interopRequireWildcard(require("react"));
11
+ var _BaseSelect = require("../BaseSelect");
12
+ var _commonUtil = require("./commonUtil");
13
+ var _legacyUtil = require("./legacyUtil");
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
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ function warningProps(props) {
18
+ const {
19
+ mode,
20
+ options,
21
+ children,
22
+ backfill,
23
+ allowClear,
24
+ placeholder,
25
+ getInputElement,
26
+ showSearch,
27
+ onSearch,
28
+ defaultOpen,
29
+ autoFocus,
30
+ labelInValue,
31
+ value,
32
+ optionLabelProp
33
+ } = props;
34
+ const multiple = (0, _BaseSelect.isMultiple)(mode);
35
+ const mergedShowSearch = showSearch !== undefined ? showSearch : multiple || mode === 'combobox';
36
+ const mergedOptions = options || (0, _legacyUtil.convertChildrenToData)(children);
37
+
38
+ // `tags` should not set option as disabled
39
+ (0, _warning.default)(mode !== 'tags' || mergedOptions.every(opt => !opt.disabled), 'Please avoid setting option to disabled in tags mode since user can always type text as tag.');
40
+
41
+ // `combobox` & `tags` should option be `string` type
42
+ if (mode === 'tags' || mode === 'combobox') {
43
+ const hasNumberValue = mergedOptions.some(item => {
44
+ if (item.options) {
45
+ return item.options.some(opt => typeof ('value' in opt ? opt.value : opt.key) === 'number');
46
+ }
47
+ return typeof ('value' in item ? item.value : item.key) === 'number';
48
+ });
49
+ (0, _warning.default)(!hasNumberValue, '`value` of Option should not use number type when `mode` is `tags` or `combobox`.');
50
+ }
51
+
52
+ // `combobox` should not use `optionLabelProp`
53
+ (0, _warning.default)(mode !== 'combobox' || !optionLabelProp, '`combobox` mode not support `optionLabelProp`. Please set `value` on Option directly.');
54
+
55
+ // Only `combobox` support `backfill`
56
+ (0, _warning.default)(mode === 'combobox' || !backfill, '`backfill` only works with `combobox` mode.');
57
+
58
+ // Only `combobox` support `getInputElement`
59
+ (0, _warning.default)(mode === 'combobox' || !getInputElement, '`getInputElement` only work with `combobox` mode.');
60
+
61
+ // Customize `getInputElement` should not use `allowClear` & `placeholder`
62
+ (0, _warning.noteOnce)(mode !== 'combobox' || !getInputElement || !allowClear || !placeholder, 'Customize `getInputElement` should customize clear and placeholder logic instead of configuring `allowClear` and `placeholder`.');
63
+
64
+ // `onSearch` should use in `combobox` or `showSearch`
65
+ if (onSearch && !mergedShowSearch && mode !== 'combobox' && mode !== 'tags') {
66
+ (0, _warning.default)(false, '`onSearch` should work with `showSearch` instead of use alone.');
67
+ }
68
+ (0, _warning.noteOnce)(!defaultOpen || autoFocus, '`defaultOpen` makes Select open without focus which means it will not close by click outside. You can set `autoFocus` if needed.');
69
+ if (value !== undefined && value !== null) {
70
+ const values = (0, _commonUtil.toArray)(value);
71
+ (0, _warning.default)(!labelInValue || values.every(val => typeof val === 'object' && ('key' in val || 'value' in val)), '`value` should in shape of `{ value: string | number, label?: ReactNode }` when you set `labelInValue` to `true`');
72
+ (0, _warning.default)(!multiple || Array.isArray(value), '`value` should be array when `mode` is `multiple` or `tags`');
73
+ }
74
+
75
+ // Syntactic sugar should use correct children type
76
+ if (children) {
77
+ let invalidateChildType = null;
78
+ (0, _toArray.default)(children).some(node => {
79
+ if (! /*#__PURE__*/React.isValidElement(node) || !node.type) {
80
+ return false;
81
+ }
82
+ const {
83
+ type
84
+ } = node;
85
+ if (type.isSelectOption) {
86
+ return false;
87
+ }
88
+ if (type.isSelectOptGroup) {
89
+ const allChildrenValid = (0, _toArray.default)(node.props.children).every(subNode => {
90
+ if (! /*#__PURE__*/React.isValidElement(subNode) || !node.type || subNode.type.isSelectOption) {
91
+ return true;
92
+ }
93
+ invalidateChildType = subNode.type;
94
+ return false;
95
+ });
96
+ if (allChildrenValid) {
97
+ return false;
98
+ }
99
+ return true;
100
+ }
101
+ invalidateChildType = type;
102
+ return true;
103
+ });
104
+ if (invalidateChildType) {
105
+ (0, _warning.default)(false, `\`children\` should be \`Select.Option\` or \`Select.OptGroup\` instead of \`${invalidateChildType.displayName || invalidateChildType.name || invalidateChildType}\`.`);
106
+ }
107
+ }
108
+ }
109
+
110
+ // value in Select option should not be null
111
+ // note: OptGroup has options too
112
+ function warningNullOptions(options, fieldNames) {
113
+ if (options) {
114
+ const recursiveOptions = (optionsList, inGroup = false) => {
115
+ for (let i = 0; i < optionsList.length; i++) {
116
+ const option = optionsList[i];
117
+ if (option[fieldNames?.value] === null) {
118
+ (0, _warning.default)(false, '`value` in Select options should not be `null`.');
119
+ return true;
120
+ }
121
+ if (!inGroup && Array.isArray(option[fieldNames?.options]) && recursiveOptions(option[fieldNames?.options], true)) {
122
+ break;
123
+ }
124
+ }
125
+ };
126
+ recursiveOptions(options);
127
+ }
128
+ }
129
+ var _default = exports.default = warningProps;
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@rc-component/select",
3
+ "version": "1.0.0",
4
+ "description": "React Select",
5
+ "engines": {
6
+ "node": ">=8.x"
7
+ },
8
+ "keywords": [
9
+ "react",
10
+ "react-component",
11
+ "react-select",
12
+ "select"
13
+ ],
14
+ "main": "./lib/index",
15
+ "module": "./es/index",
16
+ "types": "./lib/index.d.ts",
17
+ "files": [
18
+ "assets/*.css",
19
+ "assets/*.less",
20
+ "es",
21
+ "lib"
22
+ ],
23
+ "homepage": "http://github.com/react-component/select",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git@github.com:react-component/select.git"
27
+ },
28
+ "bugs": {
29
+ "url": "http://github.com/react-component/select/issues"
30
+ },
31
+ "license": "MIT",
32
+ "scripts": {
33
+ "start": "dumi dev",
34
+ "build": "dumi build",
35
+ "prepare": "husky && dumi setup",
36
+ "compile": "father build && lessc assets/index.less assets/index.css",
37
+ "prepublishOnly": "npm run compile && rc-np",
38
+ "prettier": "prettier --write --ignore-unknown .",
39
+ "lint": "eslint src/ docs/ tests/ --ext .tsx,.ts,.jsx,.js",
40
+ "test": "rc-test",
41
+ "tsc": "tsc --noEmit",
42
+ "now-build": "npm run build"
43
+ },
44
+ "lint-staged": {
45
+ "*": "prettier --write --ignore-unknown"
46
+ },
47
+ "peerDependencies": {
48
+ "react": "*",
49
+ "react-dom": "*"
50
+ },
51
+ "dependencies": {
52
+ "@rc-component/trigger": "^3.0.0",
53
+ "@rc-component/motion": "^1.1.4",
54
+ "@rc-component/util": "^1.2.1",
55
+ "classnames": "2.x",
56
+ "rc-overflow": "^1.4.0",
57
+ "rc-virtual-list": "^3.5.2"
58
+ },
59
+ "devDependencies": {
60
+ "@rc-component/father-plugin": "^2.0.2",
61
+ "@rc-component/np": "^1.0.0",
62
+ "@testing-library/jest-dom": "^6.4.5",
63
+ "@testing-library/react": "^15.0.6",
64
+ "@types/jest": "^29.5.12",
65
+ "@types/react": "^18.3.0",
66
+ "@types/react-dom": "^18.3.0",
67
+ "babel-jest": "^29.6.1",
68
+ "cross-env": "^7.0.0",
69
+ "dumi": "^2.2.13",
70
+ "eslint": "^8.55.0",
71
+ "eslint-plugin-jest": "^28.8.1",
72
+ "eslint-plugin-unicorn": "^56.0.0",
73
+ "father": "^4.0.0",
74
+ "husky": "^9.1.5",
75
+ "jsonp": "^0.2.1",
76
+ "less": "^4.2.0",
77
+ "lint-staged": "^15.2.9",
78
+ "prettier": "^3.1.1",
79
+ "querystring": "^0.2.1",
80
+ "rc-dialog": "^9.0.0",
81
+ "rc-test": "^7.0.9",
82
+ "react": "^18.2.0",
83
+ "react-dom": "^18.2.0",
84
+ "typescript": "^5.2.2"
85
+ }
86
+ }