npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@haztivity/hz-tabs

v0.7.0

Published

Tabs resource

Downloads

9

Readme

hz-tabs

hz-tabs allows to create tabs as resources with all the advatages of an haztivity resource.
hz-tabs uses jquery ui tabs under the hood.

Install

NPM

npm i --save @haztivity/hz-tabs

Dependencies

  • JQuery
  • JQuery UI tabs
  • @haztivity/core

Usage

  1. Import @haztivity/hz-tabs
  2. Add HzTabsResource to the page
  3. Create the tabs and set data-hz-resource="HzTabs"

Ts

import {PageFactory, Page, PageController, PageRegister} from "@haztivity/core";
import template from "./page.pug";
import {HzTabsResource} from "@haztivity/hz-tabs";
export let page: PageRegister = PageFactory.createPage(
  {
      name: "myPage",
      resources: [
          HzTabsResource
      ],
      template: template
  }
);
Pug
div(data-hz-resource="HzTabs")
  ul
      li
          a(href='#tabs-1') Tab 1
      li
          a(href='#tabs-2') Tab 2
  div#tabs-1
      p Tab 1 content
  div#tabs-2
      p Tab 2 content

or

HTML
<div data-hz-resource="HzTabs">
  <ul>
      <li>
          <a href="#tabs-1">Tab 1</a>
      </li>
      <li>
          <a href="#tabs-2">Tab 2</a>
      </li>
  </ul>
  <div id="tabs-1">Tab 1 content</div>
  <div id="tabs-2">Tab 2 content</div>
</div>

Sequence

By default, the tabs require being activated sequentially, to activate the 3rd tabs the 2nd must have been activated before.
It's possible to disable this behavior using the attribute data-opt-hz-tabs-sequential="false"

Options

All the options of jquery ui accordion except functions could be specified by attributes using:

    data-opt-tabs-[option]=[value]

If the option have multiple words, use dashes, for example heightStyle have to be provided as height-style

Examples:

Pug

div(data-hz-resource="HzTabs"
    data-opt-tabs-collapsible="true"
    data-opt-tabs-active="false)
    ul
        li
            a(href='#collapsible-tabs-1') Collapsible  Tab 1
        li
            a(href='#collapsible-tabs-2') Collapsible Tab 2
    div#collapsible-tabs-1
        p Tab 1 content
    div#collapsible-tabs-2
        p Tab 2 content

or

HTML

<div data-hz-resource="HzTabs data-opt-tabs-collapsible="true" data-opt-tabs-active="false>
    <ul>
        <li>
            <a href="#collapsible-tabs-1">Tab 1</a>
        </li>
        <li>
            <a href="#collapsible-tabs-2">Tab 2</a>
        </li>
    </ul>
    <div id="collapsible-tabs-1">Collapsible Tab 1 content</div>
    <div id="collapsible-tabs-2">Collapsible Tab 2 content</div>
</div>

Events

The events are assigned through jquery like usuals

page.ts

page.on(
    PageController.ON_RENDERED, null, (eventObject, $page: JQuery, pageController: PageController) => {
        //Find in the page the element that has tabs
        $page.find('#tabs-events').on('tabsactivate', (event, ui)=>{
            alert(`Tab changed, previous: ${ui.oldPanel.attr("id")}, new tab: ${ui.newPanel.attr("id")}`);
            console.log(`Tab changed, previous: ${ui.oldPanel.attr("id")}, new tab: ${ui.newPanel.attr("id")}`);
        });
    }
);

Methods

The same with the methods

page.ts

page.on(
    PageController.ON_RENDERED, null, (eventObject, $page: JQuery, pageController: PageController) => {
        //Find in the page the element that has slick
        let $tabsMethod = $page.find('#tabs-method');
        $page.find('#toggleDisabled').on('click', (event)=>{
            if($tabsMethod.tabs("option","disabled")){
                $tabsMethod.tabs("enable");
            }else{
                $tabsMethod.tabs("disable");
            }
        });
    }
);