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-tabbed-area

v1.0.4

Published

Easy to use tabbing component for React

Downloads

3

Readme

react-tabbed-area

Easy to use tabbing component for React

Installation

npm install react-tabbed-area

Usage

An example of basic usage, tabs on top with some simple content

import React, { useState } from "react";
import TabbedArea from "react-tabbed-area";

const MyContent = () => {
  const tabs = ["Tab 1", "Tab 2", "Tab 3"];
  const [selectedTab, setSelectedTab] = useState(tabs[0]);

  return (
    <TabbedArea
      tabs={tabs}
      selectedTab={selectedTab}
      onSelectTab={(tab) => setSelectedTab(tab)}
    >
      {selectedTab === "Tab 1" ? (
        <>Tab One Content</>
      ) : selectedTab === "Tab 2" ? (
        <>Tab Two Content</>
      ) : selectedTab === "Tab 3" ? (
        <>Tab Three Content</>
      ) : null}
    </TabbedArea>
  );
};

Example1

Props

| Prop Name | Description | Example Values | | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | tabs | Array of tab names, or Array of Objects with the following properties: name, icon, hideName. Tab names must be unique to each TabbedArea | ["Tab 1", "Tab 2"], [{name: "Tab 1", icon: , hideName: true}, {name: "Tab 2"}] | | selectedTab | string or object with a name property. This item should use the state of your parent component to force the rerender upon tab switch | | | onSelectTab | callback function passed when a user clicks a tab, will pass back the tab name or entire tab object. Use this to set the state of selectedTab | (tab) => setSelectedTab(tab) | | children | any content that you wish to display within the tabbed area. Use a check for the selectedTab to display different content for each tab | Any Component(s) | | tabPlacement | the position of the tabs, either "top", "left", or "right", default is "top" | | | backgroundColor | the main background color of the tabbed area and the selected tab | any hex or html color | | color | the main text color for the selected tab | any hex or html color | | inactiveBackgroundColor | the background color of a tab when it is inactive | any hex or html color | | inactiveTextColor | the color of the text on a tab when it is inactive | any hex or html color | | hoverBackgroundColor | the background color of a tab when it is not selected and is hovered over | any hex or html color | | hoverTextColor | the text color of a tab when it is not selected and is hovered over | any hex or html color |

Using a custom component for the tab name

Rather than pass an array of strings as your tabs you can use an array of objects. This will allow you to provide icons or simply a custom component as the label for each tab.

If using the object method you must include the name property in each tab, as that is how the selectedTab check will be performed. Other available properties include icon, which is where you will provide your custom component, and hideName, a self explanatory boolean.

You are able to pass any combination of text or objects to the tabs prop. Below is an example of using an image as the first tab label, but regular text as the second label, with some custom coloring.

You will need to use a slightly more complex selectedTab checking function to render your content correctly.

import React, { useState } from "react";
import TabbedArea from "react-tabbed-area";

const MyContent = () => {
  const tabs = [
    {
      name: "Tab 1",
      icon: (
        <img
          src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/React-icon.svg/2300px-React-icon.svg.png"
          width={35}
          height={25}
        />
      ),
      hideName: true,
    },
    "Tab 2",
  ];
  const [selectedTab, setSelectedTab] = useState(tabs[0]);

  const isSelected = (tab) => {
    const tabName = selectedTab.name || selectedTab;
    return tabName === tab;
  };

  return (
    <TabbedArea
      tabs={tabs}
      selectedTab={selectedTab}
      onSelectTab={(tab) => setSelectedTab(tab)}
    >
      {isSelected("Tab 1") ? (
        <>Tab One Content</>
      ) : selectedTab === "Tab 2" ? (
        <>Tab Two Content</>
      ) : null}
    </TabbedArea>
  );
};

Example2