Ripple Button
A button component with an interactive ripple effect that appears on click, expanding outward from the exact click position. This creates a Material Design-inspired touch feedback effect that provides clear visual confirmation of user interaction.Installation
Usage
Examples
Basic Usage
Custom Ripple Color
Custom Duration
With Click Handler
Fully Customized
Props
The content to display inside the button.
Additional CSS classes to apply to the button.
The color of the ripple effect. Accepts any valid CSS color value (hex, rgb, rgba, hsl, etc.). Use semi-transparent colors for best effect.
The duration of the ripple animation from start to fade out. Accepts any valid CSS duration value (e.g., “600ms”, “1s”).
Click event handler. The ripple effect is created automatically, and your handler is called after.
All standard HTML button attributes are supported (disabled, type, aria-*, etc.).
Component Details
Animation Behavior
The Ripple Button creates an interactive click effect through:- Click Detection: Captures the exact mouse click coordinates
- Ripple Creation: Creates a circular ripple at the click position
- Expansion Animation: The ripple scales from 0 to 2x while fading out
- Auto Cleanup: Removes completed ripples from the DOM automatically
Implementation Details
The component uses Svelte 5 runes for state management:x,y: Position coordinates relative to the buttonsize: Diameter of the ripple (based on button size)key: Unique identifier for cleanup
Keyframe Animation
The component requires this CSS keyframe (automatically included via registry):Position Calculation
The ripple is intelligently positioned:Multiple Ripples
The component supports multiple simultaneous ripples, allowing users to click rapidly without interference. Each ripple is independently tracked and removed after its animation completes.Dependencies
runed- For thewatchutility to manage ripple lifecycle- Tailwind CSS - For base styling
Accessibility
The ripple effect is purely decorative and doesn’t affect button functionality:- Semantic
<button>element - Full keyboard support (Enter, Space)
- Screen reader compatible
- Focus states maintained
- Click handlers work normally
- All ARIA attributes supported
The ripple container uses
pointer-events-none to ensure it doesn’t interfere with button interactions.Use Cases
The Ripple Button is ideal for:- Touch interfaces: Provides tactile feedback on mobile and tablets
- Form submissions: Confirms button activation
- Interactive dashboards: Enhances user interaction feedback
- Material Design: Follows Material Design principles
- Any clickable element: Works great for any interactive button
Performance Notes
The component is optimized for performance:- Efficient cleanup: Ripples are removed immediately after animation
- CSS animations: Uses hardware-accelerated transforms
- Minimal DOM: Only active ripples exist in the DOM
- No layout thrashing: Absolute positioning prevents reflows
Memory Management
Thewatch rune automatically cleans up timeouts when ripples complete: