feat(ui): standardize inspector spacing and compact level geometry
This commit is contained in:
@@ -19,6 +19,9 @@ export interface InspectorSectionSpec {
|
||||
|
||||
export interface InspectorProps {
|
||||
sections: InspectorSectionSpec[];
|
||||
/** Spaced form fields above sections and centered actions below them. */
|
||||
header?: ReactNode;
|
||||
footer?: ReactNode;
|
||||
defaultOpen?: string[];
|
||||
openSections?: string[];
|
||||
activeId?: string;
|
||||
@@ -31,6 +34,8 @@ export interface InspectorProps {
|
||||
|
||||
export function Inspector({
|
||||
sections,
|
||||
header,
|
||||
footer,
|
||||
defaultOpen = [],
|
||||
openSections,
|
||||
activeId,
|
||||
@@ -70,6 +75,7 @@ export function Inspector({
|
||||
return (
|
||||
<InspectorSelectPolicyContext.Provider value>
|
||||
<div className={cn("nodedc-inspector", className)} data-variant={variant === "default" ? undefined : variant}>
|
||||
{header ? <div className="nodedc-inspector__header">{header}</div> : null}
|
||||
{groups.map((group, groupIndex) => (
|
||||
<div className="nodedc-inspector__group" key={`${group.label ?? "root"}-${groupIndex}`}>
|
||||
{group.sections.map((section) => {
|
||||
@@ -107,6 +113,7 @@ export function Inspector({
|
||||
})}
|
||||
</div>
|
||||
))}
|
||||
{footer ? <div className="nodedc-inspector__footer">{footer}</div> : null}
|
||||
</div>
|
||||
</InspectorSelectPolicyContext.Provider>
|
||||
);
|
||||
|
||||
@@ -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<ButtonProps,'children'|'shape'|'value'> {
|
||||
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<ButtonProps,'children'|'shape'|'v
|
||||
fillColor?:string;
|
||||
}
|
||||
/** Compact measured resource level which opens details, with native button semantics. */
|
||||
export function LevelButton({label,value,valueText,freshness='live',levelTone='neutral',fillColor,className,style,...props}:LevelButtonProps){
|
||||
export function LevelButton({label,value,valueText,freshness='live',levelTone='neutral',fillColor,geometry,className,style,...props}:LevelButtonProps){
|
||||
const fraction=typeof value==='number'&&Number.isFinite(value)?Math.max(0,Math.min(1,value)):null;
|
||||
const custom=typeof fillColor==='string'&&/^#[0-9a-f]{6}$/i.test(fillColor)?fillColor:null;
|
||||
const channels=custom?.slice(1).match(/../g)?.map(v=>{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 <Button {...props} shape="pill" className={cn('nodedc-level-button',className)}
|
||||
aria-label={`${label}: ${text}${freshness==='stale'?' · последние показания':''}`}
|
||||
data-level-tone={levelTone} data-freshness={freshness} data-custom-fill={custom?true:undefined}
|
||||
style={{...style,'--nodedc-level-percent':`${(fraction??0)*100}%`,...(custom?{'--nodedc-level-custom':custom,'--nodedc-level-ink':ink}:{})} as CSSProperties}><span aria-hidden="true">{text}</span>{custom&&fraction!==null&&<span aria-hidden="true" className="nodedc-level-button__fill">{text}</span>}</Button>;
|
||||
style={{...style,...levelButtonGeometry(geometry,text.length),'--nodedc-level-percent':`${(fraction??0)*100}%`,...(custom?{'--nodedc-level-custom':custom,'--nodedc-level-ink':ink}:{})} as CSSProperties}><span aria-hidden="true">{text}</span>{custom&&fraction!==null&&<span aria-hidden="true" className="nodedc-level-button__fill">{text}</span>}</Button>;
|
||||
}
|
||||
|
||||
@@ -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})`};
|
||||
}
|
||||
Reference in New Issue
Block a user