{"version":3,"sources":["../src/use-chart-tooltip.ts"],"sourcesContent":["import type { CSSUIObject, PropGetter } from \"@yamada-ui/core\"\nimport type { Dict } from \"@yamada-ui/utils\"\nimport type * as Recharts from \"recharts\"\nimport type { TooltipProps } from \"./chart.types\"\nimport { useTheme } from \"@yamada-ui/core\"\nimport { cx, splitObject } from \"@yamada-ui/utils\"\nimport { useCallback, useMemo } from \"react\"\nimport { getClassName } from \"./chart-utils\"\nimport { tooltipProperties } from \"./rechart-properties\"\n\nexport interface UseChartTooltipOptions {\n  /**\n   * A function to format labels on inside the tooltip.\n   */\n  labelFormatter?: (label: string) => string\n  /**\n   * Specifies the duration of animation, the unit of this option is ms.\n   *\n   * @default 0\n   */\n  tooltipAnimationDuration?: number\n  /**\n   * A function to format values on inside the tooltip.\n   */\n  valueFormatter?: (value: any) => string\n  /**\n   * Props passed down to recharts 'Tooltip' component.\n   */\n  tooltipProps?: TooltipProps\n}\n\ninterface UseChartTooltipProps extends UseChartTooltipOptions {\n  styles: Dict<CSSUIObject | undefined>\n}\n\nexport const useChartTooltip = ({\n  styles,\n  tooltipAnimationDuration = 0,\n  tooltipProps: _tooltipProps = {},\n}: UseChartTooltipProps) => {\n  const { theme } = useTheme()\n  const { cursor, ...rest } = _tooltipProps\n  const cursorClassName = useMemo(\n    () => getClassName({ ...styles.cursor, ...cursor })(theme),\n    [cursor, styles.cursor, theme],\n  )\n\n  const [tooltipProps, tooltipUIProps] = splitObject<Dict, string>(\n    rest,\n    tooltipProperties,\n  )\n\n  const getTooltipProps: PropGetter<\n    Partial<Recharts.TooltipProps<any, any>>,\n    Recharts.TooltipProps<any, any>\n  > = useCallback(\n    (props, ref = null) => ({\n      ref,\n      animationDuration: tooltipAnimationDuration,\n      cursor: {\n        className: cx(\"ui-chart__cursor\", cursorClassName),\n      },\n      isAnimationActive: (tooltipAnimationDuration || 0) > 0,\n      ...props,\n      ...tooltipProps,\n    }),\n    [cursorClassName, tooltipAnimationDuration, tooltipProps],\n  )\n\n  return { getTooltipProps, tooltipProps: tooltipUIProps }\n}\n"],"mappings":";;;;;;;;;AAIA,SAAS,gBAAgB;AACzB,SAAS,IAAI,mBAAmB;AAChC,SAAS,aAAa,eAAe;AA6B9B,IAAM,kBAAkB,CAAC;AAAA,EAC9B;AAAA,EACA,2BAA2B;AAAA,EAC3B,cAAc,gBAAgB,CAAC;AACjC,MAA4B;AAC1B,QAAM,EAAE,MAAM,IAAI,SAAS;AAC3B,QAAM,EAAE,QAAQ,GAAG,KAAK,IAAI;AAC5B,QAAM,kBAAkB;AAAA,IACtB,MAAM,aAAa,EAAE,GAAG,OAAO,QAAQ,GAAG,OAAO,CAAC,EAAE,KAAK;AAAA,IACzD,CAAC,QAAQ,OAAO,QAAQ,KAAK;AAAA,EAC/B;AAEA,QAAM,CAAC,cAAc,cAAc,IAAI;AAAA,IACrC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,kBAGF;AAAA,IACF,CAAC,OAAO,MAAM,UAAU;AAAA,MACtB;AAAA,MACA,mBAAmB;AAAA,MACnB,QAAQ;AAAA,QACN,WAAW,GAAG,oBAAoB,eAAe;AAAA,MACnD;AAAA,MACA,oBAAoB,4BAA4B,KAAK;AAAA,MACrD,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,IACA,CAAC,iBAAiB,0BAA0B,YAAY;AAAA,EAC1D;AAEA,SAAO,EAAE,iBAAiB,cAAc,eAAe;AACzD;","names":[]}