-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f24bc83
commit b4ff1f4
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*! | ||
* Copyright 2023 Cognite AS | ||
*/ | ||
|
||
import React, { JSX, useState, useEffect, useRef } from 'react'; | ||
|
||
import { Vector3 } from 'three'; | ||
|
||
import { useReveal } from '../RevealContainer/RevealContext'; | ||
|
||
import { HtmlOverlayTool } from '@cognite/reveal/tools'; | ||
|
||
import styled from 'styled-components'; | ||
|
||
export type InfoCardProps = { | ||
card: JSX.Element; | ||
position: Vector3; | ||
}; | ||
|
||
export const InfoCard = ({ | ||
card, | ||
position | ||
}: InfoCardProps): JSX.Element => { | ||
const viewer = useReveal(); | ||
|
||
const divReference = useRef<HTMLDivElement>(null); | ||
const [htmlTool, _setHtmlTool] = useState<HtmlOverlayTool>(new HtmlOverlayTool(viewer)); | ||
const htmlElement = (<div ref={divReference}> {card} </div>); | ||
|
||
useEffect(() => { | ||
if (divReference.current === null) return; | ||
const innerElement = divReference.current; | ||
|
||
htmlTool.add(innerElement, position); | ||
|
||
return () => htmlTool.remove(innerElement); | ||
}, [card, htmlTool, divReference.current]); | ||
|
||
return htmlElement; | ||
} | ||
|
||
export const FloatingDiv = styled.div` | ||
position: absolute; | ||
` |