Created
September 30, 2021 05:01
-
-
Save javierguzman/64e590d32e32a38324cc5cbb6239b6e4 to your computer and use it in GitHub Desktop.
Storybook Gist with addon-links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const withMemoryRouter = (StoryComponent, { parameters }) => { | |
const { currentURL } = parameters; | |
if (!currentURL) { | |
return <StoryComponent />; | |
} | |
const { path, route, redirectComponent, redirectStory } = currentURL; | |
if (!redirectComponent && !redirectStory) { | |
return ( | |
<MemoryRouter initialEntries={[encodeURI(route)]}> | |
<Route path={path}> | |
<StoryComponent /> | |
</Route> | |
</MemoryRouter> | |
); | |
} | |
return ( | |
<MemoryRouter initialEntries={[encodeURI(route)]}> | |
<Route path={path}> | |
<LinkTo kind={redirectComponent} story={redirectStory} /> | |
</Route> | |
</MemoryRouter> | |
); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Landing from '../Landing'; | |
import notes from './readme.md'; | |
export default { | |
title: 'Common/Landing', | |
component: Landing, | |
parameters: { | |
notes: { notes } | |
} | |
} | |
export const defaultStory = (args) => <Landing {...args} />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Login from './Login'; | |
import notes from './readme.md'; | |
import { withMemoryRouter } from '@StoryDecorator'; | |
export default { | |
title: 'Auth/Login', | |
component: Login, | |
parameters: { | |
notes: { notes } | |
} | |
} | |
const Template = (args) => <Login {...args} />; | |
export const defaultStory = Template.bind({}); | |
export const successLogin = Template.bind({}); | |
successLogin.args = { | |
store: { | |
initialState: { | |
auth: { | |
correctLogin: true, | |
user: { | |
id: '12345', | |
roles: [], | |
sightVotes: [] | |
}, | |
errorMessage: '' | |
} | |
} | |
} | |
}; | |
successLogin.decorators = [ withMemoryRouter ]; | |
successLogin.parameters = { | |
currentURL: { | |
route: '/', | |
path: '/', | |
redirectComponent: 'Common/Landing', | |
redirectStory: 'defaultStory' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment