/** @jsxRuntime classic */ /** @jsx jsx */ import { useState, useEffect, useRef, Fragment } from 'react'; import { useColors } from '../../hooks/useColors'; import { IOption } from '../../types'; import { containerCss, labelTagCss, marginBottom, marginTop } from './style'; import { jsx } from '@emotion/react'; import { useTypography } from '../../hooks/useTypography'; import { BnIcon, Popup, SelectOptions, Typography } from '../../components'; import { ETypography, ETypographyColor, Icons } from '../../types/theme'; export interface ITagsProps { options: IOption[]; label?: string; bottomInfo?: string; selected: string[]; handleChange: (value: string) => void; } export const TagsInput = ({ options, selected, handleChange, label = '', bottomInfo = '', }: ITagsProps) => { const [searchPhrase, setSearchPhrase] = useState(''); const [isOpen, setOpen] = useState(false); const { colors } = useColors(); const { typography } = useTypography(); const inputRef = useRef(null); useEffect(() => { if (searchPhrase) { setOpen(true); } else { setOpen(false); } }, [searchPhrase]); const handleAddition = (v: string) => { setSearchPhrase(''); setOpen(false); handleChange(v); inputRef?.current?.focus(); }; return ( {label && (
{label}
)} opt.label.includes(searchPhrase))} value={selected} isMultiple onSelect={handleAddition} autoFocus={false} /> } disableAutoTrigger trigger={isOpen} >
{selected.map((tag, index) => { const state = options.find((opt) => String(opt.value) === tag); if (state) { return ( ); } return ; })} setSearchPhrase(e.target.value)} />
{bottomInfo && (
{bottomInfo}
)}
); }; const LabelTag = ({ state, handleRemove, }: { state: IOption; handleRemove: (value: string) => void; }) => { const { colors } = useColors(); const { typography } = useTypography(); return (
{state.label}
); };