mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
refactor(FE-114): update input handling for vaccination stock, mortality count, and feed stock with improved parsing and formatting
This commit is contained in:
@@ -1,65 +0,0 @@
|
|||||||
'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<FieldMessageTone, string> = {
|
|
||||||
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 (
|
|
||||||
<div
|
|
||||||
aria-live={liveRegion}
|
|
||||||
aria-hidden={!visible && !hasMessage}
|
|
||||||
className={cn(
|
|
||||||
'relative w-full text-sm leading-5 transition-[opacity,transform] duration-150 ease-out',
|
|
||||||
persistent && 'min-h-[1.25rem]',
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'block whitespace-pre-line',
|
|
||||||
toneClassName[tone],
|
|
||||||
visible
|
|
||||||
? 'opacity-100 translate-y-0'
|
|
||||||
: 'opacity-0 -translate-y-1 pointer-events-none'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{visible || persistent ? (message ?? '\u00A0') : message}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FieldMessage;
|
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user