UNPKG

copy-to-clipboard-react-button

Version:

Simple CopyToClipboard React Based Button Component

505 lines (502 loc) 17.6 kB
import ke, { memo as be, useState as Re, useLayoutEffect as Se } from "react"; var S = { exports: {} }, j = {}; /** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var de; function Oe() { if (de) return j; de = 1; var s = Symbol.for("react.transitional.element"), b = Symbol.for("react.fragment"); function m(x, i, c) { var v = null; if (c !== void 0 && (v = "" + c), i.key !== void 0 && (v = "" + i.key), "key" in i) { c = {}; for (var y in i) y !== "key" && (c[y] = i[y]); } else c = i; return i = c.ref, { $$typeof: s, type: x, key: v, ref: i !== void 0 ? i : null, props: c }; } return j.Fragment = b, j.jsx = m, j.jsxs = m, j; } var k = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var ve; function Ae() { return ve || (ve = 1, process.env.NODE_ENV !== "production" && function() { function s(e) { if (e == null) return null; if (typeof e == "function") return e.$$typeof === we ? null : e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case Y: return "Fragment"; case Te: return "Portal"; case I: return "Profiler"; case L: return "StrictMode"; case $: return "Suspense"; case W: return "SuspenseList"; } if (typeof e == "object") switch (typeof e.tag == "number" && console.error( "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue." ), e.$$typeof) { case Q: return (e.displayName || "Context") + ".Provider"; case Z: return (e._context.displayName || "Context") + ".Consumer"; case M: var r = e.render; return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e; case U: return r = e.displayName || null, r !== null ? r : s(e.type) || "Memo"; case z: r = e._payload, e = e._init; try { return s(e(r)); } catch { } } return null; } function b(e) { return "" + e; } function m(e) { try { b(e); var r = !1; } catch { r = !0; } if (r) { r = console; var t = r.error, n = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t.call( r, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", n ), b(e); } } function x() { } function i() { if (w === 0) { ee = console.log, re = console.info, te = console.warn, oe = console.error, ne = console.group, ae = console.groupCollapsed, ue = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: x, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } w++; } function c() { if (w--, w === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: p({}, e, { value: ee }), info: p({}, e, { value: re }), warn: p({}, e, { value: te }), error: p({}, e, { value: oe }), group: p({}, e, { value: ne }), groupCollapsed: p({}, e, { value: ae }), groupEnd: p({}, e, { value: ue }) }); } 0 > w && console.error( "disabledDepth fell below zero. This is a bug in React. Please file an issue." ); } function v(e) { if (J === void 0) try { throw Error(); } catch (t) { var r = t.stack.trim().match(/\n( *(at )?)/); J = r && r[1] || "", le = -1 < t.stack.indexOf(` at`) ? " (<anonymous>)" : -1 < t.stack.indexOf("@") ? "@unknown:0:0" : ""; } return ` ` + J + e + le; } function y(e, r) { if (!e || B) return ""; var t = V.get(e); if (t !== void 0) return t; B = !0, t = Error.prepareStackTrace, Error.prepareStackTrace = void 0; var n = null; n = g.H, g.H = null, i(); try { var u = { DetermineComponentFrameRoot: function() { try { if (r) { var E = function() { throw Error(); }; if (Object.defineProperty(E.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(E, []); } catch (d) { var R = d; } Reflect.construct(e, [], E); } else { try { E.call(); } catch (d) { R = d; } e.call(E.prototype); } } else { try { throw Error(); } catch (d) { R = d; } (E = e()) && typeof E.catch == "function" && E.catch(function() { }); } } catch (d) { if (d && R && typeof d.stack == "string") return [d.stack, R.stack]; } return [null, null]; } }; u.DetermineComponentFrameRoot.displayName = "DetermineComponentFrameRoot"; var a = Object.getOwnPropertyDescriptor( u.DetermineComponentFrameRoot, "name" ); a && a.configurable && Object.defineProperty( u.DetermineComponentFrameRoot, "name", { value: "DetermineComponentFrameRoot" } ); var o = u.DetermineComponentFrameRoot(), f = o[0], T = o[1]; if (f && T) { var l = f.split(` `), h = T.split(` `); for (o = a = 0; a < l.length && !l[a].includes( "DetermineComponentFrameRoot" ); ) a++; for (; o < h.length && !h[o].includes( "DetermineComponentFrameRoot" ); ) o++; if (a === l.length || o === h.length) for (a = l.length - 1, o = h.length - 1; 1 <= a && 0 <= o && l[a] !== h[o]; ) o--; for (; 1 <= a && 0 <= o; a--, o--) if (l[a] !== h[o]) { if (a !== 1 || o !== 1) do if (a--, o--, 0 > o || l[a] !== h[o]) { var C = ` ` + l[a].replace( " at new ", " at " ); return e.displayName && C.includes("<anonymous>") && (C = C.replace("<anonymous>", e.displayName)), typeof e == "function" && V.set(e, C), C; } while (1 <= a && 0 <= o); break; } } } finally { B = !1, g.H = n, c(), Error.prepareStackTrace = t; } return l = (l = e ? e.displayName || e.name : "") ? v(l) : "", typeof e == "function" && V.set(e, l), l; } function O(e) { if (e == null) return ""; if (typeof e == "function") { var r = e.prototype; return y( e, !(!r || !r.isReactComponent) ); } if (typeof e == "string") return v(e); switch (e) { case $: return v("Suspense"); case W: return v("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case M: return e = y(e.render, !1), e; case U: return O(e.type); case z: r = e._payload, e = e._init; try { return O(e(r)); } catch { } } return ""; } function A() { var e = g.A; return e === null ? null : e.getOwner(); } function me(e) { if (D.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function ge(e, r) { function t() { se || (se = !0, console.error( "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", r )); } t.isReactWarning = !0, Object.defineProperty(e, "key", { get: t, configurable: !0 }); } function pe() { var e = s(this.type); return ie[e] || (ie[e] = !0, console.error( "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release." )), e = this.props.ref, e !== void 0 ? e : null; } function he(e, r, t, n, u, a) { return t = a.ref, e = { $$typeof: P, type: e, key: r, props: a, _owner: u }, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", { enumerable: !1, get: pe }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: 0 }), Object.defineProperty(e, "_debugInfo", { configurable: !1, enumerable: !1, writable: !0, value: null }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e; } function H(e, r, t, n, u, a) { if (typeof e == "string" || typeof e == "function" || e === Y || e === I || e === L || e === $ || e === W || e === _e || typeof e == "object" && e !== null && (e.$$typeof === z || e.$$typeof === U || e.$$typeof === Q || e.$$typeof === Z || e.$$typeof === M || e.$$typeof === Ce || e.getModuleId !== void 0)) { var o = r.children; if (o !== void 0) if (n) if (q(o)) { for (n = 0; n < o.length; n++) X(o[n], e); Object.freeze && Object.freeze(o); } else console.error( "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead." ); else X(o, e); } else o = "", (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (o += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."), e === null ? n = "null" : q(e) ? n = "array" : e !== void 0 && e.$$typeof === P ? (n = "<" + (s(e.type) || "Unknown") + " />", o = " Did you accidentally export a JSX literal instead of a component?") : n = typeof e, console.error( "React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", n, o ); if (D.call(r, "key")) { o = s(e); var f = Object.keys(r).filter(function(l) { return l !== "key"; }); n = 0 < f.length ? "{key: someKey, " + f.join(": ..., ") + ": ...}" : "{key: someKey}", ce[o + n] || (f = 0 < f.length ? "{" + f.join(": ..., ") + ": ...}" : "{}", console.error( `A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, n, o, f, o ), ce[o + n] = !0); } if (o = null, t !== void 0 && (m(t), o = "" + t), me(r) && (m(r.key), o = "" + r.key), "key" in r) { t = {}; for (var T in r) T !== "key" && (t[T] = r[T]); } else t = r; return o && ge( t, typeof e == "function" ? e.displayName || e.name || "Unknown" : e ), he(e, o, a, u, A(), t); } function X(e, r) { if (typeof e == "object" && e && e.$$typeof !== je) { if (q(e)) for (var t = 0; t < e.length; t++) { var n = e[t]; N(n) && F(n, r); } else if (N(e)) e._store && (e._store.validated = 1); else if (e === null || typeof e != "object" ? t = null : (t = K && e[K] || e["@@iterator"], t = typeof t == "function" ? t : null), typeof t == "function" && t !== e.entries && (t = t.call(e), t !== e)) for (; !(e = t.next()).done; ) N(e.value) && F(e.value, r); } } function N(e) { return typeof e == "object" && e !== null && e.$$typeof === P; } function F(e, r) { if (e._store && !e._store.validated && e.key == null && (e._store.validated = 1, r = xe(r), !fe[r])) { fe[r] = !0; var t = ""; e && e._owner != null && e._owner !== A() && (t = null, typeof e._owner.tag == "number" ? t = s(e._owner.type) : typeof e._owner.name == "string" && (t = e._owner.name), t = " It was passed a child from " + t + "."); var n = g.getCurrentStack; g.getCurrentStack = function() { var u = O(e.type); return n && (u += n() || ""), u; }, console.error( 'Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.', r, t ), g.getCurrentStack = n; } } function xe(e) { var r = "", t = A(); return t && (t = s(t.type)) && (r = ` Check the render method of \`` + t + "`."), r || (e = s(e)) && (r = ` Check the top-level render call using <` + e + ">."), r; } var ye = ke, P = Symbol.for("react.transitional.element"), Te = Symbol.for("react.portal"), Y = Symbol.for("react.fragment"), L = Symbol.for("react.strict_mode"), I = Symbol.for("react.profiler"), Z = Symbol.for("react.consumer"), Q = Symbol.for("react.context"), M = Symbol.for("react.forward_ref"), $ = Symbol.for("react.suspense"), W = Symbol.for("react.suspense_list"), U = Symbol.for("react.memo"), z = Symbol.for("react.lazy"), _e = Symbol.for("react.offscreen"), K = Symbol.iterator, we = Symbol.for("react.client.reference"), g = ye.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, D = Object.prototype.hasOwnProperty, p = Object.assign, Ce = Symbol.for("react.client.reference"), q = Array.isArray, w = 0, ee, re, te, oe, ne, ae, ue; x.__reactDisabledLog = !0; var J, le, B = !1, V = new (typeof WeakMap == "function" ? WeakMap : Map)(), je = Symbol.for("react.client.reference"), se, ie = {}, ce = {}, fe = {}; k.Fragment = Y, k.jsx = function(e, r, t, n, u) { return H(e, r, t, !1, n, u); }, k.jsxs = function(e, r, t, n, u) { return H(e, r, t, !0, n, u); }; }()), k; } var Ee; function Ne() { return Ee || (Ee = 1, process.env.NODE_ENV === "production" ? S.exports = Oe() : S.exports = Ae()), S.exports; } var _ = Ne(); function Pe() { return /* @__PURE__ */ _.jsxs( "svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", className: "icon icon-tabler icons-tabler-outline icon-tabler-copy", "data-testid": "copy-paste-icon", children: [ /* @__PURE__ */ _.jsx( "path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" } ), /* @__PURE__ */ _.jsx("path", { d: "M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z" }), /* @__PURE__ */ _.jsx("path", { d: "M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1" }) ] } ); } const Ye = be(Pe); function G(s = "#000") { document.documentElement.style.setProperty("--button-color", s); } function Me({ text: s, defaultColor: b = "inherit", copiedColor: m = "#00FF00" }) { const [x, i] = Re(!1); Se(() => { G(b); }, []); function c() { i(!0), G(m), navigator.clipboard.writeText(s), setTimeout(() => { i(!1), G(b); }, 1e3); } return /* @__PURE__ */ _.jsx( "button", { onClick: c, disabled: x, "data-testid": "copy-paste-button", children: /* @__PURE__ */ _.jsx(Ye, {}) } ); } const We = be(Me); export { We as CopyToClipboard };