Sha256: 2e7d1bce7a30c38cc77681f8ca7f2ef1e303126bb174c667b6ef57c67e6c4557

Contents?: true

Size: 1.97 KB

Versions: 24

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 (const 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).textContent?.toLowerCase().includes(this.keywordValue.toLowerCase()) ?? false
  }

  getState() {
    return this.keywordValue
  }

  outletUpdate = this.change
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.59-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.59-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.59-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.59-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.59-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.59 app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.58-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.58-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.58-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.58-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.58 app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.58-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.57-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.57-aarch64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.57-x86_64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.57-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.57-x64-mingw-ucrt app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.57 app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.55-x86_64-linux app/components/ariadne/string_match_controller/string_match_controller.ts
ariadne_view_components-0.0.55-arm64-darwin app/components/ariadne/string_match_controller/string_match_controller.ts