All Projects → rhys-vdw → react-context-tabs

rhys-vdw / react-context-tabs

Licence: other
Flexible tabs for React

Programming Languages

typescript
32286 projects
CSS
56736 projects

Projects that are alternatives of or similar to react-context-tabs

Electron Tabs
Simple tabs for Electron applications
Stars: ✭ 350 (+1029.03%)
Mutual labels:  tabs, tab
PagerSlidingTabStrip
An interactive indicator to navigate between the different pages of a ViewPager
Stars: ✭ 2,194 (+6977.42%)
Mutual labels:  tabs, tab
Hyper Tabs Enhanced
Enhanced Tabs Plugin for Hyper
Stars: ✭ 173 (+458.06%)
Mutual labels:  tabs, tab
alfred-tabs
🔍 Find Chrome/Safari tabs you want easily
Stars: ✭ 13 (-58.06%)
Mutual labels:  tabs, tab
Docsify Tabs
A docsify.js plugin for rendering tabbed content from markdown
Stars: ✭ 65 (+109.68%)
Mutual labels:  tabs, tab
Fliptabs
Android Flip Tabs Library
Stars: ✭ 135 (+335.48%)
Mutual labels:  tabs, tab
ngx-tabset
A very simple library to let you create some tabs
Stars: ✭ 19 (-38.71%)
Mutual labels:  tabs, tab
esl
Lightweight and flexible UI component library based on web components technology for creating basic UX modules
Stars: ✭ 53 (+70.97%)
Mutual labels:  tabs
xMenuTools
Extended context menu tools for Windows
Stars: ✭ 56 (+80.65%)
Mutual labels:  context
vue-magic-line
A flexible tabs-component for Vue
Stars: ✭ 40 (+29.03%)
Mutual labels:  tabs
ZFMultiTabPage
iOS Swift开发的多Tab框架
Stars: ✭ 37 (+19.35%)
Mutual labels:  tab
Hunch
Hunch provides functions like: All, First, Retry, Waterfall etc., that makes asynchronous flow control more intuitive.
Stars: ✭ 94 (+203.23%)
Mutual labels:  context
kubeswitch
visually select kubernetes context/namespace from tree
Stars: ✭ 15 (-51.61%)
Mutual labels:  context
react-native-tabbar
A tabbar component for React Native
Stars: ✭ 59 (+90.32%)
Mutual labels:  tab
RickUmaliVanityWebsite
This is the Perl source code that generates my vanity webpage (hosted at rickumali.com).
Stars: ✭ 19 (-38.71%)
Mutual labels:  tabs
react-zap
⚡ Zap props from one React component to another, using React new context API and your existing higher-order components ⚡
Stars: ✭ 17 (-45.16%)
Mutual labels:  context
IndicatorView
IndicatorView Library For Android
Stars: ✭ 41 (+32.26%)
Mutual labels:  tabs
Tabbed-Container-Extension
A Qlik Extension that groups Sense objects in a container and displays tabs as a way of navigating through them
Stars: ✭ 21 (-32.26%)
Mutual labels:  tabs
context-mirror
Mirror of ConTeXt beta source code
Stars: ✭ 49 (+58.06%)
Mutual labels:  context
cursive-tabs
Tabs for gyscos/cursive views 🖥️
Stars: ✭ 21 (-32.26%)
Mutual labels:  tabs

React context tabs

standard-readme compliant

A flexible and unopinionated tab interface for React. Tabs and panes to be provided in any order or nesting. Inactive panels can be either unmounted or just hidden from view. Includes an optional minimal base stylesheet, but leaves aesthetics up to you.

Table of Contents

Install

npm install react-context-tabs --save

Usage

Basic example

Straight forward tabs!

import React from 'react'
import { Tab, TabList, Tabs, TabPanel } from 'react-context-tabs'

export default function TabExample() {
  return (
    <Tabs defaultTabId='home'>
      <TabList>
        <Tab tabId='home'>React context tabs</Tab>
        <Tab tabId='about'>What is it?</Tab>
        <Tab tabId='issues'>I have a problem</Tab>
      </TabList>
      <TabPanel tabId='home'>
        <p>
          Flexible tabs for React
        </p>
      </TabPanel>
      <TabPanel tabId='about'>
        <p>
          A fine React library
        </p>
      </TabPanel>
      <TabPanel tabId='issues'>
        <p>
          Problem? Try our
          <a href="https://github.com/usabilityhub/react-context-tabs/issues">issues</a> page.
        </p>
      </TabPanel>
    </Tabs>
  )
}

Controlled tabs

Tabs can be either "controlled" or "uncontrolled". Controlled tabs require a selectedTabId property.

import React, { Component } from 'react'
import { Tab, TabList, Tabs, TabPanel } from 'react-context-tabs'

function getHash() {
  return window.location.hash.slice(1)
}

class HashControlledTabs extends Component {

  constructor(props) {
    super(props)
    this.state = { selectedTabId: getHash() }
    this.handleHashChange = this.handleHashChange.bind(this)
    this.handleTabChange = this.handleTabChange.bind(this)
  }

  componentDidMount() {
    window.onhashchange = this.handleHashChange
  }

  componentWillUnmount() {
    window.onhashchange = null
  }

  handleHashChange(event) {
    this.setState({ selectedTabId: getHash() })
  }

  handleTabChange(nextTab, prevTab) {
    window.location.hash = nextTab
  }

