2023-09-08 02:15:20 +03:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
import Select, { GroupBase, Props, StylesConfig } from 'react-select';
|
|
|
|
|
|
|
|
import { useConceptTheme } from '../../context/ThemeContext';
|
|
|
|
import { selectDarkT, selectLightT } from '../../utils/color';
|
|
|
|
|
2023-09-14 16:53:38 +03:00
|
|
|
interface SelectMultiProps<
|
2023-09-08 02:15:20 +03:00
|
|
|
Option,
|
|
|
|
Group extends GroupBase<Option> = GroupBase<Option>
|
|
|
|
>
|
2023-09-14 16:53:38 +03:00
|
|
|
extends Omit<Props<Option, true, Group>, 'theme'> {
|
2023-09-08 02:15:20 +03:00
|
|
|
}
|
|
|
|
|
2023-09-14 16:53:38 +03:00
|
|
|
function SelectMulti<
|
2023-09-08 02:15:20 +03:00
|
|
|
Option,
|
|
|
|
Group extends GroupBase<Option> = GroupBase<Option>
|
2023-11-27 13:50:56 +03:00
|
|
|
> (props: SelectMultiProps<Option, Group>) {
|
2023-09-08 02:15:20 +03:00
|
|
|
const { darkMode, colors } = useConceptTheme();
|
|
|
|
const themeColors = useMemo(
|
2023-09-09 20:36:55 +03:00
|
|
|
() => !darkMode ? selectLightT : selectDarkT
|
|
|
|
, [darkMode]);
|
2023-09-08 02:15:20 +03:00
|
|
|
|
2023-09-14 16:53:38 +03:00
|
|
|
const adjustedStyles: StylesConfig<Option, true, Group> = useMemo(
|
2023-09-09 20:36:55 +03:00
|
|
|
() => ({
|
|
|
|
control: (styles, { isDisabled }) => ({
|
|
|
|
...styles,
|
|
|
|
borderRadius: '0.25rem',
|
|
|
|
cursor: isDisabled ? 'not-allowed' : 'pointer'
|
|
|
|
}),
|
2023-09-14 16:53:38 +03:00
|
|
|
|
2023-09-09 20:36:55 +03:00
|
|
|
option: (styles, { isSelected }) => ({
|
|
|
|
...styles,
|
|
|
|
backgroundColor: isSelected ? colors.bgSelected : styles.backgroundColor,
|
|
|
|
color: isSelected ? colors.fgSelected : styles.color,
|
|
|
|
borderWidth: '1px',
|
|
|
|
borderColor: colors.border
|
|
|
|
}),
|
2023-10-14 17:14:40 +03:00
|
|
|
menuList: (styles) => ({
|
|
|
|
...styles,
|
|
|
|
padding: '0px'
|
|
|
|
}),
|
2023-09-09 20:36:55 +03:00
|
|
|
input: (styles) => ({...styles}),
|
|
|
|
placeholder: (styles) => ({...styles}),
|
2023-09-14 16:53:38 +03:00
|
|
|
multiValue: styles => ({
|
|
|
|
...styles,
|
|
|
|
borderRadius: '0.5rem',
|
|
|
|
backgroundColor: colors.bgSelected,
|
|
|
|
}),
|
|
|
|
|
2023-09-09 20:36:55 +03:00
|
|
|
}), [colors]);
|
2023-09-08 02:15:20 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
noOptionsMessage={() => 'Список пуст'}
|
|
|
|
theme={theme => ({
|
|
|
|
...theme,
|
|
|
|
borderRadius: 0,
|
|
|
|
colors: {
|
|
|
|
...theme.colors,
|
|
|
|
...themeColors
|
|
|
|
},
|
|
|
|
})}
|
2023-09-14 16:53:38 +03:00
|
|
|
isMulti
|
2023-09-08 02:15:20 +03:00
|
|
|
styles={adjustedStyles}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-14 16:53:38 +03:00
|
|
|
export default SelectMulti;
|