Skip to content

Instantly share code, notes, and snippets.

@zeing
Created May 1, 2021 06:55
Show Gist options
  • Select an option

  • Save zeing/7cfe4e079b3790664806019be0ea8d77 to your computer and use it in GitHub Desktop.

Select an option

Save zeing/7cfe4e079b3790664806019be0ea8d77 to your computer and use it in GitHub Desktop.
Tab Tailwindcss + React
import classnames from 'classnames'
const Tab = ({ menus, value, onChange }) => {
return (
<nav className="flex justify-between sm:justify-start mx-auto container bg-white shadow-md">
{menus.map((menu, index) => (
<button
onClick={() => onChange?.(menu)}
disabled={menu?.disabled}
key={index}
className={classnames(
menu?.disabled ? 'cursor-not-allowed' : 'hover:text-error',
'py-4 px-6 block font-semibold flex-1 sm:flex-initial',
'hover:border-b-2 hover:border-primary transition duration-200 ease-in',
value === menu.name
? 'text-primary border-b-2 border-primary'
: 'text-secondary border-b-2 border-transparent',
)}
>
{menu.name}
</button>
))}
</nav>
)
}
export default Tab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment