foxit-component 0.0.1-alpha.3 → 0.0.1-alpha.30

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 (64) hide show
  1. package/es/Alert/Alert.d.ts +12 -0
  2. package/es/Alert/Alert.js +24 -0
  3. package/es/Button/Button.d.ts +2 -1
  4. package/es/Button/Button.js +4 -4
  5. package/es/Checkbox/Checkbox.d.ts +10 -2
  6. package/es/Checkbox/Checkbox.js +35 -5
  7. package/es/Drawer/Drawer.d.ts +10 -0
  8. package/es/Drawer/Drawer.js +14 -0
  9. package/es/Empty/Empty.js +0 -1
  10. package/es/Form/Form.d.ts +2 -1
  11. package/es/Form/Form.js +3 -3
  12. package/es/Form/Form.types.d.ts +9 -0
  13. package/es/Form/FormItem.js +1 -2
  14. package/es/Form/FormProvider.js +148 -115
  15. package/es/Form/useFormWatch.d.ts +3 -0
  16. package/es/Form/useFormWatch.js +37 -0
  17. package/es/Input/Input.d.ts +1 -0
  18. package/es/Input/Input.js +6 -5
  19. package/es/Menu/Menu.d.ts +2 -1
  20. package/es/Menu/Menu.js +124 -11
  21. package/es/Modal/Modal.d.ts +2 -0
  22. package/es/Modal/Modal.js +88 -17
  23. package/es/Modal/ModalTemp.js +4 -1
  24. package/es/Pagination/Pagination.d.ts +2 -0
  25. package/es/Pagination/Pagination.js +26 -13
  26. package/es/Quantity/Quantity.d.ts +10 -0
  27. package/es/Quantity/Quantity.js +45 -0
  28. package/es/Radio/Radio.js +0 -1
  29. package/es/Select/Select.d.ts +10 -0
  30. package/es/Select/Select.js +15 -10
  31. package/es/Spin/Spin.d.ts +10 -0
  32. package/es/Spin/Spin.js +23 -0
  33. package/es/Switch/Switch.d.ts +9 -0
  34. package/es/Switch/Switch.js +20 -0
  35. package/es/Table/Table.d.ts +4 -1
  36. package/es/Table/Table.js +22 -8
  37. package/es/Tabs/Tabs.js +0 -1
  38. package/es/Tag/Tag.d.ts +1 -1
  39. package/es/Tag/Tag.js +1 -2
  40. package/es/Toast/Toast.js +0 -1
  41. package/es/Toast/ToastContainer.js +0 -1
  42. package/es/Tooltip/Tooltip.js +38 -18
  43. package/es/constants/icons.d.ts +16 -0
  44. package/es/constants/icons.js +17 -1
  45. package/es/index.css +1 -0
  46. package/es/index.d.ts +9 -6
  47. package/es/index.js +7 -1
  48. package/es/node_modules/tslib/tslib.es6.js +39 -1
  49. package/package.json +18 -16
  50. package/es/Button/button.css.js +0 -6
  51. package/es/Checkbox/checkbox.css.js +0 -6
  52. package/es/Empty/empty.css.js +0 -6
  53. package/es/Form/form.css.js +0 -6
  54. package/es/Input/input.css.js +0 -6
  55. package/es/Menu/menu.css.js +0 -6
  56. package/es/Modal/modal.css.js +0 -6
  57. package/es/Pagination/pagination.css.js +0 -6
  58. package/es/Radio/radio.css.js +0 -6
  59. package/es/Table/table.css.js +0 -6
  60. package/es/Tabs/tabs.css.js +0 -6
  61. package/es/Tag/tag.css.js +0 -6
  62. package/es/Toast/toast.css.js +0 -6
  63. package/es/Tooltip/tooltip.css.js +0 -6
  64. package/es/node_modules/style-inject/dist/style-inject.es.js +0 -28
@@ -0,0 +1,37 @@
1
+ import { useRef, useEffect } from 'react';
2
+
3
+ function useFormWatch(formRef, callback, fieldNames) {
4
+ var callbackRef = useRef(callback);
5
+ useEffect(function () {
6
+ callbackRef.current = callback;
7
+ }, [callback]);
8
+ // 处理表单字段监听
9
+ useEffect(function () {
10
+ // 如果表单引用不存在,设置轮询检查
11
+ if (!formRef.current) {
12
+ var checkInterval_1 = setInterval(function () {
13
+ if (formRef.current) {
14
+ clearInterval(checkInterval_1);
15
+ subscribeToFields();
16
+ }
17
+ }, 100);
18
+ // 清理轮询
19
+ return function () { return clearInterval(checkInterval_1); };
20
+ }
21
+ else {
22
+ // 表单引用存在,直接订阅
23
+ return subscribeToFields();
24
+ }
25
+ function subscribeToFields() {
26
+ var _a;
27
+ var unsubscribe = (_a = formRef.current) === null || _a === void 0 ? void 0 : _a.subscribe(fieldNames, function (newValues) {
28
+ callbackRef.current(newValues);
29
+ });
30
+ return function () {
31
+ unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
32
+ };
33
+ }
34
+ }, [formRef, fieldNames.join(',')]);
35
+ }
36
+
37
+ export { useFormWatch };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import './input.css';
3
3
  export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
4
4
  addonAfter?: React.ReactNode;
5
+ className?: string;
5
6
  }
6
7
  declare const Input: React.FC<InputProps>;
