Skip to content

Commit e538d99

Browse files
committed
Change summary design from background colors to bars
1 parent 99c1a32 commit e538d99

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

src/components/__snapshots__/main.test.tsx.snap

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,20 @@ exports[`renders summary and transaction list 1`] = `
168168
className="summary"
169169
>
170170
<tbody>
171-
<tr
172-
style={
173-
Object {
174-
"backgroundColor": "rgba(226,91,29,1)",
175-
"color": "var(--dark-color)",
176-
}
177-
}
178-
>
171+
<tr>
179172
<th
180173
className="account"
181174
>
182175
Jan
176+
<div
177+
className="summary-bar"
178+
style={
179+
Object {
180+
"backgroundColor": "red",
181+
"width": "calc(100% - 24px)",
182+
}
183+
}
184+
/>
183185
</th>
184186
<td
185187
className="amount"
@@ -196,18 +198,20 @@ exports[`renders summary and transaction list 1`] = `
196198
</small>
197199
</td>
198200
</tr>
199-
<tr
200-
style={
201-
Object {
202-
"backgroundColor": "rgba(92,226,14,1)",
203-
"color": "var(--dark-color)",
204-
}
205-
}
206-
>
201+
<tr>
207202
<th
208203
className="account"
209204
>
210205
Martin
206+
<div
207+
className="summary-bar"
208+
style={
209+
Object {
210+
"backgroundColor": "black",
211+
"width": "calc(100% - 24px)",
212+
}
213+
}
214+
/>
211215
</th>
212216
<td
213217
className="amount"

src/components/summary.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ function formatData(accounts: Account[]) {
2020
return round(result);
2121
};
2222

23-
const getRowStyle = (amount: number, maxAmount: number) => {
23+
const getBarStyle = (amount: number, maxAmount: number) => {
2424
if (!maxAmount) {
25-
return { backgroundColor: "transparent" };
25+
return { width: 0 };
2626
}
27-
const color = amount < 0 ? [226, 91, 29] : [92, 226, 14];
28-
const opacity = Math.abs(amount) / maxAmount;
29-
color.push(opacity);
30-
const textColor = opacity > 0.6 ? "var(--dark-color)" : "";
31-
return { backgroundColor: `rgba(${color.join(",")})`, color: textColor };
27+
const color = amount < 0 ? "red" : "black";
28+
const percent = (Math.abs(amount) / maxAmount) * 100;
29+
const cellPadding = 12;
30+
return {
31+
backgroundColor: color,
32+
width: `calc(${percent}% - ${cellPadding * 2}px)`,
33+
};
3234
};
3335

3436
const maxAmount = getMaxAmount(accounts);
3537
const data = accounts.map((account) => ({
3638
amount: round(account.amount),
37-
style: getRowStyle(account.amount, maxAmount),
39+
barStyle: getBarStyle(account.amount, maxAmount),
3840
participant: account.participant,
3941
}));
4042

@@ -45,8 +47,11 @@ const Summary: FunctionComponent<Props> = ({ accounts }) => (
4547
<table className="summary">
4648
<tbody>
4749
{formatData(accounts).map((account) => (
48-
<tr key={account.participant} style={account.style}>
49-
<th className="account">{account.participant}</th>
50+
<tr key={account.participant}>
51+
<th className="account">
52+
{account.participant}
53+
<div className="summary-bar" style={account.barStyle} />
54+
</th>
5055
<td className="amount">
5156
<Amount>{account.amount}</Amount>
5257
</td>

src/index.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,14 @@ input[type="number"] {
561561
.summary tr {
562562
box-sizing: border-box;
563563
height: 56px;
564+
position: relative;
565+
}
566+
567+
.summary-bar {
568+
position: absolute;
569+
bottom: 6px;
570+
height: 5px;
571+
border-radius: 5px;
564572
}
565573

566574
#transactions .dategroup:not(:last-child) {

0 commit comments

Comments
 (0)