feat(clipboard): can temporary hide for nicer animation
This commit is contained in:
parent
e12c663d21
commit
d4322bf947
1 changed files with 17 additions and 5 deletions
|
@ -4,11 +4,13 @@ const SUCCESS_MESSAGE_TIMEOUT = 1000;
|
||||||
|
|
||||||
export class ClipboardController extends Controller {
|
export class ClipboardController extends Controller {
|
||||||
static values = { text: String };
|
static values = { text: String };
|
||||||
static targets = ['success'];
|
static targets = ['success', 'toHide'];
|
||||||
|
|
||||||
declare readonly textValue: string;
|
declare readonly textValue: string;
|
||||||
declare readonly successTarget: HTMLElement;
|
declare readonly successTarget: HTMLElement;
|
||||||
|
declare readonly toHideTarget: HTMLElement;
|
||||||
declare readonly hasSuccessTarget: boolean;
|
declare readonly hasSuccessTarget: boolean;
|
||||||
|
declare readonly hasToHideTarget: boolean;
|
||||||
|
|
||||||
#timer?: ReturnType<typeof setTimeout>;
|
#timer?: ReturnType<typeof setTimeout>;
|
||||||
|
|
||||||
|
@ -23,12 +25,22 @@ export class ClipboardController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
private displayCopyConfirmation() {
|
private displayCopyConfirmation() {
|
||||||
|
if (this.hasToHideTarget) {
|
||||||
|
this.toHideTarget.classList.add('hidden');
|
||||||
|
}
|
||||||
if (this.hasSuccessTarget) {
|
if (this.hasSuccessTarget) {
|
||||||
this.successTarget.classList.remove('hidden');
|
this.successTarget.classList.remove('hidden');
|
||||||
clearTimeout(this.#timer);
|
|
||||||
this.#timer = setTimeout(() => {
|
|
||||||
this.successTarget.classList.add('hidden');
|
|
||||||
}, SUCCESS_MESSAGE_TIMEOUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearTimeout(this.#timer);
|
||||||
|
|
||||||
|
this.#timer = setTimeout(() => {
|
||||||
|
if (this.hasSuccessTarget) {
|
||||||
|
this.successTarget.classList.add('hidden');
|
||||||
|
}
|
||||||
|
if (this.hasToHideTarget) {
|
||||||
|
this.toHideTarget.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
}, SUCCESS_MESSAGE_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue