@tendaui/components 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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +176 -0
  3. package/alert/Alert.tsx +147 -0
  4. package/alert/defaultProps.ts +3 -0
  5. package/alert/index.ts +9 -0
  6. package/alert/style/css.js +1 -0
  7. package/alert/style/index.js +1 -0
  8. package/alert/type.ts +44 -0
  9. package/badge/Badge.tsx +85 -0
  10. package/badge/defaultProps.ts +10 -0
  11. package/badge/index.ts +9 -0
  12. package/badge/style/css.js +1 -0
  13. package/badge/style/index.js +1 -0
  14. package/badge/type.ts +51 -0
  15. package/button/Button.tsx +95 -0
  16. package/button/defaultProps.ts +13 -0
  17. package/button/index.ts +7 -0
  18. package/button/style/css.js +1 -0
  19. package/button/style/index.js +1 -0
  20. package/button/type.ts +82 -0
  21. package/checkbox/Checkbox.tsx +19 -0
  22. package/checkbox/CheckboxGroup.tsx +207 -0
  23. package/checkbox/defaultProps.ts +14 -0
  24. package/checkbox/index.ts +10 -0
  25. package/checkbox/style/css.js +1 -0
  26. package/checkbox/style/index.js +1 -0
  27. package/checkbox/type.ts +117 -0
  28. package/common/Check.tsx +131 -0
  29. package/common/FakeArrow.tsx +36 -0
  30. package/common/PluginContainer.tsx +21 -0
  31. package/common/Portal.tsx +67 -0
  32. package/common.ts +76 -0
  33. package/config-provider/ConfigContext.tsx +21 -0
  34. package/config-provider/ConfigProvider.tsx +53 -0
  35. package/config-provider/index.ts +9 -0
  36. package/config-provider/type.ts +1062 -0
  37. package/dialog/Dialog.tsx +254 -0
  38. package/dialog/DialogCard.tsx +152 -0
  39. package/dialog/defaultProps.ts +25 -0
  40. package/dialog/hooks/useDialogDrag.ts +50 -0
  41. package/dialog/hooks/useDialogEsc.ts +31 -0
  42. package/dialog/hooks/useDialogPosition.ts +36 -0
  43. package/dialog/hooks/useLockStyle.ts +54 -0
  44. package/dialog/index.ts +13 -0
  45. package/dialog/plugin.tsx +78 -0
  46. package/dialog/style/css.js +1 -0
  47. package/dialog/style/index.js +1 -0
  48. package/dialog/type.ts +241 -0
  49. package/dialog/utils.ts +4 -0
  50. package/form/Form.tsx +136 -0
  51. package/form/FormContext.tsx +64 -0
  52. package/form/FormItem.tsx +554 -0
  53. package/form/FormList.tsx +303 -0
  54. package/form/const.ts +6 -0
  55. package/form/defaultProps.ts +26 -0
  56. package/form/formModel.ts +117 -0
  57. package/form/hooks/interface.ts +20 -0
  58. package/form/hooks/useForm.ts +122 -0
  59. package/form/hooks/useFormItemInitialData.ts +95 -0
  60. package/form/hooks/useFormItemStyle.tsx +122 -0
  61. package/form/hooks/useInstance.tsx +275 -0
  62. package/form/hooks/useWatch.ts +42 -0
  63. package/form/index.ts +11 -0
  64. package/form/style/css.js +1 -0
  65. package/form/style/index.js +1 -0
  66. package/form/type.ts +519 -0
  67. package/form/utils/index.ts +69 -0
  68. package/hooks/useAttach.ts +24 -0
  69. package/hooks/useCommonClassName.ts +45 -0
  70. package/hooks/useConfig.ts +3 -0
  71. package/hooks/useControlled.ts +39 -0
  72. package/hooks/useDefaultProps.ts +16 -0
  73. package/hooks/useDomCallback.ts +13 -0
  74. package/hooks/useDomRefCallback.ts +12 -0
  75. package/hooks/useDragSorter.tsx +151 -0
  76. package/hooks/useEventCallback.ts +47 -0
  77. package/hooks/useGlobalConfig.ts +14 -0
  78. package/hooks/useGlobalIcon.ts +14 -0
  79. package/hooks/useLastest.ts +13 -0
  80. package/hooks/useLayoutEffect.ts +7 -0
  81. package/hooks/useMouseEvent.ts +142 -0
  82. package/hooks/useMutationObserver.ts +56 -0
  83. package/hooks/usePopper.ts +189 -0
  84. package/hooks/useRipple.ts +0 -0
  85. package/hooks/useSetState.ts +25 -0
  86. package/hooks/useVirtualScroll.ts +246 -0
  87. package/hooks/useWindowSize.ts +31 -0
  88. package/index.ts +70 -0
  89. package/input/Input.tsx +383 -0
  90. package/input/InputGroup.tsx +29 -0
  91. package/input/defaultProps.ts +22 -0
  92. package/input/index.ts +11 -0
  93. package/input/style/css.js +1 -0
  94. package/input/style/index.js +1 -0
  95. package/input/type.ts +219 -0
  96. package/loading/Gradient.tsx +36 -0
  97. package/loading/Loading.tsx +169 -0
  98. package/loading/circleAdapter.ts +44 -0
  99. package/loading/defaultProps.ts +12 -0
  100. package/loading/index.ts +13 -0
  101. package/loading/style/css.js +1 -0
  102. package/loading/style/index.js +1 -0
  103. package/loading/type.ts +71 -0
  104. package/loading/utils/setStyle.ts +13 -0
  105. package/myform/index.ts +0 -0
  106. package/notification/Notify.ts +24 -0
  107. package/notification/NotifyContainer.tsx +90 -0
  108. package/notification/NotifyContext.tsx +173 -0
  109. package/notification/NotifyItem.tsx +121 -0
  110. package/notification/index.ts +3 -0
  111. package/notification/style/css.js +1 -0
  112. package/notification/style/index.js +1 -0
  113. package/notification/type.ts +23 -0
  114. package/package.json +52 -0
  115. package/popup/Popup.tsx +264 -0
  116. package/popup/defaultProps.ts +13 -0
  117. package/popup/hooks/useTrigger.ts +276 -0
  118. package/popup/index.ts +6 -0
  119. package/popup/style/css.js +1 -0
  120. package/popup/style/index.js +1 -0
  121. package/popup/type.ts +130 -0
  122. package/portal/Portal.tsx +63 -0
  123. package/portal/index.ts +1 -0
  124. package/select/Option.tsx +162 -0
  125. package/select/OptionGroup.tsx +30 -0
  126. package/select/PopupContent.tsx +271 -0
  127. package/select/Select.tsx +586 -0
  128. package/select/defaultProps.ts +27 -0
  129. package/select/hooks/useOptions.ts +120 -0
  130. package/select/hooks/usePanelVirtualScroll.ts +111 -0
  131. package/select/index.ts +9 -0
  132. package/select/style/css.js +1 -0
  133. package/select/style/index.js +2 -0
  134. package/select/type.ts +382 -0
  135. package/select/utils/helper.ts +256 -0
  136. package/select-input/SelectInput.tsx +98 -0
  137. package/select-input/defaultProps.ts +15 -0
  138. package/select-input/hook/useMultiple.tsx +100 -0
  139. package/select-input/hook/useOverlayInnerStyle.ts +84 -0
  140. package/select-input/hook/useSingle.tsx +112 -0
  141. package/select-input/index.ts +6 -0
  142. package/select-input/interface.ts +18 -0
  143. package/select-input/style/css.js +1 -0
  144. package/select-input/style/index.js +1 -0
  145. package/select-input/type.ts +280 -0
  146. package/space/defaultProps.ts +0 -0
  147. package/space/index.ts +0 -0
  148. package/space/type.ts +0 -0
  149. package/style/index.js +2 -0
  150. package/styles/_global.scss +39 -0
  151. package/styles/_vars.scss +386 -0
  152. package/styles/components/alert/_index.scss +175 -0
  153. package/styles/components/alert/_vars.scss +39 -0
  154. package/styles/components/badge/_index.scss +70 -0
  155. package/styles/components/badge/_vars.scss +25 -0
  156. package/styles/components/button/_index.scss +511 -0
  157. package/styles/components/button/_mixins.scss +39 -0
  158. package/styles/components/button/_vars.scss +122 -0
  159. package/styles/components/checkbox/_index.scss +158 -0
  160. package/styles/components/checkbox/_mixin.scss +0 -0
  161. package/styles/components/checkbox/_var.scss +60 -0
  162. package/styles/components/dialog/_animate.scss +135 -0
  163. package/styles/components/dialog/_index.scss +311 -0
  164. package/styles/components/dialog/_mixins.scss +0 -0
  165. package/styles/components/dialog/_vars.scss +59 -0
  166. package/styles/components/form/_index.scss +174 -0
  167. package/styles/components/form/_mixins.scss +76 -0
  168. package/styles/components/form/_vars.scss +100 -0
  169. package/styles/components/input/_index.scss +349 -0
  170. package/styles/components/input/_map.scss +0 -0
  171. package/styles/components/input/_mixins.scss +116 -0
  172. package/styles/components/input/_vars.scss +134 -0
  173. package/styles/components/loading/_index.scss +112 -0
  174. package/styles/components/loading/_vars.scss +39 -0
  175. package/styles/components/notification/_index.scss +160 -0
  176. package/styles/components/notification/_mixins.scss +12 -0
  177. package/styles/components/notification/_vars.scss +59 -0
  178. package/styles/components/popup/_index.scss +82 -0
  179. package/styles/components/popup/_mixin.scss +149 -0
  180. package/styles/components/popup/_var.scss +31 -0
  181. package/styles/components/select/_index.scss +290 -0
  182. package/styles/components/select/_var.scss +65 -0
  183. package/styles/components/select-input/_index.scss +5 -0
  184. package/styles/components/select-input/_var.scss +3 -0
  185. package/styles/components/switch/_index.scss +279 -0
  186. package/styles/components/switch/_mixins.scss +0 -0
  187. package/styles/components/switch/_vars.scss +61 -0
  188. package/styles/components/tag/_index.scss +316 -0
  189. package/styles/components/tag/_var.scss +85 -0
  190. package/styles/components/tag-input/_index.scss +163 -0
  191. package/styles/components/tag-input/_vars.scss +16 -0
  192. package/styles/globals.css +250 -0
  193. package/styles/mixins/_focus.scss +7 -0
  194. package/styles/mixins/_layout.scss +32 -0
  195. package/styles/mixins/_reset.scss +10 -0
  196. package/styles/mixins/_scrollbar.scss +31 -0
  197. package/styles/mixins/_text.scss +48 -0
  198. package/styles/rillple.css +16 -0
  199. package/styles/scrollbar.css +42 -0
  200. package/styles/themes/_dark.scss +191 -0
  201. package/styles/themes/_font.scss +79 -0
  202. package/styles/themes/_index.scss +5 -0
  203. package/styles/themes/_light.scss +190 -0
  204. package/styles/themes/_radius.scss +9 -0
  205. package/styles/themes/_size.scss +68 -0
  206. package/styles/themes.css +66 -0
  207. package/styles/utilities/_animation.scss +57 -0
  208. package/styles/utilities/_tips.scss +9 -0
  209. package/switch/Switch.tsx +120 -0
  210. package/switch/defaultProps.ts +3 -0
  211. package/switch/index.ts +7 -0
  212. package/switch/style/css.js +1 -0
  213. package/switch/style/index.js +1 -0
  214. package/switch/type.ts +46 -0
  215. package/tag/Tag.tsx +149 -0
  216. package/tag/defaultProps.ts +19 -0
  217. package/tag/index.ts +8 -0
  218. package/tag/style/css.js +1 -0
  219. package/tag/style/index.js +1 -0
  220. package/tag/type.ts +170 -0
  221. package/tag-input/TagInput.tsx +215 -0
  222. package/tag-input/defaultProps.ts +15 -0
  223. package/tag-input/hooks/useHover.ts +28 -0
  224. package/tag-input/hooks/useTagList.tsx +131 -0
  225. package/tag-input/hooks/useTagScroll.ts +105 -0
  226. package/tag-input/index.ts +9 -0
  227. package/tag-input/style/css.js +1 -0
  228. package/tag-input/style/index.js +1 -0
  229. package/tag-input/type.ts +224 -0
  230. package/tag-input/useTagList.tsx +131 -0
  231. package/utils/composeRefs.ts +14 -0
  232. package/utils/dom.ts +29 -0
  233. package/utils/forwardRefWithStatics.ts +12 -0
  234. package/utils/getScrollbarWidth.ts +11 -0
  235. package/utils/helper.ts +161 -0
  236. package/utils/isFragment.ts +22 -0
  237. package/utils/listener.ts +37 -0
  238. package/utils/noop.ts +3 -0
  239. package/utils/parentTNode.ts +38 -0
  240. package/utils/parseTNode.ts +38 -0
  241. package/utils/react-render.ts +108 -0
  242. package/utils/ref.ts +6 -0
  243. package/utils/refs.ts +81 -0
  244. package/utils/style.ts +60 -0
  245. package/utils/transition.ts +28 -0
