UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
The coree/main (#757)
Arghya Das439a886b5e7e
diff --git a/registry/magicui/highlighter.tsx b/registry/magicui/highlighter.tsxindex df829b00..f842f015 100644--- a/registry/magicui/highlighter.tsx+++ b/registry/magicui/highlighter.tsx@@ -1,10 +1,10 @@"use client";import { useEffect, useRef } from "react";+import { useInView } from "motion/react";import { annotate } from "rough-notation";import type React from "react";-// Define available annotation actionstype AnnotationAction =| "highlight"| "underline"@@ -14,7 +14,6 @@ type AnnotationAction =| "crossed-off"| "bracket";-// Custom TypeScript interface for supported propsinterface HighlighterProps {children: React.ReactNode;action?: AnnotationAction;@@ -24,43 +23,54 @@ interface HighlighterProps {iterations?: number;padding?: number;multiline?: boolean;+ isView?: boolean;}export function Highlighter({children,action = "highlight",- color = "#ffd1dc", // Default pink color+ color = "#ffd1dc",strokeWidth = 1.5,animationDuration = 600,iterations = 2,padding = 2,multiline = true,+ isView = false,}: HighlighterProps) {const elementRef = useRef<HTMLSpanElement>(null);+ const isInView = useInView(elementRef, {+ once: true,+ margin: "-10%",+ });++ // If isView is false, always show. If isView is true, wait for inView+ const shouldShow = !isView || isInView;useEffect(() => {+ if (!shouldShow) return;+const element = elementRef.current;- if (element) {- const annotation = annotate(element, {- type: action,- color,- strokeWidth,- animationDuration,- iterations,- padding,- multiline,- });+ if (!element) return;++ const annotation = annotate(element, {+ type: action,+ color,+ strokeWidth,+ animationDuration,+ iterations,+ padding,+ multiline,+ });- annotation.show();+ annotation.show();- // Store the current element in closure for cleanup- return () => {- if (element) {- annotate(element, { type: action }).remove();- }- };- }+ return () => {+ if (element) {+ annotate(element, { type: action }).remove();+ }+ };}, [+ shouldShow,action,color,strokeWidth,