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';
|
2021-09-09 10:58:32 +08:00
|
|
|
import { Radio, Input, Empty } 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
|
|
|
}
|
|
|
|
|
2020-06-22 22:51:18 +08:00
|
|
|
class IconDisplay extends React.PureComponent<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;
|
|
|
|
|
2021-09-09 10:58:32 +08:00
|
|
|
const categoriesResult = Object.keys(categories)
|
2019-12-27 10:23:11 +08:00
|
|
|
.map((key: CategoriesKeys) => {
|
|
|
|
let iconList = categories[key];
|
|
|
|
if (searchKey) {
|
2021-09-09 10:58:32 +08:00
|
|
|
const matchKey = searchKey
|
|
|
|
.replace(new RegExp(`^<([a-zA-Z]*)\\s/>$`, 'gi'), (_, name) => name)
|
|
|
|
.replace(/(Filled|Outlined|TwoTone)$/, '')
|
|
|
|
.toLowerCase();
|
|
|
|
iconList = iconList.filter(iconName => iconName.toLowerCase().includes(matchKey));
|
2019-12-27 10:23:11 +08:00
|
|
|
}
|
2019-05-07 23:54:08 +08:00
|
|
|
|
2020-07-25 15:19:33 +08:00
|
|
|
// CopyrightCircle is same as Copyright, don't show it
|
|
|
|
iconList = iconList.filter(icon => icon !== 'CopyrightCircle');
|
|
|
|
|
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}
|
|
|
|
/>
|
|
|
|
));
|
2021-09-09 10:58:32 +08:00
|
|
|
|
|
|
|
return categoriesResult.length === 0 ? <Empty style={{ margin: '2em 0' }} /> : categoriesResult;
|
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']}
|
2020-04-07 13:44:25 +08:00
|
|
|
style={{ margin: '0 10px', flex: 1 }}
|
2019-04-06 13:20:22 +08:00
|
|
|
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);
|