import ReactSelect, { ControlProps, MenuProps, PlaceholderProps, ValueContainerProps, MultiValue, OptionProps, } from 'react-select' import { controlDiv, menu, menuBackground, option, placeholderSpan, } from './Select.css' export interface SelectProps { options?: { value: string; label: string }[] placeholder: string onChange?: (newValue: MultiValue<{ value: string }>) => void value: MultiValue<{ value: string }> } export const Select = ({ placeholder, options = [], onChange, value, }: SelectProps) => { const handleChange = (newValue: MultiValue<{ value: string }>) => { if (onChange) { onChange(newValue) } } return ( ( // @ts-ignore ), }} styles={{ container: () => ({ display: 'inline-block', margin: '0 6px', '@media(min-width: 768px)': { position: 'relative', }, }), }} value={value} /> ) } const SelectControl = (props: ControlProps) => { const { children, isFocused, innerRef, innerProps } = props return (
{children}
) } const SelectPlaceholder = ({ children, }: Pick) => ( {children} ) const SelectValueContainer = ({ children, placeholder, }: ValueContainerProps & { placeholder: string }) => { const [placeholderChild, menu] = children as React.ReactElement[] if (placeholderChild.key !== 'placeholder') { return (
{placeholder} {menu}
) } return
{children}
} const SelectMenu = (props: MenuProps) => { const { children, innerRef, innerProps } = props return ( <>
{/* @ts-ignore */}
{children}
) } const SelectOption = (props: OptionProps) => { const { children, isFocused, isSelected, innerRef, innerProps } = props return (
{children} {isSelected ? ( ) : null}
) }