7
8
  interface SearchInputProps extends InputProps {
package/es/Input/Input.js CHANGED
@@ -1,21 +1,22 @@
1
1
  import { __rest, __assign } from '../node_modules/tslib/tslib.es6.js';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import { useState } from 'react';
4
- import './input.css.js';
4
+ import classNames from 'classnames';
5
5
  import { Icon } from '../Icon/index.js';
6
6
 
7
7
  var Input = function (_a) {
8
- var addonAfter = _a.addonAfter, rest = __rest(_a, ["addonAfter"]);
9
- return (jsxs("div", __assign({ className: "foxit-input-wrapper" }, { children: [jsx("input", __assign({}, rest, { className: "foxit-input-element" })), addonAfter && jsx("div", __assign({ className: "foxit-input-addon" }, { children: addonAfter }))] })));
8
+ var addonAfter = _a.addonAfter, className = _a.className, rest = __rest(_a, ["addonAfter", "className"]);
9
+ return (jsxs("div", __assign({ className: classNames('foxit-input-wrapper', rest.disabled && 'foxit-input-wrapper-disabled', className) }, { children: [jsx("input", __assign({}, rest, { className: "foxit-input-element" })), addonAfter && jsx("div", __assign({ className: "foxit-input-addon" }, { children: addonAfter }))] })));
10
10
  };
11
11
  var SearchInput = function (_a) {
12
12
  var onSearch = _a.onSearch, rest = __rest(_a, ["onSearch"]);
13
+ var _b = useState(rest.value || ''), value = _b[0], setValue = _b[1];
13
14
  var handleSearch = function () {
14
15
  if (onSearch) {
15
- onSearch(rest.value);
16
+ onSearch(value);
16
17
  }
17
18
  };
18
- return (jsx(Input, __assign({}, rest, { addonAfter: jsx("div", __assign({ style: { display: 'flex' }, onClick: handleSearch }, { children: jsx(Icon, { name: "SearchOutlined" }) })) })));
19
+ return (jsx(Input, __assign({}, rest, { onChange: function (e) { return setValue(e.target.value); }, addonAfter: jsx("div", __assign({ style: { display: 'flex' }, onClick: handleSearch }, { children: jsx(Icon, { name: "SearchOutlined" }) })) })));
19
20
  };
20
21
  var PasswordInput = function (props) {
21
22
  var _a = useState(false), visible = _a[0], setVisible = _a[1];
package/es/Menu/Menu.d.ts CHANGED
@@ -16,7 +16,8 @@ interface MenuProps {
16
16
  defaultSelectedKeys?: string[];
17
17
  defaultOpenKeys?: string[];
18
18
  style?: React.CSSProperties;
19
+ inlineCollapsed?: boolean;
19
20
  }
20
21
  export declare const getItem: (label: ReactNode, key: Key, icon?: ReactNode, children?: MenuItem[], type?: 'group') => MenuItem;
21
22
  declare const Menu: React.FC<MenuProps>;
22
- export default Menu;
23
+ export { Menu };
package/es/Menu/Menu.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { __assign, __spreadArray } from '../node_modules/tslib/tslib.es6.js';
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { useState } from 'react';
2
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
+ import { useState, useRef, useEffect } from 'react';
4
4
  import { Icon } from '../Icon/index.js';
5
- import './menu.css.js';
6
5
 
7
6
  var getItem = function (label, key, icon, children, type) {
8
7
  return {
@@ -14,23 +13,26 @@ var getItem = function (label, key, icon, children, type) {
14
13
  };
15
14
  };
16
15
  var Menu = function (_a) {
17
- var items = _a.items, onClick = _a.onClick, _b = _a.defaultSelectedKeys, defaultSelectedKeys = _b === void 0 ? [] : _b, _c = _a.defaultOpenKeys, defaultOpenKeys = _c === void 0 ? [] : _c, style = _a.style;
18
- var _d = useState(defaultOpenKeys), openKeys = _d[0], setOpenKeys = _d[1];
19
- var _e = useState(defaultSelectedKeys), selectedKeys = _e[0], setSelectedKeys = _e[1];
16
+ var items = _a.items, onClick = _a.onClick, _b = _a.defaultSelectedKeys, defaultSelectedKeys = _b === void 0 ? [] : _b, _c = _a.defaultOpenKeys, defaultOpenKeys = _c === void 0 ? [] : _c, style = _a.style, _d = _a.inlineCollapsed, inlineCollapsed = _d === void 0 ? false : _d;
17
+ var _e = useState(defaultOpenKeys), openKeys = _e[0], setOpenKeys = _e[1];
18
+ var _f = useState(defaultSelectedKeys), selectedKeys = _f[0], setSelectedKeys = _f[1];
19
+ var _g = useState(null), hoveredKey = _g[0], setHoveredKey = _g[1];
20
+ var _h = useState({ top: 0, left: 0 }), popupPosition = _h[0], setPopupPosition = _h[1];
21
+ var menuItemRefs = useRef({});
22
+ var popupRef = useRef(null);
20
23
  var handleMenuClick = function (e) {
21
24
  onClick === null || onClick === void 0 ? void 0 : onClick(e);
22
25
  setSelectedKeys([e.key]);
23
26
  };
24
- // const handleOpenChange = (keys: string[]) => {
25
- // setOpenKeys(keys);
26
- // };
27
27
  var isFirstLevel = function (item) {
28
28
  return items.some(function (i) { return i.key === item.key; });
29
29
  };
30
+ // 标准展开模式的菜单项渲染
30
31
  var renderMenuItem = function (item) {
31
32
  var isSelected = selectedKeys.includes(item.key.toString());
32
33
  return (jsx("div", __assign({ className: "foxit-menu-item ".concat(isSelected ? 'selected' : '') }, { children: jsxs("div", __assign({ className: "foxit-menu-item-content", onClick: function () { return handleMenuClick({ key: item.key.toString() }); } }, { children: [item.icon && jsx("span", __assign({ style: { marginRight: '8px' } }, { children: item.icon })), jsx("span", __assign({ className: isFirstLevel(item) ? 'foxit-menu-item-label' : '' }, { children: item.label }))] })) }), item.key));
33
34
  };
35
+ // 标准展开模式的子菜单渲染
34
36
  var renderSubMenu = function (item) {
35
37
  var isOpen = openKeys.includes(item.key.toString());
36
38
  return (jsxs("div", { children: [jsxs("div", __assign({ className: "foxit-menu-submenu-title", onClick: function () {
@@ -44,7 +46,118 @@ var Menu = function (_a) {
44
46
  return child.children ? renderSubMenu(child) : renderMenuItem(child);
45
47
  }) })))] }, item.key));
46
48
  };
47
- return (jsx("div", __assign({ className: "foxit-menu", style: __assign({}, style) }, { children: items.map(function (item) { return (item.children ? renderSubMenu(item) : renderMenuItem(item)); }) })));
49
+ // 收起模式的菜单项渲染
50
+ var renderMenuCollapsedItem = function (item) {
51
+ var isSelected = selectedKeys.includes(item.key.toString());
52
+ return (jsx("div", __assign({ ref: function (el) { return (menuItemRefs.current[item.key.toString()] = el); }, className: "foxit-menu-item foxit-menu-collapsed-item ".concat(isSelected ? 'selected' : ''), onMouseEnter: function () { return handleMouseEnter(item.key.toString()); }, onMouseLeave: handleMouseLeave }, { children: jsx("div", __assign({ className: "foxit-menu-item-content", onClick: function () { return handleMenuClick({ key: item.key.toString() }); } }, { children: item.icon && (jsx("span", __assign({ className: "foxit-menu-item-icon foxit-menu-item-icon-collapsed" }, { children: item.icon }))) })) }), item.key));
53
+ };
54
+ // 收起模式的子菜单渲染
55
+ var renderSubCollapsedMenu = function (item) {
56
+ var isSelected = selectedKeys.includes(item.key.toString());
57
+ return (jsx("div", __assign({ ref: function (el) { return (menuItemRefs.current[item.key.toString()] = el); }, className: "foxit-menu-submenu foxit-menu-collapsed-item ".concat(isSelected ? 'selected' : ''), onMouseEnter: function () { return handleMouseEnter(item.key.toString()); }, onMouseLeave: handleMouseLeave }, { children: jsx("div", __assign({ className: "foxit-menu-submenu-title" }, { children: item.icon && (jsx("span", __assign({ className: "foxit-menu-item-icon foxit-menu-item-icon-collapsed" }, { children: item.icon }))) })) }), item.key));
58
+ };
59
+ // 处理鼠标悬浮事件
60
+ var handleMouseEnter = function (key) {
61
+ setHoveredKey(key);
62
+ var itemRef = menuItemRefs.current[key];
63
+ if (itemRef) {
64
+ var rect = itemRef.getBoundingClientRect();
65
+ setPopupPosition({
66
+ top: rect.top,
67
+ left: rect.right + 5
68
+ });
69
+ }
70
+ };
71
+ // 处理鼠标离开事件
72
+ var handleMouseLeave = function () {
73
+ // 使用延时,允许鼠标移到弹出菜单上
74
+ setTimeout(function () {
75
+ if (!isMouseInPopup() && !isMouseOverAnyMenuItem()) {
76
+ setHoveredKey(null);
77
+ }
78
+ }, 50);
79
+ };
80
+ // 检查鼠标是否在弹出菜单中
81
+ var isMouseInPopup = function () {
82
+ return popupRef.current && popupRef.current.matches(':hover');
83
+ };
84
+ // 检查鼠标是否在任何菜单项上
85
+ var isMouseOverAnyMenuItem = function () {
86
+ return Object.values(menuItemRefs.current).some(function (ref) { return ref && ref.matches(':hover'); });
87
+ };
88
+ // 弹出子菜单渲染
89
+ var renderPopupMenu = function () {
90
+ if (!hoveredKey)
91
+ return null;
92
+ var item = findItemByKey(items, hoveredKey);
93
+ if (!(item === null || item === void 0 ? void 0 : item.children))
94
+ return null;
95
+ return (jsx("div", __assign({ ref: popupRef, className: "foxit-menu-popup", style: {
96
+ position: 'fixed',
97
+ top: "".concat(popupPosition.top, "px"),
98
+ left: "".concat(popupPosition.left, "px"),
99
+ zIndex: 1000
100
+ }, onMouseEnter: function () { return setHoveredKey(hoveredKey); }, onMouseLeave: function () { return setHoveredKey(null); } }, { children: jsxs("div", __assign({ className: "foxit-menu foxit-menu-popup-content" }, { children: [jsxs("div", __assign({ className: "foxit-menu-popup-title" }, { children: [jsx("span", __assign({ className: "foxit-menu-item-icon" }, { children: item.icon })), jsx("span", { children: item.label })] })), item.children.map(function (child) {
101
+ return child.children ? renderPopupSubMenu(child) : renderPopupMenuItem(child);
102
+ })] })) })));
103
+ };
104
+ // 弹出菜单中的普通菜单项渲染
105
+ var renderPopupMenuItem = function (item) {
106
+ var isSelected = selectedKeys.includes(item.key.toString());
107
+ return (jsx("div", __assign({ className: "foxit-menu-item ".concat(isSelected ? 'selected' : '') }, { children: jsxs("div", __assign({ className: "foxit-menu-item-content", onClick: function () {
108
+ handleMenuClick({ key: item.key.toString() });
109
+ setHoveredKey(null);
110
+ } }, { children: [item.icon && jsx("span", __assign({ className: "foxit-menu-item-icon" }, { children: item.icon })), jsx("span", { children: item.label })] })) }), item.key));
111
+ };
112
+ // 弹出菜单中的子菜单渲染
113
+ var renderPopupSubMenu = function (item) {
114
+ var isOpen = openKeys.includes(item.key.toString());
115
+ return (jsxs("div", { children: [jsxs("div", __assign({ className: "foxit-menu-submenu-title", onClick: function () {
116
+ if (isOpen) {
117
+ setOpenKeys(openKeys.filter(function (key) { return key !== item.key.toString(); }));
118
+ }
119
+ else {
120
+ setOpenKeys(__spreadArray(__spreadArray([], openKeys, true), [item.key.toString()], false));
121
+ }
122
+ } }, { children: [jsxs("div", __assign({ style: { display: 'flex', alignItems: 'center' } }, { children: [item.icon && jsx("span", __assign({ className: "foxit-menu-item-icon" }, { children: item.icon })), jsx("span", { children: item.label })] })), jsx("span", { children: jsx(Icon, { name: "DownOutlined", className: "foxit-menu-icon ".concat(isOpen ? '' : 'foxit-menu-rotated-icon') }) })] })), isOpen && item.children && (jsx("div", __assign({ className: "foxit-menu-submenu-items" }, { children: item.children.map(function (child) {
123
+ return child.children ? renderPopupSubMenu(child) : renderPopupMenuItem(child);
124
+ }) })))] }, item.key));
125
+ };
126
+ // 根据key查找菜单项
127
+ var findItemByKey = function (items, key) {
128
+ for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
129
+ var item = items_1[_i];
130
+ if (item.key.toString() === key) {
131
+ return item;
132
+ }
133
+ if (item.children) {
134
+ var found = findItemByKey(item.children, key);
135
+ if (found)
136
+ return found;
137
+ }
138
+ }
139
+ return undefined;
140
+ };
141
+ // 关闭副作用处理
142
+ useEffect(function () {
143
+ var handleClickOutside = function (event) {
144
+ if (hoveredKey &&
145
+ popupRef.current &&
146
+ !popupRef.current.contains(event.target) &&
147
+ !Object.values(menuItemRefs.current).some(function (ref) { return ref && ref.contains(event.target); })) {
148
+ setHoveredKey(null);
149
+ }
150
+ };
151
+ document.addEventListener('mousedown', handleClickOutside);
152
+ return function () {
153
+ document.removeEventListener('mousedown', handleClickOutside);
154
+ };
155
+ }, [hoveredKey]);
156
+ return (jsxs(Fragment, { children: [jsx("div", __assign({ className: "foxit-menu", style: __assign({}, style) }, { children: inlineCollapsed
157
+ ? items.map(function (item) {
158
+ return item.children ? renderSubCollapsedMenu(item) : renderMenuCollapsedItem(item);
159
+ })
160
+ : items.map(function (item) { return (item.children ? renderSubMenu(item) : renderMenuItem(item)); }) })), inlineCollapsed && hoveredKey && renderPopupMenu()] }));
48
161
  };
49
162
 
50
- export { Menu as default, getItem };
163
+ export { Menu, getItem };
@@ -10,6 +10,8 @@ interface IModalProps {
10
10
  maskClosable?: boolean;
11
11
  children?: React.ReactNode;
12
12
  width?: string;
13
+ type?: 'success';
14
+ closable?: boolean;
13
15
  }
14
16
  interface ModalComponent extends FC<IModalProps> {
15
17
  confirm: (props: IModalProps & {
package/es/Modal/Modal.js CHANGED
@@ -1,39 +1,110 @@
1
- import { __assign } from '../node_modules/tslib/tslib.es6.js';
1
+ import { __assign, __awaiter, __generator } from '../node_modules/tslib/tslib.es6.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { useState } from 'react';
3
4
  import { Icon } from '../Icon/index.js';
5
+ import classNames from 'classnames';
4
6
  import { createRoot } from 'react-dom/client';
5
7
  import { Modal as Modal$1 } from './ModalTemp.js';
6
8
  import { Button } from '../Button/Button.js';
7
- import './modal.css.js';
8
9
 
9
10
  var ModalContent = function (_a) {
10
- var title = _a.title, onCancel = _a.onCancel, _b = _a.onCancelText, onCancelText = _b === void 0 ? undefined : _b, onOk = _a.onOk, _c = _a.onOkText, onOkText = _c === void 0 ? undefined : _c, children = _a.children, _d = _a.width, width = _d === void 0 ? '400px' : _d;
11
- return (jsxs("div", __assign({ className: "foxit-modal-content-container", style: {
12
- maxWidth: width,
11
+ var title = _a.title, onCancel = _a.onCancel, _b = _a.onCancelText, onCancelText = _b === void 0 ? undefined : _b, onOk = _a.onOk, _c = _a.onOkText, onOkText = _c === void 0 ? undefined : _c, children = _a.children, _d = _a.width, width = _d === void 0 ? '400px' : _d, type = _a.type, _e = _a.closable, closable = _e === void 0 ? true : _e;
12
+ var _f = useState(false), loading = _f[0], setLoading = _f[1];
13
+ var _g = useState(false), cancelLoading = _g[0], setCancelLoading = _g[1];
14
+ var handleOk = function () { return __awaiter(void 0, void 0, void 0, function () {
15
+ return __generator(this, function (_a) {
16
+ switch (_a.label) {
17
+ case 0:
18
+ if (!onOk) return [3 /*break*/, 4];
19
+ _a.label = 1;
20
+ case 1:
21
+ _a.trys.push([1, , 3, 4]);
22
+ setLoading(true);
23
+ return [4 /*yield*/, onOk()];
24
+ case 2:
25
+ _a.sent();
26
+ return [3 /*break*/, 4];
27
+ case 3:
28
+ setLoading(false);
29
+ return [7 /*endfinally*/];
30
+ case 4: return [2 /*return*/];
31
+ }
32
+ });
33
+ }); };
34
+ var handleCancel = function () { return __awaiter(void 0, void 0, void 0, function () {
35
+ return __generator(this, function (_a) {
36
+ switch (_a.label) {
37
+ case 0:
38
+ if (!onCancel) return [3 /*break*/, 4];
39
+ _a.label = 1;
40
+ case 1:
41
+ _a.trys.push([1, , 3, 4]);
42
+ setCancelLoading(true);
43
+ return [4 /*yield*/, onCancel()];
44
+ case 2:
45
+ _a.sent();
46
+ return [3 /*break*/, 4];
47
+ case 3:
48
+ setCancelLoading(false);
49
+ return [7 /*endfinally*/];
50
+ case 4: return [2 /*return*/];
51
+ }
52
+ });
53
+ }); };
54
+ return (jsxs("div", __assign({ className: classNames('foxit-modal-content-container', type === 'success' ? 'foxit-modal-success' : ''), style: {
55
+ maxWidth: "min(".concat(width, ", calc(100vw - 32px))"),
13
56
  width: width
14
- } }, { children: [jsxs("div", __assign({ className: "foxit-modal-head" }, { children: [jsx("div", __assign({ className: "foxit-modal-title" }, { children: title })), jsx("div", __assign({ onClick: onCancel, className: "foxit-modal-close-button" }, { children: jsx(Icon, { name: "CloseOutlined" }) }))] })), jsx("div", { children: children }), jsxs("div", __assign({ className: "foxit-modal-footer" }, { children: [onCancelText && (jsx(Button, __assign({ size: "medium", onClick: onCancel }, { children: onCancelText }))), onOkText && (jsx(Button, __assign({ primary: true, size: "medium", onClick: onOk }, { children: onOkText })))] }))] })));
57
+ } }, { children: [jsxs("div", __assign({ className: "foxit-modal-head" }, { children: [jsx("div", __assign({ className: "foxit-modal-title" }, { children: title })), closable && (jsx("div", __assign({ onClick: onCancel, className: type === 'success' ? 'foxit-modal-success-icon' : 'foxit-modal-close-button' }, { children: type === 'success' ? (jsx(Icon, { name: "FireWorkColoursOutlined" })) : (jsx(Icon, { name: "CloseOutlined" })) })))] })), jsx("div", __assign({ className: "foxit-modal-children" }, { children: children })), jsxs("div", __assign({ className: "foxit-modal-footer" }, { children: [onCancelText && (jsx(Button, __assign({ size: "medium", onClick: handleCancel, loading: cancelLoading }, { children: onCancelText }))), onOkText && (jsx(Button, __assign({ primary: true, size: "medium", onClick: handleOk, loading: loading }, { children: onOkText })))] }))] })));
15
58
  };
16
59
  var Modal = function (_a) {
17
- var title = _a.title, opened = _a.opened, onOk = _a.onOk, onOkText = _a.onOkText, onCancel = _a.onCancel, onCancelText = _a.onCancelText, maskClosable = _a.maskClosable, children = _a.children, width = _a.width;
18
- return (jsx(Modal$1, __assign({ opened: opened, onClose: onCancel || (function () { }), maskClosable: maskClosable, position: "top" }, { children: jsx(ModalContent, __assign({ title: title, width: width, onCancel: onCancel, onCancelText: onCancelText, onOk: onOk, onOkText: onOkText }, { children: children })) })));
60
+ var title = _a.title, opened = _a.opened, onOk = _a.onOk, onOkText = _a.onOkText, onCancel = _a.onCancel, onCancelText = _a.onCancelText, maskClosable = _a.maskClosable, children = _a.children, width = _a.width, type = _a.type, closable = _a.closable;
61
+ return (jsx(Modal$1, __assign({ opened: opened, onClose: onCancel || (function () { }), maskClosable: maskClosable, position: "top" }, { children: jsx(ModalContent, __assign({ title: title, width: width, onCancel: onCancel, onCancelText: onCancelText, onOk: onOk, onOkText: onOkText, type: type, closable: closable }, { children: children })) })));
19
62
  };
20
63
  // 语法糖的调用方式
21
64
  Modal.confirm = function (_a) {
22
- var title = _a.title, onOk = _a.onOk, onCancel = _a.onCancel, onOkText = _a.onOkText, onCancelText = _a.onCancelText, _b = _a.maskClosable, maskClosable = _b === void 0 ? true : _b, content = _a.content, width = _a.width;
65
+ var title = _a.title, onOk = _a.onOk, onCancel = _a.onCancel, onOkText = _a.onOkText, onCancelText = _a.onCancelText, _b = _a.maskClosable, maskClosable = _b === void 0 ? true : _b, content = _a.content, width = _a.width, closable = _a.closable;
23
66
  var modalRoot = document.createElement('div');
24
67
  document.body.appendChild(modalRoot);
25
68
  var root = createRoot(modalRoot);
26
69
  var handleClose = function () {
27
70
  root.unmount();
28
- document.body.removeChild(modalRoot);
71
+ if (document.body.contains(modalRoot)) {
72
+ document.body.removeChild(modalRoot);
73
+ }
29
74
  };
30
- root.render(jsx(Modal$1, __assign({ opened: true, onClose: handleClose, maskClosable: maskClosable, position: "top" }, { children: jsx(ModalContent, __assign({ title: title, width: width, onCancel: function () {
31
- onCancel === null || onCancel === void 0 ? void 0 : onCancel();
32
- handleClose();
33
- }, onCancelText: onCancelText, onOk: function () {
34
- onOk === null || onOk === void 0 ? void 0 : onOk();
35
- handleClose();
36
- }, onOkText: onOkText }, { children: content })) })));
75
+ root.render(jsx(Modal$1, __assign({ opened: true, onClose: handleClose, maskClosable: maskClosable, position: "top" }, { children: jsx(ModalContent, __assign({ title: title, width: width, onCancel: onCancel instanceof Function && onCancel.constructor.name === 'AsyncFunction'
76
+ ? function () { return __awaiter(void 0, void 0, void 0, function () {
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0: return [4 /*yield*/, onCancel()];
80
+ case 1:
81
+ _a.sent();
82
+ handleClose();
83
+ return [2 /*return*/];
84
+ }
85
+ });
86
+ }); }
87
+ : function () {
88
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel();
89
+ handleClose();
90
+ }, onCancelText: onCancelText, onOk:
91
+ // 判断传进来的onOk是否为async函数
92
+ onOk instanceof Function && onOk.constructor.name === 'AsyncFunction'
93
+ ? function () { return __awaiter(void 0, void 0, void 0, function () {
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0: return [4 /*yield*/, onOk()];
97
+ case 1:
98
+ _a.sent();
99
+ handleClose();
100
+ return [2 /*return*/];
101
+ }
102
+ });
103
+ }); }
104
+ : function () {
105
+ onOk === null || onOk === void 0 ? void 0 : onOk();
106
+ handleClose();
107
+ }, onOkText: onOkText, closable: closable }, { children: content })) })));
37
108
  };
