@@ -4,12 +4,7 @@ import { STORY_CHANGED } from '@storybook/core-events';
44import Rect from '@reach/rect' ;
55
66import {
7- ADDON_ID ,
8- PANEL_ID ,
9- PANEL_Title ,
10- EVENT_ID_INIT ,
11- EVENT_ID_DATA ,
12- EVENT_ID_BACK ,
7+ getConfig ,
138} from './config' ;
149import withChannel from './withChannel' ;
1510
@@ -73,11 +68,14 @@ class PanelHOC extends React.Component {
7368 this . state = {
7469 ...urlState ,
7570 } ;
76- props . api . on ( STORY_CHANGED , ( kind , story ) => this . setState ( { kind, story } ) ) ;
71+ props . api . on ( STORY_CHANGED , ( kind , story ) =>
72+ this . setState ( { kind, story } )
73+ ) ;
7774 }
7875 render ( ) {
7976 const Panel = this . props . component ;
80- const { api, active, data, setData } = this . props ;
77+ const { api, active, data, setData, config } = this . props ;
78+ const { ADDON_ID , PANEL_ID , PANEL_Title} = config ;
8179 const { kind, story } = this . state ;
8280
8381 if ( ! active ) return null ;
@@ -112,16 +110,26 @@ class PanelHOC extends React.Component {
112110 }
113111}
114112
115- const WithChannel = withChannel ( {
116- EVENT_ID_INIT ,
117- EVENT_ID_DATA ,
118- EVENT_ID_BACK ,
119- ADDON_ID ,
120- initData : { panel : 'foo' } ,
121- panel : true ,
122- } ) ( PanelHOC ) ;
113+ export const register = ( Panel , { type = addonTypes . PANEL , initData } = { } ) => {
114+ const config = getConfig ( ) ;
115+ const {
116+ EVENT_ID_INIT ,
117+ EVENT_ID_DATA ,
118+ EVENT_ID_BACK ,
119+ ADDON_ID ,
120+ PANEL_Title,
121+ PANEL_ID ,
122+ } = config ;
123+
124+ const WithChannel = withChannel ( {
125+ EVENT_ID_INIT ,
126+ EVENT_ID_DATA ,
127+ EVENT_ID_BACK ,
128+ ADDON_ID ,
129+ initData,
130+ panel : true ,
131+ } ) ( PanelHOC ) ;
123132
124- export const register = ( Panel , type = addonTypes . PANEL ) =>
125133 addons . register ( ADDON_ID , api => {
126134 addons . add ( PANEL_ID , {
127135 title : PANEL_Title ,
@@ -132,10 +140,10 @@ export const register = (Panel, type = addonTypes.PANEL) =>
132140 key = { key }
133141 api = { api }
134142 active = { active }
135- PANEL_Title = { PANEL_Title }
136143 component = { Panel }
144+ config = { config }
137145 />
138146 ) ,
139147 } ) ;
140-
141148 } ) ;
149+ } ;
0 commit comments