Preview
Component examples, layouts, and metadata for command-owned preview pages.
PreviewExtension class
Bases: Extension
Declare component previews and expose them only through CLI-owned servers.
Install with Citry(extensions=[PreviewExtension]). Components configure examples through a nested Preview class. Ordinary application adapters receive no routes from this extension.
on_extension_created function
on_extension_created(_ctx: OnExtensionCreatedContext) -> None on_component_class_created function
on_component_class_created(ctx: OnComponentClassCreatedContext) -> None file_path function
Resolve a file beside its declaration, retaining inherited provenance.
previews function
previews(selection: Selection | None = None) -> tuple[_Preview, ...]Resolve an ordered selection with fresh variant inputs on each call.
variant function
variant(slug: str, label: str, description: str = '', params: Mapping[str, Any] | None = None, viewport: Viewport | None = None) -> VariantDeclare one preview variant with metadata and component or template params.
Variant class
One named example with display metadata and ordinary Python inputs.
Parameters
slugstr- Stable lowercase name, using letters, digits, and single hyphens.labelstr- Human-readable example label.descriptionstr- Plain-text explanation of the example.paramsMapping[str, Any]- Inputs for the component or variables for its preview template.viewportViewport | None- Optional browser dimensions overriding component defaults.
Viewport class
Layout class
Wrap preview content with one template or component class.
Exactly one source is required. The layout receives preview and a named content slot. Component classes must belong to the rendering app.
Parameters
templatestr | None- Trusted inline Citry template source.template_filestr | Path | None- UTF-8 template path relative to the declaring class.componenttype[Component] | None- Component class accepting preview metadata and content.
PreviewError class
Bases: ValueError
A preview declaration, selection, or rendering request is invalid.
PreviewComponent class
Display metadata for one component, without its live class or inputs.
PreviewMetadata class
Component and variant metadata supplied to an example or variant layout.
PreviewItem class
Variant metadata paired with lazily rendered content for a page layout.
PreviewPage class
Ordered component groups supplied to a single-preview or gallery layout.