Sha256: 1980f52c0929dbf11232da55e6b6544f2b0e89a2af70d953eb31337700d9ec7e

Contents?: true

Size: 1.97 KB

Versions: 18

Compression:

Stored size: 1.97 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.54-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.54-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.54 app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.54-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.54-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.54-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.53-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.53-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.53 app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.53-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.53-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.53-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.52-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.52-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.52-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.52-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.52 app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.52-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts