Sha256: 1228ed8b7b9bba03b2c3ce478cec2410ff3e3ee59922837009fcc8719655d9f2

Contents?: true

Size: 1.1 KB

Versions: 192

Compression:

Stored size: 1.1 KB

Contents

import {Controller} from '@hotwired/stimulus'

export default class TabNavComponent extends Controller {
  static targets = ['tab']

  declare readonly tabTargets: [HTMLAnchorElement]

  // keep in synch with tab_nav_component
  SELECTED_CLASSES = ['ariadne-border-slate-500', 'ariadne-text-slate-600']
  UNSELECTED_CLASSES = ['ariadne-text-gray-500', 'hover:ariadne-text-gray-700', 'hover:ariadne-border-gray-300']

  connect() {
    for (const tab of this.tabTargets) {
      if (tab.hasAttribute('aria-current')) {
        tab.classList.add(...this.SELECTED_CLASSES)
        tab.classList.remove(...this.UNSELECTED_CLASSES)
      }
    }
  }

  toggle(event: Event) {
    for (const tab of this.tabTargets) {
      if (tab === event.target) {
        tab.setAttribute('aria-current', 'page')
        tab.classList.add(...this.SELECTED_CLASSES)
        tab.classList.remove(...this.UNSELECTED_CLASSES)
      } else if (tab.hasAttribute('aria-current')) {
        tab.removeAttribute('aria-current')
        tab.classList.add(...this.UNSELECTED_CLASSES)
        tab.classList.remove(...this.SELECTED_CLASSES)
      }
    }
  }
}

Version data entries

192 entries across 192 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.48-x64-mingw-ucrt app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.48-aarch64-linux app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.48-x86_64-darwin app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.48-arm64-darwin app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.48 app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.48-x86_64-linux app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.47-x86_64-darwin app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.47-x86_64-linux app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.47-arm64-darwin app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.47-aarch64-linux app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.47-x64-mingw-ucrt app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.47 app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.46-aarch64-linux app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.46-x64-mingw-ucrt app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.46 app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.46-x86_64-darwin app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.46-x86_64-linux app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.46-arm64-darwin app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.45-x64-mingw-ucrt app/components/ariadne/tab_nav_component/tab-nav-component.ts
ariadne_view_components-0.0.45 app/components/ariadne/tab_nav_component/tab-nav-component.ts