Component Stories
Develop and preview Ink components in isolation using the maltty stories viewer -- a Storybook-like TUI that runs in the terminal.
Overview
Stories let you render a component with predefined props, browse variants, and interactively edit props without wiring up a full command. This shortens the feedback loop when building screen-based commands.
Prerequisites
- A maltty project with
malttyand@maltty/cliinstalled - One or more React/Ink components to preview
Defining a story
Create a .stories.tsx file next to the component. Use the story() factory for a single story:
The schema drives the interactive props editor in the viewer. Each field's Zod type determines the control kind (text input, boolean toggle, enum select, etc.).
Defining a story group
Use the stories() factory to define multiple variants that share a component and schema:
Each key in the stories record becomes a selectable variant in the sidebar.
Running the viewer
The viewer discovers all .stories.tsx, .stories.ts, .stories.jsx, and .stories.js files in the project. Use --include to narrow the search:
Viewer features
- Sidebar -- browsable tree of all discovered stories and variants
- Preview -- live render of the selected story with current props
- Props editor -- edit props interactively with type-aware controls
- Hot reload -- file watcher detects changes and reloads stories automatically
- Keyboard shortcuts -- press
?inside the viewer to see all shortcuts
Decorators
Decorators wrap a story component to provide layout, context, or other rendering concerns. Apply them per-story or per-group:
Built-in decorators:
File conventions
- Story files use the
.stories.tsx(or.stories.ts,.stories.jsx,.stories.js) suffix - Place story files next to the component they describe
- Each story file has a single default export created by
story()orstories() - The Zod schema should mirror the component's props interface