Skip to content

Commit 5f7e547

Browse files
committed
use explicit property to enable lazy loading and allow skeleteon element during the delay time
1 parent e0ad72c commit 5f7e547

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/components/OverviewItem/OverviewItemActions.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ export interface OverviewItemActionsProps extends React.HTMLAttributes<HTMLDivEl
77
* Display it only when the parent `OverviewItem` is hovered or focused.
88
*/
99
hiddenInteractions?: boolean;
10+
/**
11+
* Delay the rendering of the children by a time in milliseconds.
12+
* Could be used to prevent browser freezes for the initial `OverviewItem` rendering.
13+
*/
14+
delayDisplayChildren?: number;
15+
/**
16+
* Display element while the rendering of the actual children is delayed.
17+
*/
18+
delaySkeleton?: JSX.Element;
1019
}
1120

1221
/**
@@ -17,14 +26,18 @@ export const OverviewItemActions = ({
1726
children,
1827
className = "",
1928
hiddenInteractions = false,
29+
delayDisplayChildren = 0,
30+
delaySkeleton = <></>,
2031
...restProps
2132
}: OverviewItemActionsProps) => {
22-
const [showActions, setShowActions] = React.useState(!hiddenInteractions)
33+
const [showActions, setShowActions] = React.useState(!(delayDisplayChildren > 0));
2334

2435
React.useEffect(() => {
2536
// Delay rendering of item actions when they are hidden anyways, because rendering interaction elements like context menus currently has a large performance impact.
26-
setTimeout(() => setShowActions(true), 1)
27-
}, [])
37+
if (!showActions && delayDisplayChildren > 0) {
38+
setTimeout(() => setShowActions(true), delayDisplayChildren);
39+
}
40+
}, []);
2841

2942
return (
3043
<div
@@ -35,7 +48,7 @@ export const OverviewItemActions = ({
3548
(className ? ` ${className}` : "")
3649
}
3750
>
38-
{showActions ? children : null}
51+
{showActions ? children : delaySkeleton}
3952
</div>
4053
);
4154
};

0 commit comments

Comments
 (0)