Last active
June 27, 2023 16:53
-
-
Save horaciosystem/a5100f6b1d9b297c2e39d7f816c5c972 to your computer and use it in GitHub Desktop.
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
const DefaultRenderAnimationOutput = ({name, count}) => { | |
return ( | |
<> | |
<span className="RenderAnimation-name">{name} </span> | |
<span className="RenderAnimation-count">{count}</span> | |
</> | |
); | |
}; | |
function useRenderAnimation( | |
name, | |
animationName, | |
renderOutput = DefaultRenderAnimationOutput | |
) { | |
const renders = React.useRef(1); | |
const ref = React.createRef(); | |
React.useEffect(() => { | |
renders.current = renders.current + 1; | |
ref.current.style.animation = `${animationName} 750ms ease-out`; | |
ref.current.onanimationend = () => { | |
if (ref.current) { | |
ref.current.style.animation = null; | |
} | |
}; | |
}); | |
const renderCounter = ( | |
<div className="RenderAnimation" ref={ref}> | |
{renderOutput(name, renders.current)} | |
</div> | |
); | |
return { ref, renderCounter }; | |
} | |
function RenderWithHighlight({ name, children }) { | |
const animationName = "ContextPulse"; | |
const { renderCounter } = useRenderAnimation(name, animationName); | |
return ( | |
<div className="Block RenderCheck"> | |
{renderCounter} | |
<div className="RenderCheck-children">{children}</div> | |
</div> | |
); | |
} |
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
.RenderAnimation { | |
padding: 16px 24px; | |
border-radius: 0.25rem; | |
font-variant-numeric: tabular-nums; | |
} | |
.RenderAnimation-name { | |
font-weight: 600; | |
} | |
.RenderCheck-children { | |
padding: 10px 0 0 10px; | |
} | |
@keyframes ContextPulse { | |
0% { | |
background-color: var(--context-color); | |
} | |
100% { | |
background-color: var(--main-bg-color); | |
} | |
} | |
@keyframes RenderPulse { | |
0% { | |
background-color: var(--render-color); | |
} | |
100% { | |
background-color: var(--main-bg-color); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment