Skip to content

Commit a6505ab

Browse files
committed
maybe use semantic html?
1 parent 4843e40 commit a6505ab

File tree

6 files changed

+30
-17
lines changed

6 files changed

+30
-17
lines changed

docs/bigNumber.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ ${Dash.BigNumber(1)}
55
<div class="card grid grid-cols-4">
66
${Dash.BigNumber(1127)}
77
${Dash.BigNumber(17, {secondary: 7, secondaryFormat: "+"})}
8-
${Dash.BigNumber(1e9 * Math.E, {format: "s", secondary: -2/3, secondaryFormat: ".1%"})}
8+
${Dash.BigNumber(1e9 * Math.E, {title: "e", subtitle: "Transcendental value", format: "s", secondary: -2/3, secondaryFormat: ".1%", secondaryTitle: "Year over year"})}
99
${Dash.BigNumber(1e9 * Math.E, {format: "s", secondary: -2/3, secondaryFormat: ".1%", secondaryColor: "steelblue"})}
1010
</div>
1111

1212
<div class="card grid grid-cols-4">
13-
${Dash.BigNumber(1127, {secondary: 0})}
13+
${Dash.BigNumber(1127, {title: "A unit", secondary: 0})}
1414
${Dash.BigNumber(10, {secondary: -7/17, secondaryFormat: ".0%", children: Plot.lineY({length: 100}, Plot.mapY("cumsum", {
1515
y: d3.randomNormal.source(d3.randomLcg(42))()
1616
})).plot({width: 300, height: 40, axis: false})})}

src/client/stdlib/dash/bigNumber.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export function BigNumber(
77
href,
88
target = "_blank",
99
title,
10+
subtitle,
1011
format = ",.2~f",
12+
columnGap = "10px",
1113
secondary,
1214
secondaryFormat = format,
1315
secondaryColor = secondary == null
@@ -19,13 +21,14 @@ export function BigNumber(
1921
: "var(--theme-color-neutral)",
2022
secondaryArrow = secondary == null ? "" : secondary > 0 ? "↗︎" : secondary < 0 ? "↘︎" : "→",
2123
secondaryTitle,
22-
styles = {display: "flex", flexDirection: "column", fontFamily: "var(--sans-serif)"},
2324
children
2425
}: {
2526
href?: string;
2627
target?: string;
2728
title?: string;
29+
subtitle?: string;
2830
format?: string | ((x: any) => string);
31+
columnGap?: string;
2932
secondary?: number;
3033
secondaryFormat?: string | ((x: any) => string);
3134
secondaryColor?: string;
@@ -37,19 +40,20 @@ export function BigNumber(
3740
) {
3841
if (typeof format !== "function") format = typeof number === "string" ? String : d3.format(format);
3942
if (typeof secondaryFormat !== "function") secondaryFormat = d3.format(secondaryFormat);
40-
const div = html`<div style="${styles}">
41-
<div style="text-transform: uppercase; font-size: 12px;">${title}</div>
42-
<div style="display: flex; flex-wrap: wrap; column-gap: 10px; align-items: baseline;">
43-
<div style="font-size: 32px; font-weight: bold; line-height: 1;">${(format as (x: any) => string)(number)}</div>
43+
const div = html`<figure class="bignumber">
44+
${title != null ? html`<h2>${title}` : ""}
45+
${subtitle != null ? html`<h3>${subtitle}` : ""}
46+
<dl style="display: flex; flex-wrap: wrap; align-items: baseline; column-gap: ${columnGap};">
47+
<dt>${(format as (x: any) => string)(number)}</dt>
4448
${
4549
secondary == null
4650
? null
47-
: html`<div style="font-size: 14px; color: ${secondaryColor};" ${{title: secondaryTitle}}>${(
51+
: html`<dd style="color: ${secondaryColor};" ${{title: secondaryTitle}}>${(
4852
secondaryFormat as (x: any) => string
49-
)(secondary)} ${secondaryArrow}</div>`
53+
)(secondary)} ${secondaryArrow}`
5054
}
51-
</div>
55+
</dl>
5256
${children}
53-
</div>`;
57+
</figure>`;
5458
return href == null ? div : html`<a href=${href} target=${target} style="color: inherit;">${div}</a>`;
5559
}

src/style/bigNumber.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
:root {
2+
--theme-color-positive: #3ca951;
3+
--theme-color-negative: #ff725c;
4+
--theme-color-neutral: #efb118;
5+
}
6+
7+
figure.bignumber dl {margin-top: 0; }
8+
figure.bignumber dt {
9+
font-size: 32px; font-weight: bold; line-height: 1;
10+
}
11+
figure.bignumber dd {
12+
font-size: 14px;
13+
margin-left: 0;
14+
}

src/style/default.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import url("./global.css");
22
@import url("./layout.css");
33
@import url("./grid.css");
4+
@import url("./bigNumber.css");
45
@import url("./inspector.css");
56
@import url("./inputs.css");
67
@import url("./plot.css");

src/style/theme-dark.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@
1010
--theme-foreground-fainter: color-mix(in srgb, var(--theme-foreground) 30%, var(--theme-background));
1111
--theme-foreground-faintest: color-mix(in srgb, var(--theme-foreground) 10%, var(--theme-background));
1212
--theme-foreground-focus: oklch(0.712564 0.257662 265.758);
13-
--theme-color-positive: #3ca951; /* green */
14-
--theme-color-negative: #ff725c; /* red */
15-
--theme-color-neutral: #efb118; /* orange/yellow */
1613
color-scheme: dark;
1714
}

src/style/theme-light.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@
1010
--theme-foreground-fainter: color-mix(in srgb, var(--theme-foreground) 30%, var(--theme-background));
1111
--theme-foreground-faintest: color-mix(in srgb, var(--theme-foreground) 10%, var(--theme-background));
1212
--theme-foreground-focus: #3b5fc0;
13-
--theme-color-positive: #3ca951; /* green */
14-
--theme-color-negative: #ff725c; /* red */
15-
--theme-color-neutral: #efb118; /* orange/yellow */
1613
color-scheme: light;
1714
}

0 commit comments

Comments
 (0)