Component Organization
Components are organized into three main directories based on their purpose:Design Philosophy
Components
Small, reusable UI elements like buttons, alerts, and forms
Sections
Large page sections that compose multiple components
Layouts
Full-page wrappers with consistent structure and SEO
The Component Hierarchy
Let’s trace how components compose from top to bottom:Example: Homepage Structure
Here’s how the homepage (src/pages/index.astro) composes components:
src/pages/index.astro
Layout Components
Layout components wrap entire pages with consistent structure.Main Layout (Layout.astro)
The primary layout used by almost all pages:
src/layouts/Layout.astro
Layout Features
SEO Metadata
SEO Metadata
The layout handles all SEO-critical tags:
- Title - Page title with fallback
- Description - Meta description
- Canonical URL - Prevents duplicate content
- Keywords - SEO keywords
- Open Graph - Social media sharing tags
- Schema.org - Structured data for search engines
Global Styles
Global Styles
Three global stylesheets are imported:
Google Fonts
Google Fonts
Two font families are loaded:
- Inter (300, 400, 500, 600) - Body text
- Outfit (400, 500, 600, 700, 800) - Headings
Consistent Structure
Consistent Structure
Every page using this layout gets:
- Navigation bar (top)
- Page content (
<slot />) - Footer (bottom)
- Cookie consent banner
Blog Layout (BlogPost.astro)
A specialized layout for blog posts:
src/layouts/BlogPost.astro
Atomic Components
Small, reusable components that form the building blocks.Alert Component
A versatile alert component with multiple types:src/components/Alert.astro
Usage
src/content/blog/example.mdx
Icon Component
Icons are used throughout with theastro-icon package:
@iconify-json/mdi package.
Section Components
Larger components that compose multiple smaller components.Hero Section
src/sections/Hero.astro
Promotion Main Section
This component displays promotion details using content collections:src/components/Promociones/PromoMain.astro
- Fetches promotion data
- Displays the promotion details
- Composes other sections (ProcesoEntrega, WebTienda)
- Includes custom styled list items with checkmark icons
Component Patterns
Path Aliases
The project uses@/ as an alias for src/:
tsconfig.json
Props with TypeScript
Components define typed props using TypeScript interfaces:- IntelliSense when using the component
- Type checking at build time
- Self-documenting component API
Slots for Content Projection
The<slot /> element allows parent components to pass content:
src/components/Card.astro
Scoped Styles
Component styles are scoped by default:Tailwind Utility Classes
Most styling uses Tailwind CSS utilities:- Rapid development
- Consistent design system
- No CSS bloat
- Responsive by default
Component Categories
Navigation Components
- NavBar.astro - Main navigation bar
- HeaderLink.astro - Individual nav links
- Breadcrumbs.astro - Breadcrumb navigation
- FlechaAbajo.astro - Scroll-down arrow
- FlechaArriba.astro - Scroll-up arrow
Content Display
- Alert.astro - Info/warning/success alerts
- Autor.astro - Author bio
- BlogSidebar.astro - Blog post sidebar
- AccordionItemSEO.astro - FAQ accordion
Forms & Interaction
- FormMautic.astro - Marketing form
- FormSimple.astro - Simple contact form
- BotonPrecios.astro - Pricing CTA button
Marketing Components
- UrgencyBanner.astro - Urgency banner at top
- TrustBadges.astro - Trust indicators
- GoogleReviews.astro - Review widget
- Estrellas.astro - Star rating display
- CuentaAtras.astro - Countdown timer
Legal & Compliance
- Cookies.astro - Cookie consent banner
- Legal components - Privacy, terms, GDPR
Promotional
- PromoMain.astro - Main promotion display
- PromoLista.astro - Promotion list
- PromoDoble.astro - Two-column promos
- HeroOfertas.astro - Promotional hero
- Caracteristicas.astro - Feature list
Best Practices
Next Steps
Content Collections
Learn how components consume content data
Astro Framework
Understand how Astro renders components