UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 4.44 kB
{"version":3,"file":"tooltip.cjs","names":["createSlotComponent","tooltipStyle","Tooltip: FC<TooltipProps>","useTooltip","AnimatePresence","Portal","getPopupAnimationProps","motion"],"sources":["../../../../src/components/tooltip/tooltip.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, ReactNode } from \"react\"\nimport type { HTMLProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { HTMLMotionProps } from \"../motion\"\nimport type { PopupAnimationProps } from \"../popover\"\nimport type { PortalProps } from \"../portal\"\nimport type { TooltipStyle } from \"./tooltip.style\"\nimport type { UseTooltipProps } from \"./use-tooltip\"\nimport { AnimatePresence } from \"motion/react\"\nimport { createSlotComponent } from \"../../core\"\nimport { cast } from \"../../utils\"\nimport { motion } from \"../motion\"\nimport { getPopupAnimationProps } from \"../popover\"\nimport { Portal } from \"../portal\"\nimport { tooltipStyle } from \"./tooltip.style\"\nimport { useTooltip } from \"./use-tooltip\"\n\nexport interface TooltipProps\n extends UseTooltipProps,\n PropsWithChildren,\n PopupAnimationProps,\n ThemeProps<TooltipStyle> {\n /**\n * The content of the tooltip.\n */\n content?: ReactNode\n /**\n * The animation duration.\n *\n * @default 0.1\n */\n duration?: PopupAnimationProps[\"duration\"]\n /**\n * Props for content element.\n */\n contentProps?: HTMLMotionProps\n /**\n * Props for portal component.\n */\n portalProps?: Omit<PortalProps, \"children\">\n}\n\nconst {\n PropsContext: TooltipPropsContext,\n StyleContext,\n usePropsContext: useTooltipPropsContext,\n withContext,\n useRootComponentProps,\n} = createSlotComponent<TooltipProps, TooltipStyle>(\"tooltip\", tooltipStyle)\n\nexport { TooltipPropsContext, useTooltipPropsContext }\n\n/**\n * `Tooltip` is a component that displays short information, such as supplementary details for an element.\n *\n * @see https://yamada-ui.com/docs/components/tooltip\n */\nexport const Tooltip: FC<TooltipProps> = (props) => {\n const [\n context,\n {\n animationScheme = \"scale\",\n children,\n content,\n duration = 0.1,\n contentProps,\n portalProps,\n ...rest\n },\n ] = useRootComponentProps(props)\n const { open, getContentProps, getPositionerProps, getTriggerProps } =\n useTooltip(rest)\n\n if (!content) return children\n\n return (\n <StyleContext value={context}>\n <TooltipTrigger asChild {...getTriggerProps()}>\n {children}\n </TooltipTrigger>\n\n <AnimatePresence>\n {open ? (\n <Portal {...portalProps}>\n <TooltipPositioner {...getPositionerProps()}>\n <TooltipContent\n {...getPopupAnimationProps(animationScheme, duration)}\n {...cast<HTMLMotionProps>(\n getContentProps(cast<HTMLProps>(contentProps)),\n )}\n >\n {content}\n </TooltipContent>\n </TooltipPositioner>\n </Portal>\n ) : null}\n </AnimatePresence>\n </StyleContext>\n )\n}\n\ninterface TooltipPositionerProps extends HTMLStyledProps {}\n\nconst TooltipPositioner = withContext<\"div\", TooltipPositionerProps>(\n \"div\",\n \"positioner\",\n)()\n\ninterface TooltipTriggerProps extends HTMLStyledProps<\"button\"> {}\n\nconst TooltipTrigger = withContext<\"button\", TooltipTriggerProps>(\n \"button\",\n \"trigger\",\n)()\n\ninterface TooltipContentProps\n extends Omit<HTMLMotionProps, \"children\" | \"offset\" | \"transform\"> {}\n\nconst TooltipContent = withContext<\"div\", TooltipContentProps>(\n motion.div,\n \"content\",\n)()\n"],"mappings":";;;;;;;;;;;;;;;;;AA2CA,MAAM,EACJ,cAAc,qBACd,cACA,iBAAiB,wBACjB,aACA,0BACEA,6CAAgD,WAAWC,mCAAa;;;;;;AAS5E,MAAaC,WAA6B,UAAU;CAClD,MAAM,CACJ,SACA,EACE,kBAAkB,SAClB,UACA,SACA,WAAW,IACX,cACA,YACA,GAAG,UAEH,sBAAsB,MAAM;CAChC,MAAM,EAAE,MAAM,iBAAiB,oBAAoB,oBACjDC,+BAAW,KAAK;AAElB,KAAI,CAAC,QAAS,QAAO;AAErB,QACE,4CAAC;EAAa,OAAO;aACnB,2CAAC;GAAe;GAAQ,GAAI,iBAAiB;GAC1C;IACc,EAEjB,2CAACC,0CACE,OACC,2CAACC;GAAO,GAAI;aACV,2CAAC;IAAkB,GAAI,oBAAoB;cACzC,2CAAC;KACC,GAAIC,uCAAuB,iBAAiB,SAAS;KACrD,+CACE,4DAAgC,aAAa,CAAC,CAC/C;eAEA;MACc;KACC;IACb,GACP,OACY;GACL;;AAMnB,MAAM,oBAAoB,YACxB,OACA,aACD,EAAE;AAIH,MAAM,iBAAiB,YACrB,UACA,UACD,EAAE;AAKH,MAAM,iBAAiB,YACrBC,uBAAO,KACP,UACD,EAAE"}