Giter Site home page Giter Site logo

liinkiing / react-tabs Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 588 KB

A composable tabs library for React

Home Page: https://liinkiing.github.io/react-tabs

HTML 2.19% JavaScript 67.00% CSS 0.52% TypeScript 30.29%
react component ui library tabs composing typescript

react-tabs's Introduction

@liinkiing/react-tabs

A composable React tabs library https://liinkiing.github.io/react-tabs/

JavaScript Style Guide

Install

npm install --save @liinkiing/react-tabs

Or

yarn add @liinkiing/react-tabs

Internally, it uses framer/motion packages for the animations between the tab content. It is referenced as a peerDependency, and you should add framer-motion to your packages if you are not already using it.

npm install --save framer-motion

Or

yarn add framer-motion

Typescript support is by default enabled because the library is entirely written in Typescript

Usage

You can use the animate, initial and exit props in <Tabs> component to customize the behaviour of the transitions.

stretchTabsTitle and verticalLayout can also be used in props of <Tabs> to personalize the appearance (see example)

import * as React from 'react'

import { Tab, Tabs } from '@liinkiing/react-tabs'

class Example extends React.Component {
  render () {
    return (
      <Tabs
          {/* These values are the ones by default */}
          initial={{opacity: 0, x: 40}}
          animate={{opacity: 1, x: 0}}
          exit={{opacity: 0, x: 40}}
        >
        <Tab>
          <Tab.Title>First tab</Tab.Title>
          <Tab.Content>First Content</Tab.Content>
        </Tab>
        <Tab>
          <Tab.Title>Second tab</Tab.Title>
          <Tab.Content>Second content</Tab.Content>
        </Tab>
      </Tabs>
    )
  }
}

Nested tabs are also supported

import * as React from 'react'

import { Tab, Tabs } from '@liinkiing/react-tabs'

class Example extends React.Component {
  render () {
    return (
      <Tabs
          {/* These values are the ones by default */}
          initial={{opacity: 0, x: 40}}
          animate={{opacity: 1, x: 0}}
          exit={{opacity: 0, x: 40}}
        >
        <Tab>
          <Tab.Title>First tab</Tab.Title>
          <Tab.Content>First Content</Tab.Content>
        </Tab>
        <Tab>
          <Tab.Title>Second tab with nested</Tab.Title>
          <Tab.Content>
            I have a totally different tabs component with different animations!
            <Tabs
              verticalLayout
              initial={{opacity: 0, x: -400, y: -20}}
              animate={{opacity: 1, x: 0, y: 0}}
              exit={{opacity: 0, x: -400, y: -20}}
            >
              <Tab>
                <Tab.Title>First tab</Tab.Title>
                <Tab.Content>First Content</Tab.Content>
              </Tab>
              <Tab>
                <Tab.Title>Second tab</Tab.Title>
                <Tab.Content>Second content</Tab.Content>
              </Tab>
            </Tabs>
          </Tab.Content>
        </Tab>
      </Tabs>
    )
  }
}

Example

https://liinkiing.github.io/react-tabs/

Notes

This package was made just for the sake of learning and because I wanted a different API to compose my tabs. In a lot of tabs packages, you use a key to identify which tab correspond to which tab content but I wanted to have a hierarchy like this one:

<Tabs>
  <Tab>
    <Tab.Title>...</Tab.Title>
    <Tab.Content>...</Tab.Content>
  </Tab>
  <Tab>
    <Tab.Title>...</Tab.Title>
    <Tab.Content>...</Tab.Content>
  </Tab>
</Tabs>

to have all the informations needed in one Tab component. It's just a matter of preference. But because you are entirely composing your tabs, you can cutomize them even more in your styles and do whatever you want.

License

MIT © liinkiing

react-tabs's People

Contributors

liinkiing avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.