Astro Component Library
This documentation provides an overview of our Astro component library, including usage examples, available props, and best practices.Table of Contents
- Layout Components
- UI Components
- Dashboard Components
- Utility Components
- Authentication Components
- Transition Components
Layout Components
Layout components provide the structure for pages and handle common elements like headers, footers, and navigation.MainLayout
The primary layout for public-facing pages. File:src/layouts/MainLayout.astro
Props:
- Includes Header and Footer components
- Handles meta tags for SEO
- Integrates ViewTransitions for smooth page transitions
- Manages theme handling with CSS variables
- Sets up responsive viewports
DashboardLayout
Layout for authenticated user dashboard pages. File:src/layouts/DashboardLayout.astro
Props:
- Includes ClientRouter for navigation without full page reloads
- Contains ErrorBoundary for graceful error handling
- Responsive design adapting to different screen sizes
- Proper meta tags for SEO and sharing
- Theme handling with CSS variables
- Smooth transitions between pages
- Enhanced accessibility features
BlogLayout
Layout for blog posts and article pages. File:src/layouts/BlogLayout.astro
Props:
- Structured data for SEO and social sharing
- Tag display and filtering
- Author information
- Reading time estimation
- Related posts suggestions
- Integrates with content collections
AdminLayout
Layout for admin dashboard and management pages. File:src/layouts/AdminLayout.astro
Props:
- Role-based access control
- Admin-specific navigation
- System status indicators
- Quick action buttons
- Enhanced security features
UI Components
Reusable UI components for building interfaces.Card
Container component with a clean, bordered appearance. File:src/components/ui/Card.astro
Props:
CardHeader: Container for the card’s header areaCardTitle: Title element for the cardCardDescription: Description text below the titleCardContent: Main content area of the cardCardFooter: Footer area, typically for actions or additional infoCardAction: Action element positioned in the top-right corner
Alert
Feedback component for displaying notifications. File:src/components/ui/Alert.astro
Props:
- Four variants: info (default), success, warning, error
- Optional icon
- Dismissible option
- Action buttons support
- Accessible design with proper ARIA attributes
Button
A versatile button component that supports different variants and sizes. File:src/components/ui/Button.astro
Props:
- Multiple variants for different use cases
- Size options including icon-only buttons
- Loading state with spinner animation
- Automatic rendering as button or anchor based on href prop
- Accessibility checks for icon-only buttons
- CSS customization through class props
- Consistent styling with design system
ThemeToggle
Button for switching between light, dark, and system themes. File:src/components/ui/ThemeToggle.astro
Props:
- Cycles between light, dark, and system theme preferences
- Persists preference in localStorage
- Automatically applies theme on page load
- ARIA-labelled for accessibility
- Smooth transition between themes
Link
Enhanced anchor component with external link handling. File:src/components/base/Link.astro
Props:
- Automatic external link detection
- Optional warning icon for links opening in new tabs
- Title and accessibility attributes for better UX
- Support for named slots (title and end)
- Proper security attributes for external links
Dashboard Components
Components specifically designed for dashboard and admin views.AdminDashboard
Main component for the admin dashboard. File:src/components/admin/AdminDashboard.astro
Props:
None. This component fetches and displays system metrics automatically.
Usage:
- Displays system metrics (active users, sessions, response time, etc.)
- Error handling for API failures
- Visual indicators for status
- Auto-updates metrics periodically
- Progress bars for capacity indicators
SecurityDashboard
Dashboard for monitoring security events. File:src/components/security/SecurityDashboard.astro
Props:
None. This component fetches and displays security events automatically.
Usage:
- Real-time security event monitoring
- Filtering by event type and severity
- Statistical overview of events
- Color-coded severity indicators
- Auto-refreshes every 30 seconds
- Cleans up event listeners when component unmounts
Utility Components
Helper components that provide additional functionality.ErrorBoundary
Catches and displays errors in a user-friendly way. File:src/components/base/ErrorBoundary.astro
Props:
- Catches JavaScript errors in child components
- Displays a friendly fallback message
- Prevents the entire page from crashing
- Logs errors to the console
- Support for custom fallback content
Authentication Components
Authentication components handle user login, registration, and password management.LoginForm
A React component for user authentication. File:src/components/auth/LoginForm.tsx
Props:
- Email and password validation
- “Remember me” functionality using localStorage
- CSRF protection with token generation
- Password reset functionality
- Error handling with toast notifications
- Loading states with visual feedback
- OAuth provider integration (Google)
- Responsive design optimized for mobile
- Cross-browser compatibility including iOS fixes
ResetPasswordForm
A React component for changing passwords after reset. File:src/components/auth/ResetPasswordForm.tsx
Props:
- Password validation with strength checks
- Matching password confirmation
- Toast notifications for feedback
- Loading indicators during submission
- Error handling with user-friendly messages
- Responsive layout optimized for mobile
PasswordResetRequestForm
A React component for requesting password reset emails. File:src/components/auth/PasswordResetRequestForm.tsx
Props:
- Email validation
- Success state tracking
- Toast notifications for feedback
- Loading indicators during submission
- Error handling with user-friendly messages
RegisterForm
A React component for new user registration. File:src/components/auth/RegisterForm.tsx
Props:
- Comprehensive form validation
- Password strength requirements
- Terms and conditions agreement
- Toast notifications for feedback
- Loading indicators during registration
- Error handling with specific messages
- OAuth registration options
AuthCard
An Astro component that provides a styled card container for authentication forms. File:src/components/auth/AuthCard.astro
Props:
- Consistent styling across authentication forms
- Proper spacing and layout
- Responsive design that fits on screen without scrolling
- Dark theme styling with black background
- Subtle animations on appearance
Transition Components
Components that handle page transitions and animations.PageTransitions
An Astro component that creates smooth transitions between pages using Astro’s View Transitions API. File:src/components/transitions/PageTransitions.astro
Props:
- Multiple transition animations (fade, slide, zoom)
- Customizable duration
- Dark mode support
- Individual element transitions with named view transitions
- Browser compatibility handling
- Smooth animations with proper timing functions
- Event handling for transition completion
Best Practices
Component Composition
Combine components to create more complex interfaces:Conditional Rendering
Use Astro’s template syntax for conditional rendering:Using Slots
Leverage Astro’s slot system for flexible content placement:Client Directives
When integrating React components, use the appropriate client directive:Testing Components
All components in the library should have corresponding tests. See the Component Testing Guide for details on how to test these components.Contributing New Components
When creating new components:- Follow the established folder structure
- Include proper TypeScript types for props
- Document props and usage
- Create tests using Vitest
- Follow the React to Astro Conversion Guide if converting from React