You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import KFIcon from '@/components/KFIcon';
  2. import KFModal from '@/components/KFModal';
  3. import iconData from '@/iconfont/iconfont.json';
  4. import { type ModalProps } from 'antd';
  5. import { useEffect, useState } from 'react';
  6. import styles from './index.less';
  7. interface MenuIconSelectorProps extends Omit<ModalProps, 'onOk'> {
  8. selectedIcon?: string;
  9. onOk: (param: string) => void;
  10. }
  11. type IconObject = {
  12. icon_id: string;
  13. font_class: string;
  14. };
  15. function MenuIconSelector({ open, selectedIcon, onOk, ...rest }: MenuIconSelectorProps) {
  16. const [icons, setIcons] = useState<IconObject[]>([]);
  17. useEffect(() => {
  18. const glyphs = iconData.glyphs as IconObject[];
  19. setIcons(glyphs.filter((item) => !item.font_class.endsWith('-active')));
  20. }, []);
  21. return (
  22. <KFModal
  23. {...rest}
  24. title="选择图标"
  25. width={680}
  26. open={open}
  27. cancelButtonProps={{ style: { display: 'none' } }}
  28. okButtonProps={{ style: { display: 'none' } }}
  29. >
  30. <div className={styles['menu-icon-selector']}>
  31. {icons.map((icon) => (
  32. <div
  33. key={icon.icon_id}
  34. className={styles['menu-icon-selector__item']}
  35. onClick={() => onOk(icon.font_class)}
  36. >
  37. <KFIcon
  38. className={styles['menu-icon-selector__item__icon']}
  39. type={
  40. selectedIcon === icon.font_class
  41. ? `icon-${icon.font_class}-active`
  42. : `icon-${icon.font_class}`
  43. }
  44. font={24}
  45. />
  46. <KFIcon
  47. className={styles['menu-icon-selector__item__icon--active']}
  48. type={`icon-${icon.font_class}-active`}
  49. font={24}
  50. />
  51. </div>
  52. ))}
  53. </div>
  54. </KFModal>
  55. );
  56. }
  57. export default MenuIconSelector;