Skip to content

Commit 9af04a0

Browse files
authored
add Tabs component (#674)
* add `Tabs` component (React) * expose `Tabs` component (React) * add `Tabs` example (React) * add `Tabs` component (Vue) * expose `Tabs` component (Vue) * update changelog
1 parent 1ec5e74 commit 9af04a0

File tree

12 files changed

+4816
-2
lines changed

12 files changed

+4816
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased - React]
99

10-
- Nothing yet!
10+
### Added
11+
12+
- Add new `Tabs` component ([#674](https://github.com/tailwindlabs/headlessui/pull/674))
1113

1214
## [Unreleased - Vue]
1315

14-
- Nothing yet!
16+
### Added
17+
18+
- Add new `Tabs` component ([#674](https://github.com/tailwindlabs/headlessui/pull/674))
1519

1620
## [@headlessui/react@v1.3.0] - 2021-06-21
1721

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React, { useState } from 'react'
2+
import { Tabs, Switch } from '@headlessui/react'
3+
4+
import { classNames } from '../../src/utils/class-names'
5+
6+
export default function Home() {
7+
let tabs = [
8+
{ name: 'My Account', content: 'Tab content for my account' },
9+
{ name: 'Company', content: 'Tab content for company', disabled: true },
10+
{ name: 'Team Members', content: 'Tab content for team members' },
11+
{ name: 'Billing', content: 'Tab content for billing' },
12+
]
13+
14+
let [manual, setManual] = useState(true)
15+
16+
return (
17+
<div className="flex flex-col items-start w-screen h-full p-12 bg-gray-50 space-y-12">
18+
<Switch.Group as="div" className="flex items-center space-x-4">
19+
<Switch.Label>Manual keyboard activation</Switch.Label>
20+
21+
<Switch
22+
as="button"
23+
checked={manual}
24+
onChange={setManual}
25+
className={({ checked }) =>
26+
classNames(
27+
'relative inline-flex flex-shrink-0 h-6 border-2 border-transparent rounded-full cursor-pointer w-11 focus:outline-none focus:shadow-outline transition-colors ease-in-out duration-200',
28+
checked ? 'bg-indigo-600' : 'bg-gray-200'
29+
)
30+
}
31+
>
32+
{({ checked }) => (
33+
<span
34+
className={classNames(
35+
'inline-block w-5 h-5 bg-white rounded-full transform transition ease-in-out duration-200',
36+
checked ? 'translate-x-5' : 'translate-x-0'
37+
)}
38+
/>
39+
)}
40+
</Switch>
41+
</Switch.Group>
42+
43+
<Tabs className="flex flex-col max-w-3xl w-full" as="div">
44+
<Tabs.List
45+
className="relative z-0 rounded-lg shadow flex divide-x divide-gray-200"
46+
lazy={manual}
47+
>
48+
{tabs.map((tab, tabIdx) => (
49+
<Tabs.Tab
50+
key={tab.name}
51+
disabled={tab.disabled}
52+
className={({ selected }) =>
53+
classNames(
54+
selected ? 'text-gray-900' : 'text-gray-500 hover:text-gray-700',
55+
tabIdx === 0 ? 'rounded-l-lg' : '',
56+
tabIdx === tabs.length - 1 ? 'rounded-r-lg' : '',
57+
tab.disabled && 'opacity-50',
58+
'group relative min-w-0 flex-1 overflow-hidden bg-white py-4 px-4 text-sm font-medium text-center hover:bg-gray-50 focus:z-10'
59+
)
60+
}
61+
>
62+
{({ selected }) => (
63+
<>
64+
<span>{tab.name}</span>
65+
{tab.disabled && <small className="inline-block px-4 text-xs">(disabled)</small>}
66+
<span
67+
aria-hidden="true"
68+
className={classNames(
69+
selected ? 'bg-indigo-500' : 'bg-transparent',
70+
'absolute inset-x-0 bottom-0 h-0.5'
71+
)}
72+
/>
73+
</>
74+
)}
75+
</Tabs.Tab>
76+
))}
77+
</Tabs.List>
78+
79+
<Tabs.Panels className="mt-4">
80+
{tabs.map(tab => (
81+
<Tabs.Panel className="bg-white rounded-lg p-4 shadow" key={tab.name}>
82+
{tab.content}
83+
</Tabs.Panel>
84+
))}
85+
</Tabs.Panels>
86+
</Tabs>
87+
</div>
88+
)
89+
}

0 commit comments

Comments
 (0)