Sha256: b0f509e059f8fa56334ca5a60e86fc7202bcc634966521d525290d9967f52858

Contents?: true

Size: 799 Bytes

Versions: 34

Compression:

Stored size: 799 Bytes

Contents

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = [ "dependee", "dependant" ]

  connect() {
    this.#checkDependee()
  }

  check({ target }) {
    target === this.dependeeTarget ? this.#checkDependants() : this.#checkDependee()
  }

  #checkDependants() {
    this.dependantTargets.forEach(e => e.checked = this.dependeeTarget.checked)
  }

  #checkDependee() {
    this.dependeeTarget.checked = this.#allChecked
    this.dependeeTarget.indeterminate = this.#indeterminate
  }

  get #indeterminate() {
    return this.#atLeastOneChecked && !this.#allChecked;
  }

  get #atLeastOneChecked() {
    return this.dependantTargets.some(e => e.checked)
  }

  get #allChecked() {
    return this.dependantTargets.every(e => e.checked)
  }
}

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
css-zero-0.0.75 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.74 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.73 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.72 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.71 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.70 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.69 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.68 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.67 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.66 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.65 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.64 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.63 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.62 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.61 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.60 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.59 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.58 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.57 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js
css-zero-0.0.56 lib/generators/css_zero/add/templates/app/javascript/controllers/check_all_controller.js