import React, { useEffect, useRef } from 'react'; import { BoxSize, SilkeBox } from '../silke-box'; import { SilkeCheckbox } from '../silke-checkbox'; import { SilkeText, SilkeTextMicro } from '../silke-text'; import { Data, Entry } from './autocomplete-types'; import styles from './silke-autocomplete-field.scss'; import { SilkeIcon } from '../silke-icon'; import { EmojiType } from '@vev/utils'; export interface AutocompleteRenderItemProps { item: U; highlight?: boolean; selected?: boolean; isDisabled?: boolean; } export interface AutocompleteItemProps> { item: U; highlight?: boolean; selected?: boolean; multiple?: boolean; size?: BoxSize; iconFontSize?: string; onMouseDown: (e: React.MouseEvent) => void; ItemRender?: React.FC>; } export default function AutocompleteItem>({ item, selected, multiple, highlight, size, iconFontSize, onMouseDown, ItemRender, }: AutocompleteItemProps) { const label = (item.label || item.value || 'missing label') as string; const isDisabled = (item as Data).disabled; const ref = useRef(null); const cl = styles.autocompleteItem; useEffect(() => { const el = ref.current; if (highlight) (el as any)?.scrollIntoViewIfNeeded?.(); }, [highlight]); let iconSize: BoxSize = size || 'm'; if (size === 'm') iconSize = 'base'; if (size === 'base') iconSize = 's'; if (size === 's') iconSize = 'xs'; // For items with sublabel we need more space let boxSize: BoxSize = size || 'm'; if (item.subLabel && (size === 's' || size === 'xs')) boxSize = 'base'; return ( ) => e.preventDefault() : onMouseDown } > {ItemRender ? ( ) : ( <> {multiple && ( )} {item.image && ( )} {item.icon && ( )} {label} {item.subLabel && ( {item.subLabel} )} )} ); }