Skip to content
Kite

Stage: exercise a component in isolation

Use extras/stage for questions that are awkward to answer in the main app: does the label still fit when it’s longer? Can the disabled control still fire? A named scene fixes the starting conditions; knobs let you vary one input without rebuilding.

Mount taskStage() in a Kitex root to embed the explorer. In a standalone terminal command, call s.Run() instead of returning s.Root(). The scene returns a regular Kitex node. It doesn’t need a second copy of the application or a running service.

func TaskStage() kitex.Node {
s := stage.New()
s.Register("Task actions", []stage.Scene{{
Name: "Submit button",
Render: func(c *stage.Context) kitex.Node {
label := c.Text("Label", "Save task")
disabled := c.Bool("Disabled", false)
priority := c.Select("Priority", []string{"Normal", "High"}, "Normal")
return kitex.Button(kitex.ButtonProps{
Style: demo.Default.PrimaryButton,
Disabled: disabled,
OnPress: func() { c.Log("Submitted: " + priority) },
}, kitex.Text(label))
},
}})
return s.Root()
}

Register takes a component name and a slice of stage.Scene; add separate scenes for important starting states. c.Text, c.Bool, and c.Select return the current control values. Keep knob names stable so you can recognize them when revisiting a scene. Use c.Log inside the event callback, not in the render function: re-rendering isn’t a button press.

Use Up/Down in the sidebar to choose a scene and Tab to reach controls. Change the priority, press Save, and check the action log. Disable the button and try again: there should be no second entry. In the standalone terminal explorer, F12 opens DevTools and Ctrl+C exits Stage.

For shared settings such as a theme, register a GlobalSelect on the stage instead of repeating a knob per scene. WithContextDecorator wraps each scene and receives its context so the wrapper can read global settings. When a particular state must stay correct, turn it into a headless test.