Documentation
¶
Overview ¶
Package stage provides an interactive, isolated component development stage and playground for kitex applications.
Index ¶
- Variables
- func Register[P any](reg *Registry, config ComponentConfig[P])
- type ActionLog
- type ComponentConfig
- type Context
- func (c *Context) Bool(name string, defaultValue bool) bool
- func (c *Context) ClearLogs()
- func (c *Context) Controls() []Control
- func (c *Context) Global(name string) any
- func (c *Context) GlobalBool(name string, defaultValue bool) bool
- func (c *Context) GlobalInt(name string, defaultValue int) int
- func (c *Context) GlobalString(name string, defaultValue string) string
- func (c *Context) Int(name string, defaultValue int) int
- func (c *Context) Log(msg string)
- func (c *Context) Logs() []ActionLog
- func (c *Context) Select(name string, options []string, defaultValue string) string
- func (c *Context) Text(name string, defaultValue string) string
- func (c *Context) WithGlobals(globals map[string]Control, globalValues map[string]any) *Context
- type Control
- type ControlOverride
- type ControlType
- type EmptyProps
- type PlayableAreaProps
- type Registry
- type Scene
- type SceneConfig
- type Stage
- func (s *Stage) GlobalBool(name string, defaultValue bool) *Stage
- func (s *Stage) GlobalInt(name string, defaultValue int) *Stage
- func (s *Stage) GlobalSelect(name string, options []string, defaultValue string) *Stage
- func (s *Stage) GlobalText(name string, defaultValue string) *Stage
- func (s *Stage) Merge(prefix string, reg *Registry)
- func (s *Stage) Register(component string, scenes []Scene)
- func (s *Stage) Root() kitex.Node
- func (s *Stage) Run()
- func (s *Stage) WithContextDecorator(fn func(*Context, kitex.Node) kitex.Node) *Stage
- func (s *Stage) WithDecorator(fn func(kitex.Node) kitex.Node) *Stage
- type StageAppProps
Constants ¶
This section is empty.
Variables ¶
var PlayableArea = kitex.FC("PlayableArea", func(props PlayableAreaProps) kitex.Node { knobValues, setKnobValues := kitex.UseState(make(map[string]any)) logs, setLogs := kitex.UseState([]ActionLog{}) setKnobValue := func(name string, val any) { prev := knobValues() next := make(map[string]any) maps.Copy(next, prev) next[name] = val setKnobValues(next) } globalsMap := make(map[string]Control) for _, ctrl := range props.Globals { globalsMap[ctrl.Name] = ctrl } sceneContext := NewContext(knobValues(), setKnobValue, nil). WithGlobals(globalsMap, props.GlobalValues) sceneContext.onLogAdded = func() { setLogs(sceneContext.Logs()) } renderedScene := props.Scene.Render(sceneContext) if renderedScene != nil && props.Decorator != nil { renderedScene = props.Decorator(sceneContext, renderedScene) } // 4. Render toolbar widgets (global controls) var toolbarWidgets []kitex.Node for _, ctrl := range props.Globals { var inputWidget kitex.Node switch ctrl.Type { case ControlTypeText: currentStr := "" if val, ok := props.GlobalValues[ctrl.Name]; ok { currentStr, _ = val.(string) } else if ctrl.Default != nil { currentStr, _ = ctrl.Default.(string) } capturedName := ctrl.Name inputWidget = kitex.Input(kitex.InputProps{ Value: currentStr, Style: style.S(). Width(style.Cells(15)). Background(color.RGBA{R: 31, G: 41, B: 55, A: 255}). Padding(0, 1), OnInput: func(ie *event.InputEvent) { props.SetGlobalVal(capturedName, ie.Value) }, }) case ControlTypeBool: currentBool := false if val, ok := props.GlobalValues[ctrl.Name]; ok { currentBool, _ = val.(bool) } else if ctrl.Default != nil { currentBool, _ = ctrl.Default.(bool) } capturedName := ctrl.Name checkboxLabel := "[ ]" if currentBool { checkboxLabel = "[x]" } inputWidget = kitex.Button( kitex.ButtonProps{ Style: style.S(). Border(false). Background(color.RGBA{R: 55, G: 65, B: 81, A: 255}). Padding(0, 1), OnClick: func(e *event.MouseEvent) { props.SetGlobalVal(capturedName, !currentBool) }, }, kitex.Text(checkboxLabel), ) case ControlTypeSelect: currentStr := "" if val, ok := props.GlobalValues[ctrl.Name]; ok { currentStr, _ = val.(string) } else if ctrl.Default != nil { currentStr, _ = ctrl.Default.(string) } capturedName := ctrl.Name capturedOptions := ctrl.Options cycleOptionsText := fmt.Sprintf("%s ▾", currentStr) if currentStr == "" { cycleOptionsText = "select..." } inputWidget = kitex.Button( kitex.ButtonProps{ Style: style.S(). Border(false). Background(color.RGBA{R: 55, G: 65, B: 81, A: 255}). Padding(0, 1), OnClick: func(e *event.MouseEvent) { nextIdx := 0 for optIdx, opt := range capturedOptions { if opt == currentStr { nextIdx = (optIdx + 1) % len(capturedOptions) break } } if len(capturedOptions) > 0 { props.SetGlobalVal(capturedName, capturedOptions[nextIdx]) } }, }, kitex.Text(cycleOptionsText), ) case ControlTypeInt: currentInt := 0 if val, ok := props.GlobalValues[ctrl.Name]; ok { switch v := val.(type) { case int: currentInt = v case float64: currentInt = int(v) } } else if ctrl.Default != nil { switch v := ctrl.Default.(type) { case int: currentInt = v case float64: currentInt = int(v) } } capturedName := ctrl.Name stepperBtnStyle := style.S(). Border(false). Background(color.RGBA{R: 55, G: 65, B: 81, A: 255}). Foreground(color.RGBA{R: 209, G: 213, B: 219, A: 255}). Padding(0, 1) inputWidget = kitex.Box.Style( style.S(). Display(style.DisplayFlex). FlexDirection(style.FlexRow). AlignItems(style.AlignCenter). Width(style.Cells(12)), kitex.Button( kitex.ButtonProps{ Style: stepperBtnStyle, OnClick: func(e *event.MouseEvent) { props.SetGlobalVal(capturedName, currentInt-1) }, }, kitex.Text("−"), ), kitex.Box.Style( style.S(). Flex(1). Background(color.RGBA{R: 31, G: 41, B: 55, A: 255}). Foreground(color.RGBA{R: 229, G: 231, B: 235, A: 255}). Padding(0, 1), kitex.Text(strconv.Itoa(currentInt)), ), kitex.Button( kitex.ButtonProps{ Style: stepperBtnStyle, OnClick: func(e *event.MouseEvent) { props.SetGlobalVal(capturedName, currentInt+1) }, }, kitex.Text("+"), ), ) } toolbarWidgets = append(toolbarWidgets, kitex.Box.Style( style.S(). Display(style.DisplayFlex). FlexDirection(style.FlexRow). AlignItems(style.AlignCenter). MarginRight(2), kitex.Box.Style( style.S(). Foreground(color.RGBA{R: 156, G: 163, B: 175, A: 255}). MarginRight(1), kitex.Text(ctrl.Name+":"), ), inputWidget, )) } // 5. Render controls panel rows var controlRows []kitex.Node ctrls := sceneContext.Controls() sort.Slice(ctrls, func(i, j int) bool { return ctrls[i].Name < ctrls[j].Name }) for _, ctrl := range ctrls { var inputWidget kitex.Node switch ctrl.Type { case ControlTypeText: currentStr := "" if val, ok := knobValues()[ctrl.Name]; ok { currentStr, _ = val.(string) } else if ctrl.Default != nil { currentStr, _ = ctrl.Default.(string) } capturedName := ctrl.Name inputWidget = kitex.Input(kitex.InputProps{ Value: currentStr, Style: style.S(). Width(style.Percent(100)). Background(color.RGBA{R: 31, G: 41, B: 55, A: 255}). Padding(0, 1), OnInput: func(ie *event.InputEvent) { setKnobValue(capturedName, ie.Value) }, }) case ControlTypeBool: currentBool := false if val, ok := knobValues()[ctrl.Name]; ok { currentBool, _ = val.(bool) } else if ctrl.Default != nil { currentBool, _ = ctrl.Default.(bool) } capturedName := ctrl.Name checkboxLabel := "[ ]" if currentBool { checkboxLabel = "[x]" } inputWidget = kitex.Button( kitex.ButtonProps{ Style: style.S(). Border(false). Background(color.RGBA{R: 55, G: 65, B: 81, A: 255}). Padding(0, 0), OnClick: func(e *event.MouseEvent) { setKnobValue(capturedName, !currentBool) }, }, kitex.Text(checkboxLabel), ) case ControlTypeSelect: currentStr := "" if val, ok := knobValues()[ctrl.Name]; ok { currentStr, _ = val.(string) } else if ctrl.Default != nil { currentStr, _ = ctrl.Default.(string) } capturedName := ctrl.Name capturedOptions := ctrl.Options cycleOptionsText := fmt.Sprintf("%s ▾", currentStr) if currentStr == "" { cycleOptionsText = "select..." } inputWidget = kitex.Button( kitex.ButtonProps{ Style: style.S(). Border(false). Background(color.RGBA{R: 55, G: 65, B: 81, A: 255}). Padding(0, 1), OnClick: func(e *event.MouseEvent) { nextIdx := 0 for optIdx, opt := range capturedOptions { if opt == currentStr { nextIdx = (optIdx + 1) % len(capturedOptions) break } } if len(capturedOptions) > 0 { setKnobValue(capturedName, capturedOptions[nextIdx]) } }, }, kitex.Text(cycleOptionsText), ) case ControlTypeInt: currentInt := 0 if val, ok := knobValues()[ctrl.Name]; ok { switch v := val.(type) { case int: currentInt = v case float64: currentInt = int(v) } } else if ctrl.Default != nil { switch v := ctrl.Default.(type) { case int: currentInt = v case float64: currentInt = int(v) } } capturedName := ctrl.Name stepperBtnStyle := style.S(). Border(false). Background(color.RGBA{R: 55, G: 65, B: 81, A: 255}). Foreground(color.RGBA{R: 209, G: 213, B: 219, A: 255}). Padding(0, 1) inputWidget = kitex.Box.Style( style.S(). Display(style.DisplayFlex). FlexDirection(style.FlexRow). AlignItems(style.AlignCenter). Width(style.Percent(100)), kitex.Button( kitex.ButtonProps{ Style: stepperBtnStyle, OnClick: func(e *event.MouseEvent) { setKnobValue(capturedName, currentInt-1) }, }, kitex.Text("−"), ), kitex.Box.Style( style.S(). Flex(1). Background(color.RGBA{R: 31, G: 41, B: 55, A: 255}). Foreground(color.RGBA{R: 229, G: 231, B: 235, A: 255}). Padding(0, 1), kitex.Text(strconv.Itoa(currentInt)), ), kitex.Button( kitex.ButtonProps{ Style: stepperBtnStyle, OnClick: func(e *event.MouseEvent) { setKnobValue(capturedName, currentInt+1) }, }, kitex.Text("+"), ), ) } controlRows = append(controlRows, kitex.Box.Style( style.S(). Display(style.DisplayFlex). FlexDirection(style.FlexRow). Width(style.Percent(100)). AlignItems(style.AlignCenter). MarginBottom(1), kitex.Box.Style( style.S(). Width(style.Percent(40)). MinWidth(style.Cells(0)). Foreground(color.RGBA{R: 156, G: 163, B: 175, A: 255}), kitex.Text(ctrl.Name), ), kitex.Box.Style( style.S(). Display(style.DisplayFlex). Width(style.Percent(60)). MinWidth(style.Cells(0)), inputWidget, ), )) } // 6. Render action logs rows var logRows []kitex.Node for _, l := range logs() { logRows = append(logRows, kitex.Box.Style( style.S().Display(style.DisplayFlex).FlexDirection(style.FlexRow).Width(style.Percent(100)), kitex.Box.Style( style.S(). Width(style.Cells(10)). Foreground(color.RGBA{R: 107, G: 114, B: 128, A: 255}), kitex.Text(l.Timestamp), ), kitex.Box.Style( style.S().Foreground(color.RGBA{R: 209, G: 213, B: 219, A: 255}), kitex.Text(l.Message), ), )) } return kitex.Box.Style( playableAreaStyle, func() kitex.Node { if len(props.Globals) > 0 { return kitex.Box.Style( toolbarStyle, toolbarWidgets..., ) } return nil }(), kitex.Box.Style( canvasStyle, kitex.Box.Style( canvasInnerStyle, func() kitex.Node { if renderedScene != nil { return renderedScene } return kitex.Text("Select a scene to start") }(), ), ), kitex.Box.Style( detailPanelStyle, kitex.Box.Style( controlsPanelStyle, kitex.Box.Style( style.S(). MarginBottom(1). BorderBottom(true, style.BorderSingle, color.RGBA{R: 75, G: 85, B: 99, A: 255}), kitex.Text("🛠️ CONTROLS"), ), kitex.Box.Style( style.S().Flex(1).Overflow(style.OverflowAuto), controlRows..., ), ), kitex.Box.Style( logsPanelStyle, kitex.Box.Style( style.S(). Display(style.DisplayFlex). FlexDirection(style.FlexRow). JustifyContent(style.JustifyBetween). MarginBottom(1). BorderBottom(true, style.BorderSingle, color.RGBA{R: 75, G: 85, B: 99, A: 255}), kitex.Text("📋 ACTION LOG"), kitex.Button( kitex.ButtonProps{ Style: style.S(). Border(false). Background(color.RGBA{R: 79, G: 70, B: 229, A: 255}). Padding(0, 1), OnClick: func(e *event.MouseEvent) { setLogs([]ActionLog{}) if sceneContext != nil { sceneContext.ClearLogs() } }, }, kitex.Text("Clear"), ), ), kitex.Box.Style( style.S().Flex(1).Overflow(style.OverflowAuto), logRows..., ), ), ), ) })
PlayableArea manages the active scene hooks, rendering, knobs context, and details panels. Because it is keyed by the active scene index, all hooks and knob values are cleanly destroyed and recreated when the active scene changes.
var StageApp = kitex.FC("StageApp", func(props StageAppProps) kitex.Node { // 1. Trie structure to support nested sections type trieNode struct { Name string FullPath string Children map[string]*trieNode Scenes []Scene CompName string } normalizeComponentPath := func(compName string) []string { if compName == "" { return []string{"Default", "Default"} } parts := strings.Split(compName, "/") if len(parts) == 1 { return []string{"Default", parts[0]} } else if len(parts) == 2 { return []string{"Default", parts[0], parts[1]} } return parts } buildTrie := func(components map[string][]Scene) *trieNode { root := &trieNode{ Children: make(map[string]*trieNode), } for compName, scenes := range components { parts := normalizeComponentPath(compName) curr := root var pathBuilder []string for _, part := range parts { pathBuilder = append(pathBuilder, part) fullPath := strings.Join(pathBuilder, "/") if curr.Children == nil { curr.Children = make(map[string]*trieNode) } child, ok := curr.Children[part] if !ok { child = &trieNode{ Name: part, FullPath: fullPath, Children: make(map[string]*trieNode), } curr.Children[part] = child } curr = child } curr.Scenes = scenes curr.CompName = compName } return root } rootTrieNode := buildTrie(props.Stage.components) type sceneRef struct { compName string sceneName string index int } var allScenes []sceneRef var traverseTree func(*trieNode) traverseTree = func(node *trieNode) { var childKeys []string for k := range node.Children { childKeys = append(childKeys, k) } sort.Strings(childKeys) for _, k := range childKeys { traverseTree(node.Children[k]) } for i, sc := range node.Scenes { allScenes = append(allScenes, sceneRef{ compName: node.CompName, sceneName: sc.Name, index: i, }) } } traverseTree(rootTrieNode) activeSceneIdx, setActiveSceneIdx := kitex.UseState(0) expandedComps, setExpandedComps := kitex.UseState(make(map[string]bool)) globalValues, setGlobalValues := kitex.UseState(make(map[string]any)) filterText, setFilterText := kitex.UseState("") rootRef := kitex.UseRef[dom.Node](nil) filterInputRef := kitex.UseRef[*element.InputElement](nil) // Trie filter matching helpers var nodeMatches func(*trieNode, string) bool nodeMatches = func(node *trieNode, query string) bool { if query == "" { return true } query = strings.ToLower(query) if strings.Contains(strings.ToLower(node.Name), query) { return true } for _, sc := range node.Scenes { if strings.Contains(strings.ToLower(sc.Name), query) { return true } } for _, child := range node.Children { if nodeMatches(child, query) { return true } } return false } type filteredSceneRef struct { sc Scene index int } getFilteredScenes := func(node *trieNode, query string) []filteredSceneRef { var res []filteredSceneRef queryLower := strings.ToLower(query) compMatch := query == "" || strings.Contains(strings.ToLower(node.Name), queryLower) for i, sc := range node.Scenes { if compMatch || strings.Contains(strings.ToLower(sc.Name), queryLower) { res = append(res, filteredSceneRef{sc: sc, index: i}) } } return res } isExpanded := func(path string, node *trieNode) bool { query := filterText() if query != "" { return nodeMatches(node, query) } m := expandedComps() if val, ok := m[path]; ok { return val } if len(allScenes) > 0 { parts := normalizeComponentPath(allScenes[0].compName) firstCompNormalized := strings.Join(parts, "/") return path == firstCompNormalized || strings.HasPrefix(firstCompNormalized, path+"/") } return false } toggleComp := func(path string, node *trieNode) { m := expandedComps() next := make(map[string]bool) maps.Copy(next, m) next[path] = !isExpanded(path, node) setExpandedComps(next) } expandComponent := func(compName string) { parts := normalizeComponentPath(compName) m := expandedComps() next := make(map[string]bool) maps.Copy(next, m) var pathBuilder []string for _, part := range parts { pathBuilder = append(pathBuilder, part) next[strings.Join(pathBuilder, "/")] = true } setExpandedComps(next) } setGlobalVal := func(name string, val any) { prev := globalValues() next := make(map[string]any) maps.Copy(next, prev) next[name] = val setGlobalValues(next) } // Active scene reference var activeScene *Scene if len(allScenes) > 0 && activeSceneIdx() >= 0 && activeSceneIdx() < len(allScenes) { ref := allScenes[activeSceneIdx()] activeScene = &props.Stage.components[ref.compName][ref.index] } // Render sidebar list items as a nested collapsible tree var visibleIndices []int var sidebarItems []kitex.Node sceneKeyToIndex := make(map[string]int) for i, ref := range allScenes { key := fmt.Sprintf("%s:%d", ref.compName, ref.index) sceneKeyToIndex[key] = i } var renderNode func(*trieNode, int) renderNode = func(node *trieNode, depth int) { if node.FullPath == "" { var childKeys []string for k, child := range node.Children { if nodeMatches(child, filterText()) { childKeys = append(childKeys, k) } } sort.Strings(childKeys) for i, k := range childKeys { if i > 0 { sidebarItems = append(sidebarItems, kitex.Box.Style( style.S().Height(style.Cells(1)), )) } renderNode(node.Children[k], 0) } return } expanded := isExpanded(node.FullPath, node) var icon string hasChildren := len(node.Children) > 0 hasScenes := len(node.Scenes) > 0 if depth == 0 { if hasChildren { if expanded { icon = "◇ " } else { icon = "◆ " } } else { if expanded { icon = "✧ " } else { icon = "✦ " } } } else { if hasChildren { if expanded { icon = "▼ " } else { icon = "▶ " } } else if hasScenes { if expanded { icon = "⬡ " } else { icon = "⬢ " } } } headerStyle := style.S(). Padding(0, 1+depth*2). Width(style.Percent(100)). Bold(true) if hasChildren { headerStyle = headerStyle.Foreground(color.RGBA{R: 209, G: 213, B: 219, A: 255}) } else { headerStyle = headerStyle.Foreground(color.RGBA{R: 229, G: 231, B: 235, A: 255}) } capturedPath := node.FullPath capturedNode := node sidebarItems = append(sidebarItems, kitex.Box(kitex.BoxProps{ Style: headerStyle, OnClick: func(e *event.MouseEvent) { toggleComp(capturedPath, capturedNode) }, }, kitex.Text(icon+node.Name))) if expanded { var childKeys []string for k, child := range node.Children { if nodeMatches(child, filterText()) { childKeys = append(childKeys, k) } } sort.Strings(childKeys) for _, k := range childKeys { renderNode(node.Children[k], depth+1) } for _, fsc := range getFilteredScenes(node, filterText()) { key := fmt.Sprintf("%s:%d", node.CompName, fsc.index) globalIdx, found := sceneKeyToIndex[key] if !found { continue } visibleIndices = append(visibleIndices, globalIdx) isSelected := globalIdx == activeSceneIdx() itemStyle := style.S(). Padding(0, 1+(depth+1)*2+1). Width(style.Percent(100)) if isSelected { itemStyle = itemStyle. Background(color.RGBA{R: 79, G: 70, B: 229, A: 255}). Foreground(color.RGBA{R: 255, G: 255, B: 255, A: 255}) } else { itemStyle = itemStyle. Foreground(color.RGBA{R: 156, G: 163, B: 175, A: 255}) } capturedIdx := globalIdx sidebarItems = append(sidebarItems, kitex.Box(kitex.BoxProps{ Style: itemStyle, OnClick: func(e *event.MouseEvent) { setActiveSceneIdx(capturedIdx) }, }, kitex.Text("▪ "+fsc.sc.Name))) } } } renderNode(rootTrieNode, 0) kitex.UseEffectCleanup(func() func() { if rootRef.Current == nil { return nil } doc := rootRef.Current.OwnerDocument() if doc == nil { return nil } listener := func(e event.Event) { ke := e.(*event.KeyEvent) isInputFocused := false if target := e.Target(); target != nil { if el, ok := target.(dom.Element); ok && el.TagName() == "input" { isInputFocused = true } } if ke.MatchString("/") { if !isInputFocused && filterInputRef.Current != nil { filterInputRef.Current.Focus() e.PreventDefault() return } } if ke.MatchString("escape") || ke.MatchString("esc") { if isInputFocused && filterInputRef.Current != nil { filterInputRef.Current.Blur() if rootRef.Current != nil { if el, ok := rootRef.Current.(dom.Element); ok { el.SetTabIndex(0) el.Focus() } } e.PreventDefault() return } } // Determine navigable list var navList []int if filterText() == "" { navList = make([]int, len(allScenes)) for i := range allScenes { navList[i] = i } } else { navList = visibleIndices } current := activeSceneIdx() pos := -1 for i, idx := range navList { if idx == current { pos = i break } } isUp := ke.MatchString("up") || (!isInputFocused && ke.MatchString("k")) isDown := ke.MatchString("down") || (!isInputFocused && ke.MatchString("j")) if isUp { if pos > 0 { targetIdx := navList[pos-1] setActiveSceneIdx(targetIdx) if filterText() == "" && targetIdx >= 0 && targetIdx < len(allScenes) { expandComponent(allScenes[targetIdx].compName) } } e.PreventDefault() } else if isDown { if pos >= 0 && pos < len(navList)-1 { targetIdx := navList[pos+1] setActiveSceneIdx(targetIdx) if filterText() == "" && targetIdx >= 0 && targetIdx < len(allScenes) { expandComponent(allScenes[targetIdx].compName) } } else if pos == -1 && len(navList) > 0 { targetIdx := navList[0] setActiveSceneIdx(targetIdx) if filterText() == "" && targetIdx >= 0 && targetIdx < len(allScenes) { expandComponent(allScenes[targetIdx].compName) } } e.PreventDefault() } } sub := doc.AddEventListener(event.EventKeyDown, listener) return func() { sub.Cancel() } }, len(allScenes), activeSceneIdx(), len(visibleIndices), filterText()) return kitex.Box(kitex.BoxProps{ Ref: rootRef, Style: style.S(). Display(style.DisplayFlex). FlexDirection(style.FlexRow). Width(style.Percent(100)). Height(style.Percent(100)). Background(color.RGBA{R: 31, G: 41, B: 55, A: 255}), }, kitex.Box.Style( sidebarStyle, kitex.Box.Style( style.S(). MarginBottom(1). BorderBottom(true, style.BorderSingle, color.RGBA{R: 75, G: 85, B: 99, A: 255}), kitex.Text("📖 SCENES"), ), kitex.Input(kitex.InputProps{ Ref: filterInputRef, Value: filterText(), Placeholder: "Filter (press /)...", Style: style.S(). Width(style.Percent(100)). MarginBottom(1). Background(color.RGBA{R: 31, G: 41, B: 55, A: 255}). Foreground(color.RGBA{R: 243, G: 244, B: 246, A: 255}). Padding(0, 1), OnValueChange: func(val string) { setFilterText(val) }, OnKeyDown: func(ke *event.KeyEvent) { if ke.MatchString("escape") || ke.MatchString("enter") { if filterInputRef.Current != nil { filterInputRef.Current.Blur() } ke.PreventDefault() } }, }), kitex.Box.Style( style.S().Flex(1).Overflow(style.OverflowAuto), sidebarItems..., ), ), func() kitex.Node { if activeScene != nil { key := fmt.Sprintf("scene-%d", activeSceneIdx()) return PlayableArea.Props(PlayableAreaProps{ Key: key, Scene: activeScene, Decorator: props.Stage.decorator, Globals: props.Stage.globals, GlobalValues: globalValues(), SetGlobalVal: setGlobalVal, }) } return kitex.Box.Style( playableAreaStyle.Background(color.RGBA{R: 31, G: 41, B: 55, A: 255}), kitex.Text("Select a scene to start"), ) }(), ) })
StageApp renders the interactive playground user interface.
Functions ¶
func Register ¶
func Register[P any](reg *Registry, config ComponentConfig[P])
Register registers a component in the registry using reflection-based control generation.
Types ¶
type ComponentConfig ¶
type ComponentConfig[P any] struct { Name string DefaultProps P Render func(c *Context, props P) kitex.Node Controls map[string]ControlOverride Scenes []SceneConfig[P] Description string }
ComponentConfig specifies the configuration for a reflection-based component registration.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is passed to each Scene's Render function to register/query knobs and log actions.
func NewContext ¶
func NewContext(values map[string]any, setVal func(name string, val any), onLogAdded func()) *Context
NewContext creates a new Context for scene execution.
func (*Context) GlobalBool ¶
GlobalBool returns the value of a global control as a boolean.
func (*Context) GlobalString ¶
GlobalString returns the value of a global control as a string.
type Control ¶
type Control struct {
Name string `json:"name"`
Type ControlType `json:"type"`
Default any `json:"default"`
Options []string `json:"options,omitempty"` // populated only for ControlTypeSelect
}
Control contains the metadata for a single scene knob.
type ControlOverride ¶
type ControlOverride struct {
Label string
Min, Max int
Step int
Options []string
Description string
Hidden bool
}
ControlOverride allows customizing or overriding the auto-generated TUI controls.
type ControlType ¶
type ControlType string
ControlType represents the type of interactive knob/input control.
const ( ControlTypeText ControlType = "text" ControlTypeBool ControlType = "bool" ControlTypeSelect ControlType = "select" ControlTypeInt ControlType = "int" )
type EmptyProps ¶
type EmptyProps struct{}
EmptyProps is a default props type with no fields. Use it when registering components that do not have any controls/knobs.
type PlayableAreaProps ¶
type PlayableAreaProps struct {
Key string
Scene *Scene
Decorator func(*Context, kitex.Node) kitex.Node
Globals []Control
GlobalValues map[string]any
SetGlobalVal func(string, any)
}
PlayableAreaProps is the properties for the PlayableArea component.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores registered components and their scenes.
func (*Registry) RegisterRaw ¶
RegisterRaw registers a list of raw scenes directly.
type SceneConfig ¶
SceneConfig defines a scene variation with custom override props.
type Stage ¶
type Stage struct {
*Registry
// contains filtered or unexported fields
}
Stage manages components and their scenes for isolation testing.
func (*Stage) GlobalBool ¶
GlobalBool registers a global boolean control.
func (*Stage) GlobalSelect ¶
GlobalSelect registers a global dropdown select control.
func (*Stage) GlobalText ¶
GlobalText registers a global text control.
func (*Stage) Merge ¶
Merge merges components from another sub-registry into this stage, prepending the given prefix (if any) to the component paths.
func (*Stage) WithContextDecorator ¶
WithContextDecorator sets a context-aware wrapper function that is applied around every rendered scene node, exposing global controls to the decorator.
func (*Stage) WithDecorator ¶
WithDecorator sets a wrapper function that is applied around every rendered scene node. Use it to inject global providers — theme contexts, store providers, or any kitex.Node wrapper — without modifying individual scenes.
Example:
stg := stage.New()
stg.WithDecorator(func(n kitex.Node) kitex.Node {
return ThemeCtx.Provider(myTheme, n)
})
type StageAppProps ¶
type StageAppProps struct {
Stage *Stage
}
StageAppProps is the properties for the master StageApp component.