Mixins / Inside-out composition
A first slotted field
First, declare the component's slots (root and input):
ts
import { Attr, Behavior, Capability, Event, Slot, Slots, SlotView, Style } from 'foldkit-mixins'
const FieldSlots = Slots.define({
root: Slot.make({ capability: Capability.Container }),
input: Slot.make({
capability: Capability.TextInput,
events: [Event.Input],
attributes: [Attr.AriaInvalid],
}),
})Next, define a Style for appearance and a Behavior for validation attributes independently:
ts
const FieldStyle = Style.forSlots(FieldSlots)({
root: Style.class('field'),
input: Style.class('field-input'),
})
const Validation = Behavior.forSlots(FieldSlots)<FieldInput, Message>({
input: Behavior.slot({
requires: { capability: Capability.TextInput, attributes: [Attr.AriaInvalid] },
attributes: ({ input, h }) => [h.AriaInvalid(input.invalid)],
}),
})Finally, render the SlotView and pipe both attachments onto it:
ts
const Field = SlotView.forMessages<Message>()
.define(FieldSlots, (input: FieldInput, slots, h) =>
h.label(slots.root.attrs(), [
h.input(
slots.input.attrs([
h.Value(input.value),
h.OnInput(value => Message.ChangedValue({ value })),
]),
),
]),
)
.pipe(Style.attach(FieldStyle), Behavior.attach(Validation))Each participant keeps a single responsibility: the component author owns stable extension points, the style author owns appearance, the feature author owns element behavior, the Foldkit app owns Model and update, and the resolver enforces conflict checks.