Mixins / foldkit-mixins-ui

Table

namespace · packages/mixins-ui/src/table.ts:1

export * as Table from './table.js'

In the guides

Members

Table.checkboxes

function · packages/mixins-ui/src/table/checkboxes.ts:11

function checkboxes(
  style?: NamedStyle<typeof Checkbox.CheckboxSlots>,
): TableSelectionControl

The selection box of a row, drawn by Checkbox. Pass it as selection.control; style is a style of CheckboxSlots for the boxes' look. A table that selects nothing, or draws its own control, never imports Checkbox.

Table.configure

function · packages/mixins-ui/src/table.ts:422

function configure<const Names extends string = never>(
  config: Presets<TablePreset, Names>,
): {
  readonly view: <Row, Outer = never, Key extends string = string>(
    options: TableView<Row, Outer, Key> & PresetOption<Names>,
    h: HtmlBuilder<Outer>,
  ) => Html
}

The application's own Table: base for every use, presets chosen at a use, and the call over both.

Table.defineColumns

function · packages/mixins-ui/src/table.ts:236

function defineColumns<Row>(): <
  const Columns extends ReadonlyArray<TableColumn<Row>>,
>(
  each: Columns,
) => NoInfer<Columns>

Columns written once and used by name: Table.defineColumns<Row>()([...]) keeps each sortKey as the literal it was written, so sort.onSort receives 'name' | 'role' and not string. Columns written inline in Table.view need no helper.

Table.fluid

const · packages/mixins-ui/src/table/fluid.ts:17

const fluid = { resting, mount }

One highlight that follows the pointer to the nearest body row, in place of a hover on each. Pass it as Table.view's fluid: a table given none draws no highlight and ships none of this.

Table.nextSort

function · packages/mixins-ui/src/table.ts:100

function nextSort<Key extends string>(
  sort: Option.Option<TableSort<Key>>,
  column: Key,
): Option.Option<TableSort<Key>>

The sort after a press on column's heading: ascending first, then descending, then none. The rows are the application's to sort by it.

Table.TABLE_HOVER

const · packages/mixins-ui/src/table/fluid.ts:5

const TABLE_HOVER: 'table-hover'

The name of the rows' highlight: its place is --fk-table-hover-x, -y, -w, -h.

Table.TableColumn

interface · packages/mixins-ui/src/table.ts:75

interface TableColumn<Row, Key extends string = string> {
  readonly header: string | Html
  readonly footer?: string | Html | undefined
  readonly numeric?: boolean | undefined
  readonly value: (row: Row) => Html | string
  readonly rowHeader?: boolean | undefined
  readonly sortKey?: Key | undefined
}

One column: its heading, and each row's cell for it. Key is the type of its sortKey.

Table.TableExpansion

interface · packages/mixins-ui/src/table.ts:183

interface TableExpansion<Row, Message> {
  readonly id: string
  readonly isExpanded: (row: Row) => boolean
  readonly onToggle: (row: Row, expanded: boolean) => Message
  readonly detail: (row: Row) => Html
  readonly label?: ((row: Row) => string) | undefined
}

Rows that open on a press to show a detail below them.

Table.TableFluid

interface · packages/mixins-ui/src/table.ts:157

interface TableFluid {
  readonly resting: Readonly<Record<string, string>>
  readonly mount: () => ReturnType<typeof FluidHover>
}

One highlight behind the body rows, following the pointer: Table.fluid. resting is what the frame's custom properties hold until the Mount first writes them, and mount is that Mount, which sends no Message.

Table.TablePreset

type · packages/mixins-ui/src/table.ts:417

type TablePreset = Pick<TableView<never>, 'style' | 'words' | 'fluid'> & {
  readonly mixins?: MixinList<never>
}

What a Table is given once: its look, words and highlight; the columns and rows are each use's.

Table.TableSelection

interface · packages/mixins-ui/src/table.ts:116

