{"version":3,"file":"CopyButton-BD8dts7i.js","sources":["../../../app/javascript/components/common/clipboard/copyToClipboard.ts","../../../app/javascript/components/common/clipboard/CopyButton.tsx"],"sourcesContent":["export const copyToClipboard = async (text: string): Promise => await navigator.clipboard.writeText(text)\n","import PropTypes from 'prop-types'\nimport React, { useState } from 'react'\nimport { copyToClipboard } from './copyToClipboard'\n\ntype DoCopyAsync = (url: string) => Promise\n\nconst CopyPropTypes = {\n buttonLabel: PropTypes.node.isRequired,\n copyText: PropTypes.string.isRequired,\n className: PropTypes.string\n}\n\ntype CopyProps = PropTypes.InferProps\n\nconst delay: (t: number) => Promise = async (t: number) => await new Promise(resolve => setTimeout(resolve, t))\n\nexport const CopyButton: React.FC = ({ buttonLabel, copyText, className }) => {\n const additionalClasses = className ?? ''\n\n const [isCopying, setIsCopying] = useState(false)\n\n const currentButtonLabel = (isActive: boolean): PropTypes.ReactNodeLike => isActive ? 'COPIED!!' : buttonLabel\n\n // function structure is due to eslint recommendation:\n // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-misused-promises.md#checksvoidreturn-true\n const doCopyAsync: DoCopyAsync = async (copyText: string) => {\n const handler: () => Promise = async () => {\n await copyToClipboard(copyText)\n await delay(750)\n setIsCopying(false)\n }\n\n try {\n setIsCopying(true)\n } catch (e) {\n console.error(e)\n }\n\n handler().catch((e) => console.error(e))\n }\n\n return (\n // The onClick handler catches to avoid no-misused-promises linting error\n { doCopyAsync(copyText).catch((e) => console.error(e)) }}\n disabled={isCopying}\n >\n {currentButtonLabel(isCopying) as React.ReactNode}\n \n )\n}\n"],"names":["copyToClipboard","text","PropTypes","delay","resolve","CopyButton","buttonLabel","copyText","className","additionalClasses","isCopying","setIsCopying","useState","currentButtonLabel","isActive","doCopyAsync","handler","jsx","e"],"mappings":"6FAAO,MAAMA,EAAkB,MAAOC,GAAgC,MAAM,UAAU,UAAU,UAAUA,CAAI,ECO/FC,EAAU,KAAK,WAClBA,EAAU,OAAO,WAChBA,EAAU,OAKvB,MAAMC,EAAsC,MAAO,GAAc,MAAM,IAAI,QAAmBC,GAAA,WAAWA,EAAS,CAAC,CAAC,EAEvGC,EAAkC,CAAC,CAAE,YAAAC,EAAa,SAAAC,EAAU,UAAAC,KAAgB,CACvF,MAAMC,EAAoBD,GAAa,GAEjC,CAACE,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAK,EAE1CC,EAAsBC,GAA+CA,EAAW,WAAaR,EAI7FS,EAA2B,MAAOR,GAAqB,CAC3D,MAAMS,EAA+B,SAAY,CAC/C,MAAMhB,EAAgBO,CAAQ,EAC9B,MAAMJ,EAAM,GAAG,EACfQ,EAAa,EAAK,CACpB,EAEI,GAAA,CACFA,EAAa,EAAI,QACV,EAAG,CACV,QAAQ,MAAM,CAAC,CAAA,CAGjBK,EAAA,EAAU,MAAO,GAAM,QAAQ,MAAM,CAAC,CAAC,CACzC,EAEA,OAEEC,EAAA,IAAC,SAAA,CACC,GAAG,cACH,UAAW,UAAUR,CAAiB,GACtC,QAAS,IAAM,CAAcM,EAAAR,CAAQ,EAAE,MAAOW,GAAM,QAAQ,MAAMA,CAAC,CAAC,CAAE,EACtE,SAAUR,EAET,WAAmBA,CAAS,CAAA,CAAA,CAGnC"}