Websites/app/javascript/controllers/notice.ts

24 lines
548 B
TypeScript
Raw Normal View History

2024-05-03 03:04:43 +00:00
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static override targets = ["notice"];
declare noticeTarget: HTMLElement;
timeout: number | undefined;
// automatically close
override connect() {
this.timeout = setTimeout(() => this._close(), 3500);
}
_close() {
$(this.noticeTarget).fadeOut("fast");
}
2024-05-03 03:04:43 +00:00
close(event: KeyboardEvent) {
if (this.timeout) {
clearTimeout(this.timeout);
}
2024-05-03 03:04:43 +00:00
event.preventDefault();
}
}