@patternfly/react-code-editor 6.0.0-alpha.8 → 6.0.0-alpha.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/CHANGELOG.md +848 -0
  2. package/README.md +37 -40
  3. package/dist/esm/components/CodeEditor/CodeEditor.d.ts +8 -2
  4. package/dist/esm/components/CodeEditor/CodeEditor.d.ts.map +1 -1
  5. package/dist/esm/components/CodeEditor/CodeEditor.js +47 -41
  6. package/dist/esm/components/CodeEditor/CodeEditor.js.map +1 -1
  7. package/dist/esm/components/CodeEditor/CodeEditorControl.d.ts.map +1 -1
  8. package/dist/esm/components/CodeEditor/CodeEditorControl.js +1 -1
  9. package/dist/esm/components/CodeEditor/CodeEditorControl.js.map +1 -1
  10. package/dist/js/components/CodeEditor/CodeEditor.d.ts +8 -2
  11. package/dist/js/components/CodeEditor/CodeEditor.d.ts.map +1 -1
  12. package/dist/js/components/CodeEditor/CodeEditor.js +47 -41
  13. package/dist/js/components/CodeEditor/CodeEditor.js.map +1 -1
  14. package/dist/js/components/CodeEditor/CodeEditorControl.d.ts.map +1 -1
  15. package/dist/js/components/CodeEditor/CodeEditorControl.js +1 -1
  16. package/dist/js/components/CodeEditor/CodeEditorControl.js.map +1 -1
  17. package/package.json +9 -10
  18. package/src/components/CodeEditor/CodeEditor.tsx +77 -65
  19. package/src/components/CodeEditor/CodeEditorControl.tsx +8 -3
  20. package/src/components/CodeEditor/__test__/CodeEditor.test.tsx +69 -39
  21. package/src/components/CodeEditor/__test__/CodeEditorControl.test.tsx +18 -0
  22. package/src/components/CodeEditor/__test__/__snapshots__/CodeEditor.test.tsx.snap +116 -536
  23. package/src/components/CodeEditor/__test__/__snapshots__/CodeEditorControl.test.tsx.snap +26 -0
  24. package/src/components/CodeEditor/examples/CodeEditor.md +5 -0
  25. package/src/components/CodeEditor/examples/CodeEditorCustomControl.tsx +2 -1
  26. package/src/components/CodeEditor/examples/CodeEditorShortcutMainHeader.tsx +51 -18
@@ -0,0 +1,26 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Matches snapshot 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ style="display: contents;"
7
+ >
8
+ <button
9
+ aria-disabled="false"
10
+ class="pf-v6-c-button pf-m-plain"
11
+ data-ouia-component-id="OUIA-Generated-Button-plain-1"
12
+ data-ouia-component-type="PF6/Button"
13
+ data-ouia-safe="true"
14
+ type="button"
15
+ >
16
+ <span
17
+ class="pf-v6-c-button__icon pf-m-start"
18
+ >
19
+ <div>
20
+ icon
21
+ </div>
22
+ </span>
23
+ </button>
24
+ </div>
25
+ </DocumentFragment>
26
+ `;
@@ -15,11 +15,13 @@ import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
15
15
  ### Basic
16
16
 
17
17
  ```ts file="./CodeEditorBasic.tsx"
18
+
18
19
  ```
19
20
 
20
21
  ### With sizeToFit height, height will grow/shrink with content
21
22
 
22
23
  ```ts file="./CodeEditorSizeToFit.tsx"
24
+
23
25
  ```
24
26
 
25
27
  ### With shortcut menu and main header content
@@ -27,14 +29,17 @@ import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
27
29
  These examples below are the shortcuts that we recommend describing in the popover since they are monaco features.
28
30
 
29
31
  ```ts file="./CodeEditorShortcutMainHeader.tsx"
32
+
30
33
  ```
31
34
 
32
35
  ### With actions
33
36
 
34
37
  ```ts file="./CodeEditorWithActions.tsx"
38
+
35
39
  ```
36
40
 
37
41
  ### With custom control
38
42
 
39
43
  ```ts file="CodeEditorCustomControl.tsx"
44
+
40
45
  ```
@@ -3,7 +3,7 @@ import { CodeEditor, CodeEditorControl } from '@patternfly/react-code-editor';
3
3
  import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
4
4
 
5
5
  export const CodeEditorCustomControl: React.FunctionComponent = () => {
6
- const [code, setCode] = React.useState('');
6
+ const [code, setCode] = React.useState('Some example content');
7
7
 
8
8
  const onChange = (code) => {
9
9
  setCode(code);
@@ -32,6 +32,7 @@ export const CodeEditorCustomControl: React.FunctionComponent = () => {
32
32
  customControls={customControl}
33
33
  code={code}
34
34
  onChange={onChange}
35
+ isHeaderPlain={code === ''}
35
36
  />
36
37
  );
37
38
  };
@@ -1,34 +1,49 @@
1
1
  import React from 'react';
2
2
  import { CodeEditor, Language } from '@patternfly/react-code-editor';
3
- import { Grid, GridItem, Chip } from '@patternfly/react-core';
3
+ import { Grid, GridItem, Label, Radio } from '@patternfly/react-core';
4
4
 
5
5
  export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
6
+ type ShortcutMode = 'PC' | 'Mac';
7
+
8
+ const [currentShortcutMode, setCurrentShortcutMode] = React.useState<ShortcutMode>('PC');
9
+
6
10
  const onEditorDidMount = (editor, monaco) => {
7
11
  editor.layout();
8
12
  editor.focus();
9
13
  monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });
10
14
  };
11
15
 
12
- const onChange = (value) => {
16
+ const onChange = (value: string) => {
13
17
  // eslint-disable-next-line no-console
14
18
  console.log(value);
15
19
  };
16
20
 
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
+
17
28
  const shortcuts = [
18
29
  {
19
- keys: ['Opt', 'F1'],
30
+ PC: ['Alt', 'F1'],
31
+ Mac: ['Opt', 'F1'],
20
32
  description: 'Accessibility helps'
21
33
  },
22
34
  {
23
- keys: ['F1'],
35
+ PC: ['F1'],
36
+ Mac: ['F1'],
24
37
  description: 'View all editor shortcuts'
25
38
  },
26
39
  {
27
- keys: ['Ctrl', 'Space'],
40
+ PC: ['Ctrl', 'Space'],
41
+ Mac: ['Opt', 'Esc'],
28
42
  description: 'Activate auto complete'
29
43
  },
30
44
  {
31
- keys: ['Cmd', 'S'],
45
+ PC: ['Ctrl', 'S'],
46
+ Mac: ['Cmd', 'S'],
32
47
  description: 'Save'
33
48
  }
34
49
  ];
@@ -38,11 +53,11 @@ export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
38
53
  {shortcuts.map((shortcut, index) => (
39
54
  <React.Fragment key={index}>
40
55
  <GridItem style={{ textAlign: 'right', marginRight: '1em' }}>
41
- {shortcut.keys
56
+ {shortcut[currentShortcutMode]
42
57
  .map((key) => (
43
- <Chip key={key} isReadOnly>
58
+ <Label variant="outline" key={key}>
44
59
  {key}
45
- </Chip>
60
+ </Label>
46
61
  ))
47
62
  .reduce((prev, curr) => (
48
63
  <>{[prev, ' + ', curr]}</>
@@ -57,14 +72,32 @@ export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
57
72
  };
58
73
 
59
74
  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
+ </>
69
102
  );
70
103
  };