Skip to content

Commit a4483fa

Browse files
feat(mantine, code-editor): support custom tabSize (#4014)
1 parent 26d6336 commit a4483fa

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ interface CodeEditorProps
7272
* @default 'local'
7373
*/
7474
monacoLoader?: 'cdn' | 'local';
75+
/**
76+
* Options to pass to the monaco editor.
77+
* Currently only supporting [`tabSize`](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html#tabSize).
78+
*
79+
*/
80+
options?: Pick<monacoEditor.IStandaloneEditorConstructionOptions, 'tabSize'>;
7581
}
7682

7783
const defaultProps: Partial<CodeEditorProps> = {
@@ -101,6 +107,7 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
101107
maxHeight,
102108
disabled,
103109
monacoLoader,
110+
options: {tabSize} = {tabSize: 2},
104111
...others
105112
} = useProps('CodeEditor', defaultProps, props);
106113
const [loaded, setLoaded] = useState(false);
@@ -230,7 +237,7 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
230237
formatOnPaste: true,
231238
fontSize: px(theme.fontSizes.xs) as number,
232239
readOnly: disabled,
233-
tabSize: 2,
240+
tabSize,
234241
}}
235242
value={_value}
236243
onChange={handleChange}

packages/website/src/examples/form/code-editor/CodeEditorPython.demo.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ import {CodeEditor, useForm} from '@coveord/plasma-mantine';
33
const Demo = () => {
44
const form = useForm({
55
initialValues: {
6-
code: 'def my_extension():\n\tprint("Not implemented yet.")\n\nmy_extension()',
6+
code: 'def my_extension():\n print("Not implemented yet.")\n\nmy_extension()',
77
},
88
});
99

1010
return (
1111
<CodeEditor
1212
language="python"
1313
label="Extension"
14-
description="Define an extension using Python"
14+
description="Define an extension using Python and a custom tab size."
1515
monacoLoader="cdn"
16+
options={{tabSize: 4}}
1617
{...form.getInputProps('code')}
1718
/>
1819
);

0 commit comments

Comments
 (0)