@@ -0,0 +1,271 @@
1
+ import React, { Children, isValidElement, cloneElement, useRef, CSSProperties, useMemo } from "react";
2
+ import classNames from "classnames";
3
+ import { isEqual } from "lodash-es";
4
+ import { getSelectValueArr } from "./utils/helper";
5
+ import {
6
+ TdSelectProps,
7
+ SelectValue,
8
+ TdOptionProps,
9
+ SelectValueChangeTrigger,
10
+ SelectOption,
11
+ SelectOptionGroup
12
+ } from "./type";
13
+ import useConfig from "../hooks/useConfig";
14
+ import usePanelVirtualScroll from "./hooks/usePanelVirtualScroll";
15
+ import Option, { SelectOptionProps } from "./Option";
16
+ import OptionGroup from "./OptionGroup";
17
+
18
+ interface SelectPopupProps
19
+ extends Pick<
20
+ TdSelectProps,
21
+ | "value"
22
+ | "size"
23
+ | "multiple"
24
+ | "empty"
25
+ | "options"
26
+ | "max"
27
+ | "loadingText"
28
+ | "loading"
29
+ | "valueType"
30
+ | "keys"
31
+ | "panelTopContent"
32
+ | "panelBottomContent"
33
+ | "scroll"
34
+ > {
35
+ onChange?: (
36
+ value: SelectValue,
37
+ context?: {
38
+ label?: string | number;
39
+ value?: SelectValue;
40
+ restData?: Record<string, unknown>;
41
+ e: React.MouseEvent<HTMLLIElement>;
42
+ trigger: SelectValueChangeTrigger;
43
+ }
44
+ ) => void;
45
+ /**
46
+ * 是否展示popup
47
+ */
48
+ showPopup: boolean;
49
+ /**
50
+ * 控制popup展示的函数
51
+ */
52
+ setShowPopup: (show: boolean) => void;
53
+ children?: React.ReactNode;
54
+ onCheckAllChange?: (checkAll: boolean, e: React.MouseEvent<HTMLLIElement>) => void;
55
+ getPopupInstance?: () => HTMLDivElement;
56
+ }
57
+
58
+ const PopupContent = React.forwardRef<HTMLDivElement, SelectPopupProps>((props, ref) => {
59
+ const {
60
+ value,
61
+ size,
62
+ max,
63
+ multiple,
64
+ showPopup,
65
+ setShowPopup,
66
+ empty,
67
+ loadingText,
68
+ loading,
69
+ valueType,
70
+ children,
71
+ keys,
72
+ panelTopContent,
73
+ panelBottomContent,
74
+ onChange,
75
+ onCheckAllChange,
76
+ getPopupInstance,
77
+ options: propsOptions,
78
+ scroll: propsScroll
79
+ } = props;
80
+
81
+ // 国际化文本初始化
82
+ // const [local, t] = useLocaleReceiver('select');
83
+ // const emptyText = t(local.empty);
84
+ const popupContentRef = useRef<HTMLDivElement>(null);
85
+
86
+ popupContentRef.current = getPopupInstance();
87
+
88
+ const { visibleData, handleRowMounted, isVirtual, panelStyle, cursorStyle } = usePanelVirtualScroll({
89
+ popupContentRef,
90
+ scroll: propsScroll,
91
+ options: propsOptions,
92
+ size
93
+ });
94
+
95
+ // 全部可选选项
96
+ const selectableOptions = useMemo(() => {
97
+ const uniqueOptions = {};
98
+ propsOptions?.forEach((option: SelectOption) => {
99
+ if ((option as SelectOptionGroup).group) {
100
+ (option as SelectOptionGroup).children.forEach((item) => {
101
+ if (!item.disabled && !item.checkAll) {
102
+ uniqueOptions[item.value] = item;
103
+ }
104
+ });
105
+ } else if (!(option as TdOptionProps).disabled && !(option as TdOptionProps).checkAll) {
106
+ uniqueOptions[(option as TdOptionProps).value] = option;
107
+ }
108
+ });
109
+ return Object.values(uniqueOptions);
110
+ }, [propsOptions]);
111
+
112
+ const { classPrefix } = useConfig();
113
+ if (!children && !propsOptions) {
114
+ return null;
115
+ }
116
+
117
+ const onSelect: SelectOptionProps["onSelect"] = (selectedValue, { label, selected, event, restData }) => {
118
+ const isValObj = valueType === "object";
119
+ let objVal = {};
120
+ if (isValObj) {
121
+ objVal = { ...restData };
122
+ if (!keys?.label) {
123
+ Object.assign(objVal, { label });
124
+ }
125
+ if (!keys?.value) {
126
+ Object.assign(objVal, { value: selectedValue });
127
+ }
128
+ }
129
+
130
+ if (!Object.keys(objVal).length) {
131
+ Object.assign(objVal, {
132
+ [keys?.label || "label"]: label,
133
+ [keys?.value || "value"]: selectedValue
134
+ });
135
+ }
136
+
137
+ if (multiple) {
138
+ // calc multiple select values
139
+ const values = getSelectValueArr(value, selectedValue, selected, valueType, keys, objVal);
140
+ onChange(values, {
141
+ label,
142
+ value: selectedValue,
143
+ e: event,
144
+ trigger: selected ? "uncheck" : "check"
145
+ });
146
+ } else {
147
+ // calc single select value
148
+ const selectVal = valueType === "object" ? objVal : selectedValue;
149
+
150
+ if (!isEqual(value, selectVal)) {
151
+ onChange(selectVal, {
152
+ label,
153
+ value: selectVal,
154
+ e: event,
155
+ trigger: "check"
156
+ });
157
+ }
158
+ setShowPopup(!showPopup);
159
+ }
160
+ };
161
+
162
+ const childrenWithProps = Children.map(children, (child) => {
163
+ if (isValidElement(child)) {
164
+ const addedProps = {
165
+ size,
166
+ max,
167
+ multiple,
168
+ selectedValue: value,
169
+ onSelect
170
+ };
171
+ return cloneElement(child, { ...addedProps });
172
+ }
173
+ return child;
174
+ });
175
+
176
+ // 渲染 options
177
+ const renderOptions = (options: SelectOption[]) => {
178
+ if (options) {
179
+ // 通过 options API配置的
180
+ return (
181
+ <ul className={`${classPrefix}-select__list`}>
182
+ {options.map((item, index) => {
183
+ const { group, divider, ...rest } = item as SelectOptionGroup;
184
+ if (group) {
185
+ return (
186
+ <OptionGroup label={group} divider={divider} key={index}>
187
+ {renderOptions(rest.children)}
188
+ </OptionGroup>
189
+ );
190
+ }
191
+
192
+ const { value: optionValue, label, disabled, content, children, ...restData } = item as TdOptionProps;
193
+ return (
194
+ <Option
195
+ key={index}
196
+ max={max}
197
+ label={label}
198
+ value={optionValue}
199
+ onSelect={onSelect}
200
+ selectedValue={value}
201
+ optionLength={selectableOptions.length}
202
+ multiple={multiple}
203
+ size={size}
204
+ disabled={disabled}
205
+ restData={restData}
206
+ keys={keys}
207
+ content={content}
208
+ onCheckAllChange={onCheckAllChange}
209
+ onRowMounted={handleRowMounted}
210
+ {...(isVirtual
211
+ ? {
212
+ isVirtual,
213
+ bufferSize: propsScroll?.bufferSize,
214
+ scrollType: propsScroll?.type
215
+ }
216
+ : {})}
217
+ {...restData}
218
+ >
219
+ {children}
220
+ </Option>
221
+ );
222
+ })}
223
+ </ul>
224
+ );
225
+ }
226
+ return <ul className={`${classPrefix}-select__list`}>{childrenWithProps}</ul>;
227
+ };
228
+
229
+ const isEmpty =
230
+ (Array.isArray(childrenWithProps) && !childrenWithProps.length) || (propsOptions && propsOptions.length === 0);
231
+
232
+ const renderPanel = (renderedOptions: SelectOption[], extraStyle?: CSSProperties) => (
233
+ <div
234
+ ref={ref}
235
+ className={classNames(`${classPrefix}-select__dropdown-inner`, {
236
+ [`${classPrefix}-select__dropdown-inner--size-s`]: size === "small",
237
+ [`${classPrefix}-select__dropdown-inner--size-l`]: size === "large",
238
+ [`${classPrefix}-select__dropdown-inner--size-m`]: size === "medium"
239
+ })}
240
+ style={extraStyle}
241
+ >
242
+ {loading && <div className={`${classPrefix}-select__loading-tips`}>{loadingText}</div>}
243
+ {!loading && isEmpty && <div className={`${classPrefix}-select__empty`}>{empty}</div>}
244
+ {!loading && !isEmpty && renderOptions(renderedOptions)}
245
+ </div>
246
+ );
247
+ if (isVirtual) {
248
+ return (
249
+ <>
250
+ {panelTopContent}
251
+ <div>
252
+ <div style={cursorStyle}></div>
253
+ {renderPanel(visibleData, panelStyle)}
254
+ </div>
255
+ {panelBottomContent}
256
+ </>
257
+ );
258
+ }
259
+
260
+ return (
261
+ <>
262
+ {panelTopContent}
263
+ {renderPanel(propsOptions)}
264
+ {panelBottomContent}
265
+ </>
266
+ );
267
+ });
268
+
269
+ PopupContent.displayName = "PopupContent";
270
+
271
+ export default PopupContent;