From 4c06ed78cf3a475b4e2e27ebf546adb8ebd3f2fe Mon Sep 17 00:00:00 2001 From: "[dyad]" Date: Tue, 20 Jan 2026 12:05:34 +0100 Subject: [PATCH] [dyad] Added colored length indicators for meta tags - wrote 2 file(s) --- src/components/length-indicator.tsx | 62 +++++++++++++++++++++++++++++ src/components/meta-form.tsx | 21 ++++++++-- 2 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/components/length-indicator.tsx diff --git a/src/components/length-indicator.tsx b/src/components/length-indicator.tsx new file mode 100644 index 0000000..72c1dae --- /dev/null +++ b/src/components/length-indicator.tsx @@ -0,0 +1,62 @@ +"use client"; + +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { cn } from "@/lib/utils"; + +interface LengthIndicatorProps { + length: number; + type: "title" | "description"; +} + +const TITLE_THRESHOLDS = { + good: { min: 30, max: 60 }, + ok: { min: 15, max: 70 }, +}; + +const DESCRIPTION_THRESHOLDS = { + good: { min: 120, max: 158 }, + ok: { min: 50, max: 170 }, +}; + +export function LengthIndicator({ length, type }: LengthIndicatorProps) { + const thresholds = + type === "title" ? TITLE_THRESHOLDS : DESCRIPTION_THRESHOLDS; + + let colorClass = "bg-red-500"; + let tooltipText = "Length is not optimal"; + + if (length === 0) { + tooltipText = "Not found"; + colorClass = "bg-gray-400"; + } else if (length >= thresholds.good.min && length <= thresholds.good.max) { + colorClass = "bg-green-500"; + tooltipText = "Optimal length"; + } else if (length >= thresholds.ok.min && length <= thresholds.ok.max) { + colorClass = "bg-yellow-500"; + tooltipText = "Length could be improved"; + } else if (length < thresholds.ok.min) { + tooltipText = "Too short"; + } else if (length > thresholds.ok.max) { + tooltipText = "Too long"; + } + + return ( + + + +
+ + +

+ {tooltipText} ({length} characters) +

+
+ + + ); +} \ No newline at end of file diff --git a/src/components/meta-form.tsx b/src/components/meta-form.tsx index f5dcfed..e9df71c 100644 --- a/src/components/meta-form.tsx +++ b/src/components/meta-form.tsx @@ -6,6 +6,7 @@ import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Globe } from "lucide-react"; import { extractMetaData } from "@/app/actions"; +import { LengthIndicator } from "./length-indicator"; interface MetaData { title: string; @@ -70,14 +71,26 @@ export function MetaForm() {
-

Meta Title

-

+

+

Meta Title

+ +
+

{metaData.title || "Not found"}

-

Meta Description

-

+

+

Meta Description

+ +
+

{metaData.description || "Not found"}