Sha256: 088f6250cab4f6f12c93a79a212ae664303f00a612763b2f3c93cc8c40a419de
Contents?: true
Size: 1.18 KB
Versions: 14
Compression:
Stored size: 1.18 KB
Contents
import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = ['listItem', 'category', 'recommended'] filter(event) { const query = event.currentTarget.value.toLowerCase() const visibleCategories = new Set() // hide / show listItem links that match the query and note which // categories should be visible this.listItemTargets.forEach(listItemNode => { const listItemName = listItemNode.dataset.listItemValue.toLowerCase() if (listItemName.includes(query)) { listItemNode.hidden = false visibleCategories.add(listItemNode.dataset.category) } else { listItemNode.hidden = true } }) this.recommendedTargets.forEach(recommendedNode => { (query !== '' && visibleCategories.size === 0) ? recommendedNode.hidden = true : recommendedNode.hidden = false }) // hide / show category headers that have visible listItems this.categoryTargets.forEach(categoryNode => { const categoryName = categoryNode.innerHTML if (visibleCategories.has(categoryName)) { categoryNode.hidden = false } else { categoryNode.hidden = true } }) } }
Version data entries
14 entries across 14 versions & 1 rubygems