Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monaco editor - New Control #1134

Merged
merged 11 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/documentation/docs/assets/MonacoEditor1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/documentation/docs/assets/MonacoEditor2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions docs/documentation/docs/controls/MonacoEditor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Monaco Editor control

This control is a implementatiopn of Monaco Editor.

Here is an example of the control:

![monacoeditor](../assets/MonacoEditor1.png)

`MonacoEditor` dark theme:

![monacoeditor](../assets/MonacoEditor2.png)


## How to use this control in your solutions

- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../../#getting-started) page for more information about installing the dependency.
- Import the control into your component:

```TypeScript
import { MonacoEditor } from "@pnp/spfx-controls-react/lib/MonacoEditor";
```

- Use the `MonacoEditor` control in your code as follows:

```TypeScript
<MonacoEditor value={defaultValue}
showMiniMap={true}
onValueChange={onValueChange}
language={"javascript"}/>
```

- The `onValueChange` change event returns the upadated code and array with messages of errors on validation and can be implemented as follows:
**this validation is done only to JSON language

```TypeScript
const onValueChange = React.useCallback((newValue: string, validationErrors: string[]): void => {console.log(newValue);} , []);
```

## Implementation

The `MonacoEditor` control can be configured with the following properties:

| Property | Type | Required | Description |
| ---- | ---- | ---- | ---- |
| value | string | yes | default content for editor |
| theme | string | no | theme used by editor , two themes are supported 'vs' and 'vs-dark', default 'vs' |
| readOnly | boolean | no | indecate if editor is in read only mode |
| showLineNumbers | boolean | no | editor show linenumber or not, default : yes|
| onValueChange |(newValue:string, validationErrors:string[]) => void | no | function to get code changes, return an array with validation error in case of language is 'JSON' |
| language |string | yes | editor code language, please see https://microsoft.github.io/monaco-editor/index.html for supported languages|
| jsonDiagnosticsOptions |monaco.languages.json.DiagnosticsOptions | no | define options to JSON validation, please see https://microsoft.github.io/monaco-editor/index.html for more details |
| jscriptDiagnosticsOptions | monaco.languages.typescript.DiagnosticsOptions | no | define options to javascript or typescript validation, please see https://microsoft.github.io/monaco-editor/index.html for more details |


Loading