highlight-text
jolyui-ui/highlight-textFreeComponent
jolyui/ui publishes no description for this item.
Install it
npx shadcn@latest add https://jolyui.dev/r/highlight-text.jsonSource
1import { cva } from "class-variance-authority";2import * as React from "react";3import { cn } from "@/lib/utils";45const highlightVariants = cva("relative inline-block", {6 variants: {7 variant: {8 underline: "",9 box: "",10 circle: "",11 marker: "",12 },13 color: {14 primary:15 "[--highlight-color:hsl(var(--highlight-primary))] [&_path]:[stroke:var(--highlight-color)]",16 secondary:17 "[--highlight-color:hsl(var(--highlight-secondary))] [&_path]:[stroke:var(--highlight-color)]",18 accent:19 "[--highlight-color:hsl(var(--highlight-accent))] [&_path]:[stroke:var(--highlight-color)]",20 destructive:21 "[--highlight-color:hsl(var(--highlight-destructive))] [&_path]:[stroke:var(--highlight-color)]",22 },23 },24 defaultVariants: {25 variant: "underline",26 color: "primary",27 },28});2930type HighlightColor = "primary" | "secondary" | "accent" | "destructive";31type HighlightVariant = "underline" | "box" | "circle" | "marker";3233export interface HighlightTextProps34 extends Omit<React.HTMLAttributes<HTMLSpanElement>, "color"> {35 children: React.ReactNode;36 variant?: HighlightVariant;37 color?: HighlightColor;38 animationDuration?: number;39 animationDelay?: number;40 strokeWidth?: number;41 animate?: boolean;42}4344const HighlightText = React.forwardRef<HTMLSpanElement, HighlightTextProps>(45 (46 {47 className,48 variant = "underline",49 color = "primary",50 children,51 animationDuration = 0.8,52 animationDelay = 0,53 strokeWidth = 2,54 animate = true,55 ...props56 },57 ref,58 ) => {59 const [isVisible, setIsVisible] = React.useState(!animate);60 const [dimensions, setDimensions] = React.useState({ width: 0, height: 0 });61 const containerRef = React.useRef<HTMLSpanElement>(null);6263 React.useEffect(() => {64 const element = containerRef.current;65 if (!element) return;6667 const updateDimensions = () => {68 setDimensions({69 width: element.offsetWidth,70 height: element.offsetHeight,71 });72 };7374 updateDimensions();7576 const resizeObserver = new ResizeObserver(updateDimensions);77 resizeObserver.observe(element);7879 return () => resizeObserver.disconnect();80 }, []);8182 React.useEffect(() => {83 if (!animate) {84 setIsVisible(true);85 return;86 }8788 const element = containerRef.current;89 if (!element) return;9091// … truncated
What it pulls in
npm packages
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-boxai-prompt-box | jolyui/ui | Components | Free | 4 deps | |
| animated-beamanimated-beam | jolyui/ui | Components | Free | 1 dep | |
| animated-tableanimated-table | jolyui/ui | Components | Free | 2 deps | |
| animated-theme-toggleanimated-theme-toggle | jolyui/ui | Components | Free | 2 deps | |
| animated-toastanimated-toast | jolyui/ui | Components | Free | 2 deps | |
| animated-tooltipanimated-tooltip | jolyui/ui | Components | Free | 1 dep | |
| bento-gridbento-grid | jolyui/ui | Components | Free | no deps | |
| buttonbutton | jolyui/ui | Components | Free | 3 deps |
