A branch rule names Pushes and Pull requests in the label column beside their first toggles instead of on lines of their own, and Save changes, Cancel and Remove rule stand under the fields with room above
Browse files at this commit9234ff688673c6a5452a9d39ae77264a6e097c33Parent: e869379- style
- a branch rule names Pushes and Pull requests in the label column beside their first toggles instead of on lines of their own, and Save changes, Cancel and Remove rule stand under the fields with room above
- a short word action in any actions row stands on the middle line of the tall submit beside it, no longer pinned to the row's top
- the mail settings' Send test mail to me sits beside Save ✅ test: measure.ts checks alignment on every page and in every panel it opens: one control edge per form, each label on its control's line, actions rows centred and on the control edge
5 changed files +80 -15
- crates/forge-web/src/pages/admin_mail.rs +4 -4
- crates/forge-web/src/pages/repo_settings.rs +6 -6
- scripts/audit/measure.ts +60 -0
- style/_one.scss +6 -0
- style/_one_admin.scss +4 -5
crates/forge-web/src/pages/admin_mail.rsmodified+4 -4
| @@ -281,10 +281,10 @@ async fn mail_view( | |||
| 281 | <input type="checkbox" name="enabled" value="on" checked=(data.enabled)> | 281 | <input type="checkbox" name="enabled" value="on" checked=(data.enabled)> |
| 282 | <span>(g::t(lang, K::SendMailCheckbox))</span> | 282 | <span>(g::t(lang, K::SendMailCheckbox))</span> |
| 283 | </label> | 283 | </label> |
| 284 | - <button type="submit" class="primary">(i18n::t(lang, Key::Save))</button> | 284 | + <div class="acts"> |
| 285 | - </div> | 285 | + <button type="submit" class="primary">(i18n::t(lang, Key::Save))</button> |
| 286 | - <div class="acts"> | 286 | + <button type="submit" form="mail-test" class="act">(g::t(lang, K::SendTestMailToMe))</button> |
| 287 | - <button type="submit" form="mail-test" class="act">(g::t(lang, K::SendTestMailToMe))</button> | 287 | + </div> |
| 288 | </div> | 288 | </div> |
| 289 | </section> | 289 | </section> |
| 290 | </form> | 290 | </form> |
crates/forge-web/src/pages/repo_settings.rsmodified+6 -6
| @@ -652,8 +652,8 @@ async fn branch_rule_form( | |||
| 652 | </div> | 652 | </div> |
| 653 | } | 653 | } |
| 654 | <div class="rule-section"> | 654 | <div class="rule-section"> |
| 655 | - <h3 class="rule-head">(g::t(lang, K::SectionPushes))</h3> | ||
| 656 | <div class="field"> | 655 | <div class="field"> |
| 656 | + <span class="field-label">(g::t(lang, K::SectionPushes))</span> | ||
| 657 | <div class="checks"> | 657 | <div class="checks"> |
| 658 | <label class="switch"> | 658 | <label class="switch"> |
| 659 | <input type="checkbox" name="allow_force_push" value="on" checked=(allow_force_push)> | 659 | <input type="checkbox" name="allow_force_push" value="on" checked=(allow_force_push)> |
| @@ -671,12 +671,8 @@ async fn branch_rule_form( | |||
| 671 | </div> | 671 | </div> |
| 672 | </div> | 672 | </div> |
| 673 | <div class=(pr_class)> | 673 | <div class=(pr_class)> |
| 674 | - <h3 class="rule-head">(g::t(lang, K::SectionPullRequests))</h3> | ||
| 675 | - <div class="field"> | ||
| 676 | - <label for=(approvals_id.as_str())>(g::t(lang, K::RequiredApprovals))</label> | ||
| 677 | - <input id=(approvals_id.as_str()) type="number" name="required_approvals" min="0" max="20" step="1" inputmode="numeric" value=(required_approvals.as_str())> | ||
| 678 | - </div> | ||
| 679 | <div class="field"> | 674 | <div class="field"> |
| 675 | + <span class="field-label">(g::t(lang, K::SectionPullRequests))</span> | ||
| 680 | <div class="checks"> | 676 | <div class="checks"> |
| 681 | <label class="switch"> | 677 | <label class="switch"> |
| 682 | <input type="checkbox" name="block_on_changes_requested" value="on" checked=(block_on_changes_requested)> | 678 | <input type="checkbox" name="block_on_changes_requested" value="on" checked=(block_on_changes_requested)> |
| @@ -692,6 +688,10 @@ async fn branch_rule_form( | |||
| 692 | </label> | 688 | </label> |
| 693 | </div> | 689 | </div> |
| 694 | </div> | 690 | </div> |
| 691 | + <div class="field"> | ||
| 692 | + <label for=(approvals_id.as_str())>(g::t(lang, K::RequiredApprovals))</label> | ||
| 693 | + <input id=(approvals_id.as_str()) type="number" name="required_approvals" min="0" max="20" step="1" inputmode="numeric" value=(required_approvals.as_str())> | ||
| 694 | + </div> | ||
| 695 | <div class="field"> | 695 | <div class="field"> |
| 696 | <label for=(checks_id.as_str())>(g::t(lang, K::SectionChecks))</label> | 696 | <label for=(checks_id.as_str())>(g::t(lang, K::SectionChecks))</label> |
| 697 | <input id=(checks_id.as_str()) type="text" name="required_checks" value=(required_checks.as_str()) autocomplete="off" spellcheck="false" placeholder="ci/test, ci/lint" aria-label=(g::t(lang, K::RequiredChecks))> | 697 | <input id=(checks_id.as_str()) type="text" name="required_checks" value=(required_checks.as_str()) autocomplete="off" spellcheck="false" placeholder="ci/test, ci/lint" aria-label=(g::t(lang, K::RequiredChecks))> |
scripts/audit/measure.tsmodified+60 -0
| @@ -195,6 +195,64 @@ const DESIGN = `(() => { | |||
| 195 | return [...new Set(bad)]; | 195 | return [...new Set(bad)]; |
| 196 | })()`; | 196 | })()`; |
| 197 | 197 | ||
| 198 | +// Alignment inside `root`: a form's controls share one edge, a label stands on its control's line, | ||
| 199 | +// an actions row is one centred line on the control edge. | ||
| 200 | +const ALIGN = `((root) => { | ||
| 201 | + const bad = []; | ||
| 202 | + const seen = (e) => { const r = e.getBoundingClientRect(); return r.width > 0 && r.height > 0 && getComputedStyle(e).visibility !== 'hidden'; }; | ||
| 203 | + const name = (e) => e.tagName.toLowerCase() + (e.classList.length ? '.' + [...e.classList].join('.') : '') + ' < ' + (e.parentElement.classList[0] || e.parentElement.tagName.toLowerCase()); | ||
| 204 | + const mid = (r) => r.top + r.height / 2; | ||
| 205 | + // The first line box of an element's text, or its box when it has no text. | ||
| 206 | + const line = (e) => { const t = [...e.childNodes].find((n) => n.nodeType === 3 && n.textContent.trim()); if (t) { const g = document.createRange(); g.selectNodeContents(t); const rs = g.getClientRects(); if (rs.length) return rs[0]; } return e.getBoundingClientRect(); }; | ||
| 207 | + // One line of an actions row: its visible children sharing the first child's line are centred on it. | ||
| 208 | + for (const row of root.querySelectorAll('.acts')) { | ||
| 209 | + if (!seen(row) || getComputedStyle(row).display !== 'flex' || getComputedStyle(row).flexDirection !== 'row') continue; | ||
| 210 | + const kids = [...row.children].filter((k) => seen(k) && !k.matches('.hint, input[type=hidden]')); | ||
| 211 | + if (kids.length < 2) continue; | ||
| 212 | + const a = kids[0].getBoundingClientRect(); | ||
| 213 | + for (const k of kids.slice(1)) { | ||
| 214 | + const b = k.getBoundingClientRect(); | ||
| 215 | + if (b.top > a.bottom || b.bottom < a.top) continue; // wrapped to another line | ||
| 216 | + // A word action is centred by its text, a control by its box. | ||
| 217 | + const kb = k.matches('a.act, span.act, button.act:not([class*=pill])') && getComputedStyle(k).backgroundColor === 'rgba(0, 0, 0, 0)' ? line(k) : b; | ||
| 218 | + if (Math.abs(mid(kb) - mid(a)) > 2) bad.push('acts row off centre ' + Math.round(mid(kb) - mid(a)) + 'px: ' + name(k)); | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + for (const form of root.querySelectorAll('.fields')) { | ||
| 222 | + if (!seen(form) || form.getBoundingClientRect().width < 500) continue; | ||
| 223 | + const fields = [...form.querySelectorAll('.field')].filter((f) => seen(f) && f.closest('.fields') === form && getComputedStyle(f).display === 'grid'); | ||
| 224 | + const edges = new Map(); | ||
| 225 | + for (const f of fields) { | ||
| 226 | + const lab = f.querySelector(':scope > label:not(.switch), :scope > .field-label'); | ||
| 227 | + const ctl = [...f.children].find((k) => seen(k) && k !== lab && !k.matches('.hint')); | ||
| 228 | + if (!ctl) continue; | ||
| 229 | + const left = Math.round(ctl.getBoundingClientRect().left); | ||
| 230 | + edges.set(left, (edges.get(left) || 0) + 1); | ||
| 231 | + if (lab && seen(lab)) { | ||
| 232 | + const target = ctl.matches('.checks') ? (ctl.querySelector('label, .switch') || ctl) : ctl; | ||
| 233 | + const tb = target.getBoundingClientRect(); | ||
| 234 | + // A tall control (a box of text, a choice) is read by its first line, 38 high. | ||
| 235 | + const lm = mid(line(lab)), cm = target.matches('input, select, textarea, button, .choice') ? (tb.height > 40 ? tb.top + 19 : mid(tb)) : mid(line(target.querySelector('span') || target)); | ||
| 236 | + if (Math.abs(lm - cm) > 3) bad.push('label off its control line ' + Math.round(cm - lm) + 'px: ' + name(lab)); | ||
| 237 | + } | ||
| 238 | + // A heading standing over a field with an empty label column: the name belongs in that column. | ||
| 239 | + const prev = f.previousElementSibling; | ||
| 240 | + if (!lab && prev && prev.matches('h2, h3, h4') && seen(prev)) bad.push('group name on its own line over an empty label column: ' + name(prev)); | ||
| 241 | + } | ||
| 242 | + if (!edges.size) continue; | ||
| 243 | + const edge = [...edges].sort((x, y) => y[1] - x[1])[0][0]; | ||
| 244 | + for (const [left, n] of edges) if (left !== edge && edges.size > 1) bad.push('control edge ' + left + ' (form edge ' + edge + ', ' + n + ' fields): ' + name(form)); | ||
| 245 | + // The actions after the fields: on the control edge, with room above. | ||
| 246 | + const acts = form.querySelector(':scope > .acts:last-child') || (form.nextElementSibling?.matches('.acts') ? form.nextElementSibling : null); | ||
| 247 | + const first = acts && [...acts.children].find(seen); | ||
| 248 | + if (first && fields.length > 1) { | ||
| 249 | + const r = first.getBoundingClientRect(); | ||
| 250 | + if (Math.abs(Math.round(r.left) - edge) > 1) bad.push('actions off the control edge ' + (Math.round(r.left) - edge) + 'px: ' + name(acts)); | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + return bad; | ||
| 254 | +})`; | ||
| 255 | + | ||
| 198 | // The rules a floating panel must keep, run while it is open. | 256 | // The rules a floating panel must keep, run while it is open. |
| 199 | const PANEL = `((root) => { | 257 | const PANEL = `((root) => { |
| 200 | const bad = []; | 258 | const bad = []; |
| @@ -229,6 +287,7 @@ const OPEN = `(async () => { | |||
| 229 | } | 287 | } |
| 230 | bad.push(...${PANEL}(root)); | 288 | bad.push(...${PANEL}(root)); |
| 231 | bad.push(...(${PANEL})(root)); | 289 | bad.push(...(${PANEL})(root)); |
| 290 | + bad.push(...(${ALIGN})(root).map((l) => 'open ' + (summary.textContent || '').trim().slice(0, 30) + ': ' + l)); | ||
| 232 | if (document.documentElement.scrollWidth > innerWidth + 1) bad.push('opening makes the page wide: ' + (summary.textContent || '').trim().slice(0, 30)); | 291 | if (document.documentElement.scrollWidth > innerWidth + 1) bad.push('opening makes the page wide: ' + (summary.textContent || '').trim().slice(0, 30)); |
| 233 | } | 292 | } |
| 234 | if (e.tagName === 'DETAILS') { e.open = false; } else { document.querySelector(':popover-open')?.hidePopover(); } | 293 | if (e.tagName === 'DETAILS') { e.open = false; } else { document.querySelector(':popover-open')?.hidePopover(); } |
| @@ -251,6 +310,7 @@ for (const path of paths) { | |||
| 251 | // An account's own theme wins over the system's: the audit asks for the one it measures. | 310 | // An account's own theme wins over the system's: the audit asks for the one it measures. |
| 252 | if (process.env.AUDIT_THEME) await js(`document.documentElement.setAttribute('data-theme', ${JSON.stringify(theme)})`); | 311 | if (process.env.AUDIT_THEME) await js(`document.documentElement.setAttribute('data-theme', ${JSON.stringify(theme)})`); |
| 253 | const bad: string[] = (await js(DESIGN)) ?? ["page did not answer"]; | 312 | const bad: string[] = (await js(DESIGN)) ?? ["page did not answer"]; |
| 313 | + bad.push(...((await js(`(${ALIGN})(document.querySelector('main') || document.body)`)) ?? [])); | ||
| 254 | const code = await js("document.title"); | 314 | const code = await js("document.title"); |
| 255 | if (/not found|error/i.test(code ?? "")) bad.push("title: " + code); | 315 | if (/not found|error/i.test(code ?? "")) bad.push("title: " + code); |
| 256 | const name = path.replace(/[^a-z0-9]+/gi, "_").slice(0, 120) + "_" + width + (theme === "dark" ? "_dark" : ""); | 316 | const name = path.replace(/[^a-z0-9]+/gi, "_").slice(0, 120) + "_" + width + (theme === "dark" ? "_dark" : ""); |
style/_one.scssmodified+6 -0
| @@ -347,6 +347,12 @@ button.link-button, | |||
| 347 | align-items: center; | 347 | align-items: center; |
| 348 | gap: 4px; | 348 | gap: 4px; |
| 349 | margin-left: -10px; | 349 | margin-left: -10px; |
| 350 | + | ||
| 351 | + // Every button is pinned to the top of a flex column by the old sheet; in a row of actions a | ||
| 352 | + // short word action stands on the middle line of a tall submit instead. | ||
| 353 | + > :is(button, .button) { | ||
| 354 | + align-self: auto; | ||
| 355 | + } | ||
| 350 | } | 356 | } |
| 351 | 357 | ||
| 352 | .sec > .acts { | 358 | .sec > .acts { |
style/_one_admin.scssmodified+4 -5
| @@ -318,11 +318,9 @@ $repo: 'main:has(> section.repo-head .tab.active[href$="/settings"])'; | |||
| 318 | min-width: 0; | 318 | min-width: 0; |
| 319 | } | 319 | } |
| 320 | 320 | ||
| 321 | -#{$repo} .rule-head { | 321 | +// Each group is named in the label column beside its first toggles; a little air between groups. |
| 322 | - margin: 12px 0 0; | 322 | +#{$repo} .rule-pr { |
| 323 | - font-size: 14px; | 323 | + margin-top: 10px; |
| 324 | - font-weight: 600; | ||
| 325 | - color: var(--muted); | ||
| 326 | } | 324 | } |
| 327 | 325 | ||
| 328 | #{$repo} .branch-rule-form label.switch { | 326 | #{$repo} .branch-rule-form label.switch { |
| @@ -386,6 +384,7 @@ $repo: 'main:has(> section.repo-head .tab.active[href$="/settings"])'; | |||
| 386 | 384 | ||
| 387 | #{$repo} .rule-acts { | 385 | #{$repo} .rule-acts { |
| 388 | align-items: center; | 386 | align-items: center; |
| 387 | + margin-top: 16px; | ||
| 389 | margin-left: calc(var(--label-w) + 16px); | 388 | margin-left: calc(var(--label-w) + 16px); |
| 390 | 389 | ||
| 391 | @media (max-width: 700px) { | 390 | @media (max-width: 700px) { |