{"version":3,"file":"DropdownItem.cjs","sources":["../../../../src/components/Dropdown/DropdownItem.tsx"],"sourcesContent":["\"use client\";\n\nimport { useListItem, useMergeRefs } from \"@floating-ui/react\";\nimport { forwardRef, type ComponentProps, type ElementType, type FC, type RefCallback } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport type { PolymorphicComponentPropWithRef, PolymorphicRef } from \"../../helpers/generic-as-prop\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport type { DeepPartial } from \"../../types\";\nimport { ButtonBase, type ButtonBaseProps } from \"../Button/ButtonBase\";\nimport { useDropdownContext } from \"./DropdownContext\";\n\nexport interface FlowbiteDropdownItemTheme {\n  container: string;\n  base: string;\n  icon: string;\n}\n\nexport type DropdownItemProps<T extends ElementType = \"button\"> = PolymorphicComponentPropWithRef<\n  T,\n  {\n    href?: string;\n    icon?: FC<ComponentProps<\"svg\">>;\n    onClick?: () => void;\n    theme?: DeepPartial<FlowbiteDropdownItemTheme>;\n  }\n>;\n\ntype DropdownItemType = (<C extends ElementType = \"button\">(props: DropdownItemProps<C>) => JSX.Element) & {\n  displayName?: string;\n};\n\nexport const DropdownItem = forwardRef(\n  <T extends ElementType = \"button\">(\n    { children, className, icon: Icon, onClick, theme: customTheme = {}, ...props }: DropdownItemProps<T>,\n    forwardedRef: PolymorphicRef<T>,\n  ) => {\n    const { ref: listItemRef, index } = useListItem({ label: typeof children === \"string\" ? children : undefined });\n    const ref = useMergeRefs([forwardedRef, listItemRef]);\n    const { theme: rootTheme, activeIndex, dismissOnClick, getItemProps, handleSelect } = useDropdownContext();\n    const isActive = activeIndex === index;\n    const theme = mergeDeep(rootTheme.floating.item, customTheme);\n\n    const theirProps = props as ButtonBaseProps<T>;\n\n    return (\n      <li role=\"menuitem\" className={theme.container}>\n        <ButtonBase\n          ref={ref as RefCallback<T>}\n          className={twMerge(theme.base, className)}\n          {...theirProps}\n          {...getItemProps({\n            onClick: () => {\n              onClick?.();\n              dismissOnClick && handleSelect(null);\n            },\n          })}\n          tabIndex={isActive ? 0 : -1}\n        >\n          {Icon && <Icon className={theme.icon} />}\n          {children}\n        </ButtonBase>\n      </li>\n    );\n  },\n) as DropdownItemType;\n\nDropdownItem.displayName = \"DropdownItem\";\n"],"names":["forwardRef","useListItem","useMergeRefs","useDropdownContext","mergeDeep","jsx","jsxs","ButtonBase","twMerge"],"mappings":";;;;;;;;;;AASY,MAAC,YAAY,GAAGA,gBAAU;AACtC,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,YAAY,KAAK;AACrG,IAAI,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAGC,iBAAW,CAAC,EAAE,KAAK,EAAE,OAAO,QAAQ,KAAK,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;AACjH,IAAI,MAAM,GAAG,GAAGC,kBAAY,CAAC,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;AAC1D,IAAI,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,GAAGC,kCAAkB,EAAE,CAAC;AAC/G,IAAI,MAAM,QAAQ,GAAG,WAAW,KAAK,KAAK,CAAC;AAC3C,IAAI,MAAM,KAAK,GAAGC,mBAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAClE,IAAI,MAAM,UAAU,GAAG,KAAK,CAAC;AAC7B,IAAI,uBAAuBC,cAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,kBAAkBC,eAAI;AACnH,MAAMC,qBAAU;AAChB,MAAM;AACN,QAAQ,GAAG;AACX,QAAQ,SAAS,EAAEC,qBA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