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-tab-panel

v2.2.7

Published

React TabPanel

Downloads

273

Readme

react-tab-panel

Carefully crafted tabs for React

Docs

Visit the docs site at zippyui.com/docs/react-tab-panel

Tab Panel

Install

$ npm install --save react-tab-panel

Coming soon - scrollable tabs

Usage

import TabPanel from 'react-tab-panel'

import 'react-tab-panel/index.css'

<TabPanel>
  <div tabTitle="First Tab">
    First tab contents here
  </div>  

  <YourComponent tabTitle="Second Tab">
    Content for second tab here
  </YourComponent>
</TabPanel>

Examples

For brevity, we are not showing the import statements in the examples below (with a few exceptions, where appropriate)!

Stretching tabs:

<TabPanel tabAlign="stretch">
  <div tabTitle="First Tab">
    First tab contents here
  </div>  

  <YourComponent tabTitle="Second Tab">
    Content for second tab here
  </YourComponent>
</TabPanel>

Possible tabAlign values:

  • start
  • center
  • end
  • stretch
  • space-around
  • space-between

Disabled tabs:

<TabPanel activeIndex={1}>
  <div
    tabTitle="First Tab"
    tabProps={{disabled: true}}
  >
    First tab contents here
  </div>  

  <YourComponent tabTitle="Second Tab">
    Content for second tab here
  </YourComponent>
</TabPanel>

For disabled tabs, just specify tabProps={{disabled: true}} on the component you want to show as disabled.

Using tabProps

As an alternative to tabTitle, you can use tabProps, which should be an object with at least the title property.

You can use this property to pass in any custom props to tab titles

<TabPanel activeIndex={1}>
  <div
    tabProps={{title:'First tab here'}}
  >
    First tab contents here
  </div>  

  <YourComponent
    tabProps={{
      title: 'Second Tab',
      disabled: true,
      onClick: (e) => console.log(e)
    }}
  >
    Content for second tab here
  </YourComponent>
</TabPanel>

Using the TabStrip

import TabPanel, { TabStrip } from 'react-tab-panel'

<TabPanel activeIndex={1}>

  <TabStrip
    style={{padding: 10}}
  />

  <div tabTitle="First tab here">
    First tab contents here
  </div>  

  <YourComponent tabTitle="Second Tab">
    Content for second tab here
  </YourComponent>

</TabPanel>

Structure

*-------------------*
|    Tab Strip      |
*-------------------*
|                   |
|    Tab Body       |
|                   |
*-------------------*

The TabPanel is built of a TabStrip and a TabBody.

TabStrip

The TabStrip basically renders the tabs at the top (or bottom) of the component.

By default, when rendering a TabPanel you don't have to render a TabStrip explicitly. However, doing so gives you greater flexibility in configuring and positioning it.

Example, with TabStrip

import TabPanel, { TabStrip } from 'react-tab-panel'

<TabPanel
  activeIndex={x}
  onActivate={onActivate}
>
  <TabStrip style={{padding: 20}} />

  <div tabTitle="First Tab">
    First tab contents here
  </div>  

  <YourComponent tabTitle="Second Tab">
    Content for second tab here
  </YourComponent>
</TabPanel>

The TabPanel detects you are using the TabStrip inside it, and won't render it as a tab, instead, you can configure it's style and other props.

You can even use the TabStrip in isolation, without the TabPanel:

import { TabStrip } from 'react-tab-panel'

let x = 1
let onActivate = (newIndex) => { ... }

const tabs = [
  'First tab',
  <b>second tab</b>
]
<TabStrip
  tabs={tabs}
  activeIndex={x}
  onActivate={onActivate}
/>

Configuration

If you are using the TabStrip as a standalone component, you can specify the following props:

  • tabs: Array - an array of ReactNode elements, which will be the tab titles
  • activeIndex - the index of the tab to render as active. Controlled prop!
  • defaultActiveIndex - uncontrolled version of activeIndex
  • onActivate: Function(index) - function to be called when a new tab is clicked & activated.

TabBody

Renders the active tab contents.

You can include a TabBody inside your TabPanel to configure how the current tab content is rendered.

Example:

import TabPanel, { TabBody, TabStrip } from 'react-tab-panel'

<TabPanel>

  <TabBody style={{padding: 100}}>
    <div tabTitle="First tab">
      Lorem ipsum Nisi fugiat ut nulla consectetur reprehenderit.
    </div>
    <YourComponent tabTitle="Second"/>
  </TabBody>

  <TabStrip />
</TabPanel>

The TabPanel will detect you are using a TabBody inside, and will use its children as tabs, and not the children of the TabPanel. You can even use a TabStrip and include it after the TabBody as an alternative way of configuring the tabPosition to 'bottom'

Configuration

  • renderContent: Function - a function that gets passed the content to render in the TabBody. You can use this to add some nesting and/or custom styling, etc.

The TabBody accepts any other normal JSX props. Eg: onClick, style, className, etc

Styling

It's default className will be 'react-tab-panel__body'. If you configure it with another className, it will use both yours and the default value.

Configuration

  • children with tabTitle prop as tabs
  • tabPosition - 'top' or 'bottom' are possible values. By default the TabPanel will render tabs at the top.

Theming

For the default look&feel, just import react-tab-panel/index.css, which includes the structural styles as well as the default theme.

If you want to use only the structural styles, make sure you only include react-tab-panel/base.css and then add your own custom theme on top of those styles.

import TabPanel from 'react-tab-panel'

//now import the css files
import 'react-tab-panel/index.css' //for the default look

//the css import above is equivalent to
import 'react-tab-panel/base.css'
import 'react-tab-panel/theme/default.css'

If you want to show the TabPanel with another theme, don't forget to also specify the theme prop on the component:

<TabPanel theme="flat" ... />

Available themes:

  • default
  • red
  • flat

License

Commercial license required - copyright Zippy Technologies

For details, email us at contact at zippyui dot com