Skip to content

Commit d792cb1

Browse files
authored
feat(ui): every on/off setting is a switch that shows its state at a glance (#482)
On/off settings were plain checkboxes, and email preferences were a badge beside a **Turn on/off** button, so you had to read text to tell whether a setting was on. Every one is now a sliding switch: grey with the knob on the left when off, accent-coloured with the knob on the right when on. - **Client form** (developer console and admin dashboard): the scopes share one boxed list, one row per scope. **Allow refresh tokens** and **Require pushed authorization requests** are in a separate box below. A click anywhere on a row flips its switch. - **Admin dashboard:** **Trusted**, **Essential**, **Sign with it at once** and **Allow a reserved handle** are switch rows. - **Email preferences:** each category has one switch that saves on click. People who can see a setting but not change it see a disabled switch. The switches are still checkboxes (or buttons, for email preferences) with `role="switch"`, drawn by CSS, so they work without scripts. Radio choices are unchanged. The docs now say "turn on" instead of "tick" or "check", and the three affected screenshots are retaken. Proof: the inbox's email-preference database test and the docs screenshot specs pass on a preview; the stylesheet rendered in Chromium in light, dark and at 360px width, where a click on a row or its switch flips it and nothing scrolls sideways. Reviewed with review-loop: 2 rounds with Claude Opus 5.5 (the two GPT 6.1 Sol reviewers were out of usage). Verdict: approved > [!NOTE] > Written by Claude Opus 5.5 in Claude Code, with the scopes layout designed by Claude Fable 5.2 (via T3 Code)
1 parent d11254b commit d792cb1

19 files changed

Lines changed: 179 additions & 69 deletions

File tree

‎apps/auth-service/src/web/admin/clients.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ pub(super) async fn rotate(cx: &Cx, form: Option<Form<Rotation>>) -> Result<Resp
305305
refusal: refusal,
306306
)
307307
};
308-
App::render(cx, StatusCode::OK, "Client secrets", page).await
308+
// A large page: its future is boxed, off the handler's stack.
309+
Box::pin(App::render(cx, StatusCode::OK, "Client secrets", page)).await
309310
}
310311

311312
/// The form rotating a client's secret: the developer console's, with why.

‎apps/auth-service/src/web/auth/login/mod.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,7 @@ impl WebApplication {
626626
alert: alert,
627627
)
628628
};
629-
Ok(self
630-
.render(cx, status, step.title().as_str(), &targets, view)
631-
.await?)
629+
// A large page: its future is boxed, off the handler's stack.
630+
Ok(Box::pin(self.render(cx, status, step.title().as_str(), &targets, view)).await?)
632631
}
633632
}

