1.2.2 • Published 10 months ago

@cypress-design/react-tabs v1.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Tabs

Install

npm install @cypress-design/react-tabs

or with yarn

yarn add @cypress-design/react-tabs

Usage

import Tabs from '@cypress-design/react-tabs'
import { IconActionPlayVideo } from '@cypress-design/react-icon'

export default () => {
  const activeId = 'ov'
  const tabs = [
    { id: 'ov', label: 'Overview', ['aria-controls']: 'tabpanel-id-1' },
    {
      id: 'cl',
      label: 'Command Log',
      icon: IconActionPlayVideo,
      ['aria-controls']: 'tabpanel-id-2',
    },
    {
      id: 'err',
      label: 'Errors',
      href: 'https://www.cypress.io',
      ['aria-controls']: 'tabpanel-id-3',
    },
    {
      id: 'reco',
      label: 'Recommendations',
      ['aria-controls']: 'tabpanel-id-4',
    },
  ]

  return (
    <div>
      <Tabs activeId={activeId} tabs={tabs} />
      {tabs.map(({ id: tabId, ...rest }, i) => (
        <div
          key={i}
          role="tabpanel"
          id={rest['aria-controls']}
          style={{ display: activeId === tabId ? 'block' : 'none' }}
        >
          Tab Panel {i + 1}
        </div>
      ))}
    </div>
  )
}
import { useState } from 'react'
import { IconActionPlayVideo } from '@cypress-design/react-icon'

export default () => {
  const activeId = 'ov'
  const [allowMove, setAllowMove] = useState(true)
  const tabs = [
    { id: 'ov', label: 'Overview', ['aria-controls']: 'tabpanel-id-1' },
    {
      id: 'cl',
      label: 'Command Log',
      icon: IconActionPlayVideo,
      ['aria-controls']: 'tabpanel-id-2',
    },
    {
      id: 'err',
      label: 'Errors',
      href: 'https://www.cypress.io',
      ['aria-controls']: 'tabpanel-id-3',
    },
    {
      id: 'reco',
      label: 'Recommendations',
      ['aria-controls']: 'tabpanel-id-4',
    },
  ]
  return (
    <>
      <fieldset>
        <input
          id="allow-move"
          type="checkbox"
          onClick={() => setAllowMove(!allowMove)}
          defaultChecked={allowMove}
          className="mr-2"
        />
        <label htmlFor="allow-move">allow tab move</label>
      </fieldset>
      <Tabs
        activeId={activeId}
        tabs={tabs}
        onSwitch={(_, e) => {
          if (!allowMove) e.preventDefault()
        }}
      />
      {tabs.map(({ id: tabId, ...rest }, i) => (
        <div
          key={i}
          role="tabpanel"
          id={rest['aria-controls']}
          style={{ display: activeId === tabId ? 'block' : 'none' }}
        >
          Tab Panel {i + 1}
        </div>
      ))}
    </>
  )
}
2.0.0-next.0

10 months ago

1.2.0

12 months ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.2.2

12 months ago

1.2.1

12 months ago

0.9.2

1 year ago

0.9.0

1 year ago

0.9.1

1 year ago

0.8.6

1 year ago

0.8.5

1 year ago

0.8.4

1 year ago

0.8.3

1 year ago

0.8.2

1 year ago

0.8.1

2 years ago

0.7.2

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.6.2

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.1.0

2 years ago