15 changed files with 264 additions and 14 deletions
@ -0,0 +1,18 @@ |
|||||
|
function Welcome(props) { |
||||
|
return <h1>Hello, {props.name}</h1>; |
||||
|
} |
||||
|
|
||||
|
function App() { |
||||
|
return ( |
||||
|
<div> |
||||
|
<Welcome name="Sara" /> |
||||
|
<Welcome name="Cahal" /> |
||||
|
<Welcome name="Edite" /> |
||||
|
</div> |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
ReactDOM.render( |
||||
|
<App />, |
||||
|
document.getElementById('root') |
||||
|
); |
@ -0,0 +1,52 @@ |
|||||
|
function formatDate(date) { |
||||
|
return date.toLocaleDateString(); |
||||
|
} |
||||
|
|
||||
|
function Avatar(props) { |
||||
|
return ( |
||||
|
<img className="Avatar" |
||||
|
src={props.user.avatarUrl} |
||||
|
alt={props.user.name} /> |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
function UserInfo(props) { |
||||
|
return ( |
||||
|
<div className="UserInfo"> |
||||
|
<Avatar user={props.user} /> |
||||
|
<div className="UserInfo-name"> |
||||
|
{props.user.name} |
||||
|
</div> |
||||
|
</div> |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
function Comment(props) { |
||||
|
return ( |
||||
|
<div className="Comment"> |
||||
|
<UserInfo user={props.author} /> |
||||
|
<div className="Comment-text"> |
||||
|
{props.text} |
||||
|
</div> |
||||
|
<div className="Comment-date"> |
||||
|
{formatDate(props.date)} |
||||
|
</div> |
||||
|
</div> |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
const comment = { |
||||
|
date: new Date(), |
||||
|
text: 'I hope you enjoy learning React!', |
||||
|
author: { |
||||
|
name: 'Hello Kitty', |
||||
|
avatarUrl: 'http://placekitten.com/g/64/64' |
||||
|
} |
||||
|
}; |
||||
|
ReactDOM.render( |
||||
|
<Comment |
||||
|
date={comment.date} |
||||
|
text={comment.text} |
||||
|
author={comment.author} />, |
||||
|
document.getElementById('root') |
||||
|
); |
@ -0,0 +1,40 @@ |
|||||
|
function formatDate(date) { |
||||
|
return date.toLocaleDateString(); |
||||
|
} |
||||
|
|
||||
|
function Comment(props) { |
||||
|
return ( |
||||
|
<div className="Comment"> |
||||
|
<div className="UserInfo"> |
||||
|
<img className="Avatar" |
||||
|
src={props.author.avatarUrl} |
||||
|
alt={props.author.name} /> |
||||
|
<div className="UserInfo-name"> |
||||
|
{props.author.name} |
||||
|
</div> |
||||
|
</div> |
||||
|
<div className="Comment-text"> |
||||
|
{props.text} |
||||
|
</div> |
||||
|
<div className="Comment-date"> |
||||
|
{formatDate(props.date)} |
||||
|
</div> |
||||
|
</div> |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
const comment = { |
||||
|
date: new Date(), |
||||
|
text: 'I hope you enjoy learning React!', |
||||
|
author: { |
||||
|
name: 'Hello Kitty', |
||||
|
avatarUrl: 'http://placekitten.com/g/64/64' |
||||
|
} |
||||
|
}; |
||||
|
ReactDOM.render( |
||||
|
<Comment |
||||
|
date={comment.date} |
||||
|
text={comment.text} |
||||
|
author={comment.author} />, |
||||
|
document.getElementById('root') |
||||
|
); |
@ -0,0 +1,9 @@ |
|||||
|
function Welcome(props) { |
||||
|
return <h1>Hello, {props.name}</h1>; |
||||
|
} |
||||
|
|
||||
|
const element = <Welcome name="Sara" />; |
||||
|
ReactDOM.render( |
||||
|
element, |
||||
|
document.getElementById('root') |
||||
|
); |
@ -0,0 +1,4 @@ |
|||||
|
ReactDOM.render( |
||||
|
<h1>Hello, world!</h1>, |
||||
|
document.getElementById('root') |
||||
|
); |
@ -0,0 +1,19 @@ |
|||||
|
function formatName(user) { |
||||
|
return user.firstName + ' ' + user.lastName; |
||||
|
} |
||||
|
|
||||
|
const user = { |
||||
|
firstName: 'Harper', |
||||
|
lastName: 'Perez', |
||||
|
}; |
||||
|
|
||||
|
const element = ( |
||||
|
<h1> |
||||
|
Hello, {formatName(user)}! |
||||
|
</h1> |
||||
|
); |
||||
|
|
||||
|
ReactDOM.render( |
||||
|
element, |
||||
|
document.getElementById('root') |
||||
|
); |
@ -0,0 +1,73 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
import React, {Component} from 'react'; |
||||
|
import Container from 'components/Container'; |
||||
|
import {colors} from 'theme'; |
||||
|
|
||||
|
const EXTERNALS = [ |
||||
|
'https://unpkg.com/react/umd/react.development.js', |
||||
|
'https://unpkg.com/react-dom/umd/react-dom.development.js', |
||||
|
]; |
||||
|
|
||||
|
// Copied over styles from ButtonLink for the submit btn
|
||||
|
const primaryStyle = { |
||||
|
backgroundColor: colors.brand, |
||||
|
color: colors.black, |
||||
|
padding: '10px 25px', |
||||
|
whiteSpace: 'nowrap', |
||||
|
transition: 'background-color 0.2s ease-out', |
||||
|
outline: 0, |
||||
|
border: 'none', |
||||
|
cursor: 'pointer', |
||||
|
|
||||
|
':hover': { |
||||
|
backgroundColor: colors.white, |
||||
|
}, |
||||
|
|
||||
|
display: 'inline-block', |
||||
|
fontSize: 16, |
||||
|
}; |
||||
|
|
||||
|
class CodepenExample extends Component { |
||||
|
componentDidMount() { |
||||
|
this.codepenForm.submit(); |
||||
|
} |
||||
|
|
||||
|
render() { |
||||
|
// Codepen configuration.
|
||||
|
// https://blog.codepen.io/documentation/api/prefill/
|
||||
|
const payload = JSON.stringify({ |
||||
|
editors: '0010', |
||||
|
html: '<div id="root"></div>', |
||||
|
js: this.props.pathContext.code, |
||||
|
js_external: EXTERNALS.join(';'), |
||||
|
js_pre_processor: 'babel', |
||||
|
layout: 'left', |
||||
|
title: 'reactjs.org example', |
||||
|
}); |
||||
|
|
||||
|
return ( |
||||
|
<Container> |
||||
|
<h1>Redirecting to Codepen...</h1> |
||||
|
<form |
||||
|
style={{paddingBottom: '50px'}} |
||||
|
ref={form => { |
||||
|
this.codepenForm = form; |
||||
|
}} |
||||
|
action="https://codepen.io/pen/define" |
||||
|
method="POST"> |
||||
|
<input type="hidden" name="data" value={payload} /> |
||||
|
|
||||
|
<p> |
||||
|
Not automatically redirecting? |
||||
|
<br /> |
||||
|
<br /> |
||||
|
<input style={primaryStyle} type="submit" value="Click here" /> |
||||
|
</p> |
||||
|
</form> |
||||
|
</Container> |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default CodepenExample; |
Loading…
Reference in new issue