Sha256: 076f3936feb6d3918c33b05956d7ff7b2cccc56e85fd4cb26ad4accc5ca15cfe

Contents?: true

Size: 817 Bytes

Versions: 6

Compression:

Stored size: 817 Bytes

Contents

// Inspired by: https://github.com/excid3/tailwindcss-stimulus-components/blob/master/src/popover.js

import { Controller } from "@hotwired/stimulus";

export default class UIToggleController extends Controller {
  connect() {}

  toggle() {
    const button = this.element.querySelector("button");
    const span = this.element.querySelector("span");
    const input = this.element.querySelector("input[type='hidden']");

    if (this.element.dataset.state == "checked") {
      input.value = "unchecked";
      button.dataset.state = "unchecked";
      span.dataset.state = "unchecked";
      this.element.dataset.state = "unchecked";
    } else {
      input.value = "checked";
      button.dataset.state = "checked";
      span.dataset.state = "checked";
      this.element.dataset.state = "checked";
    }
  }
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shadcn-ui-0.0.15 app/javascript/controllers/ui/switch_controller.js
shadcn-ui-0.0.14 app/javascript/controllers/ui/switch_controller.js
shadcn-ui-0.0.13 app/javascript/controllers/ui/switch_controller.js
shadcn-ui-0.0.12 app/javascript/controllers/ui/switch_controller.js
shadcn-ui-0.0.10 app/javascript/controllers/ui/switch_controller.js
shadcn-ui-0.0.8 app/javascript/controllers/ui/switch_controller.js