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.9 kB

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