import * as React from 'react'; import { useKnobTheme } from '../core/theme'; export interface LabeledFieldProps { /** Field name printed beside the control. */ label: string; /** The control (a knob, fader, ScrubField, ToggleSwitch, …). */ children: React.ReactNode; /** Unit printed after the control, e.g. "px", "dB". */ unit?: string; /** * Label column width — set the same value on a stack of fields so their * controls line up. Number = px. Default: auto. */ labelWidth?: number | string; /** 'row' (label · control · unit, default) or 'column' (label above). */ orientation?: 'row' | 'column'; /** Push the control to the right edge of the row. Default: false. */ spread?: boolean; gap?: number; labelColor?: string; className?: string; style?: React.CSSProperties; } /** * One aligned inspector row: a label, a control and an optional unit. Give a * stack of fields the same `labelWidth` and their controls line up — the * boilerplate every properties panel rewrites, owned in one place. */ export const LabeledField: React.FC = ({ label, children, unit, labelWidth, orientation = 'row', spread = false, gap = 10, labelColor, className, style, }) => { const theme = useKnobTheme(); const column = orientation === 'column'; const labelEl = ( {label} ); return (
{labelEl}
{children} {unit && ( {unit} )}
); };