Mixins / foldkit-mixins-ui

Look, state, drawing, features: one factory each

A variation of a widget is a call with options rather than a copied file. Each widget separates four concerns:

  • Look (Recipes.X.style(selection)): compiles CSS over fixed markup from your theme's tokens. Use .extend to tweak existing variants or .add to define new axes (Recipes). Omitting style renders bare unstyled markup.
  • State (X.init and X.update, or Bundles.X): holds interaction state (what is open, a drag, a countdown) in your Foldkit Model, while application values stay in your Model.
  • Drawing (X.view(options, h) and X.configure({ base, presets })): renders markup, ARIA attributes, events, and fixed labels (words with {blanks} such as 'Remove {tag}').
  • Features (passed values like fluid: Table.fluid or kind: Chart.bars): lets you import optional capabilities explicitly so pages that omit them never ship their code.

Each widget's view derives markup purely from its arguments and your Model so server and browser renders match. Read browser facts (such as eye-dropper availability or reduced-motion preference) once in init or a Command and pass them in as Model inputs (see ColorPicker).

This example renders a compact, fluid-hover product table from your application rows:

ts
import type { Html, HtmlBuilder } from 'foldkit/html'
import { defineMessageUnion } from 'foldkit/message'
import { Recipes, Table } from 'foldkit-mixins-ui'

const Message = defineMessageUnion({ Noop: {} })
type Message = typeof Message.Type

interface Product {
  readonly name: string
  readonly price: string
}

const ProductsStyle = Recipes.Table.style({ density: 'compact' })

export const products = (rows: ReadonlyArray<Product>, h: HtmlBuilder<Message>): Html =>
  Table.view(
    {
      columns: [
        { header: 'Product', rowHeader: true, value: row => row.name },
        { header: 'Price', numeric: true, value: row => row.price },
      ],
      rows,
      rowKey: row => row.name,
      fluid: Table.fluid,
      words: { selectAll: 'Choose every product' },
      style: ProductsStyle,
    },
    h,
  )

Table.configure({ base, presets }) lets you bind style, fluid, and words once and pass only columns and rows at each call site. One factory for each part covers init/update, Bundles, configure, and Recipes in full.