Components

Window list

A list of thousands that scrolls with the page, drawing only the rows in view.

Previews are drawn in the theme you made.

Edit it
scheme
direction

A thousand rows in the page #

Town 1
Town 2
Town 3
Town 4
Town 5
Town 6
Town 7
Town 8
Town 9
Town 10
Town 11
Town 12
Town 13
Town 14
Town 15
Town 16
Town 17
Town 18
Town 19
Town 20
Town 21
Town 22
Town 23
Town 24
Town 25
Town 26
Town 27
Town 28
Town 29
Town 30
import { Bundle } from 'foldkit-bundle'
import { Bundles, Button, Recipes, WindowList, WindowListSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const Jump = Recipes.Button.style({ variant: 'outline' })

const TOWNS = Array.from({ length: 1_000 }, (_, index) => ({
  id: `town-${index}`,
  name: `Town ${index + 1}`,
}))

// A list that scrolls with the page, not in a box of its own: the rows in
// view of the window are drawn, and spacers as tall as the rest, so Space and
// End move it and the browser restores the place on back. `findable` lets
// find in page reach a row that is not drawn. A row far outside the window is
// not drawn either, so `helpers.reveal(index)` scrolls the page to it.
const App = Bundle.compose({}).pipe(
  Bundle.withMessages({ Jumped: {} }),
  Bundle.withChild('towns', Bundles.WindowList, {
    args: { id: 'basic-towns', estimatedHeight: 40 },
  }),
)

export default example({
  title: 'A thousand rows in the page',
  slots: WindowListSlots,
  recipe: Recipes.WindowList,
  state: App.placements.runtime({
    Model: App.Model,
    initial: {},
    update: App.placements.update(model => App.children.towns.helpers.reveal(799, 'center')(model)),
  }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [],
      [
        Button.view(
          { label: 'Go to Town 800', onClick: onMessage(App.Message.Jumped()), style: Jump },
          h,
        ),
        WindowList.view(
          {
            model: model.towns,
            items: TOWNS,
            itemToKey: town => town.id,
            itemToView: town => h.span([], [town.name]),
            findable: town => town.name,
            label: 'Towns',
            onMessage: message => onMessage(App.Message.GotTownsMessage({ message })),
            style,
          },
          h,
        ),
      ],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Usage

Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.

The recipe ↗This code ↗