Skip to content

Commit

Permalink
Added density tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Nov 28, 2024
1 parent 4907a7a commit 231bd89
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
1 change: 1 addition & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
"panel.seoKeywords.density": "Keyword density",
"panel.seoKeywordInfo.validInfo.label": "Heading(s)",
"panel.seoKeywordInfo.validInfo.content": "Content",
"panel.seoKeywordInfo.density.tooltip": "Recommended frequency: 0.75% - 1.5%",

"panel.seoKeywords.title": "Keywords",
"panel.seoKeywords.header.keyword": "Keyword",
Expand Down
26 changes: 26 additions & 0 deletions src/components/common/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import { Tooltip as TT } from 'react-tooltip'

export interface ITooltipProps {
id: string;
render?: () => React.ReactNode;
}

export const Tooltip: React.FunctionComponent<ITooltipProps> = ({
id,
render
}: React.PropsWithChildren<ITooltipProps>) => {

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)] text-left`;

return (
<TT
id={id}
className={tooltipClasses}
style={{
fontSize: '12px',
lineHeight: '19px'
}}
render={render} />
);
};
6 changes: 5 additions & 1 deletion src/localization/localization.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ export enum LocalizationKey {
*/
dashboardHeaderPaginationPrevious = 'dashboard.header.pagination.previous',
/**
* next
* Next
*/
dashboardHeaderPaginationNext = 'dashboard.header.pagination.next',
/**
Expand Down Expand Up @@ -1620,6 +1620,10 @@ export enum LocalizationKey {
* Content
*/
panelSeoKeywordInfoValidInfoContent = 'panel.seoKeywordInfo.validInfo.content',
/**
* Recommended frequency: 0.75% - 1.5%
*/
panelSeoKeywordInfoDensityTooltip = 'panel.seoKeywordInfo.density.tooltip',
/**
* Keywords
*/
Expand Down
23 changes: 13 additions & 10 deletions src/panelWebView/components/SeoKeywordInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Tag } from './Tag';
import { LocalizationKey, localize } from '../../localization';
import { Messenger } from '@estruyf/vscode/dist/client';
import { CommandToCode } from '../CommandToCode';
import { Tooltip } from 'react-tooltip'
import { Tooltip } from '../../components/common/Tooltip';

export interface ISeoKeywordInfoProps {
keywords: string[];
Expand All @@ -29,8 +29,6 @@ const SeoKeywordInfo: React.FunctionComponent<ISeoKeywordInfoProps> = ({
headings
}: React.PropsWithChildren<ISeoKeywordInfoProps>) => {

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)] text-left`;

const density = () => {
if (!wordCount) {
return null;
Expand All @@ -41,7 +39,14 @@ const SeoKeywordInfo: React.FunctionComponent<ISeoKeywordInfoProps> = ({
const density = (count / wordCount) * 100;
const densityTitle = `${density.toFixed(2)}* %`;
const color = (density >= 0.75 && density < 1.5) ? "--vscode-charts-green" : "--vscode-charts-yellow";
return <span className={`text-[12px] text-[var(${color})]`} title="Recommended frequency: 0.75% - 1.5%">{densityTitle}</span>;
return (
<span
className={`text-[12px] text-[var(${color})] cursor-default`}
data-tooltip-id={`tooltip-density-${keyword}`}
data-tooltip-content={localize(LocalizationKey.panelSeoKeywordInfoDensityTooltip)}>
{densityTitle}
</span>
);
};

const validateKeywords = (heading: string, keyword: string) => {
Expand Down Expand Up @@ -110,7 +115,7 @@ const SeoKeywordInfo: React.FunctionComponent<ISeoKeywordInfoProps> = ({

return (
<div
className={`inline-flex py-0.5 px-2 my-1 rounded-[3px] justify-center items-center text-[12px] leading-[16px] border border-solid
className={`inline-flex py-0.5 px-2 my-1 rounded-[3px] justify-center items-center text-[12px] leading-[16px] border border-solid cursor-default
${isValid
? "text-[var(--vscode-charts-green)] border-[var(--vscode-charts-green)] bg-[var(--frontmatter-success-background)]"
: "text-[var(--vscode-charts-yellow)] border-[var(--vscode-charts-yellow)] bg-[var(--frontmatter-warning-background)]"}`}
Expand Down Expand Up @@ -147,15 +152,13 @@ const SeoKeywordInfo: React.FunctionComponent<ISeoKeywordInfoProps> = ({

<Tooltip
id={`tooltip-checks-${keyword}`}
className={tooltipClasses}
style={{
fontSize: '12px',
lineHeight: '19px'
}}
render={() => tooltipContent} />
</VSCodeTableCell>
<VSCodeTableCell className={`text-center`}>
{density()}

<Tooltip
id={`tooltip-density-${keyword}`} />
</VSCodeTableCell>
</VSCodeTableRow>
);
Expand Down
2 changes: 1 addition & 1 deletion src/panelWebView/components/VSCode/VSCodeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const VSCodeTableHead = React.forwardRef<
<th
ref={ref}
className={cn(
"h-6 px-2 py-2 text-left align-middle font-bold",
"h-6 px-2 py-2 text-left align-middle font-bold cursor-default",
className
)}
{...props}
Expand Down

0 comments on commit 231bd89

Please sign in to comment.