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

30 lines
704 B
JavaScript
Raw Normal View History

2020-11-30 16:52:13 +00:00
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
2020-11-30 16:52:13 +00:00
import { action } from '@ember/object';
2020-06-17 09:25:54 +00:00
import chart from './chart.xstate';
2020-11-30 16:52:13 +00:00
export default class CopyButton extends Component {
@service('clipboard/os') clipboard;
@service('dom') dom;
constructor() {
super(...arguments);
2020-06-17 09:25:54 +00:00
this.chart = chart;
this.guid = this.dom.guid(this);
this._listeners = this.dom.listeners();
2020-11-30 16:52:13 +00:00
}
@action
connect() {
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'),
});
2020-11-30 16:52:13 +00:00
}
@action
disconnect() {
this._listeners.remove();
}
}