Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederickPu committed Feb 4, 2023
0 parents commit 14cf9d5
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
36 changes: 36 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';

// formating styles (makes sure text stays inside editor box)
import 'codemirror/lib/codemirror.css';

// aesthetic styles
import 'codemirror/theme/material.css'; // syntax highlighting
import 'codemirror/mode/xml/xml'; // theme styles

import { Controlled as ControlledEditor } from 'react-codemirror2';

import './style.css';

export default function App() {
const [value, setValue] = React.useState('bruh');
return (
<div>
<h1>Hello StackBlitz!</h1>
<p>Start editing to see some magic happen :)</p>
<ControlledEditor
onBeforeChange={(editor, data, value) => {
setValue(value);
}}
value={value}
className="code-mirror-wrapper"
options={{
lineWrapping: true,
lint: true,
mode: 'xml',
theme: 'material',
lineNumbers: true,
}}
/>
</div>
);
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# react-codemirror-demos

[Edit on StackBlitz ⚡️](https://stackblitz.com/edit/react-ts-4hgcxn)
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="root"></div>
17 changes: 17 additions & 0 deletions index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

import App from './App';

const rootElement = document.getElementById('root');
const root = createRoot(rootElement);

root.render(
// removed strickmode to fix doubled editor bug
// see source for more details:
// https://stackoverflow.com/questions/72464452/codemirror-editor-duplicating
// <StrictMode>
<App />
// </StrictMode>
);
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "react-ts",
"version": "0.0.0",
"private": true,
"dependencies": {
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"codemirror": "5.x",
"react": "^18.2.0",
"react-codemirror2": "^7.2.1",
"react-dom": "^18.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"react-scripts": "latest"
}
}
3 changes: 3 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1, p {
font-family: Lato;
}

0 comments on commit 14cf9d5

Please sign in to comment.