|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { Tab, 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(false) |
| 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 | + <Tab.Group className="flex flex-col max-w-3xl w-full" as="div" manual={manual}> |
| 44 | + <Tab.List className="relative z-0 rounded-lg shadow flex divide-x divide-gray-200"> |
| 45 | + {tabs.map((tab, tabIdx) => ( |
| 46 | + <Tab |
| 47 | + key={tab.name} |
| 48 | + disabled={tab.disabled} |
| 49 | + className={({ selected }) => |
| 50 | + classNames( |
| 51 | + selected ? 'text-gray-900' : 'text-gray-500 hover:text-gray-700', |
| 52 | + tabIdx === 0 ? 'rounded-l-lg' : '', |
| 53 | + tabIdx === tabs.length - 1 ? 'rounded-r-lg' : '', |
| 54 | + tab.disabled && 'opacity-50', |
| 55 | + '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' |
| 56 | + ) |
| 57 | + } |
| 58 | + > |
| 59 | + {({ selected }) => ( |
| 60 | + <> |
| 61 | + <span>{tab.name}</span> |
| 62 | + {tab.disabled && <small className="inline-block px-4 text-xs">(disabled)</small>} |
| 63 | + <span |
| 64 | + aria-hidden="true" |
| 65 | + className={classNames( |
| 66 | + selected ? 'bg-indigo-500' : 'bg-transparent', |
| 67 | + 'absolute inset-x-0 bottom-0 h-0.5' |
| 68 | + )} |
| 69 | + /> |
| 70 | + </> |
| 71 | + )} |
| 72 | + </Tab> |
| 73 | + ))} |
| 74 | + </Tab.List> |
| 75 | + |
| 76 | + <Tab.Panels className="mt-4"> |
| 77 | + {tabs.map(tab => ( |
| 78 | + <Tab.Panel className="bg-white rounded-lg p-4 shadow" key={tab.name}> |
| 79 | + {tab.content} |
| 80 | + </Tab.Panel> |
| 81 | + ))} |
| 82 | + </Tab.Panels> |
| 83 | + </Tab.Group> |
| 84 | + </div> |
| 85 | + ) |
| 86 | +} |
0 commit comments