/** * Keyword Display Component * * Displays keywords in a clean, readable format with tags */ import React, { useState } from "react"; interface KeywordDisplayProps { keywords: string | null | undefined; getString: (section: string, key: string, fallback: string) => string; maxWidth?: string; alwaysShowAll?: boolean; } const KeywordDisplay: React.FC = ({ keywords, getString, maxWidth = "max-w-md", alwaysShowAll = false, }) => { const [showAll, setShowAll] = useState(false); if (!keywords) { return ( {getString("table_cells", "no_keywords", "No keywords")} ); } // Split keywords by comma and trim whitespace const keywordArray = keywords .split(",") .map((keyword) => keyword.trim()) .filter((keyword) => keyword.length > 0); if (keywordArray.length === 0) { return ( {getString("table_cells", "no_keywords", "No keywords")} ); } const visibleCount = 5; const displayKeywords = alwaysShowAll || showAll ? keywordArray : keywordArray.slice(0, visibleCount); const hiddenCount = keywordArray.length - visibleCount; return (
{displayKeywords.map((keyword, index) => ( {keyword} ))} {!alwaysShowAll && hiddenCount > 0 && !showAll && ( )} {!alwaysShowAll && showAll && hiddenCount > 0 && ( )}
); }; export default KeywordDisplay;