Skip to content

Commit

Permalink
fix(react-frames): Illuminator rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
romelperez committed Apr 27, 2024
1 parent 0127be7 commit 0696754
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 24 additions & 6 deletions packages/react-frames/src/Illuminator/Illuminator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,34 @@ const Illuminator = (props: IlluminatorProps): ReactElement => {
const element = elementRef.current!
const parentElement = element.parentElement as Element

let bounds: DOMRect
let x: number
let y: number
let isVisible: boolean
let opacity: string

const onMove = (event: MouseEvent): void => {
const bounds = parentElement.getBoundingClientRect()
const x = event.clientX - bounds.left
const y = event.clientY - bounds.top
element.style.opacity = '1'
element.style.transform = `translate(calc(${x}px - 50%), calc(${y}px - 50%))`
bounds = parentElement.getBoundingClientRect()
x = event.clientX - bounds.left
y = event.clientY - bounds.top
isVisible =
x >= -(size / 2) &&
x <= bounds.width + size / 2 &&
y >= -(size / 2) &&
y <= bounds.height + size / 2
opacity = isVisible ? '1' : '0'

if (element.style.opacity !== opacity) element.style.opacity = opacity

if (isVisible) {
element.style.transform = `translate(calc(${x}px - 50%), calc(${y}px - 50%))`
}
}

const onHide = (): void => {
element.style.opacity = '0'
if (element.style.opacity !== '0') {
element.style.opacity = '0'
}
}

document.addEventListener('mousemove', onMove)
Expand Down
2 changes: 2 additions & 0 deletions packages/react-frames/src/IlluminatorSVG/IlluminatorSVG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const IlluminatorSVG = (props: IlluminatorSVGProps): ReactElement => {
const gradientId = useId()
const circleElementRef = useRef<SVGCircleElement>(null)

// TODO: Prevent updates on the element if it is out of bounds.

useEffect(() => {
const element = circleElementRef.current!
const svg = element.parentElement?.parentElement as unknown as SVGSVGElement // TODO:
Expand Down

0 comments on commit 0696754

Please sign in to comment.