Skip to content
CoCreateJSPublic

About

A simple clipboard component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

CoCreate-clipboard

Copies element values to the clipboard. Easily configured using HTML5 attributes and/or JavaScript API. Take it for a spin in our playground!

min file size in bytes gzip file size in bytes brotlifile size in bytes GitHub latest release GitHub GitHub

CoCreate-clipboard

For a complete guide and working demo refer to the doumentation

Declarative controls

Use clipboard on an element to copy its own value, or clipboard-query to select the source. Either attribute initializes a click listener, including on dynamically added elements.

<button clipboard>Copy this text</button>
<button clipboard-query="#message">Copy message</button>
<textarea id="message">Hello</textarea>

The trigger's clipboard attribute reflects copying, copied, or error. These are output states: changing the value does not initiate a copy. Each click copies again, including when the attribute already contains a state. The state remains until the next copy; no timer or CSS is required.

[clipboard] .copy-success { display: none; }
[clipboard="copied"] .copy-success { display: inline; }
[clipboard="copied"] .copy-icon { display: none; }

Successful copies emit the existing clipboarded event with detail.clipboardItems. Failures emit clipboard-error with detail.error. Both events bubble, and state is updated before the event fires. Elements with actions defer to the Actions chain; use actions="clipboard" with either clipboard attribute. Disabled controls and controls with aria-disabled="true" do not copy on click.

CDN

<script src="https://cdn.CoCreateJS.com/clipboard/latest/CoCreate-clipboard.min.js"></script>
<script src="https://cdn.CoCreateJS.com/clipboard/latest/CoCreate-clipboard.min.css"></script>

NPM

$ npm i @cocreate/clipboard

yarn

$ yarn install @cocreate/clipboard

Table of Contents

Announcements

All updates to this library are documented in our CHANGELOG and releases. You may also subscribe to email for releases and breaking changes.

Roadmap

If you are interested in the future direction of this project, please take a look at our open issues and pull requests. We would love to hear your feedback.

About

CoCreate-clipboard is guided and supported by the CoCreate Developer Experience Team.

Please Email the Developer Experience Team here in case of any queries.

CoCreate-clipboard is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC.

How to Contribute

We encourage contribution to our libraries (you might even score some nifty swag), please see our CONTRIBUTING guide for details.

We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create issues and pull requests or merely upvote or comment on existing issues or pull requests.

We appreciate your continued support, thank you!

License

The MIT License (MIT)

About

A simple clipboard component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages