Skip to content

Commit

Permalink
Merge pull request #19 from idesigncode/storybook
Browse files Browse the repository at this point in the history
Storybook improvements
  • Loading branch information
idesigncode authored Jun 9, 2023
2 parents 7d7e8ce + c18fccb commit 2d72076
Show file tree
Hide file tree
Showing 23 changed files with 163 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .storybook/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default {
name: '@storybook/react-webpack5',
options: {},
},
stories: ['../**/*.mdx', '../**/*.stories.*'],
stories: ['../**/Introduction.mdx', '../**/*.mdx', '../**/*.stories.*'],
storyIndexers: (indexers) => {
// ? Extend js story indexer for mjs
return indexers.map((indexer) => {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @idesigncode/storybook-tools

A collection of tools & React components for use with Storybook.
A collection of ESM tools to document component implementation examples in Storybook.

## Documentation [![Storybook](https://cdn.jsdelivr.net/gh/storybookjs/brand@main/badge/badge-storybook.svg)](https://idesigncode-storybook-tools.netlify.app)

Expand All @@ -9,7 +9,7 @@ Check out the [documentation](https://idesigncode-storybook-tools.netlify.app/)
## Installation

```shell
npm i @idesigncode/storybook-tools --save
npm i @idesigncode/storybook-tools --save-dev
```

## Features
Expand Down
6 changes: 3 additions & 3 deletions __snapshots__/components-defaultvalue.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`Components/DefaultValue Automatic Type Source test 1`] = `
style="white-space: pre;"
>
<span class="token comment">
// Stories of Component.mjs
// Component.stories.mjs
</span>
<span class>
</span>
Expand Down Expand Up @@ -112,7 +112,7 @@ exports[`Components/DefaultValue Manual Type With Link Source test 1`] = `
style="white-space: pre;"
>
<span class="token comment">
// Stories of Component.mjs
// Component.stories.mjs
</span>
<span class>
</span>
Expand Down Expand Up @@ -346,7 +346,7 @@ exports[`Components/DefaultValue Ref Type Source test 1`] = `
style="white-space: pre;"
>
<span class="token comment">
// Stories of Component.mjs
// Component.stories.mjs
</span>
<span class>
</span>
Expand Down
26 changes: 13 additions & 13 deletions __snapshots__/components-propstable.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ exports[`Components/PropsTable Automatic Props Source test 1`] = `
style="white-space: pre;"
>
<span class="token comment">
// InputWithProps.mjs (the "example component")
// Input.example.mjs (the "example component")
</span>
<span class>
</span>
Expand Down Expand Up @@ -893,7 +893,7 @@ exports[`Components/PropsTable Automatic Props Source test 1`] = `
<span class>
</span>
<span class="token function-variable function">
InputWithProps
InputExample
</span>
<span class>
</span>
Expand Down Expand Up @@ -1145,7 +1145,7 @@ exports[`Components/PropsTable Automatic Props Source test 1`] = `
default
</span>
<span class>
InputWithProps
InputExample
</span>
<span class="token punctuation">
;
Expand Down Expand Up @@ -1314,7 +1314,7 @@ exports[`Components/PropsTable Manual Type With Required Source test 1`] = `
style="white-space: pre;"
>
<span class="token comment">
// InputWithProps.mjs (the "example component")
// Input.example.mjs (the "example component")
</span>
<span class>
</span>
Expand Down Expand Up @@ -1389,7 +1389,7 @@ exports[`Components/PropsTable Manual Type With Required Source test 1`] = `
<span class>
</span>
<span class="token function-variable function">
InputWithProps
InputExample
</span>
<span class>
</span>
Expand Down Expand Up @@ -1806,7 +1806,7 @@ exports[`Components/PropsTable Manual Type With Required Source test 1`] = `
default
</span>
<span class>
InputWithProps
InputExample
</span>
<span class="token punctuation">
;
Expand Down Expand Up @@ -2090,7 +2090,7 @@ exports[`Components/PropsTable Raw Import Displayed Source test 1`] = `
style="white-space: pre;"
>
<span class="token comment">
// Source code displayed by &lt;Source code={InputWithPropsRaw} /&gt;
// Source code displayed by &lt;Source code={InputExampleRaw} /&gt;
</span>
<span class>
</span>
Expand Down Expand Up @@ -2144,7 +2144,7 @@ exports[`Components/PropsTable Raw Import Displayed Source test 1`] = `
<span class>
</span>
<span class="token function-variable function">
InputWithProps
InputExample
</span>
<span class>
</span>
Expand Down Expand Up @@ -2350,7 +2350,7 @@ exports[`Components/PropsTable Raw Import Displayed Source test 1`] = `
default
</span>
<span class>
InputWithProps
InputExample
</span>
<span class="token punctuation">
;
Expand All @@ -2372,7 +2372,7 @@ exports[`Components/PropsTable Raw Import test 1`] = `
style="white-space: pre;"
>
<span class="token comment">
// Stories of Input.mjs
// Input.stories.mjs
</span>
<span class>
</span>
Expand All @@ -2382,15 +2382,15 @@ exports[`Components/PropsTable Raw Import test 1`] = `
import
</span>
<span class>
InputWithPropsRaw
InputExampleRaw
</span>
<span class="token keyword">
from
</span>
<span class>
</span>
<span class="token string">
'./InputWithProps.mjs?raw'
'./Input.example.mjs?raw'
</span>
<span class="token punctuation">
;
Expand All @@ -2417,7 +2417,7 @@ exports[`Components/PropsTable Raw Import test 1`] = `
{
</span>
<span class="token tag script language-javascript">
InputWithPropsRaw
InputExampleRaw
</span>
<span class="token tag script language-javascript punctuation">
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions __snapshots__/components-source.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`Components/Source Code test 1`] = `
</div>
`;

exports[`Components/Source Component With Props Raw Displayed Source test 1`] = `
exports[`Components/Source Component Example Raw Displayed Source test 1`] = `
<div class="Source sb-unstyled ">
<pre class="prismjs">
<code class="language-jsx"
Expand Down Expand Up @@ -122,14 +122,14 @@ exports[`Components/Source Component With Props Raw Displayed Source test 1`] =
</div>
`;

exports[`Components/Source Component With Props Raw test 1`] = `
exports[`Components/Source Component Example Raw test 1`] = `
<div class="Source sb-unstyled ">
<pre class="prismjs">
<code class="language-jsx"
style="white-space: pre;"
>
<span class="token comment">
// Stories of Component.mjs
// Component.stories.mjs
</span>
<span class>
</span>
Expand All @@ -139,15 +139,15 @@ exports[`Components/Source Component With Props Raw test 1`] = `
import
</span>
<span class>
ComponentWithPropsRaw
ComponentExampleRaw
</span>
<span class="token keyword">
from
</span>
<span class>
</span>
<span class="token string">
'./ComponentWithProps.mjs?raw'
'./Component.example.mjs?raw'
</span>
<span class="token punctuation">
;
Expand Down Expand Up @@ -197,7 +197,7 @@ exports[`Components/Source Component With Props Raw test 1`] = `
{
</span>
<span class="token tag script language-javascript">
ComponentWithPropsRaw
ComponentExampleRaw
</span>
<span class="token tag script language-javascript punctuation">
}
Expand Down Expand Up @@ -371,14 +371,14 @@ exports[`Components/Source Component With Props Raw test 1`] = `
</div>
`;
exports[`Components/Source Component With Props test 1`] = `
exports[`Components/Source Component Example test 1`] = `
<div class="Source sb-unstyled ">
<pre class="prismjs">
<code class="language-jsx"
style="white-space: pre;"
>
<span class="token comment">
// ComponentWithProps.mjs (the "example component")
// Component.example.mjs (the "example component")
</span>
<span class>
</span>
Expand Down
8 changes: 4 additions & 4 deletions __snapshots__/configuration-webpack.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ exports[`Configuration/Webpack Raw Import test 1`] = `
style="white-space: pre;"
>
<span class="token comment">
// Stories of Component.mjs
// Component.stories.mjs
</span>
<span class>
</span>
Expand All @@ -290,15 +290,15 @@ exports[`Configuration/Webpack Raw Import test 1`] = `
import
</span>
<span class>
ComponentWithPropsRaw
ComponentExampleRaw
</span>
<span class="token keyword">
from
</span>
<span class>
</span>
<span class="token string">
'./ComponentWithProps.mjs?raw'
'./Component.example.mjs?raw'
</span>
<span class="token punctuation">
;
Expand Down Expand Up @@ -562,7 +562,7 @@ exports[`Configuration/Webpack Webpack Final Config test 1`] = `
<span class>
</span>
<span class="token comment">
// ? Enable correct display of dynamic source code in production
// ? Enable unminified display of props in production
</span>
<span class>
</span>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@idesigncode/storybook-tools",
"version": "2.1.0",
"description": "A collection of tools & React components for use with Storybook.",
"description": "A collection of ESM tools to document component implementation examples in Storybook.",
"keywords": [
"react",
"css",
Expand Down
2 changes: 1 addition & 1 deletion src/storybookConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const webpackFinal = async (config) => {
return rule;
});

// ? Enable correct display of dynamic source code in production
// ? Enable unminified display of props in production
config.optimization.minimizer.map((minimizer) => {
minimizer.options.minimizer.options.compress = false;
minimizer.options.minimizer.options.format = { comments: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Input = React.forwardRef((props, ref) => (
));
Input.displayName = 'Input';

const ComponentWithProps = () => {
const ComponentExample = () => {
const ref = React.useRef();

return (
Expand Down Expand Up @@ -56,4 +56,4 @@ const ComponentWithProps = () => {
);
};

export default ComponentWithProps;
export default ComponentExample;
2 changes: 1 addition & 1 deletion stories/DefaultValue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as DefaultValueStories from './DefaultValue.stories.mjs';

# DefaultValue

A simple [MDX component](https://storybook.js.org/docs/react/writing-docs/mdx) that adds a table with details of a single prop's default value.
A simple component that adds a table with details of a single prop's default value.

<Story of={DefaultValueStories.Props} />

Expand Down
2 changes: 1 addition & 1 deletion stories/DefaultValue.stories.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const AutomaticTypeSource = {
return (
<Source
code={[
`// Stories of Component.mjs`,
`// Component.stories.mjs`,
`import DefaultValue from '@idesigncode/storybook-tools/DefaultValue.mjs';`,
``,
formatNodeToJsxString(<DefaultValue {...args} />),
Expand Down
27 changes: 7 additions & 20 deletions stories/ImportPathReplacements.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meta, Story } from '@storybook/addon-docs';
import ImportPathReplacementsObject from './ImportPathReplacementsObject.mjs';
import * as ImportPathReplacementsStories from './ImportPathReplacements.stories.mjs';

<Meta of={ImportPathReplacementsStories} />
Expand All @@ -9,31 +10,17 @@ The [Source](/docs/components-source--docs) component can automatically display

By default, this functionality is disabled unless `process.env.IMPORT_PATH_REPLACEMENTS` has a value - a stringified `{ key: value }` object:

<table style={{ width: '100%' }}>
<tbody>
<tr>
<td>`key`</td>
<td>
A string to match within an import path. Also accepts `^` to prepend
relative paths.
</td>
</tr>
<tr>
<td>`value`</td>
<td>A string to replace the matched `key` string.</td>
</tr>
</tbody>
</table>

> #### Note:
>
> - Import path replacements are performed in the order specified.
> - Matches may occur more than once within an import path.
<ImportPathReplacementsObject />

To use import path replacements globally, you can add the configuration to an `.env` file or with [Storybook environment variables](https://storybook.js.org/docs/react/configure/environment-variables#using-storybook-configuration):

<Story of={ImportPathReplacementsStories.Env} />

> #### Note:
>
> - Import path replacements are performed in the order specified.
> - Matches may occur more than once within an import path.
>
> #### See also:
>
> - [Source](/docs/components-source--docs) - further information and examples of using import path replacements.
Loading

0 comments on commit 2d72076

Please sign in to comment.