2023-12-13 14:32:57 +03:00
|
|
|
'use client';
|
|
|
|
|
2023-09-08 02:15:20 +03:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
import Select, { GroupBase, Props, StylesConfig } from 'react-select';
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
import { useConceptTheme } from '@/context/ThemeContext';
|
|
|
|
import { selectDarkT, selectLightT } from '@/utils/color';
|
2023-09-08 02:15:20 +03:00
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
interface SelectSingleProps<Option, Group extends GroupBase<Option> = GroupBase<Option>>
|
|
|
|
extends Omit<Props<Option, false, Group>, 'theme' | 'menuPortalTarget'> {
|
|
|
|
noPortal?: boolean;
|
2023-09-08 02:15:20 +03:00
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
function SelectSingle<Option, Group extends GroupBase<Option> = GroupBase<Option>>({
|
|
|
|
noPortal,
|
|
|
|
...restProps
|
2023-11-29 13:07:55 +03:00
|
|
|
}: SelectSingleProps<Option, Group>) {
|
2023-09-08 02:15:20 +03:00
|
|
|
const { darkMode, colors } = useConceptTheme();
|
2023-12-28 14:04:44 +03:00
|
|
|
const themeColors = useMemo(() => (!darkMode ? selectLightT : selectDarkT), [darkMode]);
|
2023-09-08 02:15:20 +03:00
|
|
|
|
|
|
|
const adjustedStyles: StylesConfig<Option, false, Group> = useMemo(
|
2023-12-28 14:04:44 +03:00
|
|
|
() => ({
|
|
|
|
control: (styles, { isDisabled }) => ({
|
|
|
|
...styles,
|
|
|
|
borderRadius: '0.25rem',
|
|
|
|
cursor: isDisabled ? 'not-allowed' : 'pointer',
|
|
|
|
boxShadow: 'none'
|
|
|
|
}),
|
|
|
|
menuPortal: styles => ({
|
|
|
|
...styles,
|
|
|
|
zIndex: 9999
|
|
|
|
}),
|
|
|
|
menuList: styles => ({
|
|
|
|
...styles,
|
|
|
|
padding: '0px'
|
|
|
|
}),
|
|
|
|
option: (styles, { isSelected }) => ({
|
|
|
|
...styles,
|
|
|
|
backgroundColor: isSelected ? colors.bgSelected : styles.backgroundColor,
|
|
|
|
color: isSelected ? colors.fgSelected : styles.color,
|
|
|
|
borderWidth: '1px',
|
|
|
|
borderColor: colors.border
|
|
|
|
}),
|
|
|
|
input: styles => ({ ...styles }),
|
|
|
|
placeholder: styles => ({ ...styles }),
|
|
|
|
singleValue: styles => ({ ...styles })
|
2023-09-09 20:36:55 +03:00
|
|
|
}),
|
2023-12-28 14:04:44 +03:00
|
|
|
[colors]
|
|
|
|
);
|
2023-09-08 02:15:20 +03:00
|
|
|
|
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<Select
|
|
|
|
noOptionsMessage={() => 'Список пуст'}
|
|
|
|
theme={theme => ({
|
|
|
|
...theme,
|
|
|
|
borderRadius: 0,
|
|
|
|
colors: {
|
|
|
|
...theme.colors,
|
|
|
|
...themeColors
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
menuPortalTarget={!noPortal ? document.body : null}
|
|
|
|
styles={adjustedStyles}
|
|
|
|
{...restProps}
|
|
|
|
/>
|
|
|
|
);
|
2023-09-08 02:15:20 +03:00
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
export default SelectSingle;
|