Skip to content

Commit 00c02dc

Browse files
committed
feat(code-editor): add support for line wrapping when passing prop
1 parent 8f08fa1 commit 00c02dc

File tree

4 files changed

+60
-38
lines changed

4 files changed

+60
-38
lines changed

etc/lime-elements.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export namespace Components {
309309
"fold": boolean;
310310
"language": Language;
311311
"lineNumbers": boolean;
312+
"lineWrapping": boolean;
312313
"lint": boolean;
313314
"readonly": boolean;
314315
"value": string;
@@ -1471,6 +1472,7 @@ export namespace JSX {
14711472
"fold"?: boolean;
14721473
"language"?: Language;
14731474
"lineNumbers"?: boolean;
1475+
"lineWrapping"?: boolean;
14741476
"lint"?: boolean;
14751477
"onChange"?: (event: LimelCodeEditorCustomEvent<string>) => void;
14761478
"readonly"?: boolean;

src/components/code-editor/code-editor.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import jslint from 'jsonlint-mod';
2727
/**
2828
* @exampleComponent limel-example-code-editor
2929
* @exampleComponent limel-example-code-editor-readonly-with-line-numbers
30-
* @exampleComponent limel-example-code-editor-fold-lint
30+
* @exampleComponent limel-example-code-editor-fold-lint-wrap
3131
*/
3232
@Component({
3333
tag: 'limel-code-editor',
@@ -59,6 +59,12 @@ export class CodeEditor {
5959
@Prop()
6060
public lineNumbers: boolean = false;
6161

62+
/**
63+
* Wraps long lines instead of showing horizontal scrollbar
64+
*/
65+
@Prop()
66+
public lineWrapping: boolean = false;
67+
6268
/**
6369
* Allows the user to fold code
6470
*/
@@ -228,6 +234,7 @@ export class CodeEditor {
228234
tabSize: TAB_SIZE,
229235
indentUnit: TAB_SIZE,
230236
lineNumbers: this.lineNumbers,
237+
lineWrapping: this.lineWrapping,
231238
styleActiveLine: true,
232239
matchBrackets: true,
233240
matchTags: { bothTags: true },

src/components/code-editor/examples/code-editor-with-linting-and-folding.tsx

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Component, h, State } from '@stencil/core';
2+
import { data } from '../../table/examples/birds';
3+
4+
/**
5+
* Editable with JSON linting, folding, and line wrapping
6+
* Here you see an instance of the Code Editor component with linting,
7+
* folding, and line wrapping support. Linting allows the user to see syntax
8+
* errors in the JSON code. Folding makes it easier to collapse larger pieces
9+
* of code. Line wrapping ensures long lines wrap to the next line instead of
10+
* requiring horizontal scrolling, improving readability in constrained spaces.
11+
*/
12+
13+
@Component({
14+
tag: 'limel-example-code-editor-fold-lint-wrap',
15+
shadow: true,
16+
styleUrl: 'code-editor.scss',
17+
})
18+
export class CodeFoldLintAndWrapExample {
19+
@State()
20+
private json: string = JSON.stringify(
21+
[
22+
...data.slice(0, -1),
23+
{
24+
...data.at(-1),
25+
habitat:
26+
'Found in wetlands, marshes, lakes, rivers, and coastal areas across North America, Europe, Asia, Africa, and Australia. They prefer shallow water with abundant vegetation.',
27+
},
28+
],
29+
null,
30+
' '
31+
);
32+
33+
private handleChange = (event: CustomEvent<string>) => {
34+
this.json = event.detail;
35+
};
36+
37+
public render() {
38+
return (
39+
<limel-code-editor
40+
value={this.json}
41+
language="json"
42+
lineNumbers={true}
43+
lint={true}
44+
fold={true}
45+
lineWrapping={true}
46+
onChange={this.handleChange}
47+
/>
48+
);
49+
}
50+
}

0 commit comments

Comments
 (0)