SpacingInspector
Margin and padding as nested boxes around an element, with a number field on every side.
Spacing
Margin
Padding
Element
142 × 125
Installation
Run this in a project that has a components.json. It adds one file, components/tenor-ui/spacing-inspector.tsx, and no packages.
pnpm dlx shadcn@latest add https://tenor.design/r/spacing-inspector.jsonNo components.json? Fetch the file. It works in any React project.
curl --create-dirs -o src/components/tenor-ui/spacing-inspector.tsx https://tenor.design/r/spacing-inspector.tsxUsage
Every prop is optional. With none, it renders the content you see above.
<SpacingInspector />"use client";
import * as React from "react";
import { SpacingInspector, type SpacingInspectorValues } from "@/components/tenor-ui/spacing-inspector";
export function CardSpacing() {
const [spacing, setSpacing] = React.useState<SpacingInspectorValues>({
margin: { top: 32, right: 24, bottom: 32, left: 24 },
padding: { top: 16, right: 20, bottom: 16, left: 20 },
});
return <SpacingInspector values={spacing} onChange={setSpacing} size={{ width: 320, height: 180 }} />;
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
theme | "dark" | "light" | "dark" | Dark or light palette. |
values | SpacingInspectorValues | None | Margin and padding when the inspector is controlled. Pair with onChange. |
defaultValues | SpacingInspectorValues | spacingInspectorValues | Starting margin and padding when it is not controlled. Reset returns to them. |
onChange | (values: SpacingInspectorValues) => void | None | Called with the new values after an edit or a reset. |
size | { width: number; height: number } | None | The element's size. Left out, the label shows the size of the element box as drawn. |
unit | string | "px" | Unit shown beside each value. |
labels | SpacingInspectorLabels | spacingInspectorLabels | Text for the heading, the reset button and the three boxes. |
demo | boolean | true | Nudges padding left and margin top every three seconds until someone interacts. Never runs when controlled. |
It also takes every attribute of its root element, such as className and style.
Theming
Set any of these CSS variables on the component or on an ancestor. Each falls back to the look shown here.
--tui-surface--tui-stroke--tui-text--tui-muted--tui-field--tui-field-stroke--tui-unit--tui-margin-color--tui-padding-color--tui-font-sans--tui-font-mono