import React, { Component, useState } from 'react'; import { Button, Grid, Balloon } from '@alifd/next'; import * as AntdIcons from '@ant-design/icons'; import './index.scss'; const { Row, Col } = Grid; interface IconSelectProps { value?: string | undefined; onChange?: (value: string | undefined) => void; } const list = [ 'CaretUpOutlined', 'CaretDownOutlined', 'FormOutlined', 'DeleteOutlined', 'ExportOutlined', 'ExpandOutlined' ]; const RsIconSetter: React.FC = ({ value, onChange = () => {} }) => { const [seleted, setSelected] = useState(value); // 获取所有图标组件 // const iconList = Object.keys(AntdIcons).filter( // (key) => key.endsWith('Outlined') || key.endsWith('Filled') || key.endsWith('TwoTone'), // ); const onClear = () => { setSelected(''); onChange(''); }; const onSelect = (item: string | undefined) => { setSelected(item); onChange(item); }; const renderIcon = () => { if (!seleted) return; const Icon = AntdIcons[seleted as keyof typeof AntdIcons] as React.FC; return ; }; return (
{renderIcon()}
) : ( ) } triggerType={['click']} > {list.map((item, index) => { const Icon = AntdIcons[item as keyof typeof AntdIcons] as React.FC; return ( // eslint-disable-next-line react/no-array-index-key onSelect(item)} className="item"> ); })} {seleted ? ( ) : null} ); }; export default class extends Component { static displayName = 'IconSetter'; render() { return ; } }