NexusPanel
A versatile code editor panel that provides syntax highlighting, formatting, and editing capabilities for various programming languages.
Basic Usage
<NexusPanel
type="html"
content="<h1>Hello World</h1><p>This is a code panel</p>"
/>
Properties
General
Property | Description | Type | Default |
---|---|---|---|
content | Code content to display | string | Empty string |
type | Language for syntax highlighting | 'html' | 'css' | 'js' | js |
readonly | Set editor to read-only mode | boolean | false |
Appearance
Property | Description | Type | Default |
---|---|---|---|
theme | Editor theme configuration | { dark: boolean } | Dark theme |
lineNumbers | Show line numbers | boolean | true |
showHeader | Show the panel header | boolean | true |
panelName | Custom label for the panel header | string | Based on language |
Formatting
Property | Description | Type | Default |
---|---|---|---|
enableFormatting | Enables code formatting functionality | boolean | false |
formattingOptions | Options for code formatting | object | {} |
showFormattingButton | Show formatting button in the UI | boolean | true |
Events
contentChange
Event emitted when the editor content changes
{ content: string }
Example:
<NexusPanel
type="js"
content="console.log('Hello');"
onContentChange={(event) => {
console.log('Content changed:', event.detail.content);
}}
/>
Methods
formatCode()
Format the code in the panel
Returns:
Promise<void>
Example:
// Get a reference to the component
const panel = document.querySelector('nexus-panel');
// Format the code
panel.formatCode().then(() => {
console.log('Code formatted successfully');
});
getContent()
Get the current content from the editor
Returns:
string
Example:
// Get a reference to the component
const panel = document.querySelector('nexus-panel');
// Get the content
const content = panel.getContent();
console.log('Current content:', content);
Advanced Examples
Multiple Languages
Use NexusPanel with different language settings:
// HTML Panel
<NexusPanel
type="html"
content="<h1>Hello World</h1>"
/>
// CSS Panel
<NexusPanel
type="css"
content="h1 { color: blue; font-size: 2em; }"
/>
// JavaScript Panel
<NexusPanel
type="js"
content="console.log('Hello from Nexus Panel');"
/>
Using Slots
You can provide code content using slots instead of the content property:
<NexusPanel type="css">
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
h1 {
color: blue;
}
</NexusPanel>
Code Formatting
Enable code formatting with custom options:
<NexusPanel
type="js"
content="function example() { const x = 1; const y = 2; return x + y; }"
enableFormatting={true}
formattingOptions={{ printWidth: 80, tabWidth: 2, singleQuote: true }}
/>
React Integration
Use the React wrapper for easier integration in React applications:
import { NexusPanel } from "code-nexus-react";
function CodeEditor() {
const [code, setCode] = useState("<h1>Hello World</h1>");
const handleContentChange = (event) => {
setCode(event.detail.content);
};
return (
<NexusPanel
type="html"
content={code}
onContentChange={handleContentChange}
/>
);
}
Live Examples
Basic Panel (Read-only)
A simple HTML code panel:
JavaScript Example (Read-only)
JavaScript panel with syntax highlighting:
CSS Styling (Read-only)
CSS code with formatting:
Editable Panel (Try editing the code!)
This panel is editable - try modifying the code below:
Editable Example