UNPKG

@mankindui/core

Version:

- a react component library - you can see how @mankindui/core can be used via examples: [usage examples](https://github.com/clarklindev/mankindui-test)

43 lines (42 loc) 1.73 kB
import { j as o } from "../../_virtual/jsx-runtime.js"; import d, { useState as u } from "react"; import { Button as f } from "../Button/index.js"; import "../../icons/index.js"; import "../../context/index.js"; import { Icon as x } from "../Icon/index.js"; import C from "../../_virtual/server.browser.js"; import { useTheme as h } from "../../context/ThemeContext.js"; import { HiOutlineClipboardDocumentCheck as k, HiOutlineClipboardDocument as b } from "../../node_modules/react-icons/hi2/index.js"; const H = ({ children: e, showClipboardIcon: c = !0, darkIcon: s = "black", lightIcon: i = "white" }) => { const [l, n] = u(!1), { colorScheme: a } = h(), m = () => { n(!0); const t = setTimeout(() => { n(!1); }, 2e3); return () => { clearTimeout(t); }; }, p = async () => { let t = ""; if (typeof e == "string") t = e; else if (d.isValidElement(e)) { const r = C.renderToStaticMarkup(e); t = new DOMParser().parseFromString(r, "text/html").body.textContent || ""; } if (t) try { await navigator.clipboard.writeText(t), m(), console.log("Content copied to clipboard!"); } catch (r) { console.error("Failed to copy text: ", r); } }; return /* @__PURE__ */ o.jsxs("div", { className: "w-full min-h-10 flex items-center relative", children: [ /* @__PURE__ */ o.jsx(f, { intent: "icon", className: "absolute top-0 right-0 p-2", onClick: p, children: /* @__PURE__ */ o.jsx(x, { size: "M", children: l ? /* @__PURE__ */ o.jsx(k, { stroke: a === "dark" ? i : s }) : c && /* @__PURE__ */ o.jsx(b, { stroke: a === "dark" ? i : s }) }) }), e ] }); }; export { H as CodeBlock }; //# sourceMappingURL=index.js.map