import * as React from 'react'; import { SeoKeywordInfo } from './SeoKeywordInfo'; import { ErrorBoundary } from '@sentry/react'; import { LocalizationKey, localize } from '../../localization'; import { VSCodeTable, VSCodeTableBody, VSCodeTableHead, VSCodeTableHeader, VSCodeTableRow } from './VSCode/VSCodeTable'; import { Tooltip } from 'react-tooltip' export interface ISeoKeywordsProps { keywords: string[] | null; title: string; description: string; slug: string; content: string; headings?: string[]; wordCount?: number; firstParagraph?: string; } const SeoKeywords: React.FunctionComponent = ({ keywords, ...data }: React.PropsWithChildren) => { const [isReady, setIsReady] = React.useState(false); const tooltipClasses = `!py-[2px] !px-[8px] !rounded-[3px] !border-[var(--vscode-editorHoverWidget-border)] !border !border-solid !bg-[var(--vscode-editorHoverWidget-background)] !text-[var(--vscode-editorHoverWidget-foreground)] !font-normal !opacity-100 shadow-[0_2px_8px_var(--vscode-widget-shadow)]`; const validateKeywords = () => { if (!keywords) { return []; } if (typeof keywords === 'string') { return [keywords]; } if (Array.isArray(keywords)) { return keywords; } return []; }; const validKeywords = React.useMemo(() => { return validateKeywords(); }, [keywords]); // Workaround for lit components not updating render React.useEffect(() => { setIsReady(false); setTimeout(() => { setIsReady(true); }, 0); }, [keywords]); if (!isReady || !keywords || keywords.length === 0) { return null; } return (
{localize(LocalizationKey.panelSeoKeywordsHeaderKeyword)} {localize(LocalizationKey.panelSeoKeywordsChecks)} {localize(LocalizationKey.panelSeoKeywordsDensityTableTitle)} {validKeywords.map((keyword, index) => { return ( ); })} {data.wordCount && (
{localize(LocalizationKey.panelSeoKeywordsDensityDescription)}
)}
); }; SeoKeywords.displayName = 'SeoKeywords'; export { SeoKeywords };