Run a parent and child together

Open the cards demo, or run it in your checkout:

cargo run -p vapors-app --example demo -- cards

Each visible card is a child component. Its parent supplies a title and the body content.

Give the child props

card.wisp declares a string title and a Snippet for the content between the component’s opening and closing tags:

card.wisp
<script>#[prop]let title: String = String::new();#[prop]let children: Snippet = Snippet::empty();</script><style>/* A card (1-R1): a title row over whatever its parent passes it as   children, which it places with {render children()}. */section { margin: 8px; background-color: #ffffff; border: 1px solid #c7ccd1; border-radius: 6px; }h2 { margin: 0; padding: 8px 12px; font-size: 14px; background-color: #171b1f; color: #e4e8ec; border-radius: 5px 5px 0 0; }.body { display: flex; align-items: center; gap: 12px; padding: 8px 12px; }</style><section><h2>{title}</h2><div class="body">{render children()}</div></section>
vapors component source

The child renders the title in a heading and places the supplied content with {render children()}. Its stylesheet applies only to elements it creates.

Compose the parent

cards.wisp imports the generated types and creates a card for each layer:

cards.wisp
<script>use crate::card::{Card, CardProps};let tick: Signal<u32> = Signal::new(0);let layers: Signal<Vec<(i32, String, i32)>> = Signal::new(    (1..=20_i32)        .zip(["Curves", "Levels", "Saturation", "Warmth"].iter().cycle().skip(1))        .map(|(id, kind)| (id, String::from(*kind), id * 5 - 50))        .collect(),);</script><style>/* The layer stack (1-R1): a keyed list of layers, each a Card titled   with the layer's kind, its body the readout snippet declared once   here and rendered per layer with the layer's values: a thumbnail, the   amount, the parent's tick, and a button. */:global(html), :global(body) { height: 100%; }:global(html) { overflow: hidden; }:global(body) { margin: 0; display: grid; grid-template-rows: 44px minmax(0, 1fr); background-color: #e9ecef; font-size: 14px; color: #171b1f; }.bar { display: flex; align-items: center; padding: 0 12px; background-color: #171b1f; color: #e4e8ec; }.stack { overflow: auto; scrollbar-color: #3a4148 transparent; scrollbar-width: thin; }.thumb { width: 48px; }.text { flex-grow: 1; }button { padding: 6px 12px; border: none; border-radius: 6px; background-color: #3a7bd5; color: #ffffff; }</style>{snippet readout(kind: String, amount: i32)}<img class="thumb" src="sky.png"><div class="text">{kind} {amount} at tick {tick}</div><button>Edit</button>{/snippet}<div class="bar">Layers</div><div class="stack">{for layer in layers.get() key=layer.0}<Card title={layer.get().1}>{render readout(layer.1.clone(), layer.2)}</Card>{/for}</div>
vapors component source

The named readout snippet describes each card’s body. The parent passes it inside <Card>, along with a title prop. Elements supplied by the parent retain the parent’s style scope; the child’s heading uses the child’s scope.

Try a change

In crates/demos/demos/card.wisp, change the heading’s background color and rebuild. Every card heading should change. Then change the parent’s button color in cards.wisp: the buttons change independently of the child headings.

Choose prop behavior deliberately

Plain props are read when a child mounts. Passing the current value of a parent’s state does not automatically resend later values. Use a prop typed as Signal<T> when the child needs a shared reactive handle.

The file names produce the generated card and cards modules. A capitalized component tag needs its component and props types in scope, as the parent’s import shows. See Components for build integration and Templates for snippet rules.