Templates

basecoat-cli is deprecated

Template files now ship with basecoat-css. If you previously copied templates with basecoat-cli, install basecoat-css instead and copy the files from node_modules/basecoat-css/templates.

Basecoat ships optional Nunjucks and Jinja macros for components with larger HTML structures. They generate the same semantic Basecoat markup shown in the component docs, while keeping repeated server-rendered markup easier to maintain.

The templates are versioned with basecoat-css, so the generated markup matches the CSS and JavaScript files you installed.

Macros

Some macro files include internal recursive helpers such as render_select_items(). Those helpers are implementation details and are not part of the public API.

Usage

Install Templates

Copy the template folder for your template engine from basecoat-css. Templates are meant to be app-owned, so you can edit them after copying.

cp -R node_modules/basecoat-css/templates/nunjucks ./templates/basecoat

Copy only the files you use if you do not want the full template folder.

You can also copy the Nunjucks templates or Jinja templates from GitHub.

Use a Macro

Import a macro from the copied template file, then call it with the props for that component.

{% from "basecoat/select.njk" import select %}
{{ select(
  name="fruit",
  items=[
    { value: "apple", label: "Apple" },
    { value: "banana", label: "Banana" },
    { value: "blueberry", label: "Blueberry" }
  ]
) }}

Macro Reference

combobox()

PropTypeDefaultDescription
idstringgeneratedUnique combobox id.
selectedstring | array | objectNone / noneInitial selected value or values. Objects can include value and label.
namestringNone / noneHidden input name.
multiplebooleanfalseEnables chip-based multiple selection.
placeholderstringNone / noneVisible input placeholder.
close_on_selectbooleanfalseCloses the popover after each option selection in multiple mode.
clearbooleanfalseShows a clear button in single-select mode.
auto_highlightbooleanfalseHighlights the first matching option while filtering.
format"value" | "object""value"Hidden input serialization format.
main_attrsobject{}Extra attributes for the .combobox root.
input_attrsobject{}Extra attributes for the visible input or chip input wrapper.
popover_attrsobject{}Extra attributes for the popover element.
listbox_attrsobject{}Extra attributes for the listbox.
hidden_input_attrsobject{}Extra attributes for the hidden input.

command()

PropTypeDefaultDescription
idstringgeneratedUnique command id.
itemsarrayNone / noneOptional structured item data. Use caller content when omitted.
placeholderstring"Type a command or search..."Search input placeholder.
empty_textstring"No results found."Empty-state text.
main_attrsobject{}Extra attributes for the .command root.
input_attrsobject{}Extra attributes for the search input.
menu_attrsobject{}Extra attributes for the command menu.

command_dialog()

PropTypeDefaultDescription
idstringgeneratedUnique command dialog id.
itemsarrayNone / noneOptional structured item data. Use caller content when omitted.
placeholderstring"Type a command or search..."Search input placeholder.
empty_textstring"No results found."Empty-state text.
dialog_attrsobject{}Extra attributes for the native dialog.
input_attrsobject{}Extra attributes for the search input.
menu_attrsobject{}Extra attributes for the command menu.
openbooleanfalseRenders the dialog open by default.

dialog()

PropTypeDefaultDescription
idstringgeneratedUnique dialog id.
triggerstringNone / noneText or HTML for a generated trigger button.
titlestringNone / noneDialog title.
descriptionstringNone / noneDialog description.
footerstringNone / noneHTML for the dialog footer.
dialog_attrsobject{}Extra attributes for the native dialog.
trigger_attrsobject{}Extra attributes for the generated trigger button.
header_attrsobject{}Extra attributes for the dialog header.
body_attrsobject{}Extra attributes for the dialog body section.
footer_attrsobject{}Extra attributes for the dialog footer.
openbooleanfalseRenders the dialog open by default.
close_buttonbooleantrueIncludes the generated close button.
close_on_overlay_clickbooleantrueAdds backdrop-click close behavior.
PropTypeDefaultDescription
triggerstringrequiredHTML for the trigger button.
idstringgeneratedUnique dropdown menu id.
itemsarrayNone / noneOptional structured menu item data. Use caller content when omitted.
main_attrsobject{}Extra attributes for the .dropdown-menu root.
trigger_attrsobject{}Extra attributes for the trigger button.
popover_attrsobject{}Extra attributes for the popover element.
menu_attrsobject{}Extra attributes for the menu element.

popover()

PropTypeDefaultDescription
triggerstringrequiredHTML for the trigger button.
idstringgeneratedUnique popover id.
main_attrsobject{}Extra attributes for the .popover root.
trigger_attrsobject{}Extra attributes for the trigger button.
popover_attrsobject{}Extra attributes for the popover element.

select()

PropTypeDefaultDescription
idstringgeneratedUnique select id.
selectedstring | arrayNone / noneInitial selected value or values.
namestringgenerated from idHidden input name.
itemsarrayNone / noneOptional structured item data. Use caller content when omitted.
multiplebooleanfalseEnables multiple selection.
placeholderstringNone / nonePlaceholder text for multiple mode with no selection.
close_on_selectbooleanfalseCloses the popover after each option selection in multiple mode.
format"value" | "object""value"Hidden input serialization format.
main_attrsobject{}Extra attributes for the .select root.
trigger_attrsobject{}Extra attributes for the trigger button.
popover_attrsobject{}Extra attributes for the popover element.
listbox_attrsobject{}Extra attributes for the listbox.
input_attrsobject{}Extra attributes for the hidden input.
PropTypeDefaultDescription
idstringNone / noneOptional sidebar id. Use one when multiple sidebars exist.
labelstring"Sidebar navigation"Navigation landmark label.
openbooleantrueInitial open state.
side"left" | "right""left"Side of the viewport.
headerstringNone / noneHTML for the sidebar header.
footerstringNone / noneHTML for the sidebar footer.
menuarrayNone / noneOptional structured menu data. Use caller content when omitted.
main_attrsobject{}Extra attributes for the .sidebar root.
header_attrsobject{}Extra attributes for the header.
content_attrsobject{}Extra attributes for the scrollable content section.
footer_attrsobject{}Extra attributes for the footer.

tabs()

PropTypeDefaultDescription
idstringgeneratedUnique tabs id.
tabsetsarray[]Tab definitions. Each item can include tab, panel, tab_attrs, and panel_attrs.
main_attrsobject{}Extra attributes for the .tabs root.
tablist_attrsobject{}Extra attributes for the tablist. Use aria-orientation="vertical" or data-variant="line" here.
default_tab_indexnumber1One-based index of the initially selected tab.

toaster()

PropTypeDefaultDescription
idstring"toaster"Toaster container id.
toastsarray[]Initial toast objects rendered inside the toaster.
attrsobject{}Extra attributes for the .toaster container.

toast()

PropTypeDefaultDescription
category"success" | "error" | "info" | "warning""success"Toast category. Controls icon and ARIA role.
titlestring""Toast title.
descriptionstring""Toast description.
durationnumberdefault timeoutTimeout in milliseconds. Use -1 to keep the toast open.
iconstringcategory iconCustom icon HTML.
actionobjectNone / noneAction button/link config. Supports label, onclick, and href.
cancelobjectNone / noneCancel button/link config. Supports label, onclick, and href.
attrsobject{}Extra attributes for the .toast element.