@fleetbase/ember-ui
Version:
Fleetbase UI provides all the interface components, helpers, services and utilities for building a Fleetbase extension into the Console.
93 lines (80 loc) • 1.94 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;
/**
* If click to copy should be enabled.
*
* @var {Boolean}
*/
clickToCopy = false;
/**
* Setup the component
*
* @param {EngineInstance} owner
* @param {...Arguments} { column, clickToCopy, }
* @memberof ClickToRevealComponent
*/
constructor(owner, { column, clickToCopy }) {
super(...arguments);
this.clickToCopy = clickToCopy ?? false;
if (column && column.cellComponentArgs) {
this.clickToCopy = column.cellComponentArgs.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);
}
}