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
15,828 changes: 15,828 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

88 changes: 56 additions & 32 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,62 @@
.App {
.person {
display: flex;
justify-content: left;
width: 90%;
}
.person img {
height: 180px;
}
.details {
padding-left: 1rem;
line-height: normal;
}
.withborder {
border: 1px solid black;
margin: 1rem;
padding: 0.5rem;
}
.textCenter {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
.creditcard {
border-radius: 5px;
background-repeat: no-repeat;
background-size: 50px;
background-position: 90% 15%;
width: 350px;
height: auto;
padding: 1rem;
}
.credits {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
gap: 1rem;
}
.master {
background-image: url('./img/master-card.svg');
}
.visa {
background-image: url('./img/visa.png');
}
.driver {
background-color: #455eb5;
color: white;
text-align: center;
padding: 1rem;
margin-top: 0.5rem;
}
.driver * {
margin-top: 0.5rem;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
.driver img {
height: 160px;
width: 160px;
border-radius: 50%;
}
.likeBtn {
padding: 10px 20px;
width: fit-content;
}
.flex {
display: flex;
gap: 0.2rem;
}
112 changes: 97 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,106 @@
import React from 'react';
import logo from './logo.svg';

import './App.css';
import IdCard from './Components/IdCard/IdCard';
import Greetings from './Components/Greetings/Greetings';
import Random from './Components/Random/Random';
import BoxColor from './Components/BoxColor/BoxColor';
import CreditCard from './Components/CreditCard/CreditCard';
import Rating from './Components/Rating/Rating'
import DriverCard from './Components/DriverCard/DriverCard';
import LikeButton from './Components/LikeButton/LikeButton';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<div className="personContainer">
//Passing personInfo in a Single object to Support the data/berlin.json more easier instead of passing each detail in separate prop.
All Stylingare done not 100%accurate butan aproximation
<IdCard
personInfo={{
firstName: "John",
lastName: "Doe",
gender: "male",
height: 178,
img: "https://randomuser.me/api/portraits/men/44.jpg",
birth: new Date("1992-07-14"),
}} />
<IdCard
personInfo={{
lastName: 'Delores ',
firstName: 'Obrien',
gender: 'female',
height: 172,
birth: new Date("1988-05-11"),
img: "https://randomuser.me/api/portraits/women/44.jpg"
}}
/>
</div>
<Greetings lang="de">Ludwig</Greetings>
<Greetings lang="fr">François</Greetings>
<Random min={1} max={6} />
<Random min={1} max={100} />
<BoxColor r={255} g={0} b={0} />
<BoxColor r={128} g={255} b={0} />

<div className="credits">
<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>
<Rating>0</Rating>
<Rating>1.49</Rating>
<Rating>1.5</Rating>
<Rating>3</Rating>
<Rating>4</Rating>
<Rating>5</Rating>
<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 className="flex">

<LikeButton />
<LikeButton />
</div>

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

function BoxColor({ r, g, b }) {
let hex = rgbToHex(r, g, b)
//To Adjust the contrast always visable:
let textcolor = setForegroundColor([r, g, b])
return (
<div className="withborder textCenter" style={{ with: "100%", height: "150px", backgroundColor: `rgb(${r},${g},${b})`, fontSize: "2rem", color: `${textcolor}` }}>
<p> `rgb(${r},${g},${b})` </p>
<p>{hex}</p>
</div>
)
}

export default BoxColor
//Helpers :
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function setForegroundColor(rgb) {
var sum = Math.round(((parseInt(rgb[0]) * 299) + (parseInt(rgb[1]) * 587) + (parseInt(rgb[2]) * 114)) / 1000);
return (sum > 128) ? 'black' : 'white';
}

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

function CreditCard({ type, number, expirationMonth, expirationYear, bank, owner, bgColor, color }) {
let cssArray = []
cssArray.push('creditcard')
cssArray.push(getCardTypeClass(type))
const classes = cssArray.join(" ")
return (
<div className={classes} style={{ backgroundColor: bgColor, color }}>
<h2>{number}</h2>
<p>Expires {expirationMonth}/{expirationYear} {bank}</p>
<p>{owner}</p>
</div>
)
}

export default CreditCard
//Helpers :
//OverKill for just 2 type, but we can addd more easily:
function getCardTypeClass(type) {
switch (type) {
case 'Master Card':
return "master"
case 'Visa':
return 'visa'
}
}
15 changes: 15 additions & 0 deletions src/Components/DriverCard/DriverCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import Rating from '../Rating/Rating'

function DriverCard({ name, rating, img, car }) {
return (
<div className="driver">
<img src={img} />
<h3>{name}</h3>
<Rating>{rating}</Rating>
<p>{car.model} - {car.licensePlate}</p>
</div>
)
}

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

function Greetings(props) {
let greeting = '';
switch (props.lang) {
case 'de':
greeting = 'Hallo'
break;
case 'en':
greeting = 'Hello'
break;
case 'es':
greeting = 'Holla'
break;
case 'fr':
greeting = 'Bonjour'
break;
}
return (
<div className="withborder">
<p>
{`${greeting} ${props.children}`}
</p>
</div>
)
}

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

function IdCard({ personInfo }) {
const { lastName, firstName, gender, height, birth, img: picture } = personInfo;

return (
<div className="person withborder">
<img src={picture} />
<div className="details">

<p><strong>First Name:</strong>{firstName}</p>
<p><strong>Last Name:</strong>{lastName}</p>
<p><strong>Gender:</strong>{gender}</p>
<p><strong>Height:</strong>{height}</p>
<p><strong>Birth:</strong>{birth.toString()}</p>
</div>
</div>
)
}

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

function LikeButton() {
const [likes, setlikes] = useState(0)
const [color, setColor] = useState('purple')
const colors = ['purple', 'blue', 'green', 'yellow', 'orange', 'red'];

const handleClick = () => {
console.log(colors)
setColor(getRandomColor(colors))
setlikes((prevState) => ++prevState)

}
return (
<div onClick={handleClick} className="likeBtn" style={{ backgroundColor: color }}>
{likes} Likes
</div>
)
}

export default LikeButton
//helper
function getRandomColor(colors) {
return colors[Math.floor(Math.random() * colors.length)]

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

function Random({ min, max }) {
let randomNumber = Math.random() * (max - min) + min;
return (
<div className="withborder">
<p>
Random Value between {min} and {max} =&#62; {randomNumber}

</p>
</div>
)
}

export default Random
Loading