| description | Component development with Storybook |
|---|
This workflow guides component development and visual testing using Storybook in Daedalus.
Daedalus uses Storybook 6.4 for isolated component development and visual testing.
yarn storybookOpens at http://localhost:6006
yarn storybook:buildOutput: dist/storybook/
storybook/
├── .storybook/
│ ├── main.js # Storybook configuration
│ ├── preview.js # Story decorators
│ └── webpack.config.js # Webpack overrides
└── stories/
├── wallets/
│ ├── WalletSendForm.stories.tsx
│ └── ...
├── staking/
├── transactions/
└── ...
import React from 'react';
import { storiesOf } from '@storybook/react';
import MyComponent from '../../source/renderer/app/components/MyComponent';
storiesOf('Category|MyComponent', module)
.add('default', () => (
<MyComponent value="test" onChange={() => {}} />
))
.add('loading', () => (
<MyComponent value="" onChange={() => {}} isLoading />
))
.add('error', () => (
<MyComponent value="" onChange={() => {}} error="Something went wrong" />
));import { storiesOf } from '@storybook/react';
import { withKnobs, text, boolean, number } from '@storybook/addon-knobs';
storiesOf('Category|MyComponent', module)
.addDecorator(withKnobs)
.add('interactive', () => (
<MyComponent
label={text('Label', 'Default Label')}
disabled={boolean('Disabled', false)}
count={number('Count', 5)}
/>
));import { storiesOf } from '@storybook/react';
import { State, Store } from '@dump247/storybook-state';
const store = new Store({
value: '',
});
storiesOf('Category|Input', module)
.add('with state', () => (
<State store={store}>
{state => (
<Input
value={state.value}
onChange={value => store.set({ value })}
/>
)}
</State>
));Organize stories by domain:
| Category | Components |
|---|---|
Wallets |
Wallet creation, send/receive, settings |
Staking |
Pool selection, delegation, rewards |
Transactions |
Transaction list, details, filters |
Hardware Wallet |
Device connection, signing |
Navigation |
Sidebar, top navigation |
Settings |
Profile, display, security |
Common |
Buttons, inputs, dialogs |
Stories are wrapped with theme provider automatically:
// storybook/.storybook/preview.js
import { addDecorator } from '@storybook/react';
import ThemeDecorator from './decorators/ThemeDecorator';
addDecorator(ThemeDecorator);For internationalized components:
import { IntlProvider } from 'react-intl';
const IntlDecorator = (story) => (
<IntlProvider locale="en" messages={messages}>
{story()}
</IntlProvider>
);| Addon | Purpose |
|---|---|
@storybook/addon-actions |
Log component events |
@storybook/addon-knobs |
Interactive prop editing |
@storybook/addon-links |
Link between stories |
import { action } from '@storybook/addon-actions';
storiesOf('Button', module)
.add('with action', () => (
<Button onClick={action('button-clicked')}>
Click Me
</Button>
));storiesOf('Component', module)
.add('default', () => <Component />)
.add('loading', () => <Component isLoading />)
.add('error', () => <Component error="Error message" />)
.add('empty', () => <Component items={[]} />)
.add('with data', () => <Component items={mockData} />);import { generateWallet } from '../../utils/mockData';
const mockWallet = generateWallet({
name: 'Test Wallet',
balance: 1000000000,
});storiesOf('Component', module)
.add('with all props', () => (
<Component
// Required props
id="test-id"
name="Test Name"
// Optional props
description="Optional description"
isActive={true}
/>
));Problem: Build errors on start Solution:
yarn clear:cache
yarn storybookProblem: Blank story Solution:
- Check for missing providers (theme, intl)
- Verify imports are correct
- Check browser console for errors
Problem: Styles not applied Solution:
- Ensure SCSS modules are imported
- Check Webpack config includes SCSS loader
- Verify theme CSS variables are available
Storybook is built as part of CI checks:
yarn check:all # Includes yarn storybook:buildFailed Storybook build will fail CI.