CodeEditor
A wrapper to the React Monaco editor with our styles. Please make sure you follow the instructions (found in the repository) to include the component. Additional information regarding Tab trapping in Monaco, can be found here.
Usage
To use the Code Editor component you’ll have to install the @hitachivantara/uikit-react-code-editor
package:
npm install @hitachivantara/uikit-react-code-editor
You can specify a language through the language
prop to get proper syntax highlighting and define a default value:
The component includes only the actual code editor but you might want to have a header with some actions. The following example showcases a code editor with a header that includes the filename and two actions to copy the code or view it in fullscreen mode.
Language plugins
UI Kit’s Code Editor provides plugins for XML and SQL out of the box. You can pass a schema to the schema
prop to enable suggestions and validation.
- XML: By providing a XML schema, the XML written will be validated against the schema showing errors. Providing a schema will also enable the code editor to show suggestions when opening a tag (
<
), writing an attribute, and when clicking on the CTRL and SPACE keys at the same time. By default, the XML code editor is formatted automatically. The propertydisableAutoFormat
can be set totrue
to disable this behavior. You can also format manually the code using thehvXmlFormatter
util. - SQL: Providing a SQL schema will enable the code editor to show suggestions when writing the query, and when clicking on the CTRL and SPACE keys at the same time.
Custom language plugins
You can also create your own language plugins. The following example shows how to create a custom language plugin that extends the Code Editor’s own XML language plugin to show different suggestions and format the code differently.