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

react-tabs-scrollable

v2.0.7

Published

a simple react scrollable tabs with a lot of additional features and with fully supporting of RTL mode

Downloads

21,343

Readme

react-tabs-scrollable

a simple react scrollable tabs with a lot of additional features and with fully supporting of RTL mode

NPM JavaScript Style Guide

Install

npm install --save react-tabs-scrollable@latest
yarn add react-tabs-scrollable@latest

V1

npm install --save [email protected]
yarn add [email protected]

Demos

Demos

V1 docs

V1 docs

Features

  • Typescript out of box
  • Many modes to control the behaviour of the selected tab.
  • Easy to start with it takes you less than minute to start it up!
  • Many features and so easy to customize
  • Fully support for RTL (actually the reason why I built this component is because RTL)
  • Fully accessible
  • You can control and have access to everything inside it.
  • Small sized 9.6k (gzipped: 3.9k)
  • Great to use in navigation, menus and lists or any proper use for tabs
  • Easy to style, you have the css file so you can edit it as you would like, and there are style and className props to all the elements used inside the package.
  • You have access to all refs.
  • And much more ..

What's new in V2?

  • I rebuild the package from scratch with typescript to avoid the unnecessary bugs and to make it more elegant and easy to use with the typescript auto-complete.

    Note: this's my first time using typescript so expect many bugs with types since i was interfering a lot of types to any, and because I dont have the proper internet, I couldnt search well for them -_-. But overall I think everything works fine!.

  • I deleted the unnecessary code and made it more readable and clean.

  • I deleted selectedTabCoordinates and replaced it with getTabsBoundingClientRects function that returns DOMRect object for the tabsContainer and tab, and it's way performant comparing to the old selectedTabCoordinates, it just runs when the scroll stops and when you switch to RTL.

  • I renamed the two action onRightBtnClick and onLeftBtnClick to onRightNavBtnClick and onLeftNavBtnClick

  • I made the API and the enternals of the component more exposed to the developers who wants to use it (Please see the API table below to see all the new props), since I added about 15 new props including refs to all the elements inside the pacakge, and I added custom styles to style it as you want.

  • I added new features to make the component more compatible with my new package react-kfc-menu such as mode prop that controls the behavior of the selected tab scroll, now you can change the whole behavior of it with the new 4 modes I've added to it.

  • I added <TabScreen /> component if you want to use tab panels with the tabs.

I'm planning to add Swipeable component to make the TabScreens more interactive with drag and touch events on both, Desktop and mobile.

Please If you faced any bugs feel free to open an issue.

Usage

#Simple Tabs

import React from "react";
import { Tabs, Tab } from "react-tabs-scrollable";
import "react-tabs-scrollable/dist/rts.css";

const SimpleTabs = () => {
  // define state with initial value to let the tabs start with that value
  const [activeTab, setActiveTab] = React.useState(1);

  // define a onClick function to bind the value on tab click
  const onTabClick = (e, index) => {
    console.log(e);
    setActiveTab(index);
  };

  return (
    <>
      <Tabs activeTab={activeTab} onTabClick={onTabClick}>
        {/* generating an array to loop through it  */}
        {[...Array(20).keys()].map((item) => (
          <Tab key={item}>Tab {item}</Tab>
        ))}
      </Tabs>
    </>
  );
};

export default SimpleTabs;

#Tabs with TabScreen

import React from "react";
import { Tabs, Tab } from "react-tabs-scrollable";
import "react-tabs-scrollable/dist/rts.css";

const SimpleTabs = () => {
  // define state with initial value to let the tabs start with that value
  const [activeTab, setActiveTab] = React.useState(1);

  // define a onClick function to bind the value on tab click
  const onTabClick = (e, index) => {
    console.log(e);
    setActiveTab(index);
  };
  const tabsArray = [...Array(20).keys()];
  return (
    <>
      <Tabs activeTab={activeTab} onTabClick={onTabClick}>
        {/* generating an array to loop through it  */}
        {tabsArray.map((item) => (
          <Tab key={item}>Tab {item}</Tab>
        ))}
      </Tabs>

      {tabsArray.map((item) => (
        <TabScreen
          key={item}
          activeTab={activeTab}
          index={item}
          // You can add animation with adding a custom class
          className="some-animation-class"
        >
          TabScreen {item}
        </TabScreen>
      ))}
    </>
  );
};

