Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create User Card component #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
23 changes: 22 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { UserCard } from "./UserCard"
import { UserCardClass } from "./UserCardClass"
import "./assets/user.css"
import user from "./assets/user.json"

function App() {
return "Hello World"
return (
<div>
<UserCard
name={user.name}
age={user.age}
phoneNumber={user.phoneNumber}
address={user.address}
/>
<br />
<UserCardClass
name={user.name}
age={user.age}
phoneNumber={user.phoneNumber}
address={user.address}
/>
</div>
)
}

export default App
15 changes: 15 additions & 0 deletions src/UserCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function UserCard({ name, age, phoneNumber, address }) {
return (
<div className="card">
<h2 className="name">{name}</h2>
<div className="body">
<div className="label">Age:</div>
<div>{age}</div>
<div className="label">Phone:</div>
<div>{phoneNumber}</div>
<div className="label">Address:</div>
<div>{address}</div>
</div>
</div>
)
}
19 changes: 19 additions & 0 deletions src/UserCardClass.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react"

export class UserCardClass extends React.Component {
render() {
return (
<div className="card">
<h2 className="name">{this.props.name}</h2>
<div className="body">
<div className="label">Age:</div>
<div>{this.props.age}</div>
<div className="label">Phone:</div>
<div>{this.props.phoneNumber}</div>
<div className="label">Address:</div>
<div>{this.props.address}</div>
</div>
</div>
)
}
}
29 changes: 29 additions & 0 deletions src/assets/user.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
body {
background: #f3f3f3;
}

.card {
background: white;
border: 1px solid #777;
border-radius: 0.5rem;
box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.15);
max-width: 400px;
padding: 1.5rem;
font-family: Arial;
}

.name {
margin: 0;
margin-bottom: 2rem;
}

.body {
display: grid;
grid-template-columns: auto 1fr;
gap: 1rem 0.5rem;
padding: 0 1rem;
}

.label {
font-weight: bold;
}
6 changes: 6 additions & 0 deletions src/assets/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Kyle Cook",
"age": 27,
"phoneNumber": "123-456-7890",
"address": "123 Main St."
}