Cursor Display

An animated cursor highlight effect that follows your mouse and morphs to highlight interactive elements. This creates a polished, modern UI feel that provides visual feedback as users navigate your interface.

⚠️ Single Provider Pattern: Use one CursorProvider at the top level of your cursor-enabled area. Multiple providers create multiple cursors.

// ✅ Good - Single provider
<CursorProvider>
  <Section1 />
  <Section2 />
</CursorProvider>

// ❌ Bad - Multiple cursors
<CursorProvider><Section1 /></CursorProvider>
<CursorProvider><Section2 /></CursorProvider>

How It Works

The cursor display system consists of:

  1. CursorProvider - A wrapper component that tracks mouse position and renders the animated cursor overlay
  2. Pre-built components - CursorButton, CursorInputRoot, CursorSelectTrigger, CursorTextarea that automatically register with the cursor context
  3. withCursor HOC - A Higher-Order Component to add cursor highlighting to any custom component

Basic Example

Hover over the interactive elements below to see the cursor highlight effect.

Buttons

Input

Select

Textarea

Using withCursor HOC

The withCursor Higher-Order Component lets you add cursor highlighting to any component. This is useful when you want the cursor effect on custom components like Cards, Links, or any interactive element.

Custom components wrapped with withCursor

Cursor Card

This Card component is wrapped with withCursor

Interactive

Another Card

Hover to see the cursor highlight effect

Hover me

Even a plain div can be enhanced with cursor effects!

How withCursor Works

import { withCursor } from '@vuer-ai/vuer-uikit';

// Wrap a component
const CursorCard = withCursor(Card);

// Use it inside a CursorProvider
<CursorProvider>
  <CursorCard>Hover me!</CursorCard>
</CursorProvider>

The HOC:

  • Tracks onMouseEnter, onMouseMove, and onMouseOut events
  • Calculates the visible portion of the element (handles scrollable containers)
  • Registers/unregisters the element with the cursor context
  • Preserves forwarded refs and original event handlers

Full Page Layout Example

A comprehensive example showing how cursor display enhances a settings page with navigation, forms, and various interactive elements.

Profile
Notifications
Security
Appearance

Profile Settings

Manage your account information

CursorProvider Props

PropTypeDefaultDescription
maxOffsetXnumber5Maximum horizontal offset when cursor is near element edge
maxOffsetYnumber20Maximum vertical offset when cursor is near element edge
cursorSizenumber20Size of the cursor dot when not hovering an element
boundaryThresholdnumber4Distance from element edge (inside) before offset begins
outerThresholdnumber8Distance outside element before offset reaches maximum
cursorClassNamestring-Additional CSS classes for the cursor element
classNamestring-CSS classes for the provider wrapper
asElementType"div"The element type to render as the wrapper

Available Components

ComponentDescription
CursorProviderWrapper that enables cursor tracking and renders the overlay
CursorButtonButton with cursor highlighting
CursorInputRootInput field with cursor highlighting
CursorSelectTriggerSelect trigger with cursor highlighting
CursorTextareaTextarea with cursor highlighting
withCursorHOC to add cursor highlighting to any component

Best Practices

  1. Wrap at the right level - Place CursorProvider around the area where you want the cursor effect. It can be a whole page or just a specific section.

  2. Use pre-built components - For common UI elements, use the pre-built Cursor* components for consistency.

  3. Custom components - Use withCursor for cards, navigation items, or any custom interactive elements.

  4. Consider scrollable containers - The cursor system automatically handles elements inside scrollable containers by calculating the visible portion.

  5. Performance - The cursor uses position: fixed and CSS transitions for smooth performance. The overlay is portaled to document.body to avoid layout issues.