{"version":3,"file":"HoverCardTarget.cjs","names":["useProps","getSingleElementChild","useHoverCardContext","useMergedRef","getRefProp","Popover","cloneElement"],"sources":["../../../../src/components/HoverCard/HoverCardTarget/HoverCardTarget.tsx"],"sourcesContent":["import { cloneElement } from 'react';\nimport { useMergedRef } from '@mantine/hooks';\nimport { getRefProp, getSingleElementChild, useProps } from '../../../core';\nimport { Popover, PopoverTargetProps } from '../../Popover';\nimport { useHoverCardContext } from '../HoverCard.context';\n\nexport interface HoverCardTargetProps extends PopoverTargetProps {\n  /**\n   * Name of the prop to wrap event listeners in.\n   * Use when the target component expects event listeners in a nested object.\n   * For example, some components expect `componentProps={{ onMouseEnter, onMouseLeave }}`.\n   * @default undefined (event listeners passed directly to component)\n   */\n  eventPropsWrapperName?: string;\n}\n\nconst defaultProps = {\n  refProp: 'ref',\n} satisfies Partial<HoverCardTargetProps>;\n\nexport function HoverCardTarget(props: HoverCardTargetProps) {\n  const { children, refProp, eventPropsWrapperName, ...others } = useProps(\n    'HoverCardTarget',\n    defaultProps,\n    props\n  );\n\n  const child = getSingleElementChild(children);\n  if (!child) {\n    throw new Error(\n      'HoverCard.Target component children should be an element or a component that accepts ref. Fragments, strings, numbers and other primitive values are not supported'\n    );\n  }\n\n  const ctx = useHoverCardContext();\n  const childProps = child.props as any;\n  const targetRef = useMergedRef(getRefProp(child), ctx.assignTarget, ctx.reference);\n\n  const referenceProps = ctx.getReferenceProps(\n    eventPropsWrapperName ? childProps[eventPropsWrapperName] : childProps\n  );\n\n  const accessibleProps =\n    ctx.withRoles && ctx.role === 'tooltip'\n      ? {\n          'aria-describedby':\n            [childProps['aria-describedby'], ctx.opened ? ctx.dropdownId : null]\n              .filter(Boolean)\n              .join(' ') || undefined,\n        }\n      : undefined;\n\n  const clonedProps: any = {\n    ...(eventPropsWrapperName ? { [eventPropsWrapperName]: referenceProps } : referenceProps),\n    ...accessibleProps,\n    ref: targetRef,\n  };\n\n  return (\n    <Popover.Target refProp={refProp} {...others}>\n      {cloneElement(child, clonedProps)}\n    </Popover.Target>\n  );\n}\n\nHoverCardTarget.displayName = '@mantine/core/HoverCardTarget';\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,eAAe,EACnB,SAAS,MACX;AAEA,SAAgB,gBAAgB,OAA6B;CAC3D,MAAM,EAAE,UAAU,SAAS,uBAAuB,GAAG,WAAWA,kBAAAA,SAC9D,mBACA,cACA,KACF;CAEA,MAAM,QAAQC,iCAAAA,sBAAsB,QAAQ;CAC5C,IAAI,CAAC,OACH,MAAM,IAAI,MACR,oKACF;CAGF,MAAM,MAAMC,0BAAAA,oBAAoB;CAChC,MAAM,aAAa,MAAM;CACzB,MAAM,aAAA,GAAYC,eAAAA,aAAAA,CAAaC,qBAAAA,WAAW,KAAK,GAAG,IAAI,cAAc,IAAI,SAAS;CAEjF,MAAM,iBAAiB,IAAI,kBACzB,wBAAwB,WAAW,yBAAyB,UAC9D;CAEA,MAAM,kBACJ,IAAI,aAAa,IAAI,SAAS,YAC1B,EACE,oBACE,CAAC,WAAW,qBAAqB,IAAI,SAAS,IAAI,aAAa,IAAI,CAAC,CACjE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,KAAK,KAAA,EACpB,IACA,KAAA;CAEN,MAAM,cAAmB;EACvB,GAAI,wBAAwB,GAAG,wBAAwB,eAAe,IAAI;EAC1E,GAAG;EACH,KAAK;CACP;CAEA,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,gBAAAA,QAAQ,QAAT;EAAyB;EAAS,GAAI;EACnCC,WAAAA,GAAAA,MAAAA,aAAAA,CAAa,OAAO,WAAW;CAClB,CAAA;AAEpB;AAEA,gBAAgB,cAAc"}