Skip to content

Commit ad19542

Browse files
authored
fix(big_number) :: preserve color and spacing (#1452)
* fix(big_number) :: preserve color and spacing * refactor(big_number) :: keep spacing local * Test big-number colors with real shell themes and verify rendered padding
1 parent 2cb3d02 commit ad19542

5 files changed

Lines changed: 72 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## unreleased
44

5+
- Big number cards with a `color` once again display their main value in that color in light and dark themes, including values with a link. Their compact vertical padding has also been restored.
6+
57
## v0.46.2
68

79
- Numeric x values on Cartesian charts now explicitly use a continuous numeric axis, preventing fractional tick positions from being displayed as misleading rounded integers.

‎examples/official-site/sqlpage/migrations/49_big_number.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
2222
('progress_percent', 'The value of the progress (0-100).', 'INTEGER', FALSE, TRUE),
2323
('progress_color', 'The color of the progress bar (e.g., "primary", "success", "danger").', 'TEXT', FALSE, TRUE),
2424
('dropdown_item', 'A list of JSON objects containing links. e.g. {"label":"This week", "link":"?days=7"}', 'JSON', FALSE, TRUE),
25-
('color', 'The color of the card', 'COLOR', FALSE, TRUE)
25+
('color', 'The color of the card background and its main value.', 'COLOR', FALSE, TRUE)
2626
) x;
2727

2828
INSERT INTO example(component, description, properties) VALUES

‎sqlpage/templates/big_number.handlebars‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{{#unless ../columns}}style="min-width: 9rem;"{{/unless}}
99
{{~#if id}} id="{{id}}"{{/if~}}
1010
>
11-
<div class="card flex-fill {{#if color}}bg-{{color}}-lt{{/if}}">
11+
<div class="card flex-fill {{#if color}}bg-{{color}}-lt{{/if}}" style="--tblr-card-spacer-y: 1rem;">
1212
<div class="card-body d-flex flex-column">
1313

1414
{{#if title}}
@@ -47,7 +47,7 @@
4747
{{/if}}
4848

4949
<div class="d-flex align-items-center mt-1">
50-
<div class="h1 {{#if description}}mb-3{{else}}mb-0{{/if}} mt-auto text-nowrap text-truncate">
50+
<div class="h1 {{#if description}}mb-3{{else}}mb-0{{/if}} mt-auto text-nowrap text-truncate {{#if color}}text-{{color}}{{/if}}">
5151
{{#if value_link}}
5252
<a href="{{value_link}}"
5353
class="text-decoration-none"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SELECT 'shell' AS component, COALESCE($theme, 'light') AS theme;
2+
3+
SELECT
4+
'big_number' AS component,
5+
2 AS columns;
6+
7+
SELECT
8+
'plain-color' AS id,
9+
'Plain value' AS title,
10+
'1,234' AS value,
11+
'red' AS color;
12+
13+
SELECT
14+
'linked-color' AS id,
15+
'Linked value' AS title,
16+
'5,678' AS value,
17+
'blue' AS color,
18+
'#linked-color' AS value_link;
19+
20+
SELECT
21+
'default-color' AS id,
22+
'Default value' AS title,
23+
'9,012' AS value;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect, test } from "../../fixture";
2+
3+
for (const theme of ["light", "dark"]) {
4+
test(`colored values match their cards in the ${theme} theme`, async ({
5+
page,
6+
}) => {
7+
await page.goto(`/big-number/?theme=${theme}`);
8+
await expect(page.locator("body")).toHaveAttribute("data-bs-theme", theme);
9+
await expect(page.locator("body")).toHaveCSS("color-scheme", theme);
10+
11+
const defaultColor = await page
12+
.locator("#default-color .h1")
13+
.evaluate((value) => getComputedStyle(value).color);
14+
const rem = await page
15+
.locator("html")
16+
.evaluate((html) => Number.parseFloat(getComputedStyle(html).fontSize));
17+
18+
for (const { id, linked } of [
19+
{ id: "plain-color", linked: false },
20+
{ id: "linked-color", linked: true },
21+
]) {
22+
const item = page.locator(`#${id}`);
23+
const cardColor = await item
24+
.locator(".card")
25+
.evaluate((card) => getComputedStyle(card).color);
26+
27+
// Matching two default-colored elements must not count as a color fix.
28+
expect(cardColor).not.toBe(defaultColor);
29+
await expect(item.locator(".h1")).toHaveCSS("color", cardColor);
30+
await expect(item.locator(".h1 a")).toHaveCount(linked ? 1 : 0);
31+
if (linked) {
32+
await expect(item.locator(".h1 a")).toHaveCSS("color", cardColor);
33+
}
34+
await expect(item.locator(".card-body")).toHaveCSS(
35+
"padding-top",
36+
`${rem}px`,
37+
);
38+
await expect(item.locator(".card-body")).toHaveCSS(
39+
"padding-bottom",
40+
`${rem}px`,
41+
);
42+
}
43+
});
44+
}

0 commit comments

Comments
 (0)