UNPKG

@vertisanpro/flowbite-react

Version:

Non-Official React components built for Flowbite and Tailwind CSS

24 lines (23 loc) 1.3 kB
'use client'; import { useListItem } from '@floating-ui/react'; import { twMerge } from '@vertisanpro/tailwind-merge'; import React from 'react'; import { mergeDeep } from '../../helpers/merge-deep'; import { ButtonBase } from '../Button/ButtonBase'; import { useDropdownContext } from './DropdownContext'; export const DropdownItem = ({ children, className, icon: Icon, onClick, theme: customTheme = {}, ...props }) => { const { ref, index } = useListItem({ label: typeof children === 'string' ? children : undefined }); const { theme: rootTheme, activeIndex, dismissOnClick, getItemProps, handleSelect } = useDropdownContext(); const isActive = activeIndex === index; const theme = mergeDeep(rootTheme.floating.item, customTheme); const theirProps = props; return (React.createElement("li", { role: "menuitem", className: theme.container }, React.createElement(ButtonBase, { ref: ref, className: twMerge(theme.base, className), ...theirProps, ...getItemProps({ onClick: () => { onClick && onClick(); dismissOnClick && handleSelect(null); }, }), tabIndex: isActive ? 0 : -1 }, Icon && React.createElement(Icon, { className: theme.icon }), children))); };