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

0.4.3-alpha.5 • Public • Published

Swipable Tab UI for React



Setup

$ yarn add @karrotframe/tabs

Should import the CSS of your app

import '@karrotframe/tabs/index.css'

import { ... } from '@karrotframe/tabs'

Components

Tabs

All the props is typed and commented in TypeScript

import { Tabs } from '@karrotframe/tabs'
import { useState } from 'react'

const App: React.FC = () => {
  const [activeTabKey, setActiveTabKey] = useState<string>('tab_1')

  return (
    <Tabs
      activeTabKey={activeTabKey}
      tabs={[
        {
          key: 'tab_1',
          buttonLabel: 'Tab 1',
          render: () => <div>Tab 1</div>,
        },
      ]}
      onTabChange={(key) => {
        setActiveTabKey(key)
      }}
    />
  )
}

export default App

Hooks

useTabsController

import { useTabsController } from '@karrotframe/tabs'

const Something: React.FC = () => {
  const { enableSwipe, disableSwipe } = useTabsController()

  const onTouchDown = () => {
    // disable swipe when other action needed
    disableSwipe()

    // ...
  }

  return (
    // ...
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i @karrotframe/tabs

Weekly Downloads

516

Version

0.4.3-alpha.5

License

Apache-2.0

Unpacked Size

150 kB

Total Files

17

Last publish

Collaborators

  • irrationnelle
  • tonyfromundefined