‎apps/auth-service/src/web/settings/tests.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,12 @@ async fn announcement_emails_are_turned_off_from_the_inbox_or_their_link() {
672672
preferences.expect("preferences")[0].email
673673
};
674674
let page = html(browser.visit(&replicas.a, settings::NOTIFICATIONS).await).await;
675-
assert!(page.contains("Turn off emails for Announcements"), "{page}");
675+
assert!(
676+
page.contains(
677+
r#"aria-checked="true"><span class="visually-hidden">Emails for Announcements"#
678+
),
679+
"{page}"
680+
);
676681
for email in [false, true] {
677682
let change = InboxChange::Email {
678683
category: EmailCategory::Announcements,

‎crates/ui/assets/style/base.css‎

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,14 @@ legend {
344344
margin-bottom: 0.5rem;
345345
padding: 0;
346346
}
347-
/* A checkbox or radio button beside its label, its help below the label. */
347+
/* A radio button beside its label, its help below the label. */
348348
.choice {
349349
display: grid;
350350
grid-template-columns: auto 1fr;
351351
gap: 0.1rem 0.6rem;
352352
align-items: start;
353353
}
354-
.choice input {
354+
.choice input[type='radio'] {
355355
width: auto;
356356
min-height: 0;
357357
margin: 0.25rem 0 0;
@@ -364,6 +364,88 @@ legend {
364364
grid-column: 2;
365365
margin: 0;
366366
}
367+
/* A switch's row: a box with its label and help on the left, and the switch at
368+
its right end. */
369+
.choice:has([role='switch']) {
370+
position: relative;
371+
grid-template-columns: 1fr auto;
372+
column-gap: 1rem;
373+
align-items: center;
374+
padding: 0.65rem 0.8rem;
375+
border: 1px solid var(--line);
376+
border-radius: 6px;
377+
}
378+
.choice [role='switch'] {
379+
grid-area: 1 / 2 / span 2;
380+
z-index: 1;
381+
}
382+
.choice [role='switch'] ~ * {
383+
grid-column: 1;
384+
}
385+
/* The label covers its row, so a click anywhere on it flips the switch. */
386+
.choice [role='switch'] + label::after {
387+
content: '';
388+
position: absolute;
389+
inset: 0;
390+
cursor: pointer;
391+
}
392+
/* A name the app sends, such as a scope's, labels its switch at full size. */
393+
.choice label code {
394+
font-size: 1em;
395+
}
396+
/* The switches of one group: the rows of one box, a line between them. */
397+
.choices {
398+
border: 1px solid var(--line);
399+
border-radius: 6px;
400+
}
401+
.choices > .choice {
402+
border: 0;
403+
border-radius: 0;
404+
}
405+
.choices > .choice + .choice {
406+
border-top: 1px solid var(--line);
407+
}
408+
/* A switch: a setting on or off, drawn as a track whose thumb slides to its end
409+
and fills with the accent when on. A checkbox with the role in a form, or a
410+
button with it that posts the change at once. */
411+
[role='switch'] {
412+
appearance: none;
413+
position: relative;
414+
flex: none;
415+
width: 40px;
416+
height: 22px;
417+
min-height: 0;
418+
margin: 0;
419+
padding: 0;
420+
border: 1px solid transparent;
421+
border-radius: 999px;
422+
background: var(--muted);
423+
cursor: pointer;
424+
transition: background-color 0.15s;
425+
}
426+
[role='switch']::before {
427+
content: '';
428+
position: absolute;
429+
top: 2px;
430+
left: 2px;
431+
width: 16px;
432+
height: 16px;
433+
border-radius: 50%;
434+
background: #fff;
435+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
436+
transition: transform 0.15s;
437+
}
438+
[role='switch']:checked,
439+
[role='switch'][aria-checked='true'] {
440+
background: var(--accent);
441+
}
442+
[role='switch']:checked::before,
443+
[role='switch'][aria-checked='true']::before {
444+
transform: translateX(18px);
445+
}
446+
[role='switch']:not(:disabled):hover {
447+
filter: brightness(1.08);
448+
}
367449
.search input,
368450
.search select {
369451
flex: 1;

‎crates/ui/src/clients.rs‎

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,12 @@ async fn refusal<'a>(of: &'a Described<'a>) -> Result<impl View> {
464464
})
465465
}
466466

467-
/// A checkbox sending `name`, or with a `value`, a radio button of the group
468-
/// `name` choosing it, `checked` or not, which takes the focus if `autofocus`:
469-
/// its `label` beside it, then its `detail` below, which describes it.
467+
/// A switch sending `name` when on, or with a `value`, a radio button of the
468+
/// group `name` choosing it, `checked` or not, which takes the focus if
469+
/// `autofocus`: its `label` beside it, then its `detail` below, which describes
470+
/// it. The switch is a checkbox with the `switch` role, which the stylesheet
471+
/// draws as a sliding toggle at the right end of a boxed row; switches inside a
472+
/// `choices` element share one box.
470473
#[component]
471474
pub(crate) async fn choice<'a>(
472475
name: &'a str,
@@ -482,6 +485,7 @@ pub(crate) async fn choice<'a>(
482485
<div class="choice">
483486
<input
484487
type=(if value.is_some() { "radio" } else { "checkbox" })
488+
role=(value.is_none().then_some("switch"))
485489
id=(input.id.as_str())
486490
name=(name)
487491
value=(value)
@@ -525,22 +529,24 @@ async fn kind_question(chosen: ClientKind) -> Result<impl View> {
525529
})
526530
}
527531

