Shadix.Website.Components.ComponentDoc behaviour (shadix v0.0.1)

Copy Markdown View Source

Behaviour + demo macro for per-component documentation modules.

A doc module supplies what reflection can't: a description, the slot example the configurator renders, optional initial prop overrides, a one-line preview/1 that spreads the live prop map into the component, and curated demos. Demos are authored as heredoc HEEx strings and compiled at build time — the same string is rendered and displayed, so they can't drift, and a typo fails compilation rather than the browser.

Summary

Functions

Registers a curated demo. source must be a heredoc string literal (no interpolation) — it is compiled to a render function at build time and kept verbatim for display. opts may include :description.

Callbacks

demos()

(optional)
@callback demos() :: [map()]

description()

(optional)
@callback description() :: String.t() | nil

hidden_controls()

(optional)
@callback hidden_controls() :: [atom()]

preview(map)

@callback preview(map()) :: Phoenix.LiveView.Rendered.t()

prop_overrides()

(optional)
@callback prop_overrides() :: map()

slot_example()

@callback slot_example() :: String.t()

Functions

demo(title, opts \\ [], source)

(macro)

Registers a curated demo. source must be a heredoc string literal (no interpolation) — it is compiled to a render function at build time and kept verbatim for display. opts may include :description.