bitty installation snippets examples documentation q&a

snippets

copy with quick copy

  • bitty provides a b.quickCopy(el, sender, options = {}) feature.
  • It starts by grabbing the .innerHTML of the sender, storing it, the changing it to Copied.
  • The text from the el is copied (either the .value if it's available or the .innerHTML if it's not).
  • After 2 seconds the original .innerHTML is restored to the sender.
  • The feature is also debounced. Each time you click the button it'll copy the text and reset the 2 second timer before restoring the sender text.
  • Check the documentation for available options.
  • This feature is designed to cover the 80/20 happy path. The b.copy() features can be used if more controls is required.

html

<textarea data-r="copier">the quick brown fox jumps over the lazy dog.</textarea>

<button data-s="copier">Copy Text</button>

javascript

export const b = {};

export function copier(ev, sender, el) {
  b.quickCopy(el, sender);
}