Every macro, and the call that made it

Every macro, grouped by the file you import it from. Change a control and both the preview and the Jinja call update. Two rules hold on every section: parameters are closed enumerations, with no class= and no colour to pass, and any keyword a macro does not name becomes an HTML attribute, so hx_post="/tasks" renders as hx-post="/tasks".

01

Button

One element, seven variants, seven sizes — and no class at the call site.

In button, variant and size are closed lookups, href switches the element to an <a> and drops type, and icon_name takes any Lucide name so a caller never imports icon. An unknown keyword is passed through as an attribute, not rejected, which is how every hx-* reaches the element.

button_group renders differently by orientation. Horizontal is a row with a gap. Vertical is Basecoat's .button-group. The buttons join into one control with shared borders and no gap.

Preview


02

Data

The file that displays a value — a count, a state, a person, a definition.

The four macros with controls come first; the rest follow with one rendered example each.

table renders empty_state itself when rows is empty, so a caller writes no if-rows-else branch.

avatar uses name as both the alt text and the fallback initials. When an image carries the name, the initials are hidden from screen readers, so the person is announced once.

Preview

empty_state(title, description, icon_name)


  

metric_group(items, cols=3)


  

bullet_list(tone) / list_item() — both take a block


  

caption(text) — also takes a block, for a caption holding a link


  

link(label, href) and kbd(keys)


  

item_list() takes a block of item(title, description, clamp) calls


  

description_list(layout) takes a block of description_item(term, value) calls


  

code_block(source, label, wrap)


  

avatar(name, src, size, badge_tone) and avatar_group(overflow)


  

03

Disclosure

Two disclosures, with no fjkit JavaScript.

collapsible is a native <details>. The open state, the keyboard operation and the disclosure role all come from the element, and Basecoat animates it with CSS. tooltip is drawn entirely from a data-tooltip attribute — no second element exists.

Screen readers do not read CSS content(), so a tooltip cannot be a control's only label. Give the control an aria_label when the tooltip is the only text on it.

accordion(multiple) / collapsible(summary, open) — both take a block


  

tooltip(text, side, align) — the block is the element it wraps


  

04

Feedback

Five components for "wait", "done" and "that did not work".

alert is a fact that stays on the page. spinner and skeleton both mean "not yet". Use a skeleton when you know the shape of what is coming, a spinner when you do not. dialog interrupts. toast outlives the response that raised it.

alert(variant="destructive") takes role="alert", which interrupts a screen reader mid-sentence; every other variant is role="status", which waits for a pause. A multi-line skeleton is one live region, not one per line.

alert(title, body, variant, icon_name) — the block is the actions


  

spinner(size, tone, label, indicator)


  

skeleton(shape, width, lines)


  

dialog(id, title, description, size, footer) — the block is the body


  

toaster(align) with toast(title, description, category)


  

05

Form

Every field takes the same five parameters, and error replaces the hint.

Every field macro takes the same name, label, hint, error and id, and error replaces the hint rather than stacking on it while marking the control aria-invalid. The playground steps through five shapes of the same form: the htmx one, a field in error, the long controls, the radios-versus-select choice, and switches inside a fieldset.

target= is what makes a form an htmx form; drop it and the same macro emits an ordinary POST that works without JavaScript.

range_field sets the filled part of the track on the server. Basecoat updates it only while dragging, so without this the first paint shows the default position, not the value.

Preview

range_field(name, label, value, min, max, step, output)


  

input_group_field(name, label, start, end)


  

input_group_field(name, revealable=true) — needs reveal_scripts()


  

file_field(name, label, accept, multiple), and the bar form(progress=) moves


  

06

Icon

1,767 names, no sprite sheet, no icon font, no request.

icon("plus") inlines the Lucide path as an <svg>. It inherits currentColor, so an icon inside a primary button is already the right colour, and it costs no network request at any size.

Most macros take icon_name= directly — button, stat, empty_state, brand, sidebar_link — so you rarely call this one yourself. A sample is below; any Lucide name works.

icon(name, size=16)


      
An unknown name raises at render time instead of printing an empty box.

07

Layout

Spacing and columns are macros, so a page needs no utility classes.

A utility class such as grid gap-4 in your template is absent from the shipped stylesheet unless the kit happens to use it. stack, row and grid take spacing and column counts as parameters, and every value maps to a class the stylesheet contains.

The dashed tiles are your content. Change the controls and the source line changes with them.

page_header takes a block, and the block is its actions. The title, the description and the buttons stay on one line at every width. The header at the top of this page is the same macro with no actions.

centered and fill are one axis each. centered caps a width; fill takes the height the shell already gave main and places the children in it, which is how a sign-in card sits in the middle of the screen. For both, nest them with fill outside. fill has no preview below, because a card has no fixed height to fill.

Preview


      

centered(width="sm", gap=6) — the block is the children


  

page_header(title, description) — the block is the actions


  

section(title, description, gap=4) — the block is the children


  

divider()


  


09

Overlay

