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

Version Path
ariadne_view_components-0.0.88 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.87 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.9 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.8 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.7 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.6 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.5 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.4 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.3 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.2 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86.1 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.86 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.85 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.84 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.83.3 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.83.2 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.83.1 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.83 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.82 app/components/ariadne/ui/flash/component.ts
ariadne_view_components-0.0.81 app/components/ariadne/ui/flash/component.ts