@khipu/design-system 0.2.0-alpha.50 → 0.2.0-alpha.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1814,125 +1814,194 @@ async function copyToClipboard(text) {
1814
1814
  }
1815
1815
  }
1816
1816
  var TRANSITION_MS = 300;
1817
- var KdsCopyableTable = forwardRef22(
1818
- ({
1819
- rows,
1820
- copyAllLabel = "Copiar todos los datos",
1821
- copiedAllLabel = "Datos copiados",
1822
- showCopyAll = true,
1823
- className,
1824
- ...props
1825
- }, ref) => {
1826
- const copiedTimers = useRef2(/* @__PURE__ */ new Map());
1827
- const settlingTimers = useRef2(/* @__PURE__ */ new Map());
1828
- const [copiedRows, setCopiedRows] = useState4(/* @__PURE__ */ new Set());
1829
- const [settlingRows, setSettlingRows] = useState4(/* @__PURE__ */ new Set());
1830
- const [allCopied, setAllCopied] = useState4(false);
1831
- const markCopied = useCallback3((indexes, duration = 1500) => {
1832
- setCopiedRows((prev) => {
1833
- const next = new Set(prev);
1834
- indexes.forEach((i) => next.add(i));
1835
- return next;
1836
- });
1837
- indexes.forEach((i) => {
1838
- const st = settlingTimers.current.get(i);
1839
- if (st) {
1840
- clearTimeout(st);
1841
- settlingTimers.current.delete(i);
1842
- }
1843
- });
1844
- setSettlingRows((prev) => {
1845
- const next = new Set(prev);
1846
- indexes.forEach((i) => next.delete(i));
1847
- return next;
1848
- });
1849
- indexes.forEach((i) => {
1850
- const existing = copiedTimers.current.get(i);
1851
- if (existing) clearTimeout(existing);
1852
- const t = setTimeout(() => {
1853
- setCopiedRows((prev) => {
1854
- const next = new Set(prev);
1855
- next.delete(i);
1856
- return next;
1857
- });
1817
+ function GridVariant({
1818
+ gridRows,
1819
+ disabled,
1820
+ className,
1821
+ forwardedRef,
1822
+ rest
1823
+ }) {
1824
+ return /* @__PURE__ */ jsx24(
1825
+ "div",
1826
+ {
1827
+ ref: forwardedRef,
1828
+ className: clsx("kds-copyable-table", "kds-copyable-table--grid", className),
1829
+ ...rest,
1830
+ children: gridRows.map((cells, rowIndex) => /* @__PURE__ */ jsx24(
1831
+ "div",
1832
+ {
1833
+ className: "kds-copyable-table-row kds-copyable-table-row--grid",
1834
+ "data-testid": "kds-grid-row",
1835
+ children: cells.map((text, cellIndex) => /* @__PURE__ */ jsx24(
1836
+ "span",
1837
+ {
1838
+ className: clsx("kds-grid-cell", disabled && "kds-grid-cell--disabled"),
1839
+ children: text
1840
+ },
1841
+ cellIndex
1842
+ ))
1843
+ },
1844
+ rowIndex
1845
+ ))
1846
+ }
1847
+ );
1848
+ }
1849
+ function CopyableVariant({
1850
+ rows,
1851
+ copyAllLabel = "Copiar todos los datos",
1852
+ copiedAllLabel = "Datos copiados",
1853
+ showCopyAll = true,
1854
+ className,
1855
+ forwardedRef,
1856
+ rest
1857
+ }) {
1858
+ const copiedTimers = useRef2(/* @__PURE__ */ new Map());
1859
+ const settlingTimers = useRef2(/* @__PURE__ */ new Map());
1860
+ const [copiedRows, setCopiedRows] = useState4(/* @__PURE__ */ new Set());
1861
+ const [settlingRows, setSettlingRows] = useState4(/* @__PURE__ */ new Set());
1862
+ const [allCopied, setAllCopied] = useState4(false);
1863
+ const markCopied = useCallback3((indexes, duration = 1500) => {
1864
+ setCopiedRows((prev) => {
1865
+ const next = new Set(prev);
1866
+ indexes.forEach((i) => next.add(i));
1867
+ return next;
1868
+ });
1869
+ indexes.forEach((i) => {
1870
+ const st = settlingTimers.current.get(i);
1871
+ if (st) {
1872
+ clearTimeout(st);
1873
+ settlingTimers.current.delete(i);
1874
+ }
1875
+ });
1876
+ setSettlingRows((prev) => {
1877
+ const next = new Set(prev);
1878
+ indexes.forEach((i) => next.delete(i));
1879
+ return next;
1880
+ });
1881
+ indexes.forEach((i) => {
1882
+ const existing = copiedTimers.current.get(i);
1883
+ if (existing) clearTimeout(existing);
1884
+ const t = setTimeout(() => {
1885
+ setCopiedRows((prev) => {
1886
+ const next = new Set(prev);
1887
+ next.delete(i);
1888
+ return next;
1889
+ });
1890
+ setSettlingRows((prev) => {
1891
+ const next = new Set(prev);
1892
+ next.add(i);
1893
+ return next;
1894
+ });
1895
+ copiedTimers.current.delete(i);
1896
+ const settlingT = setTimeout(() => {
1858
1897
  setSettlingRows((prev) => {
1859
1898
  const next = new Set(prev);
1860
- next.add(i);
1899
+ next.delete(i);
1861
1900
  return next;
1862
1901
  });
1863
- copiedTimers.current.delete(i);
1864
- const settlingT = setTimeout(() => {
1865
- setSettlingRows((prev) => {
1866
- const next = new Set(prev);
1867
- next.delete(i);
1868
- return next;
1869
- });
1870
- settlingTimers.current.delete(i);
1871
- }, TRANSITION_MS);
1872
- settlingTimers.current.set(i, settlingT);
1873
- }, duration);
1874
- copiedTimers.current.set(i, t);
1875
- });
1876
- }, []);
1877
- const handleRowCopy = async (row, index) => {
1878
- const ok = await copyToClipboard(row.copy ?? row.value);
1879
- if (ok) markCopied([index]);
1880
- };
1881
- const handleCopyAll = async () => {
1882
- const text = rows.map((r) => `${r.label}: ${r.value}`).join("\n");
1883
- const ok = await copyToClipboard(text);
1884
- if (ok) {
1885
- markCopied(rows.map((_, i) => i));
1886
- setAllCopied(true);
1887
- setTimeout(() => setAllCopied(false), 2e3);
1888
- }
1889
- };
1890
- return /* @__PURE__ */ jsxs18(Fragment2, { children: [
1891
- /* @__PURE__ */ jsx24("div", { ref, className: clsx("kds-copyable-table", className), ...props, children: rows.map((row, i) => /* @__PURE__ */ jsxs18(
1892
- "div",
1893
- {
1894
- className: clsx(
1895
- "kds-copyable-table-row",
1896
- copiedRows.has(i) && "copied",
1897
- settlingRows.has(i) && "settling"
1898
- ),
1899
- role: "button",
1900
- tabIndex: 0,
1901
- onClick: () => handleRowCopy(row, i),
1902
- onKeyDown: (e) => {
1903
- if (e.key === "Enter" || e.key === " ") {
1904
- e.preventDefault();
1905
- handleRowCopy(row, i);
1906
- }
1907
- },
1908
- "aria-label": `Copiar ${row.label}: ${row.value}`,
1909
- children: [
1910
- /* @__PURE__ */ jsx24("span", { className: "kds-key", children: row.label }),
1911
- /* @__PURE__ */ jsx24("span", { className: "kds-value", children: row.value })
1912
- ]
1902
+ settlingTimers.current.delete(i);
1903
+ }, TRANSITION_MS);
1904
+ settlingTimers.current.set(i, settlingT);
1905
+ }, duration);
1906
+ copiedTimers.current.set(i, t);
1907
+ });
1908
+ }, []);
1909
+ const handleRowCopy = async (row, index) => {
1910
+ const ok = await copyToClipboard(row.copy ?? row.value);
1911
+ if (ok) markCopied([index]);
1912
+ };
1913
+ const handleCopyAll = async () => {
1914
+ const text = rows.map((r) => `${r.label}: ${r.value}`).join("\n");
1915
+ const ok = await copyToClipboard(text);
1916
+ if (ok) {
1917
+ markCopied(rows.map((_, i) => i));
1918
+ setAllCopied(true);
1919
+ setTimeout(() => setAllCopied(false), 2e3);
1920
+ }
1921
+ };
1922
+ return /* @__PURE__ */ jsxs18(Fragment2, { children: [
1923
+ /* @__PURE__ */ jsx24("div", { ref: forwardedRef, className: clsx("kds-copyable-table", className), ...rest, children: rows.map((row, i) => /* @__PURE__ */ jsxs18(
1924
+ "div",
1925
+ {
1926
+ className: clsx(
1927
+ "kds-copyable-table-row",
1928
+ copiedRows.has(i) && "copied",
1929
+ settlingRows.has(i) && "settling"
1930
+ ),
1931
+ role: "button",
1932
+ tabIndex: 0,
1933
+ onClick: () => handleRowCopy(row, i),
1934
+ onKeyDown: (e) => {
1935
+ if (e.key === "Enter" || e.key === " ") {
1936
+ e.preventDefault();
1937
+ handleRowCopy(row, i);
1938
+ }
1913
1939
  },
1914
- `${row.label}-${i}`
1915
- )) }),
1916
- showCopyAll && /* @__PURE__ */ jsxs18(
1917
- "button",
1940
+ "aria-label": `Copiar ${row.label}: ${row.value}`,
1941
+ children: [
1942
+ /* @__PURE__ */ jsx24("span", { className: "kds-key", children: row.label }),
1943
+ /* @__PURE__ */ jsx24("span", { className: "kds-value", children: row.value })
1944
+ ]
1945
+ },
1946
+ `${row.label}-${i}`
1947
+ )) }),
1948
+ showCopyAll && /* @__PURE__ */ jsxs18(
1949
+ "button",
1950
+ {
1951
+ type: "button",
1952
+ className: clsx(
1953
+ "kds-btn",
1954
+ "kds-btn-outlined",
1955
+ "kds-btn-block",
1956
+ "kds-copy-all-btn",
1957
+ allCopied && "copied"
1958
+ ),
1959
+ onClick: handleCopyAll,
1960
+ "aria-label": allCopied ? copiedAllLabel : copyAllLabel,
1961
+ children: [
1962
+ /* @__PURE__ */ jsx24("span", { className: "kds-icon", children: /* @__PURE__ */ jsx24("i", { className: "material-symbols-outlined", children: allCopied ? "check" : "content_copy" }) }),
1963
+ /* @__PURE__ */ jsx24("span", { children: allCopied ? copiedAllLabel : copyAllLabel })
1964
+ ]
1965
+ }
1966
+ )
1967
+ ] });
1968
+ }
1969
+ var KdsCopyableTable = forwardRef22(
1970
+ ({
1971
+ rows = [],
1972
+ variant = "copyable",
1973
+ gridRows = [],
1974
+ disabled = false,
1975
+ copyAllLabel,
1976
+ copiedAllLabel,
1977
+ showCopyAll,
1978
+ className,
1979
+ ...props
1980
+ }, ref) => {
1981
+ if (variant === "grid") {
1982
+ return /* @__PURE__ */ jsx24(
1983
+ GridVariant,
1918
1984
  {
1919
- type: "button",
1920
- className: clsx(
1921
- "kds-btn",
1922
- "kds-btn-outlined",
1923
- "kds-btn-block",
1924
- "kds-copy-all-btn",
1925
- allCopied && "copied"
1926
- ),
1927
- onClick: handleCopyAll,
1928
- "aria-label": allCopied ? copiedAllLabel : copyAllLabel,
1929
- children: [
1930
- /* @__PURE__ */ jsx24("span", { className: "kds-icon", children: /* @__PURE__ */ jsx24("i", { className: "material-symbols-outlined", children: allCopied ? "check" : "content_copy" }) }),
1931
- /* @__PURE__ */ jsx24("span", { children: allCopied ? copiedAllLabel : copyAllLabel })
1932
- ]
1985
+ gridRows,
1986
+ disabled,
1987
+ className,
1988
+ forwardedRef: ref,
1989
+ rest: props
1933
1990
  }
1934
- )
1935
- ] });
1991
+ );
1992
+ }
1993
+ return /* @__PURE__ */ jsx24(
1994
+ CopyableVariant,
1995
+ {
1996
+ rows,
1997
+ copyAllLabel,
1998
+ copiedAllLabel,
1999
+ showCopyAll,
2000
+ className,
2001
+ forwardedRef: ref,
2002
+ rest: props
2003
+ }
2004
+ );
1936
2005
  }
1937
2006
  );
1938
2007
  KdsCopyableTable.displayName = "KdsCopyableTable";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khipu/design-system",
3
- "version": "0.2.0-alpha.50",
3
+ "version": "0.2.0-alpha.51",
4
4
  "description": "Khipu Design System - UI components and design tokens for the Khipu payment platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",