Skip to content

Commit 56abcb8

Browse files
committed
create TextEditor component
1 parent 7b7795a commit 56abcb8

File tree

6 files changed

+68
-1
lines changed

6 files changed

+68
-1
lines changed

lib/components/TextEditor/index.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"use strict";
2+
var __extends = (this && this.__extends) || function (d, b) {
3+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4+
function __() { this.constructor = d; }
5+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6+
};
7+
var React = require('react');
8+
var styles = {
9+
editor: {
10+
textAlign: 'left',
11+
border: '2px solid red',
12+
margin: '5px',
13+
borderRadius: '3px',
14+
},
15+
};
16+
var TextEditor = (function (_super) {
17+
__extends(TextEditor, _super);
18+
function TextEditor() {
19+
_super.apply(this, arguments);
20+
}
21+
TextEditor.prototype.componentDidMount = function () {
22+
var ed = atom.workspace.buildTextEditor();
23+
ed.setGrammar(atom.grammars.grammarForScopeName('source.js'));
24+
console.log(ed);
25+
ed.setText('var a = 42;');
26+
document.querySelector("#" + this.props.name).appendChild(ed.getElement());
27+
};
28+
TextEditor.prototype.render = function () {
29+
return React.createElement("div", {id: this.props.name, style: styles.editor});
30+
};
31+
return TextEditor;
32+
}(React.Component));
33+
Object.defineProperty(exports, "__esModule", { value: true });
34+
exports.default = TextEditor;

lib/components/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var Start_1 = require('./Start');
1616
exports.Start = Start_1.default;
1717
var Tutorials_1 = require('./Tutorials');
1818
exports.Tutorials = Tutorials_1.default;
19+
var TextEditor_1 = require('./TextEditor');
20+
exports.TextEditor = TextEditor_1.default;
1921
var RouteButton_1 = require('./common/RouteButton');
2022
exports.RouteButton = RouteButton_1.default;
2123
var ContentCard_1 = require('./common/ContentCard');

src/components/Start/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default class Start extends React.Component<{
1818
}, {}> {
1919
render() {
2020
const {ready} = this.props;
21+
2122
return (
2223
<section className='cr-start'>
2324
<div style={headerStyles}>

src/components/TextEditor/index.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react';
2+
3+
const styles = {
4+
editor: {
5+
textAlign: 'left',
6+
border: '2px solid red',
7+
margin: '5px',
8+
borderRadius: '3px',
9+
},
10+
};
11+
12+
export default class TextEditor extends React.Component<{
13+
name: string
14+
}, {}> {
15+
componentDidMount() {
16+
const ed = atom.workspace.buildTextEditor();
17+
ed.setGrammar(
18+
atom.grammars.grammarForScopeName('source.js')
19+
);
20+
console.log(ed);
21+
// ed.style.textAlign = 'left';
22+
ed.setText('var a = 42;');
23+
document.querySelector(`#${this.props.name}`).appendChild(ed.getElement());
24+
}
25+
render() {
26+
return <div id={this.props.name} style={styles.editor} />;
27+
}
28+
}

src/components/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export {
2-
Alert, Markdown
2+
Alert, Markdown
33
} from 'core-coderoad';
44

55
export {default as AppMenu} from './AppMenu';
@@ -9,6 +9,7 @@ export {default as Progress} from './Progress';
99
export {default as Routes} from './Routes';
1010
export {default as Start} from './Start';
1111
export {default as Tutorials} from './Tutorials';
12+
export {default as TextEditor} from './TextEditor';
1213

1314
export {default as RouteButton} from './common/RouteButton';
1415
export {default as ContentCard} from './common/ContentCard';

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"src/components/Start/Checks/VerifyButton.tsx",
121121
"src/components/Start/index.tsx",
122122
"src/components/Start/Welcome/index.tsx",
123+
"src/components/TextEditor/index.tsx",
123124
"src/components/Tutorials/index.tsx",
124125
"src/components/Tutorials/LoadTutorials/index.tsx",
125126
"src/components/Tutorials/SelectTutorial/index.tsx",

0 commit comments

Comments
 (0)