Open this example in the interactive library
Live preview
Source code
// components/DensityControl.tsx
import { useState } from "react";
import type { ReactNode } from "react";
export default function DensityControl({
children = "Preview text",
}: { children?: ReactNode } = {}) {
const [compact, set] = useState(false);
return (
<div>
<button aria-pressed={compact} onClick={() => set(!compact)}>
Compact spacing
</button>
<section style={{ padding: compact ? 8 : 24 }}>{children}</section>
</div>
);
}
