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-with-tabs

v1.0.12

Published

A built-in component HOC for tabs that is highly customizable and easy to use.

Downloads

20

Readme

npm version

React with tabs

React with tabs is a simple and highly customizable HOC (High order components) that allows you to create tabs in seconds, the package also provides custom-built tabs components (which internally use the same HOC).

The idea of creating this package came up to me while developing nextjs-developer open source portfolio, I needed to create a simple tab component for my Experience Section, The goal was to add animation on each tab panel, Most external react tabs packages come with built-in style and components and can be challenging to optimize. See Demo

Key Features

  1. Very simple to use
  2. Highly customizable
  3. No predefined styles (You can use it with both vertical and horizontal tabs)
  4. Built-in classNames + Support for custom classNames
  5. Typescript support

Installation

  1. Install the package:
    npm i react-with-tabs
    or
    yarn add react-with-tabs
    or
    pnpm add react-with-tabs

Basic Usage:

Using built-in tabs component:

import { Tab, TabList, TabPanel, Tabs } from  "react-with-tabs";

const DefaultTabs = () => {
  return (
    <Tabs>
      <TabList>
        <Tab>Tab 1</Tab>
        <Tab>Tab 2</Tab>
      </TabList>
      <TabPanel>Tab content 1</TabPanel>
      <TabPanel>Tab content 2</TabPanel>
    </Tabs>
  );
};
export { DefaultTabs };

Using built-in HOC for custom tab component:

import { TabElements } from  'react-with-tabs';
import { CustomTabsComponent } from  './CustomTabsComponent';

const  Component = ({ children}) => {
  return (
    <div className="custom-tabs">
      {children}
    </div>
  );
};
const  CustomTabsComponent = withTabs(Component);

export const CustomTabs = () => {
  return (
    <CustomTabsComponent>
      <div className="custom-tab-list" role={TabElements.tabList}>
        <button className="custom-tab" role={TabElements.tab}>Tab 1</button>
        <button className="custom-tab" role={TabElements.tab}>Tab 2</button>	
      </div>
      <div className="custom-tab-panel" role={TabElements.tabPanel}>
        Tab Content 1
      </div>
      <div className="custom-tab-panel" role={TabElements.tabPanel}>
        Tab Content 2
      </div>
    </CustomTabsComponent>
  );
};

API

The main element in React with tabs is the HOC with tabs which creates tabs, But there are also built-in components (which use the same HOC internally)

Tabs (div)


All props for a normal div are accepted in addition to:

selectedClassName: string | undefined

This is the className for the selected tab

default: _react_Selected_Tab

className: string | undefined:

default: _react_Tabs

TabList (div)


All props for a normal div are accepted in addition to:

className: string | undefined:

default: _react_Tab_List

role: string | undefined:

default: tabs

🟥 Important: Do not change the role since it will affect the tabs

Tab (button)


All props for a normal button are accepted in addition to:

className: string | undefined:

default: _react_Tab

role: string | undefined:

default: tab

🟥 Important: Do not change the role since it will affect the tabs.

TabPanel (div)

All props for a normal div are accepted in addition to:

className: string | undefined:

default: _react_Tab_Panel

role: string | undefined:

default: tab-panel

🟥 Important: Do not change the role since it will affect the tabs.

withTabs (HOC)


A high order component that takes an element (this element need to be able to receive children) And transforms it into tabs, the children of this element need to have the same role as the built-in components.

🟥 Important : When creating custom Tabs using the HOC please use these roles defined previously for each element on your custom tab.

TabElements

A simple object to help you add roles on your custom tabs, it has the following properties:

tabList = 'tabs',
tab = 'tab',
tabPanel = 'tab-panel',

See example for a better demonstration

See Demo

Todo

  • [ ] Writing tests
  • [ ] Create a more detailed documentation
  • [ ] Add a github workflow

License

This project is licensed under the MIT License - see the LICENSE.md file for more details