copy button
![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)
A button to copy some text to the system clipboard, made with webcomponents, with no dependencies.
install
npm i -S @bicycle-codes/copy-button
demonstration
See bicycle-codes.github.io/copy-button for an example.
globals
This looks at css variables --success-color
and --copy-color
which determines the color of the success checkmark and copy icon.
use
Include this package, then use the tag <copy-button>
in HTML.
Example without a build step
Copy the files
Copy files so they are accessible by your web server.
JS
cp ./node_modules/@bicycle-codes/copy-button/dist/index.min.js public/copy-button.js
CSS
cp ./node_modules/@bicycle-codes/copy-button/dist/style.min.css public/copy-button.css
Use in HTML
<head>
<link rel="stylesheet" href="./copy-button.css">
</head>
<body>
<copy-button payload="example text"></copy-button>
<script src="/copy-button.js" type="module"></script>
</body>
With a JS build step
We expose several import options
import '@bicycle-codes/copy-button'
import '@bicycle-codes/copy-button/min'
import '@bicycle-codes/copy-button/style.css'
import '@bicycle-codes/copy-button/min/style.css'
In vite
, for example, import like this
import '@bicycle-codes/copy-button'
import '@bicycle-codes/copy-button/style.css'
import '@bicycle-codes//copy-button/min/style.css'
CSS
Override the variables --success-color
and --copy-color
to customize the color.
.copy-button {
--success-color: green;
--copy-color: blue;
}
Create a button like this
![screenshot of the button, pre-click](https://github.com/bicycle-codes/copy-button/raw/HEAD/image.png)
![screenshot of the button, post-click](https://github.com/bicycle-codes/copy-button/raw/HEAD/image-1.png)