-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08f59a0
commit d165187
Showing
33 changed files
with
542 additions
and
97 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
import React from 'react'; | ||
import { DocsContainer, Story} from '@storybook/addon-docs/blocks'; | ||
import { getContext, useStoryId } from '@component-controls/storybook-custom-docs'; | ||
|
||
const Page = () => { | ||
const storyId = useStoryId(); | ||
return ( | ||
<DocsContainer context={getContext()}><Story id={storyId}/></DocsContainer> | ||
) | ||
} | ||
export default { | ||
key: 'docs-page', | ||
title: 'Docs Page', | ||
render: ({ active, storyId }) => { | ||
return active ? <Page storyId={storyId} /> : null; | ||
} | ||
} |
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,7 @@ | ||
import React from 'react'; | ||
|
||
export default { | ||
key: 'custom', | ||
title: 'Custom Page', | ||
render: ({ active, storyId }) => active ? <div>{storyId}</div> : null, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/preset'); |
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 was deleted.
Oops, something went wrong.
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
18 changes: 2 additions & 16 deletions
18
...ions/storybook/src/page/PageContainer.tsx → ...storybook/src/docs-page/PageContainer.tsx
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
File renamed without changes.
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,16 @@ | ||
/* eslint-disable react/display-name */ | ||
import React from 'react'; | ||
import { PageContainer } from './PageContainer'; | ||
import { ControlsPage } from './ControlsPage'; | ||
|
||
export default { | ||
key: 'page', | ||
title: 'Page', | ||
render: ({ active, storyId }: { active: boolean; storyId: string }) => { | ||
return ( | ||
<PageContainer active={active} storyId={storyId}> | ||
<ControlsPage /> | ||
</PageContainer> | ||
); | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Atanas Stoyanov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,105 @@ | ||
# Table of contents | ||
|
||
|
||
# Overview | ||
|
||
The Storybook [docs addon](https://github.com/storybookjs/storybook/tree/next/addons/docs) is a great feature in Storybook, but unfortunately it is not extensibe with core parts being hard-coded. | ||
|
||
`@component-controls/storybook-custom-docs` gives the possibility to add custom `docs` pages to storybook by solving the following challenges: | ||
|
||
- Custom docs pages need to reside in the `preview` part of Storybok (in order to render stories since that's where the stories are), while the TABS addons resides in the `manager` part of storybook | ||
- Custom docs pages need to reside inside the preview `iframe` (also in order to render stories in the custom `docs` pages), while addons are rendered outside the `iframe`. | ||
|
||
|
||
# Getting Started | ||
|
||
## Install | ||
|
||
```sh | ||
yarn add @component-controls/storybook-custom-docs --dev | ||
``` | ||
|
||
## Configure | ||
within `.storybook/main.js`: | ||
|
||
```js | ||
module.exports = { | ||
addons: [ | ||
{ | ||
name: '@component-controls/storybook-custom-docs', | ||
options: { | ||
pages: [ | ||
// files exporting the custom pages: | ||
require.resolve('./custom-page'), | ||
require.resolve('./custom-page-docs') | ||
], | ||
}, | ||
}, | ||
], | ||
} | ||
``` | ||
|
||
## Pages format | ||
|
||
The page definition files need to have a default export with the following fields | ||
```js | ||
import React from 'react'; | ||
export default { | ||
// key used for navigation | ||
key: string, | ||
// title of the tab | ||
title: string, | ||
// react render function. | ||
// active boolean - if the tab custom page is active | ||
// storyId as a string | ||
// Return an object that can be rendered from ReactDOM.render | ||
render: ({ active, storyId }) => Element, | ||
} | ||
``` | ||
|
||
## Examples | ||
|
||
### Very simple page: | ||
|
||
```js | ||
import React from 'react'; | ||
|
||
export default { | ||
key: 'custom', | ||
title: 'Custom Page', | ||
render: ({ active, storyId }) => active ? <div>{storyId}</div> : null, | ||
} | ||
``` | ||
|
||
### Custom page rendering current story | ||
|
||
```js | ||
import React from 'react'; | ||
import { DocsContainer, Story} from '@storybook/addon-docs/blocks'; | ||
import { getContext, useStoryId } from '@component-controls/storybook-custom-docs'; | ||
|
||
const Page = () => { | ||
const storyId = useStoryId(); | ||
return ( | ||
<DocsContainer context={getContext()}><Story id={storyId}/></DocsContainer> | ||
) | ||
} | ||
export default { | ||
key: 'docs-page', | ||
title: 'Docs Page', | ||
render: ({ active, storyId }) => { | ||
return active ? <Page storyId={storyId} /> : null; | ||
} | ||
} | ||
``` | ||
|
||
# API | ||
|
||
## **getContext** | ||
|
||
Returns a context similar (but not identical) that can be used as an input attribute to `<DocsContainer />` | ||
|
||
## **useStoryId** | ||
|
||
A hook that tracks the changes to the current story and returns it's id | ||
|
Oops, something went wrong.