@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/beercss/khipu-beercss.css +35 -1
- package/dist/beercss/khipu-beercss.min.css +1 -1
- package/dist/beercss/khipu-beercss.scoped.css +35 -1
- package/dist/beercss/khipu-beercss.scoped.min.css +1 -1
- package/dist/beercss/metadata.json +5 -5
- package/dist/index.d.mts +33 -4
- package/dist/index.d.ts +33 -4
- package/dist/index.js +181 -112
- package/dist/index.mjs +181 -112
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1814,125 +1814,194 @@ async function copyToClipboard(text) {
|
|
|
1814
1814
|
}
|
|
1815
1815
|
}
|
|
1816
1816
|
var TRANSITION_MS = 300;
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
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.
|
|
1899
|
+
next.delete(i);
|
|
1861
1900
|
return next;
|
|
1862
1901
|
});
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
"
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
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
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
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
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
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