Components

Resizable

Two panels and a handle between them, dragged or stepped by the arrow keys, collapsed and nested.

Previews are drawn in the theme you made.

Edit it
handle
scheme
direction

Side by side #

  • notes.txt
  • todo.md
  • grid.ts

Pick a file to preview it.

import { Bundles, Recipes, Resizable, ResizableSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// The split is the Bundle's Model; its bounds go in once, as args, and both
// the folds and the handle's range read them from there.
export default example({
  title: 'Side by side',
  slots: ResizableSlots,
  recipe: Recipes.Resizable,
  state: Bundles.Resizable.with({ share: 0.35, min: 0.2, max: 0.8 }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [
        h.Style({
          blockSize: '12rem',
          inlineSize: 'min(32rem, 100%)',
          border: '1px solid color-mix(in oklab, currentColor 20%, transparent)',
          borderRadius: '0.5rem',
          overflow: 'hidden',
        }),
      ],
      [
        Resizable.view(
          {
            model,
            onMessage,
            label: 'Resize the file list',
            first: h.ul(
              [h.Style({ margin: '0', padding: '0.75rem', listStyle: 'none' })],
              [h.li([], ['notes.txt']), h.li([], ['todo.md']), h.li([], ['grid.ts'])],
            ),
            second: h.p(
              [h.Style({ margin: '0', padding: '0.75rem' })],
              ['Pick a file to preview it.'],
            ),
            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.

A collapsible sidebar #

Folders

Messages

import { Bundles, Recipes, Resizable, ResizableSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// `collapsible: 'first'` lets Enter or a double-click fold the first panel
// away, and the same again puts it back where it was. The bounds are the
// Bundle's args, so the view needs no copy of them.
export default example({
  title: 'A collapsible sidebar',
  slots: ResizableSlots,
  recipe: Recipes.Resizable,
  pins: { handle: 'grip' },
  state: Bundles.Resizable.with({ share: 0.3, min: 0.2, max: 0.6, collapsible: 'first' }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ blockSize: '12rem', inlineSize: 'min(32rem, 100%)' })],
      [
        Resizable.view(
          {
            model,
            onMessage,
            label: 'Resize the sidebar; Enter or a double-click folds it away',
            first: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Folders']),
            second: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Messages']),
            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.

Nested both ways #

Files

Editor

Terminal

import { Bundle } from 'foldkit-bundle'
import { Bundles, Recipes, Resizable, ResizableSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// Two splits, one in the other's second panel: each placed as a child of its
// own with its own bounds.
const App = Bundle.compose({}).pipe(
  Bundle.withChild('outer', Bundles.Resizable, { args: { share: 0.3 } }),
  Bundle.withChild('inner', Bundles.Resizable, { args: { share: 0.6 } }),
)

export default example({
  title: 'Nested both ways',
  slots: ResizableSlots,
  recipe: Recipes.Resizable,
  state: App.placements.runtime({ Model: App.Model, initial: {} }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ blockSize: '16rem', inlineSize: 'min(36rem, 100%)' })],
      [
        Resizable.view(
          {
            model: model.outer,
            onMessage: message => onMessage(App.Message.GotOuterMessage({ message })),
            label: 'Resize the file list',
            first: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Files']),
            // One over the other, inside the second panel: the split fills it.
            second: Resizable.view(
              {
                model: model.inner,
                onMessage: message => onMessage(App.Message.GotInnerMessage({ message })),
                orientation: 'vertical',
                label: 'Resize the editor',
                first: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Editor']),
                second: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Terminal']),
                style,
              },
              h,
            ),
            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.

A pill handle, stacked #

Preview

Console

import { Bundles, Recipes, Resizable, ResizableSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// `handle: 'pill'` draws a capsule on the line, which takes the accent while
// it is held or dragged. One over the other, it lies along the line.
export default example({
  title: 'A pill handle, stacked',
  slots: ResizableSlots,
  recipe: Recipes.Resizable,
  pins: { handle: 'pill' },
  state: Bundles.Resizable.with({ share: 0.45 }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ blockSize: '14rem', inlineSize: 'min(28rem, 100%)' })],
      [
        Resizable.view(
          {
            model,
            onMessage,
            orientation: 'vertical',
            label: 'Resize the preview',
            first: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Preview']),
            second: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Console']),
            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.

Configure once #

Top

Bottom

import { Bundles, Recipes, Resizable, ResizableSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const Pill = Recipes.Resizable.style({ handle: 'pill' })

// What every split of an application starts from: its look, said once; a
// preset is a named set over it. The bounds are a Model fact (`init`).
const AppSplit = Resizable.configure({
  base: { style: Pill },
  presets: { stacked: { orientation: 'vertical' } },
})

export default example({
  title: 'Configure once',
  slots: ResizableSlots,
  recipe: Recipes.Resizable,
  state: Bundles.Resizable.with({ share: 0.5, min: 0.25, max: 0.75 }),
  view: ({ model, onMessage, h }) =>
    h.div(
      [h.Style({ blockSize: '12rem', inlineSize: 'min(28rem, 100%)' })],
      [
        AppSplit.view(
          {
            model,
            onMessage,
            preset: 'stacked',
            label: 'Resize the panes',
            first: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Top']),
            second: h.p([h.Style({ margin: '0', padding: '0.75rem' })], ['Bottom']),
          },
          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 ↗

  • Right to left The direction switch above turns the preview over; this is what each widget reads.