Skip to content

Commit 3aaa14e

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

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
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
}

0 commit comments

Comments
 (0)