interface TableSelection<Row, Message> {
  readonly id: string
  readonly isSelected: (row: Row) => boolean
  readonly onToggle: (row: Row, selected: boolean) => Message
  readonly onToggleAll: (selected: boolean) => Message
  readonly rowLabel?: ((row: Row) => string) | undefined
  readonly control: TableSelectionControl
}

A checkbox on every row, the rows chosen being the application's.

Table.TableSelectionControl

interface · packages/mixins-ui/src/table.ts:148

interface TableSelectionControl {
  readonly draw: <Message>(
    input: TableSelectionInput<Message>,
    h: HtmlBuilder<Message>,
  ) => Html
}

Draws a row's selection box; Table.checkboxes() is the one shipped, and one of your own (a radio, a switch) is an object with this draw.

Table.TableSelectionInput

interface · packages/mixins-ui/src/table.ts:130

interface TableSelectionInput<Message> {
  readonly id: string
  readonly label: string
  readonly checked: boolean
  readonly indeterminate: boolean
  readonly onToggle: (checked: boolean) => Message
  readonly cell: 'th' | 'td'
  readonly cellAttributes: (
    extra?: SlotAttributes<Message>,
  ) => SlotAttributes<Message>
  readonly labelAttributes: (
    extra?: SlotAttributes<Message>,
  ) => SlotAttributes<Message>
}

What a selection control is given to draw: one box, in the cell the table places it in.

Table.TableSlots

const · packages/mixins-ui/src/table.ts:35

const TableSlots: Slots.Contract<{ readonly frame: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly highlight: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly caption: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly head: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly headerRow: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Inte …;

A presentational table: its regions are slots, and it owns no state. What it draws (the sort, the rows chosen, the rows open) is the application's, read from its Model; each press is a Message the application folds. That is the boundary with foldkit-data-grid, which owns a grid's state: filtering, reordering and resizing columns, editing cells, moving between them with the keys, and virtualized rows belong there, not here.

It stands in a frame, which the recipe scrolls sideways when the table is wider than the screen. Drawn with fluid, the frame holds one highlight behind the rows, which follows the pointer to the nearest one: a highlight cannot be a child of a tbody, so it is the frame's. An open row's detail and the empty state are rows of their own, which the highlight passes over.

Table.TableSort

interface · packages/mixins-ui/src/table.ts:91

interface TableSort<Key extends string = string> {
  readonly column: Key
  readonly direction: 'ascending' | 'descending'
}

The column the rows are sorted by, and which way.

Table.TableView

interface · packages/mixins-ui/src/table.ts:198

interface TableView<Row, Message = never, Key extends string = string> {
  readonly columns: ReadonlyArray<TableColumn<Row, Key>>
  readonly rows: ReadonlyArray<Row>
  readonly caption?: string | undefined
  readonly rowKey?: ((row: Row) => string) | undefined
  readonly sort?:
    | {
        readonly by: Option.Option<TableSort<Key>>
        readonly onSort: (column: Key) => Message
      }
    | undefined
  readonly selection?: TableSelection<Row, Message> | undefined
  readonly expansion?: TableExpansion<Row, Message> | undefined
  readonly empty?: Html | undefined
  readonly style?: NamedStyle<typeof TableSlots> | undefined
  readonly mixins?: MixinList<Message> | undefined
  readonly fluid?: TableFluid | undefined
  readonly words?: Partial<TableWords> | undefined
}

A plain table in one call: columns with per-row values, the rows, an optional caption, a style for its slots, and mixins beside the style. No upstream component stands behind it.

Table.TableWords

interface · packages/mixins-ui/src/table.ts:163

interface TableWords {
  readonly selectRow: string
  readonly selectAll: string
  readonly details: string
  readonly showDetails: string
}

The text a table draws that is not a use's content.

Table.view

function · packages/mixins-ui/src/table.ts:241

function view<Row, Message = never, Key extends string = string>(
  options: TableView<Row, Message, Key>,
  h: HtmlBuilder<Message>,
): Html

Table.words

const · packages/mixins-ui/src/table.ts:175

const words = { selectRow, selectAll, details, showDetails }

The words a table starts from; words overrides them one at a time.