2022-02-26 20:13:13 +00:00
|
|
|
import React, { forwardRef } from 'react';
|
|
|
|
import { Menu } from '@headlessui/react';
|
2022-02-26 22:05:30 +00:00
|
|
|
import styles from './dropdown.module.css';
|
2022-02-26 20:13:13 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
children: React.ReactNode | ((opts: { active: boolean; disabled: boolean }) => JSX.Element);
|
|
|
|
danger?: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
className?: string;
|
|
|
|
icon?: JSX.Element;
|
|
|
|
onClick?: (e: React.MouseEvent) => void;
|
|
|
|
}
|
|
|
|
|
2022-02-27 02:26:53 +00:00
|
|
|
const DropdownItem = forwardRef<HTMLAnchorElement, Props>(({
|
|
|
|
disabled,
|
|
|
|
danger,
|
|
|
|
className,
|
|
|
|
onClick,
|
|
|
|
children,
|
|
|
|
icon: IconComponent,
|
|
|
|
}, ref) => {
|
2022-02-26 20:13:13 +00:00
|
|
|
return (
|
|
|
|
<Menu.Item disabled={disabled}>
|
2022-02-27 02:26:53 +00:00
|
|
|
{({ disabled, active }) => (
|
2022-02-26 20:13:13 +00:00
|
|
|
<a
|
|
|
|
ref={ref}
|
|
|
|
href={'#'}
|
2022-02-27 02:26:53 +00:00
|
|
|
className={classNames(styles.menu_item, {
|
|
|
|
[styles.danger]: danger,
|
|
|
|
[styles.disabled]: disabled,
|
|
|
|
}, className)}
|
2022-02-26 20:13:13 +00:00
|
|
|
onClick={onClick}
|
|
|
|
>
|
|
|
|
{IconComponent}
|
2022-02-27 02:26:53 +00:00
|
|
|
{typeof children === 'function' ? children({ disabled, active }) : children}
|
2022-02-26 20:13:13 +00:00
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</Menu.Item>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default DropdownItem;
|