refactor: Specify copyable text during instantiation

This commit is contained in:
Susmitha Girumala committed 2020-09-30 11:07:44 -04:00
1 parent 046632ecd8
commit 5febe3cb7d
2 files changed
+7 -4

No files matched your search

+2 -3
View File
@@ -1,7 +1,7 @@
{{#if this.isClipboardLibrarySupported}}
<span
id={{this.id}}
aria-labelledby={{concat "copyable-text-" this.id}}
aria-labelledby={{this.copyableButtonId}}
class="copyable"
{{did-insert this.register}}
{{will-destroy this.destroy}}
@@ -11,11 +11,10 @@
</span>
<Rose::Button
id={{concat "copyable-text-" this.id}}
id={{this.copyableButtonId}}
class="copyable-button"
@style="ghost"
@iconOnly={{this.icon}}
data-clipboard-text={{@text}}
>{{@text}}</Rose::Button>
</span>
{{else}}
+5 -1
View File
@@ -12,8 +12,10 @@ export default class CopyableComponent extends Component {
// =attributes
id = generateComponentID();
copyableButtonId = `copyable-button-${this.id}`;
icon = 'copy-action';
@tracked text;
@tracked clipboard;
/**
@@ -58,7 +60,9 @@ export default class CopyableComponent extends Component {
@action
register() {
if(!this.clipboard) {
this.clipboard = new ClipboardJS('.copyable-button');
this.clipboard = new ClipboardJS(`#${this.copyableButtonId}`, {
text: () => this.args.text,
});
this.clipboard.on('success', bind(this, this.onCopySuccess));
}
}