Sha256: 069c61b08a7df11d5a012f5214be8bd288f1e5d5fa7fe4085fc45890deea777a

Contents?: true

Size: 1.11 KB

Versions: 78

Compression:

Stored size: 1.11 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-indigo-500', 'ariadne-text-indigo-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

78 entries across 78 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.24 app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.24-x86_64-linux app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.24-x86_64-darwin app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.24-x64-mingw32 app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.24-x64-mingw-ucrt app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.24-arm64-darwin app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.24-aarch64-linux app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.23 app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.23-x86_64-linux app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.23-x86_64-darwin app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.23-x64-mingw32 app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.23-x64-mingw-ucrt app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.23-arm64-darwin app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.23-aarch64-linux app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.22 app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.22-x86_64-linux app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.22-x86_64-darwin app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.22-x64-mingw32 app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.22-x64-mingw-ucrt app/components/ariadne/tab-nav-component.ts
ariadne_view_components-0.0.22-arm64-darwin app/components/ariadne/tab-nav-component.ts