Skip to main content

Module: shared/utils/storybook

utils

withProviders

withProviders(wrapperProps?): (StoryComponent: AnnotatedStoryFn<ReactRenderer, Args>, storyContext: any) => Element

Storybook decorator to be used in webapp package stories. It wraps the story with all needed providers and allows to pass state to it.

Parameters

NameType
wrapperPropsWrapperProps

Returns

fn

▸ (StoryComponent, storyContext): Element

Parameters
NameType
StoryComponentAnnotatedStoryFn<ReactRenderer, Args>
storyContextany
Returns

Element

Example

Basic usage:

example.stories.tsx
export default {
title: 'ExampleComponent',
component: ExampleComponent,
decorators: [
withProviders(),
],
};

Example

Override user profile:

example.stories.tsx
import { CurrentUserType } from '@shipfast/webapp-api-client/graphql';
import { currentUserFactory, fillCommonQueryWithUser } from '@shipfast/webapp-api-client/tests/factories';
import { ExampleComponent, ExampleComponentProps } from './example.component';

type StoryArgsType = ExampleComponentProps & { profile: CurrentUserType };

const Template: StoryFn<StoryArgsType> = ({ profile, ...args }: StoryArgsType) => {
return <ExampleComponent {...args} />;
};

export default {
title: 'ExampleComponent',
component: ExampleComponent,
decorators: [
withProviders({
apolloMocks: (defaultMocks, { args: { profile } }: any) => {
return [fillCommonQueryWithUser(profile)];
},
}),
],
};

export const Default = {
render: Template,
args: { profile: currentUserFactory({ firstName: 'First name' }) },
};

Defined in

packages/webapp/src/shared/utils/storybook.tsx:54