Alpine.js Setup
Alpine.js is bundled with the theme insource/js/main.js:
Official Plugins
The theme includes three official Alpine.js plugins:Collapse Plugin
Smooth height transitions for showing/hiding content. Installation:Intersect Plugin
Trigger actions when elements enter or leave the viewport. Installation:Focus Plugin
Manage focus within elements (useful for modals, dropdowns). Installation:Custom Alpine Data
The theme includes a customxDOM data component:
Common Patterns
Toggle Pattern
Show/hide content:Dropdown Menu
Accessible dropdown with focus trap:Modal Dialog
Full-featured modal:Tabs Component
Tab interface:Smooth Scroll Animations
Animate on scroll:Alpine Directives Reference
Core Directives
x-data- Declare component datax-init- Run code when component initializesx-show- Toggle visibility (display)x-if- Conditional rendering (DOM)x-for- Loop over datax-on/@- Event listenersx-bind/:- Bind attributesx-model- Two-way data bindingx-text- Set text contentx-html- Set HTML contentx-ref- Reference elementsx-cloak- Hide until Alpine loadsx-transition- Transition utilities
Modifiers
.prevent- preventDefault().stop- stopPropagation().outside- Trigger when clicking outside.window- Listen on window.once- Only trigger once.debounce- Debounce input.throttle- Throttle events
Best Practices
Keep Components Small
Break complex interactions into smaller components:Use Descriptive State Names
Leverage Magic Properties
Use Alpine’s magic properties:Combine with Tailwind
Dynamic Tailwind classes:Debugging
Alpine is available globally for debugging:Performance Tips
- Use
x-iffor expensive DOM - Removes from DOM entirely - Use
x-showfor frequent toggles - Only toggles display - Use
.oncemodifier - For one-time events - Debounce user input -
.debounce.500ms - Lazy load components - Use
x-intersectto initialize