18 lines
760 B
TypeScript
18 lines
760 B
TypeScript
import { Chip } from '@mui/material';
|
|
import type { StatusMeta } from '@/components/meta/types';
|
|
import { useUi } from '@/i18n/useUi';
|
|
|
|
export interface StatusChipProps {
|
|
value: string | number | null | undefined;
|
|
statuses: StatusMeta[];
|
|
size?: 'small' | 'medium';
|
|
}
|
|
|
|
/** Chip for a status value, label/colour from a StatusMeta table; unknown values render as plain text chip. */
|
|
export function StatusChip({ value, statuses, size = 'small' }: StatusChipProps) {
|
|
const { tr } = useUi();
|
|
if (value === null || value === undefined || value === '') return null;
|
|
const s = statuses.find((x) => String(x.value) === String(value));
|
|
return <Chip size={size} label={s ? tr(s.label) : String(value)} color={s?.color ?? 'default'} variant="outlined" />;
|
|
}
|