'use client'; import { ReactNode } from 'react'; import { cn } from '@/lib/helper'; type FieldMessageTone = 'error' | 'info' | 'success'; export interface FieldMessageProps { message?: ReactNode; tone?: FieldMessageTone; isVisible?: boolean; persistent?: boolean; className?: string; ariaLive?: 'off' | 'polite' | 'assertive'; } const toneClassName: Record = { error: 'text-error', info: 'text-base-content/60', success: 'text-success', }; /** * Shared helper to render bottom field feedback without causing layout shift. * Keeps a minimal slot height, but expands when the content wraps onto multiple lines. */ export const FieldMessage = ({ message, tone = 'info', isVisible, persistent = true, className, ariaLive, }: FieldMessageProps) => { const hasMessage = Boolean(message); const visible = isVisible ?? hasMessage; const liveRegion = ariaLive ?? (tone === 'error' ? 'assertive' : 'polite'); return (
{visible || persistent ? (message ?? '\u00A0') : message}
); }; export default FieldMessage;