Skip to Content
vitus·labs
Rocketstories

API Reference

Complete API reference for @vitus-labs/rocketstories.

Factory Functions

init

init(options: InitOptions): (component: ComponentType) => IRocketStories

Creates a curried factory with shared configuration. Returns a function that accepts a component and returns a story builder. Also the package's default export.

OptionTypeDescription
themeobjectTheme used to introspect rocketstyle components (getStaticDimensions / getDefaultAttrs); snapshotted per builder
decoratorsDecorator[]Storybook decorators
storyOptionsStoryOptionsDefault layout options (merged over { gap: 16, direction: 'rows', alignY: 'top', alignX: 'left' })

Other Configuration keys are accepted by the type but not applied — use .config() / .controls() for name, prefix and controls.

rocketstories

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

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

Builder Methods

.init

.init: { component, title, decorators }

The Storybook default export object — a property, not a method (no parentheses). Use it directly as the file's default export:

export default stories.init

.main()

.main(): StoryComponent

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

.dimension(name, options?)

.dimension(name: keyof $$rocketstyle, options?: { ignore?: string[] }): StoryComponent | null

Returns a story showcasing all values of a rocketstyle dimension. Returns null for non-rocketstyle components, and a "not found" placeholder story when the component has no such dimension.

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

.render(callback)

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

Returns a story with a custom render function.

.list(options)

.list(options: ListOptions): StoryComponent

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: Partial<Record<keyof Props, Control>>): RocketStoriesBuilder

Define Storybook arg controls. Merged with previously defined controls.

.storyOptions(options)

.storyOptions(options: StoryOptions): RocketStoriesBuilder

Configure story layout.

.config(options)

.config(options: ConfigOptions): RocketStoriesBuilder

Update configuration (name, prefix, decorators, storyOptions, component). The story title becomes ${prefix}/${name}; re-chaining never re-prepends the prefix. When component differs from the current component, attrs are reset (the prior attrs were tailored to the old component's prop shape). Other story-level config is preserved.

.decorators(decorators)

.decorators(decorators: Decorator[]): RocketStoriesBuilder

Append Storybook decorators to the existing list.

.replaceComponent(component)

.replaceComponent(component: ComponentType): RocketStoriesBuilder

Swap the showcased component while keeping storyOptions, controls, and decorators. Resets attrs when the new component differs from the current one — same swap-reset behaviour as .config({ component }).

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. In .main() manual controls take precedence; in .dimension() stories the generated dimension controls win.

Configuration

Full story configuration shape:

interface Configuration {
  component: RocketType | ElementType  // Component to showcase
  attrs: Record<string, any>           // Default prop values
  name: string                         // Story title (`prefix/base` once computed)
  baseName?: string                    // Internal: name without the prefix
  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
  theme?: Record<string, unknown>      // Snapshotted theme for introspection
}

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

Theme Decorator

The package does not export a decorator (its exports map only exposes the root entry). Define one that wraps stories in the rocketstyle + unistyle providers:

.storybook/ThemeDecorator.tsx
import { Provider } from '@vitus-labs/rocketstyle'
import { Provider as UnistyleProvider } from '@vitus-labs/unistyle'
import { theme } from '../src/theme'

export const ThemeDecorator = (Story) => (
  <Provider provider={UnistyleProvider} mode="light" theme={theme}>
    <Story />
  </Provider>
)

Custom Decorators

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

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

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

Exports

import init, { rocketstories } from '@vitus-labs/rocketstories' // `init` is also a named export

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

StoryOptions and ListOptions above are descriptive names only — they are not exported; use Configuration['storyOptions'] if you need the type.

Edit on GitHub

Last updated on

On this page