@eristack/line-grid
Version:
Editable QUPS line table with patchLine recalculation hook
30 lines (29 loc) • 1.2 kB
JavaScript
// src/line-grid.tsx
import { jsx, jsxs } from "react/jsx-runtime";
function LineGrid({ line, columns, renderCell }) {
return /* @__PURE__ */ jsxs("table", { className: "erista-line-grid", "data-component": "line-grid", children: [
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx("th", { scope: "col", children: column.header }, column.id)) }) }),
/* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx("td", { children: renderCell(column.id, line) }, column.id)) }) })
] });
}
// src/use-line-grid-recalc.ts
import {
calculateLine,
patchLine
} from "@eristack/qups";
import { useCallback, useState } from "react";
function useLineGridRecalc(initial) {
const [line, setLine] = useState(() => calculateLine(initial));
const applyPatch = useCallback((patch) => {
setLine((current) => patchLine(current, patch));
}, []);
const recalculate = useCallback((input) => {
setLine(calculateLine(input));
}, []);
return { line, applyPatch, recalculate };
}
export {
LineGrid,
useLineGridRecalc
};
//# sourceMappingURL=index.js.map