UNPKG

@maherunlocker/custom-react-table

Version:
85 lines 4.69 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import React from 'react'; import { Chip, Collapse } from '@mui/material'; import { createStyles, makeStyles } from '@mui/styles'; import { CrossIcon } from '../components/assets/CrossIcon'; const useStyles = makeStyles(createStyles({ filtersActiveLabel: { color: '#2B2828', fontSize: '14px', paddingRight: 10, }, chipZone: { padding: '18px 0 5px 10px', width: '100%', }, chipLabel: { fontWeight: 500, marginRight: 5, color: '#2B2828 !important', }, filterChip: { border: '1px solid #626368 !important', background: '#F6F6F6 0% 0% no-repeat padding-box !important', marginRight: '5px!important', marginBottom: '5px!important', }, })); // const getFilterValue = (column: ColumnInstance<any>, filterValue: FilterValue) => { // switch (column.filter) { // case 'between': // const min = filterValue[0]; // const max = filterValue[1]; // return min ? (max ? `${min}-${max}` : `>=${min}`) : `<=${max}`; // } // return filterValue; // }; export function FilterChipBarCollapsible({ instance, showMore, setDesignationFilter, }) { // const { t } = useTranslation(); const classes = useStyles({}); const { allColumns, setFilter, setAllFilters, state: { filters }, } = instance; const handleDelete = React.useCallback((id, selectedFilterValue) => { const filtered = filters.find((f) => f.id === id); const newValues = filtered !== undefined && (filtered === null || filtered === void 0 ? void 0 : filtered.value.filter((f) => f !== selectedFilterValue)); setFilter(id, (newValues === null || newValues === void 0 ? void 0 : newValues.length) > 0 ? newValues : undefined); }, [setFilter, filters]); const resetFilters = React.useCallback(() => { setAllFilters([]); setDesignationFilter(''); // eslint-disable-next-line }, [setAllFilters]); const [expanded, setExpanded] = React.useState(false); const handleExpandClick = () => { setExpanded(!expanded); }; function FilteredChipBar({ splicedFilter, showMore, }) { const [filtersToShow, setFiltersToShow] = React.useState(() => filters); React.useEffect(() => { if (showMore) { setFiltersToShow(splicedFilter ? filters.slice(2, filters.length) : filters.slice(0, 2)); } }, [showMore, splicedFilter]); return (_jsx(React.Fragment, { children: allColumns.map((column) => { const filter = filtersToShow.find((f) => f.id === column.id); const filterValues = filter && filter.value; return (filterValues && filterValues.map((Filtervalue) => (_jsx(Chip, { className: classes.filterChip, deleteIcon: _jsx(CrossIcon, { height: 10, width: 10, fill: "#2B2828" }), label: _jsxs(React.Fragment, { children: [_jsxs("span", Object.assign({ className: classes.chipLabel }, { children: [column.render('Header'), ":", ' '] })), _jsxs("span", Object.assign({ className: classes.chipLabel }, { children: [Filtervalue, " "] }))] }), onDelete: () => handleDelete(column.id, Filtervalue), variant: "outlined" }, Filtervalue)))); }) })); } return filters.some((filterValue) => filterValue.value.length > 0) ? (_jsxs("div", Object.assign({ className: classes.chipZone }, { children: [_jsx("span", Object.assign({ className: classes.filtersActiveLabel, style: { color: '#FF0000', textDecoration: 'underline', cursor: 'pointer', fontWeight: 'bold', }, onClick: () => resetFilters() }, { children: "Effacer tous" })), filters.length > 0 ? (_jsx(FilteredChipBar, { splicedFilter: false, showMore: showMore })) : null, _jsx(Collapse, Object.assign({ in: expanded }, { children: filters.length > 2 ? (_jsx(FilteredChipBar, { splicedFilter: true, showMore: showMore })) : null })), showMore ? (_jsx("span", Object.assign({ onClick: () => handleExpandClick(), style: { textAlign: 'end', color: '#0077D7', textDecoration: 'underline', cursor: 'pointer', alignItems: 'flex-end', display: 'block', marginRight: '11px', } }, { children: expanded ? 'Afficher moins' : 'Afficher plus' }))) : null] }))) : null; } //# sourceMappingURL=FilterChipBarCollapsible.js.map