UI Caret
snap-cn/caretFreeComponent
A blinking text caret — a controlled vertical bar, or a pure motion atom that blinks deterministically from useCurrentFrame.
Install it
npx shadcn@latest add https://snapcn.dev/r/caret.jsonSource
1"use client";23import type { CSSProperties } from "react";4import { useCurrentFrame, useVideoConfig } from "remotion";56export interface CaretProps {7 color?: string;8 width?: number;9 height?: number;10 radius?: number;11 opacity?: number;12 blink?: boolean;13 blinkPerSecond?: number;14 speed?: number;15 marginLeft?: number;16 className?: string;17 style?: CSSProperties;18}1920export function caretBlinkOpacity(21 frame: number,22 opts: { fps: number; blinkPerSecond: number; speed: number },23): number {24 const cycles = opts.blinkPerSecond <= 0 ? 1 : opts.blinkPerSecond;25 const halfPeriod = opts.fps / cycles / 2;26 if (halfPeriod <= 0) return 1;27 return Math.floor((frame * opts.speed) / halfPeriod) % 2 === 0 ? 1 : 0;28}2930export function Caret({31 color = "currentColor",32 width = 2,33 height = 18,34 radius = 1,35 opacity,36 blink = false,37 blinkPerSecond = 1,38 speed = 1,39 marginLeft = 0,40 className,41 style,42}: CaretProps) {43 const frame = useCurrentFrame();44 const { fps } = useVideoConfig();4546 const resolvedOpacity =47 opacity !== undefined48 ? opacity49 : blink50 ? caretBlinkOpacity(frame, { fps, blinkPerSecond, speed })51 : 1;5253 return (54 <span55 className={className}56 style={{57 display: "inline-block",58 flexShrink: 0,59 width,60 height,61 borderRadius: radius,62 background: color,63 opacity: resolvedOpacity,64 marginLeft,65 ...style,66 }}67 />68 );69}
What it pulls in
npm packages
Files it writes
More from snap-cn
All 24 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Answer Streamanswer-stream | snap-cn | Components | Free | 2 deps | |
| Follower Rushfollower-rush | snap-cn | Components | Free | 2 deps | |
| Product Herohero-launch | snap-cn | Components | Free | 2 deps | |
| UI Inputinput | snap-cn | Components | Free | 2 deps · 2 files | |
| Karaoke Captionskaraoke-captions | snap-cn | Components | Free | 2 deps | |
| Laptop Framelaptop-frame | snap-cn | Components | Free | 1 dep | |
| Logo Assemblelogo-assemble | snap-cn | Components | Free | 1 dep | |
| Logo Flickerlogo-flicker | snap-cn | Components | Free | 1 dep |
