router5-tabs-react
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

router5-tabs-react

Tabs component, based on router5 and react which provides minimalistic interface for toggleable tabbed navigation.

React tabs component download

NPM PRs Welcome npm

Install

yarn add router5-tabs-react

Features

📎 Accessibility and semantics
🔒 Supports stateful URLs
🐹 Tiny component (< 120 lines, ~3kb gzipped)
✂️ Customizable icons
❤️ Tailwind default styles
📈 Content won't be deleted - only hidden
🔍 Provides data-cy prop for e2e testing

Usage

import Tabs from 'router5-tabs-react'

export const Profile = () => {
  const tabs = [
    {
      name: 'user',
      label: 'User',
    },
    {
      name: 'settings',
      label: 'Settings',
    },
    {
      name: 'billing',
      label: 'Billing',
    },
  ]
  return (
    <Tabs>
      <User />
      <Settings />
      <Billing />
    </Tabs>
  )
}

Stateful URLs

To support stateful URLs - you need tab parameter added to your router. It can be query or /subpath

router.ts

{
  name: 'users',
  path: '/:userId',
  // add following to node where you want stateful tabs enabled:
  forwardTo: 'users.tab', // value of {tab: string} should match name of tab you want to show by default
  defaultParams: { tab: 'info' },
  children: [{ name: 'tab', path: '/:tab' }], // add this
},

Also you need to return proper page, for that you can use something like this in your App:

  'users': lazy(() => import('./users')),
  'users.tab': lazy(() => import('./users')),

Acknowledgements

Dee Money
Dee Money

License

MIT © https://github.com/thousandsofraccoons

/router5-tabs-react/

    Package Sidebar

    Install

    npm i router5-tabs-react

    Weekly Downloads

    1

    Version

    0.1.3

    License

    MIT

    Unpacked Size

    62.6 kB

    Total Files

    12

    Last publish

    Collaborators

    • thousandsofraccoons