import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
import classNames from 'classnames';
import type { ReactNode } from 'react';
import { forwardRef } from 'react';
import { Icon } from '../icon';
const itemClass = classNames(
'relative flex items-center justify-between rounded-sm p-2 text-sm',
'cursor-default hover:cursor-pointer',
'hover:bg-white dark:hover:bg-neutral-200',
'focus:bg-white dark:focus:bg-neutral-200',
'select-none',
'whitespace-nowrap'
);
type DropdownMenuProps = DropdownMenuPrimitive.DropdownMenuProps & {
trigger: ReactNode;
};
/**
* Contains all the parts of a dropdown menu.
*/
export const DropdownMenu = ({
children,
trigger,
...props
}: DropdownMenuProps) => {
return (
{trigger}
{children}
);
};
/**
* The button that toggles the dropdown menu.
* By default, the {@link DropdownMenuContent} will position itself against the trigger.
*/
export const DropdownMenuTrigger = forwardRef<
React.ElementRef,
React.ComponentProps
>(({ className, children, ...props }, forwardedRef) => {
const triggerClasses = classNames(
className,
'text-sm py-1 px-2 rounded bg-transparent border border-neutral-500 whitespace-nowrap',
'hover:bg-neutral-500/20 dark:hover:bg-neutral-500/40'
);
return (
);
});
/**
* Used to group multiple {@link DropdownMenuRadioItem}s.
*/
export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
/**
* The component that pops out when the dropdown menu is open.
*/
export const DropdownMenuContent = forwardRef<
React.ElementRef,
React.ComponentProps
>(({ className, ...contentProps }, forwardedRef) => (
));
/**
* The component that contains the dropdown menu items.
*/
export const DropdownMenuItem = forwardRef<
React.ElementRef,
React.ComponentProps
>(({ className, ...itemProps }, forwardedRef) => (
));
/**
* An item that can be controlled and rendered like a checkbox.
*/
export const DropdownMenuCheckboxItem = forwardRef<
React.ElementRef,
React.ComponentProps
>(({ className, ...checkboxItemProps }, forwardedRef) => (
));
/**
* An item that can be controlled and rendered like a radio.
*/
export const DropdownMenuRadioItem = forwardRef<
React.ElementRef,
React.ComponentProps & {
inset?: boolean;
}
>(({ className, inset = false, ...radioItemprops }, forwardedRef) => (
));
/**
* Renders when the parent {@link DropdownMenuCheckboxItem} or {@link DropdownMenuRadioItem} is checked.
* You can style this element directly, or you can use it as a wrapper to put an icon into, or both.
*/
export const DropdownMenuItemIndicator = forwardRef<
React.ElementRef,
React.ComponentProps
>(({ ...itemIndicatorProps }, forwardedRef) => (
));
/**
* Used to visually separate items in the dropdown menu.
*/
export const DropdownMenuSeparator = forwardRef<
React.ElementRef,
React.ComponentProps
>(({ className, ...separatorProps }, forwardedRef) => (
));