@fe-free/core 2.2.8 → 2.2.10
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.
- package/CHANGELOG.md +14 -0
- package/package.json +2 -2
- package/src/ahooks/ahooks.stories.tsx +78 -0
- package/src/button/button.stories.ts +1 -2
- package/src/button/index.tsx +3 -1
- package/src/copy/copy.stories.tsx +11 -4
- package/src/copy/index.tsx +8 -2
- package/src/tailwindcss.stories.tsx +4 -4
- package/src/tree/index.tsx +27 -7
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"remark-gfm": "^4.0.1",
|
|
42
42
|
"vanilla-jsoneditor": "^0.23.1",
|
|
43
43
|
"zustand": "^4.5.4",
|
|
44
|
-
"@fe-free/tool": "2.2.
|
|
44
|
+
"@fe-free/tool": "2.2.10"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@ant-design/pro-components": "2.8.9",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useGlobalRequest } from '@fe-free/core';
|
|
2
|
+
import { useRequest } from 'ahooks';
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: '@fe-free/core/ahooks',
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
parameters: {
|
|
8
|
+
docs: {
|
|
9
|
+
description: {
|
|
10
|
+
component: `基于 ahooks 封装
|
|
11
|
+
- useGlobalRequest。基于 useRequest 封装,会抛出全局错误。
|
|
12
|
+
- useGlobalInfiniteScroll。基于 useInfiniteScroll 封装,会抛出全局错误。
|
|
13
|
+
`,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default meta;
|
|
20
|
+
|
|
21
|
+
const handleError = (event) => {
|
|
22
|
+
console.log('global error', event);
|
|
23
|
+
alert('global error');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
window.addEventListener('error', handleError);
|
|
27
|
+
window.addEventListener('unhandledrejection', handleError);
|
|
28
|
+
|
|
29
|
+
export const UseGlobalRequest = () => {
|
|
30
|
+
const { data, loading, error, run } = useGlobalRequest(
|
|
31
|
+
async () => {
|
|
32
|
+
return new Promise((_, reject) => {
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
reject('错误啦');
|
|
35
|
+
}, 1000);
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
manual: true,
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div>
|
|
45
|
+
<div>useGlobalRequest 会抛出全局错误</div>
|
|
46
|
+
<button onClick={run}>run</button>
|
|
47
|
+
|
|
48
|
+
<div>data: {data}</div>
|
|
49
|
+
<div>loading: {loading ? 'true' : 'false'}</div>
|
|
50
|
+
<div>error: {error}</div>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const UseRequest = () => {
|
|
56
|
+
const { data, loading, error, run } = useRequest(
|
|
57
|
+
async () => {
|
|
58
|
+
return new Promise((_, reject) => {
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
reject('错误啦');
|
|
61
|
+
}, 1000);
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
manual: true,
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div>
|
|
71
|
+
<div>ahooks useRequest</div>
|
|
72
|
+
<button onClick={run}>run</button>
|
|
73
|
+
<div>data: {data}</div>
|
|
74
|
+
<div>loading: {loading ? 'true' : 'false'}</div>
|
|
75
|
+
<div>error: {error}</div>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
@@ -8,8 +8,7 @@ const meta: Meta<typeof LoadingButton> = {
|
|
|
8
8
|
parameters: {
|
|
9
9
|
docs: {
|
|
10
10
|
description: {
|
|
11
|
-
component:
|
|
12
|
-
'LoadingButton 是一个带有加载状态的按钮组件,适用于异步操作场景。<br/>区别于 antd Button 需要手动传 loading props。',
|
|
11
|
+
component: '基于 antd Button 封装的 LoadingButton,自动根据 onClick 显示 loading',
|
|
13
12
|
},
|
|
14
13
|
},
|
|
15
14
|
},
|
package/src/button/index.tsx
CHANGED
|
@@ -2,7 +2,9 @@ import type { ButtonProps } from 'antd';
|
|
|
2
2
|
import { Button } from 'antd';
|
|
3
3
|
import { useCallback, useState } from 'react';
|
|
4
4
|
|
|
5
|
-
function LoadingButton(
|
|
5
|
+
function LoadingButton(props: ButtonProps) {
|
|
6
|
+
const { onClick, ...rest } = props;
|
|
7
|
+
|
|
6
8
|
const [loading, setLoading] = useState(false);
|
|
7
9
|
|
|
8
10
|
const handleClick = useCallback(
|
|
@@ -5,6 +5,13 @@ const meta: Meta<typeof Copy> = {
|
|
|
5
5
|
title: '@fe-free/core/Copy',
|
|
6
6
|
component: Copy,
|
|
7
7
|
tags: ['autodocs'],
|
|
8
|
+
parameters: {
|
|
9
|
+
docs: {
|
|
10
|
+
description: {
|
|
11
|
+
component: '基于 antd 的 Copy 组件,自动根据 value 显示复制按钮',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
8
15
|
};
|
|
9
16
|
|
|
10
17
|
export default meta;
|
|
@@ -14,7 +21,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
14
21
|
export const Basic: Story = {
|
|
15
22
|
args: {
|
|
16
23
|
value: '点击复制',
|
|
17
|
-
children: '点击复制',
|
|
24
|
+
children: 'children 点击复制',
|
|
18
25
|
},
|
|
19
26
|
};
|
|
20
27
|
|
|
@@ -22,7 +29,7 @@ export const ShowIcon: Story = {
|
|
|
22
29
|
args: {
|
|
23
30
|
value: 'icon复制',
|
|
24
31
|
showIcon: true,
|
|
25
|
-
children: '
|
|
32
|
+
children: 'children 点击复制',
|
|
26
33
|
},
|
|
27
34
|
};
|
|
28
35
|
|
|
@@ -31,7 +38,7 @@ export const HoverIcon: Story = {
|
|
|
31
38
|
value: 'hover复制',
|
|
32
39
|
showIcon: true,
|
|
33
40
|
hoverIcon: true,
|
|
34
|
-
children: '
|
|
41
|
+
children: 'children 点击复制',
|
|
35
42
|
},
|
|
36
43
|
};
|
|
37
44
|
|
|
@@ -41,6 +48,6 @@ export const OnCopied: Story = {
|
|
|
41
48
|
onCopied: () => {
|
|
42
49
|
alert('复制成功');
|
|
43
50
|
},
|
|
44
|
-
children: '点击复制',
|
|
51
|
+
children: 'children 点击复制',
|
|
45
52
|
},
|
|
46
53
|
};
|
package/src/copy/index.tsx
CHANGED
|
@@ -4,14 +4,20 @@ import classNames from 'classnames';
|
|
|
4
4
|
import React, { useCallback } from 'react';
|
|
5
5
|
|
|
6
6
|
interface CopyProps {
|
|
7
|
+
/** 复制的内容 */
|
|
7
8
|
value: string;
|
|
9
|
+
/** 是否显示复制 icon */
|
|
8
10
|
showIcon?: boolean;
|
|
11
|
+
/** 是否在 hover 时显示复制 icon */
|
|
9
12
|
hoverIcon?: boolean;
|
|
10
13
|
children?: React.ReactNode;
|
|
14
|
+
/** 复制成功后的回调 */
|
|
11
15
|
onCopied?: () => void;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
function Copy(props: CopyProps) {
|
|
19
|
+
const { value, showIcon, hoverIcon, children, onCopied } = props;
|
|
20
|
+
|
|
15
21
|
const handleCopy = useCallback(async () => {
|
|
16
22
|
await copyToClipboard(value);
|
|
17
23
|
onCopied?.();
|
|
@@ -39,7 +45,7 @@ const Copy: React.FC<CopyProps> = ({ value, showIcon, hoverIcon, children, onCop
|
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
return <div onClick={handleCopy}>{children}</div>;
|
|
42
|
-
}
|
|
48
|
+
}
|
|
43
49
|
|
|
44
50
|
export { Copy };
|
|
45
51
|
export type { CopyProps };
|
|
@@ -7,10 +7,10 @@ export const Default = () => {
|
|
|
7
7
|
return (
|
|
8
8
|
<div>
|
|
9
9
|
<div>@fe-free/core 扩展的</div>
|
|
10
|
-
<div
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
<
|
|
10
|
+
<div>
|
|
11
|
+
<div className="text-primary">text-primary</div>
|
|
12
|
+
<div className="text-secondary">text-secondary</div>
|
|
13
|
+
<div className="text-desc">text-desc</div>
|
|
14
14
|
</div>
|
|
15
15
|
<div>
|
|
16
16
|
<div className="c-border-bottom">c-border-bottom</div>
|
package/src/tree/index.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { useDebounce } from 'ahooks';
|
|
|
3
3
|
import type { TreeProps as AntdTreeProps } from 'antd';
|
|
4
4
|
import { Tree as AntdTree, Input } from 'antd';
|
|
5
5
|
import type { DataNode } from 'antd/es/tree';
|
|
6
|
-
import { useMemo, useState } from 'react';
|
|
6
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
7
7
|
import { flatToTreeData } from './helper';
|
|
8
8
|
|
|
9
9
|
interface TreeProps<T extends DataNode> extends AntdTreeProps<T> {
|
|
@@ -101,8 +101,32 @@ function Tree<T extends DataNode>(props: TreeProps<T>) {
|
|
|
101
101
|
treeData: filterTreeData,
|
|
102
102
|
search: debouncedSearch,
|
|
103
103
|
});
|
|
104
|
+
const newTreeData = highlightedTreeData;
|
|
104
105
|
|
|
105
|
-
const
|
|
106
|
+
const handleSearch = useCallback((e) => {
|
|
107
|
+
setSearch(e.target.value);
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
const searchExpandKeysProps = useMemo(() => {
|
|
111
|
+
if (!debouncedSearch) {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const keys: string[] = [];
|
|
116
|
+
function loop(arr) {
|
|
117
|
+
arr.forEach((item) => {
|
|
118
|
+
keys.push(item.key);
|
|
119
|
+
if (item.children) {
|
|
120
|
+
loop(item.children);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
loop(newTreeData);
|
|
125
|
+
|
|
126
|
+
return { expandedKeys: keys };
|
|
127
|
+
}, [debouncedSearch, newTreeData]);
|
|
128
|
+
|
|
129
|
+
const node = <AntdTree {...searchExpandKeysProps} {...rest} treeData={newTreeData} />;
|
|
106
130
|
|
|
107
131
|
if (!enableSearch) {
|
|
108
132
|
return node;
|
|
@@ -114,11 +138,7 @@ function Tree<T extends DataNode>(props: TreeProps<T>) {
|
|
|
114
138
|
start={
|
|
115
139
|
enableSearch && (
|
|
116
140
|
<div className="px-2 pb-2">
|
|
117
|
-
<Input.Search
|
|
118
|
-
placeholder="搜索"
|
|
119
|
-
value={search}
|
|
120
|
-
onChange={(e) => setSearch(e.target.value)}
|
|
121
|
-
/>
|
|
141
|
+
<Input.Search placeholder="搜索" value={search} onChange={handleSearch} />
|
|
122
142
|
</div>
|
|
123
143
|
)
|
|
124
144
|
}
|