import * as React from 'react'; import manifest from '@ant-design/icons/lib/manifest'; import { ThemeType as ThemeFolderType } from '@ant-design/icons/lib/types'; import { Radio, Icon, Input } from 'antd'; import { RadioChangeEvent } from 'antd/lib/radio/interface'; import { injectIntl, InjectedIntlProps } from 'react-intl'; import debounce from 'lodash/debounce'; import Category from './Category'; import { FilledIcon, OutlinedIcon, TwoToneIcon } from './themeIcons'; import { categories, Categories, CategoriesKeys } from './fields'; import { ThemeType } from '../../../../components/icon'; interface IconDisplayProps extends InjectedIntlProps {} interface IconDisplayState { theme: ThemeType; searchKey: string; } class IconDisplay extends React.Component { constructor(props: IconDisplayProps) { super(props); this.handleSearchIcon = debounce(this.handleSearchIcon, 300); } static categories: Categories = categories; static newIconNames: string[] = []; static themeTypeMapper: { [key: string]: ThemeFolderType } = { filled: 'fill', outlined: 'outline', twoTone: 'twotone', }; state: IconDisplayState = { theme: 'outlined', searchKey: '', }; getComputedDisplayList() { return Object.keys(IconDisplay.categories) .map((category: CategoriesKeys) => ({ category, icons: IconDisplay.categories[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, }); }; handleSearchIcon = (searchKey: string) => { this.setState(prevState => ({ ...prevState, searchKey, })); }; renderCategories(list: Array<{ category: CategoriesKeys; icons: string[] }>) { const { searchKey } = this.state; return list .map(({ category, icons }) => { const iconResult = icons.filter(name => name.includes(searchKey)); if (iconResult.length === 0) { return null; } return ( ); }) .filter(category => !!category); } render() { const { intl: { messages }, } = this.props; const list = this.getComputedDisplayList(); return (

{messages['app.docs.components.icon.pick-theme']}

{messages['app.docs.components.icon.outlined']} {messages['app.docs.components.icon.filled']} {messages['app.docs.components.icon.two-tone']} this.handleSearchIcon(e.currentTarget.value)} size="large" />
{this.renderCategories(list)}
); } } export default injectIntl(IconDisplay);