@myorders/ember-ui
Version:
Myorders UI provides all the interface components, helpers, services and utilities for building a Myorders extension into the Console.
80 lines (69 loc) • 1.6 kB
JavaScript
import ClickToCopyComponent from './click-to-copy';
import { tracked } from '@glimmer/tracking';
import { action, computed } from '@ember/object';
import { later } from '@ember/runloop';
export default class ClickToRevealComponent extends ClickToCopyComponent {
/**
* The visiblity state of the value
*
* @var {Boolean}
*/
isVisible = false;
/**
* The loading state of the reveal process
*
* @var {Boolean}
*/
isLoading = false;
/**
* The loading timing
*
* @var {Integer}
*/
timeout = 600;
/**
* The loading state of the reveal process
*
* @var {Boolean}
*/
get clickToCopy() {
const { clickToCopy } = this.args;
return clickToCopy ?? false;
}
/**
* The loading state of the reveal process
*
* @var {Boolean}
*/
get canClickToCopy() {
return this.clickToCopy && this.isVisible;
}
/**
* Reveals the hidden text
*
* @void
*/
reveal() {
this.isLoading = true;
later(
this,
() => {
this.isLoading = false;
this.isVisible = true;
},
600
);
}
/**
* Copies the hidden text
*
* @param {String} value
* @void
*/
copy(value) {
if (!this.canClickToCopy) {
return;
}
return this.copyToClipboard(value);
}
}