mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-03-28 17:42:40 +01:00
Added density tooltip
This commit is contained in:
@@ -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",
|
||||
|
||||
26
src/components/common/Tooltip.tsx
Normal file
26
src/components/common/Tooltip.tsx
Normal file
@@ -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} />
|
||||
);
|
||||
};
|
||||
@@ -616,7 +616,7 @@ export enum LocalizationKey {
|
||||
*/
|
||||
dashboardHeaderPaginationPrevious = 'dashboard.header.pagination.previous',
|
||||
/**
|
||||
* next
|
||||
* Next
|
||||
*/
|
||||
dashboardHeaderPaginationNext = 'dashboard.header.pagination.next',
|
||||
/**
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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[];
|
||||
@@ -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;
|
||||
@@ -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) => {
|
||||
@@ -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)]"}`}
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user