import React from 'react';
import BFilter from '@ui/BFilter';
import IFilterField from '@ui/BFilter/IFilterField';
import { FilterComponentField, FilterDatePickerField, FilterInputField, FilterSelectField } from '@ui/BFilter/FilterField';
const MyComponent: React.FC = () = {
const [filterParams, setFilterParams] = useState<Record<string, any> | null>({
search: '',
userId: null,
dateCreated: '2024-05-05',
custom: '',
});
const [redefineValuesDep, setRedefineValuesDep] = useState<boolean>(false);
const filterFields: IFilterField[] = [
new FilterInputField({
keyName: 'search',
name: 'Поиск',
value: filterParams.search,
label: 'Поиск',
}),
new FilterSelectField({
keyName: 'userId',
label: 'Пользователь',
getMethod: () => usersList,
reduceListItem: (elem) => elem.name,
reduceValue: (elem) => elem.id,
value: filterParams?.userId ?? null,
searchQueryParam: 'name',
}),
new FilterDatePickerField({
keyName: 'dateCreated',
label: 'Date Created',
value: filterParams.dateCreated,
}),
new FilterComponentField({
keyName: 'custom',
value: filterParams.custom,
component: ({ keyName, value, key, onChange }) =>
<input type='text' data-testid={'BFilterFieldKey-' + keyName} key={key} value={value} onChange={(e) => onChange(e.target.value)} />,
})
];
return (
<>
<BFilter
filterFields={filterFields}
redefineValuesDep={redefineValuesDep}
realTime={true}
onChange={(e: Record<string, any> | null) => filterParams = e}
/>
// BTable with BPagination or sth eles
</>
);
};
export default MyComponent;
type IFilterField =
| IFilterInput
| IFilterDatePicker
| IFilterCheckbox
| IFilterRadio
| IFilterSelect<any, any>
| IFilterFieldComponent;
enum FilterFieldType {
DATEPICKER,
SELECT,
CHECKBOX,
RADIO,
INPUT,
COMPONENT,
}