Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

feat: add a new highlighter component (#543)

Pratiyank Kumar47750e026600
diff --git a/__registry__/index.tsx b/__registry__/index.tsx
index 1fe52065..d23da2ee 100644
--- a/__registry__/index.tsx
+++ b/__registry__/index.tsx
@@ -1649,6 +1649,30 @@ export const Index: Record<string, any> = {
}),
meta: undefined,
},
+ highlighter: {
+ name: "highlighter",
+ description:
+ "A text highlighter that mimics the effect of a human-drawn marker stroke.",
+ type: "registry:ui",
+ registryDependencies: undefined,
+ files: [
+ {
+ path: "registry/magicui/highlighter.tsx",
+ type: "registry:ui",
+ target: "components/magicui/highlighter.tsx",
+ },
+ ],
+ component: React.lazy(async () => {
+ const mod = await import("@/registry/magicui/highlighter.tsx");
+ const exportName =
+ Object.keys(mod).find(
+ (key) =>
+ typeof mod[key] === "function" || typeof mod[key] === "object",
+ ) || item.name;
+ return { default: mod.default || mod[exportName] };
+ }),
+ meta: undefined,
+ },
"magic-card-demo": {
name: "magic-card-demo",
description:
@@ -4583,6 +4607,34 @@ export const Index: Record<string, any> = {
}),
meta: undefined,
},
+ "highlighter-demo": {
+ name: "highlighter-demo",
+ description: "Example showing the demo of a Highlighter",
+ type: "registry:example",
+ registryDependencies: ["https://magicui.design/r/highlighter"],
+ files: [
+ {
+ path: "registry/example/highlighter-demo.tsx",
+ type: "registry:example",
+ target: "components/highlighter-demo.tsx",
+ },
+ {
+ path: "registry/magicui/highlighter.tsx",
+ type: "registry:ui",
+ target: "components/magicui/highlighter.tsx",
+ },
+ ],
+ component: React.lazy(async () => {
+ const mod = await import("@/registry/example/highlighter-demo.tsx");
+ const exportName =
+ Object.keys(mod).find(
+ (key) =>
+ typeof mod[key] === "function" || typeof mod[key] === "object",
+ ) || item.name;
+ return { default: mod.default || mod[exportName] };
+ }),
+ meta: undefined,
+ },
utils: {
name: "utils",
description: "",
diff --git a/config/docs.ts b/config/docs.ts
index 5eda4a0e..69f7ad8b 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -354,6 +354,12 @@ export const docsConfig: DocsConfig = {
title: "Pixel Image",
href: "/docs/components/pixel-image",
items: [],
+ label: "",
+ },
+ {
+ title: "Highlighter",
+ href: "/docs/components/highlighter",
+ items: [],
label: "New",
},
],
diff --git a/content/docs/components/highlighter.mdx b/content/docs/components/highlighter.mdx
new file mode 100644
index 00000000..a1f6d88d
--- /dev/null
+++ b/content/docs/components/highlighter.mdx
@@ -0,0 +1,78 @@
+---
+title: Highlighter
+date: 2025-02-11
+description: A text highlighter that mimics the effect of a human-drawn marker stroke.
+author: pratiyank
+published: true
+---
+
+<ComponentPreview name="highlighter-demo" />
+
+## Installation
+
+<Tabs defaultValue="cli">
+
+<TabsList>
+ <TabsTrigger value="cli">CLI</TabsTrigger>
+ <TabsTrigger value="manual">Manual</TabsTrigger>
+</TabsList>
+<TabsContent value="cli">
+
+```bash
+npx shadcn@latest add "https://magicui.design/r/highlighter"
+```
+
+</TabsContent>
+
+<TabsContent value="manual">
+
+<Steps>
+
+<Step>Copy and paste the following code into your project.</Step>
+
+<ComponentSource name="highlighter" />
+
+</Steps>
+
+</TabsContent>
+
+</Tabs>
+
+## Usage
+
+```tsx
+import { Highlighter } from "@/components/magicui/highlighter";
+```
+
+```tsx
+<p>
+ The{" "}
+ <Highlighter action="underline" color="#FF9800">
+ Magic UI Highlighter
+ </Highlighter>{" "}
+ makes important{" "}
+ <Highlighter action="highlight" color="#87CEFA">
+ text stand out
+ </Highlighter>{" "}
+ effortlessly.
+</p>
+```
+
+## Props
+
+Here's the updated props table with units specified for the numerical values:
+
+| Prop | Type | Default | Description |
+| ------------------- | --------------------------------------------------------------------------------------------------- | ------------- | ---------------------------------------------------------------------------- |
+| `children` | `React.ReactNode` | Required | The content to be highlighted/annotated. |
+| `color` | `string` | `"#ffd1dc"` | The color of the highlight. |
+| `action` | `"highlight" \| "circle" \| "box" \| "bracket" \| "crossed-off" \| "strike-through" \| "underline"` | `"highlight"` | The type of annotation effect to apply. |
+| `strokeWidth` | `number` | `1.5px` | The width of the annotation stroke. |
+| `animationDuration` | `number` | `500ms` | Duration of the animation in milliseconds. |
+| `iterations` | `number` | `2` | Number of times to draw the annotation (adds a sketchy effect when > 1). |
+| `padding` | `number` | `2px` | Padding between the element and the annotation. |
+| `multiline` | `boolean` | `true` | Whether to annotate across multiple lines or treat content as a single line. |
+
+## Credits
+
+- Credit to [@pratiyank](https://github.com/Pratiyankkumar) for this component!
diff --git a/package.json b/package.json
index 19ce553d..56a54677 100644
--- a/package.json
+++ b/package.json
@@ -74,6 +74,7 @@
"react-dom": "18.3.1",
"react-hook-form": "^7.50.1",
"react-tweet": "^3.2.1",
+ "rough-notation": "^0.5.1",
"schema-dts": "^1.1.2",
"shadcn": "2.4.0-canary.20",
"sonner": "^1.5.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f0b2276d..1fab222e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -158,6 +158,9 @@ importers:
react-tweet:
specifier: ^3.2.1
+ rough-notation:
+ specifier: ^0.5.1
+ version: 0.5.1
schema-dts:
specifier: ^1.1.2
version: 1.1.5
@@ -4892,6 +4895,9 @@ packages:
resolution: {integrity: sha512-l0OE8wL34P4nJH/H2ffoaniAokM2qSmrtXHmlpvYr5AVVX8msAyW0l8NVJFDxlSK4u3Uh/f41cQheDVdnYijwQ==}
hasBin: true
+ resolution: {integrity: sha512-ITHofTzm13cWFVfoGsh/4c/k2Mg8geKgBCwex71UZLnNuw403tCRjYPQ68jSAd37DMbZIePXPjDgY0XdZi9HPw==}
+
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
@@ -10989,6 +10995,8 @@ snapshots:
dependencies:
glob: 10.4.5
+
dependencies:
queue-microtask: 1.2.3
diff --git a/public/r/highlighter-demo.json b/public/r/highlighter-demo.json
new file mode 100644
index 00000000..50122af6
--- /dev/null
+++ b/public/r/highlighter-demo.json
@@ -0,0 +1,27 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "highlighter-demo",
+ "type": "registry:example",
+ "title": "Highlighter Demo",
+ "description": "Example showing the demo of a Highlighter",
+ "dependencies": [
+ "rough-notation"
+ ],
+ "registryDependencies": [
+ "https://magicui.design/r/highlighter"
+ ],
+ "files": [
+ {
+ "path": "registry/example/highlighter-demo.tsx",
+ "content": "import { Highlighter } from \"@/registry/magicui/highlighter\";\n\nexport default function HighlighterDemo() {\n return (\n <div className=\"text-center\">\n <p className=\"leading-relaxed\">\n The{\" \"}\n <Highlighter action=\"underline\" color=\"#FF9800\">\n Magic UI Highlighter\n </Highlighter>{\" \"}\n makes important{\" \"}\n <Highlighter action=\"highlight\" color=\"#87CEFA\">\n text stand out\n </Highlighter>{\" \"}\n effortlessly.\n </p>\n </div>\n );\n}\n",
+ "type": "registry:example",
+ "target": "components/highlighter-demo.tsx"
+ },
+ {
+ "path": "registry/magicui/highlighter.tsx",
+ "content": "\"use client\";\n\nimport { useEffect, useRef } from \"react\";\nimport { annotate } from \"rough-notation\";\nimport type React from \"react\";\n\n// Define available annotation actions\ntype AnnotationAction =\n | \"highlight\"\n | \"underline\"\n | \"box\"\n | \"circle\"\n | \"strike-through\"\n | \"crossed-off\"\n | \"bracket\";\n\n// Custom TypeScript interface for supported props\ninterface HighlighterProps {\n children: React.ReactNode;\n action?: AnnotationAction;\n color?: string;\n strokeWidth?: number;\n animationDuration?: number;\n iterations?: number;\n padding?: number;\n multiline?: boolean;\n}\n\nexport function Highlighter({\n children,\n action = \"highlight\",\n color = \"#ffd1dc\", // Default pink color\n strokeWidth = 1.5,\n animationDuration = 600,\n iterations = 2,\n padding = 2,\n multiline = true,\n}: HighlighterProps) {\n const elementRef = useRef<HTMLSpanElement>(null);\n\n useEffect(() => {\n const element = elementRef.current;\n if (element) {\n const annotation = annotate(element, {\n type: action,\n color,\n strokeWidth,\n animationDuration,\n iterations,\n padding,\n multiline,\n });\n\n annotation.show();\n\n // Store the current element in closure for cleanup\n return () => {\n if (element) {\n annotate(element, { type: action }).remove();\n }\n };\n }\n }, [\n action,\n color,\n strokeWidth,\n animationDuration,\n iterations,\n padding,\n multiline,\n ]);\n\n return (\n <span ref={elementRef} className=\"relative inline-block bg-transparent\">\n {children}\n </span>\n );\n}\n",
+ "type": "registry:ui",
+ "target": "components/magicui/highlighter.tsx"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/public/r/highlighter.json b/public/r/highlighter.json
new file mode 100644
index 00000000..9d7001e7
--- /dev/null
+++ b/public/r/highlighter.json
@@ -0,0 +1,18 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "highlighter",
+ "type": "registry:ui",
+ "title": "Highlighter",
+ "description": "A text highlighter that mimics the effect of a human-drawn marker stroke.",
+ "dependencies": [
+ "rough-notation"
+ ],
+ "files": [
+ {
+ "path": "registry/magicui/highlighter.tsx",
+ "content": "\"use client\";\n\nimport { useEffect, useRef } from \"react\";\nimport { annotate } from \"rough-notation\";\nimport type React from \"react\";\n\n// Define available annotation actions\ntype AnnotationAction =\n | \"highlight\"\n | \"underline\"\n | \"box\"\n | \"circle\"\n | \"strike-through\"\n | \"crossed-off\"\n | \"bracket\";\n\n// Custom TypeScript interface for supported props\ninterface HighlighterProps {\n children: React.ReactNode;\n action?: AnnotationAction;\n color?: string;\n strokeWidth?: number;\n animationDuration?: number;\n iterations?: number;\n padding?: number;\n multiline?: boolean;\n}\n\nexport function Highlighter({\n children,\n action = \"highlight\",\n color = \"#ffd1dc\", // Default pink color\n strokeWidth = 1.5,\n animationDuration = 600,\n iterations = 2,\n padding = 2,\n multiline = true,\n}: HighlighterProps) {\n const elementRef = useRef<HTMLSpanElement>(null);\n\n useEffect(() => {\n const element = elementRef.current;\n if (element) {\n const annotation = annotate(element, {\n type: action,\n color,\n strokeWidth,\n animationDuration,\n iterations,\n padding,\n multiline,\n });\n\n annotation.show();\n\n // Store the current element in closure for cleanup\n return () => {\n if (element) {\n annotate(element, { type: action }).remove();\n }\n };\n }\n }, [\n action,\n color,\n strokeWidth,\n animationDuration,\n iterations,\n padding,\n multiline,\n ]);\n\n return (\n <span ref={elementRef} className=\"relative inline-block bg-transparent\">\n {children}\n </span>\n );\n}\n",
+ "type": "registry:ui",
+ "target": "components/magicui/highlighter.tsx"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/public/r/pointer.json b/public/r/pointer.json
index 866cf75b..bf7f7d1f 100644
--- a/public/r/pointer.json
+++ b/public/r/pointer.json
@@ -10,7 +10,7 @@
"files": [
{
"path": "registry/magicui/pointer.tsx",
- "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n AnimatePresence,\n HTMLMotionProps,\n motion,\n useMotionValue,\n} from \"motion/react\";\nimport { useEffect, useRef, useState } from \"react\";\n\ninterface PointerProps extends Omit<HTMLMotionProps<\"div\">, \"ref\"> {}\n\n/**\n * A custom pointer component that displays an animated cursor.\n * Add this as a child to any component to enable a custom pointer when hovering.\n * You can pass custom children to render as the pointer.\n *\n * @component\n * @param {PointerProps} props - The component props\n */\nexport function Pointer({\n className,\n style,\n children,\n ...props\n}: PointerProps): JSX.Element {\n const x = useMotionValue(0);\n const y = useMotionValue(0);\n const [isActive, setIsActive] = useState<boolean>(false);\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (typeof window !== \"undefined\" && containerRef.current) {\n // Get the parent element directly from the ref\n const parentElement = containerRef.current.parentElement;\n\n if (parentElement) {\n // Add cursor-none to parent\n parentElement.style.cursor = \"none\";\n\n // Add event listeners to parent\n const handleMouseMove = (e: MouseEvent) => {\n x.set(e.clientX);\n y.set(e.clientY);\n };\n\n const handleMouseEnter = () => {\n setIsActive(true);\n };\n\n const handleMouseLeave = () => {\n setIsActive(false);\n };\n\n parentElement.addEventListener(\"mousemove\", handleMouseMove);\n parentElement.addEventListener(\"mouseenter\", handleMouseEnter);\n parentElement.addEventListener(\"mouseleave\", handleMouseLeave);\n\n return () => {\n parentElement.style.cursor = \"\";\n parentElement.removeEventListener(\"mousemove\", handleMouseMove);\n parentElement.removeEventListener(\"mouseenter\", handleMouseEnter);\n parentElement.removeEventListener(\"mouseleave\", handleMouseLeave);\n };\n }\n }\n }, [x, y]);\n\n return (\n <>\n <div ref={containerRef} />\n <AnimatePresence>\n {isActive && (\n <motion.div\n className=\"transform-[translate(-50%,-50%)] pointer-events-none fixed z-50\"\n style={{\n top: y,\n left: x,\n ...style,\n }}\n initial={{\n scale: 0,\n opacity: 0,\n }}\n animate={{\n scale: 1,\n opacity: 1,\n }}\n exit={{\n scale: 0,\n opacity: 0,\n }}\n {...props}\n >\n {children || (\n <svg\n stroke=\"currentColor\"\n fill=\"currentColor\"\n strokeWidth=\"1\"\n viewBox=\"0 0 16 16\"\n height=\"24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n className={cn(\n \"rotate-[-70deg] stroke-white text-black\",\n className,\n )}\n >\n <path d=\"M14.082 2.182a.5.5 0 0 1 .103.557L8.528 15.467a.5.5 0 0 1-.917-.007L5.57 10.694.803 8.652a.5.5 0 0 1-.006-.916l12.728-5.657a.5.5 0 0 1 .556.103z\" />\n </svg>\n )}\n </motion.div>\n )}\n </AnimatePresence>\n </>\n );\n}\n",
+ "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n AnimatePresence,\n HTMLMotionProps,\n motion,\n useMotionValue,\n} from \"motion/react\";\nimport { useEffect, useRef, useState } from \"react\";\n\ninterface PointerProps extends Omit<HTMLMotionProps<\"div\">, \"ref\"> {}\n\n/**\n * A custom pointer component that displays an animated cursor.\n * Add this as a child to any component to enable a custom pointer when hovering.\n * You can pass custom children to render as the pointer.\n *\n * @component\n * @param {PointerProps} props - The component props\n */\nexport function Pointer({\n className,\n style,\n children,\n ...props\n}: PointerProps): JSX.Element {\n const x = useMotionValue(0);\n const y = useMotionValue(0);\n const [isActive, setIsActive] = useState<boolean>(false);\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (typeof window !== \"undefined\" && containerRef.current) {\n // Get the parent element directly from the ref\n const parentElement = containerRef.current.parentElement;\n\n if (parentElement) {\n // Add cursor-none to parent\n parentElement.style.cursor = \"none\";\n\n // Add event listeners to parent\n const handleMouseMove = (e: MouseEvent) => {\n x.set(e.clientX);\n y.set(e.clientY);\n };\n\n const handleMouseEnter = (e: MouseEvent) => {\n x.set(e.clientX);\n y.set(e.clientY);\n setIsActive(true);\n };\n\n const handleMouseLeave = () => {\n setIsActive(false);\n };\n\n parentElement.addEventListener(\"mousemove\", handleMouseMove);\n parentElement.addEventListener(\"mouseenter\", handleMouseEnter);\n parentElement.addEventListener(\"mouseleave\", handleMouseLeave);\n\n return () => {\n parentElement.style.cursor = \"\";\n parentElement.removeEventListener(\"mousemove\", handleMouseMove);\n parentElement.removeEventListener(\"mouseenter\", handleMouseEnter);\n parentElement.removeEventListener(\"mouseleave\", handleMouseLeave);\n };\n }\n }\n }, [x, y]);\n\n return (\n <>\n <div ref={containerRef} />\n <AnimatePresence>\n {isActive && (\n <motion.div\n className=\"transform-[translate(-50%,-50%)] pointer-events-none fixed z-50\"\n style={{\n top: y,\n left: x,\n ...style,\n }}\n initial={{\n scale: 0,\n opacity: 0,\n }}\n animate={{\n scale: 1,\n opacity: 1,\n }}\n exit={{\n scale: 0,\n opacity: 0,\n }}\n {...props}\n >\n {children || (\n <svg\n stroke=\"currentColor\"\n fill=\"currentColor\"\n strokeWidth=\"1\"\n viewBox=\"0 0 16 16\"\n height=\"24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n className={cn(\n \"rotate-[-70deg] stroke-white text-black\",\n className,\n )}\n >\n <path d=\"M14.082 2.182a.5.5 0 0 1 .103.557L8.528 15.467a.5.5 0 0 1-.917-.007L5.57 10.694.803 8.652a.5.5 0 0 1-.006-.916l12.728-5.657a.5.5 0 0 1 .556.103z\" />\n </svg>\n )}\n </motion.div>\n )}\n </AnimatePresence>\n </>\n );\n}\n",
"type": "registry:ui",
"target": "components/magicui/pointer.tsx"
}
diff --git a/public/registry.json b/public/registry.json
index 70f3bde9..fd01d520 100644
--- a/public/registry.json
+++ b/public/registry.json
@@ -1312,6 +1312,22 @@
}
]
},
+ {
+ "name": "highlighter",
+ "type": "registry:ui",
+ "title": "Highlighter",
+ "description": "A text highlighter that mimics the effect of a human-drawn marker stroke.",
+ "dependencies": [
+ "rough-notation"
+ ],
+ "files": [
+ {
+ "path": "registry/magicui/highlighter.tsx",
+ "type": "registry:ui",
+ "target": "components/magicui/highlighter.tsx"
+ }
+ ]
+ },
{
"name": "magic-card-demo",
"type": "registry:example",
@@ -3343,6 +3359,30 @@
}
]
},
+ {
+ "name": "highlighter-demo",
+ "type": "registry:example",
+ "title": "Highlighter Demo",
+ "description": "Example showing the demo of a Highlighter",
+ "dependencies": [
+ "rough-notation"
+ ],
+ "registryDependencies": [
+ "https://magicui.design/r/highlighter"
+ ],
+ "files": [
+ {
+ "path": "registry/example/highlighter-demo.tsx",
+ "type": "registry:example",
+ "target": "components/highlighter-demo.tsx"
+ },
+ {
+ "path": "registry/magicui/highlighter.tsx",
+ "type": "registry:ui",
+ "target": "components/magicui/highlighter.tsx"
+ }
+ ]
+ },
{
"name": "utils",
"type": "registry:lib",
diff --git a/registry.json b/registry.json
index 70f3bde9..fd01d520 100644
--- a/registry.json
+++ b/registry.json
@@ -1312,6 +1312,22 @@
}
]
},
+ {
+ "name": "highlighter",
+ "type": "registry:ui",
+ "title": "Highlighter",
+ "description": "A text highlighter that mimics the effect of a human-drawn marker stroke.",
+ "dependencies": [
+ "rough-notation"
+ ],
+ "files": [
+ {
+ "path": "registry/magicui/highlighter.tsx",
+ "type": "registry:ui",
+ "target": "components/magicui/highlighter.tsx"
+ }
+ ]
+ },
{
"name": "magic-card-demo",
"type": "registry:example",
@@ -3343,6 +3359,30 @@
}
]
},
+ {
+ "name": "highlighter-demo",
+ "type": "registry:example",
+ "title": "Highlighter Demo",
+ "description": "Example showing the demo of a Highlighter",
+ "dependencies": [
+ "rough-notation"
+ ],
+ "registryDependencies": [
+ "https://magicui.design/r/highlighter"
+ ],
+ "files": [
+ {
+ "path": "registry/example/highlighter-demo.tsx",
+ "type": "registry:example",
+ "target": "components/highlighter-demo.tsx"
+ },
+ {
+ "path": "registry/magicui/highlighter.tsx",
+ "type": "registry:ui",
+ "target": "components/magicui/highlighter.tsx"
+ }
+ ]
+ },
{
"name": "utils",
"type": "registry:lib",
diff --git a/registry/example/highlighter-demo.tsx b/registry/example/highlighter-demo.tsx
new file mode 100644
index 00000000..697fff20
--- /dev/null
+++ b/registry/example/highlighter-demo.tsx
@@ -0,0 +1,19 @@
+import { Highlighter } from "@/registry/magicui/highlighter";
+
+export default function HighlighterDemo() {
+ return (
+ <div className="text-center">
+ <p className="leading-relaxed">
+ The{" "}
+ <Highlighter action="underline" color="#FF9800">
+ Magic UI Highlighter
+ </Highlighter>{" "}
+ makes important{" "}
+ <Highlighter action="highlight" color="#87CEFA">
+ text stand out
+ </Highlighter>{" "}
+ effortlessly.
+ </p>
+ </div>
+ );
+}
diff --git a/registry/magicui/highlighter.tsx b/registry/magicui/highlighter.tsx
new file mode 100644
index 00000000..df829b00
--- /dev/null
+++ b/registry/magicui/highlighter.tsx
@@ -0,0 +1,78 @@
+"use client";
+
+import { useEffect, useRef } from "react";
+import { annotate } from "rough-notation";
+import type React from "react";
+
+// Define available annotation actions
+type AnnotationAction =
+ | "highlight"
+ | "underline"
+ | "box"
+ | "circle"
+ | "strike-through"
+ | "crossed-off"
+ | "bracket";
+
+// Custom TypeScript interface for supported props
+interface HighlighterProps {
+ children: React.ReactNode;
+ action?: AnnotationAction;
+ color?: string;
+ strokeWidth?: number;
+ animationDuration?: number;
+ iterations?: number;
+ padding?: number;
+ multiline?: boolean;
+}
+
+export function Highlighter({
+ children,
+ action = "highlight",
+ color = "#ffd1dc", // Default pink color
+ strokeWidth = 1.5,
+ animationDuration = 600,
+ iterations = 2,
+ padding = 2,
+ multiline = true,
+}: HighlighterProps) {
+ const elementRef = useRef<HTMLSpanElement>(null);
+
+ useEffect(() => {
+ const element = elementRef.current;
+ if (element) {
+ const annotation = annotate(element, {
+ type: action,
+ color,
+ strokeWidth,
+ animationDuration,
+ iterations,
+ padding,
+ multiline,
+ });
+
+ annotation.show();
+
+ // Store the current element in closure for cleanup
+ return () => {
+ if (element) {
+ annotate(element, { type: action }).remove();
+ }
+ };
+ }
+ }, [
+ action,
+ color,
+ strokeWidth,
+ animationDuration,
+ iterations,
+ padding,
+ multiline,
+ ]);
+
+ return (
+ <span ref={elementRef} className="relative inline-block bg-transparent">
+ {children}
+ </span>
+ );
+}
diff --git a/registry/registry-examples.ts b/registry/registry-examples.ts
index a1c1e5f6..deaf3a60 100644
--- a/registry/registry-examples.ts
+++ b/registry/registry-examples.ts
@@ -1780,4 +1780,24 @@ export const examples: Registry["items"] = [
},
],
},
+ {
+ name: "highlighter-demo",
+ type: "registry:example",
+ title: "Highlighter Demo",
+ description: "Example showing the demo of a Highlighter",
+ registryDependencies: ["https://magicui.design/r/highlighter"],
+ files: [
+ {
+ path: "registry/example/highlighter-demo.tsx",
+ type: "registry:example",
+ target: "components/highlighter-demo.tsx",
+ },
+ {
+ path: "registry/magicui/highlighter.tsx",
+ type: "registry:ui",
+ target: "components/magicui/highlighter.tsx",
+ },
+ ],
+ dependencies: ["rough-notation"],
+ },
];
diff --git a/registry/registry-ui.ts b/registry/registry-ui.ts
index 58259ed6..b973dfe8 100644
--- a/registry/registry-ui.ts
+++ b/registry/registry-ui.ts
@@ -1244,4 +1244,19 @@ export const ui: Registry["items"] = [
},
],
},
+ {
+ name: "highlighter",
+ type: "registry:ui",
+ title: "Highlighter",
+ description:
+ "A text highlighter that mimics the effect of a human-drawn marker stroke.",
+ files: [
+ {
+ path: "registry/magicui/highlighter.tsx",
+ type: "registry:ui",
+ target: "components/magicui/highlighter.tsx",
+ },
+ ],
+ dependencies: ["rough-notation"],
+ },
];