Appearance colours are a few presets plus a hue stripe, in light and dark tabs
Browse files at this commit3f4e1ca0982b0840ac0ac97c633be2e053e9eaf1Parent: cd71b21- feat
- appearance colours are a few presets plus a hue stripe, in light and dark tabs
5 changed files +453 -106
- crates/forge-web/assets/nav.js +101 -0
- crates/forge-web/src/i18n/misc.rs +16 -12
- crates/forge-web/src/pages/settings_appearance.rs +200 -46
- crates/forge-web/tests/ui_prefs_e2e.rs +21 -18
- style/main.scss +115 -30
crates/forge-web/assets/nav.jsmodified+101 -0
| @@ -502,6 +502,8 @@ | ||
| 502 | 502 | var i = pair.indexOf('='); |
| 503 | 503 | if (i < 0) { return; } |
| 504 | 504 | var name = pair.slice(0, i), value = pair.slice(i + 1); |
| 505 | + // The custom colour sheet's href, or empty when no colour is a custom hue. | |
| 506 | + if (name === 'custom_css') { setCustomCss(value); return; } | |
| 505 | 507 | if (name.indexOf('data-') !== 0) { return; } |
| 506 | 508 | if (value) { root.setAttribute(name, value); } else { root.removeAttribute(name); } |
| 507 | 509 | }); |
| @@ -738,6 +740,52 @@ | ||
| 738 | 740 | // The attributes match what the shell renders: theme `auto` has no data-theme, `dark` is dark, else light. |
| 739 | 741 | var PREVIEW_ATTR = { accent_light: 'data-accent-light', accent_dark: 'data-accent-dark', base_light: 'data-base-light', base_dark: 'data-base-dark', sidebar_side: 'data-sidebar' }; |
| 740 | 742 | |
| 743 | + // The custom stylesheet sets the colours of the hue choices (`hue-N`). Its link follows the four | |
| 744 | + // colour attributes on <html>: it is added when one of them is a hue, its href is kept in step, | |
| 745 | + // and it is removed when none is. | |
| 746 | + // An empty href removes the link. The server sends the href in the live payload (`custom_css`). | |
| 747 | + function setCustomCss(href) { | |
| 748 | + var link = document.head.querySelector('link[rel="stylesheet"][href^="/theme/custom.css"]'); | |
| 749 | + if (!href) { | |
| 750 | + if (link) { link.remove(); } | |
| 751 | + return; | |
| 752 | + } | |
| 753 | + if (!link) { | |
| 754 | + link = document.createElement('link'); | |
| 755 | + link.rel = 'stylesheet'; | |
| 756 | + document.head.appendChild(link); | |
| 757 | + } | |
| 758 | + if (link.getAttribute('href') !== href) { link.setAttribute('href', href); } | |
| 759 | + } | |
| 760 | + | |
| 761 | + // Builds the custom sheet's href from the four colour attributes on <html> while a drag or a | |
| 762 | + // preset pick is shown before the save returns. The server builds the same href on the next load. | |
| 763 | + function syncCustomCss() { | |
| 764 | + var slots = ['data-accent-light', 'data-accent-dark', 'data-base-light', 'data-base-dark']; | |
| 765 | + var vals = slots.map(function (name) { return root.getAttribute(name) || ''; }); | |
| 766 | + var custom = vals.some(function (v) { return /^hue-\d+$/.test(v); }); | |
| 767 | + if (!custom) { setCustomCss(''); return; } | |
| 768 | + setCustomCss('/theme/custom.css?al=' + encodeURIComponent(vals[0]) + '&ad=' + encodeURIComponent(vals[1]) + | |
| 769 | + '&bl=' + encodeURIComponent(vals[2]) + '&bd=' + encodeURIComponent(vals[3])); | |
| 770 | + } | |
| 771 | + | |
| 772 | + // A drag moves the stylesheet at most once a frame, however many input events it sends. | |
| 773 | + var previewFrame = 0; | |
| 774 | + function previewLater() { | |
| 775 | + if (previewFrame) { return; } | |
| 776 | + previewFrame = requestAnimationFrame(function () { previewFrame = 0; syncCustomCss(); }); | |
| 777 | + } | |
| 778 | + | |
| 779 | + // Moves a row's stripe knob to a hue, and makes the row's Custom choice that hue (the value a save posts). | |
| 780 | + // The hue is also set on the row as `--hue`, which the stripe's knob and the Custom swatch read. | |
| 781 | + function setKnob(row, hue) { | |
| 782 | + var range = row.querySelector('input[data-hue-stripe]'); | |
| 783 | + var custom = row.querySelector('input[data-hue-custom]'); | |
| 784 | + if (range) { range.value = String(hue); } | |
| 785 | + row.style.setProperty('--hue', String(hue)); | |
| 786 | + if (custom) { custom.value = 'hue-' + hue; } | |
| 787 | + } | |
| 788 | + | |
| 741 | 789 | document.addEventListener('change', function (e) { |
| 742 | 790 | var el = e.target; |
| 743 | 791 | if (!el || !el.form || !el.form.hasAttribute('data-appearance')) { return; } |
| @@ -746,11 +794,63 @@ | ||
| 746 | 794 | else { root.setAttribute('data-theme', el.value === 'dark' ? 'dark' : 'light'); } |
| 747 | 795 | return; |
| 748 | 796 | } |
| 797 | + if (el.type === 'radio' && el.hasAttribute('data-colour-tab')) { | |
| 798 | + var group = el.closest('[data-colour-group]'); | |
| 799 | + if (group) { group.setAttribute('data-tab', el.value); } | |
| 800 | + return; | |
| 801 | + } | |
| 749 | 802 | if (el.type === 'radio' && Object.prototype.hasOwnProperty.call(PREVIEW_ATTR, el.name)) { |
| 750 | 803 | root.setAttribute(PREVIEW_ATTR[el.name], el.value); |
| 804 | + // A preset moves its row's knob to the preset's hue, without choosing Custom. | |
| 805 | + var row = el.closest('[data-colour-row]'); | |
| 806 | + var hue = el.getAttribute('data-hue'); | |
| 807 | + if (row && hue) { setKnob(row, hue); } | |
| 808 | + syncCustomCss(); | |
| 809 | + } | |
| 810 | + }, false); | |
| 811 | + | |
| 812 | + // Dragging a stripe selects its Custom choice and shows the hue on <html> while the drag lasts. | |
| 813 | + // The save waits for the release (the change event), which the autosubmit handler sends. | |
| 814 | + document.addEventListener('input', function (e) { | |
| 815 | + var el = e.target; | |
| 816 | + if (!el || el.type !== 'range' || !el.hasAttribute('data-hue-stripe') || !el.form || !el.form.hasAttribute('data-appearance')) { return; } | |
| 817 | + var row = el.closest('[data-colour-row]'); | |
| 818 | + var custom = row ? row.querySelector('input[data-hue-custom]') : null; | |
| 819 | + if (!custom) { return; } | |
| 820 | + setKnob(row, el.value); | |
| 821 | + custom.checked = true; | |
| 822 | + if (Object.prototype.hasOwnProperty.call(PREVIEW_ATTR, custom.name)) { | |
| 823 | + root.setAttribute(PREVIEW_ATTR[custom.name], custom.value); | |
| 751 | 824 | } |
| 825 | + previewLater(); | |
| 752 | 826 | }, false); |
| 753 | 827 | |
| 828 | + // The theme the viewer sees: `dark` or `light` on <html>, else the system's setting. | |
| 829 | + function effectiveDark() { | |
| 830 | + var t = root.getAttribute('data-theme'); | |
| 831 | + if (t === 'dark') { return true; } | |
| 832 | + if (t === 'light') { return false; } | |
| 833 | + return !!(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches); | |
| 834 | + } | |
| 835 | + | |
| 836 | + // The colour panel opens on the theme the viewer sees. A tab the viewer picked is kept across a | |
| 837 | + // swap, because the swap restores it as a changed field. Each panel is set up once; after that its | |
| 838 | + // shown panel follows its tab radios. Called on every page change (see `enhance`). | |
| 839 | + function enhanceColours() { | |
| 840 | + document.querySelectorAll('[data-colour-group]').forEach(function (group) { | |
| 841 | + var tabs = group.querySelectorAll('input[data-colour-tab]'); | |
| 842 | + if (!group.__colourTab) { | |
| 843 | + group.__colourTab = true; | |
| 844 | + var moved = Array.prototype.some.call(tabs, function (r) { return r.checked !== r.defaultChecked; }); | |
| 845 | + if (!moved) { | |
| 846 | + Array.prototype.forEach.call(tabs, function (r) { r.checked = r.value === (effectiveDark() ? 'dark' : 'light'); }); | |
| 847 | + } | |
| 848 | + } | |
| 849 | + var on = group.querySelector('input[data-colour-tab]:checked'); | |
| 850 | + if (on) { group.setAttribute('data-tab', on.value); } | |
| 851 | + }); | |
| 852 | + } | |
| 853 | + | |
| 754 | 854 | // A filtered view asked for in place: the URL is replaced (no history entry per change), fields |
| 755 | 855 | // and caret come through the swap, and the scroll stays put. |
| 756 | 856 | // Live unread count. The bell is re-rendered by every swap, so it is looked up on each update. One |
| @@ -1894,6 +1994,7 @@ | ||
| 1894 | 1994 | // ---- toolbar and upload ---- |
| 1895 | 1995 | |
| 1896 | 1996 | function enhance() { |
| 1997 | + enhanceColours(); | |
| 1897 | 1998 | document.querySelectorAll('textarea').forEach(function (ta) { |
| 1898 | 1999 | if (ta.__md || !eligible(ta)) { return; } |
| 1899 | 2000 | ta.__md = true; |
crates/forge-web/src/i18n/misc.rsmodified+16 -12
| @@ -25,10 +25,11 @@ pub enum K { | ||
| 25 | 25 | SwitchToMatchSystem, |
| 26 | 26 | ChooseTheme, |
| 27 | 27 | ChooseLanguage, |
| 28 | - AccentLabel, | |
| 29 | 28 | ChooseAccent, |
| 30 | - LightColours, | |
| 31 | - DarkColours, | |
| 29 | + ColoursLabel, | |
| 30 | + AccentRowLabel, | |
| 31 | + CustomLabel, | |
| 32 | + HueLabel, | |
| 32 | 33 | BackgroundLabel, |
| 33 | 34 | ChooseBase, |
| 34 | 35 | // Appearance: which side the shell sidebar sits on. |
| @@ -175,10 +176,11 @@ const ALL: &[K] = &[ | ||
| 175 | 176 | K::SwitchToMatchSystem, |
| 176 | 177 | K::ChooseTheme, |
| 177 | 178 | K::ChooseLanguage, |
| 178 | - K::AccentLabel, | |
| 179 | 179 | K::ChooseAccent, |
| 180 | - K::LightColours, | |
| 181 | - K::DarkColours, | |
| 180 | + K::ColoursLabel, | |
| 181 | + K::AccentRowLabel, | |
| 182 | + K::CustomLabel, | |
| 183 | + K::HueLabel, | |
| 182 | 184 | K::BackgroundLabel, |
| 183 | 185 | K::ChooseBase, |
| 184 | 186 | K::SidebarLabel, |
| @@ -330,14 +332,16 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 330 | 332 | (ChooseTheme, Tr) => "Listeden bir tema seçin.", |
| 331 | 333 | (ChooseLanguage, En) => "Choose a language from the list.", |
| 332 | 334 | (ChooseLanguage, Tr) => "Listeden bir dil seçin.", |
| 333 | - (AccentLabel, En) => "Accent colour", | |
| 334 | - (AccentLabel, Tr) => "Vurgu rengi", | |
| 335 | 335 | (ChooseAccent, En) => "Choose an accent colour from the list.", |
| 336 | 336 | (ChooseAccent, Tr) => "Listeden bir vurgu rengi seçin.", |
| 337 | - (LightColours, En) => "Light theme", | |
| 338 | - (LightColours, Tr) => "Açık tema", | |
| 339 | - (DarkColours, En) => "Dark theme", | |
| 340 | - (DarkColours, Tr) => "Koyu tema", | |
| 337 | + (ColoursLabel, En) => "Colours", | |
| 338 | + (ColoursLabel, Tr) => "Renkler", | |
| 339 | + (AccentRowLabel, En) => "Accent", | |
| 340 | + (AccentRowLabel, Tr) => "Vurgu", | |
| 341 | + (CustomLabel, En) => "Custom", | |
| 342 | + (CustomLabel, Tr) => "Özel", | |
| 343 | + (HueLabel, En) => "Hue", | |
| 344 | + (HueLabel, Tr) => "Ton", | |
| 341 | 345 | (BackgroundLabel, En) => "Background", |
| 342 | 346 | (BackgroundLabel, Tr) => "Arka plan", |
| 343 | 347 | (ChooseBase, En) => "Choose a background from the list.", |
crates/forge-web/src/pages/settings_appearance.rsmodified+200 -46
| @@ -15,7 +15,7 @@ use topcoat::router::error::{SeeOther, see_other}; | ||
| 15 | 15 | use topcoat::router::{page, route}; |
| 16 | 16 | use topcoat::view::{View, component, view}; |
| 17 | 17 | |
| 18 | -use crate::accent; | |
| 18 | +use crate::accent::{self, hue_of, preset_accent_hue, preset_base_hue}; | |
| 19 | 19 | use crate::audit::{self, Actor, Target}; |
| 20 | 20 | use crate::auth::{require_csrf, require_user}; |
| 21 | 21 | use crate::i18n::accents::{accent_name, base_name}; |
| @@ -34,6 +34,9 @@ const THEME_CODES: &[&str] = &["auto", "light", "dark"]; | ||
| 34 | 34 | /// Sidebar sides, in display order. Must match `store::ui_prefs::SIDEBAR_SIDES`. |
| 35 | 35 | const SIDEBAR_CODES: &[&str] = &["left", "right"]; |
| 36 | 36 | |
| 37 | +/// The colour tabs, in display order: the light theme's colours, then the dark theme's. | |
| 38 | +const TAB_CODES: &[&str] = &["light", "dark"]; | |
| 39 | + | |
| 37 | 40 | /// Reads a field that is present as a string, even an empty one. The plain `Option<String>` |
| 38 | 41 | /// reading would turn an empty value into `None`, which is the same as a missing field. |
| 39 | 42 | fn present_string<'de, D: Deserializer<'de>>( |
| @@ -69,17 +72,29 @@ struct Choice { | ||
| 69 | 72 | value: &'static str, |
| 70 | 73 | label: &'static str, |
| 71 | 74 | selected: bool, |
| 75 | + /// The hue a preset moves the stripe knob to, as text; empty when the preset has none. | |
| 76 | + hue: String, | |
| 77 | +} | |
| 78 | + | |
| 79 | +/// Where a hue stripe's knob sits. `custom` says the stored choice is that hue, rather than a | |
| 80 | +/// preset whose hue the knob was moved to. | |
| 81 | +struct Stripe { | |
| 82 | + hue: u16, | |
| 83 | + custom: bool, | |
| 72 | 84 | } |
| 73 | 85 | |
| 74 | -/// The colour choices of one theme: its background and its accent colour. `dark` picks the | |
| 75 | -/// field names and the swatch attributes that belong to the dark theme. | |
| 86 | +/// The colour choices of one theme: a background and an accent, each a row of presets and a hue | |
| 87 | +/// stripe. `dark` picks the field names and the swatch attributes that belong to the dark theme. | |
| 76 | 88 | struct ColourGroup { |
| 77 | 89 | dark: bool, |
| 78 | - heading: &'static str, | |
| 79 | 90 | background: &'static str, |
| 80 | 91 | accent: &'static str, |
| 92 | + custom: &'static str, | |
| 93 | + hue: &'static str, | |
| 81 | 94 | bases: Vec<Choice>, |
| 82 | 95 | accents: Vec<Choice>, |
| 96 | + base_stripe: Stripe, | |
| 97 | + accent_stripe: Stripe, | |
| 83 | 98 | } |
| 84 | 99 | |
| 85 | 100 | struct AppearancePage { |
| @@ -87,6 +102,10 @@ struct AppearancePage { | ||
| 87 | 102 | csrf: String, |
| 88 | 103 | theme: Vec<Choice>, |
| 89 | 104 | language: Vec<Choice>, |
| 105 | + colours: &'static str, | |
| 106 | + /// The tab that opens first: the light or the dark colours. | |
| 107 | + tab: &'static str, | |
| 108 | + tabs: Vec<Choice>, | |
| 90 | 109 | light: ColourGroup, |
| 91 | 110 | dark: ColourGroup, |
| 92 | 111 | sidebar: Vec<Choice>, |
| @@ -134,52 +153,103 @@ fn choices( | ||
| 134 | 153 | value, |
| 135 | 154 | label: label(value), |
| 136 | 155 | selected: value == current, |
| 156 | + hue: String::new(), | |
| 137 | 157 | }) |
| 138 | 158 | .collect() |
| 139 | 159 | } |
| 140 | 160 | |
| 141 | -/// One theme's colour choices, with the stored (resolved) background and accent selected. | |
| 161 | +/// The label of a colour tab: the light or the dark theme. | |
| 162 | +fn tab_label(lang: Lang, code: &str) -> &'static str { | |
| 163 | + if code == "dark" { | |
| 164 | + g::t(lang, K::Dark) | |
| 165 | + } else { | |
| 166 | + g::t(lang, K::Light) | |
| 167 | + } | |
| 168 | +} | |
| 169 | + | |
| 170 | +/// Fills in the hue each preset moves the stripe knob to. | |
| 171 | +fn with_hues(mut list: Vec<Choice>, hue: fn(&str) -> Option<u16>) -> Vec<Choice> { | |
| 172 | + for choice in &mut list { | |
| 173 | + choice.hue = hue(choice.value).map(|h| h.to_string()).unwrap_or_default(); | |
| 174 | + } | |
| 175 | + list | |
| 176 | +} | |
| 177 | + | |
| 178 | +/// The id a row shows as selected. A custom hue stays as stored; a preset is resolved, so an id | |
| 179 | +/// that is no longer offered shows the default, as the page renders it on `<html>`. | |
| 180 | +fn shown<'a>(stored: &'a str, resolved: &'static str) -> &'a str { | |
| 181 | + if hue_of(stored).is_some() { | |
| 182 | + stored | |
| 183 | + } else { | |
| 184 | + resolved | |
| 185 | + } | |
| 186 | +} | |
| 187 | + | |
| 188 | +/// The stripe of one row. A stored custom hue puts the knob on it; a preset puts the knob on the | |
| 189 | +/// preset's hue, and nothing is selected as custom. | |
| 190 | +fn stripe(stored: &str, preset: Option<u16>) -> Stripe { | |
| 191 | + match hue_of(stored) { | |
| 192 | + Some(hue) => Stripe { hue, custom: true }, | |
| 193 | + None => Stripe { | |
| 194 | + hue: preset.unwrap_or(0), | |
| 195 | + custom: false, | |
| 196 | + }, | |
| 197 | + } | |
| 198 | +} | |
| 199 | + | |
| 200 | +/// One theme's colour choices, with the stored background and accent selected. | |
| 142 | 201 | fn colour_group(lang: Lang, dark: bool, base: &str, accent_id: &str) -> ColourGroup { |
| 143 | 202 | let base_codes: Vec<&'static str> = accent::base_ids().collect(); |
| 144 | 203 | let accent_codes: Vec<&'static str> = accent::ids().collect(); |
| 204 | + let base_shown = shown(base, accent::resolve_base(base).id); | |
| 205 | + let accent_shown = shown(accent_id, accent::resolve(accent_id).id); | |
| 145 | 206 | ColourGroup { |
| 146 | 207 | dark, |
| 147 | - heading: g::t( | |
| 148 | - lang, | |
| 149 | - if dark { | |
| 150 | - K::DarkColours | |
| 151 | - } else { | |
| 152 | - K::LightColours | |
| 153 | - }, | |
| 154 | - ), | |
| 155 | 208 | background: g::t(lang, K::BackgroundLabel), |
| 156 | - accent: g::t(lang, K::AccentLabel), | |
| 157 | - bases: choices(&base_codes, base, |id| base_name(lang, id)), | |
| 158 | - accents: choices(&accent_codes, accent_id, |id| accent_name(lang, id)), | |
| 209 | + accent: g::t(lang, K::AccentRowLabel), | |
| 210 | + custom: g::t(lang, K::CustomLabel), | |
| 211 | + hue: g::t(lang, K::HueLabel), | |
| 212 | + bases: with_hues( | |
| 213 | + choices(&base_codes, base_shown, |id| base_name(lang, id)), | |
| 214 | + preset_base_hue, | |
| 215 | + ), | |
| 216 | + accents: with_hues( | |
| 217 | + choices(&accent_codes, accent_shown, |id| accent_name(lang, id)), | |
| 218 | + preset_accent_hue, | |
| 219 | + ), | |
| 220 | + base_stripe: stripe(base, preset_base_hue(base_shown)), | |
| 221 | + accent_stripe: stripe(accent_id, preset_accent_hue(accent_shown)), | |
| 159 | 222 | } |
| 160 | 223 | } |
| 161 | 224 | |
| 225 | +/// One theme's panel: a Background row and an Accent row. Each row is its presets as round | |
| 226 | +/// radios, then a hue stripe whose Custom radio carries the `hue-N` value. | |
| 162 | 227 | #[component] |
| 163 | -async fn colour_group_fields(group: ColourGroup) -> Result<impl View> { | |
| 228 | +async fn colour_panel(group: ColourGroup) -> Result<impl View> { | |
| 164 | 229 | let ColourGroup { |
| 165 | 230 | dark, |
| 166 | - heading, | |
| 167 | 231 | background, |
| 168 | 232 | accent, |
| 233 | + custom, | |
| 234 | + hue, | |
| 169 | 235 | bases, |
| 170 | 236 | accents, |
| 237 | + base_stripe, | |
| 238 | + accent_stripe, | |
| 171 | 239 | } = group; |
| 172 | 240 | let base_field = if dark { "base_dark" } else { "base_light" }; |
| 173 | 241 | let accent_field = if dark { "accent_dark" } else { "accent_light" }; |
| 242 | + let panel = if dark { "dark" } else { "light" }; | |
| 243 | + let base_custom = format!("hue-{}", base_stripe.hue); | |
| 244 | + let accent_custom = format!("hue-{}", accent_stripe.hue); | |
| 174 | 245 | Ok(view! { |
| 175 | - <fieldset class="card colour-group"> | |
| 176 | - <legend>(heading)</legend> | |
| 177 | - <fieldset class="colour-picker"> | |
| 246 | + <div class="colour-panel" data-colour-panel=(panel)> | |
| 247 | + <fieldset class="colour-picker" data-colour-row="true"> | |
| 178 | 248 | <legend>(background)</legend> |
| 179 | 249 | <div class="colour-choices"> |
| 180 | 250 | for choice in bases.into_iter() { |
| 181 | 251 | <label class="colour-choice"> |
| 182 | - <input type="radio" name=(base_field) value=(choice.value) checked=(choice.selected) data-autosubmit="true"> | |
| 252 | + <input type="radio" name=(base_field) value=(choice.value) checked=(choice.selected) data-hue=(choice.hue.as_str()) data-autosubmit="true"> | |
| 183 | 253 | if dark { |
| 184 | 254 | <span class="base-swatch" data-base-dark-swatch=(choice.value) aria-hidden="true"></span> |
| 185 | 255 | } else { |
| @@ -189,13 +259,21 @@ async fn colour_group_fields(group: ColourGroup) -> Result<impl View> { | ||
| 189 | 259 | </label> |
| 190 | 260 | } |
| 191 | 261 | </div> |
| 262 | + <div class="hue-row"> | |
| 263 | + <label class="colour-choice"> | |
| 264 | + <input type="radio" name=(base_field) value=(base_custom.as_str()) checked=(base_stripe.custom) data-hue-custom="true" data-autosubmit="true"> | |
| 265 | + <span class="base-swatch hue-swatch" aria-hidden="true"></span> | |
| 266 | + <span>(custom)</span> | |
| 267 | + </label> | |
| 268 | + <input type="range" class="hue-stripe hue-stripe-base" min="0" max="359" value=(base_stripe.hue) aria-label=(hue) data-hue-stripe="true" data-autosubmit="true"> | |
| 269 | + </div> | |
| 192 | 270 | </fieldset> |
| 193 | - <fieldset class="colour-picker"> | |
| 271 | + <fieldset class="colour-picker" data-colour-row="true"> | |
| 194 | 272 | <legend>(accent)</legend> |
| 195 | 273 | <div class="colour-choices"> |
| 196 | 274 | for choice in accents.into_iter() { |
| 197 | 275 | <label class="colour-choice"> |
| 198 | - <input type="radio" name=(accent_field) value=(choice.value) checked=(choice.selected) data-autosubmit="true"> | |
| 276 | + <input type="radio" name=(accent_field) value=(choice.value) checked=(choice.selected) data-hue=(choice.hue.as_str()) data-autosubmit="true"> | |
| 199 | 277 | if dark { |
| 200 | 278 | <span class="accent-swatch" data-accent-dark-swatch=(choice.value) aria-hidden="true"></span> |
| 201 | 279 | } else { |
| @@ -205,8 +283,16 @@ async fn colour_group_fields(group: ColourGroup) -> Result<impl View> { | ||
| 205 | 283 | </label> |
| 206 | 284 | } |
| 207 | 285 | </div> |
| 286 | + <div class="hue-row"> | |
| 287 | + <label class="colour-choice"> | |
| 288 | + <input type="radio" name=(accent_field) value=(accent_custom.as_str()) checked=(accent_stripe.custom) data-hue-custom="true" data-autosubmit="true"> | |
| 289 | + <span class="accent-swatch hue-swatch" aria-hidden="true"></span> | |
| 290 | + <span>(custom)</span> | |
| 291 | + </label> | |
| 292 | + <input type="range" class="hue-stripe" min="0" max="359" value=(accent_stripe.hue) aria-label=(hue) data-hue-stripe="true" data-autosubmit="true"> | |
| 293 | + </div> | |
| 208 | 294 | </fieldset> |
| 209 | - </fieldset> | |
| 295 | + </div> | |
| 210 | 296 | }) |
| 211 | 297 | } |
| 212 | 298 | |
| @@ -217,6 +303,9 @@ async fn appearance_body(page: AppearancePage) -> Result<impl View> { | ||
| 217 | 303 | csrf, |
| 218 | 304 | theme, |
| 219 | 305 | language, |
| 306 | + colours, | |
| 307 | + tab, | |
| 308 | + tabs, | |
| 220 | 309 | light, |
| 221 | 310 | dark, |
| 222 | 311 | sidebar, |
| @@ -258,10 +347,19 @@ async fn appearance_body(page: AppearancePage) -> Result<impl View> { | ||
| 258 | 347 | </div> |
| 259 | 348 | </fieldset> |
| 260 | 349 | </div> |
| 261 | - <div class="appearance-columns"> | |
| 262 | - colour_group_fields(group: light) | |
| 263 | - colour_group_fields(group: dark) | |
| 264 | - </div> | |
| 350 | + <fieldset class="card colour-group" data-colour-group="true" data-tab=(tab)> | |
| 351 | + <legend>(colours)</legend> | |
| 352 | + <div class="segmented snippet-segmented colour-tabs" role="group"> | |
| 353 | + for choice in tabs.into_iter() { | |
| 354 | + <label class="segment"> | |
| 355 | + <input type="radio" name="colour_tab" value=(choice.value) checked=(choice.selected) data-colour-tab=(choice.value)> | |
| 356 | + <span>(choice.label)</span> | |
| 357 | + </label> | |
| 358 | + } | |
| 359 | + </div> | |
| 360 | + colour_panel(group: light) | |
| 361 | + colour_panel(group: dark) | |
| 362 | + </fieldset> | |
| 265 | 363 | </form> |
| 266 | 364 | </div> |
| 267 | 365 | }) |
| @@ -318,6 +416,13 @@ pub fn sidebar_stored(stored: &str) -> &'static str { | ||
| 318 | 416 | /// stored id is no longer offered, which is what the page renders on `<html>` too. |
| 319 | 417 | fn page_for(viewer: &(User, Session), lang: Lang) -> AppearancePage { |
| 320 | 418 | let user = &viewer.0; |
| 419 | + // The tab that opens first is the dark colours for a dark theme. The page script moves it to | |
| 420 | + // the one the viewer sees when the theme follows the system. | |
| 421 | + let tab = if user.theme == "dark" { | |
| 422 | + "dark" | |
| 423 | + } else { | |
| 424 | + "light" | |
| 425 | + }; | |
| 321 | 426 | AppearancePage { |
| 322 | 427 | lang, |
| 323 | 428 | csrf: viewer.1.csrf_token.clone(), |
| @@ -325,18 +430,11 @@ fn page_for(viewer: &(User, Session), lang: Lang) -> AppearancePage { | ||
| 325 | 430 | language: choices(LANGUAGE_CODES, &user.language, |code| { |
| 326 | 431 | language_label(lang, code) |
| 327 | 432 | }), |
| 328 | - light: colour_group( | |
| 329 | - lang, | |
| 330 | - false, | |
| 331 | - accent::resolve_base(&user.base_light).id, | |
| 332 | - accent::resolve(&user.accent).id, | |
| 333 | - ), | |
| 334 | - dark: colour_group( | |
| 335 | - lang, | |
| 336 | - true, | |
| 337 | - accent::resolve_base(&user.base_dark).id, | |
| 338 | - accent::resolve(&user.accent_dark).id, | |
| 339 | - ), | |
| 433 | + colours: g::t(lang, K::ColoursLabel), | |
| 434 | + tab, | |
| 435 | + tabs: choices(TAB_CODES, tab, |code| tab_label(lang, code)), | |
| 436 | + light: colour_group(lang, false, &user.base_light, &user.accent), | |
| 437 | + dark: colour_group(lang, true, &user.base_dark, &user.accent_dark), | |
| 340 | 438 | sidebar: choices(SIDEBAR_CODES, sidebar_stored(&user.sidebar_side), |code| { |
| 341 | 439 | sidebar_label(lang, code) |
| 342 | 440 | }), |
| @@ -426,18 +524,40 @@ mod tests { | ||
| 426 | 524 | #[test] |
| 427 | 525 | fn the_newer_colours_pass_and_their_wrong_cases_do_not() { |
| 428 | 526 | for id in [ |
| 429 | - "teal", "moss", "indigo", "amber", "clay", "berry", "ember", "crimson", "coral", | |
| 430 | - "gold", "lime", "mint", "cyan", "sky", "violet", "fuchsia", | |
| 527 | + "sage", "spark", "ocean", "plum", "rose", "gold", "hue-0", "hue-359", | |
| 431 | 528 | ] { |
| 432 | 529 | assert_eq!(accent_choice(Lang::En, Some(id), "sage").unwrap(), id); |
| 433 | 530 | assert!(accent_choice(Lang::Tr, Some(&id.to_uppercase()), "sage").is_err()); |
| 434 | 531 | } |
| 435 | - for id in ["dune", "lilac", "dusk", "blush", "graphite", "pine"] { | |
| 532 | + for id in ["fern", "spark", "graphite", "dusk", "ink", "hue-120"] { | |
| 436 | 533 | assert_eq!(base_choice(Lang::Tr, Some(id), "fern").unwrap(), id); |
| 437 | 534 | assert!(base_choice(Lang::Tr, Some(&id.to_uppercase()), "fern").is_err()); |
| 438 | 535 | } |
| 439 | - assert!(accent_choice(Lang::En, Some("terracotta"), "sage").is_err()); | |
| 440 | - assert!(base_choice(Lang::En, Some("slate-blue"), "fern").is_err()); | |
| 536 | + // Removed presets, and hue values that are out of range or not canonical, are refused. | |
| 537 | + for id in [ | |
| 538 | + "teal", | |
| 539 | + "moss", | |
| 540 | + "ember", | |
| 541 | + "terracotta", | |
| 542 | + "hue-360", | |
| 543 | + "hue-07", | |
| 544 | + "hue-", | |
| 545 | + "hue-+5", | |
| 546 | + "teal", | |
| 547 | + ] { | |
| 548 | + assert!(accent_choice(Lang::En, Some(id), "sage").is_err(), "{id}"); | |
| 549 | + } | |
| 550 | + for id in [ | |
| 551 | + "dune", | |
| 552 | + "lilac", | |
| 553 | + "blush", | |
| 554 | + "pine", | |
| 555 | + "slate-blue", | |
| 556 | + "hue-360", | |
| 557 | + "hue-07", | |
| 558 | + ] { | |
| 559 | + assert!(base_choice(Lang::En, Some(id), "fern").is_err(), "{id}"); | |
| 560 | + } | |
| 441 | 561 | } |
| 442 | 562 | |
| 443 | 563 | #[test] |
| @@ -491,6 +611,40 @@ mod tests { | ||
| 491 | 611 | assert_eq!(group.bases[0].value, crate::accent_palette::BASE_DEFAULT); |
| 492 | 612 | } |
| 493 | 613 | |
| 614 | + #[test] | |
| 615 | + fn a_stored_hue_checks_custom_and_sets_the_knob() { | |
| 616 | + let group = colour_group(Lang::En, false, "hue-200", "hue-40"); | |
| 617 | + assert!(group.base_stripe.custom); | |
| 618 | + assert_eq!(group.base_stripe.hue, 200); | |
| 619 | + assert!(group.accent_stripe.custom); | |
| 620 | + assert_eq!(group.accent_stripe.hue, 40); | |
| 621 | + assert!(group.bases.iter().all(|c| !c.selected)); | |
| 622 | + assert!(group.accents.iter().all(|c| !c.selected)); | |
| 623 | + } | |
| 624 | + | |
| 625 | + #[test] | |
| 626 | + fn a_stored_preset_checks_the_preset_and_moves_the_knob_to_its_hue() { | |
| 627 | + let group = colour_group(Lang::En, true, "ink", "plum"); | |
| 628 | + let plum_hue = preset_accent_hue("plum").unwrap(); | |
| 629 | + let ink_hue = preset_base_hue("ink").unwrap(); | |
| 630 | + assert!(!group.accent_stripe.custom); | |
| 631 | + assert_eq!(group.accent_stripe.hue, plum_hue); | |
| 632 | + assert!(!group.base_stripe.custom); | |
| 633 | + assert_eq!(group.base_stripe.hue, ink_hue); | |
| 634 | + let plum = group.accents.iter().find(|c| c.value == "plum").unwrap(); | |
| 635 | + assert!(plum.selected); | |
| 636 | + assert_eq!(plum.hue, plum_hue.to_string()); | |
| 637 | + } | |
| 638 | + | |
| 639 | + #[test] | |
| 640 | + fn a_stored_hue_is_only_read_in_range() { | |
| 641 | + assert_eq!(hue_of("hue-359"), Some(359)); | |
| 642 | + assert_eq!(hue_of("hue-360"), None); | |
| 643 | + assert_eq!(hue_of("hue-"), None); | |
| 644 | + assert_eq!(hue_of("hue-+5"), None); | |
| 645 | + assert_eq!(hue_of("sage"), None); | |
| 646 | + } | |
| 647 | + | |
| 494 | 648 | #[test] |
| 495 | 649 | fn labels_follow_the_page_language() { |
| 496 | 650 | assert_eq!(theme_label(Lang::En, "dark"), "Dark"); |
crates/forge-web/tests/ui_prefs_e2e.rsmodified+21 -18
| @@ -309,7 +309,10 @@ async fn the_form_has_no_save_button_and_every_field_autosubmits() { | ||
| 309 | 309 | scraper::Selector::parse("form[data-appearance] input, form[data-appearance] select") |
| 310 | 310 | .expect("selector"); |
| 311 | 311 | for field in doc.select(&fields) { |
| 312 | - if field.value().attr("type") == Some("hidden") { | |
| 312 | + // The hidden fields never save, and the colour tab switch only shows a panel. | |
| 313 | + if field.value().attr("type") == Some("hidden") | |
| 314 | + || field.value().attr("data-colour-tab").is_some() | |
| 315 | + { | |
| 313 | 316 | continue; |
| 314 | 317 | } |
| 315 | 318 | assert!( |
| @@ -342,7 +345,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | ||
| 342 | 345 | ("accent_light", "ocean"), |
| 343 | 346 | ("accent_dark", "plum"), |
| 344 | 347 | ("base_light", "ink"), |
| 345 | - ("base_dark", "mist"), | |
| 348 | + ("base_dark", "dusk"), | |
| 346 | 349 | ], |
| 347 | 350 | Some(&session), |
| 348 | 351 | ) |
| @@ -350,7 +353,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | ||
| 350 | 353 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 351 | 354 | |
| 352 | 355 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 353 | - let chosen = ["ocean", "plum", "ink", "mist"].map(str::to_owned); | |
| 356 | + let chosen = ["ocean", "plum", "ink", "dusk"].map(str::to_owned); | |
| 354 | 357 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); |
| 355 | 358 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 356 | 359 | |
| @@ -363,14 +366,14 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | ||
| 363 | 366 | ("csrf", &csrf), |
| 364 | 367 | ("theme", "light"), |
| 365 | 368 | ("language", "en"), |
| 366 | - ("base_dark", "sand"), | |
| 369 | + ("base_dark", "spark"), | |
| 367 | 370 | ], |
| 368 | 371 | Some(&session), |
| 369 | 372 | ) |
| 370 | 373 | .await; |
| 371 | 374 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 372 | 375 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 373 | - let chosen = ["ocean", "plum", "ink", "sand"].map(str::to_owned); | |
| 376 | + let chosen = ["ocean", "plum", "ink", "spark"].map(str::to_owned); | |
| 374 | 377 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); |
| 375 | 378 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 376 | 379 | |
| @@ -396,7 +399,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | ||
| 396 | 399 | assert_ne!(res.status, 303, "bad {field} {bad:?} must not save"); |
| 397 | 400 | } |
| 398 | 401 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 399 | - let chosen = ["ocean", "plum", "ink", "sand"].map(str::to_owned); | |
| 402 | + let chosen = ["ocean", "plum", "ink", "spark"].map(str::to_owned); | |
| 400 | 403 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); |
| 401 | 404 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 402 | 405 | |
| @@ -409,9 +412,9 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | ||
| 409 | 412 | ("csrf", &csrf), |
| 410 | 413 | ("theme", "light"), |
| 411 | 414 | ("language", "tr"), |
| 412 | - ("accent_light", "teal"), | |
| 413 | - ("accent_dark", "berry"), | |
| 414 | - ("base_light", "dune"), | |
| 415 | + ("accent_light", "hue-200"), | |
| 416 | + ("accent_dark", "gold"), | |
| 417 | + ("base_light", "spark"), | |
| 415 | 418 | ("base_dark", "dusk"), |
| 416 | 419 | ], |
| 417 | 420 | Some(&session), |
| @@ -419,7 +422,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | ||
| 419 | 422 | .await; |
| 420 | 423 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 421 | 424 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 422 | - let chosen = ["teal", "berry", "dune", "dusk"].map(str::to_owned); | |
| 425 | + let chosen = ["hue-200", "gold", "spark", "dusk"].map(str::to_owned); | |
| 423 | 426 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); |
| 424 | 427 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 425 | 428 | |
| @@ -432,9 +435,9 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | ||
| 432 | 435 | ("csrf", &csrf), |
| 433 | 436 | ("theme", "light"), |
| 434 | 437 | ("language", "en"), |
| 435 | - ("accent_light", "crimson"), | |
| 436 | - ("accent_dark", "fuchsia"), | |
| 437 | - ("base_light", "pine"), | |
| 438 | + ("accent_light", "sage"), | |
| 439 | + ("accent_dark", "ocean"), | |
| 440 | + ("base_light", "ink"), | |
| 438 | 441 | ("base_dark", "graphite"), |
| 439 | 442 | ], |
| 440 | 443 | Some(&session), |
| @@ -442,7 +445,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | ||
| 442 | 445 | .await; |
| 443 | 446 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 444 | 447 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 445 | - let chosen = ["crimson", "fuchsia", "pine", "graphite"].map(str::to_owned); | |
| 448 | + let chosen = ["sage", "ocean", "ink", "graphite"].map(str::to_owned); | |
| 446 | 449 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); |
| 447 | 450 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 448 | 451 | } |
| @@ -463,16 +466,16 @@ async fn a_save_without_colour_fields_keeps_the_stored_colours() { | ||
| 463 | 466 | ("theme", "light"), |
| 464 | 467 | ("language", "en"), |
| 465 | 468 | ("accent_light", "rose"), |
| 466 | - ("accent_dark", "slate"), | |
| 467 | - ("base_light", "sand"), | |
| 468 | - ("base_dark", "stone"), | |
| 469 | + ("accent_dark", "gold"), | |
| 470 | + ("base_light", "fern"), | |
| 471 | + ("base_dark", "spark"), | |
| 469 | 472 | ], |
| 470 | 473 | Some(&session), |
| 471 | 474 | ) |
| 472 | 475 | .await; |
| 473 | 476 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 474 | 477 | let before = env.http.get("/settings/appearance", Some(&session)).await; |
| 475 | - let stored = ["rose", "slate", "sand", "stone"].map(str::to_owned); | |
| 478 | + let stored = ["rose", "gold", "fern", "spark"].map(str::to_owned); | |
| 476 | 479 | assert_eq!(html_colours(&before.body), stored.clone().map(Some)); |
| 477 | 480 | |
| 478 | 481 | let saved = env |
style/main.scssmodified+115 -30
| @@ -2094,8 +2094,8 @@ code { | ||
| 2094 | 2094 | |
| 2095 | 2095 | // Colour pickers (appearance settings). Each choice is a native radio, so the keyboard and screen |
| 2096 | 2096 | // readers work as usual; the swatch beside it shows the colour. The swatch colours come from the |
| 2097 | -// generated _accents.scss, so nothing here names a colour. The two themes sit side by side, and | |
| 2098 | -// stack on narrow screens, so the whole page fits a laptop window without a long scroll. | |
| 2097 | +// generated _accents.scss, so nothing here names a colour. One theme's panel shows at a time | |
| 2098 | +// (Light or Dark tabs), so the page fits a laptop window without a long scroll. | |
| 2099 | 2099 | .appearance { |
| 2100 | 2100 | display: grid; |
| 2101 | 2101 | gap: 16px; |
| @@ -2178,13 +2178,114 @@ code { | ||
| 2178 | 2178 | } |
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | -// One theme card per row, so each card is wide enough for 11 labelled colour columns. The light | |
| 2182 | -// card and the dark card are the same shape, so they still line up. | |
| 2183 | -.appearance-columns { | |
| 2181 | +// One card for both themes, with Light and Dark tabs. nav.js sets data-tab on the card; the panel | |
| 2182 | +// that is not shown is hidden, but it stays in the form, so a save still posts all four colours. | |
| 2183 | +.colour-group[data-tab="light"] > .colour-panel[data-colour-panel="dark"], | |
| 2184 | +.colour-group[data-tab="dark"] > .colour-panel[data-colour-panel="light"] { | |
| 2185 | + display: none; | |
| 2186 | +} | |
| 2187 | + | |
| 2188 | +.colour-panel { | |
| 2184 | 2189 | display: grid; |
| 2185 | - grid-template-columns: minmax(0, 1fr); | |
| 2186 | - gap: 16px; | |
| 2190 | + gap: 18px; | |
| 2191 | + min-width: 0; | |
| 2192 | +} | |
| 2193 | + | |
| 2194 | +// The hue stripe: a range input whose track is a rainbow, with a round knob. The background stripe | |
| 2195 | +// is a pale, low-saturation band so it reads as a tint. nav.js sets --hue on the row: the knob and the | |
| 2196 | +// Custom swatch take their colour from it. | |
| 2197 | +[data-colour-row] { | |
| 2198 | + --hue: 0; | |
| 2199 | +} | |
| 2200 | + | |
| 2201 | +.hue-row { | |
| 2202 | + display: flex; | |
| 2203 | + align-items: center; | |
| 2204 | + gap: 12px; | |
| 2187 | 2205 | min-width: 0; |
| 2206 | + | |
| 2207 | + // The Custom choice takes the width of one preset, so the stripe lines up with the presets' row. | |
| 2208 | + > .colour-choice { | |
| 2209 | + flex: none; | |
| 2210 | + width: 4.5rem; | |
| 2211 | + } | |
| 2212 | +} | |
| 2213 | + | |
| 2214 | +.hue-stripe { | |
| 2215 | + --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%)); | |
| 2216 | + -webkit-appearance: none; | |
| 2217 | + appearance: none; | |
| 2218 | + flex: 1 1 auto; | |
| 2219 | + width: 100%; | |
| 2220 | + min-width: 0; | |
| 2221 | + height: 22px; | |
| 2222 | + margin: 0; | |
| 2223 | + padding: 0; | |
| 2224 | + border: 0; | |
| 2225 | + background: transparent; | |
| 2226 | + cursor: pointer; | |
| 2227 | + | |
| 2228 | + &.hue-stripe-base { | |
| 2229 | + --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%)); | |
| 2230 | + } | |
| 2231 | + | |
| 2232 | + &::-webkit-slider-runnable-track { | |
| 2233 | + height: 14px; | |
| 2234 | + border-radius: var(--radius-full); | |
| 2235 | + background: var(--track); | |
| 2236 | + } | |
| 2237 | + | |
| 2238 | + &::-moz-range-track { | |
| 2239 | + height: 14px; | |
| 2240 | + border-radius: var(--radius-full); | |
| 2241 | + background: var(--track); | |
| 2242 | + } | |
| 2243 | + | |
| 2244 | + &::-webkit-slider-thumb { | |
| 2245 | + -webkit-appearance: none; | |
| 2246 | + appearance: none; | |
| 2247 | + box-sizing: border-box; | |
| 2248 | + width: 22px; | |
| 2249 | + height: 22px; | |
| 2250 | + margin-top: -4px; | |
| 2251 | + border-radius: 50%; | |
| 2252 | + border: 3px solid var(--surface); | |
| 2253 | + background: hsl(var(--hue) 80% 50%); | |
| 2254 | + box-shadow: 0 0 0 1px var(--border-strong); | |
| 2255 | + } | |
| 2256 | + | |
| 2257 | + &::-moz-range-thumb { | |
| 2258 | + box-sizing: border-box; | |
| 2259 | + width: 22px; | |
| 2260 | + height: 22px; | |
| 2261 | + border-radius: 50%; | |
| 2262 | + border: 3px solid var(--surface); | |
| 2263 | + background: hsl(var(--hue) 80% 50%); | |
| 2264 | + box-shadow: 0 0 0 1px var(--border-strong); | |
| 2265 | + } | |
| 2266 | + | |
| 2267 | + &.hue-stripe-base::-webkit-slider-thumb { | |
| 2268 | + background: hsl(var(--hue) 40% 62%); | |
| 2269 | + } | |
| 2270 | + | |
| 2271 | + &.hue-stripe-base::-moz-range-thumb { | |
| 2272 | + background: hsl(var(--hue) 40% 62%); | |
| 2273 | + } | |
| 2274 | + | |
| 2275 | + &:focus-visible { | |
| 2276 | + outline: 2px solid var(--focus); | |
| 2277 | + outline-offset: 3px; | |
| 2278 | + } | |
| 2279 | +} | |
| 2280 | + | |
| 2281 | +// The Custom swatch shows the hue the stripe is on. The accent one is saturated, the background | |
| 2282 | +// one pale, like the presets beside it. | |
| 2283 | +.hue-swatch { | |
| 2284 | + background: hsl(var(--hue) 75% 50%); | |
| 2285 | +} | |
| 2286 | + | |
| 2287 | +.base-swatch.hue-swatch { | |
| 2288 | + background: hsl(var(--hue) 40% 82%); | |
| 2188 | 2289 | } |
| 2189 | 2290 | |
| 2190 | 2291 | .colour-group { |
| @@ -2222,30 +2323,13 @@ code { | ||
| 2222 | 2323 | } |
| 2223 | 2324 | } |
| 2224 | 2325 | |
| 2225 | -// The picker is a grid with equal columns, so rows are exact and the Background and Accent rows | |
| 2226 | -// share column lines. The card is the container: wide cards get 11 columns (the 11 backgrounds | |
| 2227 | -// are one row, the 22 accents two), medium cards 6, and phone cards 4. | |
| 2228 | -.colour-group { | |
| 2229 | - container-type: inline-size; | |
| 2230 | -} | |
| 2231 | - | |
| 2326 | +// The presets are a wrapping row of fixed-width columns, so a phone wraps them and a wide card | |
| 2327 | +// keeps them in one line. | |
| 2232 | 2328 | .colour-choices { |
| 2233 | - display: grid; | |
| 2234 | - grid-template-columns: repeat(4, minmax(0, 1fr)); | |
| 2235 | - gap: 12px 4px; | |
| 2236 | -} | |
| 2237 | - | |
| 2238 | -@container (min-width: 30rem) { | |
| 2239 | - .colour-choices { | |
| 2240 | - grid-template-columns: repeat(6, minmax(0, 1fr)); | |
| 2241 | - } | |
| 2242 | -} | |
| 2243 | - | |
| 2244 | -@container (min-width: 34rem) { | |
| 2245 | - .colour-choices { | |
| 2246 | - grid-template-columns: repeat(11, minmax(0, 1fr)); | |
| 2247 | - gap: 12px 2px; | |
| 2248 | - } | |
| 2329 | + display: flex; | |
| 2330 | + flex-wrap: wrap; | |
| 2331 | + gap: 12px 8px; | |
| 2332 | + min-width: 0; | |
| 2249 | 2333 | } |
| 2250 | 2334 | |
| 2251 | 2335 | .colour-choice { |
| @@ -2253,6 +2337,7 @@ code { | ||
| 2253 | 2337 | flex-direction: column; |
| 2254 | 2338 | align-items: center; |
| 2255 | 2339 | gap: 4px; |
| 2340 | + width: 4.5rem; | |
| 2256 | 2341 | min-width: 0; |
| 2257 | 2342 | position: relative; |
| 2258 | 2343 | cursor: pointer; |