@@ -21,6 +21,9 @@ import { HotKeyBoundActions } from '../hotkeys/HotKeyBoundActions';
2121
2222import { ComponentViewerDropDown } from './ComponentViewerDropDown' ;
2323
24+ import { ComponentViewerHelp } from './help/ComponentViewerHelp' ;
25+ import { globalActionDefaultKeys } from './GlobalActions' ;
26+
2427import './ComponentViewer.css' ;
2528
2629export interface Props {
@@ -44,11 +47,11 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
4447
4548 this . state = this . stateFromUrl ( ) ;
4649 this . hotKeyBoundActions = {
47- 'Alt F' : this . onFullScreenToggle ,
48- 'Ctrl Alt Down' : this . onNextDemo ,
49- 'Ctrl Alt Up' : this . onPrevDemo ,
50- 'Ctrl Alt Right' : this . onNextDemoEntry ,
51- 'Ctrl Alt Left' : this . onPrevDemoEntry ,
50+ [ globalActionDefaultKeys . fullScreenToggle ] : this . onFullScreenToggle ,
51+ [ globalActionDefaultKeys . nextDemo ] : this . onNextDemo ,
52+ [ globalActionDefaultKeys . prevDemo ] : this . onPrevDemo ,
53+ [ globalActionDefaultKeys . nextDemoEntry ] : this . onNextDemoEntry ,
54+ [ globalActionDefaultKeys . prevDemoEntry ] : this . onPrevDemoEntry ,
5255 ...this . dropDownKeyBoundActions ( )
5356 } ;
5457 }
@@ -81,7 +84,8 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
8184 registryName,
8285 demoName,
8386 filterText,
84- selectedToolbarItem
87+ selectedToolbarItem,
88+ isHelpOn
8589 } = this . state ;
8690
8791 return (
@@ -96,7 +100,8 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
96100
97101 < div className = "rcv-toolbar-panel" >
98102 < Toolbar
99- onFullScreen = { this . onFullScreenToggle }
103+ questionMarkToggledOn = { isHelpOn }
104+ onQuestionMarkClick = { this . onQuestionMarkToggle }
100105 dropDownLabel = { dropDown ? dropDown . label : undefined }
101106 dropDownSelected = { selectedToolbarItem }
102107 dropDownItems = { dropDown ? dropDown . items : undefined }
@@ -124,6 +129,10 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
124129 < div className = "rcv-preview" >
125130 { this . renderDemo ( demoEntry , false ) }
126131 </ div >
132+
133+ { isHelpOn && < div className = "rcv-help" >
134+ < ComponentViewerHelp />
135+ </ div > }
127136 </ div >
128137 ) ;
129138 }
@@ -200,12 +209,11 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
200209 }
201210
202211 private onFullScreenToggle = ( ) => {
203- this . pushUrl (
204- this . state . registryName ,
205- this . state . demoName ,
206- this . state . entryTitle ,
207- ! this . state . isFullScreen ,
208- this . state . selectedToolbarItem ) ;
212+ this . pushUrl ( { isFullScreen : ! this . state . isFullScreen } ) ;
213+ }
214+
215+ private onQuestionMarkToggle = ( ) => {
216+ this . pushUrl ( { isHelpOn : ! this . state . isHelpOn } ) ;
209217 }
210218
211219 private onNextDemo = ( ) => {
@@ -260,41 +268,24 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
260268 }
261269
262270 private selectRegistry = ( registryName : string ) => {
263- this . pushUrl (
271+ this . pushUrl ( {
264272 registryName,
265- '' ,
266- '' ,
267- this . state . isFullScreen ,
268- this . state . selectedToolbarItem ) ;
273+ demoName : '' ,
274+ entryTitle : '' } ) ;
269275 }
270276
271277 private selectDemo = ( demoName : string ) => {
272- this . pushUrl (
273- this . state . registryName ,
274- demoName ,
275- '' ,
276- this . state . isFullScreen ,
277- this . state . selectedToolbarItem ) ;
278+ this . pushUrl ( { demoName, entryTitle : '' } ) ;
278279 }
279280
280281 private selectInstanceByTitle = ( title : string ) => {
281- this . pushUrl (
282- this . state . registryName ,
283- this . state . demoName ,
284- title ,
285- this . state . isFullScreen ,
286- this . state . selectedToolbarItem ) ;
282+ this . pushUrl ( { entryTitle : title } ) ;
287283 }
288284
289285 private selectToolbarItem = ( label : string ) => {
290286 const { dropDown} = this . props ;
291287
292- this . pushUrl (
293- this . state . registryName ,
294- this . state . demoName ,
295- this . state . entryTitle ,
296- this . state . isFullScreen ,
297- label ) ;
288+ this . pushUrl ( { selectedToolbarItem : label } ) ;
298289
299290 if ( dropDown ) {
300291 dropDown . onSelect ( label ) ;
@@ -316,15 +307,9 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
316307 [ ] ;
317308 }
318309
319- private pushUrl (
320- registryName : string ,
321- demoName : string ,
322- entryTitle : string ,
323- isFullScreen : boolean ,
324- selectedToolbarItem : string
325- ) {
326- const searchParams = this . stateCreator . buildUrlSearchParams (
327- { registryName, demoName, entryTitle, isFullScreen, selectedToolbarItem, filterText : '' } ) ;
310+ private pushUrl ( newState : Partial < ComponentViewerState > ) {
311+ const fullState = { ...this . state , ...newState } ;
312+ const searchParams = this . stateCreator . buildUrlSearchParams ( { ...fullState , filterText : '' } ) ;
328313 const newUrl = '?' + searchParams ;
329314
330315 window . history . pushState ( { } , '' , newUrl ) ;
0 commit comments