})
}
@@ -709,6 +819,25 @@ mod tests {
assert_eq!(hue_of("sage"), None, "hue: preset id");
}
+ /// A stored `hue-95-v80` fills the hue and vividness sliders, and the Custom value is that id again.
+ #[test]
+ fn a_stored_hue_and_vividness_fill_the_sliders() {
+ let group = colour_group(Lang::En, true, "hue-95-v80", "hue-95-v80");
+ let accent = &group.accent_stripe;
+ assert_eq!((accent.hue, accent.vivid), (95, 80), "accent: sliders");
+ assert!(accent.custom, "accent: custom");
+ assert_eq!(
+ custom_id(accent.hue, accent.vivid),
+ "hue-95-v80",
+ "accent: value"
+ );
+ assert_eq!(
+ (group.base_stripe.hue, group.base_stripe.vivid),
+ (95, 80),
+ "base: sliders"
+ );
+ }
+
#[test]
fn labels_follow_the_page_language() {
assert_eq!(theme_label(Lang::En, "dark"), "Dark");
diff --git a/crates/forge-web/tests/e2e/ui_prefs_e2e.rs b/crates/forge-web/tests/e2e/ui_prefs_e2e.rs
index ca58fb3..afcc2e7 100644
--- a/crates/forge-web/tests/e2e/ui_prefs_e2e.rs
+++ b/crates/forge-web/tests/e2e/ui_prefs_e2e.rs
@@ -308,8 +308,10 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() {
.await;
assert_eq!(saved.status, 303, "save: {}", saved.body);
let page = env.http.get("/settings/appearance", Some(&session)).await;
+ // The Custom radio carries the hue at the default vividness; the stored id stays `hue-200`.
+ let checked = ["hue-200-v50", "gold", "spark", "dusk"].map(str::to_owned);
+ assert_eq!(checked_colours(&page.body), checked.map(Some));
let chosen = ["hue-200", "gold", "spark", "dusk"].map(str::to_owned);
- assert_eq!(checked_colours(&page.body), chosen.clone().map(Some));
assert_eq!(html_colours(&page.body), chosen.map(Some));
// The newest accents and backgrounds save and show the same way.
diff --git a/style/main.scss b/style/main.scss
index 5f46801..515e96b 100644
--- a/style/main.scss
+++ b/style/main.scss
@@ -2504,28 +2504,61 @@ code {
min-width: 0;
}
-// The hue stripe: a range input whose track is a rainbow, with a round knob. The background stripe
-// is a pale, low-saturation band so it reads as a tint. nav.js sets --hue on the row: the knob and the
-// Custom swatch take their colour from it.
+// Each row's colour is drawn with oklch() from custom properties on the row. nav.js sets --hue (the
+// hue) and --v (the vividness, 0..1) on the row; the panel sets the lightness, and the kind of row
+// sets the chroma range. The background rows are drawn a little stronger than their real tint, so
+// the hue shows on a pale page. The knob and the Custom swatch take the same colour as the track.
[data-colour-row] {
--hue: 0;
+ --v: 0.5;
+ --c-min: 0.03;
+ --c-span: 0.16;
+ --track-l: 0.75;
+ --track-c: calc(var(--c-min) + var(--c-span) * var(--v));
+}
+
+[data-colour-row][data-kind="base"] {
+ --v: 0.3;
+ --c-min: 0.02;
+ --c-span: 0.06;
+ --track-l: 0.8;
+}
+
+[data-colour-panel="light"] [data-colour-row][data-kind="accent"] {
+ --track-l: 0.52;
}
.hue-row {
- display: flex;
- align-items: center;
- gap: 12px;
+ display: grid;
+ grid-template-columns: 4.5rem minmax(0, 1fr);
+ align-items: start;
+ gap: 8px 12px;
min-width: 0;
- // The Custom choice takes the width of one preset, so the stripe lines up with the presets' row.
+ // The Custom choice takes the width of one preset, so the sliders line up beside the presets.
> .colour-choice {
- flex: none;
width: 4.5rem;
}
}
-.hue-stripe {
- --track: linear-gradient(to right, hsl(0 85% 55%), hsl(60 90% 52%), hsl(120 65% 45%), hsl(180 70% 42%), hsl(240 80% 58%), hsl(300 75% 55%), hsl(360 85% 55%));
+// The sliders stack: the hue slider full width, then the vividness slider and the hex box on one line,
+// then a note that shows only when a typed hex was lightened to keep text readable.
+.tune {
+ display: grid;
+ gap: 6px;
+ min-width: 0;
+}
+
+.tune-row {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ min-width: 0;
+}
+
+// The hue and vividness tracks and knobs. Both are drawn from the row's custom properties.
+.hue-stripe,
+.vivid-stripe {
-webkit-appearance: none;
appearance: none;
flex: 1 1 auto;
@@ -2538,10 +2571,6 @@ code {
background: transparent;
cursor: pointer;
- &.hue-stripe-base {
- --track: linear-gradient(to right, hsl(0 45% 84%), hsl(60 45% 84%), hsl(120 35% 81%), hsl(180 35% 81%), hsl(240 40% 85%), hsl(300 35% 83%), hsl(360 45% 84%));
- }
-
&::-webkit-slider-runnable-track {
height: 14px;
border-radius: var(--radius-full);
@@ -2563,7 +2592,7 @@ code {
margin-top: -4px;
border-radius: 50%;
border: 3px solid var(--surface);
- background: hsl(var(--hue) 80% 50%);
+ background: oklch(var(--track-l) var(--track-c) var(--hue));
box-shadow: 0 0 0 1px var(--border-strong);
}
@@ -2573,32 +2602,59 @@ code {
height: 22px;
border-radius: 50%;
border: 3px solid var(--surface);
- background: hsl(var(--hue) 80% 50%);
+ background: oklch(var(--track-l) var(--track-c) var(--hue));
box-shadow: 0 0 0 1px var(--border-strong);
}
- &.hue-stripe-base::-webkit-slider-thumb {
- background: hsl(var(--hue) 40% 62%);
- }
-
- &.hue-stripe-base::-moz-range-thumb {
- background: hsl(var(--hue) 40% 62%);
- }
-
&:focus-visible {
outline: 2px solid var(--focus);
outline-offset: 3px;
}
}
-// The Custom swatch shows the hue the stripe is on. The accent one is saturated, the background
-// one pale, like the presets beside it.
-.hue-swatch {
- background: hsl(var(--hue) 75% 50%);
+// The hue track: the row's lightness and chroma, every 30 degrees around the wheel.
+.hue-stripe {
+ --track: linear-gradient(to right, oklch(var(--track-l) var(--track-c) 0), oklch(var(--track-l) var(--track-c) 30), oklch(var(--track-l) var(--track-c) 60), oklch(var(--track-l) var(--track-c) 90), oklch(var(--track-l) var(--track-c) 120), oklch(var(--track-l) var(--track-c) 150), oklch(var(--track-l) var(--track-c) 180), oklch(var(--track-l) var(--track-c) 210), oklch(var(--track-l) var(--track-c) 240), oklch(var(--track-l) var(--track-c) 270), oklch(var(--track-l) var(--track-c) 300), oklch(var(--track-l) var(--track-c) 330), oklch(var(--track-l) var(--track-c) 360));
}
-.base-swatch.hue-swatch {
- background: hsl(var(--hue) 40% 82%);
+// The vividness track: from no colour to full, at the current hue.
+.vivid-stripe {
+ --track: linear-gradient(to right, oklch(var(--track-l) var(--c-min) var(--hue)), oklch(var(--track-l) calc(var(--c-min) + var(--c-span)) var(--hue)));
+}
+
+// The hex box. A typed value that is not a colour is outlined in red and keeps the last good colour.
+.hex-input {
+ flex: none;
+ box-sizing: border-box;
+ width: 96px;
+ height: 28px;
+ padding: 2px 8px;
+ border: 1px solid var(--border-strong);
+ border-radius: var(--radius-sm);
+ background: var(--surface);
+ color: var(--text);
+ font-family: var(--mono);
+ font-size: 0.8125rem;
+
+ &[aria-invalid="true"] {
+ outline: 2px solid var(--danger);
+ outline-offset: 0;
+ }
+}
+
+// The lightness note is empty, and so hidden, unless a typed colour was lightened.
+.hex-note {
+ font-size: 0.75rem;
+ color: var(--muted);
+
+ &:empty {
+ display: none;
+ }
+}
+
+// The Custom swatch shows the colour its row's sliders stand for.
+.hue-swatch {
+ background: oklch(var(--track-l) var(--track-c) var(--hue));
}
.colour-group {