Mixins / foldkit-mixins-ui
Sixty seconds: style a Button without copying it
Start with a normal @foldkit/ui Button. The adapter publishes its consumer
attribute bundle as the button Slot.
ts
import type { HtmlBuilder } from 'foldkit/html'
import { defineMessageUnion } from 'foldkit/message'
import * as UiButton from '@foldkit/ui/button'
import { Style } from 'foldkit-mixins'
import { Button, ButtonSlots } from 'foldkit-mixins-ui'
const Message = defineMessageUnion({ Saved: {} })
type Message = typeof Message.Type
const SaveStyle = Style.forSlots(ButtonSlots)({
button: Style.class('btn btn-primary'),
})
const saveButton = (h: HtmlBuilder<Message>) =>
UiButton.view(
{
onClick: Message.Saved({}),
toView: Button.toView([SaveStyle.mixin], { h }, ({ button }) => h.button(button, ['Save'])),
},
h,
)The important line is:
ts
toView: Button.toView(mixins, { h }, draw)Conceptually:
attributes from @foldkit/ui
+
Style / Behavior mixins
|
v
Button.toView(...)
|
v
draw(resolved slot arrays)The caller never copies Button's internal behavior and never has to know how to merge its handlers/ARIA/structural attributes safely.