-
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.
feat: added cusomt docs pages examples and docs
- Loading branch information
1 parent
cef6681
commit b25dcef
Showing
25 changed files
with
579 additions
and
5,216 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
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 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
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,86 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
presets:[ | ||
{ | ||
name: require.resolve('webpack-react-docgen-typescript/preset'), | ||
options: { | ||
fileNameResolver: ({ resourcePath, cacheFolder }) => path.join(cacheFolder, resourcePath.replace(/[^a-z0-9]/gi, '_')), | ||
}, | ||
}, | ||
|
||
], | ||
stories: [ | ||
'../../../ui/editors/src/**/*.stories.(js|tsx|mdx)', | ||
'../../../ui/components/src/**/*.stories.(js|tsx|mdx)', | ||
'../../../ui/blocks/src/**/*.stories.(js|tsx|mdx)', | ||
'../../stories/src/**/*.stories.(js|tsx|mdx)', | ||
'../stories/**/*.stories.(js|tsx|mdx)', | ||
], | ||
addons: [ | ||
'@storybook/addon-docs', | ||
{ | ||
name: '@component-controls/storybook', | ||
options: { | ||
addonPanel: false, | ||
docsPage: false, | ||
}, | ||
}, | ||
{ | ||
name: '@component-controls/storybook-custom-docs', | ||
options: { | ||
pages: [ | ||
require.resolve('./page-simple'), | ||
require.resolve('./page-docs-blocks'), | ||
require.resolve('./page-component-blocks'), | ||
require.resolve('./page-mixed-blocks') | ||
] | ||
}, | ||
} | ||
], | ||
webpackFinal: async (config, { configType }) => { | ||
return { | ||
...config, | ||
module: { | ||
...config.module, | ||
rules: [ | ||
...config.module.rules, | ||
{ | ||
test: /\.(story|stories).(js|jsx|ts|tsx|mdx)$/, | ||
loader: "@component-controls/loader/loader", | ||
exclude: [/node_modules/], | ||
enforce: 'pre', | ||
options: { | ||
propsLoaders: [ | ||
{ name: '@component-controls/react-docgen-info', test: /\.(js|jsx)$/}, | ||
{ name: '@component-controls/react-docgen-typescript-info', test: /\.(ts|tsx)$/} | ||
], | ||
prettier: { | ||
tabWidth: 2, | ||
}, | ||
components: { | ||
storeSourceFile: true, //false | ||
resolveFile: (componentName, filePath) => { | ||
if (filePath.includes('/theme-ui/dist')) { | ||
return `${ | ||
filePath.split('/theme-ui/dist')[0] | ||
}/@theme-ui/components/src/${componentName}.js`; | ||
} else if (filePath.includes('@component-controls/storybook/dist')) { | ||
return path.resolve(path.dirname(filePath), `../src/blocks/${componentName}.tsx`) | ||
} | ||
return filePath; | ||
}, | ||
}, | ||
stories: { | ||
storeSourceFile: true, //false | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
...config.resolve, | ||
extensions: [...(config.resolve.extensions || []), '.ts', '.tsx'], | ||
}, | ||
}}, | ||
}; |
22 changes: 22 additions & 0 deletions
22
examples/storybook-custom-docs-pages/.storybook/page-component-blocks.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { DocsContainer } from '@component-controls/storybook'; | ||
import { Story, Title, ControlsTable, Playground } from '@component-controls/blocks'; | ||
|
||
const Page = ({ active, storyId }) => { | ||
return ( | ||
<DocsContainer active={active} storyId={storyId}> | ||
<Title>Component controls blocks</Title> | ||
<Playground openTab="source" title="."> | ||
<Story id="." /> | ||
</Playground> | ||
<ControlsTable id='.' /> | ||
</DocsContainer> | ||
) | ||
} | ||
export default { | ||
key: 'component-page', | ||
title: 'Controls blocks', | ||
render: ({ active, storyId }) => { | ||
return <Page storyId={storyId} active={active} />; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
examples/storybook-custom-docs-pages/.storybook/page-docs-blocks.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { DocsContainer, Primary, Title } from '@storybook/addon-docs/blocks'; | ||
import { getContext } from '@component-controls/storybook-custom-docs'; | ||
|
||
const Page = () => { | ||
return ( | ||
<DocsContainer context={getContext()}> | ||
<Title>Using storybook docs page blocks</Title> | ||
<Primary /> | ||
</DocsContainer> | ||
) | ||
} | ||
export default { | ||
key: 'docs-page', | ||
title: 'Docs blocks', | ||
render: ({ active, storyId }) => { | ||
return active ? <Page storyId={storyId} /> : null; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
examples/storybook-custom-docs-pages/.storybook/page-mixed-blocks.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { DocsContainer as SBDocsContainer, Preview, Story as SBStory, Title as SBTitle, Props} from '@storybook/addon-docs/blocks'; | ||
import { getContext, useStoryId } from '@component-controls/storybook-custom-docs'; | ||
import { DocsContainer } from '@component-controls/storybook'; | ||
import { Story, Title, Playground, PropsTable } from '@component-controls/blocks'; | ||
|
||
const Page = ({ storyId: id }) => { | ||
const storyId = useStoryId(id); | ||
return ( | ||
<> | ||
<SBDocsContainer context={getContext()}> | ||
<SBTitle /> | ||
<Preview > | ||
<SBStory id={storyId} /> | ||
</Preview> | ||
<Props of='.' /> | ||
</SBDocsContainer> | ||
<DocsContainer active={true} storyId={storyId}> | ||
<Title /> | ||
<Playground openTab="source" title="."> | ||
<Story id="." /> | ||
</Playground> | ||
<PropsTable of="." /> | ||
</DocsContainer> | ||
</> | ||
) | ||
} | ||
export default { | ||
key: 'mixed-page', | ||
title: 'Mixed blocks', | ||
render: ({ active, storyId }) => { | ||
return active ? <Page storyId={storyId} /> : null; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
examples/storybook-custom-docs-pages/.storybook/page-simple.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
export default { | ||
key: 'custom', | ||
title: 'Simple Page', | ||
render: ({ active, storyId }) => active ? <div><h1>Simple docs page</h1><p>{storyId}</p></div> : null, | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/storybook-custom-docs-pages/.storybook/preview.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { addParameters } from '@storybook/react'; | ||
|
||
const categories = ['Storybook', 'Blocks', 'Editors', 'Components'] | ||
addParameters({ | ||
dependencies: { hideEmpty: true }, | ||
options: { | ||
storySort: (a, b) => { | ||
const aKind = a[1].kind.split('/')[0]; | ||
const aIndex = categories.findIndex(c => c === aKind); | ||
const bKind = b[1].kind.split('/')[0]; | ||
const bIndex = categories.findIndex(c => c === bKind); | ||
return aIndex - bIndex; | ||
}, | ||
}, | ||
}); |
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,28 @@ | ||
{ | ||
"private": true, | ||
"version": "0.6.0", | ||
"name": "component-controls-storybook-custom-docs-pages", | ||
"license": "MIT", | ||
"scripts": { | ||
"debug": "NODE_OPTIONS=--inspect-brk start-storybook -p 9017 -c .storybook", | ||
"storybook": "start-storybook -p 9017 -c .storybook", | ||
"build-storybook": "build-storybook -c .storybook -o ../../docs" | ||
}, | ||
"dependencies": { | ||
"@component-controls/react-docgen-info": "^0.6.0", | ||
"@component-controls/react-docgen-typescript-info": "^0.6.0", | ||
"@component-controls/storybook": "^0.6.0", | ||
"@component-controls/storybook-custom-docs": "^0.6.0", | ||
"@storybook/addon-docs": "next", | ||
"@storybook/addon-storysource": "next", | ||
"@storybook/react": "next", | ||
"babel-loader": "^8.0.6", | ||
"babel-preset-react-app": "^9.0.0", | ||
"cross-env": "^5.2.0", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0", | ||
"typescript": "^3.8.3", | ||
"webpack-react-docgen-typescript": "^0.9.5" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/storybook-custom-docs-pages/stories/smart-controls.stories.mdx
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 @@ | ||
import { Meta, PropsTable, Playground as Preview, Story, BlockContextProvider, ControlsTable, ComponentSource, StorySource } from '@component-controls/storybook'; | ||
import { Button } from '../../stories/src/components/Button'; | ||
|
||
<Meta title="Storybook/MDX" parameters={{component: Button}} /> | ||
|
||
|
||
<ComponentSource of={Button} title='Component source' /> | ||
|
||
<PropsTable of={Button} /> | ||
|
||
|
||
<Preview> | ||
<Story name="smart story"> | ||
{(props) => ( | ||
<Button label="default" {...props}/> | ||
)} | ||
</Story> | ||
</Preview> | ||
|
||
|
||
|
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,15 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"declaration": true, | ||
"resolveJsonModule": true, | ||
"sourceMap": false, | ||
"outDir": "./dist", | ||
"rootDir": "./src", | ||
"baseUrl": "./", | ||
"typeRoots": ["../../node_modules/@types", "node_modules/@types"] | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules/**"] | ||
} |
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
/* eslint-disable react/display-name */ | ||
import React from 'react'; | ||
import { PageContainer } from './PageContainer'; | ||
import { DocsContainer } from './DocsContainer'; | ||
import { ControlsPage } from './ControlsPage'; | ||
|
||
export default { | ||
key: 'page', | ||
title: 'Page', | ||
render: ({ active, storyId }: { active: boolean; storyId: string }) => { | ||
return ( | ||
<PageContainer active={active} storyId={storyId}> | ||
<DocsContainer active={active} storyId={storyId}> | ||
<ControlsPage /> | ||
</PageContainer> | ||
</DocsContainer> | ||
); | ||
}, | ||
}; |
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,2 @@ | ||
export * from './DocsContainer'; | ||
export * from './ControlsPage'; |
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,2 +1,3 @@ | ||
export * from './context'; | ||
export * from './blocks'; | ||
export * from './context'; | ||
export * from './docs-page'; |
Oops, something went wrong.