Skip to content

Commit 57e3b54

Browse files
gaearonbvaughn
authored andcommitted
Make homepage examples more approachable (#10872)
1 parent 14d0ef4 commit 57e3b54

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

www/src/components/CodeEditor/CodeEditor.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class CodeEditor extends Component {
9898
}}>
9999
<div
100100
css={{
101-
flex: '0 0 50%',
101+
flex: '0 0 70%',
102102
overflow: 'hidden',
103103
borderRadius: '10px 0 0 10px',
104104

@@ -137,7 +137,7 @@ class CodeEditor extends Component {
137137
{error &&
138138
<div
139139
css={{
140-
flex: '0 0 50%',
140+
flex: '0 0 70%',
141141
overflow: 'hidden',
142142
border: `1px solid ${colors.error}`,
143143
borderRadius: '0 10px 10px 0',
@@ -167,7 +167,7 @@ class CodeEditor extends Component {
167167
{!error &&
168168
<div
169169
css={{
170-
flex: '0 0 50%',
170+
flex: '0 0 30%',
171171
overflow: 'hidden',
172172
border: `1px solid ${colors.divider}`,
173173
borderRadius: '0 10px 10px 0',

www/src/css/reset.css

+4
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ img {
3333
display: inline-block;
3434
vertical-align: top;
3535
}
36+
37+
pre {
38+
font-family: source-code-pro, Menlo, Consolas, "Courier New", monospace;
39+
}

www/src/templates/home.js

+28-13
Original file line numberDiff line numberDiff line change
@@ -317,26 +317,34 @@ const markdownStyles = {
317317

318318
// TODO Move these hard-coded examples into example files and out of the template?
319319
// Alternately, move them into the markdown and transform them during build?
320+
const name = Math.random() > .5 ? 'John' : 'Jane';
320321
const HELLO_COMPONENT = `
321322
class HelloMessage extends React.Component {
322323
render() {
323-
return <div>Hello {this.props.name}</div>;
324+
return (
325+
<div>
326+
Hello {this.props.name}
327+
</div>
328+
);
324329
}
325330
}
326331
327-
ReactDOM.render(<HelloMessage name="Devin" />, mountNode);
332+
ReactDOM.render(
333+
<HelloMessage name="${name}" />,
334+
mountNode
335+
);
328336
`.trim();
329337

330338
const TIMER_COMPONENT = `
331339
class Timer extends React.Component {
332340
constructor(props) {
333341
super(props);
334-
this.state = {secondsElapsed: 0};
342+
this.state = { seconds: 0 };
335343
}
336344
337345
tick() {
338346
this.setState((prevState) => ({
339-
secondsElapsed: prevState.secondsElapsed + 1
347+
seconds: prevState.seconds + 1
340348
}));
341349
}
342350
@@ -350,7 +358,9 @@ class Timer extends React.Component {
350358
351359
render() {
352360
return (
353-
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
361+
<div>
362+
Seconds: {this.state.seconds}
363+
</div>
354364
);
355365
}
356366
}
@@ -362,9 +372,9 @@ var TODO_COMPONENT = `
362372
class TodoApp extends React.Component {
363373
constructor(props) {
364374
super(props);
375+
this.state = { items: [], text: '' };
365376
this.handleChange = this.handleChange.bind(this);
366377
this.handleSubmit = this.handleSubmit.bind(this);
367-
this.state = {items: [], text: ''};
368378
}
369379
370380
render() {
@@ -373,20 +383,25 @@ class TodoApp extends React.Component {
373383
<h3>TODO</h3>
374384
<TodoList items={this.state.items} />
375385
<form onSubmit={this.handleSubmit}>
376-
<input onChange={this.handleChange} value={this.state.text} />
377-
<button>{'Add #' + (this.state.items.length + 1)}</button>
386+
<input
387+
onChange={this.handleChange}
388+
value={this.state.text}
389+
/>
390+
<button>
391+
Add #{this.state.items.length + 1}
392+
</button>
378393
</form>
379394
</div>
380395
);
381396
}
382397
383398
handleChange(e) {
384-
this.setState({text: e.target.value});
399+
this.setState({ text: e.target.value });
385400
}
386401
387402
handleSubmit(e) {
388403
e.preventDefault();
389-
var newItem = {
404+
const newItem = {
390405
text: this.state.text,
391406
id: Date.now()
392407
};
@@ -417,15 +432,15 @@ class MarkdownEditor extends React.Component {
417432
constructor(props) {
418433
super(props);
419434
this.handleChange = this.handleChange.bind(this);
420-
this.state = {value: 'Type some *markdown* here!'};
435+
this.state = { value: 'Type some *markdown* here!' };
421436
}
422437
423438
handleChange(e) {
424-
this.setState({value: e.target.value});
439+
this.setState({ value: e.target.value });
425440
}
426441
427442
getRawMarkup() {
428-
var md = new Remarkable();
443+
const md = new Remarkable();
429444
return { __html: md.render(this.state.value) };
430445
}
431446

0 commit comments

Comments
 (0)