From be929f9d8e58f4b99ca14b8bd3794bc2d0bd2be1 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 18:18:10 +0300 Subject: [PATCH] feat(ui): standardize inspector spacing and compact level geometry --- apps/catalog/src/CatalogApp.tsx | 4 +++- docs/COMPONENTS.md | 5 +++++ docs/LEVEL_BUTTON.md | 6 ++++++ packages/ui-core/styles.css | 9 ++++++--- packages/ui-react/src/Inspector.tsx | 7 +++++++ packages/ui-react/src/LevelButton.tsx | 8 ++++++-- packages/ui-react/src/levelButtonGeometry.ts | 10 ++++++++++ registry/components.json | 9 ++++++--- scripts/control-density-contract.test.mjs | 16 ++++++++++++++++ scripts/inspector-select-contract.test.mjs | 9 +++++++++ 10 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 packages/ui-react/src/levelButtonGeometry.ts diff --git a/apps/catalog/src/CatalogApp.tsx b/apps/catalog/src/CatalogApp.tsx index 3d20077..0715ebd 100644 --- a/apps/catalog/src/CatalogApp.tsx +++ b/apps/catalog/src/CatalogApp.tsx @@ -1508,6 +1508,8 @@ export function CatalogApp() { + + @@ -2357,7 +2359,7 @@ export function CatalogApp() { draggable onClose={() => setInspectorOpen(false)} > - + Поля и секции разделены единым шагом 12 px.} footer={} sections={environmentSections} defaultOpen={["application-material"]} />
+ {header ?
{header}
: null} {groups.map((group, groupIndex) => (
{group.sections.map((section) => { @@ -107,6 +113,7 @@ export function Inspector({ })}
))} + {footer ?
{footer}
: null}
); diff --git a/packages/ui-react/src/LevelButton.tsx b/packages/ui-react/src/LevelButton.tsx index ae981a9..fd3f046 100644 --- a/packages/ui-react/src/LevelButton.tsx +++ b/packages/ui-react/src/LevelButton.tsx @@ -1,9 +1,13 @@ +import {levelButtonGeometry,type LevelButtonGeometry} from './levelButtonGeometry.js'; +export type {LevelButtonGeometry} from './levelButtonGeometry.js'; import type {CSSProperties} from 'react'; import {Button,type ButtonProps} from './Button.js'; import {cn} from './cn.js'; export interface LevelButtonProps extends Omit { label:string; + /** Optional operator geometry; text and padding shrink together below 64 × 24. */ + geometry?:LevelButtonGeometry; /** Measured fraction. Missing is unknown, never zero or animated progress. */ value?:number|null; valueText?:string; @@ -13,7 +17,7 @@ export interface LevelButtonProps extends Omit{const c=parseInt(v,16)/255;return c<=.04045?c/12.92:((c+.055)/1.055)**2.4;}); @@ -22,5 +26,5 @@ export function LevelButton({label,value,valueText,freshness='live',levelTone='n return ; + style={{...style,...levelButtonGeometry(geometry,text.length),'--nodedc-level-percent':`${(fraction??0)*100}%`,...(custom?{'--nodedc-level-custom':custom,'--nodedc-level-ink':ink}:{})} as CSSProperties}>{custom&&fraction!==null&&}; } diff --git a/packages/ui-react/src/levelButtonGeometry.ts b/packages/ui-react/src/levelButtonGeometry.ts new file mode 100644 index 0000000..c68d306 --- /dev/null +++ b/packages/ui-react/src/levelButtonGeometry.ts @@ -0,0 +1,10 @@ +import type {CSSProperties} from 'react'; +export type LevelButtonGeometry={width:number;height:number;radius?:number}; +/** Keep type and padding proportional when the operator chooses a tiny indicator. */ +export function levelButtonGeometry(value:LevelButtonGeometry|undefined,characters:number):CSSProperties{ + if(!value)return {}; + const bounded=(n:number|undefined,fallback:number,min:number,max:number)=>typeof n==='number'&&Number.isFinite(n)?Math.max(min,Math.min(max,n)):fallback; + const width=bounded(value.width,115,32,4096),height=bounded(value.height,46,12,1024),radius=bounded(value.radius,999,0,4096); + const scale=Math.min(1,height/24,width/Math.max(64,(characters+2)*8)); + return {width,minWidth:width,height,minHeight:height,borderRadius:radius,flexShrink:0,fontSize:`calc(var(--nodedc-font-size-md) * ${scale})`,lineHeight:1,padding:`calc(0.25rem * ${scale}) calc(var(--nodedc-space-2) * ${scale})`}; +} diff --git a/registry/components.json b/registry/components.json index f9d2825..cbf03b2 100644 --- a/registry/components.json +++ b/registry/components.json @@ -1096,7 +1096,8 @@ "Inspector selection fields use InspectorSelectField only: a stacked visible label and the 276/8/46 px split control; integrated pills are prohibited.", "The panel variant reuses AdminNavigationPanel pill, icon and theme tokens while retaining the same controlled accordion state and domain-owned content.", "A section action is a sibling IconButton before the disclosure chevron, never nested in the trigger. It does not toggle the section. Panel chevrons point down when collapsed and up when expanded.", - "Accent-filled section headers belong to Environment Settings; neutral headers remain available for other approved inspector contexts." + "Accent-filled section headers belong to Environment Settings; neutral headers remain available for other approved inspector contexts.", + "Default sections and optional header fields use the canonical 12 px spacing token; footer actions are centered with the same gap. Nested Inspectors retain this rhythm; the panel variant retains its compact row geometry." ] }, { @@ -1368,7 +1369,8 @@ "package": "@nodedc/ui-react", "exports": [ "LevelButton", - "LevelButtonProps" + "LevelButtonProps", + "LevelButtonGeometry" ], "domContract": [ "nodedc-level-button" @@ -1377,7 +1379,8 @@ "rules": [ "Consumer supplies a measured fraction and freshness; unknown is not zero.", "Stale retains the last number and accessible stale text; explicit user fill colours are retained.", - "Keyboard, focus, disabled and pointer behavior come from Button. Explicit fillColor uses contrast-correct text on the filled portion." + "Keyboard, focus, disabled and pointer behavior come from Button. Explicit fillColor uses contrast-correct text on the filled portion.", + "Optional geometry sets width, height and radius with a 32 × 12 px minimum. At small dimensions the text and padding shrink proportionally; both contrast layers share the same type geometry. Consumer owns header-group offset." ], "documentation": "../docs/LEVEL_BUTTON.md" } diff --git a/scripts/control-density-contract.test.mjs b/scripts/control-density-contract.test.mjs index 78604e5..f1a1da4 100644 --- a/scripts/control-density-contract.test.mjs +++ b/scripts/control-density-contract.test.mjs @@ -47,3 +47,19 @@ test("viewport controls share one scale without scaling nested controls twice", assert.match(styles, /\.nodedc-segmented\) :is\([^}]+zoom: 1;/); assert.ok(JSON.parse(registrySource).components.find(c=>c.id==='button').domContract.includes('nodedc-viewport-controls')); }); + +import { LevelButton } from "../packages/ui-react/dist/index.js"; +import { levelButtonGeometry } from "../packages/ui-react/dist/levelButtonGeometry.js"; +test("compact level indicators fit both contrast layers with proportional text and padding", () => { + const tiny=levelButtonGeometry({width:32,height:12,radius:4},4); + const normal=levelButtonGeometry({width:64,height:24,radius:8},4); + assert.equal(tiny.fontSize,'calc(var(--nodedc-font-size-md) * 0.5)'); + assert.equal(tiny.padding,'calc(0.25rem * 0.5) calc(var(--nodedc-space-2) * 0.5)'); + assert.equal(normal.fontSize,'calc(var(--nodedc-font-size-md) * 1)'); + assert.equal(levelButtonGeometry({width:-1,height:NaN},4).width,32); + assert.equal(levelButtonGeometry({width:-1,height:NaN},4).height,46); + const markup=renderToStaticMarkup(createElement(LevelButton,{value:1,label:'Battery',fillColor:'#ffffff',geometry:{width:32,height:12,radius:4}})); + assert.match(markup,/width:32px/);assert.match(markup,/height:12px/); + assert.match(markup,/nodedc-level-button__fill/); + assert.match(markup,/100/);assert.match(markup,/aria-label="Battery: 100%"/); +}); diff --git a/scripts/inspector-select-contract.test.mjs b/scripts/inspector-select-contract.test.mjs index 036b47a..ebf6dd8 100644 --- a/scripts/inspector-select-contract.test.mjs +++ b/scripts/inspector-select-contract.test.mjs @@ -59,3 +59,12 @@ test("Foundry Inspector screens consume the semantic selection field", async () assert.equal((catalog.match(/{ + const markup=renderToStaticMarkup(createElement(Inspector,{header:'Form fields',footer:'Action',sections:[{id:'surface',label:'Surface',content:'Controls'},{id:'textures',label:'Textures',content:'Slots'}]})); + assert.ok(markup.indexOf('nodedc-inspector__header')markup.lastIndexOf('nodedc-inspector__section')); + const css=await readFile(new URL('../packages/ui-core/styles.css',import.meta.url),'utf8'); + assert.match(css,/\.nodedc-inspector__group\s*\{[^}]*gap: var\(--nodedc-space-3\)/); + assert.match(css,/\.nodedc-inspector__footer\s*\{[^}]*justify-content: center/); +});