Installation
Enable thematerial-design feature in your Cargo.toml:
Importing
Components
Ripple Effect
TheRipple component creates a Material Design-style ripple effect that expands from the click position and fades out.
Basic Usage
Customization
Properties
color(color)- Set the ripple color (default: primary theme color)duration(duration)- Set animation duration (default: 800ms)
Material Button
Extend any Freya button with a ripple effect using theripple() method.
Basic Material Button
Customization
Complete Example
How It Works
Ripple Component
TheRipple component:
- Listens for mouse down events
- Creates a ripple instance at the click location
- Animates the ripple expanding and fading out
- Automatically removes finished ripples
Button Integration
TheButtonRippleExt trait:
- Wraps the button’s children in a
Ripplecomponent - Preserves all button functionality (press events, styling, etc.)
- Adjusts padding to maintain the button’s original appearance
Animation Details
Ripple Animation
- Scale: Animates from 0 to max_size (2.5x container size)
- Opacity: Fades from 0.35 to 0.0
- Duration: Default 800ms, customizable
- Easing: Expo ease-out for natural motion
Multiple Ripples
The component supports multiple simultaneous ripples - each click creates a new ripple that animates independently.Styling
Default Ripple Color
By default, ripples use the theme’s primary color:Custom Colors
Transparent Backgrounds
Ripples work well with transparent backgrounds:Layout Integration
Ripples respect the container’s layout and overflow:Advanced Usage
Custom Interactive Element
Multiple Ripple Colors
Fast Ripples
API Reference
Ripple
ButtonRippleExt
RippleButton
Examples
Material Card
Icon Button
List Item
Notes
- Ripples are automatically clipped to the container’s bounds
- Multiple ripples can animate simultaneously
- Ripples use the Freya animation system for smooth 60fps animations
- The ripple effect works on any element, not just buttons
- Default ripple color comes from the current theme