open-consul/ui/packages/consul-ui/app/components/copy-button/index.js

27 lines
749 B
JavaScript
Raw Normal View History

import Component from '@ember/component';
import { inject as service } from '@ember/service';
2020-06-17 09:25:54 +00:00
import chart from './chart.xstate';
export default Component.extend({
clipboard: service('clipboard/os'),
dom: service('dom'),
tagName: '',
init: function() {
this._super(...arguments);
2020-06-17 09:25:54 +00:00
this.chart = chart;
this.guid = this.dom.guid(this);
this._listeners = this.dom.listeners();
},
willDestroyElement: function() {
this._super(...arguments);
this._listeners.remove();
},
didInsertElement: function() {
this._super(...arguments);
2020-06-17 09:25:54 +00:00
this._listeners.add(this.clipboard.execute(`#${this.guid} button`), {
success: () => this.dispatch('SUCCESS'),
error: () => this.dispatch('ERROR'),
});
},
});