brumate/ui

Virtualizer

A box that scrolls a long collection, such as thousands of rows, and renders only the rows in view.

Photo 0001.jpg
Photo 0002.jpg
Photo 0003.jpg
Photo 0004.jpg
Photo 0005.jpg
Photo 0006.jpg
Photo 0007.jpg
Photo 0008.jpg
Photo 0009.jpg
Photo 0010.jpg
Photo 0011.jpg
Photo 0012.jpg
Photo 0013.jpg
Photo 0014.jpg
Photo 0015.jpg
Photo 0016.jpg
Photo 0017.jpg
Photo 0018.jpg
Photo 0019.jpg
Photo 0020.jpg
<script>
  import Tree from '@brumate/ui/Tree.brm';
  import TreeItem from '@brumate/ui/TreeItem.brm';
  import Virtualizer from '@brumate/ui/Virtualizer.brm';

  interface File {
    id: string;
    name: string;
  }
  const files: File[] = Array.from({ length: 5000 }, (_, index) => ({
    id: `file-${index}`,
    name: `Photo ${String(index + 1).padStart(4, '0')}.jpg`,
  }));
</script>

<Virtualizer class="ui-virtualizer" rowHeight=(32)>
  <Tree class="ui-tree" aria-label="5000 photos" items=files item=file />
</Virtualizer>

#template file(file: File) {
  <TreeItem class="ui-treerow" textValue=(file.name)>{file.name}</TreeItem>
}
<Virtualizer rowHeight=(32) style="height: 300px">
  <Tree aria-label="Photos" items=files item=file />
</Virtualizer>

Other collections

A GridList, a ListBox or a Table takes items, as a Tree does, and renders only the rows in view when it is in a Virtualizer:

<Virtualizer rowHeight=(32) style="height: 300px">
  <ListBox aria-label="Files" items=files item=file getTextValue=((file) => file.name) />
</Virtualizer>

A Table takes items and getTextValue, and its TableBody takes item. Their keys read the data, as the keyboard section says.

Rows that you write out or render from a #for of your own have no data to read. Give the #for window(height), and it renders only the rows in view, in the box that scrolls:

<Virtualizer style="height: 300px">
  <Table aria-label="Files">
    <TableHeader>…</TableHeader>
    <TableBody>
      #for (file of files by file.id) window(32) {
        <Row id=(file.id)>…</Row>
      }
    </TableBody>
  </Table>
</Virtualizer>

See windowed lists for how it renders.

Keyboard