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
97 changes: 92 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,104 @@
import React, { Component } from 'react';
import IdCard from './components/IdCard.js'
import Greetings from './components/Greetings.js';
import Random from './components/Random.js';
import BoxColor from './components/BoxColor.js';
import CreditCard from './components/CredirCard.js';
import Rating from './components/Rating.js';
import DriverCard from './components/DriverCard.js';

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")}
picture="https://randomuser.me/api/portraits/men/44.jpg"
/>

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

<h1>Greetings</h1>
{/* TODO: Use the Greetings component */}
</div>
);
}
<Greetings lang='es'>Nico</Greetings>

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

<h1>Color</h1>
<BoxColor r={255} g={3} b={5}/>

<h1>Credit Card</h1>
<div className="card-container">
<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"
/>
</div>

<h1>Ratings</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"
}} />
</div>
);
}
}

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

function BoxColor(props) {
const rgbToHex = (color) => {
let hex = Number(color).toString(16);
if (hex.length < 2) {
hex = '0' + hex;
} return hex;
}
const fullColorToHex = (red,green,blue) => {
let r = rgbToHex(red);
let g = rgbToHex(green);
let b = rgbToHex(blue);
return r+g+b
}
const background = {background: `rgb(${props.r},${props.g},${props.b})`};
return (
<div className="box" style={background}>
<p>rgb({props.r}, {props.g}, {props.b})</p>
<p>#{fullColorToHex (props.r, props.g, props.b)}</p>
</div>
)
}

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

function CredirCard(props) {
const printNumberCard = (num) => {
return num.slice(0, -4).replace(/./g, '•') + num.slice(-4)
}
const logoCard = props.type === 'Visa' ? './img/visa.png' : './img/master-card.svg';
const styles= {
background: props.bgColor,
color: props.color
}
return (
<div style={styles} className="card">
<div>
<img src={logoCard} alt=""/>
</div>
<h2>{printNumberCard(props.number)}</h2>
<p>Expires {props.expirationMonth}/{props.expirationYear} <span>{props.bank}</span></p>
<p>{props.owner}</p>
</div>
)
}


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

export default function DriverCard(props) {
const intRating = Math.round(props.rating)
const stars = (rating) =>{

let starFilled = '★';
let starEmpty = '☆';
let starsArr = new Array(5);
for(let i = 0; i < 5; i++){
if(i < rating){
starsArr[i] = starFilled;
}else{
starsArr[i] = starEmpty;
}
}

return starsArr.join('')
}
return (
<div className="driver-card">
<div><img src={props.img} alt={props.name}/></div>
<div>
<h3>{props.name}</h3>
<p>{stars(intRating)}</p>
<p>{props.car.model} - {props.car.licensePlate}</p>
</div>
</div>
)
}
14 changes: 14 additions & 0 deletions src/components/Greetings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'

function Greetings(props) {
return (
<div className="greetings">
{props.lang === 'de' ? <span>Hallo {props.children}</span> : null}
{props.lang === 'en' ? <span>Hello {props.children}</span> : null}
{props.lang === 'es' ? <span>Hola {props.children}</span> : null}
{props.lang === 'fr' ? <span>Bonjour {props.children}</span> : null}
</div>
)
}

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

function IdCard(props) {
return (
<div className="id-card">
<img src={props.picture} alt={props.firstName}/>
<article>
<p>First name: <span>{props.firstName}</span></p>
<p>Last name: <span>{props.lastName}</span></p>
<p>Gender: <span>{props.gender}</span></p>
<p>Heigth: <span>{props.height}</span></p>
<p>Birth: <span>{props.birth.toLocaleDateString()}</span></p>
</article>
</div>
)
}

export default IdCard;
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 from 'react'

function Random(props) {
return (
<div className="random">
<p>Random value between {props.min} and {props.max} => {Math.floor(Math.random() * (props.max - props.min) + props.min)}</p>
</div>
)
}


export default Random;
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 from 'react'

export default function Rating(props) {
const intRating = Math.round(props.children)

const stars = (rating) =>{

let starFilled = '★';
let starEmpty = '☆';
let starsArr = new Array(5);
for(let i = 0; i < 5; i++){
if(i < rating){
starsArr[i] = starFilled;
}else{
starsArr[i] = starEmpty;
}
}

return starsArr.join('')
}
return (
<div>
{stars(intRating)}
</div>
)
}
116 changes: 111 additions & 5 deletions src/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading