Reasoning Effort
A pill-shaped slider that picks one of a few effort levels, such as Low, Medium, High, and Max. While you drag, a bubble grows out of the track and names the level.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/reasoning-effort.jsonCopies Reasoning Effort into your app, installs the packages, and adds the styles. Then import it from @/components/ui/reasoning-effort. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-mergeAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Copy and paste the following code into your project.
'use client'; import { useEffect, useId, useLayoutEffect, useRef, useState, type KeyboardEvent, type PointerEvent } from 'react'; import { cn } from '@/lib/sprout/classes'; const TRACK = 256; const HEIGHT = 32; const RADIUS = HEIGHT / 2; const BUMP_H = 20; const REST_W = 27.2; const DRAG_W = 33.6; const REST_H = 27.2; const EDGE_PAD = (HEIGHT - REST_H) / 2; const SHOULDER = 23.572; const TEXT_SIDE = 20; const PHI_MAX = 0.6; const PHI_REACH = 36; function clamp(n: number, min: number, max: number) { return Math.min(max, Math.max(min, n)); } function easeOut(t: number) { return 1 - (1 - t) ** 3; } function smoothstep(t: number) { const x = clamp(t, 0, 1); return x * x * (3 - 2 * x); } function reducedMotion() { return typeof window !== 'undefined' && window.matchMedia?.('(prefers-reduced-motion: reduce)').matches; } function plateauFor(textW: number) { return Math.max(8, textW + TEXT_SIDE * 2 - SHOULDER * 2); } function capFoot(side: -1 | 1, phi: number) { const crown = side === -1 ? RADIUS : TRACK - RADIUS; return { x: crown + side * RADIUS * Math.sin(phi), y: BUMP_H + RADIUS * (1 - Math.cos(phi)), }; } function shellGeom(cx: number, plateauW: number) { const crownL = RADIUS; const crownR = TRACK - RADIUS; let topL = cx - plateauW / 2; let topR = topL + plateauW; let phiL = 0; let phiR = 0; const overflowL = crownL - (topL - SHOULDER); if (overflowL > 0) { phiL = PHI_MAX * smoothstep(overflowL / PHI_REACH); const foot = capFoot(-1, phiL); const minTopL = foot.x + SHOULDER * Math.cos(phiL); if (topL < minTopL) { topR += minTopL - topL; topL = minTopL; } } const overflowR = topR + SHOULDER - crownR; if (overflowR > 0) { phiR = PHI_MAX * smoothstep(overflowR / PHI_REACH); const foot = capFoot(1, phiR); const maxTopR = foot.x - SHOULDER * Math.cos(phiR); if (topR > maxTopR) { topL -= topR - maxTopR; topR = maxTopR; } } const insetL = phiL > 0 ? SHOULDER * (1 - Math.cos(phiL)) : 0; const insetR = phiR > 0 ? SHOULDER * (1 - Math.cos(phiR)) : 0; topR += insetL; topL -= insetR; return { topL, topR, phiL, phiR, insetL, insetR }; } function shoulderCmds(footX: number, footY: number, platX: number, platY: number, phi: number, dir: 1 | -1) { const xScale = Math.abs(platX - footX) / SHOULDER; const yScale = Math.max(0.001, (footY - platY) / 20); const tangent = { x: dir * Math.cos(phi), y: -Math.sin(phi) }; const map = (lx: number, ly: number) => ({ x: footX + dir * lx * xScale, y: footY + (ly - 20) * yScale, }); const h1 = 5.398 * xScale; const p0 = { x: footX, y: footY }; const c1 = { x: footX + tangent.x * h1, y: footY + tangent.y * h1 }; const c2 = map(10.012, 16.114); const p1 = map(10.93, 10.794); const c3 = map(11.916, 4.577); const c4 = map(17.277, 0); const p3 = { x: platX, y: platY }; const fmt = (p: { x: number; y: number }) => `${p.x.toFixed(2)} ${p.y.toFixed(2)}`; if (dir === 1) return `C${fmt(c1)} ${fmt(c2)} ${fmt(p1)}C${fmt(c3)} ${fmt(c4)} ${fmt(p3)}`; return `C${fmt(c4)} ${fmt(c3)} ${fmt(p1)}C${fmt(c2)} ${fmt(c1)} ${fmt(p0)}`; } function shellPath(cx: number, open: number, plateauW: number) { const trackTop = BUMP_H; const trackBot = BUMP_H + HEIGHT; const crownL = RADIUS; const crownR = TRACK - RADIUS; if (open < 0.012) { return `M${crownL} ${trackTop}H${crownR}A${RADIUS} ${RADIUS} 0 0 1 ${crownR} ${trackBot}H${crownL}A${RADIUS} ${RADIUS} 0 0 1 ${crownL} ${trackTop}Z`; } const bumpTop = BUMP_H * (1 - open); const { topL, topR, phiL, phiR } = shellGeom(cx, plateauW); const cmds = [`M${crownL} ${trackBot}`]; if (phiL > 0.001) { const foot = capFoot(-1, phiL); cmds.push(`A${RADIUS} ${RADIUS} 0 0 1 ${foot.x.toFixed(2)} ${foot.y.toFixed(2)}`); cmds.push(shoulderCmds(foot.x, foot.y, topL, bumpTop, phiL, 1)); } else { cmds.push(`A${RADIUS} ${RADIUS} 0 0 1 ${crownL} ${trackTop}`); const footL = topL - SHOULDER; if (footL > crownL + 0.4) cmds.push(`H${footL.toFixed(2)}`); cmds.push(shoulderCmds(footL, trackTop, topL, bumpTop, 0, 1)); } if (topR > topL + 0.4) cmds.push(`H${topR.toFixed(2)}`); if (phiR > 0.001) { const foot = capFoot(1, phiR); cmds.push(shoulderCmds(foot.x, foot.y, topR, bumpTop, phiR, -1)); cmds.push(`A${RADIUS} ${RADIUS} 0 0 1 ${crownR} ${trackBot}`); } else { const footR = topR + SHOULDER; cmds.push(shoulderCmds(footR, trackTop, topR, bumpTop, 0, -1)); if (footR < crownR - 0.4) cmds.push(`H${crownR}`); cmds.push(`A${RADIUS} ${RADIUS} 0 0 1 ${crownR} ${trackBot}`); } cmds.push(`H${crownL}Z`); return cmds.join(''); } function useTween(target: number, duration: number, delay = 0) { const ref = useRef(target); const [value, setValue] = useState(target); useEffect(() => { const from = ref.current; if (reducedMotion() || Math.abs(target - from) < 0.001) { ref.current = target; setValue(target); return; } const start = performance.now(); let raf = 0; const step = (now: number) => { const elapsed = now - start - delay; if (elapsed >= 0) { const t = Math.min(1, elapsed / duration); ref.current = from + (target - from) * easeOut(t); setValue(ref.current); if (t === 1) return; } raf = requestAnimationFrame(step); }; raf = requestAnimationFrame(step); return () => cancelAnimationFrame(raf); }, [target, duration, delay]); return value; } export interface ReasoningEffortProps { levels: readonly string[]; value: number; onValueChange: (index: number) => void; label?: string | undefined; 'aria-label'?: string | undefined; 'aria-labelledby'?: string | undefined; className?: string | undefined; } export function ReasoningEffort({ levels, value, onValueChange, label, 'aria-label': ariaLabel = 'Reasoning effort', 'aria-labelledby': ariaLabelledBy, className, }: ReasoningEffortProps) { const max = Math.max(0, levels.length - 1); const current = clamp(Math.round(value), 0, max); const trackRef = useRef<HTMLDivElement>(null); const labelRef = useRef<HTMLDivElement>(null); const [dragging, setDragging] = useState(false); const [dragValue, setDragValue] = useState(current); const [textW, setTextW] = useState(64); const gradId = useId(); const settled = useTween(dragging ? dragValue : current, 220); const display = dragging ? dragValue : settled; const open = useTween(dragging ? 1 : 0, 220); const reveal = useTween(dragging ? 1 : 0, dragging ? 132 : 90, dragging ? 85 : 0); const plateauW = useTween(plateauFor(textW), 90); const centerFor = (index: number) => RADIUS + (max === 0 ? 0 : index / max) * (TRACK - RADIUS * 2); const valueFrom = (clientX: number) => { const rect = trackRef.current?.getBoundingClientRect(); if (!rect || max === 0) return current; return clamp(((clientX - rect.left - RADIUS) / (rect.width - RADIUS * 2)) * max, 0, max); }; const move = (next: number) => { setDragValue(next); if (Math.round(next) !== current) onValueChange(Math.round(next)); }; const onPointerDown = (event: PointerEvent<HTMLDivElement>) => { if (event.button !== 0) return; event.currentTarget.setPointerCapture?.(event.pointerId); setDragging(true); move(valueFrom(event.clientX)); }; const onPointerMove = (event: PointerEvent<HTMLDivElement>) => { if (dragging) move(valueFrom(event.clientX)); }; const onPointerUp = (event: PointerEvent<HTMLDivElement>) => { if (!dragging) return; if (event.currentTarget.hasPointerCapture?.(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId); setDragging(false); }; const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => { const keys: Record<string, number> = { ArrowRight: current + 1, ArrowUp: current + 1, ArrowLeft: current - 1, ArrowDown: current - 1, Home: 0, End: max, }; const next = keys[event.key]; if (next === undefined) return; event.preventDefault(); const clamped = clamp(next, 0, max); if (clamped !== current) onValueChange(clamped); }; const center = centerFor(display); const thumbW = REST_W + (DRAG_W - REST_W) * open; const thumbLeft = clamp(center - thumbW / 2, EDGE_PAD, TRACK - EDGE_PAD - thumbW); const thumbRight = thumbLeft + thumbW; const fillW = Math.min(TRACK, thumbRight + EDGE_PAD); const active = Math.round(display); const level = levels[active]; const plateau = shellGeom(center, plateauW); const labelX = (plateau.topL + plateau.topR) / 2 + (plateau.insetL - plateau.insetR) / 2; useLayoutEffect(() => { const w = labelRef.current?.getBoundingClientRect().width ?? 0; if (w > 0 && Math.abs(w - textW) > 0.4) setTextW(w); }, [level, label, textW]); return ( <div data-slot="reasoning-effort" data-dragging={dragging} className={cn('sprout-reasoning-effort', className)}> <svg className="sprout-reasoning-effort-shell" viewBox={`0 0 ${TRACK} ${BUMP_H + HEIGHT}`} aria-hidden="true"> <defs> <linearGradient id={gradId} x1="0" y1="0" x2="0" y2="1"> <stop offset="0" className="sprout-reasoning-effort-stop-top" /> <stop offset="1" className="sprout-reasoning-effort-stop-bottom" /> </linearGradient> </defs> <path data-slot="reasoning-effort-shell" d={shellPath(center, open, plateauW)} fill={`url(#${gradId})`} strokeWidth="0.5" strokeLinejoin="round" vectorEffect="non-scaling-stroke" /> </svg> <div ref={labelRef} data-slot="reasoning-effort-bubble" aria-hidden="true" className="sprout-reasoning-effort-bubble" style={{ left: labelX, opacity: reveal, filter: reveal > 0.98 ? undefined : `blur(${((1 - reveal) * 3).toFixed(2)}px)`, transform: `translate(-50%, ${3 * (1 - open)}px)`, }} > <span key={level} className="sprout-reasoning-effort-bubble-text"> {label && <span className="sprout-reasoning-effort-bubble-label">{label}</span>} <span className="sprout-reasoning-effort-bubble-level">{level}</span> </span> </div> <div ref={trackRef} role="slider" tabIndex={0} data-slot="reasoning-effort-track" aria-label={ariaLabelledBy ? undefined : ariaLabel} aria-labelledby={ariaLabelledBy} aria-orientation="horizontal" aria-valuemin={0} aria-valuemax={max} aria-valuenow={current} aria-valuetext={levels[current]} className="sprout-reasoning-effort-track" onPointerDown={onPointerDown} onPointerMove={onPointerMove} onPointerUp={onPointerUp} onPointerCancel={onPointerUp} onKeyDown={onKeyDown} > <div data-slot="reasoning-effort-fill" className="sprout-reasoning-effort-fill" style={{ width: fillW }} /> <div data-slot="reasoning-effort-thumb" className="sprout-reasoning-effort-thumb" style={{ left: thumbLeft, width: thumbW, height: REST_H, marginTop: -REST_H / 2, }} /> {levels.map((name, index) => { const x = centerFor(index); const onThumb = x >= thumbLeft + 0.5 && x <= thumbRight - 0.5; return ( <span key={`${index}-${name}`} data-slot="reasoning-effort-tick" data-on-thumb={onThumb} data-active={index === active && !onThumb} className="sprout-reasoning-effort-tick" style={{ left: x, height: 4.8 + (max === 0 ? 0 : index / max) * 4.8, }} /> ); })} </div> </div> ); }Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-reasoning-effort { --sprout-reasoning-effort-thumb: oklch(100% 0 0); touch-action: none; -webkit-user-select: none; user-select: none; flex-shrink: 0; width: 256px; height: 52px; position: relative; } .sprout-reasoning-effort-shell { pointer-events: none; width: 100%; height: 100%; position: absolute; inset: 0; overflow: visible; } .sprout-reasoning-effort-shell path { stroke: var(--sprout-line); } .sprout-reasoning-effort-stop-top { stop-color: var(--sprout-hover); } .sprout-reasoning-effort-stop-bottom { stop-color: var(--sprout-active); } .sprout-reasoning-effort-bubble { z-index: 2; font-size: var(--sprout-text-xs); white-space: nowrap; pointer-events: none; font-weight: 500; line-height: 16px; position: absolute; top: 2px; } .sprout-reasoning-effort-bubble-text { gap: 3px; display: flex; } .sprout-reasoning-effort-bubble-label { color: var(--sprout-text); } .sprout-reasoning-effort-bubble-level { color: var(--sprout-muted); } .sprout-reasoning-effort-track { inset-inline: 0; cursor: grab; border-radius: 999px; outline: 0 solid #0000; height: 32px; position: absolute; bottom: 0; } .sprout-reasoning-effort-track:focus-visible { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: 0; } .sprout-reasoning-effort[data-dragging="true"] .sprout-reasoning-effort-track { cursor: grabbing; } .sprout-reasoning-effort-fill { inset-block: 0; background-color: var(--sprout-primary); pointer-events: none; border-radius: 999px; position: absolute; left: 0; box-shadow: inset 0 1px 1px oklch(100% 0 0 / .16); } .sprout-reasoning-effort-thumb { z-index: 2; background-color: var(--sprout-reasoning-effort-thumb); pointer-events: none; border-radius: 999px; position: absolute; top: 50%; box-shadow: 0 0 0 .5px oklch(0% 0 0 / .14), 0 1px 2px oklch(0% 0 0 / .14); } .sprout-reasoning-effort-tick { z-index: 3; background-color: color-mix(in oklab, var(--sprout-text) 25%, transparent); pointer-events: none; border-radius: 1px; width: 1.5px; margin-left: -.75px; position: absolute; top: 50%; transform: translateY(-50%); } .sprout-reasoning-effort-tick[data-active="true"] { background-color: color-mix(in oklab, var(--sprout-on-primary) 60%, transparent); } .sprout-reasoning-effort-tick[data-on-thumb="true"] { background-color: oklch(0% 0 0 / .45); } @media (prefers-reduced-motion: no-preference) { .sprout-reasoning-effort-bubble-text { animation: sprout-reasoning-effort-level-in var(--sprout-motion-normal, .18s) var(--sprout-motion-ease, ease-out); } .sprout-reasoning-effort-track { transition: outline-color var(--sprout-motion-fast, .12s) var(--sprout-motion-ease, ease-out); } } @keyframes sprout-reasoning-effort-level-in { from { opacity: .35; filter: blur(2.5px); } } @media (forced-colors: active) { .sprout-reasoning-effort-shell path { stroke: canvastext; } .sprout-reasoning-effort-stop-top, .sprout-reasoning-effort-stop-bottom { stop-color: Canvas; } .sprout-reasoning-effort-fill { background-color: highlight; } .sprout-reasoning-effort-thumb { background-color: canvas; border: 1px solid canvastext; } .sprout-reasoning-effort-tick, .sprout-reasoning-effort-tick[data-active="true"], .sprout-reasoning-effort-tick[data-on-thumb="true"] { background-color: canvastext; } .sprout-reasoning-effort-track:focus-visible { outline-color: highlight; } } }Import it from
@/components/ui/reasoning-effort. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/reasoning-effort.
Interactive effort selector
Drag the thumb, click a spot on the track, or use the arrow keys. A bubble with the level name grows out of the track while you drag, and the thumb snaps to the nearest level when you let go.
Selected level: Balanced
Composer model picker
The chat composer's model picker. The slider sits below the model list, the bubble shows the model name with the level, and picking a model keeps the panel open so you can set its effort.
Ask about your workspace…
Level counts
A model's level list sets the ticks. Ticks grow taller toward higher effort, and the tick under the fill turns light. One level still renders, with the thumb parked at the start.
Usage
import { ReasoningEffort } from "@tulipfarm/sprout/reasoning-effort";
const levels = ["Quick", "Balanced", "Thorough", "Maximum"];
const [value, setValue] = useState(1);
<ReasoningEffort levels={levels} value={value} onValueChange={setValue} />const effortLabel = { low: "Low", medium: "Medium", high: "High", max: "Max" };
const index = Math.max(0, model.efforts.indexOf(effort));
{model.efforts.length > 0 && (
<ReasoningEffort
label={model.label}
levels={model.efforts.map((level) => effortLabel[level])}
value={index}
onValueChange={(next) => setEffort(model.efforts[next])}
/>
)}The slider is controlled: pass the chosen index as value and update it in onValueChange. It callsonValueChange as soon as a drag crosses into a new level, not only on release. Hide it when a model has no levels.
Props
levels: level names from lowest to highest effort. Each one gets a tick, spaced evenly. Ticks grow taller toward higher effort.value: the index of the chosen level.onValueChange: called with the new index.label: optional text before the level name in the bubble, such as the model name.aria-label(default "Reasoning effort") oraria-labelledbynames the slider.className: added to the root.
The control is a fixed 256 × 52px: a 32px track with 20px above it for the bubble. It fits the 18rem picker popover with 16px from each outer edge: 15px of padding plus the popover's 1px border.
Accessibility
The track is one role="slider" tab stop. Its value is the index, and aria-valuetext reads the level name. Arrow keys move one level, and Home and End jump to the ends. Keyboard focus shows a 2px --sprout-focus outline.
The bubble is hidden from screen readers because the value text already names the level. When reduced motion is requested, the thumb, bubble, and level change jump instead of tweening. In forced colors mode the track, fill, thumb, and ticks use system colors.
Theme tokens
The fill uses --sprout-primary, so the opt-in TulipFarm theme tints it green. The pill and bubble shade from--sprout-hover to --sprout-active with a--sprout-line edge. The bubble's label uses--sprout-text and its level uses --sprout-muted. The thumb is white; override --sprout-reasoning-effort-thumbto change it.