2022-11-25 20:25:03 +00:00
|
|
|
import { forwardRef } from 'react';
|
|
|
|
import * as React from 'react';
|
2022-06-05 18:56:42 +00:00
|
|
|
import { Menu } from '@headlessui/react';
|
|
|
|
import styles from './style.module.css';
|
|
|
|
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-06-26 19:13:52 +00:00
|
|
|
const DropdownItem = forwardRef<HTMLAnchorElement, Props>(
|
|
|
|
({ disabled, danger, className, onClick, children, icon: IconComponent }, ref) => {
|
|
|
|
return (
|
|
|
|
<Menu.Item disabled={disabled}>
|
|
|
|
{({ disabled, active }) => (
|
|
|
|
<a
|
|
|
|
ref={ref}
|
|
|
|
href={'#'}
|
|
|
|
className={classNames(
|
|
|
|
styles.menu_item,
|
|
|
|
{
|
|
|
|
[styles.danger]: danger,
|
|
|
|
[styles.disabled]: disabled,
|
|
|
|
},
|
2022-11-25 20:25:03 +00:00
|
|
|
className,
|
2022-06-26 19:13:52 +00:00
|
|
|
)}
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
|
|
|
{IconComponent}
|
|
|
|
{typeof children === 'function' ? children({ disabled, active }) : children}
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</Menu.Item>
|
|
|
|
);
|
2022-11-25 20:25:03 +00:00
|
|
|
},
|
2022-06-26 19:13:52 +00:00
|
|
|
);
|
2022-06-05 18:56:42 +00:00
|
|
|
|
|
|
|
export default DropdownItem;
|