blob: 2391687e29210268df1d20d0297e68c328878045 [file] [log] [blame]
Jiarenxiang38dcb052025-03-13 16:40:09 +08001import * as React from 'react';
2import CopyableIcon from './CopyableIcon';
3import type { ThemeType } from './index';
4import type { CategoriesKeys } from './fields';
5import { useIntl } from '@umijs/max';
6import styles from './style.less';
7
8interface CategoryProps {
9 title: CategoriesKeys;
10 icons: string[];
11 theme: ThemeType;
12 newIcons: string[];
13 onSelect: (type: string, name: string) => any;
14}
15
16const Category: React.FC<CategoryProps> = props => {
17
18 const { icons, title, newIcons, theme } = props;
19 const intl = useIntl();
20 const [justCopied, setJustCopied] = React.useState<string | null>(null);
21 const copyId = React.useRef<NodeJS.Timeout | null>(null);
22 const onSelect = React.useCallback((type: string, text: string) => {
23 const { onSelect } = props;
24 if (onSelect) {
25 onSelect(type, text);
26 }
27 setJustCopied(type);
28 copyId.current = setTimeout(() => {
29 setJustCopied(null);
30 }, 2000);
31 }, []);
32 React.useEffect(
33 () => () => {
34 if (copyId.current) {
35 clearTimeout(Number(copyId.current));
36 }
37 },
38 [],
39 );
40
41 return (
42 <div>
43 <h4>{intl.formatMessage({
44 id: `app.docs.components.icon.category.${title}`,
45 defaultMessage: '信息',
46 })}</h4>
47 <ul className={styles.anticonsList}>
48 {icons.map(name => (
49 <CopyableIcon
50 key={name}
51 name={name}
52 theme={theme}
53 isNew={newIcons.includes(name)}
54 justCopied={justCopied}
55 onSelect={onSelect}
56 />
57 ))}
58 </ul>
59 </div>
60 );
61};
62
63export default Category;