Preview
Component examples, layouts, and metadata for command-owned preview pages. Experimental, so these names and the citry ext run preview commands may change in a minor release.
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.
Experimental
The preview extension, everything
citry.ext.previewexports, and thecitry ext run previewcommands are experimental. They may change in a minor release without a deprecation period.
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.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
Variant class
One named example with display metadata and ordinary Python inputs.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
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
Browser dimensions and pixel scale used to capture one variant.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
Parameters
widthint- CSS width from 1 through 8192 pixels.heightint- CSS height from 1 through 8192 pixels.device_scale_factorfloat- Finite pixel scale greater than zero, at most four.
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.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
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.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
PreviewComponent class
Display metadata for one component, without its live class or inputs.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
PreviewVariant class
Display metadata for one variant, without its Python params.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
PreviewMetadata class
Component and variant metadata supplied to an example or variant layout.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
PreviewItem class
Variant metadata paired with lazily rendered content for a page layout.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
PreviewGroup class
One component's metadata and ordered preview items.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.
PreviewPage class
Ordered component groups supplied to a single-preview or gallery layout.
Experimental
Part of the experimental
citry.ext.previewextension, which may change in a minor release without a deprecation period. SeePreviewExtension.