Shiny Button
A button component with a shiny gradient mask effect that continuously animates across the text, creating an elegant shine effect. The button features smooth spring animations and scales down on press, providing a premium interactive experience.Installation
Usage
Examples
Basic Usage
With Custom Styling
Dark Theme
With Click Handler
Props
The content to display inside the button.
Additional CSS classes to apply to the button.
All standard HTML button attributes are supported (onclick, disabled, type, etc.).
Component Details
Animation Behavior
The Shiny Button creates its effect through motion-sv (Framer Motion for Svelte) animations:- Gradient Mask: A linear gradient masks the text, creating the shine effect
- Horizontal Movement: The gradient position animates from right (-75deg) to left
- Border Shine: A complementary gradient animates on the border
- Spring Physics: Natural spring animations for scale effects
- Press Feedback: Scales down to 0.95 when pressed
- Infinite Loop: Continuously repeats with a 1-second delay between cycles
Motion Configuration
The component uses sophisticated motion properties:Gradient Masks
The component uses two gradient masks: Text Gradient:CSS Variables
The component uses the--x CSS variable to control the gradient position, which is animated by motion-sv.
Dark Mode Adaptation
The button automatically adapts to dark mode:- Light mode: 65% black text
- Dark mode: 90% white text with lighter font weight
- Background: Radial gradient from primary color in dark mode
- Shadow: Enhanced shadow on hover in dark mode
Dependencies
motion-sv- For spring animations and gesture handling- Tailwind CSS - For styling
Accessibility
The component maintains full button accessibility:- Semantic
<button>element via motion.button - Full keyboard support (Tab, Enter, Space)
- Screen reader compatible
- Focus states maintained
- Press states with tactile feedback
- All ARIA attributes supported
The shine effect is purely decorative and doesn’t interfere with accessibility.
Use Cases
The Shiny Button is ideal for:- Premium actions: Highlight important or premium features
- Call-to-action: Draw attention to primary actions
- Hero sections: Create visual interest in landing pages
- Modern interfaces: Add polish to contemporary designs
- Interactive elements: Provide engaging user feedback
Performance Notes
The component is optimized for performance:- Hardware acceleration: Uses CSS transforms
- Spring physics: Natural, efficient animations
- CSS variables: Animated via CSS custom properties
- Motion-sv optimization: Leverages motion-sv’s performance features
Motion-sv Benefits
motion-sv provides:- Automatic hardware acceleration
- Optimized animation scheduling
- Efficient spring physics calculations
- Gesture handling without extra event listeners
Browser Compatibility
The component requires:- CSS Variables: All modern browsers
- CSS Mask: All modern browsers (Safari 15.4+, Chrome 120+, Firefox 115+)
- Spring animations: Handled by motion-sv
Customization Tips
Adjust Shine Speed
Modify the transition properties:Custom Colors
Override the primary color:Border Styling
Customize the border:Background Effects
Add custom backgrounds:Reduced Motion Support
For users who prefer reduced motion, consider adding:prefers-reduced-motion automatically for most animations.
Comparison with Shimmer Button
While similar, the Shiny Button differs from the Shimmer Button:| Feature | Shiny Button | Shimmer Button |
|---|---|---|
| Animation Library | motion-sv | CSS only |
| Effect Type | Gradient mask on text | Rotating spark |
| Press Feedback | Spring scale | Vertical shift |
| Complexity | Moderate | High |
| Performance | Excellent | Excellent |
| Customization | Limited | Extensive |