import clsx from 'clsx'; import React, { useMemo } from 'react'; import { FixedSizeList as List } from 'react-window'; import { FiChevronUp, FiChevronLeft } from 'react-icons/fi'; import { MdCheck } from 'react-icons/md'; import { useEnv } from '@/context/EnvContext'; import { useTranslation } from '@/hooks/useTranslation'; import { useResponsiveSize } from '@/hooks/useResponsiveSize'; interface DropdownProps { family?: string; selected: string; options: { option: string; label?: string }[]; moreOptions?: { option: string; label?: string }[]; onSelect: (option: string) => void; onGetFontFamily: (option: string, family: string) => string; } interface FontItemProps { index: number; style: React.CSSProperties; data: { options: { option: string; label?: string }[]; selected: string; onSelect: (option: string) => void; onGetFontFamily: (option: string, family: string) => string; family: string; iconSize: number; }; } const FontItem: React.FC = ({ index, style, data }) => { const { options, selected, onSelect, onGetFontFamily, family, iconSize: iconSize16 } = data; const option = options[index]!; return (
  • onSelect(option.option)} >
    {selected === option.option && ( )} {option.label || option.option}
  • ); }; const FontDropdown: React.FC = ({ family, selected, options, moreOptions, onSelect, onGetFontFamily, }) => { const _ = useTranslation(); const { appService } = useEnv(); const iconSize = useResponsiveSize(16); const allOptions = [...options, ...(moreOptions ?? [])]; const selectedOption = allOptions.find((option) => option.option === selected) ?? allOptions[0]!; const ITEM_HEIGHT = 40; const MAX_HEIGHT = 320; const mainListData = useMemo( () => ({ options, selected, onSelect, onGetFontFamily, family: family ?? '', iconSize, appService, }), [options, selected, onSelect, onGetFontFamily, family, iconSize, appService], ); const moreListData = useMemo( () => ({ options: moreOptions ?? [], selected, onSelect, onGetFontFamily, family: family ?? '', iconSize, }), [moreOptions, selected, onSelect, onGetFontFamily, family, iconSize], ); return (
      {/* Virtualized main options */}
      {FontItem}
      {/* More options with nested dropdown */} {moreOptions && moreOptions.length > 0 && (
    • {_('System Fonts')}
        {/* Virtualized more options */}
        {FontItem}
    • )}
    ); }; export default FontDropdown;