import classNames from "classnames"; import { useTranslation } from "next-i18next"; import { useContext, useMemo } from "react"; import { BlockHighlightContext } from "./highlight-context"; import { evaluateHighlight, getHighlightClass } from "utils/highlights"; export default function Block({ value, label, field }) { const { t } = useTranslation(); const highlightConfig = useContext(BlockHighlightContext); const highlight = useMemo(() => { if (!highlightConfig) return null; const labels = Array.isArray(label) ? label : [label]; const candidates = []; if (typeof field === "string") candidates.push(field); for (const candidateLabel of labels) { if (typeof candidateLabel === "string") candidates.push(candidateLabel); } for (const candidate of candidates) { const result = evaluateHighlight(candidate, value, highlightConfig); if (result) return result; } return null; }, [field, label, value, highlightConfig]); const highlightClass = useMemo(() => { if (!highlight?.level) return undefined; return getHighlightClass(highlight.level, highlightConfig); }, [highlight, highlightConfig]); const applyToValueOnly = highlight?.valueOnly === true; return (
{value === undefined || value === null ? "-" : value}
{t(label)}
); }