2022-06-22 16:35:50 +00:00
|
|
|
import React, { Fragment } from 'react'
|
2021-12-18 06:37:05 +00:00
|
|
|
import { Menu, Transition } from '@headlessui/react'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
export type MenuItem = {
|
|
|
|
name: string
|
|
|
|
href: string
|
|
|
|
onClick?: () => void
|
|
|
|
}
|
|
|
|
|
2021-12-18 06:37:05 +00:00
|
|
|
export function MenuButton(props: {
|
2022-06-03 00:40:41 +00:00
|
|
|
buttonContent: JSX.Element
|
2022-06-22 16:35:50 +00:00
|
|
|
menuItems: MenuItem[]
|
2021-12-18 06:37:05 +00:00
|
|
|
className?: string
|
|
|
|
}) {
|
|
|
|
const { buttonContent, menuItems, className } = props
|
|
|
|
return (
|
2022-06-22 16:35:50 +00:00
|
|
|
<Menu
|
|
|
|
as="div"
|
|
|
|
className={clsx(className ? className : 'relative z-40 flex-shrink-0')}
|
|
|
|
>
|
2021-12-18 06:37:05 +00:00
|
|
|
<div>
|
2022-03-31 05:35:20 +00:00
|
|
|
<Menu.Button className="w-full rounded-full">
|
2021-12-18 06:37:05 +00:00
|
|
|
<span className="sr-only">Open user menu</span>
|
|
|
|
{buttonContent}
|
|
|
|
</Menu.Button>
|
|
|
|
</div>
|
|
|
|
<Transition
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-out duration-100"
|
|
|
|
enterFrom="transform opacity-0 scale-95"
|
|
|
|
enterTo="transform opacity-100 scale-100"
|
|
|
|
leave="transition ease-in duration-75"
|
|
|
|
leaveFrom="transform opacity-100 scale-100"
|
|
|
|
leaveTo="transform opacity-0 scale-95"
|
|
|
|
>
|
2022-06-22 16:35:50 +00:00
|
|
|
<Menu.Items className="absolute left-0 mt-2 w-40 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
|
2021-12-18 06:37:05 +00:00
|
|
|
{menuItems.map((item) => (
|
2022-06-22 16:35:50 +00:00
|
|
|
<Menu.Item key={item.href}>
|
2021-12-18 06:37:05 +00:00
|
|
|
{({ active }) => (
|
|
|
|
<a
|
|
|
|
href={item.href}
|
2021-12-31 20:33:05 +00:00
|
|
|
target={item.href.startsWith('http') ? '_blank' : undefined}
|
2021-12-19 23:56:22 +00:00
|
|
|
onClick={item.onClick}
|
2021-12-18 06:37:05 +00:00
|
|
|
className={clsx(
|
|
|
|
active ? 'bg-gray-100' : '',
|
2022-06-22 16:35:50 +00:00
|
|
|
'line-clamp-3 block py-1.5 px-4 text-sm text-gray-700'
|
2021-12-18 06:37:05 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
{item.name}
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</Menu.Item>
|
|
|
|
))}
|
|
|
|
</Menu.Items>
|
|
|
|
</Transition>
|
|
|
|
</Menu>
|
|
|
|
)
|
|
|
|
}
|