feat(Boxer): implement Boxer component with autocomplete and server-side support

This commit is contained in:
2026-01-17 18:26:20 +02:00
parent 31f2a0428f
commit a8e9c50290
9 changed files with 963 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { Combobox, Checkbox } from '@mantine/core';
import { useMemo } from 'react';
import type { BoxerItem } from '../Boxer.types';
interface UseBoxerOptionsProps {
boxerData: Array<BoxerItem>;
value?: any | Array<any>;
multiSelect?: boolean;
onOptionSubmit: (index: number) => void;
}
const useBoxerOptions = (props: UseBoxerOptionsProps) => {
const { boxerData, value, multiSelect, onOptionSubmit } = props;
const options = useMemo(() => {
return boxerData.map((item, index) => {
const isSelected = multiSelect
? Array.isArray(value) && value.includes(item.value)
: value === item.value;
return (
<Combobox.Option
key={`${item.value}-${index}`}
value={String(index)}
active={isSelected}
>
{multiSelect ? (
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<Checkbox checked={isSelected} onChange={() => {}} tabIndex={-1} />
<span>{item.label}</span>
</div>
) : (
item.label
)}
</Combobox.Option>
);
});
}, [boxerData, value, multiSelect]);
return { options };
};
export default useBoxerOptions;