import { useEffect, useRef, useState } from 'react'; import { useField } from '@unform/core'; import { useTheme as useStyledTheme } from 'styled-components'; import { useTheme } from '../../../hooks/theme'; import { InputContainer, Label, Error } from '../styles'; import { Container } from './styles'; type Option = { value: number | string; label: string; }; interface Props { name: string; label?: string; placeholder?: string; options: Option[]; returnType?: 'key' | 'option'; onChange?: (value: string | number | null) => void; menuPlacement?: 'top' | 'bottom' | 'auto'; } type SelectProps = JSX.IntrinsicElements['input'] & Props; export function Select({ name, label, disabled, options, placeholder, returnType = 'key', onChange, menuPlacement = 'auto', }: SelectProps): JSX.Element { const { colorScheme } = useTheme(); const { colors, shadows } = useStyledTheme(); const selectRef = useRef(null); const { fieldName, defaultValue, registerField, error } = useField(name); const [selected, setSelected] = useState