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

Version Path
ariadne_view_components-0.0.51-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.51-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.51-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.51-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.51 app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.51-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.50 app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.50-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.50-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.50-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.50-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.50-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.49-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.49-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.49-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.49-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.49-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.49 app/components/ariadne/string_match_controller/string_match_controller.ts