@fe-free/file 2.5.0 → 2.5.2
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 +8 -0
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/src/file/file.stories.tsx +0 -53
- package/src/file/helper.tsx +0 -120
- package/src/file/icon/AudioIcon.tsx +0 -20
- package/src/file/icon/VideoIcon.tsx +0 -20
- package/src/file/index.tsx +0 -63
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { FileCard } from '@fe-free/file';
|
|
2
|
-
import type { StoryObj } from '@storybook/react-vite';
|
|
3
|
-
import { PRESET_FILE_ICONS } from './helper';
|
|
4
|
-
|
|
5
|
-
const meta = {
|
|
6
|
-
title: '@fe-free/file/FileCard',
|
|
7
|
-
component: FileCard,
|
|
8
|
-
tags: ['autodocs'],
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default meta;
|
|
12
|
-
type Story = StoryObj<typeof FileCard>;
|
|
13
|
-
|
|
14
|
-
export const Default: Story = {
|
|
15
|
-
render: () => {
|
|
16
|
-
let size = 0;
|
|
17
|
-
return (
|
|
18
|
-
<div>
|
|
19
|
-
<div className="flex flex-col gap-2">
|
|
20
|
-
{PRESET_FILE_ICONS.map((item) => (
|
|
21
|
-
<div key={item.key} className="flex gap-2">
|
|
22
|
-
<FileCard name={`这是文件名.${item.ext.join('.') || ''}`} size={(size += 1000000)} />
|
|
23
|
-
</div>
|
|
24
|
-
))}
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
);
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const Direction: Story = {
|
|
32
|
-
render: () => (
|
|
33
|
-
<div>
|
|
34
|
-
<FileCard name="这是文件名.pdf" size={10000} direction="vertical" />
|
|
35
|
-
</div>
|
|
36
|
-
),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const FileIcon: Story = {
|
|
40
|
-
render: () => (
|
|
41
|
-
<div>
|
|
42
|
-
<FileCard.FileIcon name="这是文件名.pdf" className="text-3xl" />
|
|
43
|
-
</div>
|
|
44
|
-
),
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const FileIconExt: Story = {
|
|
48
|
-
render: () => (
|
|
49
|
-
<div>
|
|
50
|
-
<FileCard.FileIcon name="这是文件名.xlsx" showExt className="text-5xl" />
|
|
51
|
-
</div>
|
|
52
|
-
),
|
|
53
|
-
};
|
package/src/file/helper.tsx
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FileExcelFilled,
|
|
3
|
-
FileImageFilled,
|
|
4
|
-
FileMarkdownFilled,
|
|
5
|
-
FilePdfFilled,
|
|
6
|
-
FilePptFilled,
|
|
7
|
-
FileTextFilled,
|
|
8
|
-
FileWordFilled,
|
|
9
|
-
FileZipFilled,
|
|
10
|
-
} from '@ant-design/icons';
|
|
11
|
-
import AudioIcon from './icon/AudioIcon';
|
|
12
|
-
import VideoIcon from './icon/VideoIcon';
|
|
13
|
-
|
|
14
|
-
type PresetIcons =
|
|
15
|
-
| 'default'
|
|
16
|
-
| 'excel'
|
|
17
|
-
| 'image'
|
|
18
|
-
| 'markdown'
|
|
19
|
-
| 'pdf'
|
|
20
|
-
| 'ppt'
|
|
21
|
-
| 'word'
|
|
22
|
-
| 'zip'
|
|
23
|
-
| 'video'
|
|
24
|
-
| 'audio';
|
|
25
|
-
|
|
26
|
-
const IMG_EXTS = ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'svg'];
|
|
27
|
-
|
|
28
|
-
const DEFAULT_ICON_COLOR = '#8c8c8c';
|
|
29
|
-
const DEFAULT_ICON = <FileTextFilled />;
|
|
30
|
-
|
|
31
|
-
const PRESET_FILE_ICONS: {
|
|
32
|
-
key: PresetIcons;
|
|
33
|
-
ext: string[];
|
|
34
|
-
color: string;
|
|
35
|
-
icon: React.ReactElement;
|
|
36
|
-
}[] = [
|
|
37
|
-
{
|
|
38
|
-
key: 'default',
|
|
39
|
-
icon: DEFAULT_ICON,
|
|
40
|
-
color: DEFAULT_ICON_COLOR,
|
|
41
|
-
ext: [],
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
key: 'excel',
|
|
45
|
-
icon: <FileExcelFilled />,
|
|
46
|
-
color: '#22b35e',
|
|
47
|
-
ext: ['xlsx', 'xls'],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
key: 'image',
|
|
51
|
-
icon: <FileImageFilled />,
|
|
52
|
-
color: 'rgb(22, 119, 255)',
|
|
53
|
-
ext: IMG_EXTS,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
key: 'markdown',
|
|
57
|
-
icon: <FileMarkdownFilled />,
|
|
58
|
-
color: DEFAULT_ICON_COLOR,
|
|
59
|
-
ext: ['md', 'mdx'],
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
key: 'pdf',
|
|
63
|
-
icon: <FilePdfFilled />,
|
|
64
|
-
color: '#ff4d4f',
|
|
65
|
-
ext: ['pdf'],
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
key: 'ppt',
|
|
69
|
-
icon: <FilePptFilled />,
|
|
70
|
-
color: '#ff6e31',
|
|
71
|
-
ext: ['ppt', 'pptx'],
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
key: 'word',
|
|
75
|
-
icon: <FileWordFilled />,
|
|
76
|
-
color: '#1677ff',
|
|
77
|
-
ext: ['doc', 'docx'],
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
key: 'zip',
|
|
81
|
-
icon: <FileZipFilled />,
|
|
82
|
-
color: '#fab714',
|
|
83
|
-
ext: ['zip', 'rar', '7z', 'tar', 'gz'],
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
key: 'video',
|
|
87
|
-
icon: <VideoIcon />,
|
|
88
|
-
color: '#ff4d4f',
|
|
89
|
-
ext: ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv'],
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
key: 'audio',
|
|
93
|
-
icon: <AudioIcon />,
|
|
94
|
-
color: '#FFDC00',
|
|
95
|
-
ext: ['mp3', 'wav', 'flac', 'ape', 'aac', 'ogg'],
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
function isImage(name: string) {
|
|
100
|
-
return IMG_EXTS.includes(name.split('.').pop() || '');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getFileExt(name?: string) {
|
|
104
|
-
return name?.split('.').pop() || '';
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function getFileSize(size: number) {
|
|
108
|
-
if (size < 1024) {
|
|
109
|
-
return size + 'B';
|
|
110
|
-
}
|
|
111
|
-
if (size < 1024 * 1024) {
|
|
112
|
-
return (size / 1024).toFixed(2) + 'KB';
|
|
113
|
-
}
|
|
114
|
-
if (size < 1024 * 1024 * 1024) {
|
|
115
|
-
return (size / 1024 / 1024).toFixed(2) + 'MB';
|
|
116
|
-
}
|
|
117
|
-
return (size / 1024 / 1024 / 1024).toFixed(2) + 'GB';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { DEFAULT_ICON, DEFAULT_ICON_COLOR, getFileExt, getFileSize, isImage, PRESET_FILE_ICONS };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export default function AudioIcon() {
|
|
2
|
-
return (
|
|
3
|
-
<svg
|
|
4
|
-
width="1em"
|
|
5
|
-
height="1em"
|
|
6
|
-
viewBox="0 0 16 16"
|
|
7
|
-
version="1.1"
|
|
8
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
9
|
-
//xmlnsXlink="http://www.w3.org/1999/xlink"
|
|
10
|
-
>
|
|
11
|
-
<title>audio</title>
|
|
12
|
-
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
|
|
13
|
-
<path
|
|
14
|
-
d="M14.1178571,4.0125 C14.225,4.11964286 14.2857143,4.26428571 14.2857143,4.41607143 L14.2857143,15.4285714 C14.2857143,15.7446429 14.0303571,16 13.7142857,16 L2.28571429,16 C1.96964286,16 1.71428571,15.7446429 1.71428571,15.4285714 L1.71428571,0.571428571 C1.71428571,0.255357143 1.96964286,0 2.28571429,0 L9.86964286,0 C10.0214286,0 10.1678571,0.0607142857 10.275,0.167857143 L14.1178571,4.0125 Z M10.7315824,7.11216117 C10.7428131,7.15148751 10.7485063,7.19218979 10.7485063,7.23309113 L10.7485063,8.07742614 C10.7484199,8.27364959 10.6183424,8.44607275 10.4296853,8.50003683 L8.32984514,9.09986306 L8.32984514,11.7071803 C8.32986605,12.5367078 7.67249692,13.217028 6.84345686,13.2454634 L6.79068592,13.2463395 C6.12766108,13.2463395 5.53916361,12.8217001 5.33010655,12.1924966 C5.1210495,11.563293 5.33842118,10.8709227 5.86959669,10.4741173 C6.40077221,10.0773119 7.12636292,10.0652587 7.67042486,10.4442027 L7.67020842,7.74937024 L7.68449368,7.74937024 C7.72405122,7.59919041 7.83988806,7.48101083 7.98924584,7.4384546 L10.1880418,6.81004755 C10.42156,6.74340323 10.6648954,6.87865515 10.7315824,7.11216117 Z M9.60714286,1.31785714 L12.9678571,4.67857143 L9.60714286,4.67857143 L9.60714286,1.31785714 Z"
|
|
15
|
-
fill="currentColor"
|
|
16
|
-
/>
|
|
17
|
-
</g>
|
|
18
|
-
</svg>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export default function VideoIcon() {
|
|
2
|
-
return (
|
|
3
|
-
<svg
|
|
4
|
-
width="1em"
|
|
5
|
-
height="1em"
|
|
6
|
-
viewBox="0 0 16 16"
|
|
7
|
-
version="1.1"
|
|
8
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
9
|
-
// xmlnsXlink="http://www.w3.org/1999/xlink"
|
|
10
|
-
>
|
|
11
|
-
<title>video</title>
|
|
12
|
-
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
|
|
13
|
-
<path
|
|
14
|
-
d="M14.1178571,4.0125 C14.225,4.11964286 14.2857143,4.26428571 14.2857143,4.41607143 L14.2857143,15.4285714 C14.2857143,15.7446429 14.0303571,16 13.7142857,16 L2.28571429,16 C1.96964286,16 1.71428571,15.7446429 1.71428571,15.4285714 L1.71428571,0.571428571 C1.71428571,0.255357143 1.96964286,0 2.28571429,0 L9.86964286,0 C10.0214286,0 10.1678571,0.0607142857 10.275,0.167857143 L14.1178571,4.0125 Z M12.9678571,4.67857143 L9.60714286,1.31785714 L9.60714286,4.67857143 L12.9678571,4.67857143 Z M10.5379461,10.3101106 L6.68957555,13.0059749 C6.59910784,13.0693494 6.47439406,13.0473861 6.41101953,12.9569184 C6.3874624,12.9232903 6.37482581,12.8832269 6.37482581,12.8421686 L6.37482581,7.45043999 C6.37482581,7.33998304 6.46436886,7.25043999 6.57482581,7.25043999 C6.61588409,7.25043999 6.65594753,7.26307658 6.68957555,7.28663371 L10.5379461,9.98249803 C10.6284138,10.0458726 10.6503772,10.1705863 10.5870027,10.2610541 C10.5736331,10.2801392 10.5570312,10.2967411 10.5379461,10.3101106 Z"
|
|
15
|
-
fill="currentColor"
|
|
16
|
-
/>
|
|
17
|
-
</g>
|
|
18
|
-
</svg>
|
|
19
|
-
);
|
|
20
|
-
}
|
package/src/file/index.tsx
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_ICON,
|
|
5
|
-
DEFAULT_ICON_COLOR,
|
|
6
|
-
getFileExt,
|
|
7
|
-
getFileSize,
|
|
8
|
-
PRESET_FILE_ICONS,
|
|
9
|
-
} from './helper';
|
|
10
|
-
|
|
11
|
-
function FileIcon({
|
|
12
|
-
name,
|
|
13
|
-
className,
|
|
14
|
-
showExt = false,
|
|
15
|
-
}: {
|
|
16
|
-
name?: string;
|
|
17
|
-
className?: string;
|
|
18
|
-
showExt?: boolean;
|
|
19
|
-
}) {
|
|
20
|
-
const ext = getFileExt(name) || '';
|
|
21
|
-
|
|
22
|
-
const iconItem = useMemo(() => {
|
|
23
|
-
return PRESET_FILE_ICONS.find((item) => item.ext.includes(ext));
|
|
24
|
-
}, [ext]);
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<div className={classNames('flex flex-col items-center', className)}>
|
|
28
|
-
<div style={{ color: iconItem?.color || DEFAULT_ICON_COLOR }}>
|
|
29
|
-
{iconItem?.icon || DEFAULT_ICON}
|
|
30
|
-
</div>
|
|
31
|
-
{showExt && <div className="text-base">{ext}</div>}
|
|
32
|
-
</div>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function FileCard({
|
|
37
|
-
name,
|
|
38
|
-
size,
|
|
39
|
-
direction = 'horizontal',
|
|
40
|
-
}: {
|
|
41
|
-
name?: string;
|
|
42
|
-
size?: number;
|
|
43
|
-
direction?: 'horizontal' | 'vertical';
|
|
44
|
-
}) {
|
|
45
|
-
return (
|
|
46
|
-
<div
|
|
47
|
-
className={classNames('flex items-center gap-1', {
|
|
48
|
-
'flex-row items-center': direction === 'horizontal',
|
|
49
|
-
'flex-col': direction === 'vertical',
|
|
50
|
-
})}
|
|
51
|
-
>
|
|
52
|
-
<FileIcon name={name} className="text-4xl" />
|
|
53
|
-
<div className={classNames('flex flex-col', { 'items-center': direction === 'vertical' })}>
|
|
54
|
-
{name && <div className="truncate">{name}</div>}
|
|
55
|
-
{size && <div className="text-sm text-desc">{getFileSize(size)}</div>}
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
FileCard.FileIcon = FileIcon;
|
|
62
|
-
|
|
63
|
-
export { FileCard };
|