Sha256: b94d7ab8d9e7e7c697c2930174d6ce62ff56b361763d6aa2418d7f7e925a9c45

Contents?: true

Size: 984 Bytes

Versions: 2

Compression:

Stored size: 984 Bytes

Contents

import PbEnhancedElement from '../pb_enhanced_element'

export default class PbFixedConfirmationToast extends PbEnhancedElement {
  static get selector() {
    return '[class*="pb_fixed_confirmation_toast_kit"]'
  }

  connect() {
    this.self = this.element
    this.autoCloseToast(this.self)

    if (this.self.classList.contains('remove_toast')) {
      this.self.addEventListener('click', () => {
        this.removeToast(this.self)
      })
    }
  }

  removeToast(elem) {
    elem.parentNode.removeChild(elem)
  }

  autoCloseToast(element) {
    const classListValues = element.classList.value
    const hasAutoCloseClass = classListValues.includes('auto_close')

    if (hasAutoCloseClass) {
      const classList = classListValues.split(' ')
      const autoCloseValue = classList[classList.length - 1].split('_')[2]
      const autoCloseIntValue = parseInt(autoCloseValue)

      setTimeout(() => {
        this.removeToast(element)
      }, autoCloseIntValue)
    }
  }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
playbook_ui-14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5757 app/pb_kits/playbook/pb_fixed_confirmation_toast/index.js
playbook_ui-14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5754 app/pb_kits/playbook/pb_fixed_confirmation_toast/index.js