Mixins / foldkit-mixins-ui

Why some components needed a fork

The bridge needs a consumer-visible attribute bundle. Menu, Listbox, ComboBox, DatePicker and Toast build (parts of) their element tree internally and expose no toView-style seam, so there is nothing for Mixins to attach to: a limitation of the exposed render seam, not of Slot resolution. Each is transcribed from the pinned @foldkit/ui source (attributed in its module) with the missing toView added, and a parity battery draws the fork and upstream's view over the same models; state, Messages, update, Commands and Mounts stay upstream in every case. If upstream gains seams, the forks go away.

That seam is what makes a row styleable. Drawn through @foldkit/ui's own view, a Menu item or a Listbox or Combobox option takes only a className (its itemToConfig), so no Slot's attributes reach it and no Mixin can land on it: the page can style it only from the panel's Slot, with a rule under it keyed on the role and the state attributes upstream writes. Drawn through the fork, the row is the item Slot, styled like any other:

ts
import { Capability, Slot, Slots, Style } from 'foldkit-mixins'
import { Theme } from 'foldkit-mixins/theme'
import { ListboxSlots } from 'foldkit-mixins-ui'

const t = Theme.ref(Theme.standard(Theme.make({})))

// Through `Listbox.toView`: each option is the `item` Slot.
const ListboxStyle = Style.forSlots(ListboxSlots)({
  item: [{ cursor: 'pointer' }, Style.pseudo('[data-active]', { background: t.surface.muted })],
})

// Through upstream's view: the options are reached from the panel's Slot.
const PanelSlots = Slots.define({ items: Slot.make({ capability: Capability.Container }) })
const PanelStyle = Style.forSlots(PanelSlots)({
  items: Style.nest('[role="option"][data-active]', { background: t.surface.muted }),
})

The second keeps the rule in the panel's layer and reads only what @foldkit/ui publishes (role, data-active, data-selected, data-disabled), but no Behavior or Mount can reach the row that way. Use it for a port that keeps upstream's view; draw through the adapter otherwise. Listbox, Combobox and Calendar draw the standard markup from the styled bundles when toView is given no draw; pass a draw to arrange the parts yourself.

The Menu is three layers, each built on the one before:

Menu.init / update / view      the component: rows with values, submenus, a point
        |
MenuSlots, Menu.resolve,       the panel adapter: styles any @foldkit/ui Menu
Menu.toView, fluid,            drawn through the fork, whoever keeps its Model
overlayBars, drawAtPoint,
pointTarget
        |
MenuView                       the fork: @foldkit/ui/menu's view with a toView

MenuView is the fork; the Menu's Model, update and Mounts are upstream's. The panel adapter styles a Menu drawn through it: Menu.toView(mixins, { h }, draw?) is that Menu's toView, and without a draw draws the panel through drawMenu (Menu.toView([MenuStyle.mixin], { h }) is a whole styled menu). Menubar draws its menus this way, and so does an application that folds @foldkit/ui's Menu itself, for typed items or groups, which the component's rows do not have. Such a Menu opens at a point with Menu.drawAtPoint(point, h) as toView's draw (its button becomes a mark of no size at point, an Option, which the anchor places the rows against, so give the anchor gap: 0) and Menu.pointTarget({ onPress, onOpen }, h) on the area: a right press sends onPress with its point, which the application keeps, and the contextmenu after it (or Shift+F10, or the ContextMenu key) sends onOpen, which the application answers with the Menu's own Opened Message, the browser's menu kept shut. A finger's press sends onPress too, so Android's contextmenu for a held finger opens under it; iOS fires none, which the component's Menu.target answers by opening on the hold itself. The component is this package's own, drawn through the adapter, as the Slider is; its Menu.target is pointTarget wired to its own Messages.

ToastView follows the fork's shape: ToastView.make binds upstream's Toast.make for the payload and swaps in the transcribed view. Listbox forks both variants over one shared transcription (ListboxView.create and ListboxView.Multi.create bind the upstream bundles; the single and multi Models are structurally identical, so the single adaptor maps maybeSelectedValue to selectedValues exactly as upstream's does). The forks add one view input upstream lacks, direction?: 'ltr' | 'rtl': under 'rtl' a horizontal listbox's ArrowLeft moves to the next item. Combobox follows the same shape over its own shared transcription (ComboboxView.create / ComboboxView.Multi.create). DatePicker's bundles mix the popover's pre-bound groups with the date picker's own attributes, so they speak only the date picker's Message: its toView takes no builder of the application's, and without a draw draws upstream's markup. DragAndDrop and Animation do not have adapters here yet.

Limits

This package separates responsibilities into three layers:

component state / accessibility -> @foldkit/ui
merge semantics                 -> foldkit-mixins
adapter metadata, widgets       -> foldkit-mixins-ui

The components that keep a Model here (Menu, Toast, Sheet and the rest) do so where @foldkit/ui has no such component, or composes one beneath them (a Sheet is a Dialog, a Menubar a row of Menus); when upstream gains one, the adapter is the better home. The recipes assume the page ships the theme's tokens; a widget never reads a value out of a theme. Accessibility support entries are claims found in source, not a WCAG conformance statement.

Next