import { CSSObject } from '@emotion/serialize'; import { Field as FormikField, FieldProps } from 'formik'; import React, { forwardRef } from 'react'; import Select, { ContainerProps, ControlProps, GroupProps, IndicatorContainerProps, IndicatorProps, InputProps, MenuListComponentProps, MenuProps, MultiValueProps, OptionProps, PlaceholderProps, SingleValueProps, StylesConfig, ValueContainerProps } from 'react-select'; import Creatable from 'react-select/creatable'; import tw, { theme } from 'twin.macro'; import Label from '@/components/elements/Label'; import { ValueType } from 'react-select/src/types'; import { GroupHeadingProps } from 'react-select/src/components/Group'; import { MenuPortalProps, NoticeProps } from 'react-select/src/components/Menu'; import { LoadingIndicatorProps } from 'react-select/src/components/indicators'; import { MultiValueRemoveProps } from 'react-select/src/components/MultiValue'; type T = any; export const SelectStyle: StylesConfig = { // eslint-disable-next-line @typescript-eslint/no-unused-vars clearIndicator: (base: CSSObject, props: IndicatorProps): CSSObject => { return { ...base, color: props.isFocused ? theme`colors.neutral.300` : theme`colors.neutral.400`, ':hover': { color: theme`colors.neutral.100`, }, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars container: (base: CSSObject, props: ContainerProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars control: (base: CSSObject, props: ControlProps): CSSObject => { return { ...base, height: '2.75rem', /* paddingTop: '0.75rem', paddingBottom: '0.75rem', paddingLeft: '4rem', paddingRight: '4rem', */ background: theme`colors.neutral.600`, borderColor: theme`colors.neutral.500`, borderWidth: '2px', color: theme`colors.neutral.200`, cursor: 'pointer', // boxShadow: props.isFocused ? '0 0 0 2px #2684ff' : undefined, ':hover': { borderColor: !props.isFocused ? theme`colors.neutral.400` : theme`colors.neutral.500`, }, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars dropdownIndicator: (base: CSSObject, props: IndicatorProps): CSSObject => { return { ...base, color: props.isFocused ? theme`colors.neutral.300` : theme`colors.neutral.400`, // TODO: find better alternative for `isFocused` so this only triggers when the dropdown is visible. transform: props.isFocused ? 'rotate(180deg)' : undefined, ':hover': { color: theme`colors.neutral.300`, }, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars group: (base: CSSObject, props: GroupProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars groupHeading: (base: CSSObject, props: GroupHeadingProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars indicatorsContainer: (base: CSSObject, props: IndicatorContainerProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars indicatorSeparator: (base: CSSObject, props: IndicatorProps): CSSObject => { return { ...base, // width: '0', backgroundColor: theme`colors.neutral.500`, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars input: (base: CSSObject, props: InputProps): CSSObject => { return { ...base, color: theme`colors.neutral.200`, fontSize: '0.875rem', }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars loadingIndicator: (base: CSSObject, props: LoadingIndicatorProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars loadingMessage: (base: CSSObject, props: NoticeProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars menu: (base: CSSObject, props: MenuProps): CSSObject => { return { ...base, background: theme`colors.neutral.900`, color: theme`colors.neutral.200`, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars menuList: (base: CSSObject, props: MenuListComponentProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars menuPortal: (base: CSSObject, props: MenuPortalProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars multiValue: (base: CSSObject, props: MultiValueProps): CSSObject => { return { ...base, background: theme`colors.neutral.900`, color: theme`colors.neutral.200`, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars multiValueLabel: (base: CSSObject, props: MultiValueProps): CSSObject => { return { ...base, color: theme`colors.neutral.200`, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars multiValueRemove: (base: CSSObject, props: MultiValueRemoveProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars noOptionsMessage: (base: CSSObject, props: NoticeProps): CSSObject => { return { ...base, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars option: (base: CSSObject, props: OptionProps): CSSObject => { return { ...base, background: theme`colors.neutral.900`, ':hover': { background: theme`colors.neutral.700`, cursor: 'pointer', }, }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars placeholder: (base: CSSObject, props: PlaceholderProps): CSSObject => { return { ...base, color: theme`colors.neutral.300`, fontSize: '0.875rem', }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars singleValue: (base: CSSObject, props: SingleValueProps): CSSObject => { return { ...base, color: '#00000', }; }, // eslint-disable-next-line @typescript-eslint/no-unused-vars valueContainer: (base: CSSObject, props: ValueContainerProps): CSSObject => { return { ...base, }; }, }; export interface Option { value: string; label: string; } interface Props { id?: string; name: string; label?: string; description?: string; placeholder?: string; validate?: (value: any) => undefined | string | Promise; options: Array