Vitus Labs
Rocketstories

API Reference

Complete API reference for @vitus-labs/rocketstories.

Factory Functions

init

init(options?: InitOptions): (component: ComponentType) => RocketStoriesBuilder

Creates a curried factory with shared configuration. Returns a function that accepts a component and returns a story builder.

OptionTypeDescription
themeobjectTheme object for the decorator
decoratorsDecorator[]Storybook decorators
storyOptionsStoryOptionsDefault layout options
controlsRecord<string, Control>Default controls

rocketstories

rocketstories(component: ComponentType, options?: InitOptions): RocketStoriesBuilder

One-shot factory that creates a story builder directly for a component.

Builder Methods

.init()

.init(): StorybookMeta

Returns the Storybook default export object containing component, title, and decorators.

.main()

.main(): StoryObj

Returns the main story with auto-generated controls. For rocketstyle components, includes dimension and pseudo-state controls.

.dimension(name, options?)

.dimension(name: string, options?: { ignore?: string[] }): StoryObj | null

Returns a story showcasing all values of a rocketstyle dimension. Returns null for non-rocketstyle components.

ParameterTypeDescription
namestringDimension prop name (e.g., 'state', 'size')
options.ignorestring[]Dimension values to exclude

.render(callback)

.render(callback: (props: ComponentProps) => ReactNode): StoryObj

Returns a story with a custom render function.

.list(options)

.list(options: ListOptions): StoryObj

Returns a story rendering multiple component instances as a list.

OptionTypeDescription
dataany[]Array of items to render
valueNamestringProp name for primitive array items
itemKeystring | ((item, index) => string)Key derivation
itemPropsobjectExtra props for each item
wrapComponentComponentTypeWrapper component
wrapPropsobjectProps for wrapper

Chaining Methods

All methods return a new builder instance (immutable).

.attrs(props)

.attrs(props: Record<string, any>): RocketStoriesBuilder

Merge default props for all stories.

.controls(config)

.controls(config: Record<string, Control>): RocketStoriesBuilder

Define Storybook arg controls.

.storyOptions(options)

.storyOptions(options: StoryOptions): RocketStoriesBuilder

Configure story layout.

.config(options)

.config(options: ConfigOptions): RocketStoriesBuilder

Update configuration (name, prefix, decorators, storyOptions).

.decorators(decorators)

.decorators(decorators: Decorator[]): RocketStoriesBuilder

Add or replace Storybook decorators.

.replaceComponent(component)

.replaceComponent(component: ComponentType): RocketStoriesBuilder

Swap the showcased component while keeping configuration.

Types

StoryOptions

interface StoryOptions {
  direction?: 'inline' | 'rows'
  alignX?: 'left' | 'center' | 'right' | 'spaceBetween'
  alignY?: 'top' | 'center' | 'bottom' | 'spaceBetween'
  gap?: number
  pseudo?: boolean
}

Control

interface Control {
  type?: ControlType
  value?: any
  valueType?: string
  description?: string
  group?: string
  options?: any[]
  disable?: boolean
}

ControlType

TypeStorybook UIWhen to Use
'text'Text inputString values
'number'Number inputNumeric values
'range'SliderBounded numbers (pair with min/max)
'boolean'Toggle switchtrue/false
'color'Color pickerColor strings
'select'Dropdown (single)Choose one from options array
'multi-select'Multi-select dropdownChoose multiple from options
'radio'Radio groupSingle choice (stacked layout)
'inline-radio'Inline radio groupSingle choice (horizontal layout)
'check'Checkbox groupMultiple choices (stacked layout)
'inline-check'Inline checkboxesMultiple choices (horizontal layout)
'tag'Tag selectorHTML tag names
'object'JSON editorObject values
'array'Array editorArray values
'function'Disabled (shown as type)Function references (not interactive)
'component'Disabled (shown as type)Component references (not interactive)

Auto-Generated Controls

For rocketstyle components, controls are automatically generated:

SourceControl TypeExample
Single-select dimensions'select'state: { type: 'select', options: ['primary', 'danger'] }
Multi-select dimensions'multi-select'multiple: { type: 'multi-select', options: ['bold', 'italic'] }
Pseudo-states'boolean'hover: { type: 'boolean' }

Auto-generated controls are merged with manually defined controls — manual controls take precedence.

Configuration

Full story configuration shape:

interface Configuration {
  component: RocketType | ElementType  // Component to showcase
  attrs: Record<string, any>           // Default prop values
  name: string                         // Display name (auto-detected)
  prefix?: string                      // Story title prefix (e.g., 'Components/')
  storyOptions: Partial<StoryOptions>  // Layout rendering options
  controls: Record<string, Control>    // Storybook control definitions
  decorators: Decorator[]              // HOCs wrapping stories
}

RocketStoryConfiguration

Configuration narrowed to rocketstyle components (guarantees component is RocketType).

StoryConfiguration

Configuration narrowed to regular React components (guarantees component is ElementType).

StoryComponent

Functional component extended with Storybook metadata:

type StoryComponent<P = {}> = FC<P> & Partial<{
  args: Record<string, unknown>
  argTypes: Record<string, unknown>
  parameters: Record<string, unknown>
}>

IRocketStories

The builder interface returned by init() and rocketstories(). All chain methods are immutable — each returns a new builder.

RocketType

Type guard for rocketstyle components — must have IS_ROCKETSTYLE, getStaticDimensions(), and getDefaultAttrs().

getStaticDimensions()

Static method on rocketstyle components, called internally by rocketstories to introspect dimensions:

component.getStaticDimensions(theme: object): {
  dimensions: Record<string, Record<string, any>>  // dimension → { value1, value2, ... }
  useBooleans: boolean                              // Boolean shorthand enabled
  multiKeys: Record<string, true>                   // Multi-select dimensions
}

Used to:

  • Generate Storybook control dropdowns automatically
  • Extract dimension values for .dimension() story rendering
  • Create code snippets in Storybook docs panel
  • Determine 'select' vs 'multi-select' control type

Decorator System

Decorators are functions that wrap story components:

type Decorator = (Story: ComponentType) => ReactNode

Built-in Theme Decorator

import Theme from '@vitus-labs/rocketstories/decorators/Theme'

Wraps each story in rocketstyle + unistyle providers. Reads theme from the global config set via init({ theme }) and applies 'light' mode by default.

Custom Decorators

const LayoutDecorator = (Story) => (
  <div style={{ maxWidth: 600, margin: '0 auto' }}>
    <Story />
  </div>
)

const stories = storyOf(Button).decorators([Theme, LayoutDecorator])

Decorators accumulate — calling .decorators() appends to any decorators from init().

Exports

import { init, rocketstories } from '@vitus-labs/rocketstories'
import Theme from '@vitus-labs/rocketstories/decorators/Theme'

import type {
  IRocketStories,
  Init,
  Rocketstories,
  Configuration,
  RocketStoryConfiguration,
  StoryConfiguration,
  StoryComponent,
  StorybookControl,
  RocketType,
  Control,
  ControlTypes,
  Controls,
  PartialControls,
  StoryOptions,
  ExtractDimensions,
  ExtractProps,
  ElementType,
} from '@vitus-labs/rocketstories'

On this page