Skip to content

Commit

Permalink
perf: removed hidden styles
Browse files Browse the repository at this point in the history
  • Loading branch information
morellodev committed Jan 23, 2023
1 parent 7dfa3ab commit e3e6966
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions packages/lib/src/Reveal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import { getAnimationCss } from "./utils/animations";
import { isNullable, isStringLike } from "./utils/guards";
import { matchIf, matchIfOrNull } from "./utils/patterns";

function hideWhen(condition: boolean) {
return matchIfOrNull<CSSProperties>(() => ({ opacity: 0 }))(condition);
}

export interface RevealProps {
/**
* Stagger its children animations.
Expand Down Expand Up @@ -156,13 +152,9 @@ export const Reveal: React.FC<RevealProps> = (props) => {
ref={ref}
className={cx(childClassName, node.props.className)}
css={matchIfOrNull(() => animationStyles)(inView)}
style={Object.assign(
{},
childStyle,
node.props.style,
hideWhen(!inView),
{ animationDelay: nodeDelay + "ms" }
)}
style={Object.assign({}, childStyle, node.props.style, {
animationDelay: nodeDelay + "ms",
})}
/>
)}
</ClassNames>
Expand Down Expand Up @@ -247,9 +239,9 @@ const TextReveal: React.FC<
<span
key={index}
css={matchIfOrNull(() => animationStyles)(inView)}
style={Object.assign({}, hideWhen(!inView), {
style={{
animationDelay: delay + index * duration * damping + "ms",
})}
}}
>
{char}
</span>
Expand Down Expand Up @@ -284,7 +276,7 @@ const FragmentReveal: React.FC<
ref={ref}
className={className}
css={matchIfOrNull(() => animationStyles)(inView)}
style={Object.assign({}, style, hideWhen(!inView))}
style={style}
>
{children}
</div>
Expand Down

0 comments on commit e3e6966

Please sign in to comment.