Skip to content

Commit

Permalink
Add an option to disable line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Apr 30, 2024
1 parent 71cec83 commit 11f1361
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/jsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface JSONEditorProps {
value?: any;
onChange: (value: any) => void;
readOnly?: boolean;
showLines?: boolean;
}

type AvailableEditorProps = Pick<EditorProps, 'height'>;
Expand All @@ -17,6 +18,7 @@ const JSONEditor: React.FC<JSONEditorProps & AvailableEditorProps> = ({
value = '',
onChange,
readOnly = false,
showLines = true,
...props
}) => {
const monacoOnChange: OnChange = value => {
Expand All @@ -43,14 +45,17 @@ const JSONEditor: React.FC<JSONEditorProps & AvailableEditorProps> = ({

const jsonData = JSON.stringify(value, null, 2);

const extraOptions: EditorProps['options'] = {readOnly};
if (!showLines) extraOptions.lineNumbers = 'off';

return (
<Editor
language="json"
options={{
minimap: {enabled: false},
contextmenu: false,
renderWhitespace: 'trailing',
readOnly,
...extraOptions,
}}
value={jsonData}
onChange={monacoOnChange}
Expand Down

0 comments on commit 11f1361

Please sign in to comment.