/** Text activity animation shared by a row and its nested text fragments. */ import { createContext, memo, useContext, type ReactNode } from 'react' import clsx from 'clsx' import css from './TextShimmer.module.css' const DecorativeCopy = createContext(undefined) /** Text and activity supplied by the owning row. */ export interface TextShimmerProps { /** Text or presentational children with text in nested TextShimmer instances. No effects or element ids. */ children: ReactNode /** Whether to animate; nested instances share the containing row's activity. */ active?: boolean | undefined className?: string | undefined /** Layout class applied equally to the base and decorative content. */ contentClassName?: string | undefined } function TextContent({ children, className }: Pick) { const decorative = useContext(DecorativeCopy) const generated = decorative === true && typeof children === 'string' return ( {generated ? null : children} ) } /** * Render text with one shared highlight while retaining selectable, accessible content. * Nested instances inherit the outer animation. Keep icons outside; mark decorative * separators with data-shimmer-decoration so their background follows the highlight. * Active children also render in an inert, clipped decoration; supply only presentation. * @param props - localized text, running state, and owner styling. * @returns retained text and its optional decorative highlight. */ export const TextShimmer = memo(function TextShimmer({ children, active = false, className, contentClassName }: TextShimmerProps) { const decorative = useContext(DecorativeCopy) if (decorative !== undefined) return {children} const content = typeof children === 'string' ? {children} : children return ( {content} {active && ( // React 18 forwards inert as an empty string; a boolean is dropped. )} ) })