@hitachivantara/uikit-react-core
Version:
Core React components for the NEXT Design System.
37 lines (36 loc) • 1.1 kB
JavaScript
import { ensurePluginOrder } from "react-table";
const getHeaderPropsHook = (props, { instance, column }) => {
const { isMultiSortEvent = (e) => e.shiftKey } = instance;
const sortDirection = column.isSortedDesc ? "descending" : "ascending";
const nextProps = {
sortable: column.canSort,
sorted: column.isSorted,
sortDirection: column.isSorted ? sortDirection : void 0,
onClick: column.canSort ? (e) => {
e.persist();
column.toggleSortBy(
void 0,
!instance.disableMultiSort && isMultiSortEvent(e)
);
} : void 0
};
return [props, nextProps];
};
const getCellPropsHook = (props, { cell }) => {
const nextProps = {
sorted: cell.column.isSorted
};
return [props, nextProps];
};
const useInstanceHook = (instance) => {
ensurePluginOrder(instance.plugins, ["useSortBy"], "useHvSortBy");
};
const useHvSortBy = (hooks) => {
hooks.getHeaderProps.push(getHeaderPropsHook);
hooks.getCellProps.push(getCellPropsHook);
hooks.useInstance.push(useInstanceHook);
};
useHvSortBy.pluginName = "useHvSortBy";
export {
useHvSortBy
};