1- import { chakra , Flex } from '@chakra-ui/react' ;
1+ import { Box , chakra , Flex , Separator } from '@chakra-ui/react' ;
22import React from 'react' ;
33
44import type { EntityTag } from './types' ;
@@ -15,8 +15,23 @@ interface Props {
1515}
1616
1717const EntityTagTooltip = ( { data, children } : Props ) => {
18+ const hasPopover = Boolean (
19+ data . meta ?. tooltipIcon ||
20+ data . meta ?. tooltipTitle ||
21+ data . meta ?. tooltipDescription ||
22+ data . meta ?. tooltipUrl ||
23+ data . meta ?. tooltipAttribution ,
24+ ) ;
25+
1826 const link = makePrettyLink ( data . meta ?. tooltipUrl ) ;
19- const hasPopover = Boolean ( data . meta ?. tooltipIcon || data . meta ?. tooltipTitle || data . meta ?. tooltipDescription || data . meta ?. tooltipUrl ) ;
27+
28+ const attribution = React . useMemo ( ( ) => {
29+ if ( ! data . meta ?. tooltipAttribution ) {
30+ return ;
31+ }
32+ const link = makePrettyLink ( data . meta ?. tooltipAttribution ) ;
33+ return link ?? data . meta . tooltipAttribution ;
34+ } , [ data . meta ?. tooltipAttribution ] ) ;
2035
2136 const handleLinkClick = React . useCallback ( ( ) => {
2237 if ( ! data . meta ?. tooltipUrl ) {
@@ -36,16 +51,30 @@ const EntityTagTooltip = ({ data, children }: Props) => {
3651 }
3752
3853 const content = (
39- < Flex textStyle = "sm" flexDir = "column" rowGap = { 2 } textAlign = "left" className = "dark" >
40- { ( data . meta ?. tooltipIcon || data . meta ?. tooltipTitle ) && (
41- < Flex columnGap = { 3 } alignItems = "center" >
42- { data . meta ?. tooltipIcon && < Image src = { data . meta . tooltipIcon } boxSize = "30px" alt = { `${ data . name } tag logo` } /> }
43- { data . meta ?. tooltipTitle && < chakra . span fontWeight = "600" > { data . meta . tooltipTitle } </ chakra . span > }
44- </ Flex >
45- ) }
46- { data . meta ?. tooltipDescription && < chakra . span > { data . meta . tooltipDescription } </ chakra . span > }
47- { link && < Link external href = { link . href } onClick = { handleLinkClick } > { link . domain } </ Link > }
48- </ Flex >
54+ < Box className = "dark" >
55+ < Flex textStyle = "sm" flexDir = "column" rowGap = { 2 } textAlign = "left" _empty = { { display : 'none' } } >
56+ { ( data . meta ?. tooltipIcon || data . meta ?. tooltipTitle ) && (
57+ < Flex columnGap = { 3 } alignItems = "center" >
58+ { data . meta ?. tooltipIcon && < Image src = { data . meta . tooltipIcon } boxSize = "30px" alt = { `${ data . name } tag logo` } /> }
59+ { data . meta ?. tooltipTitle && < chakra . span fontWeight = "600" > { data . meta . tooltipTitle } </ chakra . span > }
60+ </ Flex >
61+ ) }
62+ { data . meta ?. tooltipDescription && < chakra . span > { data . meta . tooltipDescription } </ chakra . span > }
63+ { link && < Link external href = { link . href } onClick = { handleLinkClick } > { link . domain } </ Link > }
64+ </ Flex >
65+ { attribution ? (
66+ < >
67+ { ( data . meta ?. tooltipIcon || data . meta ?. tooltipTitle || data . meta ?. tooltipDescription || link ) && < Separator mt = { 2 } mb = { 1 } /> }
68+ < Flex alignItems = "center" color = "text.secondary" textStyle = "xs" >
69+ < chakra . span mr = { 2 } > Source:</ chakra . span >
70+ { data . meta ?. tooltipAttributionIcon && < Image src = { data . meta . tooltipAttributionIcon } boxSize = { 4 } mr = { 1 } zIndex = { 1 } /> }
71+ { typeof attribution === 'string' ?
72+ < chakra . span fontWeight = "500" > { attribution } </ chakra . span > :
73+ < Link external href = { attribution . href } > { attribution . domain } </ Link > }
74+ </ Flex >
75+ </ >
76+ ) : null }
77+ </ Box >
4978 ) ;
5079
5180 return (
0 commit comments