From 7e3f448bd1861f9a01b22622e022e646a3fd4449 Mon Sep 17 00:00:00 2001 From: jkusa Date: Fri, 4 Nov 2022 22:15:45 -0500 Subject: [PATCH] feat: support direct use of the clipboard modifier Introduced `data-clipboard-id` attribute instead of setting an elements `id` --- README.md | 22 ++++++++++++++++++---- addon-test-support/index.js | 2 +- addon/components/copy-button.hbs | 2 +- addon/modifiers/clipboard.js | 10 +++++++++- tests/dummy/app/templates/application.hbs | 23 +++++++++++++++++++++++ 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0f8dc27..df239dc 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ http://jkusa.github.io/ember-cli-clipboard ## Usage -### Angle Bracket Invocation +### CopyButton Component ```hbs @@ -48,7 +48,7 @@ http://jkusa.github.io/ember-cli-clipboard ``` -### Arguments +#### Arguments - `text` - string value or action that returns a string to be copied - `target` - selector string of element or action that returns an element from which to copy text @@ -59,7 +59,7 @@ http://jkusa.github.io/ember-cli-clipboard Any HTML [button attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Attributes) passed to the component will be "splatted" on the button element. The one exception to this is the `type` attribute due to this [issue](https://github.com/emberjs/ember.js/issues/18232) < Ember `3.25.x`. -### Actions +#### Actions The following clipboard.js custom events are sent as actions @@ -68,7 +68,21 @@ The following clipboard.js custom events are sent as actions More information about the clipboard.js events can be found [here](https://github.com/zenorocha/clipboard.js/#events) -## Template Helper +### Clipboard Element Modifier + +Under the hood the `` component is powered by a `{{clipboard}}` element modifier. This can be used directly as an alternative to the `` component. It has the same argument contract as the `` component except for the exclusion of the `buttonType` argument. + +```hbs + +``` + +### Template Helper The helper `is-clipboard-supported` can be used to check if [clipboard.js](http://zenorocha.github.io/clipboard.js/) is supported or not. diff --git a/addon-test-support/index.js b/addon-test-support/index.js index 159d4f1..908f3c5 100644 --- a/addon-test-support/index.js +++ b/addon-test-support/index.js @@ -47,7 +47,7 @@ export function _fireComponentAction(owner, selector, actionName) { */ function _getComponentBySelector(owner, selector = '.copy-btn') { const renderTree = Ember._captureRenderTree(owner); - const guid = document.querySelector(selector).id; + const guid = document.querySelector(selector).dataset.clipboardId; return _findComponentInstance(renderTree[0], guid); } diff --git a/addon/components/copy-button.hbs b/addon/components/copy-button.hbs index 9bcda8d..bd78a30 100644 --- a/addon/components/copy-button.hbs +++ b/addon/components/copy-button.hbs @@ -1,7 +1,7 @@ + {{! template-lint-disable block-indentation no-unbalanced-curlies}} + <button + type="button" + \{{clipboard + text="clipboard modifier" + onSuccess=this.onSuccess + }} +> + Copy Text +</button> + +

{{#if (is-clipboard-supported)}}