Sha256: b11275c25008747adc186cbaa329c75bb37ee63b1886b3c8196e989e430cf3ec

Contents?: true

Size: 581 Bytes

Versions: 10

Compression:

Stored size: 581 Bytes

Contents

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

export default class UIFilter extends Controller {
  static targets = ["source", "item"];

  connect() {}

  filter(event) {
    let lowerCaseFilterTerm = this.sourceTarget.value.toLowerCase();
    let regex = new RegExp("^" + lowerCaseFilterTerm);
    if (this.hasItemTarget) {
      this.itemTargets.forEach((el, i) => {
        let filterableKey = el.innerText.toLowerCase();

        // Check for consecutive characters match using regex
        el.classList.toggle("hidden", !regex.test(filterableKey));
      });
    }
  }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shadcn-ui-0.0.15 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.14 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.13 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.12 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.10 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.8 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.5 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.4 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.3 app/javascript/controllers/ui/filter_controller.js
shadcn-ui-0.0.2 app/javascript/controllers/ui/filter_controller.js