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

28 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-02-20 20:22:05 +03:00
import { SelectMulti, type SelectMultiProps } from '@/components/Input';
import { type Styling } from '@/components/props';
2025-02-20 20:22:05 +03:00
import { Grammeme, type IGrammemeOption } from '../models/language';
import { getCompatibleGrams, grammemeCompare, supportedGrammeOptions } from '../models/languageAPI';
2024-06-07 20:17:03 +03:00
2025-02-20 20:22:05 +03:00
interface SelectMultiGrammemeProps extends Omit<SelectMultiProps<IGrammemeOption>, 'value' | 'onChange'>, Styling {
2024-06-07 20:17:03 +03:00
value: IGrammemeOption[];
onChange: (newValue: IGrammemeOption[]) => void;
2024-06-07 20:17:03 +03:00
placeholder?: string;
}
2025-02-15 16:42:33 +03:00
export 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}
/>
);
}