@ndla/tabs
TypeScript icon, indicating that this package has built-in type declarations

4.0.3 • Public • Published

ndla-tabs

A simple tabs component.

Installation

yarn add --save @ndla/tabs
npm install @ndla/tabs --save

Usage

Basic example

import { Tabs } from "@ndla/tabs";
import BananaComponent from "banana";
import PickleComponent from "picke";

const Fruits = () => {
  const fruitTabs = [
    {
      title: "Apple",
      id: "apple",
      content: <p>An apple a day keeps the doctor away</p>,
    },
    {
      title: "Orange",
      id: "orange",
      content: () => <h1>Orange is the new black</h1>,
    },
    { title: "Banana", id: "banana", content: <BananaComponent /> },
    {
      title: "Pickle",
      id: "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";

const FruitTabSelector = () => {
  const [value, setValue] = useState(undefined);
  return (
    <div>
      <button onClick={() => setValue("banana")}>Show banana tab</button>
      <Tabs value={value} tabs={fruitTabs} />
    </div>
  );
};

Readme

Keywords

Package Sidebar

Install

npm i @ndla/tabs

Weekly Downloads

365

Version

4.0.3

License

GPL-3.0

Unpacked Size

56.7 kB

Total Files

9

Last publish

Collaborators

  • kronen_ki
  • rauboti
  • mapoken
  • katrinewi
  • ndlauser
  • jonasc-knowit
  • gunnarvelle
  • jnatten