38
109
 
39
110
  export { Modal };
@@ -4,7 +4,6 @@ import { useState, useEffect, useRef } from 'react';
4
4
  import { CSSTransition } from 'react-transition-group';
5
5
  import { createPortal } from 'react-dom';
6
6
  import classNames from 'classnames';
7
- import './modal.css.js';
8
7
 
9
8
  var contentAnimation = {
10
9
  enter: 'foxit-modal-opacity-0 foxit-modal-scale-0',
@@ -24,6 +23,10 @@ var Portal = function (_a) {
24
23
  useEffect(function () {
25
24
  var _a, _b;
26
25
  (_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.appendChild) === null || _b === void 0 ? void 0 : _b.call(_a, container);
26
+ return function () {
27
+ var _a, _b;
28
+ (_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.removeChild) === null || _b === void 0 ? void 0 : _b.call(_a, container);
29
+ };
27
30
  }, [container]);
28
31
  return createPortal(children, container);
29
32
  };
@@ -5,6 +5,8 @@ interface PaginationProps {
5
5
  pageSize: number;
6
6
  onChange?: (page: number) => void;
7
7
  defaultCurrent?: number;
8
+ current?: number;
9
+ mobile?: boolean;
8
10
  }
9
11
  declare const Pagination: React.FC<PaginationProps>;
10
12
  export default Pagination;
@@ -1,15 +1,20 @@
1
1
  import { __assign } from '../node_modules/tslib/tslib.es6.js';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import { useState, useEffect } from 'react';
4
- import './pagination.css.js';
4
+ import { Button } from '../Button/Button.js';
5
5
 
6
6
  var $_MORE = 9999999999;
7
7
  var Pagination = function (_a) {
8
- var total = _a.total, pageSize = _a.pageSize, onChange = _a.onChange, _b = _a.defaultCurrent, defaultCurrent = _b === void 0 ? 1 : _b;
9
- var _c = useState(defaultCurrent), current = _c[0], setCurrent = _c[1];
10
- var _d = useState([]), pages = _d[0], setPages = _d[1];
8
+ var total = _a.total, pageSize = _a.pageSize, onChange = _a.onChange, _b = _a.defaultCurrent, defaultCurrent = _b === void 0 ? 1 : _b, currentProp = _a.current, _c = _a.mobile, mobile = _c === void 0 ? false : _c;
9
+ var _d = useState(currentProp !== undefined ? currentProp : defaultCurrent), current = _d[0], setCurrent = _d[1];
10
+ var _e = useState([]), pages = _e[0], setPages = _e[1];
11
11
  var maxButtons = 5;
12
12
  var totalPages = Math.ceil(total / pageSize);
13
+ useEffect(function () {
14
+ if (currentProp !== undefined && currentProp !== current) {
15
+ setCurrent(currentProp);
16
+ }
17
+ }, [currentProp, current]);
13
18
  useEffect(function () {
14
19
  var generatePages = function () {
15
20
  var pageArray = [];
@@ -49,14 +54,16 @@ var Pagination = function (_a) {
49
54
  var handleClick = function (page, index) {
50
55
  if (page === $_MORE) {
51
56
  if (index > 0 && pages[index - 1] !== null && pages[index - 1] !== 1) {
52
- setCurrent(pages[index - 1] + 1);
53
- onChange === null || onChange === void 0 ? void 0 : onChange(pages[index - 1] + 1);
57
+ var newPage = pages[index - 1] + 1;
58
+ setCurrent(newPage);
59
+ onChange === null || onChange === void 0 ? void 0 : onChange(newPage);
54
60
  }
55
61
  else if (index < pages.length - 1 &&
56
62
  pages[index + 1] !== null &&
57
63
  pages[index + 1] !== totalPages) {
58
- setCurrent(pages[index + 1] - 1);
59
- onChange === null || onChange === void 0 ? void 0 : onChange(pages[index + 1] - 1);
64
+ var newPage = pages[index + 1] - 1;
65
+ setCurrent(newPage);
66
+ onChange === null || onChange === void 0 ? void 0 : onChange(newPage);
60
67
  }
61
68
  }
62
69
  else if (page !== current) {
@@ -66,17 +73,23 @@ var Pagination = function (_a) {
66
73
  };
67
74
  var handlePrev = function () {
68
75
  if (current > 1) {
69
- setCurrent(current - 1);
70
- onChange === null || onChange === void 0 ? void 0 : onChange(current - 1);
76
+ var newPage = current - 1;
77
+ setCurrent(newPage);
78
+ onChange === null || onChange === void 0 ? void 0 : onChange(newPage);
71
79
  }
72
80
  };
73
81
  var handleNext = function () {
74
82
  if (current < totalPages) {
75
- setCurrent(current + 1);
76
- onChange === null || onChange === void 0 ? void 0 : onChange(current + 1);
83
+ var newPage = current + 1;
84
+ setCurrent(newPage);
85
+ onChange === null || onChange === void 0 ? void 0 : onChange(newPage);
77
86
  }
78
87
  };
79
- return (jsxs("div", __assign({ className: "foxit-pagination-container" }, { children: [jsx("button", __assign({ className: "foxit-pagination-prev", onClick: handlePrev, disabled: current === 1 }, { children: '<' })), pages.map(function (page, index) { return (jsx("button", __assign({ className: "foxit-pagination-button", onClick: function () { return handleClick(page, index); }, disabled: page === current }, { children: page === $_MORE ? '...' : page }), index)); }), jsx("button", __assign({ className: "foxit-pagination-next", onClick: handleNext, disabled: current === totalPages }, { children: '>' }))] })));
88
+ // 新增:移动端只显示“展开更多”按钮
89
+ if (mobile) {
90
+ return total > pageSize ? (jsxs("div", __assign({ className: "foxit-pagination-mobile-container" }, { children: [jsx(Button, __assign({ className: "foxit-pagination-mobile-prev", onClick: handlePrev, size: "small", disabled: current === 1 }, { children: '<' })), jsxs("span", __assign({ className: "foxit-pagination-mobile-info" }, { children: [current, " / ", totalPages] })), jsx(Button, __assign({ className: "foxit-pagination-mobile-next", onClick: handleNext, size: "small", disabled: current === totalPages }, { children: '>' }))] }))) : null;
91
+ }
92
+ return total > pageSize ? (jsxs("div", __assign({ className: "foxit-pagination-container" }, { children: [jsx("button", __assign({ className: "foxit-pagination-prev", onClick: handlePrev, disabled: current === 1 }, { children: '<' })), pages.map(function (page, index) { return (jsx("button", __assign({ className: "foxit-pagination-button", onClick: function () { return handleClick(page, index); }, disabled: page === current }, { children: page === $_MORE ? '...' : page }), index)); }), jsx("button", __assign({ className: "foxit-pagination-next", onClick: handleNext, disabled: current === totalPages }, { children: '>' }))] }))) : null;
80
93
  };
81
94
 
82
95
  export { Pagination as default };
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import './quantity.css';
3
+ interface QuantityProps {
4
+ value?: number;
5
+ onChange?: (value: number) => void;
6
+ min?: number;
7
+ max?: number;
8
+ }
9
+ declare const Quantity: React.FC<QuantityProps>;
10
+ export { Quantity };
@@ -0,0 +1,45 @@
1
+ import { __assign } from '../node_modules/tslib/tslib.es6.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { useState } from 'react';
4
+
5
+ var Quantity = function (_a) {
6
+ var value = _a.value, onChange = _a.onChange, min = _a.min, max = _a.max;
7
+ var _b = useState(value || min || 0), internalValue = _b[0], setInternalValue = _b[1];
8
+ var currentValue = value !== undefined ? value : internalValue;
9
+ var handleIncrement = function () {
10
+ var newValue = currentValue + 1;
11
+ if (max !== undefined && newValue > max)
12
+ return;
13
+ if (onChange) {
14
+ onChange(newValue);
15
+ }
16
+ setInternalValue(newValue);
17
+ };
18
+ var handleDecrement = function () {
19
+ var newValue = currentValue - 1;
20
+ if (min !== undefined && newValue < min)
21
+ return;
22
+ if (onChange) {
23
+ onChange(newValue);
24
+ }
25
+ setInternalValue(newValue);
26
+ };
27
+ var handleChange = function (e) {
28
+ var newValue = parseInt(e.target.value, 10) || 0;
29
+ if (min !== undefined && newValue < min) {
30
+ newValue = min;
31
+ }
32
+ if (max !== undefined && newValue > max) {
33
+ newValue = max;
34
+ }
35
+ if (onChange) {
36
+ onChange(newValue);
37
+ }
38
+ setInternalValue(newValue);
39
+ };
40
+ return (jsxs("div", __assign({ className: "foxit-quantity" }, { children: [jsx("button", __assign({ className: "foxit-quantity-button", onClick: handleDecrement, disabled: min !== undefined && currentValue <= min }, { children: jsx("div", { children: "-" }) })), jsx("input", {
41
+ // type="number"
42
+ value: currentValue, onChange: handleChange, min: min, max: max, className: "foxit-quantity-number" }), jsx("button", __assign({ className: "foxit-quantity-button", onClick: handleIncrement, disabled: max !== undefined && currentValue >= max }, { children: jsx("div", { children: "+" }) }))] })));
43
+ };
44
+
45
+ export { Quantity };
package/es/Radio/Radio.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { __assign } from '../node_modules/tslib/tslib.es6.js';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import { createContext, useContext, useState } from 'react';
4
- import './radio.css.js';
5
4
 
6
5
  var RadioContext = createContext({});
7
6
  var Radio = function (_a) {
@@ -12,6 +12,16 @@ export interface SelectProps {
12
12
  isMulti?: boolean;
13
13
  placeholder?: string;
14
14
  preIcon?: React.ReactNode;
15
+ value?: string | number | CustomOption | null;
16
+ onChange?: (v: unknown) => void;
17
+ [key: string]: unknown;
18
+ }
19
+ interface CustomOption {
20
+ readonly value: string | number;
21
+ readonly label: string;
22
+ readonly color?: string;
23
+ readonly isFixed?: boolean;
24
+ readonly isDisabled?: boolean;
15
25
  }
16
26
  declare const Select: React.FC<SelectProps>;
17
27
  export default Select;
@@ -5,15 +5,18 @@ import classNames from 'classnames';
5
5
  import { Icon } from '../Icon/index.js';
6
6
 
7
7
  var Select = function (_a) {
8
- var options = _a.options, className = _a.className, defaultValue = _a.defaultValue, isDisabled = _a.isDisabled, isClearable = _a.isClearable, isSearchable = _a.isSearchable, isMulti = _a.isMulti, _b = _a.placeholder, placeholder = _b === void 0 ? 'Select...' : _b, preIcon = _a.preIcon, rest = __rest(_a, ["options", "className", "defaultValue", "isDisabled", "isClearable", "isSearchable", "isMulti", "placeholder", "preIcon"]);
8
+ var options = _a.options, className = _a.className, defaultValue = _a.defaultValue, isDisabled = _a.isDisabled, isClearable = _a.isClearable, isSearchable = _a.isSearchable, isMulti = _a.isMulti, _b = _a.placeholder, placeholder = _b === void 0 ? 'Select...' : _b, preIcon = _a.preIcon, value = _a.value, onChange = _a.onChange, rest = __rest(_a, ["options", "className", "defaultValue", "isDisabled", "isClearable", "isSearchable", "isMulti", "placeholder", "preIcon", "value", "onChange"]);
9
9
  var customStyles = {
10
- control: function (styles) { return (__assign(__assign({}, styles), { backgroundColor: 'white',
11
- // minWidth: 200,
12
- height: 48, borderRadius: 10, fontSize: 14, boxShadow: 'none', border: '1px solid #B3B3B3', ':hover': {
13
- border: '1px solid #757575'
14
- }, ':focus-within': {
15
- border: '1px solid #FF5F00'
16
- } })); },
10
+ control: function (styles, _a) {
11
+ var isDisabled = _a.isDisabled;
12
+ return (__assign(__assign({}, styles), { backgroundColor: isDisabled ? '#f8f8f8' : 'white',
13
+ // minWidth: 200,
14
+ height: 48, paddingLeft: 8, borderRadius: 10, fontSize: 14, boxShadow: 'none', border: '1px solid #D9D9D9', ':hover': {
15
+ border: '1px solid #757575'
16
+ }, ':focus-within': {
17
+ border: '1px solid #FF5F00'
18
+ } }));
19
+ },
17
20
  option: function (styles, _a) {
18
21
  var isSelected = _a.isSelected, isFocused = _a.isFocused;
19
22
  return __assign(__assign({}, styles), { backgroundColor: isFocused ? '#FFF6F0' : 'white', color: isSelected ? '#FF5F00' : '#666', ':hover': {
@@ -26,7 +29,7 @@ var Select = function (_a) {
26
29
  };
27
30
  var CustomControl = function (props) { return (jsxs(components.Control, __assign({}, props, { children: [preIcon && (jsx("div", __assign({ style: {
28
31
  display: 'flex',
29
- paddingLeft: 16,
32
+ paddingLeft: 8,
30
33
  marginRight: -4,
31
34
  color: props.hasValue ? '#525252' : '#B3B3B3'
32
35
  } }, { children: preIcon }))), props.children] }))); };
@@ -36,7 +39,9 @@ var Select = function (_a) {
36
39
  return Array.isArray(defaultValue) &&
37
40
  defaultValue.includes(option.value);
38
41
  })
39
- : options.find(function (option) { return option.value === defaultValue; }), isDisabled: isDisabled, isClearable: isClearable, isSearchable: isSearchable, isMulti: isMulti, components: { Control: CustomControl, Option: CustomOptionComp } }, rest)));
42
+ : options.find(function (option) { return option.value === defaultValue; }), isDisabled: isDisabled, isClearable: isClearable, isSearchable: isSearchable, isMulti: isMulti, components: { Control: CustomControl, Option: CustomOptionComp }, onChange: onChange, menuPosition: "fixed" }, rest, { value: isMulti && Array.isArray(value)
43
+ ? value.map(function (v) { return options.find(function (option) { return option.value === v; }); })
44
+ : options.find(function (option) { return option.value === value; }) || value })));
40
45
  };
41
46
 
42
47
  export { Select as default };