2018-09-01 14:05:47 +08:00
|
|
|
import * as React from 'react';
|
2018-09-01 17:44:15 +08:00
|
|
|
import { ThemeType, IconType } from '../../../../components/icon';
|
2018-09-01 16:16:11 +08:00
|
|
|
import manifest from '@ant-design/icons/lib/manifest';
|
2018-09-01 16:48:48 +08:00
|
|
|
import { ThemeType as ThemeFolderType } from '@ant-design/icons/lib/types';
|
2018-09-01 16:16:11 +08:00
|
|
|
import Category from './Category';
|
2018-09-01 16:48:48 +08:00
|
|
|
import { Radio, Icon as AntdIcon } from 'antd';
|
2018-09-01 16:16:11 +08:00
|
|
|
import { RadioChangeEvent } from 'antd/lib/radio/interface';
|
|
|
|
import { FilledIcon, OutlinedIcon, TwoToneIcon } from './themeIcons';
|
|
|
|
import { categories, Categories, CategoriesKeys } from './fields';
|
|
|
|
import { injectIntl, InjectedIntlProps } from 'react-intl';
|
2018-09-01 14:05:47 +08:00
|
|
|
|
2018-09-01 17:44:15 +08:00
|
|
|
const Icon: IconType = AntdIcon as any;
|
2018-09-01 16:48:48 +08:00
|
|
|
|
2018-09-01 16:16:11 +08:00
|
|
|
interface IconDisplayProps extends InjectedIntlProps {
|
2018-09-01 14:05:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IconDisplayState {
|
|
|
|
theme: ThemeType;
|
|
|
|
}
|
|
|
|
|
2018-09-01 16:16:11 +08:00
|
|
|
class IconDisplay extends React.Component<IconDisplayProps, IconDisplayState> {
|
|
|
|
|
|
|
|
static cagetories: Categories = categories;
|
|
|
|
|
|
|
|
static newIconNames: string[] = [];
|
|
|
|
|
|
|
|
static themeTypeMapper: { [key: string]: ThemeFolderType } = {
|
|
|
|
filled: 'fill',
|
|
|
|
outlined: 'outline',
|
|
|
|
twoTone: 'twotone',
|
|
|
|
};
|
|
|
|
|
2018-09-01 14:05:47 +08:00
|
|
|
state: IconDisplayState = {
|
|
|
|
theme: 'outlined',
|
|
|
|
};
|
|
|
|
|
2018-09-01 16:16:11 +08:00
|
|
|
getComputedDisplayList() {
|
|
|
|
return Object.keys(IconDisplay.cagetories)
|
|
|
|
.map(
|
|
|
|
(category: CategoriesKeys) => ({
|
|
|
|
category,
|
|
|
|
icons: IconDisplay.cagetories[category]
|
|
|
|
.filter((name) => manifest[IconDisplay.themeTypeMapper[this.state.theme]].indexOf(name) !== -1),
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.filter(({ icons }) => Boolean(icons.length));
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChangeTheme = (e: RadioChangeEvent) => {
|
|
|
|
this.setState({
|
|
|
|
theme: e.target.value as ThemeType,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-01 16:48:48 +08:00
|
|
|
renderCategories(list: Array<{ category: CategoriesKeys, icons: string[] }>) {
|
2018-09-01 16:16:11 +08:00
|
|
|
return list.map(({ category, icons }) => {
|
|
|
|
return (
|
|
|
|
<Category
|
|
|
|
key={category}
|
|
|
|
title={category}
|
|
|
|
icons={icons}
|
|
|
|
theme={this.state.theme}
|
|
|
|
newIcons={IconDisplay.newIconNames}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-01 14:05:47 +08:00
|
|
|
render() {
|
2018-09-01 16:16:11 +08:00
|
|
|
const { intl: { messages } } = this.props;
|
|
|
|
const list = this.getComputedDisplayList();
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h3>{messages['app.docs.components.icon.pick-theme']}</h3>
|
|
|
|
<Radio.Group value={this.state.theme} onChange={this.handleChangeTheme}>
|
|
|
|
<Radio.Button value="outlined">
|
|
|
|
<Icon component={OutlinedIcon} /> Outlined
|
|
|
|
</Radio.Button>
|
2018-09-01 17:44:15 +08:00
|
|
|
<Radio.Button value="filled">
|
|
|
|
<Icon component={FilledIcon} /> Filled
|
|
|
|
</Radio.Button>
|
2018-09-01 16:16:11 +08:00
|
|
|
<Radio.Button value="twoTone">
|
|
|
|
<Icon component={TwoToneIcon} /> Two Tone
|
|
|
|
</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
{this.renderCategories(list)}
|
|
|
|
</div>
|
|
|
|
);
|
2018-09-01 14:05:47 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-01 16:16:11 +08:00
|
|
|
|
|
|
|
export default injectIntl(IconDisplay);
|