diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6ed47a31..db7956cb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -220,7 +220,7 @@ Each role has one kit component in `src/ui`. Variants are typed props, never cla Layout and text utility classes are not kit components, and features may use them directly: `rp-row` (a title or label and its controls on one line), `rp-cluster` (items that wrap, with `nowrap` to keep one line), `rp-col`, `rp-grow`, `rp-contents`, and the text styles `rp-label`, `rp-note`, `rp-h3` and `rp-code`. They place or style what a feature composes and draw no control or surface, so they are not wrapped in components. Classes that draw a kit part (a card, a button, an empty or loading state, a value tile, a chart placeholder) stay inside `src/ui`, and `no-restricted-syntax` rejects them in features. Keyboard focus uses one `--rp-focus-width` (2px) outline in `--rp-focus-color`, following the target's radius. Keep at least 2px between the ring and visible content: text-only targets use padding with compensating margins, and scroll-clipped controls use an inset ring. Text fields put the ring on the field box, not both the input and its wrapper; clear and reveal buttons own their rings. Preserve unfocused content positions, palette values and selection backgrounds when changing focus styles. -Set control sizes only with the kit component's `size` prop (`M` or `L`), never with CSS height, font-size or padding overrides. `Toolbar page`, `Tabs page` and page-action/link components enforce L (40px); cards, dialogs, inspectors, tables, widgets and the sidebar keep M (32px, 36px on phones/coarse pointers). `Segmented` is always L, wherever it sits, so every segmented control matches; a row that holds one sets the controls beside it to L too (through `ControlSizeContext`, `Card size="L"` or their `size` prop), and the Activity control cards, which share a row with the outbound mode switch, are all L. Contextual help stays at XS (24px), centred beside its label or control regardless of the surrounding size. A few controls take no `size` and stay M wherever they sit: the drag handle of a sortable cell (`SortableCanvas`), the `Disclosure` trigger, `Checkbox` and `Radio`; `buttonClass`, which styles such react-aria buttons, does not accept a `size` either. The page heading reserves the L row height even while page actions are unmounted during chunk loading. Side-labelled source pickers wrap the label when needed to keep the complete basename inside the viewport. `src/ui/styles/controlSize.test.ts` guards CSS ownership and height tokens, `e2e/toolbar-height.spec.ts` checks every route's page rows and local M/L mixing, and `e2e/segmented-size.spec.ts` checks every segmented control and its row on every route, the widget panel and dashboard editing. +Set control sizes only with the kit component's `size` prop (`M` or `L`), never with CSS height, font-size or padding overrides. Every control is S2's default M (32px, 36px on phones/coarse pointers) wherever it sits: page toolbars, tab rows, page actions and links, cards, dialogs, inspectors, tables, widgets and the sidebar alike. No container forces L; a control is L only where S2 itself prescribes L, by passing `size="L"`, and then takes L's 16px text and L's corners (9px, or a 20px pill for a text Button). A control's own `size` prop wins over the size a `Card` provides through `ControlSizeContext`; dialogs and popovers reset it. `Segmented` has no size, as S2's SegmentedControl has none: it is always M, its items flush in the track. Tab rows use the M control height, S2's compact Tabs height (32px), so a tab row and the controls beside it share one height. Contextual help stays at XS (24px), centred beside its label or control regardless of the surrounding size. The page heading reserves the M row height even while page actions are unmounted during chunk loading. Side-labelled source pickers wrap the label when needed to keep the complete basename inside the viewport. `src/ui/styles/controlSize.test.ts` guards CSS ownership, height tokens and the size precedence, `e2e/toolbar-height.spec.ts` checks every route's page rows and local M/L mixing, and `e2e/segmented-size.spec.ts` checks every segmented control and its row on every route, the widget panel and dashboard editing. | Role (S2 name) | Kit component | | --------------------------------- | ------------------------------------------------- | diff --git a/README.md b/README.md index 3a52cb54..51c116bf 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Changes since beta.12; see the [full changelog](CHANGELOG.md#010-beta13---2026-1 - Size dashboard cards by width and height presets or by dragging their edges, with a hint for the space left in each row while editing. - Arrange widgets in a floating, pinned or phone-drawer panel, preview the panel at its real width in the widget editor, and hide an unpinned, undocked panel at the screen edge. - Follow a group's active-node latency on Activity and view CPU and latency trends alongside first-run setup guidance. -- Page toolbars, tab rows and segmented controls share one 40px height, and keyboard focus rings keep clear of their content and are no longer clipped. +- Page toolbars, tab rows and segmented controls use S2's default 32px height, and keyboard focus rings keep clear of their content and are no longer clipped. Debian and Ubuntu users: the deb is now `doona-web` and installs into `/usr/share/doona-web`, because both distributions ship an unrelated `doona` package; set honk's `ui` to the new path. diff --git a/README.zh-CN.md b/README.zh-CN.md index 9872c30f..2a9693ff 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -68,7 +68,7 @@ doona 依赖 honk 的原生 API,目前只有 [Glassyiris/honk `feat/native-api - 按宽度与高度预设或拖动边缘调整仪表盘卡片大小,编辑时显示每行的剩余空间。 - 在浮动、固定或手机抽屉式面板中排列小工具,在小工具编辑器中按实际宽度预览面板,并将未固定且未停靠的面板隐藏在屏幕边缘。 - 在活动页查看群组当前节点的延迟、CPU 与延迟趋势,以及首次设置引导。 -- 页面工具栏、标签栏与分段控件统一为 40px 高;键盘焦点环与内容保持间距,也不再被容器裁切。 +- 页面工具栏、标签栏与分段控件采用 S2 默认的 32px 高度;键盘焦点环与内容保持间距,也不再被容器裁切。 Debian 与 Ubuntu 用户请注意:deb 软件包已更名为 `doona-web`,安装到 `/usr/share/doona-web`,因为这两个发行版自带一个无关的 `doona` 软件包;请将 honk 的 `ui` 改为新路径。 diff --git a/README.zh-TW.md b/README.zh-TW.md index c65817e4..491d36b3 100644 --- a/README.zh-TW.md +++ b/README.zh-TW.md @@ -68,7 +68,7 @@ doona 需要 honk 的原生 API,目前只有 [Glassyiris/honk `feat/native-api - 依寬度與高度預設或拖曳邊緣調整儀表板卡片大小,編輯時顯示每列的剩餘空間。 - 在浮動、固定或手機抽屜式面板中排列小工具,於小工具編輯器中依實際寬度預覽面板,並將未固定且未停靠的面板隱藏在螢幕邊緣。 - 在活動頁檢視群組目前節點的延遲、CPU 與延遲趨勢,以及首次設定引導。 -- 頁面工具列、分頁列與分段控制項統一為 40px 高;鍵盤焦點環與內容保持間距,也不再被容器裁切。 +- 頁面工具列、分頁列與分段控制項採用 S2 預設的 32px 高度;鍵盤焦點環與內容保持間距,也不再被容器裁切。 Debian 與 Ubuntu 使用者請注意:deb 套件已更名為 `doona-web`,安裝至 `/usr/share/doona-web`,因為這兩個發行版內建一個無關的 `doona` 套件;請將 honk 的 `ui` 改為新路徑。 diff --git a/changes/fix-s2-control-sizes.md b/changes/fix-s2-control-sizes.md new file mode 100644 index 00000000..9678db0f --- /dev/null +++ b/changes/fix-s2-control-sizes.md @@ -0,0 +1,3 @@ +Fixed + +- Controls are back to their S2 sizes: segmented controls, page toolbars, tab rows and the mode card are M (32px) again instead of a forced 40px, icon buttons in table rows lose the stray side padding, and any control that asks for L gets L text and corners. diff --git a/e2e/activity-main-geometry.ts b/e2e/activity-main-geometry.ts index 4acafdeb..ff53481c 100644 --- a/e2e/activity-main-geometry.ts +++ b/e2e/activity-main-geometry.ts @@ -4,6 +4,8 @@ // the details column below it; main's 2fr/1fr split put it 4px off (history 728 to 732 wide, outbounds 4px narrower). // Another in zh-TW at 1440, 1024 and 768px and in en at 1024 and 768px: the control cards' row gives each card its one // line first and shares the rest by the footprints (see fitSpans), so those boxes are this branch's. +// And one more in en at 1024 and 768px and zh-TW at 1440 to 768px: the mode and global lines are narrower at the default M +// size, so those cards' share of the row moves (card 1 and 2, and card 0 in zh-TW at 1280px, which now fits one line). export const cardBounds: Record = { 'en-1440': [ [280, 156, 462.84375, 110], @@ -22,8 +24,8 @@ export const cardBounds: Record element.getBoundingClientRect().height)).toBe(40); + expect(await filter.evaluate(element => element.getBoundingClientRect().height)).toBe(32); await level('Errors 3').click(); await expect(rows).toHaveCount(2); await expect(rows.first()).toContainText('Repeated error'); diff --git a/e2e/dashboard.spec.ts b/e2e/dashboard.spec.ts index 23eef820..70b1aa41 100644 --- a/e2e/dashboard.spec.ts +++ b/e2e/dashboard.spec.ts @@ -1143,7 +1143,7 @@ test('a chart set tall, by settings or by its edge, fills the card it grew', asy }); // The editor's controls take the library's sizes: the page row is L, a card's tools and every overlay are M. -test('the editor page row is L and the card tools, settings and gallery are M, except segmented controls', async ({page}) => { +test('the editor page row, card tools, settings and gallery are all M, segmented controls included', async ({page}) => { await page.setViewportSize({width: 1280, height: 1000}); await page.goto('/#/activity'); await expect(tile(page, 'cpu').locator('.rp-tile-body')).toBeVisible(); @@ -1160,19 +1160,20 @@ test('the editor page row is L and the card tools, settings and gallery are M, e ); const row = page.locator('.rp-page-actions'); await expect(row.getByRole('button', {name: 'Done', exact: true})).toBeVisible(); - expect(new Set((await sizes(row)).map(String))).toEqual(new Set(['L,40'])); + expect(new Set((await sizes(row)).map(String))).toEqual(new Set(['M,32'])); await tile(page, 'cpu').hover(); const tools = tile(page, 'cpu').locator('.rp-dashboard-tools'); await expect(tools).toHaveCSS('opacity', '1'); expect(new Set((await sizes(tools)).map(([, size]) => size))).toEqual(new Set([32])); expect((await sizes(tools)).every(([size]) => size === null || size === 'M')).toBe(true); - // In the settings every segmented control is L, as everywhere, and the other controls stay M. + // In the settings every segmented control is M, as everywhere, and so are the other controls. const dialog = await settings(page, 'cpu'); const all = await sizes(dialog); const segmented = await sizes(dialog.locator('.rp-segfit')); - expect(new Set(segmented.map(String))).toEqual(new Set(['L,40'])); - expect(all.filter(([size]) => size === 'L')).toHaveLength(segmented.length); - expect(new Set(all.filter(([size]) => size !== 'L').map(String))).toEqual(new Set(['M,32'])); + expect(segmented.length).toBeGreaterThan(0); + expect(new Set(segmented.map(String))).toEqual(new Set(['M,32'])); + expect(all.filter(([size]) => size === 'L')).toHaveLength(0); + expect(new Set(all.map(String))).toEqual(new Set(['M,32'])); await close(page); await row.getByRole('button', {name: 'Widget gallery', exact: true}).click(); const gallery = page.getByRole('dialog'); @@ -1258,8 +1259,9 @@ test.describe('control row zh-TW', () => { expect(line.cut).toBe(false); } }); - test('stacks every card of the first row together when the lines do not fit, at 1280 px', async ({page}) => { - await page.setViewportSize({width: 1280, height: 900}); + // At M the row still fits at 1280 px; at 1200 px, with the sidebar shown, it does not. + test('stacks every card of the first row together when the lines do not fit, at 1200 px', async ({page}) => { + await page.setViewportSize({width: 1200, height: 900}); await page.goto('/#/activity'); await expect(quick(page)).toHaveAttribute('data-controls', 'stacked'); await expect(quick(page)).not.toHaveAttribute('data-fit'); diff --git a/e2e/nodes-phone.spec.ts b/e2e/nodes-phone.spec.ts index edb46d1c..8afb88ff 100644 --- a/e2e/nodes-phone.spec.ts +++ b/e2e/nodes-phone.spec.ts @@ -24,10 +24,10 @@ for (const width of [320, 360, 390]) expect(await size(refresh)).toEqual(await size(more)); expect(await size(paste)).toEqual(await size(refresh)); for (const button of [refresh, more, paste]) { - await expect(button).toHaveAttribute('data-size', 'L'); - expect((await size(button)).height).toBe(40); + await expect(button).toHaveAttribute('data-size', 'M'); + expect((await size(button)).height).toBe(36); } - // L keeps M's text size on a phone. + // M's text size on a phone. const controlFont = await refresh.evaluate(el => getComputedStyle(el).getPropertyValue('--rp-text-md').trim()); expect((await size(refresh)).fontSize).toBe(controlFont); const boxes = await Promise.all([refresh.boundingBox(), more.boundingBox()]); @@ -143,7 +143,7 @@ test('desktop subscription and node actions use the kit control text role', asyn for (const name of [/^Update \d+ subscriptions?$/, 'Add subscription', 'Paste node link']) { const button = page.getByRole('button', {name, exact: true}); await expect(button).toBeVisible(); - await expect(button).toHaveAttribute('data-size', 'L'); + await expect(button).toHaveAttribute('data-size', 'M'); const type = await button.evaluate(el => { const style = getComputedStyle(el); return { @@ -155,7 +155,7 @@ test('desktop subscription and node actions use the kit control text role', asyn }); expect(type.size).toBe(type.control); expect(type.weight).toBe('500'); - expect(type.height).toBe(40); + expect(type.height).toBe(32); } }); diff --git a/e2e/segmented-size.spec.ts b/e2e/segmented-size.spec.ts index 4e510e1d..ecce7ceb 100644 --- a/e2e/segmented-size.spec.ts +++ b/e2e/segmented-size.spec.ts @@ -3,8 +3,9 @@ import {expect, loadCatalogues, mockBackend, routes, settle, settleFrames, test} import {translate} from '../src/i18n'; import {defaultWidget, defaults, type Layout} from '../src/shell/widgets/layout'; -// Every segmented control is S2 size L (40px, on a phone too), its selected item fills it, and every control on its row -// is as tall and centred on the same line, on every page, in the widget panel and while editing the dashboard. +// Every segmented control is S2's default M (32px, the touch height on a phone), its selected item fills it, and every +// control on its row is as tall and centred on the same line, on every page, in the widget panel and while editing the +// dashboard. test.beforeAll(loadCatalogues); const t = (key: Parameters[1]) => translate('zh-TW', key); // The default panel with a group switch, whose network choice is a segmented control too. @@ -17,7 +18,7 @@ const save = (page: Page, layout: Layout) => // Failures for every segmented control under the scope; how many were measured comes back so a scope cannot pass empty. async function segmentedGeometry(scope: Locator) { return scope.evaluate(root => { - const large = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--rp-control-lg')); + const control = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--rp-control')); const rows = '.rp-toolbar, .rp-tabhead, .rp-page-actions, .rp-row, .rp-cluster, .rp-field-row'; const controls = '.rp-btn, .rp-input, .rp-selectbtn, .rp-select, .rp-switch, .rp-tab, .rp-segfit'; const failures: string[] = []; @@ -32,11 +33,11 @@ async function segmentedGeometry(scope: Locator) { const shown = collapsed ? fit.querySelector('.rp-segpick .rp-selectbtn')! : seg; const box = shown.getBoundingClientRect(); measured++; - if (off(seg.getBoundingClientRect().height, large)) failures.push(`${name}: track ${seg.getBoundingClientRect().height}`); - if (off(box.height, large)) failures.push(`${name}: shown ${box.height}`); + if (off(seg.getBoundingClientRect().height, control)) failures.push(`${name}: track ${seg.getBoundingClientRect().height}`); + if (off(box.height, control)) failures.push(`${name}: shown ${box.height}`); if (!collapsed) { const selected = seg.querySelector('.rp-btn[data-selected]')!.getBoundingClientRect(); - if (off(selected.height, large) || off(selected.top, box.top)) failures.push(`${name}: selected ${selected.top} ${selected.height}`); + if (off(selected.height, control) || off(selected.top, box.top)) failures.push(`${name}: selected ${selected.top} ${selected.height}`); } const centre = box.top + box.height / 2; for (let row = fit.parentElement?.closest(rows); row; row = row.parentElement?.closest(rows)) { @@ -92,13 +93,13 @@ for (const [width, phone] of [ await page.goto('/#/activity'); await settle(page); await expectSegmented(page.locator('.rp-content'), 'activity', 2); - // The control cards share one row with the outbound mode switch, so each of their controls is L. - const large = await page.evaluate(() => parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--rp-control-lg'))); + // The control cards share one row with the outbound mode switch, so each of their controls is M. + const control = await page.evaluate(() => parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--rp-control'))); const heights = await page .locator('.rp-control-card :is(.rp-btn, .rp-selectbtn, .rp-seg):not(.rp-seg .rp-btn)') .evaluateAll(nodes => nodes.filter(node => node.checkVisibility()).map(node => node.getBoundingClientRect().height)); expect(heights.length).toBeGreaterThanOrEqual(3); - expect(heights.filter(height => Math.abs(height - large) > 0.5)).toEqual([]); + expect(heights.filter(height => Math.abs(height - control) > 0.5)).toEqual([]); await page.getByRole('button', {name: t('dashboard.edit'), exact: true}).click(); await expect(page.locator('.rp-dashboard-tools').first()).toBeVisible(); await settleFrames(page); diff --git a/e2e/segmented.spec.ts b/e2e/segmented.spec.ts index dc9a00b6..e69dfb96 100644 --- a/e2e/segmented.spec.ts +++ b/e2e/segmented.spec.ts @@ -162,7 +162,7 @@ for (const width of [1440, 768, 390]) { const tabs = el.querySelector('.rp-tabbar')!; return { tabs: tabs.getBoundingClientRect().height, - control: parseFloat(getComputedStyle(el).getPropertyValue('--rp-control-lg')) + control: parseFloat(getComputedStyle(el).getPropertyValue('--rp-control')) }; }); expect(geometry.tabs).toBe(geometry.control); diff --git a/e2e/toolbar-height.spec.ts b/e2e/toolbar-height.spec.ts index 80cd6d66..e4709ad4 100644 --- a/e2e/toolbar-height.spec.ts +++ b/e2e/toolbar-height.spec.ts @@ -4,7 +4,7 @@ import type {Page} from '@playwright/test'; for (const width of [1280, 390]) { test.describe(`uniform page controls ${width}`, () => { test.use({viewport: {width, height: 900}, storage: {'doona-lang': 'zh-TW'}}); - test('every route and tab keeps fixed L page rows and uniform geometry', async ({page}) => { + test('every route and tab keeps M page rows and uniform geometry', async ({page}) => { test.setTimeout(120000); for (const route of routes) { await page.goto(`/#/${route}`); @@ -21,8 +21,8 @@ for (const width of [1280, 390]) { const failures: string[] = []; for (const row of await toolbarGeometry(page)) { const {controls} = row; - if (row.pageRow && controls.some(control => Math.abs(control.height - row.large) > 0.5)) - failures.push(`${route}/${index}: ${row.row}: not L ${JSON.stringify(controls)}`); + if (row.pageRow && controls.some(control => Math.abs(control.height - row.control) > 0.5)) + failures.push(`${route}/${index}: ${row.row}: not M ${JSON.stringify(controls)}`); if (row.pageRow && Math.max(...controls.map(control => control.height)) - Math.min(...controls.map(control => control.height)) > 0.5) failures.push(`${route}/${index}: unequal heights`); if (row.pageRow && Math.max(...controls.map(control => control.centre)) - Math.min(...controls.map(control => control.centre)) > 1) @@ -46,7 +46,7 @@ test.describe('tab and segment hover and press', () => { const radius = (locator: ReturnType) => locator.evaluate(el => getComputedStyle(el).borderTopLeftRadius); for (const [route, bar, item] of [ ['config', '.rp-content .rp-tabbar', '[role=tab]'], - ['rules', '.rp-content .rp-seg[data-size=L]', '.rp-btn'] + ['rules', '.rp-content .rp-seg[data-size=M]', '.rp-btn'] ]) { await page.goto(`/#/${route}`); const group = page.locator(bar).first(); @@ -67,7 +67,7 @@ test.describe('tab and segment hover and press', () => { }); }); -// A phone keeps L's 40px height but M's inline padding and text, so the rows lay out as they did at M. +// On a phone the page rows take the touch height and still lay out on as few lines as before. test.describe('page rows on a phone', () => { test.use({viewport: {width: 390, height: 900}, storage: {'doona-lang': 'zh-TW'}}); test('page links and tab rows stay on one line, and the connections toolbar is no taller than before', async ({page}) => { @@ -91,7 +91,7 @@ test.describe('page rows on a phone', () => { }); }); -// The lines the Connections toolbar took at 390px before the controls moved to L, on main. +// The lines the Connections toolbar took at 390px with its controls at M. const connectionsToolbarLinesBefore = 3; // How many lines the visible items inside the matching containers fill; items on one line share a top. @@ -129,7 +129,7 @@ async function toolbarGeometry(page: Page) { return page.locator('body').evaluate(root => { const rows = '.rp-toolbar, .rp-tabhead, .rp-tabbar, .rp-page-actions, .rp-page-links'; const localRows = '.rp-row, .rp-cluster, .rp-field-row'; - const large = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--rp-control-lg')); + const control = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--rp-control')); const controls = '.rp-btn, .rp-input, .rp-selectbtn, .rp-select, .rp-seg, .rp-switch, .rp-tab, .rp-tabbar'; return [...root.querySelectorAll(`${rows}, ${localRows}`)] .filter(row => row.checkVisibility({visibilityProperty: true})) @@ -168,7 +168,7 @@ async function toolbarGeometry(page: Page) { row.matches('[data-page-toolbar], [data-page-tabrow], .rp-page-actions, .rp-page-links') || !!row.closest('[data-page-toolbar], .rp-page-actions, .rp-page-links') || (!localSurface && !!row.closest(rows)); - return lines.map(line => ({row: row.className, pageRow, large, controls: line})); + return lines.map(line => ({row: row.className, pageRow, control, controls: line})); }); }); } diff --git a/e2e/widgets-review.spec.ts b/e2e/widgets-review.spec.ts index 8a112c6c..7e260f71 100644 --- a/e2e/widgets-review.spec.ts +++ b/e2e/widgets-review.spec.ts @@ -82,9 +82,9 @@ for (const host of ['panel', 'dashboard'] as const) { await page.evaluate(() => document.fonts.ready); const before = (await widget.boundingBox())!; // The picker is as wide as its widest outbound, so whether the title shares the line is settled before a draft: the - // dashboard card, alone in quick's first track, stacks the title above the large picker and Apply, which stay on - // one line. - const inline = host === 'panel'; + // dashboard card, alone in quick's first track, shares the line with the M picker and Apply at 1280px and stacks + // the title above them at 390px; the picker and Apply stay on one line. + const inline = host === 'panel' || width === 1280; const section = page.locator('.rp-dash-section').filter({has: widget}); if (host === 'dashboard') await expect(section).toHaveAttribute('data-controls', inline ? 'inline' : 'stacked'); const line = async () => { diff --git a/src/features/activity/ActivityCard.tsx b/src/features/activity/ActivityCard.tsx index 3cadbaba..647b762f 100644 --- a/src/features/activity/ActivityCard.tsx +++ b/src/features/activity/ActivityCard.tsx @@ -84,7 +84,7 @@ function MetricModule({kind, scale}: {kind: Parameters[0]; s switch (kind) { case 'status': content = ( - +
{vm.status.text}
diff --git a/src/features/activity/ModeSwitch.tsx b/src/features/activity/ModeSwitch.tsx index 4ccffadd..f83b9ffc 100644 --- a/src/features/activity/ModeSwitch.tsx +++ b/src/features/activity/ModeSwitch.tsx @@ -1,7 +1,6 @@ import {useLang, useT} from '../../i18n'; import {docsHref} from '../shared/docs'; import {Button, Card, ErrorMessage, Light, Link, ChoiceMenu, PopoverDialog, Segmented, WidestLabel} from '../../ui/ui'; -import {ControlSizeContext} from '../../ui/controlSize'; import Shuffle from '../../ui/icons/Shuffle'; import Filter from '../../ui/icons/Filter'; type ModeCardsModel = { @@ -37,40 +36,37 @@ export function ModeApply({model: vm}: {model: Pick - - - {vm.writable ? ( - - ) : vm.readOnly ? ( - - {vm.status} - - } - > - {() => ( - <> -

{t('act.modeReadOnlyReason')}

-

{t('act.modeReadOnlyAction')}

- - {t('act.readOnlyDocs')} - - - )} -
- ) : ( - - {vm.status} - - )} -
- + + + {vm.writable ? ( + + ) : vm.readOnly ? ( + + {vm.status} + + } + > + {() => ( + <> +

{t('act.modeReadOnlyReason')}

+

{t('act.modeReadOnlyAction')}

+ + {t('act.readOnlyDocs')} + + + )} +
+ ) : ( + + {vm.status} + + )} +
); } @@ -84,7 +80,6 @@ export function ModeCards({model: vm, part}: {model: ModeCardsModel; part?: 'mod title={t('act.mode')} aria-label={t('act.mode')} tile={{icon: , tint: 3, kind: 'control'}} - size="L" reason={vm.reasons.mode} aside={} /> @@ -93,7 +88,6 @@ export function ModeCards({model: vm, part}: {model: ModeCardsModel; part?: 'mod , tint: 2, kind: 'control'}} - size="L" reason={vm.reasons.global} aside={ diff --git a/src/ui/PageActions.tsx b/src/ui/PageActions.tsx index 9c65a64c..b1396065 100644 --- a/src/ui/PageActions.tsx +++ b/src/ui/PageActions.tsx @@ -1,9 +1,8 @@ import {createContext, useContext, type ReactNode} from 'react'; import {createPortal} from 'react-dom'; -import {ControlSizeContext} from './controlSize'; export const PageActionsTarget = createContext(null); export function PageActions({children}: {children: ReactNode}) { const target = useContext(PageActionsTarget); - return target ? createPortal({children}, target) : null; + return target ? createPortal(children, target) : null; } diff --git a/src/ui/PageLinks.tsx b/src/ui/PageLinks.tsx index b6c138d4..14128779 100644 --- a/src/ui/PageLinks.tsx +++ b/src/ui/PageLinks.tsx @@ -1,16 +1,13 @@ import {Link} from './Link'; -import {ControlSizeContext} from './controlSize'; export function PageLinks({label, items}: {label: string; items: {id: string; href: string; label: string; current?: boolean}[]}) { return ( - - - + ); } diff --git a/src/ui/Segmented.tsx b/src/ui/Segmented.tsx index e171549d..f36fe421 100644 --- a/src/ui/Segmented.tsx +++ b/src/ui/Segmented.tsx @@ -5,8 +5,7 @@ import {LabeledSelect} from './Picker'; // S2 does not scroll a segmented control: one too wide for its space collapses into a picker, as S2 Tabs do. The hidden // track keeps its box, so the switch moves nothing, and is measured to tell when the items fit again. -// Every segmented control is S2 size L (40px) wherever it sits, so all of them match; a row that holds one provides L to -// the controls beside it. +// S2's SegmentedControl has no size: it is always M (32px), as are the default controls beside it. export function Segmented({ items, value, @@ -24,7 +23,6 @@ export function Segmented({ fill?: boolean; }) { const [ref, pos] = useSlider(value); - const controlSize = 'L'; const collapsed = useOverflow(ref, items.flat().join('\n')); // Focus inside the control follows it across the switch, so it is neither hidden nor dropped to the page; focus // elsewhere stays. The picker's ref detaches before the picker leaves the page, while it can still hold focus. @@ -47,7 +45,7 @@ export function Segmented({ {pos && } {items.map(([k, l]) => ( - + {l} ))} {collapsed && (
- ({id, label: l}))} - /> + ({id, label: l}))} />
)}
diff --git a/src/ui/Tabs.tsx b/src/ui/Tabs.tsx index 40b4a623..a43bc1b6 100644 --- a/src/ui/Tabs.tsx +++ b/src/ui/Tabs.tsx @@ -25,13 +25,12 @@ export function Tabs({ // Controls at the end of the tab row, such as a filter for the panel shown; they wrap under the tabs on a phone. // Passing the prop, even as null, keeps the row, so the tab bar is not remounted when the controls come and go. actions?: ReactNode; - // A page's own tab row: its tabs and controls are L, as page toolbars are. + // A page's own tab row, measured as one of the page's toolbars. Its tabs are M, S2's compact Tabs height (32px). page?: boolean; }) { // The marker sits beside the TabList: anything inside it joins the RAC collection and re-renders the tabs. const [ref, pos] = useSlider(value, '[data-selected]'); - const inherited = useControlSize(); - const controlSize = page ? 'L' : inherited; + const controlSize = useControlSize(); // On a phone the bar scrolls: the selected tab stays in view and a faded end shows there are more tabs. useScrollStrip(ref, value); // The selected tab and its marker answer the click in the urgent render; a panel opened for the first time (a diff --git a/src/ui/Toolbar.tsx b/src/ui/Toolbar.tsx index 72676e6d..abbbfa2b 100644 --- a/src/ui/Toolbar.tsx +++ b/src/ui/Toolbar.tsx @@ -1,12 +1,10 @@ import type {ComponentProps, ReactNode} from 'react'; -import {ControlSizeContext} from './controlSize'; import {cx} from './cx'; export function Toolbar({page, className, children, ...props}: ComponentProps<'div'> & {page?: boolean; children?: ReactNode}) { - const row = ( + return (
{children}
); - return page ? {row} : row; } diff --git a/src/ui/controlSize.ts b/src/ui/controlSize.ts index ac168788..e36e0eb9 100644 --- a/src/ui/controlSize.ts +++ b/src/ui/controlSize.ts @@ -1,9 +1,10 @@ import {createContext, useContext} from 'react'; -// S2's control sizes: M is 32px (36px on touch), L is 40px. A page toolbar or tab row provides L and wins over a -// control's own prop, so nothing in it can break the row; a card, dialog or popover resets to none. +// S2's control sizes: M is 32px (36px on touch), L is 40px. Every control is M unless it asks for L; a control's own +// prop wins over the size a card provides, and a dialog or popover resets to none. export type ControlSize = 'M' | 'L'; export const ControlSizeContext = createContext(null); export function useControlSize(size?: ControlSize): ControlSize { - return useContext(ControlSizeContext) ?? size ?? 'M'; + const provided = useContext(ControlSizeContext); + return size ?? provided ?? 'M'; } diff --git a/src/ui/styles/buttons-menus.css b/src/ui/styles/buttons-menus.css index 8a48d4ef..a83b02ef 100644 --- a/src/ui/styles/buttons-menus.css +++ b/src/ui/styles/buttons-menus.css @@ -41,7 +41,7 @@ width: 16px; height: 16px; } -.rp-btn.sm:not([data-size='L']) { +.rp-btn.sm { --rp-icon-size: 1lh; padding: 0 var(--rp-space-2); font-size: var(--rp-text-xs); @@ -57,10 +57,12 @@ padding-inline: var(--rp-lg-inset-btn); font-size: var(--rp-lg-text); line-height: var(--rp-line-body); + border-radius: calc(var(--rp-control-lg) / 2); } .rp-btn.icon[data-size='L'] { width: var(--rp-control-lg); padding: 0; + border-radius: var(--rp-lg-radius); } .rp-btn.accent { background: var(--rp-accent); diff --git a/src/ui/styles/controlSize.test.ts b/src/ui/styles/controlSize.test.ts index 7340bc67..da6a44db 100644 --- a/src/ui/styles/controlSize.test.ts +++ b/src/ui/styles/controlSize.test.ts @@ -2,7 +2,7 @@ import {createElement} from 'react'; import {renderToStaticMarkup} from 'react-dom/server'; import {transform, type Selector} from 'lightningcss'; import {expect, it} from 'vitest'; -import {ControlSizeContext} from '../controlSize'; +import {ControlSizeContext, useControlSize} from '../controlSize'; import {Segmented} from '../Segmented'; import segmentedCss from './segmented.css?raw'; @@ -95,7 +95,8 @@ it('rejects page, one-off and literal control sizing, including logical sizes an expect(violations('.rp-btn > svg {height: 16px}', 'buttons-menus.css')).toEqual([]); }); -// Every segmented control is S2 size L (40px), so a time range in a card matches a page filter. +// Every segmented control is S2's default M (32px), as S2's SegmentedControl has no size, so a time range in a card +// matches a page filter. function segmentedHeights(css: string): string[] { const values: string[] = []; transform({ @@ -117,16 +118,28 @@ function segmentedHeights(css: string): string[] { return values; } -it('sizes every segmented control at L only', () => { +it('sizes every segmented control at M only', () => { const heights = segmentedHeights(segmentedCss); expect(heights.length).toBeGreaterThan(0); - expect(heights.filter(value => !value.includes('"--rp-control-lg"'))).toEqual([]); + expect(heights.filter(value => !value.includes('"--rp-control"'))).toEqual([]); const items: Array<[string, string]> = [ ['a', 'A'], ['b', 'B'] ]; const segmented = createElement(Segmented, {items, value: 'a', onChange: () => {}, label: 'Range'}); - for (const markup of [renderToStaticMarkup(segmented), renderToStaticMarkup(createElement(ControlSizeContext, {value: null}, segmented))]) { - expect(markup.match(/data-size="[^"]*"/g)).toEqual(Array(3).fill('data-size="L"')); + for (const value of [null, 'M', 'L'] as const) { + const markup = renderToStaticMarkup(createElement(ControlSizeContext, {value}, segmented)); + expect(markup.match(/data-size="[^"]*"/g)).toEqual(Array(3).fill('data-size="M"')); } }); + +// A control is M unless it asks for L; its own size wins over the size a card provides. +it('lets a control size win over the provided size', () => { + const Probe = ({size}: {size?: 'M' | 'L'}) => useControlSize(size); + const render = (value: 'M' | 'L' | null, size?: 'M' | 'L') => renderToStaticMarkup(createElement(ControlSizeContext, {value}, createElement(Probe, {size}))); + expect(render(null)).toBe('M'); + expect(render('L')).toBe('L'); + expect(render('L', 'M')).toBe('M'); + expect(render('M', 'L')).toBe('L'); + expect(render(null, 'L')).toBe('L'); +}); diff --git a/src/ui/styles/dialogs-search.css b/src/ui/styles/dialogs-search.css index 10f7c175..4ed5c36b 100644 --- a/src/ui/styles/dialogs-search.css +++ b/src/ui/styles/dialogs-search.css @@ -14,9 +14,10 @@ } .rp-select[data-size='L'] { height: var(--rp-control-lg); - padding-inline: var(--rp-lg-inset-compact); + padding-inline: var(--rp-lg-inset-field); font-size: var(--rp-lg-text-compact); line-height: var(--rp-line-body); + border-radius: var(--rp-lg-radius); } .rp-select[data-hovered] { background: var(--rp-fill); @@ -78,6 +79,7 @@ height: var(--rp-control-lg); padding-inline: var(--rp-lg-inset-field); font-size: var(--rp-lg-text); + border-radius: var(--rp-lg-radius); } /* The field's own glyphs match button icons: 16px in the 32px field, 20px in the large header search. */ .rp-input .rp-icon { diff --git a/src/ui/styles/fields.css b/src/ui/styles/fields.css index 2bbcaf47..0480cdd4 100644 --- a/src/ui/styles/fields.css +++ b/src/ui/styles/fields.css @@ -230,6 +230,7 @@ height: var(--rp-control-lg); padding-inline: var(--rp-lg-inset-field); font-size: var(--rp-lg-text); + border-radius: var(--rp-lg-radius); } .rp-switch[data-size='L'] { min-height: var(--rp-control-lg); diff --git a/src/ui/styles/foundations.css b/src/ui/styles/foundations.css index d6c940fa..24394390 100644 --- a/src/ui/styles/foundations.css +++ b/src/ui/styles/foundations.css @@ -87,7 +87,6 @@ --rp-focus-width: 2px; --rp-focus-color: var(--rp-accent); --rp-focus-offset: var(--rp-space-half); - --rp-control-inset: var(--rp-space-half); /* Segment items fill the track's height at every size, so a selected segment is as tall as the button beside it. */ --rp-control-block-inset: 0px; /* Global stacking, low to high: the floating panel, then modals and tooltips (tooltips are portaled after the modal @@ -102,11 +101,14 @@ --rp-scrollbar: 6px; --rp-control: 32px; --rp-control-lg: 40px; - /* L's inline padding; phones take M's (below), so a row of L controls fits as a row of M controls does. L's text is M's text size at every width. */ + /* L's inline padding; phones take M's (below), so a row of L controls fits as a row of M controls does. */ --rp-lg-inset-btn: calc(var(--rp-control-lg) / 2); --rp-lg-inset-field: calc(var(--rp-control-lg) * 3 / 8); - --rp-lg-inset-compact: calc(var(--rp-control-lg) * 3 / 8); - --rp-lg-text: var(--rp-text-md); + /* A segmented item's inline padding: S2's M inset, M's tighter 8px on a phone so the rows fit as before. */ + --rp-inset-compact: var(--rp-space-3); + --rp-lg-text: var(--rp-text-lg); + /* S2's L corner: 9px on an action button, picker or field; a Button is a pill. */ + --rp-lg-radius: 9px; --rp-lg-text-compact: var(--rp-text-lg); --rp-control-xs: 24px; --rp-duration: 150ms; @@ -148,7 +150,7 @@ --rp-control: 36px; --rp-lg-inset-btn: var(--rp-space-3); --rp-lg-inset-field: var(--rp-space-3); - --rp-lg-inset-compact: var(--rp-space-2); + --rp-inset-compact: var(--rp-space-2); --rp-lg-text-compact: var(--rp-text-xs); } } diff --git a/src/ui/styles/page-layout.css b/src/ui/styles/page-layout.css index a297625b..9ab3cb30 100644 --- a/src/ui/styles/page-layout.css +++ b/src/ui/styles/page-layout.css @@ -505,7 +505,7 @@ justify-content: space-between; gap: var(--rp-space-3); min-inline-size: 0; - min-block-size: var(--rp-control-lg); + min-block-size: var(--rp-control); } .rp-page-actions { margin-inline-start: auto; diff --git a/src/ui/styles/segmented.css b/src/ui/styles/segmented.css index 60e04328..49670bd1 100644 --- a/src/ui/styles/segmented.css +++ b/src/ui/styles/segmented.css @@ -6,24 +6,11 @@ gap: var(--rp-space-1); max-width: 100%; background: var(--rp-overlay); - border-radius: var(--rp-r-lg); - padding: var(--rp-control-block-inset) var(--rp-control-inset); + /* S2's default: the items sit flush in the track, which takes their height and radius. */ + min-block-size: var(--rp-control); + border-radius: var(--rp-r-md); position: relative; } -/* Always S2 size L (40px): every segmented control matches, in a page toolbar, a card or a panel alike. */ -.rp-seg[data-size='L'] { - min-block-size: var(--rp-control-lg); -} -/* Flush with the track at L, so the items and the slider take the track's radius, as a tab does. */ -.rp-seg[data-size='L'] > .rp-slider, -.rp-seg[data-size='L'] .rp-btn { - border-radius: var(--rp-r-lg); -} -.rp-seg[data-size='L'] .rp-btn { - height: var(--rp-control-lg); - padding-inline: var(--rp-lg-inset-compact); - font-size: var(--rp-lg-text); -} /* Too narrow for its items, the track stays as a hidden placeholder and a picker sits over it at the same height. The track hugs its items in a column or a grid too, where a flex or grid item would otherwise stretch. */ .rp-segfit { @@ -87,7 +74,7 @@ } .rp-seg .rp-btn { flex: none; - padding: 0 var(--rp-space-2); + padding: 0 var(--rp-inset-compact); min-height: 0; background: transparent; color: var(--rp-text);