Skip to content
Browse components

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.json

No 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.tsx

Usage

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

PropTypeDefaultWhat it does
theme"dark" | "light""dark"Dark or light palette.
valuesSpacingInspectorValuesNoneMargin and padding when the inspector is controlled. Pair with onChange.
defaultValuesSpacingInspectorValuesspacingInspectorValuesStarting margin and padding when it is not controlled. Reset returns to them.
onChange(values: SpacingInspectorValues) => voidNoneCalled with the new values after an edit or a reset.
size{ width: number; height: number }NoneThe element's size. Left out, the label shows the size of the element box as drawn.
unitstring"px"Unit shown beside each value.
labelsSpacingInspectorLabelsspacingInspectorLabelsText for the heading, the reset button and the three boxes.
demobooleantrueNudges 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