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

coherent-gameface-tabs

v3.2.2

Published

Tabs component for Coherent Labs' Gameface.

Downloads

9

Readme

The tabs component is part of the Gameface custom components suite. As most of the components in this suite, it uses slots to allow dynamic content.

Installation

npm i coherent-gameface-tabs

Usage

Usage with UMD:

<script src="./node_modules/coherent-gameface-tabs/dist/tabs.production.min.js"></script>
  • add the tabs component to your html:
<gameface-tabs></gameface-tabs>

This is all! Load the file in Gameface to see the tabs.

Usage with JavaScript:

If you wish to import the Tabs using JavaScript you can remove the script tag and import it like this:

import { Tabs } from 'coherent-gameface-modal';

or simply

import 'coherent-gameface-modal';

Note that this approach requires a module bundler like Webpack or Rollup to resolve the modules from the node_modules folder.

Customizing the Tabs

Use the slots to put customized background or label.

The tabs component has two slots:

  • tab - this is where the tab headings are added.
  • panel - this is where the corresponding panels are added.

Use the <component-import> to import the tabs. Put any custom slots as children of the <component-import>.

<gameface-tabs>
    <tab-heading slot="tab">Chapter One</tab-heading>
    <tab-panel slot="panel">Chapter One Content</tab-panel>
    <tab-heading slot="tab">Chapter Two</tab-heading>
    <tab-panel slot="panel">Chapter Two Content</tab-panel>
    <tab-heading slot="tab">Chapter Three</tab-heading>
    <tab-panel slot="panel">Chapter Three Content</tab-panel>
    <tab-heading slot="tab">Chapter Four</tab-heading>
    <tab-panel slot="panel">Chapter Four Content</tab-panel>
</gameface-tabs>

You can put any custom styles inline or use class names and add an external file.

The tabs component registers two more custom elements - The <tab-heading> and <tab-panel>. Every time you create an element of one of these types an index is assigned to it. This index ensures that your heading will be linked to its corresponding panel. This means that you can add new tabs and panels like this and they will work:

const tab = document.createElement('tab-heading');
tab.innerText = 'My new tab.';
tab.slot = 'tab';
document.querySelector('[data-name="tab"]').appendChild(tab);

const panel = document.createElement('tab-panel');
panel.innerText = 'My new panel.';
panel.slot = 'panel';
document.querySelector('[data-name="panel"]').appendChild(panel);

Add the Styles

<link rel="stylesheet" href="coherent-gameface-components-theme.css">
<link rel="stylesheet" href="styles.css">

To overwrite the default styles, simply create new rules for the class names that you wish to change and include them after the default styles.

Selecting a tab

To set a tab as the default, add the selected attribute to the tab-heading that needs to be selected and its corresponding tab-panel.

<gameface-tabs>
    <tab-heading selected slot="tab">Chapter One</tab-heading>
    <tab-panel selected slot="panel">Chapter One Content</tab-panel>
    <tab-heading slot="tab">Chapter Two</tab-heading>
    <tab-panel slot="panel">Chapter Two Content</tab-panel>
    <tab-heading slot="tab">Chapter Three</tab-heading>
    <tab-panel slot="panel">Chapter Three Content</tab-panel>
    <tab-heading slot="tab">Chapter Four</tab-heading>
    <tab-panel slot="panel">Chapter Four Content</tab-panel>
</gameface-tabs>

Ensure that only one tab-heading and one tab-panel have the selected attribute. Adding it to multiple tabs will cause more than one tab to be marked as selected, disrupting the visual display.

To select another tab using JavaScript, use the selectTab method. Pass a tab-heading as an argument, and it will open the corresponding tab-panel.

const tabs = document.querySelector('gameface-tabs');
const newTab = document.querySelectorAll('tab-heading')[1];

tabs.selectTab(newTab);