Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ rows: readonly T[]
center?: boolean
children?: JSX.Element
horizontal?: boolean
material?: Material
vertical?: boolean
```

Expand Down
24 changes: 13 additions & 11 deletions src/components/_shared/material.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
* than tidy. An undefined custom property does not fall back to its initial
* value: CSS drops the whole declaration. Three of these used to be read bare,
* so a theme that defined twenty-eight of the thirty-one glass tokens got a
* surface with no background at all rather than a plainer one. The two shipped
* themes both use `white` for the three colours, so that is what the fallbacks
* say. `src/styles/glass.ts` derives the rest from `blur`, `refraction` and
* `depth`.
* surface with no background at all rather than a plainer one. The fallbacks
* tint glass with the theme itself: the film is `base-100` and the border
* `base-content`, so glass is the page's own surface made translucent, in any
* theme, rather than a white film laid over it. Highlights stay white, because
* they are light catching an edge. `src/styles/glass.ts` derives the rest from
* `blur`, `refraction` and `depth`.
*/

@layer components {
Expand Down Expand Up @@ -71,12 +73,12 @@
:root.glass [data-material="solid"]:not([data-material-explicit]) {
background-color: color-mix(
in oklab,
var(--glass-background-color, white),
var(--glass-background-color, var(--color-base-100)),
transparent calc(100% - var(--glass-background-opacity, 55%))
);
border-color: color-mix(
in oklab,
var(--glass-border-color, white),
var(--glass-border-color, var(--color-base-content)),
transparent calc(100% - var(--glass-border-opacity, 12%))
);
}
Expand Down Expand Up @@ -110,12 +112,12 @@
[data-material="glass"] {
background-color: color-mix(
in oklab,
var(--glass-background-color, white),
var(--glass-background-color, var(--color-base-100)),
transparent calc(100% - var(--glass-background-opacity, 55%))
);
border-color: color-mix(
in oklab,
var(--glass-border-color, white),
var(--glass-border-color, var(--color-base-content)),
transparent calc(100% - var(--glass-border-opacity, 12%))
);
-webkit-backdrop-filter: blur(var(--glass-blur, 9px))
Expand Down Expand Up @@ -288,7 +290,7 @@
[data-control-material="glass"] {
background-color: color-mix(
in oklab,
var(--glass-background-color, white),
var(--glass-background-color, var(--color-base-100)),
transparent
calc(
100% -
Expand All @@ -311,7 +313,7 @@
[data-material="glass"] {
background-color: color-mix(
in oklab,
var(--glass-background-color, white),
var(--glass-background-color, var(--color-base-100)),
transparent calc(100% - var(--glass-fallback-background-opacity, 78%))
);
}
Expand All @@ -321,7 +323,7 @@
[data-material="glass"] {
background-color: color-mix(
in oklab,
var(--glass-background-color, white),
var(--glass-background-color, var(--color-base-100)),
transparent calc(100% - var(--glass-fallback-background-opacity, 78%))
);
-webkit-backdrop-filter: none;
Expand Down
9 changes: 5 additions & 4 deletions src/components/card/Card.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,20 @@
initial value: CSS drops the whole declaration. Three of these were read
bare, so a theme that defined twenty-eight of the thirty-one glass tokens
got a card with no background at all rather than a plainer one, and the
only themes that defined all thirty-one were the two shipped here. Both
use `white` for the three colours, so that is what the fallbacks say.
only themes that defined all thirty-one were the two shipped here. The
film falls back to `base-100` and the border to `base-content`, the same
theme colours `_shared/material.css` uses.

`src/styles/glass.ts` derives the other twenty-five from three numbers. */
.card--material-glass {
--card-bg: color-mix(
in oklab,
var(--glass-background-color, white),
var(--glass-background-color, var(--color-base-100)),
transparent calc(100% - var(--glass-background-opacity, 55%))
);
--card-border: color-mix(
in oklab,
var(--glass-border-color, white),
var(--glass-border-color, var(--color-base-content)),
transparent calc(100% - var(--glass-border-opacity, 12%))
);
-webkit-backdrop-filter: blur(
Expand Down
18 changes: 16 additions & 2 deletions src/components/footer/Footer.layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import "./footer.css";
import type { JSX } from "@solidjs/web";
import {type ParentComponent, omit} from "solid-js";
import { twMerge } from "../../lib/twMerge";
import type { UIBaseProps } from "../vocabulary";
import "../_shared/material.css";
import type { Material, UIBaseProps } from "../vocabulary";
import { FooterTitle } from "./FooterTitle.generated";
import { CLASSES } from "./Footer.recipe";
import type { Layout } from "../../lib/layouts";
Expand All @@ -13,10 +14,21 @@ export type FooterProps = UIBaseProps & {
center?: boolean;
horizontal?: boolean;
vertical?: boolean;
/** What the footer is made of. Unset keeps the footer's own background. */
material?: Material;
};

const Footer: Layout<typeof componentRecipe, FooterProps> = () => {
const others = omit(props, "children", "class", "dataTheme", "center", "horizontal", "vertical");
const others = omit(
props,
"children",
"class",
"dataTheme",
"center",
"horizontal",
"vertical",
"material",
);

const classes = () =>
twMerge(
Expand All @@ -31,6 +43,8 @@ const Footer: Layout<typeof componentRecipe, FooterProps> = () => {
<footer
{...others}
data-theme={props.dataTheme}
data-material={props.material}
data-material-explicit={props.material ? "" : undefined}
{...{ class: classes() }}
>
{props.children}
Expand Down
6 changes: 3 additions & 3 deletions src/components/glow-card/GlowCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
border-radius: inherit;
background: color-mix(
in oklab,
var(--glass-background-color, white) var(--glass-background-opacity, 38%),
var(--glass-background-color, var(--color-base-100)) var(--glass-background-opacity, 38%),
transparent
);
border: var(--border, 1px) solid
color-mix(
in oklab,
var(--glass-border-color, white) var(--glass-border-opacity, 30%),
var(--glass-border-color, var(--color-base-content)) var(--glass-border-opacity, 30%),
transparent
);
backdrop-filter: blur(var(--glow-card-blur))
Expand Down Expand Up @@ -87,7 +87,7 @@
.glow-card {
background: color-mix(
in oklab,
var(--glass-background-color, white)
var(--glass-background-color, var(--color-base-100))
var(--glass-fallback-background-opacity, 78%),
transparent
);
Expand Down
25 changes: 16 additions & 9 deletions src/components/navbar/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,48 +64,55 @@
padding: 0.5rem 1rem;
}

.navbar__row--ghost {
.navbar__row--ghost:not([data-material="glass"]) {
background-color: var(--color-base-100);
color: var(--color-base-content);
}

.navbar__row--flavor-neutral {
.navbar__row--flavor-neutral:not([data-material="glass"]) {
background-color: var(--color-neutral);
color: var(--color-neutral-content);
}

.navbar__row--flavor-primary {
.navbar__row--flavor-primary:not([data-material="glass"]) {
background-color: var(--color-primary);
color: var(--color-primary-content);
}

.navbar__row--flavor-secondary {
.navbar__row--flavor-secondary:not([data-material="glass"]) {
background-color: var(--color-secondary);
color: var(--color-secondary-content);
}

.navbar__row--flavor-accent {
.navbar__row--flavor-accent:not([data-material="glass"]) {
background-color: var(--color-accent);
color: var(--color-accent-content);
}

.navbar__row--flavor-destructive {
.navbar__row--flavor-destructive:not([data-material="glass"]) {
background-color: var(--color-error);
color: var(--color-error-foreground);
}

.navbar__row--flavor-success {
.navbar__row--flavor-success:not([data-material="glass"]) {
background-color: var(--color-success);
color: var(--color-success-foreground);
}

.navbar__row--flavor-warning {
.navbar__row--flavor-warning:not([data-material="glass"]) {
background-color: var(--color-warning);
color: var(--color-warning-foreground);
}

.navbar__row--flavor-info {
.navbar__row--flavor-info:not([data-material="glass"]) {
background-color: var(--color-info);
color: var(--color-info-content);
}

/* A glass row is the theme's surface made translucent, so a flavour's fill
would hide the glass: the film comes from `_shared/material.css`, and the
text takes the surface's colour rather than the flavour's. */
.navbar__row[data-material="glass"] {
color: var(--color-base-content);
}
}
8 changes: 7 additions & 1 deletion src/components/navbar/NavbarRow.layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {omit, createMemo, children as resolveChildren} from "solid-js";
import type { JSX } from "@solidjs/web";
import { twMerge } from "../../lib/twMerge";
import type { UIBaseProps, Flavor, Variant } from "../vocabulary";
import "../_shared/material.css";
import type { UIBaseProps, Flavor, Material, Variant } from "../vocabulary";
import type { ComponentColor } from "../types";
import { CLASSES } from "./Navbar.recipe";
import type { Layout } from "../../lib/layouts";
Expand All @@ -14,6 +15,8 @@ export type NavbarRowProps = JSX.HTMLAttributes<HTMLDivElement> &
flavor?: Flavor;
/** Ghost is transparent chrome. It used to be a colour named `ghost`. */
variant?: Extract<Variant, "solid" | "ghost">;
/** What the row is made of. Unset keeps the row's own background. */
material?: Material;
};

const NavbarRow: Layout<typeof componentRecipe, NavbarRowProps> = () => {
Expand All @@ -27,6 +30,7 @@ const NavbarRow: Layout<typeof componentRecipe, NavbarRowProps> = () => {
"class",
"style",
"dataTheme",
"material",
);

const resolvedChildren = resolveChildren(() => props.children);
Expand All @@ -52,6 +56,8 @@ const NavbarRow: Layout<typeof componentRecipe, NavbarRowProps> = () => {
{...{ class: classes() }}
style={props.style}
data-theme={props.dataTheme}
data-material={props.material}
data-material-explicit={props.material ? "" : undefined}
{...others}
>
{resolvedChildren()}
Expand Down
22 changes: 9 additions & 13 deletions src/styles/glass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,17 @@ export function resolveGlassTokens(
const controlTint = v.controlTint;

/*
* Dark mode's film has to be a film, not a rounding error.
* The film is the theme's own `base-100`, so both modes take one curve.
*
* This was `7 * rv`, so the entire refraction range moved the surface from
* 0% to 7% while light mode spanned 18% to 48%. Measured across the whole
* slider, dark mode's largest step was under two points of opacity, which is
* below what anyone can see on a near-black desk: the axis read as broken
* rather than as subtle, and the consuming app worked around it by
* overriding this token from a slider of its own.
*
* Dark still lands lower than light, and deliberately - a light film on a
* dark surface reads much faster than a dark film on a light one, so parity
* in numbers would not be parity in appearance. 26% at the top is enough for
* the surface to declare itself while leaving the text ladder its contrast.
* Dark used to land lower (4% to 26%) because its film was white, and a
* light film on a dark surface reads much faster than a dark one. Tinted
* with the theme's surface instead, the film is dark on dark: at 4% to 26%
* of it the panel all but vanished, and at the white film's opacities the
* panel read as milky rather than as glass, which is what sites overrode
* this token to escape. 18% to 48% of the theme's own surface is the range
* a translucent header on the same backdrop already sits in.
*/
const background = light ? (zero ? 0 : 18 + 30 * rv) : zero ? 0 : 4 + 22 * rv;
const background = zero ? 0 : 18 + 30 * rv;
const border = light ? (zero ? 0 : 18 + 18 * rs) : 26 * rs;
const highlight = light ? (zero ? 0 : 22 + 26 * rs) : 24 * rs;
const bottomHighlight = light
Expand Down
6 changes: 3 additions & 3 deletions src/styles/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@
--noise: 1;

/* Glass surface tokens */
--glass-background-color: white;
--glass-background-opacity: 0.96%;
--glass-border-color: white;
--glass-background-color: var(--color-base-100);
--glass-background-opacity: 41.55%;
--glass-border-color: var(--color-base-content);
--glass-border-opacity: 30%;
--glass-highlight-color: white;
--glass-highlight-opacity: 6.4%;
Expand Down
2 changes: 1 addition & 1 deletion src/styles/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
--noise: 1;

/* Glass surface tokens */
--glass-background-color: white;
--glass-background-color: var(--color-base-100);
--glass-background-opacity: 0.96%;
--glass-border-color: white;
--glass-border-opacity: 30%;
Expand Down
Loading