2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2023-05-12 13:54:13 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
2019-07-15 17:14:32 +00:00
|
|
|
import { task, timeout } from 'ember-concurrency';
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class CopyButton extends Component {
|
2023-05-12 13:54:13 +00:00
|
|
|
@tracked state = null;
|
|
|
|
|
|
|
|
get text() {
|
|
|
|
if (typeof this.args.clipboardText === 'function')
|
|
|
|
return this.args.clipboardText;
|
|
|
|
if (typeof this.args.clipboardText === 'string')
|
|
|
|
return this.args.clipboardText;
|
|
|
|
|
|
|
|
return String(this.args.clipboardText);
|
|
|
|
}
|
2019-07-15 17:14:32 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@(task(function* () {
|
2023-05-12 13:54:13 +00:00
|
|
|
this.state = 'success';
|
2019-07-15 17:14:32 +00:00
|
|
|
|
|
|
|
yield timeout(2000);
|
2023-05-12 13:54:13 +00:00
|
|
|
this.state = null;
|
2020-06-10 13:49:16 +00:00
|
|
|
}).restartable())
|
|
|
|
indicateSuccess;
|
|
|
|
}
|