@vaadin/hilla-react-crud
Version:
Hilla CRUD utils for React
17 lines • 1.09 kB
JavaScript
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import { GridSorter } from '@vaadin/react-components/GridSorter.js';
import { useContext } from 'react';
import { ColumnContext } from './autogrid-column-context.js';
export function HeaderSorter() {
const context = useContext(ColumnContext);
const sorterState = context.sortState[context.propertyInfo.name];
const direction = sorterState?.direction ?? null;
const headerLabel = context.customColumnOptions?.header ?? context.propertyInfo.humanReadableName;
return context.customColumnOptions?.sortable === false ? (_jsx(_Fragment, { children: headerLabel })) : (_jsx(GridSorter, { path: context.propertyInfo.name, direction: direction, onDirectionChanged: (e) => {
context.setSortState((prevState) => {
const newSorterState = e.detail.value ? { direction: e.detail.value } : undefined;
return { ...prevState, [context.propertyInfo.name]: newSorterState };
});
}, children: headerLabel }));
}
//# sourceMappingURL=header-sorter.js.map