Component Libraries
A component library is a cargo crate of .wisp components. An app adds it to [dependencies] and uses its components as <ui:Button>, with no import line.
Make One
wisp new ui-kit --lib
The prefix is the crate name with _ for - (32 characters at most). The examples shorten it to ui:
# Cargo.toml
[package]
name = "ui-kit"
version = "0.1.0"
edition = "2024"
links = "ui-kit" # lets Cargo hand the components to apps
[package.metadata.wisp]
prefix = "ui_kit" # <ui_kit:Button>; shorten it, say to "ui"
[dependencies]
wisp = { git = "https://wisp.ar0.eu/", package = "wisp-web-rt" } # `wisp new` adds the tag of the CLI
[build-dependencies]
wisp-build = { git = "https://wisp.ar0.eu/", package = "wisp-web-build" }
// build.rs
fn main() {
wisp_build::package();
}
Components go in src/components. src/lib.rs holds the Rust they use. Markup and prop defaults see the crate's pub items (Tone below), not the app's.
<!-- src/components/Button.wisp -->
{@props label: &str, tone: Tone = Tone::Primary}
<button class="btn ${tone.class()}">${label}</button>
<style>.btn { border-radius: 6px; }</style>
Inside the library its components go by bare name (<Button>). A library uses no other library's components.
wisp check in the library checks its manifest (prefix, links, the build script) and every component. wisp package [args] checks it and runs cargo package. cargo publish sends it.
Use One
# the app's Cargo.toml
[dependencies]
ui-kit = { path = "../ui-kit" } # or a version, or git
<ui:Card title="Hello">
<p>From the app.</p>
<ui:Button label="Save" />
</ui:Card>
<ui:Counter start=${3} client:visible />
<Button /> <!-- the app's own, a different component -->
In Rust, ui::Button::html("Save", ui_kit::Tone::Primary) draws one to a string. A prefix is a lowercase letter, then lowercase letters, digits and _, 32 characters at most. It is not a Rust keyword, wisp, index, std, core, alloc, proc_macro or test.
- CSS: each component's
<style>has its own scope (.w-…), served in/_app/app.css. - Browser code: a component with a
<script>,{:…}oron:clickgets its own module, loaded only by pages that draw it.client:visibleand the otherclient:props make it an island. - Tools:
wisp lsphovers, completes and jumps to<ui:Button>, tree-sitter highlights it, andwisp mcplists it. - Dependencies: the app sees only libraries it depends on itself.
- Collisions: the app's
<Button>and<ui:Button>are two components. Two libraries with the same prefix are an error. Rename one in the app with[package.metadata.wisp.prefixes]:
[package.metadata.wisp]
prefixes = { "acme-ui" = "acme" } # <acme:Button>
How It Works
Because the crate has links, Cargo passes the library's components folder, prefix and crate name from wisp_build::package to the app's wisp_build::run as DEP_<LINKS>_* variables. So a path, git or registry dependency works alike. The build finds a renamed dependency (kit = { package = "ui-kit" }, or kit = { workspace = true }) by its new name.
The build copies each library's src/components to .wisp/libs/<prefix>/ with an index (.wisp/libs/index, git-ignored), so wisp dev, wisp check and the editor need no Cargo run. Each component compiles into the app like its own, so a library costs nothing on the request path.
With wisp dev running, an edit in a path-dependency library reaches the app at its next cargo build, so restart wisp dev. The app's own files reload as always.
Plugins and Layers
A component library ships components only. To ship pages too, use a plugin crate (use = ["kit"]) or a layer (extends = ["../base"]). A layer shares its src/lib too. The app's own file of the same name wins, also when the app's file is x.ts and the layer's is x.js. See Config. Both lists take "double" or 'single' quoted strings. A malformed list is a build error.
Is This Page Useful?