### Event Handling Example (HTML)
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
Shows how to listen for events emitted by the Alpine Calendar component using Alpine.js's `@` syntax. This allows for reacting to changes in selection or navigation.
```html
```
--------------------------------
### Presetting Multiple Date Values
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This example shows how to set multiple initial dates for the calendar. The `value` option takes a comma-separated string of dates, pre-selecting '2026-03-10', '2026-03-15', and '2026-03-20'.
```html
```
--------------------------------
### Programmatic Control Example (HTML)
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
Demonstrates how to programmatically control the Alpine Calendar component using its exposed methods via `$refs`. This allows for setting dates or clearing the selection from external HTML elements.
```html
```
--------------------------------
### Presetting Single Date Value
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This example shows how to set an initial single date value for the calendar. The `value` option in the `calendar()` configuration is used to pre-select '2026-03-15' when the calendar is initialized.
```html
```
--------------------------------
### Initialize Alpine Calendar Plugin
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This snippet demonstrates how to import and register the calendar plugin with Alpine.js. It requires Alpine.js to be installed.
```javascript
import Alpine from 'alpinejs'
import { calendarPlugin } from '../src/index.ts'
Alpine.plugin(calendarPlugin)
Alpine.start()
```
--------------------------------
### Alpine Calendar: Sunday Start Day Configuration
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
Explains how to override the default Monday start day to Sunday using the `firstDay: 0` option. This is useful for regions where the week traditionally starts on Sunday.
```html
```
--------------------------------
### Configure Calendar in Year-Month Wizard Mode
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This configuration starts the wizard mode from the year view, then proceeds to month selection, and finally day selection. It's activated using `wizard: 'year-month'`.
```html
```
--------------------------------
### Install Alpine Calendar with npm/pnpm and Initialize AlpineJS
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This snippet shows how to add the Alpine Calendar package using npm or pnpm and then initialize AlpineJS with the calendar plugin. It ensures the calendar's CSS is also imported for proper styling.
```bash
pnpm add @reachweb/alpine-calendar
# or
npm install @reachweb/alpine-calendar
```
```javascript
import Alpine from 'alpinejs'
import { calendarPlugin } from '@reachweb/alpine-calendar'
import '@reachweb/alpine-calendar/css'
Alpine.plugin(calendarPlugin)
Alpine.start()
```
--------------------------------
### Configure Calendar with Static Date Metadata (Room Pricing)
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This example shows how to attach metadata like pricing and availability to specific dates using a static object. Dates can be styled based on their metadata, such as showing price labels or indicating availability.
```html
```
--------------------------------
### Range Presets Setup with JavaScript
Source: https://context7.com/reachweb/alpine-calendar/llms.txt
Imports predefined functions for generating common date range presets like 'Today', 'Last 7 Days', and 'This Month'. These presets can be used to quickly populate the calendar's range selection.
```javascript
import {
presetToday,
presetYesterday,
presetLastNDays,
presetThisWeek,
presetLastWeek,
presetThisMonth,
presetLastMonth,
presetThisYear,
presetLastYear,
} from '@reachweb/alpine-calendar'
```
--------------------------------
### Configure Calendar in Popup Wizard Mode
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This setup displays the full wizard mode within a popup dropdown, triggered by interacting with an input field. It combines `wizard: true` with `display: 'popup'`.
```html
```
--------------------------------
### Listen to Calendar Events (HTML & JavaScript)
Source: https://context7.com/reachweb/alpine-calendar/llms.txt
Illustrates how to listen for various calendar events such as 'change', 'navigate', 'open', 'close', and 'view-change' using Alpine.js directives. It provides example JavaScript functions to handle the event details.
```html
```
--------------------------------
### Configure Calendar with Disabled/Enabled Date Exceptions
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This example demonstrates how to disable weekends by default but then selectively enable specific dates and disable others within a given period. It uses `disabledDaysOfWeek`, `enabledDates`, and `disabledDates` for fine-grained control.
```html
```
--------------------------------
### Development Commands for Alpine Calendar
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
Lists common pnpm commands used for developing and maintaining the Alpine Calendar project. These commands cover dependency installation, running the development server, executing tests, type checking, linting, formatting, and building different bundle outputs.
```bash
pnpm install # Install dependencies
pnpm dev # Start dev server with demo
pnpm test # Run tests
pnpm test:watch # Run tests in watch mode
pnpm test:coverage # Run tests with coverage report
pnpm typecheck # Type-check without emitting
pnpm lint # Lint source files
pnpm lint:fix # Lint and auto-fix
pnpm format # Format source files with Prettier
pnpm build # Build all bundles (ESM + UMD + CDN + CSS + types)
pnpm build:lib # Build ESM + UMD only
pnpm build:cdn # Build CDN/IIFE bundle only
# Full verification chain before release:
pnpm typecheck && pnpm lint && pnpm test && pnpm build
```
--------------------------------
### Livewire Integration for Alpine Calendar
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
Shows how to integrate Alpine Calendar with Livewire, including adding necessary CSS and JavaScript files via `@push` directives and using `wire:ignore` to prevent Livewire from interfering with the calendar's DOM manipulation. This setup allows for seamless use of the calendar within Livewire applications.
```php
@push('styles')
@endpush
@push('scripts')
@endpush
```
--------------------------------
### Install Alpine Calendar via CDN
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This snippet demonstrates how to include the Alpine Calendar component using Content Delivery Network (CDN) links. It includes the necessary CSS and JavaScript files for both AlpineJS and the calendar plugin, suitable for projects without a bundler.
```html
```
--------------------------------
### Popup Calendar with Input Binding
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This example demonstrates setting up a popup calendar that binds to an input field. The calendar is configured for single date selection and uses `x-ref="rc-input"` to link with the input element, enabling automatic input masking and ARIA attributes.
```html
```
--------------------------------
### Theming with TailwindCSS 4 (CSS)
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
Provides an example of how to theme the Alpine Calendar component using CSS custom properties, specifically demonstrating overrides compatible with TailwindCSS 4. This allows for easy visual customization of the calendar's appearance.
```css
@theme {
--color-calendar-bg: var(--color-white);
--color-calendar-text: var(--color-gray-900);
--color-calendar-primary: var(--color-indigo-600);
--color-calendar-primary-text: var(--color-white);
--color-calendar-hover: var(--color-gray-100);
--color-calendar-disabled: var(--color-gray-300);
--color-calendar-range: var(--color-indigo-50);
--color-calendar-today-ring: var(--color-indigo-400);
--color-calendar-border: var(--color-gray-200);
--color-calendar-other-month: var(--color-gray-400);
--color-calendar-weekday: var(--color-gray-500);
--color-calendar-focus-ring: var(--color-indigo-600);
--color-calendar-overlay: oklch(0 0 0 / 0.2);
--radius-calendar: var(--radius-lg);
--shadow-calendar: var(--shadow-lg);
--font-calendar: system-ui, -apple-system, sans-serif;
}
```
--------------------------------
### Range Date Selection Model - JavaScript
Source: https://context7.com/reachweb/alpine-calendar/llms.txt
Handles date range selection, supporting a start and end date. It allows for incremental range building, checking if a date falls within the selected range, and provides methods to get the start date, check for partial or complete ranges, and retrieve the range as a formatted string. It also supports direct range assignment.
```javascript
import { RangeSelection, CalendarDate } from '@reachweb/alpine-calendar'
const selection = new RangeSelection()
// First click sets start
selection.toggle(new CalendarDate(2025, 6, 10))
console.log(selection.isPartial()) // true
console.log(selection.getStart()) // CalendarDate(2025, 6, 10)
// Second click sets end (auto-swaps if before start)
selection.toggle(new CalendarDate(2025, 6, 20))
console.log(selection.isComplete()) // true
console.log(selection.toValue()) // "2025-06-10 – 2025-06-20"
// Check if date is in range (inclusive)
console.log(selection.isInRange(new CalendarDate(2025, 6, 15))) // true
// Hover preview for range building
const hoverDate = new CalendarDate(2025, 6, 25)
console.log(selection.isInRange(new CalendarDate(2025, 6, 22), hoverDate)) // depends on state
// Third click restarts with new start
selection.toggle(new CalendarDate(2025, 7, 1))
console.log(selection.isPartial()) // true
// Direct assignment (bypasses toggle semantics)
selection.setRange(
new CalendarDate(2025, 8, 1),
new CalendarDate(2025, 8, 1) // Same-day range
)
console.log(selection.toValue()) // "2025-08-01 – 2025-08-01"
```
--------------------------------
### Presetting Range Date Values
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This HTML snippet demonstrates how to set an initial date range for the calendar. The `value` option accepts a string representing the start and end dates, separated by ' - ', to pre-select the range '2026-03-10' to '2026-03-20'.
```html
```
--------------------------------
### Alpine Calendar: Basic Range Selection
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
Shows how to configure Alpine Calendar for range selection, allowing users to pick a start and end date. Hovering over dates previews the selected range.
```html
```
--------------------------------
### Alpine Calendar Component: Single Date Selection (Inline)
Source: https://context7.com/reachweb/alpine-calendar/llms.txt
Shows how to implement an inline calendar for single date selection using Alpine.js. Includes examples for basic configuration and advanced options like value binding, date constraints, and formatting.
```html
```
--------------------------------
### Set Global Calendar Defaults (JavaScript)
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
Configures global default settings for all instances of the Alpine.js calendar component using the `calendarPlugin.defaults()` method. This example sets the first day of the week to Monday (1) and the locale to Greek ('el'). The plugin is then registered with Alpine.js.
```javascript
import { calendarPlugin } from '@reachweb/alpine-calendar'
calendarPlugin.defaults({ firstDay: 1, locale: 'el' })
Alpine.plugin(calendarPlugin)
```
--------------------------------
### Server-Rendered Date Value with Blade
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This example shows how to pass a server-side variable, such as a date from a Blade template, directly into the Alpine Calendar configuration. The `{{ $date }}` syntax injects the backend variable into the `value` option.
```html
```
--------------------------------
### Birth Date Wizard Configuration with HTML
Source: https://context7.com/reachweb/alpine-calendar/llms.txt
Configures the calendar to function as a wizard for selecting birth dates, optimizing the selection process by starting with year, then month, then day. It supports full wizard mode, year-month only, or month-day only selection.
```html
```
--------------------------------
### Configure Calendar for 3-Month Inline Display
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This setup displays three months of the calendar inline within a scrollable container, which is useful for longer booking flows. The `months: 3` option controls the number of months displayed.
```html
```
--------------------------------
### Calendar Integration with Form Submission
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This example shows how to integrate the Alpine Calendar with an HTML form for submission. By setting the `name` attribute in the calendar configuration, hidden input fields are automatically generated for the selected date(s), facilitating form data handling.
```html
```
--------------------------------
### Apply Custom Green Theme to Calendar using CSS
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This CSS example shows how to customize the calendar's primary accent color to green. It overrides `--color-calendar-primary`, `--color-calendar-primary-text`, `--color-calendar-today-ring`, and `--color-calendar-range` for a branded look.
```css
.green-theme {
--color-calendar-primary: #059669;
--color-calendar-primary-text: #ffffff;
--color-calendar-today-ring: #34d399;
--color-calendar-range: #ecfdf5;
}
```
--------------------------------
### Alpine Calendar: Popup Range Selection with 3 Months
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
Illustrates a popup range picker configured to display three months (`months: 3`) for enhanced usability. This setup is ideal for selecting check-in and check-out dates.
```html
```
--------------------------------
### Create Reusable Date Constraint Functions (JavaScript)
Source: https://context7.com/reachweb/alpine-calendar/llms.txt
Provides a JavaScript example using `@reachweb/alpine-calendar` to create a reusable date constraint function. This function validates dates against various criteria like min/max dates, disabled days/dates/months, and enabled years/dates, outside of the calendar component itself.
```javascript
import { createDateConstraint, CalendarDate } from '@reachweb/alpine-calendar'
const isDisabled = createDateConstraint({
minDate: new CalendarDate(2025, 1, 1),
maxDate: new CalendarDate(2025, 12, 31),
disabledDaysOfWeek: [0, 6], // Disable weekends
disabledDates: [ // Specific holidays
new CalendarDate(2025, 7, 4),
new CalendarDate(2025, 12, 25)
],
enabledDates: [ // Force-enable exceptions
new CalendarDate(2025, 7, 5) // Override weekend
],
disabledMonths: [8], // Disable August
enabledYears: [2025, 2026] // Only allow 2025-2026
})
// Check individual dates
console.log(isDisabled(new CalendarDate(2025, 6, 15))) // false (valid weekday)
console.log(isDisabled(new CalendarDate(2025, 6, 14))) // true (Saturday)
console.log(isDisabled(new CalendarDate(2025, 7, 4))) // true (holiday)
```
--------------------------------
### Alpine Calendar: Form Submission with Hidden Inputs
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
Demonstrates how Alpine Calendar automatically generates hidden inputs for form submission when a `name` is provided. This example shows a basic form submission handler.
```html
```
--------------------------------
### Integrate Alpine Calendar with Laravel Livewire
Source: https://context7.com/reachweb/alpine-calendar/llms.txt
Provides instructions for integrating the Alpine Calendar with Laravel Livewire applications. It emphasizes using `wire:ignore` to prevent DOM morphing conflicts and demonstrates how to manage calendar state with `@entangle` for two-way data binding.
```php
{{-- In your Blade view --}}
@push('styles')
@endpush
@push('scripts')
@endpush
{{-- Wire:ignore prevents Livewire from morphing the calendar DOM --}}
{{-- With @entangle for two-way binding --}}
```
--------------------------------
### Configure Calendar in Month-Day Wizard Mode
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This wizard mode begins with month selection and then proceeds to day selection. It is configured using `wizard: 'month-day'`.
```html
```
--------------------------------
### Configure Calendar with Dynamic Date Metadata (Computed Pricing)
Source: https://github.com/reachweb/alpine-calendar/blob/main/demo/index.html
This configuration uses a callback function to dynamically determine metadata for each date, such as calculating pricing based on the day of the week and availability. Weekends are marked as unavailable, while weekdays display a computed price.
```html
```
--------------------------------
### Configure Alpine Calendar with Period-Specific Rules (HTML)
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
This HTML snippet demonstrates how to configure the Alpine.js calendar component using `x-data`. It specifically shows the use of `minRange` and `rules` for defining period-specific date constraints, allowing for different validation logic based on date ranges.
```html
```
--------------------------------
### Event Handling
Source: https://context7.com/reachweb/alpine-calendar/llms.txt
Listen for various calendar events such as date changes, navigation, and view updates to integrate calendar interactions with your application's logic.
```APIDOC
## Events
### Description
Listen for calendar events to integrate with your application logic. Events are dispatched using Alpine.js's event system.
### Method
Event listeners attached to the calendar element.
### Endpoint
N/A (Client-side event handling)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```html
```
### Response
#### Success Response (N/A)
Event details are passed as `$event.detail` to the handler functions.
#### Response Example
Event detail object structure varies based on the event. For `calendar:change`, it includes `value`, `dates`, and `formatted`. For `calendar:navigate`, it includes `year`, `month`, and `view`.
```
--------------------------------
### TypeScript Imports for Alpine Calendar
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
Demonstrates how to import core functionalities and types from the '@reachweb/alpine-calendar' package. This is useful for integrating the calendar component into TypeScript projects, enabling type safety and autocompletion.
```typescript
import {
calendarPlugin,
CalendarDate,
getISOWeekNumber,
SingleSelection,
MultipleSelection,
RangeSelection,
createCalendarData,
parseDate,
formatDate,
createMask,
computePosition,
autoUpdate,
generateMonth,
generateMonths,
generateMonthGrid,
generateYearGrid,
createDateConstraint,
createRangeValidator,
createDisabledReasons,
isDateDisabled,
presetToday,
presetYesterday,
presetLastNDays,
presetThisWeek,
presetLastWeek,
presetThisMonth,
presetLastMonth,
presetThisYear,
presetLastYear,
} from '@reachweb/alpine-calendar'
import type {
CalendarConfig,
CalendarConfigRule,
RangePreset,
DayCell,
MonthCell,
YearCell,
Selection,
Placement,
PositionOptions,
DateConstraintOptions,
DateConstraintProperties,
DateConstraintRule,
ConstraintMessages,
InputMask,
MaskEventHandlers,
} from '@reachweb/alpine-calendar'
```
--------------------------------
### Alpine Calendar Configuration
Source: https://github.com/reachweb/alpine-calendar/blob/main/README.md
Configuration options for the Alpine Calendar component, passed via `x-data='calendar({...})'`.
```APIDOC
## Configuration
All options are passed via `x-data="calendar({ ... })"`.
### Options
| Option | Type | Default | Description |
|---|---|---|---|
| `mode` | `'single' | 'multiple' | 'range'` | `'single'` | Selection mode |
| `display` | `'inline' | 'popup'` | `'inline'` | Inline calendar or popup with input |
| `format` | `string` | `'DD/MM/YYYY'` | Date format (tokens: `DD`, `MM`, `YYYY`, `D`, `M`, `YY`) |
| `months` | `number` | `1` | Months to display (1=single, 2=dual side-by-side, 3+=scrollable) |
| `firstDay` | `0–6` | `1` | First day of week (0=Sun, 1=Mon, ...) |
| `mask` | `boolean` | `true` | Enable input masking |
| `value` | `string` | — | Initial value (ISO or formatted string) |
| `name` | `string` | `''` | Input name attribute for form submission |
| `locale` | `string` | — | BCP 47 locale for month/day names |
| `timezone` | `string` | — | IANA timezone for resolving "today" |
| `closeOnSelect` | `boolean` | `true` | Close popup after selection |
| `wizard` | `boolean | 'year-month' | 'month-day'` | `false` | Birth date wizard mode |
| `beforeSelect` | `(date, ctx) => boolean` | — | Custom validation before selection |
| `showWeekNumbers` | `boolean` | `false` | Show ISO 8601 week numbers alongside the day grid |
| `inputId` | `string` | — | ID for the popup input (allows external `