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
559 changes: 521 additions & 38 deletions package-lock.json

Large diffs are not rendered by default.

104 changes: 102 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,114 @@
import React, { Component } from 'react';
import IdCard from './Components/IdCard';
import Greetings from './Components/Greetings';
import Random from './Components/Random';
import BoxColor from './Components/BoxColor';
import CreditCard from './Components/CreditCard';
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={new Date("1992-07-14").toString()}
picture="https://randomuser.me/api/portraits/men/44.jpg"
/>
<IdCard
lastName='Delores '
firstName='Obrien'
gender='female'
height={172}
birth={new Date("1988-05-11").toString()}
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>CreditCard</h1>
<CreditCard
type="Visa"
number="0123456789018845"
expirationMonth={3}
expirationYear={2021}
bank="BNP"
owner="Maxence Bouret"
bgColor="#11aa99"
color="white" />
<CreditCard
type="Master Card"
number="0123456789010995"
expirationMonth={3}
expirationYear={2021}
bank="N26"
owner="Maxence Bouret"
bgColor="#eeeeee"
color="#222222" />
<CreditCard
type="Visa"
number="0123456789016984"
expirationMonth={12}
expirationYear={2019}
bank="Name of the Bank"
owner="Firstname Lastname"
bgColor="#ddbb55"
color="white" />

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

<h1>DriverCard</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"
}} />

<h1>Like Button</h1>
<div><LikeButton /> <LikeButton /></div>

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

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

const divStyle = (r,g,b) => {
const style = `rgb(${r}, ${g}, ${b})`
return style;
};

const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');

function BoxColor(props) {
const {r,g,b} = props;
return (
<div style={{backgroundColor: divStyle(r, g, b)}}>
{divStyle(r, g, b)}<br/>
#{RGBToHex(r, g, b)}
</div>
)
}

export default BoxColor;

24 changes: 24 additions & 0 deletions src/Components/ClickablePicture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { Component } from 'react';

class ClickablePicture extends Component {
state = {
src: this.props.img,
}

changePic = () => {
const { src } = this.state;
const { img, imgClicked } = this.props;
let newSrc = (src === img) ? imgClicked : img;
this.setState({
src: newSrc
})
};

render() {
return (
<img onClick={this.changePic} src={this.state.src} alt={'click to change'}/>
)
}
}

export default ClickablePicture;
20 changes: 20 additions & 0 deletions src/Components/CreditCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'

function CreditCard(props) {

const {type,number,expirationMonth,expirationYear,bank,owner,bgColor,color} = props;

return (
<div style={{backgroundColor: bgColor,color: color}}>
<img src={ type === 'Visa' ? '/img/visa.png' : '/img/master-card.svg' } width={50} alt=""/>
<p>{number}</p>
<p>Expires {expirationMonth.toLocaleString('en-US', {minimumIntegerDigits: 2, useGrouping:false})}/{expirationYear.toString().slice(2, 4)}</p>
<p>{bank}</p>
<p>{owner}</p>
</div>
)
}

export default CreditCard;


26 changes: 26 additions & 0 deletions src/Components/Dice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { Component } from 'react';

class Dice extends Component {
state = {
initial: (Math.floor(Math.random() * (6 - 1 + 1)) + 1),
}

changeDice = () => {
this.setState({
initial: '-empty'
})
setTimeout(() => {
this.setState({
initial: (Math.floor(Math.random() * (6 - 1 + 1)) + 1)
})
}, 1000);
};

render() {
return (
<img onClick={this.changeDice} src={`/img/dice${this.state.initial}.png`} alt={'click to change'} width={150}/>
)
}
}

export default Dice;
16 changes: 16 additions & 0 deletions src/Components/DriverCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import Rating from './Rating';

function DriverCard(props) {
const {name,rating,img,car} = props;
return (
<div style={{backgroundColor: '#455EB5', color: 'white'}}>
<img src={img} alt={name} width={100} height={100} style={{borderRadius: 50, objectFit: 'cover'}}/>
<h3>{name}</h3>
<Rating>{rating}</Rating>
<p>{car.model} – {car.licensePlate}</p>
</div>
)
}

export default DriverCard;
20 changes: 20 additions & 0 deletions src/Components/Greetings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'


function Greetings(props) {
switch (props.lang) {
case "de":
return (<p>Hallo {props.children}</p>)
case "en":
return (<p>Hello {props.children}</p>)
case "es":
return (<p>Hola {props.children}</p>)
case "fr":
return (<p>Bonjour {props.children}</p>)
default:
break;
}

}

export default Greetings;
16 changes: 16 additions & 0 deletions src/Components/IdCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

function IdCard(props) {
return (
<article>
<img src={props.picture} alt={props.firstName}/>
<p><b>First name</b>: {props.firstName}</p>
<p><b>Last name</b>: {props.lastName}</p>
<p><b>Gender</b>: {props.gender}</p>
<p><b>Height</b>: {props.height}</p>
<p><b>Birth</b>: {props.birth}</p>
</article>
)
}

export default IdCard;
26 changes: 26 additions & 0 deletions src/Components/LikeButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { Component } from 'react';

class LikeButton extends Component {
state = {
number:0,
}

addNumber = () => {
let newNumber = this.state.number;
this.setState({
number: ++newNumber
})
};

render() {
const {number} = this.state;
const colors = ['purple','blue','green','yellow','orange','red']; 
return (
<button style={{backgroundColor: colors[number%(colors.length)], color: 'white'}} onClick={this.addNumber}>
{number} Likes
</button>
)
}
}

export default LikeButton;
11 changes: 11 additions & 0 deletions src/Components/Random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'

const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;

function Random(props) {
return (
<p>Random value between {props.min} and {props.max} => {randomIntegerInRange(props.min, props.max)}</p>
)
}

export default Random;
16 changes: 16 additions & 0 deletions src/Components/Rating.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

function Rating(props) {
const numberStars = Math.round(props.children)
const emptyStars = 5 - numberStars;
const fs = '★';
const es = '☆';

return (
<div>
{fs.repeat(numberStars).concat(es.repeat(emptyStars))}
</div>
)
}

export default Rating;
Loading