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

@almostbearded/react-tabs

v1.0.4

Published

A minimalist, accessible React tabs component.

Downloads

24

Readme

react-tabs

A minimalist, accessible React tabs component. The rendered content is fully accessible. The implementation, styling, and configuration has purposely been kept as simple as possible.

The storybook demonstrating some common usage examples can be found at https://almostbearded-react-tabs.netlify.app.

Installation

This package has only a dependency on React. The easiest way to install is via npm:

npm install @almostbearded/react-tabs

Basic Usage

Import the Tabs component from the @almostbearded/react-tabs package:

import { Tabs } from '@almostbearded/react-tabs'

The currently selected tab could itself be stored in a state variable or derived from one. For example, to store the selected tab in state:

const [selectedTab, setSelectedTab] = useState('default-tab-id')

Afterwards, the Tabs component can simply be used in other components:

<Tabs
    tabs={[
        { id: 'tab-1', title: 'Tab 1', content: 'Content of Tab 1' },
        { id: 'tab-2', title: 'Tab 2', content: 'Content of Tab 2' },
    ]}
    selectedTab={selectedTab}
    onSelectTab={setSelectedTab} />

It is also possible to pass more complex nodes to the title and content props:

<Tabs
    tabs={[
        {
            id: 'tab-1',
            title: <h3>Tab 1</h3>,
            content: <p>Complex content of tab 1</p>
        },
        {
            id: 'tab-2',
            title: <h3>Tab 2</h3>,
            content: <p>Complex content of tab 2</p>
        },
    ]}
    selectedTab={selectedTab}
    onSelectTab={setSelectedTab} />

API

The Tabs component can be configured via a number of props:

  • The tabs prop is an array containing the configuration of the titles and contents of tabs. Every tab consists of an unique id, a title shown in the tab, and content shown in the panel linked to a tab.
  • The selectedTab prop defines which tab is currently selected and therefore which content is currently shown.
  • The onSelectTab prop takes a callback that is invoked with the id of the newly selected tab, whenever a user clicks one of the tabs.

Demos

The following demos show the Tabs component being used with different configurations.

Single tab

Demo showing a single tab

Two Tabs

Demo showing two tabs

Many Tabs

Demo showing many tabs

Tabs Containing Sign in and Sign up Forms

Demo showing sign in and sign up forms

Known Issues

No known issues at the moment.

Additional Resources

  • https://www.npmjs.com/package/@almostbearded/react-tabs
  • https://almostbearded-react-tabs.netlify.app