Portal/rsconcept/frontend/src/features/rsform/components/SelectMultiGrammeme.tsx

32 lines
1.1 KiB
TypeScript
Raw Normal View History

import { SelectMulti, SelectMultiProps } from '@/components/Input';
2025-01-28 23:23:03 +03:00
import { CProps } from '@/components/props';
import { Grammeme, IGrammemeOption } from '../models/language';
import { getCompatibleGrams, grammemeCompare, supportedGrammeOptions } from '../models/languageAPI';
2024-06-07 20:17:03 +03:00
interface SelectMultiGrammemeProps
extends Omit<SelectMultiProps<IGrammemeOption>, 'value' | 'onChange'>,
CProps.Styling {
value: IGrammemeOption[];
onChange: (newValue: IGrammemeOption[]) => void;
2024-06-07 20:17:03 +03:00
placeholder?: string;
}
function SelectMultiGrammeme({ value, onChange, ...restProps }: SelectMultiGrammemeProps) {
2025-02-05 21:55:26 +03:00
const compatible = getCompatibleGrams(
value.filter(data => Object.values(Grammeme).includes(data.value as Grammeme)).map(data => data.value as Grammeme)
);
const options = supportedGrammeOptions.filter(({ value }) => compatible.includes(value as Grammeme));
2024-06-07 20:17:03 +03:00
return (
<SelectMulti
options={options}
value={value}
onChange={newValue => onChange([...newValue].sort((left, right) => grammemeCompare(left.value, right.value)))}
2024-06-07 20:17:03 +03:00
{...restProps}
/>
);
}
export default SelectMultiGrammeme;