Skip to main content

Slider Spell

The SliderSpell component creates an interactive horizontal slider that appears at the cursor position, perfect for making precise numerical adjustments. It features smooth mouse-based control, customizable ranges, and integrates seamlessly with Cedar’s hold-mode activation pattern.

Features

  • Mouse-Driven Control: Horizontal mouse movement directly controls slider value
  • Hold Mode Integration: Activates on key/mouse hold, executes on release
  • Customizable Ranges: Configure min, max, step, and units
  • Visual Feedback: Real-time value display above slider thumb
  • Smart Positioning: Appears above cursor, centered horizontally
  • Theme Integration: Adapts to Cedar’s light/dark mode
  • Smooth Animations: Container3D styling with smooth transitions

Installation

Basic Usage

Usage: Hold ‘O’ key and move mouse horizontally to adjust opacity from 0-100%.

Props

SliderSpell Props

SliderConfig Interface

Hold Mode Pattern

The SliderSpell is designed for hold-mode interaction, providing natural and efficient value selection:
User flow:
  1. Hold key (or right-click) to activate slider
  2. Move mouse horizontally to adjust value
  3. Release to confirm selection and execute callback
  4. Press ESC while holding to cancel

Advanced Examples

Volume Control

Create a volume slider with audio feedback:

Color Opacity Adjuster

Adjust transparency for design tools:

Temperature Sensor Reading

For scientific or IoT applications:

Multiple Sliders System

Coordinate multiple sliders for complex adjustments:

Dynamic Range Slider

Adjust slider range based on context:

Mouse Sensitivity

The slider uses a sensitivity system to map mouse movement to value changes:

Customizing Sensitivity

While not directly configurable, you can adjust effective sensitivity by modifying your range:

Visual Behavior

Positioning

The slider appears above the cursor, centered horizontally:
  • Mouse Events: Positioned at cursor location
  • Keyboard Events: Positioned at viewport center
  • Above Cursor: Positioned with 8px gap above cursor
  • Centered: Horizontally centered on activation point

Value Display

  • Real-time Updates: Value shown above slider thumb
  • Unit Display: Configured unit appears after value
  • Theme Adaptive: Colors adapt to light/dark mode
  • Smooth Transitions: No jarring animations, just smooth updates

Styling Integration

The component uses Cedar’s styling system:
  • Container3D: 3D-styled slider track and thumb
  • Theme Colors: Respects dark/light mode preferences
  • Consistent Typography: Matches Cedar’s text styling
  • Backdrop Blur: Subtle backdrop blur for better visibility

Interaction Details

Mouse Control

  • Horizontal Movement: Only horizontal mouse movement affects value
  • Relative Positioning: Movement relative to activation point
  • Continuous Updates: Value updates in real-time during movement
  • Clamping: Values automatically clamped to min/max range
  • Step Snapping: Values snap to configured step increments

Keyboard Support

  • ESC: Cancel slider without executing callback
  • Hold Pattern: Must hold activation key throughout interaction
  • Release to Confirm: Release key to execute callback with final value

Edge Cases

  • Viewport Boundaries: Slider stays within viewport bounds
  • Rapid Movement: Handles fast mouse movements smoothly
  • Step Precision: Ensures values align with step configuration

Best Practices

1. Choose Appropriate Ranges

2. Use Meaningful Units

3. Logical Key Bindings

4. Handle Errors Gracefully

5. Provide Visual Context

Performance Considerations

Efficient Updates

  • Throttled Rendering: Value updates are smooth but not excessive
  • Ref-based State: Uses refs to avoid unnecessary re-renders
  • Conditional Rendering: Only renders when active
  • Memory Cleanup: Automatically cleans up event listeners

Event Handling

  • Single Listener: Uses efficient event delegation
  • Debounced Actions: Prevents spam during rapid movements
  • Optimized Calculations: Minimal computation per mouse move

Accessibility

Keyboard Navigation

  • The slider is primarily mouse-driven but keyboard accessible
  • ESC key provides clear exit path
  • Hold pattern is intuitive for keyboard users

Screen Reader Support

Consider providing alternative interfaces for screen readers:

Alternative Access

Provide multiple ways to adjust values:

Common Patterns

Media Controls

Design Tools

Scientific Instruments

Troubleshooting

Slider not appearing

  • Check that spell ID is unique
  • Verify activation conditions are correct
  • Ensure component is mounted
  • Check for conflicting event handlers

Values not updating

  • Verify mouse movement is being detected
  • Check min/max/step configuration
  • Ensure onComplete callback is defined
  • Check for JavaScript errors

Position issues

  • Verify cursor position detection
  • Check for CSS transforms on parent elements
  • Ensure proper z-index for visibility
  • Check viewport boundary calculations

Performance problems

  • Reduce update frequency if needed
  • Check for memory leaks in callbacks
  • Verify event listeners are cleaned up
  • Monitor re-render frequency