Directory
- Welcome
Icon Component
The Icon component provides a consistent way to display SVG icons throughout your application. With built-in size variants and hover effects, you can easily integrate icons that match your design system.
Key Features
-
Multiple Sizes: Pre-defined size variants from small to extra-large
-
Hover Effects: Optional hover states for interactive icons
-
Flexible Integration: Works with any SVG content
-
Responsive Design: Automatic scaling and fitting options
Basic Usage
The Icon component accepts SVG content through the svg
prop:
---import importedSvg from '@/assets/icons/example.svg?raw';---
<Icon svg={importedSvg} />
Size Variants
The Icon component comes with predefined size variants:
<Icon svg={mySvg} size="sm" /> <!-- 16x16 pixels --><Icon svg={mySvg} size="md" /> <!-- 20x20 pixels --><Icon svg={mySvg} size="default" /> <!-- 24x24 pixels --><Icon svg={mySvg} size="lg" /> <!-- 32x32 pixels --><Icon svg={mySvg} size="xl" /> <!-- 48x48 pixels --><Icon svg={mySvg} size="fit" /> <!-- Fits container -->
Interactive Variants
Add hover effects to make icons interactive:
<Icon svg={mySvg} variant="default" /> <!-- Static icon --><Icon svg={mySvg} variant="hover" /> <!-- Hover effect -->
Component API
Prop | Type | Default | Description |
---|---|---|---|
svg | string | - | SVG content to display |
size | sm | md | default | lg | xl | fit | default | Icon size variant |
variant | default | hover | default | Visual style variant |
class | string | - | Additional CSS classes |
Best Practices
-
SVG Optimization
- Optimize SVGs before use
- Remove unnecessary attributes
- Use consistent viewBox sizes
- Minimize path complexity
-
Accessibility
- Include aria-label when icon conveys meaning
- Use role=“img” for decorative icons
- Ensure sufficient color contrast
- Consider icon recognition
Limited Time Launch Sale
Add beautiful, responsive icons to your project with our Icon component. Get started with our AstroJS starter template today!
GET 60% OFF!