Property inspector
A design tool’s inspector: dense label-and-control rows in a dark panel. PropertyGroup and PropertyRow are app-owned compositions of Stack and Text. The Select and Popover mount their popups inside the panel with container, so they keep its dark theme.
Source · recipes/property-inspector.tsx
'use client'
import { Box, Popover, Select, Separator, Stack, Switch, Text } from '@blocks/design-system'
import { type ReactNode, useState } from 'react'
// App-owned compositions of Stack and Text: a titled group and a label-and-control row.
function PropertyGroup({ title, children }: { title: string; children: ReactNode }) {
return (
<Stack as="section" gap="xs" aria-label={title}>
<Text as="h3" fontSize="xs" fontWeight="semibold" color="text-muted" margin="none">
{title}
</Text>
{children}
</Stack>
)
}
function PropertyRow({ label, children }: { label: ReactNode; children: ReactNode }) {
return (
<Stack direction="row" justify="space-between" align="center" gap="sm">
<Text fontSize="sm">{label}</Text>
{children}
</Stack>
)
}
const sizes = [
{ value: 'sm', label: 'Small' },
{ value: 'md', label: 'Medium' },
{ value: 'lg', label: 'Large' },
]
// A dark inspector panel; its popups mount inside it to keep the theme.
export default function PropertyInspector() {
const [panel, setPanel] = useState<HTMLElement | null>(null)
const [size, setSize] = useState<string | null>('md')
const [visible, setVisible] = useState(true)
return (
<Box
as="aside"
ref={setPanel}
data-ds-theme="dark"
aria-label="Inspector"
padding="md"
backgroundColor="bg"
color="text"
border="default"
maxWidth="sm"
>
<Stack gap="md">
<PropertyGroup title="Button">
<PropertyRow label="Size">
<Select items={sizes} value={size} onValueChange={setSize}>
<Select.Trigger aria-label="Size" size="sm" />
<Select.Content container={panel}>
{sizes.map((option) => (
<Select.Item key={option.value} value={option.value}>
{option.label}
</Select.Item>
))}
</Select.Content>
</Select>
</PropertyRow>
<PropertyRow label="Visible">
<Switch aria-label="Visible" checked={visible} onCheckedChange={setVisible} />
</PropertyRow>
</PropertyGroup>
<Separator />
<PropertyGroup title="Preview">
<Text fontSize="sm" role="status" aria-label="Inspector preview">
{visible ? `A ${sizes.find((option) => option.value === size)?.label.toLowerCase()} button` : 'Hidden'}
</Text>
<Popover>
<Popover.Trigger render={<button type="button" />}>About size</Popover.Trigger>
<Popover.Content container={panel}>
<Popover.Title>Size</Popover.Title>
<Popover.Description>Sizes follow the control-height tokens: 28, 32 and 40px.</Popover.Description>
</Popover.Content>
</Popover>
</PropertyGroup>
</Stack>
</Box>
)
}