From 3a4ee0f7a54b9d16e5d90d7957f13a6e2d55a9b5 Mon Sep 17 00:00:00 2001 From: piquel Date: Tue, 10 Nov 2026 17:32:50 +0100 Subject: [PATCH 1/3] feat(ui): every on/off setting is a switch that shows its state at a glance Boolean settings were checkboxes, and email preferences a badge beside a Turn on/off button. Each is now a sliding switch: the client form's scopes and token settings, the admin dashboard's switches, and the inbox's email preferences. Scopes share one boxed list, apart from the other settings. --- apps/auth-service/src/web/settings/tests.rs | 7 +- crates/ui/assets/style/base.css | 86 +++++++++++++++++- crates/ui/src/clients.rs | 66 ++++++++------ crates/ui/src/form.rs | 27 +++++- crates/ui/src/settings/notifications.rs | 20 ++-- docs/dev/operations/administration.md | 2 +- docs/images/account/notification-email.png | Bin 19015 -> 17977 bytes docs/images/apps/app-settings.png | Bin 99978 -> 106222 bytes docs/images/apps/new-app.png | Bin 91292 -> 97480 bytes docs/user/account/notifications.md | 8 +- .../skills/sourceorigin-deploy/SKILL.md | 2 +- .../skills/sourceorigin-dev-setup/SKILL.md | 2 +- .../skills/sourceorigin-sign-in/SKILL.md | 2 +- docs/user/apps/browser-apps.md | 4 +- docs/user/apps/sign-in-rust.md | 6 +- docs/user/apps/sign-in-typescript.md | 6 +- .../browser/screenshots/app-settings.spec.ts | 2 +- 17 files changed, 175 insertions(+), 65 deletions(-) diff --git a/apps/auth-service/src/web/settings/tests.rs b/apps/auth-service/src/web/settings/tests.rs index ade8f2f01..31860cdce 100644 --- a/apps/auth-service/src/web/settings/tests.rs +++ b/apps/auth-service/src/web/settings/tests.rs @@ -672,7 +672,12 @@ async fn announcement_emails_are_turned_off_from_the_inbox_or_their_link() { preferences.expect("preferences")[0].email }; let page = html(browser.visit(&replicas.a, settings::NOTIFICATIONS).await).await; - assert!(page.contains("Turn off emails for Announcements"), "{page}"); + assert!( + page.contains( + r#"aria-checked="true">Emails for Announcements"# + ), + "{page}" + ); for email in [false, true] { let change = InboxChange::Email { category: EmailCategory::Announcements, diff --git a/crates/ui/assets/style/base.css b/crates/ui/assets/style/base.css index 3de48cb89..606f6aa79 100644 --- a/crates/ui/assets/style/base.css +++ b/crates/ui/assets/style/base.css @@ -344,14 +344,14 @@ legend { margin-bottom: 0.5rem; padding: 0; } -/* A checkbox or radio button beside its label, its help below the label. */ +/* A radio button beside its label, its help below the label. */ .choice { display: grid; grid-template-columns: auto 1fr; gap: 0.1rem 0.6rem; align-items: start; } -.choice input { +.choice input[type='radio'] { width: auto; min-height: 0; margin: 0.25rem 0 0; @@ -364,6 +364,88 @@ legend { grid-column: 2; margin: 0; } +/* A switch's row: a box with its label and help on the left, and the switch at + its right end. */ +.choice:has([role='switch']) { + position: relative; + grid-template-columns: 1fr auto; + column-gap: 1rem; + align-items: center; + padding: 0.65rem 0.8rem; + border: 1px solid var(--line); + border-radius: 6px; +} +.choice [role='switch'] { + grid-area: 1 / 2 / span 2; + z-index: 1; +} +.choice [role='switch'] ~ * { + grid-column: 1; +} +/* The label covers its row, so a click anywhere on it flips the switch. */ +.choice [role='switch'] + label::after { + content: ''; + position: absolute; + inset: 0; + cursor: pointer; +} +/* A name the app sends, such as a scope's, labels its switch at full size. */ +.choice label code { + font-size: 1em; +} +/* The switches of one group: the rows of one box, a line between them. */ +.choices { + border: 1px solid var(--line); + border-radius: 6px; +} +.choices > .choice { + border: 0; + border-radius: 0; +} +.choices > .choice + .choice { + border-top: 1px solid var(--line); +} +/* A switch: a setting on or off, drawn as a track whose thumb slides to its end + and fills with the accent when on. A checkbox with the role in a form, or a + button with it that posts the change at once. */ +[role='switch'] { + appearance: none; + position: relative; + flex: none; + width: 40px; + height: 22px; + min-height: 0; + margin: 0; + padding: 0; + border: 1px solid transparent; + border-radius: 999px; + background: var(--line); + cursor: pointer; + transition: background-color 0.15s; +} +[role='switch']::before { + content: ''; + position: absolute; + top: 2px; + left: 2px; + width: 16px; + height: 16px; + border-radius: 50%; + background: #fff; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); + transition: transform 0.15s; +} +[role='switch']:checked, +[role='switch'][aria-checked='true'] { + background: var(--accent); +} +[role='switch']:checked::before, +[role='switch'][aria-checked='true']::before { + transform: translateX(18px); +} +[role='switch']:hover { + filter: brightness(1.08); +} .search input, .search select { flex: 1; diff --git a/crates/ui/src/clients.rs b/crates/ui/src/clients.rs index b51ee9024..338e204dc 100644 --- a/crates/ui/src/clients.rs +++ b/crates/ui/src/clients.rs @@ -464,9 +464,12 @@ async fn refusal<'a>(of: &'a Described<'a>) -> Result { }) } -/// A checkbox sending `name`, or with a `value`, a radio button of the group -/// `name` choosing it, `checked` or not, which takes the focus if `autofocus`: -/// its `label` beside it, then its `detail` below, which describes it. +/// A switch sending `name` when on, or with a `value`, a radio button of the +/// group `name` choosing it, `checked` or not, which takes the focus if +/// `autofocus`: its `label` beside it, then its `detail` below, which describes +/// it. The switch is a checkbox with the `switch` role, which the stylesheet +/// draws as a sliding toggle at the right end of a boxed row; switches inside a +/// `choices` element share one box. #[component] pub(crate) async fn choice<'a>( name: &'a str, @@ -482,6 +485,7 @@ pub(crate) async fn choice<'a>(
Result { }) } -/// A checkbox for each standard scope, those of `chosen` checked, and why the +/// A switch for each standard scope, those of `chosen` checked, and why the /// service refused them, as `scopes` says, if it did. #[component] async fn scope_choices<'a>(chosen: ScopeChoice, scopes: &'a Described<'a>) -> Result { Ok(view! {
"Scopes" - for scope in Scope::ALL { - choice( - name: scope.as_str(), - checked: chosen.has(scope), - autofocus: scopes.refused() && scope == Scope::ALL[0], - label: view! { (scope.as_str()) }, - detail: view! { (scope_description(scope)) }, - ) - } +
+ for scope in Scope::ALL { + choice( + name: scope.as_str(), + checked: chosen.has(scope), + autofocus: scopes.refused() && scope == Scope::ALL[0], + label: view! { (scope.as_str()) }, + detail: view! { (scope_description(scope)) }, + ) + } +
refusal(of: scopes) }) @@ -633,22 +639,24 @@ pub(crate) async fn client_form<'a>( help(of: &logouts, "Optional, one per line: pages users may return to after signing out.") refusal(of: &logouts) scope_choices(chosen: draft.scopes, scopes: &scopes) - choice( - name: "allow_refresh", - checked: draft.allow_refresh.0, - label: view! { "Allow refresh tokens" }, - detail: view! { - "When your app requests " "offline_access" ", it can stay signed in without sending users back to Origin Auth." - }, - ) - choice( - name: "require_pushed_authorization_requests", - checked: draft.require_pushed_authorization_requests.0, - label: view! { "Require pushed authorization requests" }, - detail: view! { - "Your app must post its sign-in requests to " "/oauth/par" " (RFC 9126), so none of their parameters travel through the browser." - }, - ) +
+ choice( + name: "allow_refresh", + checked: draft.allow_refresh.0, + label: view! { "Allow refresh tokens" }, + detail: view! { + "When your app requests " "offline_access" ", it can stay signed in without sending users back to Origin Auth." + }, + ) + choice( + name: "require_pushed_authorization_requests", + checked: draft.require_pushed_authorization_requests.0, + label: view! { "Require pushed authorization requests" }, + detail: view! { + "Your app must post its sign-in requests to " "/oauth/par" " (RFC 9126), so none of their parameters travel through the browser." + }, + ) +
backchannel_input(uri: &draft.backchannel_logout_uri, of: &backchannel) (child) ) diff --git a/crates/ui/src/form.rs b/crates/ui/src/form.rs index a2f0178d5..8744252dc 100644 --- a/crates/ui/src/form.rs +++ b/crates/ui/src/form.rs @@ -418,13 +418,16 @@ pub(crate) async fn hidden(#[into] fields: Fields) -> Result { /// the user fills in as `child`, the reason an administrator gives when `reason` /// asks for one, holding what they typed last, and a button labelled `label`, of `class`, beside a link back to /// `cancel` when there is one. With `confirm`, the passkey script first confirms -/// the session with a passkey; a ceremony that fails says why in the form. +/// the session with a passkey; a ceremony that fails says why in the form. With +/// `on`, the button is instead a [`switch`] named `label`, showing whether the +/// setting `change` toggles is on. #[component] pub(crate) async fn change_form<'a>( action: &'a str, #[into] change: Fields, #[into] label: String, #[default] class: &'a str, + #[default] on: Option, #[into] #[default] aria_label: Option, @@ -456,7 +459,11 @@ pub(crate) async fn change_form<'a>( }
- + if let Some(on) = on { + switch(on: on, label: label.as_str()) + } else { + + } if let Some(cancel) = &cancel { "Cancel" } @@ -465,6 +472,22 @@ pub(crate) async fn change_form<'a>( }) } +/// A switch named `label`, showing whether its setting is `on`: a button the +/// stylesheet draws as a sliding toggle, which posts its form, or with +/// `disabled`, only shows the setting to whom cannot change it. +#[component] +pub(crate) async fn switch<'a>( + on: bool, + label: &'a str, + #[default] disabled: bool, +) -> Result { + Ok(view! { + + }) +} + /// A passkey ceremony the passkey script runs before posting a [`passkey_form`], /// named by the form's marker. #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/crates/ui/src/settings/notifications.rs b/crates/ui/src/settings/notifications.rs index 1081aa36c..e0ddfcf31 100644 --- a/crates/ui/src/settings/notifications.rs +++ b/crates/ui/src/settings/notifications.rs @@ -3,7 +3,7 @@ use super::{Audience, HistoryRow, Holdings, timeline::report_form}; use crate::{ - form::{Checkbox, Precision, Query, change_form, open, time}, + form::{Checkbox, Precision, Query, change_form, open, switch, time}, icons::{Icon, icon}, layout::{announcement_text, dialog, page_head}, }; @@ -232,14 +232,9 @@ async fn email_preferences<'a>(page: InboxPage<'a>) -> Result {