Inspector Panel
One property group of a design tool's side panel: a header with its switches and actions, and rows of fields.
import { InspectorPanel, InspectorPanelType, InspectorRow } from '@youj/react'
Installation & usage
npm i @youj/reactFor an app already set up with npx @youj/cli init, which installs the peers (@youj/core, @youj/motion, motion and Base UI) and wires the provider. New app? Start at Installation.
Use it to build the side panel of an editor: one panel per property group, stacked. The body is rows; a row is a label on the left and one or two fields on a two-column grid. Scrub Number Field and Color Opacity Field are made for it, and any other field fits. For the whole panel with a live preview, see the Effects inspector block.
import { InspectorPanel, InspectorRow, ScrubNumberField } from '@youj/react'
export function BlurPanel({ blur, onBlur }: { blur: number; onBlur: (blur: number) => void }) {
return (
<InspectorPanel title="Layer blur" enabled onEnabledChange={() => {}} onRemove={() => {}}>
<InspectorRow label="Amount">
<ScrubNumberField size="sm" aria-label="Amount" label="A" unit="px" min={0} value={blur} onValueChange={onBlur} />
</InspectorRow>
</InspectorPanel>
)
}The state is yours: enabled, visible and type are controlled, and open follows defaultOpen until you control it.
Description
A shadow group with every part of the header.
The header holds, from the left: a checkbox that switches the group on or off, the title (a menu when you give it types), and on the right an eye, a plus, a trash and a chevron. Each appears when its props are given. Switched off, the body dims and every field in it is disabled. The chevron folds the body away.
Code
inspector-panel-demo.tsx, the Demo story. The component itself comes from the package.
Reference
Propstitle, enabled, types, visible, onAdd, onRemove, open…
Props
| Prop | Type | |
|---|---|---|
titleRequired | stringThe group's name. It names the section, and the remove button ("Remove Drop shadow"). | – |
enabled | booleanThe checkbox in front of the title (controlled). Leave it out for no checkbox. | – |
onEnabledChange | (enabled: boolean) => void | – |
types | InspectorPanelType[]Turns the title into a menu of these kinds. | – |
type | stringThe chosen kind's value. | – |
onTypeChange | (type: string) => void | – |
visible | booleanThe eye's state (controlled): false is hidden. Leave it out for no eye. | – |
onVisibleChange | (visible: boolean) => void | – |
onAdd | () => voidShows a plus button. | – |
onRemove | () => voidShows a trash button. | – |
actions | ReactNodeHeader actions placed before the eye, plus and trash buttons. | – |
open | booleanWhether the body is open (controlled). | – |
defaultOpen | booleanWhether the body starts open (uncontrolled). default true | true |
onOpenChange | (open: boolean) => void | – |
children | ReactNode | – |
Other props pass through: extends ComponentProps<'div'>. | ||
Inspector Row
| Prop | Type | |
|---|---|---|
labelRequired | ReactNodeThe row's name, on the left. | – |
childrenRequired | ReactNodeOne or two fields: two share the width. | – |
Other props pass through: extends ComponentProps<'div'>. | ||
Data attributes
The panel carries data-slot="inspector-panel", data-yj-enabled and data-yj-visible (true or false, when their props are given) and Base UI's data-open while the body is open. The header is inspector-panel-header, the type menu's trigger inspector-panel-type, and the body inspector-panel-body.
MotionFold · reduced motion
Motion
| Moment | Tokens | ||
|---|---|---|---|
| Fold and unfoldthe body eases between zero and its height while its content fades | duration.baseease.standard220ms · cubic-bezier(0.2, 0, 0, 1) | 220mscubic-bezier(0.2, 0, 0, 1) | |
| Switched offthe body dims | duration.fastease.standard140ms · cubic-bezier(0.2, 0, 0, 1) | 140mscubic-bezier(0.2, 0, 0, 1) |
Reduced motion
The body opens and closes at once, and dims without a fade.
Reduced motion
Folding and dimming happen at once; the chevron turns over without a spring.
AccessibilitySection, header controls, disabled body
Accessibility
- The panel is a
sectionnamed by its title. A row's fields are agroupnamed by the row's label. - The checkbox is named "Enable" followed by the title. The eye says what it will do ("Hide", or "Show" while hidden) and is a toggle (
aria-pressed). The plus is "Add", the trash "Remove" and the title, and the chevron "Collapse" or "Expand" witharia-expanded. All of these are translated through the labels. - With
types, the title is a menu button named "Change type" and the title. Arrow keys move through the kinds, Enter picks one and Escape closes it. - Switched off, the body is a disabled
fieldset, so nothing in it is reachable until the checkbox is on again.