0.8.3 • Published 5 years ago

@whatoplay/react-tab-bar v0.8.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

React Tab Bar

A React version of an MDC Tab Bar.

Installation

npm install @material/react-tab-bar

Usage

Styles

with Sass:

import '@material/react-tab-bar/index.scss';
import '@material/react-tab-scroller/index.scss';
import '@material/react-tab/index.scss';
import '@material/react-tab-indicator/index.scss';

with CSS:

import '@material/react-tab-bar/dist/tab-bar.css';
import '@material/react-tab-scroller/dist/tab-scroller.css';
import '@material/react-tab/dist/tab.css';
import '@material/react-tab-indicator/dist/tab-indicator.css';

Javascript Instantiation

import React from 'react';
import Tab from '@material/react-tab';
import TabBar from '@material/react-tab-bar';

class MyApp extends React.Component {
  state = {activeIndex: 0};

  handleActiveIndexUpdate = (activeIndex) => this.setState({activeIndex});

  render() {
    return (
      <div>
        <TabBar
          activeIndex={this.state.activeIndex}
          handleActiveIndexUpdate={this.handleActiveIndexUpdate}
        >
          <Tab>
            <span className='mdc-tab__text-label'>One</span>
          </Tab>
          ...
        </TabBar>
      </div>
    );
  }
}

NOTE: You can also use a custom tab component with the TabBar, but it must implement the methods activate, deactivate, focus, computeIndicatorClientRect, and computeDimensions. See MDCTab documentation for more details.

Props

Prop NameTypeDescription
activeIndexnumberIndex of the active tab.
indexInViewnumberIndex of the tab to be scrolled into view.
handleActiveIndexUpdateFunction(activeIndex: number) => voidCallback after the active index is updated.
classNamestringClasses to appear on className attribute of root element.
isRtlBooleanWhether the direction of the tab bar is RTL.

Sass Mixins

Sass mixins may be available to customize various aspects of the components. Please refer to the MDC Web repository for more information on what mixins are available, and how to use them.

Advanced Sass Mixins