528-
/// A checkbox for each standard scope, those of `chosen` checked, and why the
532+
/// A switch for each standard scope, those of `chosen` checked, and why the
529533
/// service refused them, as `scopes` says, if it did.
530534
#[component]
531535
async fn scope_choices<'a>(chosen: ScopeChoice, scopes: &'a Described<'a>) -> Result<impl View> {
532536
Ok(view! {
533537
<fieldset aria-describedby=(scopes.refused().then(|| scopes.error()))>
534538
<legend>"Scopes"</legend>
535-
for scope in Scope::ALL {
536-
choice(
537-
name: scope.as_str(),
538-
checked: chosen.has(scope),
539-
autofocus: scopes.refused() && scope == Scope::ALL[0],
540-
label: view! { <code>(scope.as_str())</code> },
541-
detail: view! { (scope_description(scope)) },
542-
)
543-
}
539+
<div class="choices">
540+
for scope in Scope::ALL {
541+
choice(
542+
name: scope.as_str(),
543+
checked: chosen.has(scope),
544+
autofocus: scopes.refused() && scope == Scope::ALL[0],
545+
label: view! { <code>(scope.as_str())</code> },
546+
detail: view! { (scope_description(scope)) },
547+
)
548+
}
549+
</div>
544550
</fieldset>
545551
refusal(of: scopes)
546552
})
@@ -633,22 +639,24 @@ pub(crate) async fn client_form<'a>(
633639
help(of: &logouts, "Optional, one per line: pages users may return to after signing out.")
634640
refusal(of: &logouts)
635641
scope_choices(chosen: draft.scopes, scopes: &scopes)
636-
choice(
637-
name: "allow_refresh",
638-
checked: draft.allow_refresh.0,
639-
label: view! { "Allow refresh tokens" },
640-
detail: view! {
641-
"When your app requests " <code>"offline_access"</code> ", it can stay signed in without sending users back to Origin Auth."
642-
},
643-
)
644-
choice(
645-
name: "require_pushed_authorization_requests",
646-
checked: draft.require_pushed_authorization_requests.0,
647-
label: view! { "Require pushed authorization requests" },
648-
detail: view! {
649-
"Your app must post its sign-in requests to " <code>"/oauth/par"</code> " (RFC 9126), so none of their parameters travel through the browser."
650-
},
651-
)
642+
<div class="choices">
643+
choice(
644+
name: "allow_refresh",
645+
checked: draft.allow_refresh.0,
646+
label: view! { "Allow refresh tokens" },
647+
detail: view! {
648+
"When your app requests " <code>"offline_access"</code> ", it can stay signed in without sending users back to Origin Auth."
649+
},
650+
)
651+
choice(
652+
name: "require_pushed_authorization_requests",
653+
checked: draft.require_pushed_authorization_requests.0,
654+
label: view! { "Require pushed authorization requests" },
655+
detail: view! {
656+
"Your app must post its sign-in requests to " <code>"/oauth/par"</code> " (RFC 9126), so none of their parameters travel through the browser."
657+
},
658+
)
659+
</div>
652660
backchannel_input(uri: &draft.backchannel_logout_uri, of: &backchannel)
653661
(child)
654662
)

