Sha256: b90d573bcfedfb1834f54a6a017a8459f4c3076811763326888fb6aa79ead960

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

import { Controller } from '@hotwired/stimulus';
export default class TabNavComponent extends Controller {
    constructor() {
        super(...arguments);
        // keep in synch with tab_nav_component
        this.SELECTED_CLASSES = ['ariadne-border-indigo-500', 'ariadne-text-indigo-600'];
        this.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) {
        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);
            }
        }
    }
}
TabNavComponent.targets = ['tab'];

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.19 app/components/ariadne/tab-nav-component.js
ariadne_view_components-0.0.17 app/components/ariadne/tab-nav-component.js
ariadne_view_components-0.0.16 app/components/ariadne/tab-nav-component.js
ariadne_view_components-0.0.15 app/components/ariadne/tab-nav-component.js