-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storyshots: First-class CSF support (#8000)
Storyshots: First-class CSF support
- Loading branch information
Showing
79 changed files
with
2,539 additions
and
1,849 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
import { configure } from '@storybook/react'; | ||
|
||
const req = require.context('../stories/required_with_context', true, /\.stories\.js$/); | ||
|
||
function loadStories() { | ||
req.keys().forEach(filename => req(filename)); | ||
require('../stories/directly_required'); | ||
} | ||
|
||
configure(loadStories, module); | ||
configure( | ||
[ | ||
require.context('../stories/required_with_context', false, /\.stories\.js$/), | ||
require.context('../stories/directly_required', false, /index\.js$/), | ||
], | ||
module | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { configure } from '@storybook/react'; | ||
|
||
const req = require.context('../stories/required_with_context', true, /\.stories\.js$/); | ||
const req = require.context('../stories/required_with_context', false, /\.stories\.js$/); | ||
|
||
function loadStories() { | ||
req.keys().forEach(filename => req(filename)); | ||
const loadStories = () => { | ||
const result = req.keys().map(filename => req(filename)); | ||
// eslint-disable-next-line global-require | ||
require('../stories/directly_required'); | ||
} | ||
return result; | ||
}; | ||
|
||
configure(loadStories, module); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { ScriptTransformer } = require('@jest/transform'); | ||
|
||
const getNextTransformer = (fileName, config) => { | ||
const self = config.transform.find(([pattern]) => new RegExp(pattern).test(fileName)); | ||
return new ScriptTransformer({ | ||
...config, | ||
transform: config.transform.filter(entry => entry !== self), | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
process(src, fileName, config, { instrument }) { | ||
const transformer = getNextTransformer(fileName, config); | ||
const { code } = transformer.transformSource(fileName, src, instrument); | ||
|
||
return `${code}; | ||
if(exports.default != null) { | ||
exports.default.parameters = exports.default.parameters || {}; | ||
exports.default.parameters.fileName = '${fileName}'; | ||
} | ||
`; | ||
}, | ||
}; |
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
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
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
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
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
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
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
32 changes: 20 additions & 12 deletions
32
addons/storyshots/storyshots-core/stories/required_with_context/Button.stories.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
import React from 'react'; | ||
|
||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Button } from '@storybook/react/demo'; | ||
|
||
storiesOf('Button', module) | ||
.addParameters({ | ||
export default { | ||
title: 'Button', | ||
|
||
parameters: { | ||
component: Button, | ||
}) | ||
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>) | ||
.add('with some emoji', () => ( | ||
<Button onClick={action('clicked')}> | ||
<span role="img" aria-label="so cool"> | ||
😀 😎 👍 💯 | ||
</span> | ||
</Button> | ||
)); | ||
}, | ||
}; | ||
|
||
export const withText = () => <Button onClick={action('clicked')}>Hello Button</Button>; | ||
|
||
export const withSomeEmoji = () => ( | ||
<Button onClick={action('clicked')}> | ||
<span role="img" aria-label="so cool"> | ||
😀 😎 👍 💯 | ||
</span> | ||
</Button> | ||
); | ||
|
||
withSomeEmoji.story = { | ||
name: 'with some emoji', | ||
}; |
17 changes: 12 additions & 5 deletions
17
addons/storyshots/storyshots-core/stories/required_with_context/Welcome.stories.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import React from 'react'; | ||
|
||
import { storiesOf } from '@storybook/react'; | ||
import { linkTo } from '@storybook/addon-links'; | ||
import { Welcome } from '@storybook/react/demo'; | ||
|
||
storiesOf('Welcome', module) | ||
.addParameters({ | ||
export default { | ||
title: 'Welcome', | ||
|
||
parameters: { | ||
component: Welcome, | ||
}) | ||
.add('to Storybook', () => <Welcome showApp={linkTo('Button')} />); | ||
}, | ||
}; | ||
|
||
export const toStorybook = () => <Welcome showApp={linkTo('Button')} />; | ||
|
||
toStorybook.story = { | ||
name: 'to Storybook', | ||
}; |
2 changes: 1 addition & 1 deletion
2
...storyshots-core/stories/required_with_context/__snapshots__/Async.stories.async.storyshot
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
2 changes: 1 addition & 1 deletion
2
.../storyshots/storyshots-core/stories/required_with_context/__snapshots__/Async.stories.foo
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
2 changes: 1 addition & 1 deletion
2
...shots/storyshots-core/stories/required_with_context/__snapshots__/Async.stories.storyshot
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
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
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
Oops, something went wrong.