UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

111 lines (110 loc) 2.51 kB
"use client"; import { jsxs as c, jsx as b } from "react/jsx-runtime"; import { useDataCrossTable as g } from "./data-cross-table-context.js"; import { Button as f } from "../../button.js"; import { Icon as v } from "../../icon.js"; const R = ({ className: x = "" }) => { const { editedCells: m, setEditedCells: u, toDefaultCells: n, setToDefaultCells: d, editMode: p, setEditMode: C, onConfirmedCells: o, editConfirmLabel: D, editCancelLabel: j, editRestoreDefaultLabel: k, showDefaultActionButton: h } = g(); if (!p) return null; const l = Object.keys(m).length, s = Object.keys(n).length, i = l > 0 || s > 0, L = () => { if (o) { const a = Object.entries(n).map( ([$, { value: r, cell: e }]) => ({ fromId: e.fromId, toId: e.toId, id: e.id, value: r }) ); o({ editedCells: [], toDefaultCells: a }); } d({}); }, N = () => { if (o && i) { const a = Object.entries(m).map( ([r, { value: e, cell: t }]) => ({ fromId: t.fromId, toId: t.toId, id: t.id, value: e }) ), I = Object.entries(n).map( ([r, { value: e, cell: t }]) => ({ fromId: t.fromId, toId: t.toId, id: t.id, value: e }) ); o({ editedCells: a, toDefaultCells: I }); } u({}), d({}), C(!1); }, O = () => { u({}), d({}), C(!1); }; return /* @__PURE__ */ c("div", { className: `flex items-center space-x-2 ${x}`, children: [ h && /* @__PURE__ */ c( f, { variant: "outline", size: "sm", onClick: L, disabled: s === 0, className: "text-xs", iconLeft: "RotateCcw", children: [ k, " ", s > 0 && `(${s})` ] } ), /* @__PURE__ */ b( f, { variant: "outline", size: "sm", onClick: O, className: "text-xs", iconLeft: "X", children: j } ), /* @__PURE__ */ c( f, { size: "sm", onClick: N, disabled: !i, className: "text-xs", children: [ /* @__PURE__ */ b(v, { name: "Check", className: "mr-1 h-3 w-3" }), D, " ", h ? i && `(${l + s})` : l > 0 && `(${l})` ] } ) ] }); }; export { R as DataCrossTableButtonsGroup };