About
A segmented control for how hard the model thinks, with an indicator that slides on a spring.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Reasoning Effort to your project and fits it to your theme.
Code
How Reasoning Effort is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client"
import * as React from "react"
import { Icon, IconNode, ReasoningEffort, createIcon } from "@/components/ui/reasoning-effort"
const reducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches
/** How long a choice holds a tour before it carries on. */
const RESUME_MS = 1800
/**
* Steps through `values` on a timer, so a 21st preview (and its cover video) shows every option
* without a click. Picking a value holds it, and the tour carries on from there after
* `RESUME_MS`, so a click never leaves the preview still. Reduced motion never starts it.
*/
function useCycle<T>(values: readonly T[], ms: number) {
const [index, setIndex] = React.useState(0)
const [heldAt, setHeldAt] = React.useState(0)
React.useEffect(() => {
if (reducedMotion()) return
let id = 0
const start = () => {
id = window.setInterval(() => setIndex((n) => (n + 1) % values.length), ms)
}
const wait = window.setTimeout(start, heldAt ? RESUME_MS : 0)
return () => {
window.clearTimeout(wait)
window.clearInterval(id)
}
}, [heldAt, values.length, ms])
const pick = React.useCallback(
(value: T) => {
setHeldAt(Date.now())
setIndex(Math.max(0, values.indexOf(value)))
},
[values],
)
return [values[index] as T, pick] as const
}
/** Each effort with a request that suits it, so the tour reads like someone choosing. */
const TOUR = [
{
effort: "low",
prompt: "Rename userId to accountId across the billing module.",
hint: "Answers in a few seconds. Good for lookups and small edits.",
},
{
effort: "medium",
prompt: "Why does the cart total sometimes come out one cent off?",
hint: "Thinks before answering. The default for most tasks.",
},
{
effort: "high",
prompt: "Plan the move from nightly batch jobs to an event queue, with a rollback at each step.",
hint: "Takes its time on hard problems: migrations, proofs, tricky bugs.",
},
] as const
const FIT_CSS = "html,body{overflow:hidden}[data-fit-small] [data-fit-hide]{display:none!important}"
/**
* 21st shows a demo in a small frame: about 674 by 421 on a component page, 358 by 224 on a
* phone and 245 by 139 on a profile card. A demo taller than its frame gets scrollbars, which
* render white on dark pages. FitFrame fills the frame exactly instead.
*
* - "scale": the content shrinks until it fits, centered. For visuals such as orbs.
* - "crop": the content stays at full size from the top and fades out at the bottom. For text
* that streams in, where a changing scale would make the page breathe.
*
* `minWidth` lays out a wide demo (a table, a two column panel) at that width and scales it down
* to the frame, instead of letting it collapse to a narrow layout. The frame centers it, so it
* shrinks evenly on both sides.
*
* Anything marked `data-fit-hide` (state buttons, the chatcn.dev line) drops out in frames
* shorter than `hideBelow`, so a profile card shows the visual alone.
*/
function FitFrame({
children,
mode = "scale",
hideBelow = 360,
minWidth,
}: {
children: React.ReactNode
mode?: "scale" | "crop"
hideBelow?: number
minWidth?: string
}) {
const content = React.useRef<HTMLDivElement>(null)
const [cropped, setCropped] = React.useState(false)
React.useLayoutEffect(() => {
const el = content.current
if (!el) return
const measure = () => {
const vw = window.innerWidth
const vh = window.innerHeight
el.toggleAttribute("data-fit-small", vh < hideBelow)
// Layout sizes ignore the transform, so measuring never feeds back.
const w = Math.max(el.offsetWidth, el.scrollWidth)
const h = Math.max(el.offsetHeight, el.scrollHeight)
const scale = mode === "scale" ? Math.min(1, vw / w, vh / h) : 1
el.style.transform = scale < 1 ? `scale(${scale})` : ""
setCropped(mode === "crop" && h > vh + 1)
}
measure()
const observer = new ResizeObserver(measure)
observer.observe(el)
// Content that changes inside a fixed width box (a headline that cycles words) never resizes
// the box itself, so changes below it measure again on the next frame.
let frame = 0
const mutations = new MutationObserver(() => {
cancelAnimationFrame(frame)
frame = requestAnimationFrame(measure)
})
mutations.observe(el, { subtree: true, childList: true, characterData: true })
window.addEventListener("resize", measure)
return () => {
observer.disconnect()
mutations.disconnect()
cancelAnimationFrame(frame)
window.removeEventListener("resize", measure)
}
}, [mode, hideBelow])
const fade = "linear-gradient(to bottom, #000 calc(100% - 40px), transparent)"
return (
<div
className="flex w-full justify-center overflow-hidden"
style={{
height: "100dvh",
alignItems: mode === "crop" ? "flex-start" : "center",
maskImage: cropped ? fade : undefined,
WebkitMaskImage: cropped ? fade : undefined,
}}
>
<style>{FIT_CSS}</style>
<div
ref={content}
className="w-full shrink-0"
style={{ transformOrigin: mode === "crop" ? "top center" : "center", minWidth }}
>
{children}
</div>
</div>
)
}
const iconNode: IconNode = [
["path", {"d":"m14.81 7.92-6.36 6.36a1.75 1.75 0 0 0 0 2.47 1.75 1.75 0 0 0 2.47 0l7.07-7.07a3.5 3.5 0 0 0 0-4.95 3.5 3.5 0 0 0-4.95 0L5.97 11.8a5.25 5.25 0 0 0 0 7.43 5.25 5.25 0 0 0 7.43 0l4.95-4.95"}],
]
const PaperclipIcon: Icon = /* @__PURE__ */ createIcon("paperclip", iconNode)
const iconNode2: IconNode = [
["path", {"d":"m18.5 11.5-4.73-4.73a2.5 2.5 0 0 0-3.54 0L5.5 11.5"}],
["path", {"d":"M12 19v-9"}],
]
const ArrowUpIcon: Icon = /* @__PURE__ */ createIcon("arrow-up", iconNode2)
/** The line under each 21st demo that points back to the kit. */
function MoreOn({ slug, children }: { slug: string; children: React.ReactNode }) {
return (
<p data-fit-hide className="text-[0.75rem]/[1rem] text-(color:--chatcn-fg-faint) text-center text-balance">
{children}{" "}
<a
href={`https://chatcn.dev/docs/components/${slug}`}
target="_blank"
rel="noopener"
className="text-(color:--chatcn-fg-subtle) hover:text-(color:--chatcn-fg) underline underline-offset-2"
>
chatcn.dev
</a>
</p>
)
}
/**
* A composer with the effort control in its toolbar. The tour picks the effort that suits each
* request, and the indicator slides between them. Click or use the arrow keys to take over.
*/
export default function ReasoningEffortPreview() {
const [step, pick] = useCycle(TOUR, 2600)
return (
<FitFrame minWidth="38rem">
<div className="flex w-full flex-col items-center justify-center gap-5 p-6">
<div className="flex w-full max-w-xl flex-col gap-3.5">
<div className="rounded-(--chatcn-radius-xl) bg-(color:--chatcn-card) shadow-(--chatcn-shadow-sm) border-(color:--chatcn-border) border p-3">
<p
key={step.effort}
className="text-[1rem]/[1.5rem] tracking-[-0.01em] text-(color:--chatcn-fg) min-h-14 px-1 pt-0.5 text-pretty"
>
{step.prompt}
</p>
<div className="mt-3 flex items-center gap-2">
<span className="text-(color:--chatcn-fg-subtle) flex size-9 items-center justify-center" aria-hidden="true">
<PaperclipIcon className="size-[18px]" />
</span>
<ReasoningEffort
icon
value={step.effort}
onValueChange={(v) => pick(TOUR.find((t) => t.effort === v) ?? TOUR[0])}
/>
<span className="flex-1" />
<span
className="bg-(color:--chatcn-fg) text-(color:--chatcn-bg) flex size-9 items-center justify-center rounded-full"
aria-hidden="true"
>
<ArrowUpIcon className="size-4" />
</span>
</div>
</div>
<p key={step.hint} className="text-[0.875rem]/[1.25rem] tracking-[-0.003em] text-(color:--chatcn-fg-muted) px-1 text-center text-pretty">
{step.hint}
</p>
</div>
<MoreOn slug="reasoning-effort">How hard the model thinks, as one sliding control. On</MoreOn>
</div>
</FitFrame>
)
}
















