mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-29 20:08:37 +08:00
1f39811047
* refactor(iconSearch): use message hooks usage * fix: use useApp
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import * as React from 'react';
|
|
import { useIntl } from 'dumi';
|
|
import { App } from 'antd';
|
|
import CopyableIcon from './CopyableIcon';
|
|
import type { ThemeType } from './index';
|
|
import type { CategoriesKeys } from './fields';
|
|
|
|
interface CategoryProps {
|
|
title: CategoriesKeys;
|
|
icons: string[];
|
|
theme: ThemeType;
|
|
newIcons: string[];
|
|
}
|
|
|
|
const Category: React.FC<CategoryProps> = (props) => {
|
|
const { message } = App.useApp();
|
|
const { icons, title, newIcons, theme } = props;
|
|
const intl = useIntl();
|
|
const [justCopied, setJustCopied] = React.useState<string | null>(null);
|
|
const copyId = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
const onCopied = React.useCallback((type: string, text: string) => {
|
|
message.success(
|
|
<span>
|
|
<code className="copied-code">{text}</code> copied 🎉
|
|
</span>,
|
|
);
|
|
setJustCopied(type);
|
|
copyId.current = setTimeout(() => {
|
|
setJustCopied(null);
|
|
}, 2000);
|
|
}, []);
|
|
React.useEffect(
|
|
() => () => {
|
|
if (copyId.current) {
|
|
clearTimeout(copyId.current);
|
|
}
|
|
},
|
|
[],
|
|
);
|
|
return (
|
|
<div>
|
|
<h3>{intl.formatMessage({ id: `app.docs.components.icon.category.${title}` })}</h3>
|
|
<ul className="anticons-list">
|
|
{icons.map((name) => (
|
|
<CopyableIcon
|
|
key={name}
|
|
name={name}
|
|
theme={theme}
|
|
isNew={newIcons.includes(name)}
|
|
justCopied={justCopied}
|
|
onCopied={onCopied}
|
|
/>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Category;
|