Pass one id; the macro derives the ids that connect a trigger to its panel.

Everything in ui/overlay.html is driven by Basecoat's own JavaScript, which the shell already loads and which re-scans on htmx:afterSwap, so an overlay that arrives in a swap works with nothing extra.

A trigger and its panel find each other through four related ids. A wrong one fails silently. The panel opens but is never announced, or never opens. Every macro here takes one id and derives the other three.

select_menu and combobox put their value in a hidden input, pre-filled on the server, so a swap that re-renders the fragment keeps the selection. Prefer select_field when it is enough. A native <select> is one element and needs no script.

Both take multiple=true, and both then want a list in selected where they took a scalar before. The hidden input carries Basecoat's JSON array, and multiselect_scripts(), loaded by the page that has such a field, re-emits it on submit as a repeated field: labels=bug&labels=ui. The route declares labels: list[str] = Form([]). Without the script the field posts one JSON string, and the route answers 422.

A multiple combobox is laid out for a narrow column. The filter box takes the first line on its own, the chips wrap below it, the control fills the column and the list is anchored to the box rather than to the bottom of the chips, so picking several options in a row never moves the option under the pointer. Long labels wrap in the list and truncate in a chip.

Up to about a dozen options, a checkbox group inside a fieldset posts the same thing and needs no script.

popover(id, label, side, align, width) — the block is the body


  

dropdown_menu(id, label) with menu_item / menu_group / menu_separator


  

select_menu(name, options, selected)


  

combobox(name, options, selected, empty)


  

select_menu(name, options, selected, multiple) — needs multiselect_scripts()


  

combobox(name, options, selected, multiple) — chips are drawn by JS


  

visible_label / hint / error — the same two controls rendered as fields


  

drawer(id, title, side) with drawer_trigger(label, target)


  

command(id, dialog) with command_group / command_item


  

10

Shell

The document template your base.html extends. This page is built on it.

shell.html has no macros and no preview, because the preview is this page. It owns the <head>, the theme flash-guard, the asset links, the toaster and the header/main/footer skeleton. Your brand, your navigation and your footer text are blocks.

Filling the sidebar block changes the layout to a side column plus a top bar, and the shell adds the sidebar_trigger to the header. There is no flag to set.

The header stays pinned to the top of the viewport while the page scrolls. It is position: sticky, not fixed, so the bar keeps its own space and you do not have to pad anything in main to clear it. With a sidebar, the bar spans the whole width and the rail starts underneath it. A page that needs the header in the flow instead, such as an embedded or print layout, overrides the header block with its own <header>.

your base.html, in full


  

every block the shell exposes, in source order


  


12

Table

A column spec, and the two controls a list needs around it.

columns is a list of dicts — label, and optionally align, width, sort, sort_url or select — and the macro tests rows to decide whether to render your body or the empty state. It takes rows without iterating them for that reason. The caller writes no if-rows-else branch.

Render each row with a macro call inside your loop. {% include %} in a loop does a template lookup and builds a new context per row, and is 20–30% slower (jinja-performance.md).

A column carrying a sort_url becomes a sortable header, and pagination goes under the table. Neither builds a URL. The router owns the query string, because it is the only thing that knows which filters are on. Both render real hrefs and take target= to add the htmx swap on top, so sorting and paging work without JavaScript and the URL can be bookmarked.

{"select": true} puts a batch-selection column in front of the rest. It posts as the repeated field a checkbox column has always sent, and select_scripts() is what ticks the whole column from the header box.

resizable=true puts a handle on the trailing edge of each labelled column. A visitor drags it, or focuses it and presses the arrow keys; Home or a double-click gives the column back its natural width. The script keeps the widths in localStorage under the table's id, which is why a resizable table must have one, and they come back after a reload and after an htmx swap. The page loads resize_scripts(); without it the handles stay hidden and the table is the ordinary one. CSS cannot do this. resize works only on a block box with overflow, and a table cell is not one.

page_size is a <form method="get">, because a bare <select> cannot submit without a script. Its url must carry no query string. A GET submit replaces the whole query with the form's fields, so pass the filters in keep. Do not keep the page number; a new page size invalidates it.

Preview


13

Tabs

Two ids, passed once, and the keyboard is Basecoat's.

Basecoat owns which tab is selected, the roving tabindex and the arrow keys, and the shell already loads it. This macro carries the aria contract that behaviour reads: a [role="tab"] whose aria-controls names a [role="tabpanel"] with that id.

selected names the tab that starts open. The server knows which one the request was for, so it is a parameter rather than something a script decides after paint. The code tabs under every playground on this page use this macro.

For a tab group inside another tab's panel, such as a mode switch inside a page section, use variant="segmented" on the inner one. It renders as a pill strip, so the two levels do not look alike. variant here is shape, not a colour role as it is on button or badge; the values are underline, the default, and segmented, and anything else falls back to the default.

tabs(items, label, selected) / tab_panel(id) — both take a block


  

tabs(items, label, variant="segmented") — nested inside a tab_panel