Skip to content

Composing UCP Components

How-to Guide1 min read
Edit page

You will build rich components — tables, virtual lists, dropdown menus, clipboard access — through the Universal Component Protocol (UCP), so the composition code stays framework-agnostic while an adapter crate supplies the native rendering.

Prerequisites: the ui feature (included by the gpui feature); for GPUI rendering the adapter ships quoin-ui-gpui automatically.

UCP splits rich widgets into:

  1. Traits in quoin-ui — abstract contracts such as TableAdapter, VirtualListAdapter, ButtonAdapter, TextInputAdapter, DropdownMenuAdapter, TabBarAdapter, and Clipboard.
  2. Adapter implementations — concrete per-framework crates such as quoin-ui-gpui that know how to render the widget natively.

Your code talks to the traits; the framework feature pulls in the implementation.

ButtonVariant selects emphasis (primary, ghost, destructive) and density (ComponentSize::Small | Medium | Large):

use quoin_ui::{ButtonAdapter, ButtonVariant, ComponentSize};
let adapter = GpuiButtonAdapter::default();
let button = adapter.render(Some("Click Me".into()), ButtonVariant {
primary: true,
size: ComponentSize::Medium,
..Default::default()
});

Inside quoin_render!, the data_table element declares columns with keys, labels, and render closures; sorting and striping come from attributes:

data_table(rows: people, striped: true) {
column(key: "name", label: "Name", render: |p: &Person| p.name.clone())
column(key: "age", label: "Age", render: |p: &Person| p.age.to_string())
}

SortDirection (None | Asc | Desc) models the per-column sort state on the TableAdapter side.

virtual_list backs scrollable lists with the VirtualListAdapter contract so only visible rows render; scroll restoration is part of the node vocabulary (scroll_restoration).

The Clipboard trait abstracts the system clipboard; the clipboard_button element wires a button that copies text and reports success:

clipboard_button(copy_text: "Copied!") { "Copy" }

QuoinTheme resolves theme color tokens for adapters, so UCP components pick up consistent colors across light and dark appearances without hard-coded hex values in your code.