Thinking Orbs New
Four small orbs for agent status: breathing, glass with a travelling highlight, dithered and a morphing blob.
Installation
01
Install with the shadcn CLI. The NiceUI theme comes along the first time.
$ npx shadcn@latest add https://niceui.dev/r/ai-thinking-orbs.json02
Or copy the source below (2 files). Dependencies: lucide-react.
Source
components/niceui/ai/thinking/ThinkingOrbs.tsx
import { useState, type CSSProperties } from 'react';
import { Pills, Showcase, Size, ThinkingLabel, TONES, type ThinkingState, type Tone } from './shared';
export type OrbVariant = 'breathing' | 'glass' | 'dithered' | 'blob';
export type ThinkingOrbProps = {
size?: number;
variant?: OrbVariant;
tone?: Tone;
state?: ThinkingState;
className?: string;
};
const KEYFRAMES = `
@keyframes nui-orb-breathe { 0%,100% { transform: scale(.82); opacity: .75 } 50% { transform: scale(1); opacity: 1 } }
@keyframes nui-orb-spin { to { transform: rotate(360deg) } }
@keyframes nui-orb-blob {
0%,100% { border-radius: 42% 58% 63% 37% / 41% 44% 56% 59%; transform: rotate(0deg) }
33% { border-radius: 63% 37% 41% 59% / 58% 36% 64% 42% }
66% { border-radius: 38% 62% 53% 47% / 37% 61% 39% 63% }
50% { transform: rotate(180deg) }
}
@media (prefers-reduced-motion: reduce) { .nui-orb * { animation: none !important } }
`;
export function ThinkingOrb({ size = 20, variant = 'breathing', tone = 'sky', state = 'thinking', className }: ThinkingOrbProps) {
const c = TONES[tone];
const on = state === 'thinking';
const dur = (s: number) => (on ? `${s}s` : `${s * 3}s`);
const play: CSSProperties['animationPlayState'] = state === 'idle' ? 'paused' : 'running';
const box: CSSProperties = { position: 'relative', display: 'inline-block', width: size, height: size, flexShrink: 0 };
const glow = state === 'done' ? `0 0 ${size * 0.35}px ${c.main}66` : on ? `0 0 ${size * 0.6}px ${c.main}88` : 'none';
let inner;
if (variant === 'breathing') {
inner = (
<span
style={{
position: 'absolute',
inset: 0,
borderRadius: '50%',
background: `radial-gradient(circle at 35% 30%, ${c.soft}, ${c.main} 45%, ${c.deep} 100%)`,
boxShadow: glow,
animation: `nui-orb-breathe ${dur(1.8)} ease-in-out infinite`,
animationPlayState: play,
opacity: state === 'idle' ? 0.55 : 1,
}}
/>
);
} else if (variant === 'glass') {
inner = (
<>
<span style={{ position: 'absolute', inset: 0, borderRadius: '50%', background: `radial-gradient(circle at 50% 120%, ${c.main}cc, ${c.deep}55 60%, transparent 75%), rgba(255,255,255,.04)`, boxShadow: `inset 0 0 0 1px rgba(255,255,255,.18), ${glow}` }} />
<span style={{ position: 'absolute', inset: 0, borderRadius: '50%', overflow: 'hidden', animation: `nui-orb-spin ${dur(2.4)} linear infinite`, animationPlayState: play }}>
<span style={{ position: 'absolute', left: '18%', top: '10%', width: '38%', height: '26%', borderRadius: '50%', background: 'radial-gradient(closest-side, rgba(255,255,255,.85), transparent)', filter: `blur(${Math.max(0.5, size / 40)}px)` }} />
</span>
</>
);
} else if (variant === 'dithered') {
const dot = Math.max(2, size / 9);
inner = (
<span
style={{
position: 'absolute',
inset: 0,
borderRadius: '50%',
background: `conic-gradient(from 0deg, ${c.soft}, ${c.deep}, ${c.main}, ${c.soft})`,
WebkitMaskImage: `radial-gradient(circle, #000 ${dot * 0.32}px, transparent ${dot * 0.42}px)`,
maskImage: `radial-gradient(circle, #000 ${dot * 0.32}px, transparent ${dot * 0.42}px)`,
WebkitMaskSize: `${dot}px ${dot}px`,
maskSize: `${dot}px ${dot}px`,
animation: `nui-orb-spin ${dur(3)} linear infinite`,
animationPlayState: play,
filter: on ? `drop-shadow(0 0 ${size * 0.15}px ${c.main})` : undefined,
}}
/>
);
} else {
inner = (
<span
style={{
position: 'absolute',
inset: '4%',
background: `linear-gradient(135deg, ${c.soft}, ${c.main} 45%, ${c.deep})`,
boxShadow: glow,
animation: `nui-orb-blob ${dur(4)} ease-in-out infinite`,
animationPlayState: play,
}}
/>
);
}
return (
<span role="img" aria-label={on ? 'Thinking' : state === 'done' ? 'Done' : 'Idle'} className={['nui-orb', className].filter(Boolean).join(' ')} style={box}>
<style>{KEYFRAMES}</style>
{inner}
</span>
);
}
const VARIANTS = ['breathing', 'glass', 'dithered', 'blob'] as const;
const STATES = ['idle', 'thinking', 'done'] as const;
export function ThinkingOrbsDemo() {
const [variant, setVariant] = useState<OrbVariant>('glass');
const [state, setState] = useState<ThinkingState>('thinking');
return (
<Showcase
controls={
<>
<Pills label="Variant" value={variant} options={VARIANTS} onChange={setVariant} />
<Pills label="State" value={state} options={STATES} onChange={setState} />
</>
}
sizes={
<>
<Size px={14}><ThinkingOrb size={14} variant={variant} state={state} /></Size>
<Size px={24}><ThinkingOrb size={24} variant={variant} state={state} tone="violet" /></Size>
<Size px={40}><ThinkingOrb size={40} variant={variant} state={state} /></Size>
<Size px={64}><ThinkingOrb size={64} variant={variant} state={state} tone="emerald" /></Size>
</>
}
chat={
<div className="flex items-center gap-2.5">
<ThinkingOrb size={16} variant={variant} state={state} />
{state === 'done' ? <span className="text-sm text-ink-300">Thought for 4s</span> : <ThinkingLabel>{state === 'idle' ? 'Ready when you are' : 'Thinking…'}</ThinkingLabel>}
</div>
}
/>
);
}components/niceui/ai/thinking/shared.tsx
import { useEffect, useState, type ReactNode } from 'react';
import { Sparkles } from 'lucide-react';
import { cn } from '@/lib/cn';
export type ThinkingState = 'idle' | 'thinking' | 'done';
export const TONES = {
sky: { main: '#38bdf8', soft: '#7dd3fc', deep: '#0284c7' },
violet: { main: '#a78bfa', soft: '#c4b5fd', deep: '#7c3aed' },
emerald: { main: '#34d399', soft: '#6ee7b7', deep: '#059669' },
amber: { main: '#fbbf24', soft: '#fcd34d', deep: '#d97706' },
white: { main: '#e5e7eb', soft: '#f9fafb', deep: '#9ca3af' },
} as const;
export type Tone = keyof typeof TONES;
export function usePrefersReducedMotion() {
const [reduce, setReduce] = useState(false);
useEffect(() => {
const mq = window.matchMedia('(prefers-reduced-motion: reduce)');
setReduce(mq.matches);
const on = () => setReduce(mq.matches);
mq.addEventListener('change', on);
return () => mq.removeEventListener('change', on);
}, []);
return reduce;
}
/** Ticks a frame counter at `fps` while active. */
export function useTick(active: boolean, fps = 12) {
const [n, setN] = useState(0);
useEffect(() => {
if (!active) return;
const id = window.setInterval(() => setN((v) => v + 1), 1000 / fps);
return () => window.clearInterval(id);
}, [active, fps]);
return n;
}
export function Pills<T extends string>({ value, options, onChange, label }: { value: T; options: readonly T[]; onChange: (v: T) => void; label: string }) {
return (
<div role="radiogroup" aria-label={label} className="flex flex-wrap gap-1 rounded-xl bg-white/[0.03] p-1 ring-1 ring-white/5">
{options.map((o) => (
<button
key={o}
role="radio"
aria-checked={value === o}
onClick={() => onChange(o)}
className={cn(
'focus-ring rounded-lg px-2.5 py-1 text-xs capitalize transition-colors',
value === o ? 'bg-white/10 text-ink-50 shadow-hairline' : 'text-ink-400 hover:text-ink-200',
)}
>
{o}
</button>
))}
</div>
);
}
/** Standard showcase: variant pills, a size ladder and an inline chat row. */
export function Showcase({ controls, sizes, chat, footer }: { controls: ReactNode; sizes: ReactNode; chat: ReactNode; footer?: ReactNode }) {
return (
<div className="mx-auto flex w-full max-w-xl flex-col gap-5">
<div className="flex flex-wrap items-center justify-center gap-2">{controls}</div>
<div className="flex min-h-[112px] flex-wrap items-center justify-center gap-x-10 gap-y-6 rounded-2xl bg-ink-900/80 px-6 py-7 shadow-card">{sizes}</div>
<div className="flex items-start gap-3 rounded-2xl bg-ink-900 p-4 shadow-card">
<span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-brand-500/15 text-brand-300">
<Sparkles className="h-4 w-4" />
</span>
<div className="min-w-0 flex-1 pt-1.5">{chat}</div>
</div>
{footer}
</div>
);
}
export function Size({ px, children }: { px: number; children: ReactNode }) {
return (
<div className="flex flex-col items-center gap-2.5">
<div className="flex h-16 items-center justify-center">{children}</div>
<span className="font-mono text-[10px] tabular-nums text-ink-500">{px}px</span>
</div>
);
}
export function ThinkingLabel({ children = 'Thinking…' }: { children?: ReactNode }) {
return <span className="shimmer-text text-sm font-medium">{children}</span>;
}