CRUD / foldkit-mixins-crud
Draw an editor, delete confirmation, and toolbar
EditorView wraps your edit form with status feedback, ConfirmView asks before deleting, and Toolbar lays out list controls:
import { ConfirmView, EditorView, Toolbar } from 'foldkit-mixins-crud'
const PostEditorView = EditorView.forMessages<Message>().define()
const DeletePost = ConfirmView.forMessages<Message>().define()
const PostTools = Toolbar.forMessages<Message>().define()
PostTools({ search: h.input([h.Type('search'), h.AriaLabel('Search titles')]) }, h)
PostEditorView(
{
id: 'post-editor',
status: 'Editing',
title: 'Edit post',
form: h.form([], []),
onClose: Message.ClosedPost(),
},
h,
)
DeletePost(
{
id: 'delete-post',
status: 'Confirming',
name: Option.some('Hello'),
onConfirm: Message.ConfirmedDelete(),
onCancel: Message.CancelledDelete(),
},
h,
)Each editor status updates the section cleanly while keeping the draft visible on failures:
| Status | Status line | Form shown |
|---|---|---|
Closed | Nothing drawn | — |
Loading | Loading… (aria-busy) | No |
NotFound, LoadFailed | Alert with optional onRetry | No |
Editing | None | Yes |
Saving, Saved | Saving… (aria-busy), Saved. | Yes |
SaveFailed, Conflict | Shown in the form's failure Slot | Yes (draft kept) |
Moved | Notice that record changed elsewhere | Yes |
When placing EditorView inside a foldkit-mixins-ui Dialog or Drawer, answer the dialog's Closed OutMessage with editor.close() so the editor stops holding the record open. ConfirmView renders a role="group" asking Delete {name}? and disables confirmation while name is None.
Style views with theme recipes
foldkit-mixins-crud/recipes provides token-backed Styles for List, RowList, Editor, Confirm, and Toolbar:
import { Style } from 'foldkit-mixins'
import { ListSlots } from 'foldkit-mixins-crud'
import { List } from 'foldkit-mixins-crud/recipes'
const StyledTable = ListView.forMessages<Message>()
.define(PostList)
.pipe(Style.attach(Style.forSlots(ListSlots)(List({}))))Customize recipes with .extend(...) (for example, List.extend({ base: { cell: { padding: '1rem 0.5rem' } } })({})) rather than forking them.