UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

28 lines (27 loc) 1.24 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { forwardRef } from "react"; import { useSortManagerCtx } from "./context.js"; import { sortModelToSortItems } from "./utils/sort-model-to-sort-items.js"; import { itemsWithIdToMap } from "@1771technologies/lytenyte-shared"; import { useEvent, useSlot } from "@1771technologies/lytenyte-core/yinternal"; export const SortCancel = forwardRef(function SortCancel({ as, ...props }, forwarded) { const ctx = useSortManagerCtx(); const onCancel = useEvent(() => { const model = ctx.mode ? ctx.grid.state.columnPivotModel.get().sorts : ctx.grid.state.sortModel.get(); const lookup = itemsWithIdToMap(ctx.mode ? ctx.grid.state.columnPivotColumns.get() : ctx.grid.state.columns.get()); const state = sortModelToSortItems(model, lookup); if (!state.length) ctx.setSortItems([{ isCustom: false, sortDirection: "ascending" }]); else ctx.setSortItems(state); }); const renderer = useSlot({ props: [typeof as !== "function" ? { onClick: onCancel } : {}, props], ref: forwarded, slot: as ?? _jsx("button", {}), state: { onCancel }, }); return renderer; });