Gathering detailed insights and metrics for @earlold/react-simple-code-editor
Gathering detailed insights and metrics for @earlold/react-simple-code-editor
Gathering detailed insights and metrics for @earlold/react-simple-code-editor
Gathering detailed insights and metrics for @earlold/react-simple-code-editor
Simple no-frills code editor with syntax highlighting
npm install @earlold/react-simple-code-editor
Typescript
Module System
Node Version
NPM Version
TypeScript (86.97%)
CSS (8.43%)
HTML (4.6%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,692 Stars
134 Commits
171 Forks
10 Watchers
3 Branches
17 Contributors
Updated on Jul 09, 2025
Latest Version
0.12.0
Package Id
@earlold/react-simple-code-editor@0.12.0
Unpacked Size
79.73 kB
Size
21.60 kB
File Count
7
NPM Version
8.5.5
Node Version
16.15.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
20
Simple no-frills code editor with syntax highlighting.
Several browser based code editors such as Ace, CodeMirror, Monaco etc. provide the ability to embed a full-featured code editor in your web page. However, if you just need a simple editor with syntax highlighting without any of the extra features, they can be overkill as they don't usually have a small bundle size footprint. This library aims to provide a simple code editor with syntax highlighting support without any of the extra features, perfect for simple embeds and forms where users can submit code.
Ctrl+Shift+M
(Mac) / Ctrl+M
to toggle capturing tab key1npm install react-simple-code-editor
or
1yarn add react-simple-code-editor
You need to use the editor with a third party library which provides syntax highlighting. For example, it'll look like following with prismjs
:
1import React from "react"; 2import Editor from "react-simple-code-editor"; 3import { highlight, languages } from "prismjs/components/prism-core"; 4import "prismjs/components/prism-clike"; 5import "prismjs/components/prism-javascript"; 6import "prismjs/themes/prism.css"; //Example style, you can use another 7 8function App() { 9 const [code, setCode] = React.useState( 10 `function add(a, b) {\n return a + b;\n}` 11 ); 12 return ( 13 <Editor 14 value={code} 15 onValueChange={(code) => setCode(code)} 16 highlight={(code) => highlight(code, languages.js)} 17 padding={10} 18 style={{ 19 fontFamily: '"Fira code", "Fira Mono", monospace', 20 fontSize: 12, 21 }} 22 /> 23 ); 24}
Note that depending on your syntax highlighter, you might have to include additional CSS for syntax highlighting to work.
The editor accepts all the props accepted by textarea
. In addition, you can pass the following props:
value
(string
): Current value of the editor i.e. the code to display. This must be a controlled prop.onValueChange
(string => mixed
): Callback which is called when the value of the editor changes. You'll need to update the value prop when this is called.highlight
(string => string | React.Node
): Callback which will receive text to highlight. You'll need to return an HTML string or a React element with syntax highlighting using a library such as prismjs
.tabSize
(number
): The number of characters to insert when pressing tab key. For example, for 4 space indentation, tabSize
will be 4
and insertSpaces
will be true
. Default: 2
.insertSpaces
(boolean
): Whether to use spaces for indentation. Default: true
. If you set it to false
, you might also want to set tabSize
to 1
.ignoreTabKey
(boolean
): Whether the editor should ignore tab key presses so that keyboard users can tab past the editor. Users can toggle this behaviour using Ctrl+Shift+M
(Mac) / Ctrl+M
manually when this is false
. Default: false
.padding
(number
): Optional padding for code. Default: 0
.textareaId
(string
): An ID for the underlying textarea
, can be useful for setting a label
.textareaClassName
(string
): A className for the underlying textarea
, can be useful for more precise control of its styles.preClassName
(string
): A className for the underlying pre
, can be useful for more precise control of its styles.satya164.github.io/react-simple-code-editor
It works by overlaying a syntax highlighted <pre>
block over a <textarea>
. When you type, select, copy text etc., you interact with the underlying <textarea>
, so the experience feels native. This is a very simple approach compared to other editors which re-implement the behaviour.
The syntax highlighting can be done by any third party library as long as it returns HTML and is fully controllable by the user.
The vanilla <textarea>
doesn't support inserting tab characters for indentation, so we re-implement it by listening to keydown
events and programmatically updating the text. One caveat with programmatically updating the text is that we lose the undo stack, so we need to maintain our own undo stack. As a result, we can also implement improved undo behaviour such as undoing whole words similar to editors like VSCode.
Due to the way it works, it has certain limitations:
<textarea>
, changing anything that affects the layout can misalign it.-webkit-text-fill-color: transparent
, which works in all modern browsers (even non-webkit ones such as Firefox and Edge). On IE 10+, we use color: transparent
which doesn't hide the cursor. Text may appear bolder in unsupported browsers.While developing, you can run the example app to test your changes:
1yarn example
Make sure your code passes Flow and ESLint. Run the following to verify:
1yarn flow 2yarn lint
To fix formatting errors, run the following:
1yarn lint -- --fix
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
16 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More