@@ -7,7 +7,7 @@ import { Box } from '../Box';
77
88export type TooltipProps = React . ComponentProps < typeof TooltipPrimitive . Root > &
99 React . ComponentProps < typeof TooltipPrimitive . Content > & {
10- children : React . ReactElement ;
10+ children : React . ReactElement | React . ReactNode ;
1111 content : React . ReactNode ;
1212 multiline ?: boolean ;
1313 css ?: CSS ;
@@ -33,6 +33,38 @@ const ArrowBox = styled(Box, {
3333 color : '$tooltipContentBg' ,
3434} ) ;
3535
36+ export const TooltipContent = ( { css, multiline, children, ...props } : Partial < TooltipProps > ) => {
37+ const isContentString = React . useMemo ( ( ) => typeof children === 'string' , [ children ] ) ;
38+ return (
39+ < Content css = { css } side = "top" align = "center" sideOffset = { 5 } { ...props } multiline = { multiline } >
40+ { isContentString ? (
41+ < Text
42+ size = "1"
43+ as = "p"
44+ css = { {
45+ color : 'currentColor' ,
46+ lineHeight : multiline ? '20px' : undefined ,
47+ } }
48+ >
49+ { children }
50+ </ Text >
51+ ) : (
52+ children
53+ ) }
54+ < ArrowBox >
55+ < TooltipPrimitive . Arrow
56+ offset = { 5 }
57+ width = { 11 }
58+ height = { 5 }
59+ style = { {
60+ fill : 'currentColor' ,
61+ } }
62+ />
63+ </ ArrowBox >
64+ </ Content >
65+ ) ;
66+ } ;
67+
3668export function Tooltip ( {
3769 children,
3870 content,
@@ -43,47 +75,20 @@ export function Tooltip({
4375 css,
4476 ...props
4577} : TooltipProps ) {
46- const isContentString = React . useMemo ( ( ) => typeof content === 'string' , [ content ] ) ;
4778 return (
4879 < TooltipPrimitive . Root open = { open } defaultOpen = { defaultOpen } onOpenChange = { onOpenChange } >
4980 < TooltipPrimitive . Trigger asChild > { children } </ TooltipPrimitive . Trigger >
5081 < TooltipPrimitive . Portal >
51- < Content
52- css = { css }
53- side = "top"
54- align = "center"
55- sideOffset = { 5 }
56- { ...props }
57- multiline = { multiline }
58- >
59- { isContentString ? (
60- < Text
61- size = "1"
62- as = "p"
63- css = { {
64- color : 'currentColor' ,
65- lineHeight : multiline ? '20px' : undefined ,
66- } }
67- >
68- { content }
69- </ Text >
70- ) : (
71- content
72- ) }
73- < ArrowBox >
74- < TooltipPrimitive . Arrow
75- offset = { 5 }
76- width = { 11 }
77- height = { 5 }
78- style = { {
79- fill : 'currentColor' ,
80- } }
81- />
82- </ ArrowBox >
83- </ Content >
82+ < TooltipContent css = { css } multiline = { multiline } { ...props } >
83+ { content }
84+ </ TooltipContent >
8485 </ TooltipPrimitive . Portal >
8586 </ TooltipPrimitive . Root >
8687 ) ;
8788}
8889
90+ export const TooltipRoot = TooltipPrimitive . Root ;
91+ export const TooltipTrigger = TooltipPrimitive . Trigger ;
92+ export const TooltipPortal = TooltipPrimitive . Portal ;
93+
8994export type TooltipVariants = VariantProps < typeof Tooltip > ;
0 commit comments