misc_pterodactyl-panel/resources/scripts/components/elements/dropdown/DropdownItem.tsx

44 lines
1.2 KiB
TypeScript
Raw Normal View History

import React, { forwardRef } from 'react';
import { Menu } from '@headlessui/react';
import styles from './dropdown.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-02-27 02:26:53 +00:00
const DropdownItem = forwardRef<HTMLAnchorElement, Props>(({
disabled,
danger,
className,
onClick,
children,
icon: IconComponent,
}, ref) => {
return (
<Menu.Item disabled={disabled}>
2022-02-27 02:26:53 +00:00
{({ disabled, active }) => (
<a
ref={ref}
href={'#'}
2022-02-27 02:26:53 +00:00
className={classNames(styles.menu_item, {
[styles.danger]: danger,
[styles.disabled]: disabled,
}, className)}
onClick={onClick}
>
{IconComponent}
2022-02-27 02:26:53 +00:00
{typeof children === 'function' ? children({ disabled, active }) : children}
</a>
)}
</Menu.Item>
);
});
export default DropdownItem;