Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Graph Mindset] Implement Hover Component #2500

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/components/mindset/components/HoverCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
import { colors } from '~/utils/colors'

type Props = {
title?: string
description?: string
}

export const HoverCard = ({ title, description }: Props) => (
<Portal>
<TooltipContainer>
<ContentWrapper>
<Title>{title}</Title>
{description && <Description>{description}</Description>}
</ContentWrapper>
</TooltipContainer>
</Portal>
)

const Portal = styled.div`
position: fixed;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 1000;
`

const TooltipContainer = styled(Flex)`
width: 390px;
min-height: 100px;
background: ${colors.HOVER_CARD_BG};
border-radius: 8px;
padding: 15px;
padding-bottom: 3px !important;
position: fixed;
flex-direction: column;
gap: 4px;
top: calc(-230px);
left: 100%;
z-index: 1000;
margin-left: 450px;
pointer-events: auto;
`

const ContentWrapper = styled(Flex)`
margin-top: 0;
flex-direction: column;
gap: 4px;
`

const Title = styled(Text)`
font-family: Barlow;
font-size: 20px;
font-weight: 600;
line-height: 24px;
color: ${colors.white};
margin: 0;
`

const Description = styled(Text)`
font-family: Barlow;
font-size: 14px;
font-weight: 400;
line-height: 20px;
color: ${colors.white};
margin: 0;
opacity: 0.8;
`
50 changes: 27 additions & 23 deletions src/components/mindset/components/Scene/Board/Node/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Html } from '@react-three/drei'
import { useThree } from '@react-three/fiber'
import { memo } from 'react'
import { memo, useState } from 'react'
import { Flex } from '~/components/common/Flex'
import { HoverCard } from '../../../HoverCard'
import { RoundedRectangle } from '../RoundedRectangle'
import { Content } from './Content'
import { Image } from './Image'
Expand All @@ -15,10 +16,12 @@ type Props = {
name: string
type: string
color: string
description?: string
}

export const Node = memo(({ width, height, position, url, onButtonClick, name, type, color }: Props) => {
export const Node = memo(({ width, height, position, url, onButtonClick, name, type, color, description }: Props) => {
const { camera } = useThree()
const [isHovered, setIsHovered] = useState(false)

return (
<group position={position}>
Expand All @@ -27,27 +30,28 @@ export const Node = memo(({ width, height, position, url, onButtonClick, name, t
{false && <Image height={height} url={url} width={width} />}

{/* Html */}
{true && (
<Html position={[-width / 2, height / 2, 0]}>
<Flex
onClick={() => onButtonClick()}
style={{
fontSize: '12px',
color: 'white',
fontWeight: 600,
width: `${width * camera.zoom}px`,
height: `${height * camera.zoom}px`,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderRadius: '8px',
pointerEvents: 'auto', // Allow interaction with the HTML element
}}
>
<Content name={`${name}`} type={type || ''} url={url} />
</Flex>
</Html>
)}
<Html position={[-width / 2, height / 2, 0]}>
<Flex
onClick={() => onButtonClick()}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
style={{
fontSize: '12px',
color: 'white',
fontWeight: 600,
width: `${width * camera.zoom}px`,
height: `${height * camera.zoom}px`,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderRadius: '8px',
pointerEvents: 'auto',
}}
>
<Content name={`${name}`} type={type || ''} url={url} />
{isHovered && <HoverCard description={description} title={name} />}
</Flex>
</Html>
</group>
)
})
Expand Down
2 changes: 2 additions & 0 deletions src/components/mindset/components/Scene/Board/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@
<Fragment key={node.ref_id}>
<Node
color="#353A46"
description={node?.properties?.description}
height={nodeHeight}
name={node?.properties?.name || ''}
onButtonClick={console.log}

Check warning on line 128 in src/components/mindset/components/Scene/Board/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement

Check warning on line 128 in src/components/mindset/components/Scene/Board/index.tsx

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement
position={[node.x, node.y, node.z]}
type={node.node_type}
url={node?.properties?.image_url || 'logo.png'}
Expand All @@ -136,9 +137,10 @@
<Node
key={`${relatedNode.ref_id}-${node.ref_id}`}
color="#353A46"
description={relatedNode?.properties?.description}
height={nodeHeight}
name={relatedNode?.properties?.name || ''}
onButtonClick={console.log}

Check warning on line 143 in src/components/mindset/components/Scene/Board/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement
position={[relatedNode.x, relatedNode.y, relatedNode.z]}
type={relatedNode.node_type}
url={relatedNode?.properties?.image_url || 'logo.png'}
Expand Down
1 change: 1 addition & 0 deletions src/utils/colors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const colors = {
DIVIDER_4: 'rgba(46, 55, 67, 1)',
INPUT_BG: 'rgba(255, 255, 255, 0.05)',
INPUT_PLACEHOLDER: 'rgba(255, 255, 255, 0.5)',
HOVER_CARD_BG: 'rgba(41, 44, 54, 1)',
} as const

export type ColorName = keyof typeof colors
Loading