Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
580 changes: 535 additions & 45 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<!--

<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Expand All @@ -22,12 +20,13 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
<title>React App</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

Expand All @@ -37,5 +36,6 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
</body>

</html>
75 changes: 73 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,85 @@
import React, { Component } from 'react';
import IdCard from "./components/IdCard";
import Greetings from "./components/Greeting";
import Random from './components/Random';
import BoxColor from "./components/BoxColor";
import Rating from "./components/Rating";
import DriverCard from "./components/DriverCard";
import LikeButton from "./components/LikeButton";
import ClickablePicture from "./components/ClickablePicture";
import Dice from "./components/Dice";


class App extends Component {
render() {
return (
<div className="App">
<h1>IdCard</h1>
{/* TODO: Use the IdCard component */}
<IdCard
lastName='Doe'
firstName='John'
gender='male'
height={178}
birth="1992-07-14"
picture="https://randomuser.me/api/portraits/men/44.jpg"
/>

<IdCard
lastName='Delores '
firstName='Obrien'
gender='female'
height={172}
birth="1988-05-11"
picture="https://randomuser.me/api/portraits/women/44.jpg"
/>

<h1>Greetings</h1>
{/* TODO: Use the Greetings component */}

<Greetings lang="de">Ludwig</Greetings>
<Greetings lang="fr">François</Greetings>

<h1>Random</h1>

<Random min={1} max={6} />
<Random min={1} max={100} />

<h1>BoxColor</h1>

<BoxColor r={255} g={0} b={0} />
<BoxColor r={128} g={255} b={0} />

<h1>Rating</h1>
<Rating>0</Rating>
<Rating>1.49</Rating>
<Rating>1.5</Rating>
<Rating>3</Rating>
<Rating>4</Rating>
<Rating>5</Rating>

<h1>Driver Card</h1>

<DriverCard
name="Travis Kalanick"
rating={4.2}
img="https://si.wsj.net/public/resources/images/BN-TY647_37gql_OR_20170621052140.jpg?width=620&height=428"
car={{
model: "Toyota Corolla Altis",
licensePlate: "CO42DE"
}} />
<DriverCard
name="Dara Khosrowshahi"
rating={4.9}
img="https://ubernewsroomapi.10upcdn.com/wp-content/uploads/2017/09/Dara_ELT_Newsroom_1000px.jpg"
car={{
model: "Audi A3",
licensePlate: "BE33ER"
}} />
<LikeButton /> <LikeButton />

<ClickablePicture img="/img/persons/maxence.png" imgClicked="/img/persons/maxence-glasses.png" />

<Dice />

</div>
);
}
Expand Down
26 changes: 26 additions & 0 deletions src/components/BoxColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { Component } from 'react'

export default class BoxColor extends Component {

toHexadecimal(number) {
const hex = number.toString(16)
if (hex.toString().length < 2) {
return `${hex}${hex}`
}
return `${hex}`
}

bgcolor = {
backgroundColor: `rgb(${this.props.r}, ${this.props.g}, ${this.props.b})`
}

render() {

return (
<div style={this.bgcolor}>
<h2>rgb({this.props.r},{this.props.g},{this.props.b})</h2>
<h2>#{this.toHexadecimal(this.props.r)}{this.toHexadecimal(this.props.g)}{this.toHexadecimal(this.props.b)}</h2>
</div>
)
}
}
27 changes: 27 additions & 0 deletions src/components/ClickablePicture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { Component } from 'react'

export default class ClickablePicture extends Component {

state = {
showGlasses: false
}

toggleShowGlasses() {
this.setState({
showGlasses: !this.state.showGlasses
})
}

render() {
return (
<div>
{
this.state.showGlasses ?
<img onClick={() => this.toggleShowGlasses()} src={this.props.imgClicked} alt="" />
:
<img onClick={() => this.toggleShowGlasses()} src={this.props.img} alt="" />
}
</div>
)
}
}
25 changes: 25 additions & 0 deletions src/components/Dice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { Component } from 'react'

export default class Dice extends Component {

state = {
diceNum: `/img/dice${Math.floor(Math.random() * 6)}.png`
}

RollDice() {
setTimeout(() => {

this.setState({
diceNum: `/img/dice${Math.floor(Math.random() * 5 + 1)}.png`
})
}, 1000)
}

render() {
return (
<div>
<img height="100" onClick={() => this.RollDice()} src={this.state.diceNum} />
</div>
)
}
}
24 changes: 24 additions & 0 deletions src/components/DriverCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { Component } from 'react'
import Rating from "./Rating"

export default class DriverCard extends Component {

flex = {
display: "flex",
alignItems: "center",
backgroundColor: "lightblue"
}

render() {
return (
<div style={this.flex}>
<img width="100" height="100" src={this.props.img} />
<div>
<p><b>{this.props.name}</b></p>
<Rating>{this.props.rating}</Rating>
<p>{this.props.car.model} - {this.props.car.licensePlate}</p>
</div>
</div>
)
}
}
28 changes: 28 additions & 0 deletions src/components/Greeting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Component } from 'react'

export default class Greetings extends Component {

translate(language) {
switch (language) {
case "en":
return "Helo "
break;
case "es":
return "Hola "
break;
case "de":
return "Hallo "
break;
case "fr":
return "Bonjour "
break;
}
}

render() {
return (
<p>{this.translate(this.props.lang)}{this.props.children}</p>
)
}
}

25 changes: 25 additions & 0 deletions src/components/IdCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react'

export default function IdCard(props) {

const height = props.height / 100;


const flex = {
display: "flex",
border: "1px solid black"
}

return (
<div style={flex}>
<img width="200" src={props.picture} />
<div>
<p><b>First name: </b> {props.lastName}</p>
<p><b>Last name: </b> {props.firstName}</p>
<p><b>Gender: </b> {props.gender}</p>
<p><b>Heigth: </b> {height} m</p>
<p><b>Birth: </b> {props.birth}</p>
</div>
</div>
)
}
27 changes: 27 additions & 0 deletions src/components/LikeButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { Component } from 'react'

export default class LikeButton extends Component {


state = {
likes: 0,
colors: ['purple', 'blue', 'green', 'yellow', 'orange', 'red']
}

bgColor = {
backgroundColor: `${this.state.colors[this.state.likes % 6]}`
}

addLike() {
this.setState({
likes: this.state.likes + 1
})
console.log(this.state.colors[this.state.likes % 6])
}

render() {
return (
<button style={this.bgColor} onClick={() => this.addLike()}>{this.state.likes} Likes</button>
)
}
}
12 changes: 12 additions & 0 deletions src/components/Random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { Component } from 'react'

export default class Random extends Component {

number = Math.floor(Math.random() * this.props.max);

render() {
return (
<h3> Random value between {this.props.min} and {this.props.max} => {this.number}</h3>
)
}
}
26 changes: 26 additions & 0 deletions src/components/Rating.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { Component } from 'react'

export default class Rating extends Component {

printStars(number) {
number = Math.round(number)
let string = ""
for (let i = 0; i < number; i++) {
string += "★"
}
for (let i = 0; i < 5 - number; i++) {
string += "☆"
}
return string
}

render() {
return (
<div>
{
<h2>{this.printStars(this.props.children)}</h2>
}
</div>
)
}
}