export default SimpleTabs;

#Full example with all features

<Tabs
  // the selected tab state which must be passed to the commponent
  activeTab={activeTab}
  // tab on click function
  // it has two props
  // first one is event object
  // second one is the index of the selected tab
  onTabClick={(val) => console.log(val)}
  // this prop returns a group of events to control the tabs such as onLeftNavBtnClick , onRightNavBtnClick to control the tabs
  // you should pass here a ref to get the required functionality
  action={tabRef}
  // sets if the direction of the page is RTL or not
  // default false
  isRTL={false}
  // sets if the tabs reached the end point of the tab container
  // function
  didReachEnd={(val) => console.log(val)}
  // sets if the tabs reached the start point container
  // function
  didReachStart={(val) => console.log(val)}
  // sets how many tabs you want to scroll on every move
  // default 3 tabs on each navigation button click
  tabsScrollAmount={3}
  // sets the general animation duration when you click on the navigation buttons and when you click out the tabs view
  // this option will disable navBtnCLickAnimationDuration and selectedAnimationDuration
  // default 300s
  animationDuration={300}
  // sets the animation of the scroll when you click on the navigation buttons
  // note : this will overwirte the animationDuration value
  // default 300s
  navBtnCLickAnimationDuration={300}
  // sets the animation of the scroll when you click on a tab that is out of the view
  // note : this will overwirte the animationDuration value
  // default 300s
  selectedAnimationDuration={300}
  // sets the right navitgation vutton icon
  // default feather arrow-right svg icon
  // you can pass jsx here or just a string
  rightBtnIcon={">"}
  // sets the left navitgation button icon
  // default feather arrow-left svg icon
  // you can pass jsx here or just a string
  leftBtnIcon={"<"}
  //hides the navigantion button
  // default false
  hideNavBtns={false}
  // hides the navigation buttons on mobile devices
  // default true
  hideNavBtnsOnMobile={true}
  // shows the scroll of the tabs
  // default false
  showTabsScroll={false}
  // returns the DOMRect object of the selected tab and the tabs container
  getTabsBoundingClientRects={(val) => console.log(val)}
  // A react ref that can be used to control the tabs programmatically
  //   Check the API section to understand more
  action={ref}
  //   You can change the behaviour of the selected tab scroll by changing the option of it, whether to move it to center, start, end or to center but if the selected tab is in the view.
  //   Check the API section to understand more or you can play with it to understand the idea
  mode="scrollSelectedToCenterFromView"
  //   changes the underline HTML element
  navBtnAs="div"
  //   These props sets the className of their elements
  tabsContainerClassName=""
  tabsUpperContainerClassName=""
  tabsContainerClassName=""
  leftNavBtnClassName=""
  rightNavBtnClassName=""
  navBtnClassName=""
  navBtnContainerClassName=""
  //  Sets the style of these element
  navBtnStyle={{}}
  tabsContainerStyle={{}}
  tabsUpperContainerStyle={{}}
  //    You can get the ref of these elements
  tabsContainerRef={ref}
  tabRef={ref}
  leftNavBtnRef={ref}
  rightNavBtnRef={ref}
>
  <Tab>item </Tab>
  {[...Array(20).keys()].map((tab) => (
    <Tab key={tab}>Tab {tab}</Tab>
  ))}
</Tabs>

API

Tab

TabScreen

If you liked this project don't forget to see my other projects on NPM and github

Contrubite

Show your support by giving a ⭐. Any feature requests are welcome! Anyone is welcomed to contribute in this project.

Financial Contributions

Buying me coffee will help me sustain the updates and work on new project for the open-source

Organizations

Support this project with your organization / company or individual.