You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.6 KiB

6 years ago
import * as React from 'react';
import { message } from 'antd';
import { injectIntl } from 'react-intl';
6 years ago
import { ThemeType } from '../../../../components/icon';
import CopyableIcon from './CopyableIcon';
import { CategoriesKeys } from './fields';
interface CategoryProps {
6 years ago
title: CategoriesKeys;
icons: string[];
theme: ThemeType;
newIcons: string[];
intl: any;
6 years ago
}
interface CategoryState {
justCopied: string | null;
}
class Category extends React.Component<CategoryProps, CategoryState> {
6 years ago
copyId?: number;
6 years ago
state = {
justCopied: null,
};
componentWillUnmount() {
window.clearTimeout(this.copyId);
}
onCopied = (type: string, text: string) => {
6 years ago
message.success(
<span>
<code className="copied-code">{text}</code> copied 🎉
</span>,
);
6 years ago
this.setState({ justCopied: type }, () => {
this.copyId = window.setTimeout(() => {
6 years ago
this.setState({ justCopied: null });
}, 2000);
});
6 years ago
};
6 years ago
render() {
const {
6 years ago
icons,
title,
theme,
newIcons,
6 years ago
intl: { messages },
} = this.props;
6 years ago
const items = icons.map(name => {
6 years ago
return (
<CopyableIcon
key={name}
type={name}
theme={theme}
isNew={newIcons.indexOf(name) >= 0}
justCopied={this.state.justCopied}
onCopied={this.onCopied}
/>
);
});
return (
<div>
<h3>{messages[`app.docs.components.icon.category.${title}`]}</h3>
<ul className="anticons-list">{items}</ul>
6 years ago
</div>
);
}
}
export default injectIntl(Category);