Sha256: 5c4004c701e294799e6f9c15691af973bad036453b048b9ebc96724de3366b2b

Contents?: true

Size: 743 Bytes

Versions: 147

Compression:

Stored size: 743 Bytes

Contents

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static values = {
    label: String,
    labelAlternate: String,
    useAlternate: Boolean,
  }

  connect() {
    this.updateLabel()
  }

  toggle(event) {
    if (undefined !== event?.detail?.useAlternate) {
      this.useAlternateValue = event.detail.useAlternate
    } else {
      this.useAlternateValue = !this.useAlternateValue
    }
  }

  useAlternateValueChanged() {
    this.updateLabel()
  }

  updateLabel() {
    if (!this.hasLabelValue || !this.hasLabelAlternateValue || !this.hasUseAlternateValue) {
      return
    }

    this.element.textContent = this.useAlternateValue === true ? this.labelAlternateValue : this.labelValue
  }
}

Version data entries

147 entries across 147 versions & 1 rubygems

Version Path
bullet_train-1.1.5 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.1.4 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.1.3 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.1.2 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.1.1 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.1.0 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.0.99 app/javascript/controllers/text_toggle_controller.js