diff --git a/src/components/Select.tsx b/src/components/Select.tsx index 8247b0983a32847d0eb981df57a995e49961bea4..378c697adba5044e7b6ba57293fb765a54ee87a8 100644 --- a/src/components/Select.tsx +++ b/src/components/Select.tsx @@ -1,11 +1,25 @@ import React from 'react'; import type { Theme } from 'react-select'; -import ReactSelect, { NamedProps, StylesConfig } from 'react-select'; +import ReactSelect, { NamedProps, StylesConfig, components } from 'react-select'; +import Tag from './Tag'; + +const Option = ({ children, data, ...rest }: { children: any; data: any }) => { + return ( + <components.Option {...rest}> + <Tag color={data.value.color}>{children}</Tag> + </components.Option> + ); +}; const Select = <OptionType, isMulti extends boolean>(props: NamedProps<OptionType, isMulti>): JSX.Element => { const customStyles: StylesConfig<OptionType, isMulti> = { control: (provided) => ({ ...provided, border: '0', borderRadius: '0.5em' }), - multiValue: (provided) => ({ ...provided, borderRadius: '999px', padding: '0 3px' }), + multiValue: (provided, state) => ({ + ...provided, + backgroundColor: state?.data?.value?.color || 'grey', + borderRadius: '999px', + padding: '0 3px', + }), multiValueRemove: (provided) => ({ ...provided, color: 'hsl(0, 0%, 50%)', @@ -15,6 +29,9 @@ const Select = <OptionType, isMulti extends boolean>(props: NamedProps<OptionTyp return ( <ReactSelect + components={{ + Option, + }} theme={(theme): Theme => ({ ...theme, // @ts-expect-error: ThemeConfig type from definitely-typed is not complete