How should a tinted page canvas with raised cards be built with $theme-bgs?
#43163
Replies: 1 comment
|
You don't need to re-point the component token maps. In alpha.1 you get the same result by re-declaring the Each component emits its token map on its own selector. For example, @layer custom {
body {
background-color: light-dark(var(--bs-gray-050), var(--bs-gray-975));
}
/* Raised surfaces: stock scale in light mode, one step lighter in dark mode */
.card, .dialog, .menu, .popover, .toast {
--bs-bg-body: light-dark(var(--bs-white), var(--bs-gray-950));
--bs-bg-1: light-dark(var(--bs-gray-025), var(--bs-gray-900));
--bs-bg-2: light-dark(var(--bs-gray-050), var(--bs-gray-800));
--bs-bg-3: light-dark(var(--bs-gray-100), var(--bs-gray-700));
--bs-bg-4: light-dark(var(--bs-gray-200), var(--bs-gray-600));
/* These aliases are resolved on :root, so they don't follow the scale */
--bs-btn-input-bg: var(--bs-bg-body);
--bs-control-disabled-bg: var(--bs-bg-3);
--bs-border-bg: var(--bs-bg-body);
--bs-fg-bg: var(--bs-bg-body);
}
}I tested this in Chromium with the alpha.1 CDN CSS. Light mode matches your option A exactly. In dark mode:
Add The catch is that this relies on where the tokens happen to be declared. That's my reading of the source, not a documented contract. Some tokens are resolved once on |
Uh oh!
There was an error while loading. Please reload this page.
v6 has one background role,
--bg-body, for both the page and the default component surface. The numbered steps--bg-1to--bg-4get darker in light mode and lighter in dark mode. There is no role for a raised surface that differs from the page, so I'm not sure how the team intends a common layout to be built: a tinted canvas with raised cards on it, as in dashboards, settings pages or the Album example.scss/_theme.scss(6.0.0-alpha.1, unchanged onmain):How components use them:
--bg-bodypaints the page (body { background-color: var(--bg-body); }incontent/_reboot.scss). It is also the default fill for card (--card-bg), list group, table, dialog, drawer, menu, popover, toast, accordion, pagination, datepicker and form controls (--btn-input-bg).--bg-1is the recessed fill inside those surfaces. It is used for:--card-cap-bg), alerts, the nav pills track, and toast and popover headers;There are two ways to build a tinted canvas, and each one breaks something. Measured with the snippet below; Chromium 156 and Firefox 157 give the same values:
#f1f2f3#171a1d#f1f2f3#080a0c#ffffff#080a0c#ffffff#0f1214#f6f7f8#0f1214#ffffff#0f1214#f6f7f8#0f1214#ffffff#0f1214#f6f7f8#0f1214#ffffff#0f1214#ffffff#080a0c#f1f2f3#080a0c#ffffff#080a0c#f1f2f3#080a0c.bg-2, cards on--bg-body. The Album example does this with.bg-1. Light mode is right. In dark mode the card (#080a0c) is darker than the canvas (#171a1d), so raised cards look sunken, becausebodyis the darkest step in dark mode.--bg-body, cards on--bg-1. Inside a card, list group items and table cells show the canvas colour, while the card header, alert and pills track lose their tint and match the card. Dialogs, menus, popovers and toasts also paint--bg-body, so they take the canvas colour too.B can be repaired by re-pointing component token maps through the entrypoint. This compiles with alpha.1:
That still leaves card caps, alerts, the pills track and hover states on
--bg-1, the same colour as the card, so they have to move down a step as well. Every new component then needs the same check.I ran into this while building Dayframe (#43152). It uses B, which meant re-pointing ten component token maps: card, list group, table, nav, nav pills, dialog, menu, popover, toast and datepicker (
vite.config.ts).Questions:
"surface"in$theme-bgs(--bg-surface), defaulting tovar(--bg-body)? Card, list group, table, dialog, drawer, menu, popover and toast would read it instead of--bg-body. The default output would not change, and a tinted canvas would only need--bg-bodychanged, plus--bg-surfaceif the cards should differ from white.Related: #42657 (keep
$theme-bgsa linear scale) and #38733 (v5.3, where$body-bgalso sets component backgrounds).Snippet. Switch the OS or devtools colour scheme to see dark mode:
All reactions