import React from "react"; import { loremIpsum } from "react-lorem-ipsum"; import { ApplicationContainer, Button, ContextMenu, Depiction, Icon, IconButton, OverflowText, OverviewItem, OverviewItemActions, OverviewItemDescription, OverviewItemLine, OverviewItemList, Spinner, Tooltip, } from "./../../../../index"; import { Default as ContextMenuExample } from "./../../ContextOverlay/ContextMenu.stories"; import canonicalIcons, { ValidIconName } from "./../../Icon/canonicalIconNames"; interface OverviewItemListPerformanceProps { /** list length */ length: number; /** include `OverviewItem` elements in list */ useOverviewitem: boolean; /** include depiction */ withDepiction: boolean; /** include description */ withDescription: boolean; /** include icon button in hidden actions */ withIconButtonInHiddenActions: boolean; /** include button in actions */ withButtonInActions: boolean; /** inlcude context menu in actions */ withContextMenuInActions: boolean; /** include tooltips on all elments that can have one */ withTooltips: boolean; /** delay rendering of action items */ delayActions: number; } const createTextArray = (items: number, length: number) => { return loremIpsum({ p: 1, avgWordsPerSentence: length, avgSentencesPerParagraph: items, startWithLoremIpsum: false, random: false, })[0].split(". "); }; const textShort = createTextArray(100, 3); const textLong = createTextArray(100, 25); export const OverviewItemListPerformance = ({ length = 500, useOverviewitem = false, withDepiction = false, withDescription = true, withButtonInActions = false, withIconButtonInHiddenActions = false, withTooltips = false, withContextMenuInActions = false, delayActions = 1, }: OverviewItemListPerformanceProps) => { const renderStart = new Date(); const containerRef = React.useRef(null); const observerRef = React.useRef(undefined); const iconNames = Object.keys(canonicalIcons); const ItemWrapper = useOverviewitem ? OverviewItem : "div"; const ItemDescription = useOverviewitem ? OverviewItemDescription : "div"; const ItemLine = useOverviewitem ? OverviewItemLine : "div"; const ItemActions = useOverviewitem ? OverviewItemActions : "span"; const actionsProps = useOverviewitem ? { delayDisplayChildren: delayActions, delaySkeleton: } : {}; const hiddenActionsProps = useOverviewitem ? { ...actionsProps, hiddenInteractions: true } : {}; React.useEffect(() => { const renderEnd = new Date(); // eslint-disable-next-line no-console console.log( "OverviewItemListPerformance Rendering time (s)", (renderEnd.getTime() - renderStart.getTime()) / 1000, ); if (containerRef.current) { let changeCount = 0; const changeReporter = () => { const renderChange = new Date(); // eslint-disable-next-line no-console console.log( `Change ${++changeCount} after time (s)`, (renderChange.getTime() - renderEnd.getTime()) / 1000, ); }; if (observerRef.current) { observerRef.current.disconnect(); } observerRef.current = new MutationObserver(changeReporter); observerRef.current.observe(containerRef.current, { childList: true, subtree: true }); } }); return (
{Array(length) .fill("x") .map((_, id) => { return ( {withDepiction && ( } caption={withTooltips ? textShort[(id + 10) % textShort.length] : undefined} captionPosition={withTooltips ? "tooltip" : "none"} /> )} {withDescription && ( {textShort[id % textShort.length]} {withTooltips ? ( {textLong[id % textLong.length]} ) : ( {textLong[id % textLong.length]} )} )} {withIconButtonInHiddenActions && ( )} {(withButtonInActions || withContextMenuInActions) && ( {withButtonInActions && ( )} {withContextMenuInActions && ( )} )} ); })}
); };