This repository has been archived by the owner on Nov 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from pocka/feature/docs-in-panel
Docs in panel mode
- Loading branch information
Showing
14 changed files
with
269 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'storybook-addon-vue-info/lib/register' |
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,7 @@ | ||
export const AddonName = 'STORYBOOK_ADDON_VUE_INFO' | ||
|
||
export const PanelName = AddonName + '/panel' | ||
|
||
export const Events = { | ||
ShowDocs: AddonName + '/show_docs' | ||
} |
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
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 @@ | ||
import * as React from 'react' | ||
import Vue, { ComponentOptions } from 'vue' | ||
import { VueWrapper } from 'vuera' | ||
|
||
import addons, { Api, Channel } from '@storybook/addons' | ||
|
||
import { AddonName, PanelName, Events } from './addon' | ||
import { InfoAddonOptions } from './options' | ||
import { StoryInfo } from './types/info' | ||
|
||
import Wrapper from './components/Wrapper/index.vue' | ||
|
||
interface Props { | ||
channel: Channel | ||
api: Api | ||
active: boolean | ||
} | ||
|
||
interface State { | ||
/** Information of current story */ | ||
info?: StoryInfo | ||
/** Addon options */ | ||
options?: InfoAddonOptions | ||
} | ||
|
||
class Info extends React.Component<Props, State> { | ||
public state: State = {} | ||
|
||
/** Callback to remove event handler */ | ||
private stopListen?: () => void | ||
|
||
/** | ||
* Callback for ShowDocs event | ||
*/ | ||
private onShowDocs = ({ info, options }: State) => { | ||
this.setState({ info, options }) | ||
} | ||
|
||
public componentDidMount() { | ||
const { channel, api } = this.props | ||
|
||
channel.on(Events.ShowDocs, this.onShowDocs) | ||
|
||
this.stopListen = api.onStory(() => { | ||
// Clear panel when story changes | ||
this.setState({ | ||
info: undefined, | ||
options: undefined | ||
}) | ||
}) | ||
} | ||
|
||
public render() { | ||
const { info, options } = this.state | ||
const { active } = this.props | ||
|
||
if (!active || !info || !options) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div> | ||
<VueWrapper component={Wrapper} info={info} options={options} /> | ||
</div> | ||
) | ||
} | ||
|
||
public componentWillUnmount() { | ||
if (this.stopListen) { | ||
this.stopListen() | ||
} | ||
|
||
const { channel } = this.props | ||
|
||
channel.removeListener(Events.ShowDocs, this.onShowDocs) | ||
} | ||
} | ||
|
||
addons.register(AddonName, api => { | ||
addons.addPanel(PanelName, { | ||
title: 'Info(Vue)', | ||
render: ({ active }) => ( | ||
<Info channel={addons.getChannel()} api={api} active={active} /> | ||
) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"es2015", | ||
"es2015.promise" | ||
], | ||
"jsx": "react", | ||
"target": "es5", | ||
"strict": true, | ||
"module": "es2015", | ||
|
Oops, something went wrong.