  render() {
    const { selectedTabId } = this.state

    return (
      <Tabs
        selectedTabId={selectedTabId}
        onTabChange={this.handleTabChange}
      >
        <TabList>
          <Tab tabId='happy'>Happy</Tab>
          <Tab tabId='sad'>Sad</Tab>
        </TabList>
        <TabPanel tabId='happy'>
          <span style={{ fontSize: '100px', transform: 'rotate(0.25turn)' }}>
            :)
          </span>
        </TabPanel>
        <TabPanel tabId='sad'>
          <span style={{ fontSize: '100px', transform: 'rotate(0.25turn)' }}>
            :(
          </span>
        </TabPanel>
      </Tabs>
    )
  }
}

Nesting

Thanks to React's context feature, children can be re-ordered or nested as you please.

import React from 'react'
import { Tab, TabList, Tabs, TabPanel } from 'react-context-tabs'

function CharacterInformation({ warrior, wizard }) {
  return (
    <Tabs defaultTabId='warrior'>

      <section className='characterInfo'>
        <TabPanel tabId='warrior'>
          <CharacterStats stats={warrior.stats} />
        </TabPanel>
        <TabPanel tabId='wizard'>

          {/* Tabception */}
          <Tabs defaultTabId='stats'>
            <TabList>
              <Tab tabId='stats'>Stats</Tab>
              <Tab tabId='spells'>Spells</Tab>
            </TabList>
            <TabPanel tabId='stats'>
              <CharacterStats stats={wizard.stats} />
            </TabPanel>
            <TabPanel tabId='spells'>
              <CharacterSpells spells={wizard.spells} />
            </TabPanel>
          </Tabs>

        </TabPanel>
      </section>

      {/* Children can be any old component */}
      <marquee>Select your character!</marquee>

      {/* Tabs come after panels */}
      <section className='characterSelection'>
        <TabList>
          <Tab tabId='warrior'>
            Warrior
          </Tab>
          <Tab tabId='wizard'>
            Wizard
          </Tab>
        </TabList>
      </section>
    </Tabs>
  )
}

Styles

A base style sheet is included in the build at /lib/styles/base.css. This just sets appropriate cursor and removes default list styles (for the TabList). You'll still need to write your own CSS to make the tabs look how you want.

Each component has a default class name that is the same as its component name. eg:

<div class="Tabs">
  <ul class="TabList">
    <li class="Tab isSelected">First</li>
    <li class="Tab">Second</li>
  </ul>
  <section className="TabPanel">
    First content
  </section>
<!--
  <section className="TabPanel">
    Second content
  </section>
-->
</div>

Note that PersistentTabPanel and TabPanel both have the same class: TabPanel.

API

Tabs

Parent container to which child components are passed. Tabs can be either "controlled" or "uncontrolled". Supply either defaultTabId for uncontrolled or selectedTabId for controlled.

import { Tabs } from 'react-context-tabs'
import Tabs from 'react-context-tabs/Tabs'
// controlled
<Tabs
  selectedTabId={this.state.selectedTabId}
  onTabChange={(nextTabId, prevTabId) =>
    this.setState({ selectedTadId: nextTabId })
  }
>
  {/* ... */}
</Tabs>

// uncontrolled
<Tabs defaultTabId={initialTabId}>
  {/* ... */}
</Tabs>

Props

  • defaultTabId: any - The tabId of the initially selected tab when uncontrolled.
  • selectedTabId: any - The tabId of the currently selected tab when controlled.
  • onTabChange: (nextTabId, prevTabId) => - Called when the tab changes. Optional for uncontrolled tabs.

TabList

A wrapper component for Tabs. This is just a ul.

import { TabList } from 'react-context-tabs'
import TabList from 'react-context-tabs/TabList'
<TabList>
  <Tab tabId='inbox'>Inbox</Tab>
  <Tab tabId='outbox'>Outbox</Tab>
  <Tab tabId='sent'>Sent</Tab>
</TabList>

Tab

An individual tab. Has CSS class Tab, and isSelected or isDisabled.

import { Tab } from 'react-context-tabs'
import Tab from 'react-context-tabs/Tab'
<Tab tabId='home'>
  <Icon icon='house' />
  Home
</Tab>

Props

  • tabId: any - The ID of the TabPanel to show when clicked.
  • disabled: bool - Disallow clicking on this tab.
  • tabindex: number - Allow this tab to be selected with tab. See MDN tabindex reference.

TabPanel

Container for each tab's content. TabPanels are removed from the DOM when inactive.

TabPanel can be used as children of a ReactCSSTransitionGroup.

import { TabPanel } from 'react-context-tabs'
import TabPanel from 'react-context-tabs/TabPanel'
<TabPanel tabId='avatar'>
  <img src={`/images/avatars/${user.id}.jpeg`} />
  <span>{ user.name }</span>
</TabPanel>

Props

  • tabId: any - The ID of the Tab that will reveal this panel.

PersistentTabPanel

An alternative to TabPanel. PersistentTabPanel is not removed from the DOM when inactive. Instead it is set to display: none. Children will not be rendered until the tab is first revealed.

These panels are useful for tabs that are computationally expensive to render, or need to persist internal state while deselected.

import { PersistentTabPanel } from 'react-context-tabs'
import PersistentTabPanel from 'react-context-tabs/PersistentTabPanel'

Props

  • tabId: any - The ID of the Tab that will reveal this panel.

Contribute

Questions, bug reports and pull requests welcome. See GitHub issues.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].