Sha256: 6018500aa683e3118f03e88b353ad2b7edf83c1b061326f5c86b5480a3bab3bb
Contents?: true
Size: 1.36 KB
Versions: 25
Compression:
Stored size: 1.36 KB
Contents
import {Controller} from '@hotwired/stimulus' // @ts-expect-error: this is untyped https://github.com/mmccall10/el-transition/issues/11 import {enter, leave} from 'el-transition' export default class FlashController extends Controller { static classes = ['ariadne-hidden'] static values = { timer: { default: 4000, type: Number, }, } declare readonly hasHiddenClass: boolean declare readonly hasTimerValue: boolean declare readonly hiddenClass: string declare readonly hiddenClasses: string[] declare timerValue: number async connect(): Promise<void> { // Start animation as soon as it connects to the dom await this.show() const noop = (): void => {} // Set a timer for it to be removed from the dom automatically setTimeout(() => { this.hide().then(noop).catch(noop) }, this.timerValue) } async disconnect(): Promise<void> { await this.hide() } async hide(): Promise<void> { await leave(this.element) if (this.hasHiddenClass) { this.element.classList.add(this.hiddenClass) } else { this.element.classList.add('hidden') } this.element.remove() } async show(): Promise<void> { if (this.hasHiddenClass) { this.element.classList.remove(this.hiddenClass) } else { this.element.classList.remove('hidden') } await enter(this.element) } }
Version data entries
25 entries across 25 versions & 1 rubygems