CRUD / foldkit-mixins-crud
mixins-crud
Building list tables, loading/empty/error states, retry buttons, detail views, edit cards, and delete confirmations for every resource repeats the same ARIA wiring (aria-sort, aria-busy, role="alert", keyboard-focusable row actions) across your app.
foldkit-mixins-crud turns foldkit-crud lists, details, editors, and removers into accessible HTML views whose every element is a foldkit-mixins Slot. foldkit-remote owns the fetched rows, foldkit-crud defines columns and Display formatters, your application owns Messages and styles, and foldkit-mixins-crud draws the DOM structure without internal state. See CRUD screens running in the Chirp demo.
Install
pnpm add effect foldkit foldkit-crud foldkit-mixins foldkit-mixins-crud foldkit-remoteA first CRUD table
Create a Crud.list, bind a ListView to your Message union with ListView.forMessages<Message>().define(list), and render a page from your view:
import { Schema } from 'effect'
import { Crud } from 'foldkit-crud'
import { Entity } from 'foldkit-entity'
import { ListView } from 'foldkit-mixins-crud'
import { Query, type Page, type RemoteData } from 'foldkit-remote'
import type { Html, HtmlBuilder } from 'foldkit/html'
const Post = Entity.define('Post', Schema.Struct({ id: Schema.String, title: Schema.String }))
const PostsQuery = Query.make('Posts', { Input: {}, Result: Query.connection(Post) })
const PostList = Crud.list('Posts', {
query: PostsQuery,
selection: Entity.select(Post, { id: true, title: true }),
})
type Message = { readonly _tag: 'OpenedPost'; readonly id: string }
const PostTable = ListView.forMessages<Message>().define(PostList)
const renderTable = (
page: RemoteData<Page<{ readonly id: string; readonly title: string }>>,
h: HtmlBuilder<Message>,
): Html =>
PostTable({ page, onOpen: row => ({ _tag: 'OpenedPost', id: row.id }) }, h)PostTable renders a <table> with a column header per shown field, formatted cell values using each column's Display, an empty/loading status message when no rows exist, and a <button> in the first cell of each row that dispatches OpenedPost when clicked.
To hide a field (such as id) while keeping it available on row for onOpen, annotate it with Entity.annotateMembers({ id: Display.of(Display.hidden()) }).