11import React from 'react' ;
22import { CodeEditor , Language } from '@patternfly/react-code-editor' ;
3- import { Grid , GridItem , Label } from '@patternfly/react-core' ;
3+ import { Grid , GridItem , Label , Radio } from '@patternfly/react-core' ;
44
55export const CodeEditorShortcutMainHeader : React . FunctionComponent = ( ) => {
6+ type ShortcutMode = 'PC' | 'Mac' ;
7+
8+ const [ currentShortcutMode , setCurrentShortcutMode ] = React . useState < ShortcutMode > ( 'PC' ) ;
9+
610 const onEditorDidMount = ( editor , monaco ) => {
711 editor . layout ( ) ;
812 editor . focus ( ) ;
913 monaco . editor . getModels ( ) [ 0 ] . updateOptions ( { tabSize : 5 } ) ;
1014 } ;
1115
12- const onChange = ( value ) => {
16+ const onChange = ( value : string ) => {
1317 // eslint-disable-next-line no-console
1418 console . log ( value ) ;
1519 } ;
1620
21+ const onShortcutModeChange = ( event : React . FormEvent < HTMLInputElement > , checked : boolean ) => {
22+ if ( checked ) {
23+ const newMode = event . currentTarget . value as ShortcutMode ;
24+ setCurrentShortcutMode ( newMode ) ;
25+ }
26+ } ;
27+
1728 const shortcuts = [
1829 {
19- keys : [ 'Opt' , 'F1' ] ,
30+ PC : [ 'Alt' , 'F1' ] ,
31+ Mac : [ 'Opt' , 'F1' ] ,
2032 description : 'Accessibility helps'
2133 } ,
2234 {
23- keys : [ 'F1' ] ,
35+ PC : [ 'F1' ] ,
36+ Mac : [ 'F1' ] ,
2437 description : 'View all editor shortcuts'
2538 } ,
2639 {
27- keys : [ 'Ctrl' , 'Space' ] ,
40+ PC : [ 'Ctrl' , 'Space' ] ,
41+ Mac : [ 'Opt' , 'Esc' ] ,
2842 description : 'Activate auto complete'
2943 } ,
3044 {
31- keys : [ 'Cmd' , 'S' ] ,
45+ PC : [ 'Ctrl' , 'S' ] ,
46+ Mac : [ 'Cmd' , 'S' ] ,
3247 description : 'Save'
3348 }
3449 ] ;
@@ -38,7 +53,7 @@ export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
3853 { shortcuts . map ( ( shortcut , index ) => (
3954 < React . Fragment key = { index } >
4055 < GridItem style = { { textAlign : 'right' , marginRight : '1em' } } >
41- { shortcut . keys
56+ { shortcut [ currentShortcutMode ]
4257 . map ( ( key ) => (
4358 < Label variant = "outline" key = { key } >
4459 { key }
@@ -57,14 +72,32 @@ export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
5772 } ;
5873
5974 return (
60- < CodeEditor
61- shortcutsPopoverProps = { shortcutsPopoverProps }
62- isLanguageLabelVisible
63- code = "Some example content"
64- onChange = { onChange }
65- language = { Language . javascript }
66- onEditorDidMount = { onEditorDidMount }
67- height = "400px"
68- />
75+ < >
76+ < Radio
77+ checked = { currentShortcutMode === 'PC' }
78+ onChange = { onShortcutModeChange }
79+ label = "PC shortcuts"
80+ name = "shortcut-radio"
81+ id = "pc-shortcuts"
82+ value = "PC"
83+ />
84+ < Radio
85+ checked = { currentShortcutMode === 'Mac' }
86+ onChange = { onShortcutModeChange }
87+ label = "Mac shortcuts"
88+ name = "shortcut-radio"
89+ id = "mac-shortcuts"
90+ value = "Mac"
91+ />
92+ < CodeEditor
93+ shortcutsPopoverProps = { shortcutsPopoverProps }
94+ isLanguageLabelVisible
95+ code = "Some example content"
96+ onChange = { onChange }
97+ language = { Language . javascript }
98+ onEditorDidMount = { onEditorDidMount }
99+ height = "400px"
100+ />
101+ </ >
69102 ) ;
70103} ;
0 commit comments