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

sliding-tabs

v1.2.5

Published

Web Component for slidable tabs

Downloads

23

Readme

sliding-tabs

Built With Stencil MIT License npm version npm downloads Known Vulnerabilities

Buy me a coffee

sliding-tabs is a web component buildt with Stencil for slideable tabs or just for a simple slider.

Demo with fixed tabs

Demo with scrollable tabs

Using this component

Script tag

  • Put <script src='https://unpkg.com/sliding-tabs@latest/dist/sliding-tabs.js'></script> in the head of your index.html
  • Then you can use the component

Node Modules

  • Run npm install sliding-tabs --save
  • Put a script tag similar to this <script src='node_modules/sliding-tabs/dist/sliding-tabs.js></script> in the head of your index.html
  • Then you can use the component

In a stencil-starter app

  • Run npm install sliding-tabs --save
  • Add { name: 'sliding-tabs' } to your collections
  • Then you can use the component

In a Angular or Ionic Project

  • Run npm install sliding-tabs --save
  • Include the CUSTOM_ELEMENTS_SCHEMA in the modules that use the components
  • Define the custom elements within your app by calling defineCustomElements(window) from main.ts (or some other appropriate place)

Including the Custom Elements Schema

import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { SharedModule } from './shared/shared.module';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, FormsModule, SharedModule],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}

Defining the Custom Elements

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

import { defineCustomElements } from 'sliding-tabs';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));
defineCustomElements(window);

Usage

As simple slider

Without the toolbar, you can use this component as a simple slider:

<sliding-tabs>
    <sliding-tabs-content>
      <sliding-tab tab-name="a">Slide A</sliding-tab>
      <sliding-tab tab-name="b">Slide B</sliding-tab>
      <sliding-tab tab-name="c">Slide C</sliding-tab>
    </sliding-tabs-content>
  </sliding-tabs>

With toolbar for tabs

<sliding-tabs>
	<sliding-tabs-content>
		<sliding-tab tab-name="a">Content A</sliding-tab>
		<sliding-tab tab-name="b">Content B</sliding-tab>
		<sliding-tab tab-name="c">Content C</sliding-tab>
	</sliding-tabs-content>
	<sliding-tabs-toolbar>
		<sliding-tabs-button for-tab="a">
		    Button A
		</sliding-tabs-button>
		<sliding-tabs-button for-tab="b">
		    Button B
		</sliding-tabs-button>
		<sliding-tabs-button for-tab="c">
		    Button C
		</sliding-tabs-button>
	</sliding-tabs-toolbar>
</sliding-tabs>

The toolbar can also be placed on top of the content:

<sliding-tabs>
	<sliding-tabs-toolbar>
		<sliding-tabs-button for-tab="a">
		    Button A
		</sliding-tabs-button>
		<sliding-tabs-button for-tab="b">
		    Button B
		</sliding-tabs-button>
		<sliding-tabs-button for-tab="c">
		    Button C
		</sliding-tabs-button>
	</sliding-tabs-toolbar>
	<sliding-tabs-content>
		<sliding-tab tab-name="a">Content A</sliding-tab>
		<sliding-tab tab-name="b">Content B</sliding-tab>
		<sliding-tab tab-name="c">Content C</sliding-tab>
	</sliding-tabs-content>    
</sliding-tabs>

You can add an indicator, which shows the current tab position relative to the buttons:

<sliding-tabs>	
	<sliding-tabs-content>
		<sliding-tab tab-name="a">Content A</sliding-tab>
		<sliding-tab tab-name="b">Content B</sliding-tab>
		<sliding-tab tab-name="c">Content C</sliding-tab>
	</sliding-tabs-content>
	<sliding-tabs-toolbar indicator-placement="top">
		<div class="my-indicator" slot="indicator"></div>
		<sliding-tabs-button for-tab="a">
		    Button A
		</sliding-tabs-button>
		<sliding-tabs-button for-tab="b">
		    Button B
		</sliding-tabs-button>
		<sliding-tabs-button for-tab="c">
		    Button C
		</sliding-tabs-button>
	</sliding-tabs-toolbar>
</sliding-tabs>

There are two more slots you can use for additional buttons:

<sliding-tabs>	
	<sliding-tabs-content>
		<sliding-tab tab-name="a">Content A</sliding-tab>
		<sliding-tab tab-name="b">Content B</sliding-tab>
		<sliding-tab tab-name="c">Content C</sliding-tab>
	</sliding-tabs-content>
	<sliding-tabs-toolbar indicator-placement="top" id="toolbar">
		<div class="my-indicator" slot="indicator"></div>
		<div slot="toolbar-left" class="pager-item" id="previous">&lt;</div>
      	<div slot="toolbar-right" class="pager-item" id="next">&gt;</div>
		<sliding-tabs-button for-tab="a">
		    Button A
		</sliding-tabs-button>
		<sliding-tabs-button for-tab="b">
		    Button B
		</sliding-tabs-button>
		<sliding-tabs-button for-tab="c">
		    Button C
		</sliding-tabs-button>
	</sliding-tabs-toolbar>
</sliding-tabs>

<script>
	var toolbar = document.getElementById('toolbar');
	var previous = document.getElementById('previous');
	var next = document.getElementById('next');

	previous.addEventListener('click', () => toolbar.scrollToLeft());
	next.addEventListener('click', () => toolbar.scrollToRight());
</script>

API

sliding-tabs Element

Parameters

active-tab-index: The index of the active tab.

<sliding-tabs active-tab-index="1">...</sliding-tabs>	

active-tab: The name of the active tab

<sliding-tabs active-tab="c">...</sliding-tabs>

Events

tabChanged: Fires everytime a tab changed. The event contains a property details with the index and name of the current tab:

interface tabChandedEvent {
	index: number;
	name: string;
}

sliding-tabs-content

Parameters

drag-threshold: Number of pixels that must be swiped through before the drag event triggers (default: 20)

<sliding-tabs-content drag-threshold="50">...</sliding-tabs-content>

sliding-tabs-toolbar Element

Parameters

indicator-placement: Possible values are top (place indicator on top of the buttons) and bottom (place indicator to the bottom).

<sliding-tabs-toolbar indicator-placement="bottom">...</sliding-tabs-toolbar>

scrollable: Enables swiping in the toolbar. This is usefull if you have a lot of tabs or buttons with large content.

<sliding-tabs-toolbar scrollable="true">...</sliding-tabs-toolbar>

active-tab-position: The position of the active tab when scrollable="true". Possible values are left, center and right.

<sliding-tabs-toolbar scrollable="true" active-tab-position="center">...</sliding-tabs-toolbar>

Methods on the DOM-Element

async scrollToButton(name: string): Scroll to a specific button (if scrollable="true")

async scrollToLeft(): Scroll the toolbar to the left (previous button).

async scrollToRight(): Scroll the toolbar to the right (next button).

async setActiveTab(): Switch to a specific tab.

Changelog

1.2.5

  • Fixed some bugs

1.2.4

  • Updated dependencies
  • Fixed some bugs

1.2.0

  • Added drag-threshold property to sliding-tabs-content
  • Only change activeTabIndex if tab exists

1.1.0

  • Added active-tab property to scroll-tabs
  • Added active-tab-position property to scroll-tabs-toolbar
  • Improved performance