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.4.1 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.4.0 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.25 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.24 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.23 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.22 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.21 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.20 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.19 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.18 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.17 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.16 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.15 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.14 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.13 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.12 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.11 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.10 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.9 app/javascript/controllers/text_toggle_controller.js
bullet_train-1.3.8 app/javascript/controllers/text_toggle_controller.js