Skip to content

Commit c637701

Browse files
committed
chore: finish blog post
1 parent cb4cee5 commit c637701

File tree

1 file changed

+123
-2
lines changed

1 file changed

+123
-2
lines changed

examples/stories/src/blogs/custom-docs-pages.mdx

+123-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ the custom page template files must have a default export with the following fie
8181

8282
## Examples
8383

84-
1. **From component-controls/pages**
84+
1. **From `component-controls/pages`**
8585

8686
Component-controls comes with a handy selection of page templates that you can use as a starting point. The only requirement is to enclose the pages in a `DocsContainer` context from `@component-controls/storybook`
8787

@@ -98,4 +98,125 @@ export default {
9898
</DocsContainer>
9999
): null,
100100
};
101-
```
101+
```
102+
103+
![component-controls page](https://github.com/ccontrols/component-controls/raw/master/misc/storybook-custom-docs/images/custom-page.jpeg)
104+
105+
2. **Custom render the current story**
106+
107+
You can create docs pages from the grounds up and to render the stories, you can use the context.storyFn which is the equivalent of the story decorated CSF export.
108+
109+
```js
110+
import React, { createElement } from 'react';
111+
import { useContext } from '@component-controls/storybook-custom-docs';
112+
const CustomPage = () => {
113+
const context = useContext();
114+
return (
115+
<div>
116+
<h1>Simple docs page</h1>
117+
{createElement(context.storyFn)}
118+
</div>
119+
);
120+
}
121+
const page = {
122+
key: 'custom',
123+
title: 'Simple Page',
124+
render: ({ active }) => active ? <CustomPage /> : null,
125+
}
126+
export default page;
127+
```
128+
![simple custom page](https://github.com/ccontrols/component-controls/raw/master/misc/storybook-custom-docs/images/simple-page.jpg)
129+
130+
3. **Storybook addon-docs blocks**
131+
132+
In order to embed storybook's addon-docs block elements, you need to import them from `@storybook/addon-docs/blocks` and enclose them in a `DocsContainer` container:
133+
134+
```js
135+
import React from 'react';import { DocsContainer, Story, Preview, Source, Title } from '@storybook/addon-docs/blocks';
136+
import { useContext } from '@component-controls/storybook-custom-docs';
137+
const Page = () => {
138+
const context = useContext();
139+
return (
140+
<DocsContainer context={context}>
141+
<Title>Using storybook docs page blocks</Title>
142+
<Preview>
143+
<Story id="." />
144+
</Preview>
145+
<Source id="." />
146+
</DocsContainer>
147+
);
148+
}
149+
const page = {
150+
key: 'docs-page',
151+
title: 'Docs blocks',
152+
render: ({ active }) => active ? <Page /> : null}
153+
export default page;
154+
```
155+
![storybook docs blocks](https://github.com/ccontrols/component-controls/raw/master/misc/storybook-custom-docs/images/docs-blocks.jpg)
156+
157+
4. **Component-controls blocks**
158+
159+
In order to embed component-controls own blocks, you need to enclose them in a `DocsContainer` imported from '@component-controls/storybook' and the basic blocks are to be imported from '@component-controls/blocks'
160+
161+
```js
162+
import React from 'react';
163+
import { DocsContainer } from '@component-controls/storybook';
164+
import { Story, Title, Playground } from '@component-controls/blocks';
165+
const Page = ({ active }) => (
166+
<DocsContainer active={active} >
167+
<Title>Component controls blocks</Title>
168+
<Playground openTab="source" title=".">
169+
<Story id="." />
170+
</Playground>
171+
</DocsContainer>
172+
);
173+
const page = {
174+
key: 'component-page',
175+
title: 'Controls blocks',
176+
render: ({ active }) => active ? <Page /> : null
177+
}
178+
export default page;
179+
```
180+
![component-controls blocks](https://github.com/ccontrols/component-controls/raw/master/misc/storybook-custom-docs/images/componnet-controls-blocks.jpg)
181+
182+
183+
5. **Mixed blocks**
184+
185+
You can even create documentation pages with a mix of storybook and component-controls block components:
186+
```js
187+
import React from 'react';
188+
import { DocsContainer as SBDocsContainer, Preview, Story as SBStory, Title as SBTitle, Props} from '@storybook/addon-docs/blocks';
189+
import { useContext } from '@component-controls/storybook-custom-docs';
190+
import { DocsContainer } from '@component-controls/storybook';
191+
import { Story, Title, Playground, PropsTable } from '@component-controls/blocks';
192+
const Page = () => {
193+
const context = useContext();
194+
return (
195+
<>
196+
<h1>Mixing storybook docs blocks and component-controls blocks</h1>
197+
<SBDocsContainer context={context}>
198+
<SBTitle />
199+
<Preview >
200+
<SBStory id={context.storyId} />
201+
</Preview>
202+
<Props of='.' />
203+
</SBDocsContainer>
204+
<DocsContainer storyId={context.storyId}>
205+
<Title />
206+
<Playground openTab="source" title="." dark={true}>
207+
<Story id="." />
208+
</Playground>
209+
<PropsTable of="." />
210+
</DocsContainer>
211+
</>
212+
);
213+
}
214+
const page = {
215+
key: 'mixed-page',
216+
title: 'Mixed blocks',
217+
render: ({ active }) => active ? <Page /> : null,
218+
}
219+
export default page;
220+
```
221+
![mixed blocks](https://github.com/ccontrols/component-controls/raw/master/misc/storybook-custom-docs/images/mixed-blocks.jpg)
222+

0 commit comments

Comments
 (0)