|
| 1 | +import React from 'react' |
| 2 | + |
| 3 | +import type {Meta} from '@storybook/react' |
| 4 | +import type {ComponentProps} from '../utils/types' |
| 5 | +import {StressTest} from '../utils/StressTest' |
| 6 | +import {TreeView} from './TreeView' |
| 7 | +import {FileIcon, DiffAddedIcon} from '@primer/octicons-react' |
| 8 | +import Octicon from '../Octicon' |
| 9 | + |
| 10 | +export default { |
| 11 | + title: 'StressTests/Components/TreeView', |
| 12 | + component: TreeView, |
| 13 | +} as Meta<ComponentProps<typeof TreeView>> |
| 14 | + |
| 15 | +const totalIterations = 100 |
| 16 | + |
| 17 | +const Files = Array.from({length: totalIterations}, (_, i) => ({ |
| 18 | + name: `File_${i + 1}.tsx`, |
| 19 | +})) |
| 20 | + |
| 21 | +export const CurrentUpdate = () => { |
| 22 | + return ( |
| 23 | + <StressTest |
| 24 | + componentName="TreeView" |
| 25 | + title="Simple current update" |
| 26 | + description="Marking a file as current from a large list." |
| 27 | + totalIterations={totalIterations} |
| 28 | + renderIteration={count => ( |
| 29 | + <TreeView aria-label="Files changed"> |
| 30 | + <TreeView.Item id="src" defaultExpanded> |
| 31 | + <TreeView.LeadingVisual> |
| 32 | + <TreeView.DirectoryIcon /> |
| 33 | + </TreeView.LeadingVisual> |
| 34 | + src |
| 35 | + <TreeView.SubTree> |
| 36 | + {Files.map((file, index) => ( |
| 37 | + <TreeView.Item key={index} id={`src/${file.name}`} current={index === count}> |
| 38 | + <TreeView.LeadingVisual> |
| 39 | + <FileIcon /> |
| 40 | + </TreeView.LeadingVisual> |
| 41 | + {file.name} |
| 42 | + <TreeView.TrailingVisual label="Added"> |
| 43 | + <Octicon icon={DiffAddedIcon} color="success.fg" /> |
| 44 | + </TreeView.TrailingVisual> |
| 45 | + </TreeView.Item> |
| 46 | + ))} |
| 47 | + </TreeView.SubTree> |
| 48 | + </TreeView.Item> |
| 49 | + </TreeView> |
| 50 | + )} |
| 51 | + /> |
| 52 | + ) |
| 53 | +} |
0 commit comments