Thinking Shimmer
A quiet shimmer over the agent's status while it keeps working.
Preview
"use client";
import { ThinkingShimmer } from "@/components/agents/loading-states/thinking-shimmer";
export function ThinkingShimmerPreview() {
return (
<ThinkingShimmer className="text-lg" duration={1.8}>
Thinking…
</ThinkingShimmer>
);
}
"use client";
// beui.dev/components/agents/loading-states/thinking-shimmer
import type { ReactNode } from "react";
import { TextShimmer } from "@/components/motion/text-shimmer";
import { useMessages } from "@/lib/i18n";
import { cn } from "@/lib/utils";
import { type LoadingStatesMessages, loadingStatesMessages } from "./messages";
export interface ThinkingShimmerProps {
/** Loading message shown to the user. */
children?: ReactNode;
/** Seconds taken for one shimmer pass. */
duration?: number;
/** Override any built-in string. */
labels?: Partial<LoadingStatesMessages>;
/** Classes merged onto the shimmering text. */
className?: string;
}
export function ThinkingShimmer({
children,
duration = 1.8,
labels,
className,
}: ThinkingShimmerProps) {
const t = useMessages("loadingStates", loadingStatesMessages, labels);
return (
<TextShimmer
as="span"
duration={duration}
className={cn("font-medium", className)}
>
{children ?? t("thinking")}
</TextShimmer>
);
}
Add it with the shadcn CLI, or copy the source manually.
$ bunx --bun shadcn add @beui/thinking-shimmerthinking-shimmerthinking-shimmer
Needs beUI's theme tokens once: paste the theme CSS, or with shadcn run
npx shadcn add https://beui.dev/r/theme.json. Theme setupInstall dependencies
npm i clsx tailwind-mergeAdd util files
TSXlib/i18n.tsx
"use client";
import {
createContext,
type ReactNode,
useCallback,
useContext,
useMemo,
} from "react";
/**
* A component's messages. Plain strings with `{name}` placeholders, so a
* dictionary stays JSON-serializable and can be passed from a server layout.
* There are no plural forms: write messages that read correctly for any count.
*/
export type Messages = Record<string, string>;
/** A language file: component namespace → any subset of that component's messages. */
export type LocaleMessages = Record<string, Partial<Messages>>;
type LocaleContextValue = {
locale?: string;
messages: LocaleMessages;
};
const NO_MESSAGES: LocaleMessages = {};
const LocaleContext = createContext<LocaleContextValue>({ messages: NO_MESSAGES });
/** Without a locale, digits stay plain so server and client render the same text. */
export function formatNumber(value: number, locale?: string) {
return locale ? new Intl.NumberFormat(locale).format(value) : String(value);
}
export interface LocaleProviderProps {
/** BCP 47 tag, e.g. `de`, `pt-BR`. Drives `Intl` number formatting. */
locale: string;
/**
* Component namespace → translated strings. Missing keys fall back to English.
* Pass a stable object (a module constant, imported JSON or a memoized value):
* a new object each render gives every translated component a new `t`.
*/
messages?: LocaleMessages;
children: ReactNode;
}
export function LocaleProvider({ locale, messages = NO_MESSAGES, children }: LocaleProviderProps) {
const value = useMemo(() => ({ locale, messages }), [locale, messages]);
return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>;
}
export function useLocale(): { locale?: string } {
return { locale: useContext(LocaleContext).locale };
}
/**
* Resolves a component's strings: `labels` prop, then the provider's
* messages for `namespace`, then the component's English `defaults`.
* Numbers passed as values are formatted for the provider's locale.
*/
export function useMessages<T extends Messages>(
namespace: string,
defaults: T,
labels?: Partial<T>,
) {
const { locale, messages } = useContext(LocaleContext);
const provided = messages[namespace];
// Inline `labels={{ … }}` is a new object every render. Keying it by content
// keeps `t` one identity until a label changes, so effects and memos that
// depend on `t` don't re-run per render, and render-time reads never lag.
const labelsKey = labels ? JSON.stringify(labels) : "";
const stableLabels = useMemo(
() => (labelsKey ? (JSON.parse(labelsKey) as Partial<T>) : undefined),
[labelsKey],
);
return useCallback(
(key: keyof T & string, values?: Record<string, string | number>) => {
const template = stableLabels?.[key] ?? provided?.[key] ?? defaults[key];
if (!values) return template;
return template.replace(/\{(\w+)\}/g, (match, name: string) => {
const value = values[name];
if (value === undefined) return match;
return typeof value === "number" ? formatNumber(value, locale) : value;
});
},
[defaults, stableLabels, locale, provided],
);
}
TSXlib/utils.ts
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
TSXlib/text-shimmer.ts
import type { CSSProperties } from "react";
// The reduced-motion rule travels with the component. The site's globals.css calms CSS
// animation globally, but the registry bundles imports only, so an installed
// copy never receives that reset.
//
// `!important` because the sweep is an inline style, which outranks a plain rule
// in a media query. It selects a marker class carried by TEXT_SHIMMER_CLASS_NAME
// so it also reaches consumers that build their own span out of these exports.
export const TEXT_SHIMMER_KEYFRAMES =
"@keyframes beui-text-shimmer{from{background-position:200% 0}to{background-position:-200% 0}}" +
"@media (prefers-reduced-motion: reduce){.beui-text-shimmer{animation:none !important}}";
export const TEXT_SHIMMER_CLASS_NAME =
"beui-text-shimmer bg-[length:200%_100%] bg-clip-text text-transparent bg-[linear-gradient(110deg,var(--muted-foreground)_30%,var(--foreground)_50%,var(--muted-foreground)_70%)]";
/**
* Only the moving highlight band, transparent elsewhere. Laid over text drawn
* in pieces (a letter cascade), so one band sweeps the whole phrase instead
* of every piece carrying, and flashing, its own gradient.
*/
export const TEXT_SHIMMER_HIGHLIGHT_CLASS_NAME =
"beui-text-shimmer bg-[length:200%_100%] bg-clip-text text-transparent bg-[linear-gradient(110deg,transparent_30%,var(--foreground)_50%,transparent_70%)]";
export function textShimmerStyle(duration: number): CSSProperties {
return {
animation: `beui-text-shimmer ${duration}s linear infinite`,
};
}
Copy the source code
TSXcomponents/agents/loading-states/thinking-shimmer.tsx
"use client";
// beui.dev/components/agents/loading-states/thinking-shimmer
import type { ReactNode } from "react";
import { TextShimmer } from "@/components/motion/text-shimmer";
import { useMessages } from "@/lib/i18n";
import { cn } from "@/lib/utils";
import { type LoadingStatesMessages, loadingStatesMessages } from "./messages";
export interface ThinkingShimmerProps {
/** Loading message shown to the user. */
children?: ReactNode;
/** Seconds taken for one shimmer pass. */
duration?: number;
/** Override any built-in string. */
labels?: Partial<LoadingStatesMessages>;
/** Classes merged onto the shimmering text. */
className?: string;
}
export function ThinkingShimmer({
children,
duration = 1.8,
labels,
className,
}: ThinkingShimmerProps) {
const t = useMessages("loadingStates", loadingStatesMessages, labels);
return (
<TextShimmer
as="span"
duration={duration}
className={cn("font-medium", className)}
>
{children ?? t("thinking")}
</TextShimmer>
);
}
TSXcomponents/agents/loading-states/messages.ts
/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */
export const loadingStatesMessages = {
thinking: "Thinking…",
churning: "Churning",
inProgress: "{label}, in progress",
reasoning: "Reasoning",
phraseThinking: "Thinking",
phraseReading: "Reading the context",
phraseConnecting: "Connecting the details",
phraseForming: "Forming a response",
};
export type LoadingStatesMessages = typeof loadingStatesMessages;
TSXcomponents/motion/text-shimmer.tsx
import { cn } from "@/lib/utils";
import type { ElementType, ReactNode } from "react";
import {
TEXT_SHIMMER_CLASS_NAME,
TEXT_SHIMMER_KEYFRAMES,
textShimmerStyle,
} from "@/lib/text-shimmer";
export interface TextShimmerProps {
children: ReactNode;
/** Element to render the text as. Default: "span" */
as?: ElementType;
/** Length of one shimmer sweep (s). Default: 2.5 */
duration?: number;
/** Classes merged onto the text element. */
className?: string;
}
export function TextShimmer({ children, as: Comp = "span", duration = 2.5, className }: TextShimmerProps) {
return (
<>
<style>
{TEXT_SHIMMER_KEYFRAMES}
</style>
<Comp
style={textShimmerStyle(duration)}
className={cn(
"inline-block",
TEXT_SHIMMER_CLASS_NAME,
className,
)}
>
{children}
</Comp>
</>
);
}
PropTypeDefault
children?ReactNodeLoading message shown to the user.
Default
—duration?numberSeconds taken for one shimmer pass.
Default
1.8labels?Partial<{ thinking: string; churning: string; inProgress: string; reasoning: string; phraseThinking: string; phraseReading: string; phraseConnecting: string; phraseForming: string; }>Override any built-in string.
Default
—className?stringClasses merged onto the shimmering text.
Default
—Todo List
A collapsible agent task plan with morphing status marks, a completion count, compact metadata, and smooth list updates.
Message
Composable conversation primitives for message rows, grouped bubbles, avatars, metadata, live markers, and a mount-only trailing-edge pop-up for newly sent rows.
Prompt Input
An auto-growing agent composer with prompt actions, model selection, keyboard submission, and animated send and stop states.
Updated