-
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
46f28a4
commit 02c2368
Showing
7 changed files
with
103 additions
and
3 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,5 +1,10 @@ | ||
import { config } from 'docz-rollup'; | ||
|
||
export default config({ | ||
input: ['./src/index.ts', './src/preset.ts', './src/config.ts'], | ||
input: [ | ||
'./src/index.ts', | ||
'./src/preset.ts', | ||
'./src/config.ts', | ||
'./src/register.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
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 React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { BroadcastChannel } from 'broadcast-channel'; | ||
import { DocsPage } from '../page/DocsPage'; | ||
|
||
const ATTACH_DOCS_PAGE = 'attach_docs_page'; | ||
const channel = new BroadcastChannel(ATTACH_DOCS_PAGE); | ||
|
||
channel.onmessage = (message: { id: string; active: boolean }) => { | ||
console.log('will attach'); | ||
ReactDOM.render( | ||
<DocsPage active={message.active} />, | ||
document.getElementById(message.id), | ||
); | ||
}; |
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,39 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { | ||
ControlsTable, | ||
Title, | ||
Subtitle, | ||
Story, | ||
Playground, | ||
Stories, | ||
Description, | ||
ComponentSource, | ||
PropsTable, | ||
} from '@component-controls/blocks'; | ||
import { ThemeProvider, BlockContextProvider } from '../context'; | ||
|
||
interface DocsPageProps { | ||
active?: boolean; | ||
} | ||
export const DocsPage: FC<DocsPageProps> = ({ active }) => { | ||
if (!active) { | ||
return null; | ||
} | ||
return ( | ||
<ThemeProvider> | ||
<BlockContextProvider> | ||
<Title /> | ||
<Subtitle /> | ||
<Description /> | ||
<ComponentSource id="." title="Component" /> | ||
<Playground openTab="source" title="."> | ||
<Story id="." /> | ||
</Playground> | ||
<ControlsTable id="." /> | ||
<PropsTable of="." /> | ||
<Stories dark={true} /> | ||
</BlockContextProvider> | ||
</ThemeProvider> | ||
); | ||
}; |
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 const ADDON_ID = 'storybook/page'; | ||
export const PANEL_ID = `${ADDON_ID}/panel`; |
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,8 +1,13 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
module.exports = { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
config: (entry: any[] = [], options: any = {}) => { | ||
const result = [...entry]; | ||
result.push(require.resolve('./config')); | ||
return result; | ||
}, | ||
managerEntries: (entry: any[] = [], options: any = {}) => { | ||
const result = [...entry]; | ||
result.push(require.resolve('./register')); | ||
return result; | ||
}, | ||
}; |
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 @@ | ||
/* eslint-disable react/display-name */ | ||
import React from 'react'; | ||
import { addons, types } from '@storybook/addons'; | ||
import { ADDON_ID, PANEL_ID } from './page/constants'; | ||
|
||
interface AddonPanelProps { | ||
active?: boolean; | ||
id?: string; | ||
} | ||
|
||
const AddonPanel: React.FC<AddonPanelProps> = ({ active, id }) => { | ||
const channel = React.useMemo( | ||
() => new BroadcastChannel('attach_docs_page'), | ||
[], | ||
); | ||
React.useEffect(() => { | ||
console.log('will post message'); | ||
channel.postMessage({ id: id, active }); | ||
}, [active]); | ||
return <div id={id} />; | ||
}; | ||
addons.register(ADDON_ID, () => { | ||
const title = 'Page'; | ||
const key = title.toLowerCase(); | ||
addons.add(PANEL_ID, { | ||
type: types.TAB, | ||
title, | ||
route: ({ storyId }) => `/${key}/${storyId}`, | ||
match: ({ viewMode }) => viewMode === key, | ||
render: ({ active }) => ( | ||
<AddonPanel active={active} id={`controls-docs-page-${key}`} /> | ||
), | ||
}); | ||
}); |