Component Architecture
Astro components use a unique.astro format that combines:
- Frontmatter (TypeScript/JavaScript)
- Template (HTML-like JSX)
- Scoped styles (CSS)
- Client-side scripts
Creating a New Component
Create the Component File
Components live in For property-related components, use the subdirectory:
src/components/. Create a new file:Real Example: Footer Component
Let’s examine the existingFooter.astro component as a reference:
Location: src/components/Footer.astro
- Uses i18n utilities for translations
- Computes
currentYeardynamically - Scoped styles (not shown for brevity)
src/components/Footer.astro:1-100 for the full implementation.
Styling Patterns
Using CSS Custom Properties
The project uses consistent CSS variables defined insrc/styles/global.css:
Responsive Design
Follow the existing breakpoint conventions:Adding Client-Side Interactivity
For components that need JavaScript, use<script> tags:
Animation Integration
Add scroll-triggered animations using the project’s utilities:See the Customizing Animations guide for detailed animation patterns.
Component Props Patterns
Required vs Optional Props
Complex Props (Example: Property Component)
src/types/index.ts:74-77 for the PropertyCardProps interface.
Reusable Component Examples
The project includes several reusable components you can reference:Navigation
Location:
src/components/Navigation.astroFeatures:- Desktop and mobile layouts
- Hamburger menu animation
- Language switcher
- Auto-hide on scroll
src/components/Navigation.astro:1-469ScrollGallery
Location:
src/components/ScrollGallery.astroFeatures:- Scroll-hijacking gallery
- Progress indicators
- Configurable text position
- Responsive layout
src/components/ScrollGallery.astro:1-80ShareButtons
Location:
src/components/ShareButtons.astroFeatures:- Social media sharing
- WhatsApp integration
- Copy link functionality
- QR code generation
EmptySection
Location:
src/components/EmptySection.astroFeatures:- Simple placeholder component
- Minimal styling
- Reusable pattern
Best Practices
Component Size
Component Size
Keep components focused and single-purpose. If a component exceeds 200 lines, consider breaking it into smaller sub-components.
TypeScript Types
TypeScript Types
Always define Props interfaces. This provides autocomplete and type safety:
Scoped Styles
Scoped Styles
Prefer scoped styles in
<style> tags over global CSS. This prevents style conflicts between components.Accessibility
Accessibility
Include proper ARIA labels and semantic HTML:
Testing Your Component
Visual Testing
Add your component to a test page and run the dev server:Navigate to the page and verify appearance.
Responsive Testing
Use browser DevTools device emulation to test different screen sizes:
- Desktop (greater than 1024px)
- Tablet (768px - 1023px)
- Mobile (less than 768px)
Next Steps
Working with Properties
Learn about the Property interface and data fetching
Customizing Animations
Add scroll-triggered animations to your components