2018-09-01 14:05:47 +08:00
|
|
|
import * as React from 'react';
|
2019-08-30 00:06:35 +08:00
|
|
|
import Icon, * as AntdIcons from '@ant-design/icons';
|
2019-08-13 14:07:17 +08:00
|
|
|
import { Radio, Input } from 'antd';
|
2019-08-05 15:37:00 +08:00
|
|
|
import { RadioChangeEvent } from 'antd/es/radio/interface';
|
2019-08-09 11:32:01 +08:00
|
|
|
import { injectIntl } from 'react-intl';
|
2019-04-06 13:20:22 +08:00
|
|
|
import debounce from 'lodash/debounce';
|
|
|
|
import Category from './Category';
|
2019-08-22 17:53:31 +08:00
|
|
|
import IconPicSearcher from './IconPicSearcher';
|
2018-09-01 16:16:11 +08:00
|
|
|
import { FilledIcon, OutlinedIcon, TwoToneIcon } from './themeIcons';
|
|
|
|
import { categories, Categories, CategoriesKeys } from './fields';
|
2019-08-13 14:07:17 +08:00
|
|
|
|
2019-12-27 10:23:11 +08:00
|
|
|
export enum ThemeType {
|
|
|
|
Filled = 'Filled',
|
|
|
|
Outlined = 'Outlined',
|
|
|
|
TwoTone = 'TwoTone',
|
|
|
|
}
|
2019-10-30 16:28:28 +08:00
|
|
|
|
2019-08-13 14:07:17 +08:00
|
|
|
const allIcons: {
|
|
|
|
[key: string]: any;
|
|
|
|
} = AntdIcons;
|
2018-09-01 14:05:47 +08:00
|
|
|
|
2019-08-09 11:32:01 +08:00
|
|
|
interface IconDisplayProps {
|
|
|
|
intl: any;
|
|
|
|
}
|
2018-09-01 14:05:47 +08:00
|
|
|
|
|
|
|
interface IconDisplayState {
|
|
|
|
theme: ThemeType;
|
2019-04-06 13:20:22 +08:00
|
|
|
searchKey: string;
|
2018-09-01 14:05:47 +08:00
|
|
|
}
|
|
|
|
|
2018-09-01 16:16:11 +08:00
|
|
|
class IconDisplay extends React.Component<IconDisplayProps, IconDisplayState> {
|
2019-04-06 13:20:22 +08:00
|
|
|
static categories: Categories = categories;
|
2018-09-01 16:16:11 +08:00
|
|
|
|
2019-02-17 12:18:40 +08:00
|
|
|
static newIconNames: string[] = [];
|
2018-09-01 16:16:11 +08:00
|
|
|
|
2018-09-01 14:05:47 +08:00
|
|
|
state: IconDisplayState = {
|
2019-12-27 10:23:11 +08:00
|
|
|
theme: ThemeType.Outlined,
|
2019-04-06 13:20:22 +08:00
|
|
|
searchKey: '',
|
2018-09-01 14:05:47 +08:00
|
|
|
};
|
|
|
|
|
2019-04-08 10:17:03 +08:00
|
|
|
constructor(props: IconDisplayProps) {
|
|
|
|
super(props);
|
|
|
|
this.handleSearchIcon = debounce(this.handleSearchIcon, 300);
|
|
|
|
}
|
|
|
|
|
2018-09-01 16:16:11 +08:00
|
|
|
handleChangeTheme = (e: RadioChangeEvent) => {
|
|
|
|
this.setState({
|
|
|
|
theme: e.target.value as ThemeType,
|
|
|
|
});
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2018-09-01 16:16:11 +08:00
|
|
|
|
2019-04-06 13:20:22 +08:00
|
|
|
handleSearchIcon = (searchKey: string) => {
|
|
|
|
this.setState(prevState => ({
|
|
|
|
...prevState,
|
|
|
|
searchKey,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2019-12-27 10:23:11 +08:00
|
|
|
renderCategories() {
|
|
|
|
const { searchKey = '', theme } = this.state;
|
|
|
|
|
|
|
|
return Object.keys(categories)
|
|
|
|
.map((key: CategoriesKeys) => {
|
|
|
|
let iconList = categories[key];
|
|
|
|
if (searchKey) {
|
|
|
|
iconList = iconList.filter(iconName =>
|
|
|
|
iconName.toLowerCase().includes(searchKey.toLowerCase()),
|
|
|
|
);
|
|
|
|
}
|
2019-05-07 23:54:08 +08:00
|
|
|
|
2019-12-27 10:23:11 +08:00
|
|
|
return {
|
|
|
|
category: key,
|
|
|
|
icons: iconList.map(iconName => iconName + theme).filter(iconName => allIcons[iconName]),
|
|
|
|
};
|
|
|
|
})
|
2019-05-16 17:47:50 +08:00
|
|
|
.filter(({ icons }) => !!icons.length)
|
|
|
|
.map(({ category, icons }) => (
|
|
|
|
<Category
|
|
|
|
key={category}
|
2019-12-27 10:23:11 +08:00
|
|
|
title={category as CategoriesKeys}
|
2019-12-25 14:42:15 +08:00
|
|
|
theme={theme}
|
2019-05-16 17:47:50 +08:00
|
|
|
icons={icons}
|
|
|
|
newIcons={IconDisplay.newIconNames}
|
|
|
|
/>
|
|
|
|
));
|
2018-09-01 16:16:11 +08:00
|
|
|
}
|
|
|
|
|
2018-09-01 14:05:47 +08:00
|
|
|
render() {
|
2018-12-07 20:02:01 +08:00
|
|
|
const {
|
|
|
|
intl: { messages },
|
|
|
|
} = this.props;
|
2018-09-01 16:16:11 +08:00
|
|
|
return (
|
2019-04-08 10:17:03 +08:00
|
|
|
<>
|
2019-04-06 13:20:22 +08:00
|
|
|
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
2019-06-19 19:09:08 +08:00
|
|
|
<Radio.Group
|
|
|
|
value={this.state.theme}
|
|
|
|
onChange={this.handleChangeTheme}
|
|
|
|
size="large"
|
|
|
|
buttonStyle="solid"
|
|
|
|
>
|
2019-12-27 10:23:11 +08:00
|
|
|
<Radio.Button value={ThemeType.Outlined}>
|
2019-04-06 13:20:22 +08:00
|
|
|
<Icon component={OutlinedIcon} /> {messages['app.docs.components.icon.outlined']}
|
|
|
|
</Radio.Button>
|
2019-12-27 10:23:11 +08:00
|
|
|
<Radio.Button value={ThemeType.Filled}>
|
2019-04-06 13:20:22 +08:00
|
|
|
<Icon component={FilledIcon} /> {messages['app.docs.components.icon.filled']}
|
|
|
|
</Radio.Button>
|
2019-12-27 10:23:11 +08:00
|
|
|
<Radio.Button value={ThemeType.TwoTone}>
|
2019-04-06 13:20:22 +08:00
|
|
|
<Icon component={TwoToneIcon} /> {messages['app.docs.components.icon.two-tone']}
|
|
|
|
</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
<Input.Search
|
2019-04-08 10:17:03 +08:00
|
|
|
placeholder={messages['app.docs.components.icon.search.placeholder']}
|
2019-04-06 13:20:22 +08:00
|
|
|
style={{ marginLeft: 10, flex: 1 }}
|
|
|
|
allowClear
|
|
|
|
onChange={e => this.handleSearchIcon(e.currentTarget.value)}
|
|
|
|
size="large"
|
2019-04-08 10:17:03 +08:00
|
|
|
autoFocus
|
2019-08-22 17:53:31 +08:00
|
|
|
suffix={<IconPicSearcher />}
|
2019-04-06 13:20:22 +08:00
|
|
|
/>
|
|
|
|
</div>
|
2019-12-27 10:23:11 +08:00
|
|
|
{this.renderCategories()}
|
2019-04-08 10:17:03 +08:00
|
|
|
</>
|
2018-09-01 16:16:11 +08:00
|
|
|
);
|
2018-09-01 14:05:47 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-01 16:16:11 +08:00
|
|
|
|
|
|
|
export default injectIntl(IconDisplay);
|