‎crates/ui/src/form.rs‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,16 @@ pub(crate) async fn hidden(#[into] fields: Fields) -> Result<impl View> {
418418
/// the user fills in as `child`, the reason an administrator gives when `reason`
419419
/// asks for one, holding what they typed last, and a button labelled `label`, of `class`, beside a link back to
420420
/// `cancel` when there is one. With `confirm`, the passkey script first confirms
421-
/// the session with a passkey; a ceremony that fails says why in the form.
421+
/// the session with a passkey; a ceremony that fails says why in the form. With
422+
/// `on`, the button is instead a [`switch`] named `label`, showing whether the
423+
/// setting `change` toggles is on.
422424
#[component]
423425
pub(crate) async fn change_form<'a>(
424426
action: &'a str,
425427
#[into] change: Fields,
426428
#[into] label: String,
427429
#[default] class: &'a str,
430+
#[default] on: Option<bool>,
428431
#[into]
429432
#[default]
430433
aria_label: Option<String>,
@@ -456,7 +459,11 @@ pub(crate) async fn change_form<'a>(
456459
<p class="notice error" role="alert" data-passkey-error="" hidden=""></p>
457460
}
458461
<div class="row actions">
459-
<button class=(class) aria-label=(aria_label.as_deref())>(label.as_str())</button>
462+
if let Some(on) = on {
463+
switch(on: on, label: label.as_str())
464+
} else {
465+
<button class=(class) aria-label=(aria_label.as_deref())>(label.as_str())</button>
466+
}
460467
if let Some(cancel) = &cancel {
461468
<a class="button secondary" href=(cancel.as_str())>"Cancel"</a>
462469
}
@@ -465,6 +472,22 @@ pub(crate) async fn change_form<'a>(
465472
})
466473
}
467474

475+
/// A switch named `label`, showing whether its setting is `on`: a button the
476+
/// stylesheet draws as a sliding toggle, which posts its form, or with
477+
/// `disabled`, only shows the setting to whom cannot change it.
478+
#[component]
479+
pub(crate) async fn switch<'a>(
480+
on: bool,
481+
label: &'a str,
482+
#[default] disabled: bool,
483+
) -> Result<impl View> {
484+
Ok(view! {
485+
<button role="switch" aria-checked=(if on { "true" } else { "false" }) disabled=(disabled)>
486+
<span class="visually-hidden">(label)</span>
487+
</button>
488+
})
489+
}
490+
468491
/// A passkey ceremony the passkey script runs before posting a [`passkey_form`],
469492
/// named by the form's marker.
470493
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

‎crates/ui/src/settings/notifications.rs‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use super::{Audience, HistoryRow, Holdings, timeline::report_form};
55
use crate::{
6-
form::{Checkbox, Precision, Query, change_form, open, time},
6+
form::{Checkbox, Precision, Query, change_form, open, switch, time},
77
icons::{Icon, icon},
88
layout::{announcement_text, dialog, page_head},
99
};
@@ -232,14 +232,9 @@ async fn email_preferences<'a>(page: InboxPage<'a>) -> Result<impl View> {
232232
<ul class="list">
233233
for preference in page.preferences {
234234
<li>
235+
let label = format!("Emails for {}", preference.category.label());
235236
<div class="text">
236237
<strong>(preference.category.label())</strong>
237-
" "
238-
if preference.email {
239-
<span class="badge ok">"Emailed"</span>
240-
} else {
241-
<span class="badge">"Not emailed"</span>
242-
}
243238
<small>(preference.category.description())</small>
244239
</div>
245240
if owner {
@@ -249,14 +244,11 @@ async fn email_preferences<'a>(page: InboxPage<'a>) -> Result<impl View> {
249244
category: preference.category,
250245
email: Checkbox(!preference.email),
251246
},
252-
label: if preference.email { "Turn off" } else { "Turn on" },
253-
class: "secondary small",
254-
aria_label: format!(
255-
"Turn {} emails for {}",
256-
if preference.email { "off" } else { "on" },
257-
preference.category.label(),
258-
),
247+
label: label,
248+
on: Some(preference.email),
259249
)
250+
} else {
251+
switch(on: preference.email, label: label.as_str(), disabled: true)
260252
}
261253
</li>
262254
}

‎docs/dev/operations/administration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ On the dashboard:
310310
accounts**: paste a list, one handle, verified email or account ID per line,
311311
or type into the search box and select **Find**, then **Add** beside each
312312
account. Finding and adding save nothing.
313-
3. Check **Essential** if every recipient must receive it by email.
313+
3. Turn on **Essential** if every recipient must receive it by email.
314314
4. Select **Save draft** to check the email first, or **Send** to send it now.
315315
Saving a draft needs no passkey; sending asks for one.
316316

-1.01 KB
Loading

‎docs/images/apps/app-settings.png‎

6.25 KB
Loading

0 commit comments

Comments
 (0)