Created
July 27, 2023 10:25
-
-
Save danielotieno/a6877967d53153d02b57fe34e73a4b7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This example requires some changes to your config: | |
``` | |
// tailwind.config.js | |
module.exports = { | |
// ... | |
plugins: [ | |
// ... | |
require('@tailwindcss/forms'), | |
], | |
} | |
``` | |
*/ | |
const tabs = [ | |
{ name: 'My Account', href: '#', current: false }, | |
{ name: 'Company', href: '#', current: false }, | |
{ name: 'Team Members', href: '#', current: true }, | |
{ name: 'Billing', href: '#', current: false }, | |
] | |
function classNames(...classes) { | |
return classes.filter(Boolean).join(' ') | |
} | |
export default function Example() { | |
return ( | |
<div> | |
<div className="sm:hidden"> | |
<label htmlFor="tabs" className="sr-only"> | |
Select a tab | |
</label> | |
{/* Use an "onChange" listener to redirect the user to the selected tab URL. */} | |
<select | |
id="tabs" | |
name="tabs" | |
className="block w-full rounded-md border-gray-300 py-2 pl-3 pr-10 text-base focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm" | |
defaultValue={tabs.find((tab) => tab.current).name} | |
> | |
{tabs.map((tab) => ( | |
<option key={tab.name}>{tab.name}</option> | |
))} | |
</select> | |
</div> | |
<div className="hidden sm:block"> | |
<div className="border-b border-gray-200"> | |
<nav className="-mb-px flex space-x-8" aria-label="Tabs"> | |
{tabs.map((tab) => ( | |
<a | |
key={tab.name} | |
href={tab.href} | |
className={classNames( | |
tab.current | |
? 'border-indigo-500 text-indigo-600' | |
: 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700', | |
'whitespace-nowrap border-b-2 py-4 px-1 text-sm font-medium' | |
)} | |
aria-current={tab.current ? 'page' : undefined} | |
> | |
{tab.name} | |
</a> | |
))} | |
</nav> | |
</div> | |
</div> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment