Sha256: c3511c336d1cfad653744af89e2bca36a2c27970969c94b37020148b7a9d9c4a
Contents?: true
Size: 1.96 KB
Versions: 18
Compression:
Stored size: 1.96 KB
Contents
import {TOutletChangeData} from '../outlet_manager_controller/outlet_manager_controller' import SyncedBooleanAttributesController from '../synced_boolean_attributes_controller/synced_boolean_attributes_controller' export interface StringMatchOutlet extends SyncedBooleanAttributesController<string> { change: (event: Event, updateTo?: TOutletChangeData<string>) => void } export default class StringMatchController extends SyncedBooleanAttributesController<string> implements StringMatchOutlet { static outlets = SyncedBooleanAttributesController.outlets static targets = ['match', 'empty'] static values = { ...SyncedBooleanAttributesController.values, keyword: String, } declare readonly matchTargets: Array<HTMLElement> declare readonly hasMatchTarget: boolean declare readonly emptyTarget: Element declare readonly hasEmptyTarget: boolean declare keywordValue: string change(event: Event, updateTo: TOutletChangeData<string> = {}) { const value = updateTo.data ?? (event.currentTarget as HTMLInputElement).value this.keywordValue = value this.#compareKeywordToTargets() this.sendToOutlets(event, {...updateTo, data: this.keywordValue}) } #compareKeywordToTargets() { if (this.hasMatchTarget) { let foundMatch = false for (let index in this.matchTargets) { const target = this.matchTargets[index] const value = this.getValueForElement(target) this.updateAttributesForElement(target, value) if (value) { foundMatch = true } } if (this.hasEmptyTarget) { this.emptyTarget.setAttribute('aria-hidden', String(foundMatch)) } } } getElementsToSync(): Element[] | null | undefined { return this.matchTargets } getValueForElement(element: Element) { return (element as HTMLElement).innerText?.toLowerCase().includes(this.keywordValue.toLowerCase()) ?? false } getState() { return this.keywordValue } outletUpdate = this.change }
Version data entries
18 entries across 18 versions & 1 rubygems