Socket
Book a DemoInstallSign in
Socket

ndla-tabs

Package Overview
Dependencies
Maintainers
5
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ndla-tabs

React Tabs component for NDLA

latest
Source
npmnpm
Version
0.8.0
Version published
Weekly downloads
5
150%
Maintainers
5
Weekly downloads
 
Created
Source

ndla-tabs

A simple tabs component. Mainly a wrapper for react-tabs.

Installation

$ yarn add --save ndla-tabs
$ npm install ndla-tabs --save

Usage

Styling

/* Your project's main .scss import file */
@import '~ndla-tabs/scss/tabs'; // with webpack and sass-loader
@import '../path/to/node_modules/ndla-tabs/scss/tabs'; // direct reference

Basic example

import Tabs from 'ndla-tabs';
import BananaComponent from 'banana';
import PickleComponent from 'picke';

const Fruits = () => {
  const fruitTabs = [
    { title: 'Apple', content: <p>An apple a day keeps the doctor away</p> },
    { title: 'Orange', content: () => <h1>Orange is the new black</h1> },
    { title: 'Banana', content: <BananaComponent /> },
    { title: 'Pickle', content: <PickleComponent />, disabled: true }, // No vegetables allowed!
  ];
  return <Tabs tabs={fruitTabs} />;
};

Example where selected tab is controlled via selectedIndex prop

import Tabs from 'ndla-tabs';
import fruitTabs from 'fruit-tabs';

class FruitTabSelector extends Component {
  constructor(props) {
    super(props);
    this.state = {
      index: 0,
    };
  }

  render() {
    const { index } = this.state;
    return (
      <div>
        <button onClick={() => this.setState({ index: 1 })}>
          Show banana tab
        </button>
        <Tabs selectedIndex={index} tabs={fruitTabs} />
      </div>
    );
  }
}

PropTypes

PropsTypeRequiredDescription
tabsarray*An array of tabs represented as objects. An tab object requires the following properties: title, content. Property disabled is optional.
onSelectfuncIs called when a tab is selected. Current index and last index will be passed as parameters.
selectedIndexobjectIs the tab to select when rendered. Used when you want to control which tab is rendered from the a parent component.
forceRenderTabPanelboolIs false by default. Set to true to render all tab's content instead of only selected tab content.
modifierstringAn BEM modifier which is added to all html classes.

Server side rendering

resetIdCounter should be called on server before render to prevent server and client markup diff. Example:

  import { resetIdCounter } from 'ndla-tabs';
  resetIdCounter();
  ReactDOMServer.renderToString(...);

Keywords

ndla

FAQs

Package last updated on 17 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts