Skip to content

Commit 4c2431c

Browse files
committed
code editor and fix build
1 parent d193708 commit 4c2431c

File tree

13 files changed

+28
-31
lines changed

13 files changed

+28
-31
lines changed

packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { Component, createRef, Fragment } from 'react';
22
import { css } from '@patternfly/react-styles';
33
import styles from '@patternfly/react-styles/css/components/CodeEditor/code-editor';
44
import fileUploadStyles from '@patternfly/react-styles/css/components/FileUpload/file-upload';
@@ -236,11 +236,11 @@ interface CodeEditorState {
236236
copied: boolean;
237237
}
238238

239-
class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
239+
class CodeEditor extends Component<CodeEditorProps, CodeEditorState> {
240240
static displayName = 'CodeEditor';
241241
private editor: editor.IStandaloneCodeEditor | null = null;
242-
private wrapperRef = React.createRef<HTMLDivElement>();
243-
private ref = React.createRef<HTMLDivElement>();
242+
private wrapperRef = createRef<HTMLDivElement>();
243+
private ref = createRef<HTMLDivElement>();
244244
private timer: number | null = null;
245245
private observer = () => {};
246246

@@ -576,7 +576,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
576576
!!shortcutsPopoverProps.bodyContent;
577577

578578
const editorHeaderContent = (
579-
<React.Fragment>
579+
<Fragment>
580580
<div className={css(styles.codeEditorControls)}>
581581
<CodeEditorContext.Provider value={{ code: value }}>
582582
{isCopyEnabled && (!showEmptyState || !!value) && (
@@ -622,7 +622,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
622622
</Popover>
623623
</div>
624624
)}
625-
</React.Fragment>
625+
</Fragment>
626626
);
627627

628628
const editorHeader = (

packages/react-code-editor/src/components/CodeEditor/CodeEditorControl.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { useContext } from 'react';
22
import { Button, ButtonProps } from '@patternfly/react-core/dist/esm/components/Button';
33
import { Tooltip } from '@patternfly/react-core/dist/esm/components/Tooltip';
44
import { CodeEditorContext } from './CodeEditorUtils';
@@ -31,7 +31,7 @@ export const CodeEditorControl: React.FunctionComponent<CodeEditorControlProps>
3131
tooltipProps = {},
3232
...props
3333
}: CodeEditorControlProps) => {
34-
const context = React.useContext(CodeEditorContext);
34+
const context = useContext(CodeEditorContext);
3535

3636
const onCustomClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
3737
onClick(context.code, event);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as React from 'react';
1+
import { createContext } from 'react';
22

33
interface CodeEditorContext {
44
code: string;
55
}
66

7-
export const CodeEditorContext = React.createContext<CodeEditorContext>(null);
7+
export const CodeEditorContext = createContext<CodeEditorContext>(null);

packages/react-code-editor/src/components/CodeEditor/__test__/CodeEditor.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { render, screen, act } from '@testing-library/react';
32
import { CodeEditor, Language } from '../CodeEditor';
43
import styles from '@patternfly/react-styles/css/components/CodeEditor/code-editor';

packages/react-code-editor/src/components/CodeEditor/__test__/CodeEditorControl.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { render, screen } from '@testing-library/react';
32
import { CodeEditorControl } from '../CodeEditorControl';
43

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ propComponents: ['CodeEditor', 'CodeEditorControl', 'Popover']
77

88
Note: Code editor lives in its own package at [@patternfly/react-code-editor](https://www.npmjs.com/package/@patternfly/react-code-editor) and has [**required peer deps**](https://github.com/patternfly/patternfly-react/blob/main/packages/react-code-editor/package.json).
99

10+
import { Fragment, useState } from 'react';
1011
import { CodeEditor, CodeEditorControl, Language } from '@patternfly/react-code-editor';
1112
import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
1213

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorBasic.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React from 'react';
1+
import { useState } from 'react';
22
import { CodeEditor, Language } from '@patternfly/react-code-editor';
33
import { Checkbox } from '@patternfly/react-core';
44

55
export const CodeEditorBasic: React.FunctionComponent = () => {
6-
const [isDarkTheme, setIsDarkTheme] = React.useState(false);
7-
const [isLineNumbersVisible, setIsLineNumbersVisible] = React.useState(true);
8-
const [isReadOnly, setIsReadOnly] = React.useState(false);
9-
const [isMinimapVisible, setIsMinimapVisible] = React.useState(false);
6+
const [isDarkTheme, setIsDarkTheme] = useState(false);
7+
const [isLineNumbersVisible, setIsLineNumbersVisible] = useState(true);
8+
const [isReadOnly, setIsReadOnly] = useState(false);
9+
const [isMinimapVisible, setIsMinimapVisible] = useState(false);
1010

1111
const toggleDarkTheme = (checked) => {
1212
setIsDarkTheme(checked);

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorCustomControl.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
1+
import { useState } from 'react';
22
import { CodeEditor, CodeEditorControl } from '@patternfly/react-code-editor';
33
import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
44

55
export const CodeEditorCustomControl: React.FunctionComponent = () => {
6-
const [code, setCode] = React.useState('Some example content');
6+
const [code, setCode] = useState('Some example content');
77

88
const onChange = (code) => {
99
setCode(code);

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorFullHeight.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { CodeEditor, Language } from '@patternfly/react-code-editor';
32

43
export const CodeEditorFullHeight: React.FunctionComponent = () => {

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorShortcutMainHeader.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React from 'react';
1+
import { Fragment, useState } from 'react';
22
import { CodeEditor, Language } from '@patternfly/react-code-editor';
33
import { Grid, GridItem, Label, Radio } from '@patternfly/react-core';
44

55
export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
66
type ShortcutMode = 'PC' | 'Mac';
77

8-
const [currentShortcutMode, setCurrentShortcutMode] = React.useState<ShortcutMode>('PC');
8+
const [currentShortcutMode, setCurrentShortcutMode] = useState<ShortcutMode>('PC');
99

1010
const onEditorDidMount = (editor, monaco) => {
1111
editor.layout();
@@ -51,7 +51,7 @@ export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
5151
bodyContent: (
5252
<Grid span={6} hasGutter key="grid">
5353
{shortcuts.map((shortcut, index) => (
54-
<React.Fragment key={index}>
54+
<Fragment key={index}>
5555
<GridItem style={{ textAlign: 'right', marginRight: '1em' }}>
5656
{shortcut[currentShortcutMode]
5757
.map((key) => (
@@ -64,7 +64,7 @@ export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
6464
))}
6565
</GridItem>
6666
<GridItem>{shortcut.description}</GridItem>
67-
</React.Fragment>
67+
</Fragment>
6868
))}
6969
</Grid>
7070
),

0 commit comments

Comments
 (0)