Skip to content

Commit

Permalink
Improve Explanation dialog design (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaburgan authored Oct 29, 2024
1 parent 85568e6 commit 43da2d4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
9 changes: 6 additions & 3 deletions components/chart-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ interface ChartBarProps {
export default function ChartBar(props: ChartBarProps) {
const {value, total} = props;
let percent = value * 100 / total;
let color = "red";
let color = red;
if (value < 0) {
percent = -percent;
color = "green";
color = green;
}

return (<div className={styles.chartBar}>
<span className={styles.bar} style={{width: percent + "%", backgroundColor: color}}></span>
<span className={styles.co2}>{displayCO2(value)}</span>
</div>);
}
}

export const red = "#ce2550";
export const green = "#25CFA4";
6 changes: 4 additions & 2 deletions components/explanation-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FootprintDetails } from "../types/AdemeECV";
import { useLingui } from "@lingui/react";
import { getFootprintDetails } from "../lib/ademe-api";
import { Locale } from "../types/i18n";
import ChartBar from "./chart-bar";
import ChartBar, { green, red } from "./chart-bar";

interface ExplanationDialogProps {
item: Item;
Expand Down Expand Up @@ -43,7 +43,9 @@ export default function ExplanationDialog(props: ExplanationDialogProps) {
</main>
<footer>
<h3><Trans>Total:</Trans></h3>
<p><strong>{total} kg CO<sub>2</sub>e</strong></p>
<div>
<strong style={{backgroundColor: total > 0 ? red : green}}>{total} kg CO<sub>2</sub>e</strong>
</div>
</footer>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions styles/chart-bar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
display: inline-block;
height: 1rem;
margin-right: 5px;
border-radius: 3px;
border: solid 2px #333;
}

.co2 {
Expand Down
27 changes: 24 additions & 3 deletions styles/explanation-dialog.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@
border-radius: $box-border-radius;

header,
main {
main,
footer {
padding: 1rem;
}

main {
padding-top: 0;
padding-bottom: 0;
}

h2 {
font-size: 1.6rem;
}

h2,
h3 {
margin: 0;
}
h3 {
margin-bottom: 5px;
margin-bottom: .5rem;
}

ul {
margin: 0;
padding: 0;
Expand All @@ -46,5 +55,17 @@

footer {
text-align: center;

h3 {
font-size: 1.4rem;
margin-bottom: 1rem;
}

strong {
font-size: 1.6rem;
padding: .4rem .8rem;
border: solid #333 2px;
border-radius: 3px;
}
}
}

0 comments on commit 43da2d4

Please sign in to comment.