Skip to content

Commit f715661

Browse files
committed
Improving components
1 parent 8f89d56 commit f715661

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

Sections/Section 3/01-starting-setup/src/App.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
import ExpenseItem from "./components/ExpenseItem";
22

33
function App() {
4+
const expenses = [
5+
{
6+
id: 'e1',
7+
title: 'Toilet Paper',
8+
amount: 94.12,
9+
date: new Date(2020, 7, 14),
10+
},
11+
{ id: 'e2', title: 'New TV', amount: 799.49, date: new Date(2021, 2, 12) },
12+
{
13+
id: 'e3',
14+
title: 'Car Insurance',
15+
amount: 294.67,
16+
date: new Date(2021, 2, 28),
17+
},
18+
{
19+
id: 'e4',
20+
title: 'New Desk (Wooden)',
21+
amount: 450,
22+
date: new Date(2021, 5, 12),
23+
},
24+
];
25+
426
return (
527
<div>
628
<h2>Let's get started!</h2>
7-
<ExpenseItem></ExpenseItem>
29+
<ExpenseItem title={expenses[0].title} amount={expenses[0].amount} date={expenses[0].date}></ExpenseItem>
30+
<ExpenseItem title={expenses[1].title} amount={expenses[1].amount} date={expenses[1].date}></ExpenseItem>
31+
<ExpenseItem title={expenses[2].title} amount={expenses[2].amount} date={expenses[2].date}></ExpenseItem>
32+
<ExpenseItem title={expenses[3].title} amount={expenses[3].amount} date={expenses[3].date}></ExpenseItem>
833
</div>
934
);
1035
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.expense-date {
2+
display: flex;
3+
flex-direction: column;
4+
width: 5.5rem;
5+
height: 5.5rem;
6+
border: 1px solid #ececec;
7+
background-color: #2a2a2a;
8+
color: white;
9+
border-radius: 12px;
10+
align-items: center;
11+
justify-content: center;
12+
}
13+
14+
.expense-date__month {
15+
font-size: 0.75rem;
16+
font-weight: bold;
17+
}
18+
19+
.expense-date__year {
20+
font-size: 0.75rem;
21+
}
22+
23+
.expense-date__day {
24+
font-size: 1.5rem;
25+
font-weight: bold;
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import './ExpenseDate.css'
2+
function ExpenseDate(props) {
3+
const month = props.date.toLocaleString('en-US', {month: 'long'});
4+
const day = props.date.toLocaleString('en-US', {day: '2-digit'});
5+
const year = props.date.getFullYear();
6+
7+
return (
8+
<div className="expense-date">
9+
<div className="expense-date__month">{month}</div>
10+
<div className="expense-date__day">{day}</div>
11+
<div className="expense-date__year">{year}</div>
12+
</div>
13+
)
14+
}
15+
16+
export default ExpenseDate

Sections/Section 3/01-starting-setup/src/components/ExpenseItem.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import './ExpenseItem.css'
2+
import ExpenseDate from './ExpenseDate'
23

3-
function ExpenseItem () {
4-
const expenseDate = new Date(2021, 2, 28);
5-
const expenseTitle = 'Car Insurance';
6-
const expenseAmount = 294.67;
7-
4+
function ExpenseItem (props) {
85
return (
96
<div className="expense-item">
10-
<div>{expenseDate.toISOString()}</div>
7+
<ExpenseDate date={props.date}/>
118
<div className="expense-item__description">
12-
<h2>{expenseTitle}</h2>
13-
<div className="expense-item__price">${expenseAmount}</div>
9+
<h2>{props.title}</h2>
10+
<div className="expense-item__price">${props.amount}</div>
1411
</div>
1512
</div>
1613
)

0 commit comments

Comments
 (0)