Logic
Calendar Controller API
Complete API reference for the Calendar Controller component.
Constructor
Initialize a Calendar Controller instance
Configuration
Configure controller behavior
State Properties
Access controller state values
Methods
API methods for controlling calendar
Constructor
Creates a new instance of the Calendar Controller with optional configuration.
Example Usage
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
firstDayOfWeek | number | 0 (Sunday) | The first day of the week (0 = Sunday, 1 = Monday, etc.) |
hideOtherMonthDays | boolean | false | Whether to hide days from previous/next months |
minDate | Date | null | null | Minimum selectable date |
maxDate | Date | null | null | Maximum selectable date |
locale | string | 'en-US' | Locale for date formatting and internationalization |
yearRangeSize | number | 12 | Number of years to display in year view |
isRangeSelection | boolean | false | Whether range selection mode is active |
Option | Type | Default | Description |
---|---|---|---|
firstDayOfWeek | number | 0 (Sunday) | The first day of the week (0 = Sunday, 1 = Monday, etc.) |
hideOtherMonthDays | boolean | false | Whether to hide days from previous/next months |
minDate | Date | null | null | Minimum selectable date |
maxDate | Date | null | null | Maximum selectable date |
locale | string | 'en-US' | Locale for date formatting and internationalization |
yearRangeSize | number | 12 | Number of years to display in year view |
isRangeSelection | boolean | false | Whether range selection mode is active |
State Properties
Property | Type | Description |
---|---|---|
currentMonth | number | Current month (0-11) |
currentYear | number | Current year |
currentMonthName | string | Name of the current month in the selected locale |
selectedDate | Date | null | Currently selected date |
weekdayNames | string[] | Array of weekday names in the selected locale |
daysInMonth | CalendarDay[] | Array of day objects for the current month view |
viewMode | 'day' | 'month' | 'year' | Current view mode of the calendar |
isRangeMode | boolean | Whether range selection mode is active |
selectedRange | { start: Date | null, end: Date | null } | Currently selected date range |
locale | string | Current locale for internationalization |
Accessing State Example
1// Get current state values2const month = calendar.currentMonth; // 0-113const year = calendar.currentYear;4const monthName = calendar.currentMonthName;56// Check selected dates7if (calendar.selectedDate) {8 console.log(`Selected date: ${calendar.selectedDate.toLocaleDateString()}`);9}1011// Work with calendar days12const days = calendar.daysInMonth;13const today = days.find(day => day.isToday);
Methods
Events
Event Subscription
Subscribe to calendar events with callback functions
- 1onDateSelected(callback: (date: Date) => void): () => void
Triggered when a date is selected
- 1onRangeSelected(callback: (range: {start: Date, end: Date}) => void): () => void
Triggered when a date range is selected
- 1onMonthChanged(callback: (month: number, year: number) => void): () => void
Triggered when the month changes
- 1onYearChanged(callback: (year: number) => void): () => void
Triggered when the year changes
- 1onViewModeChanged(callback: (mode: 'day' | 'month' | 'year') => void): () => void
Triggered when the view mode changes
Event Handling Example
1// Subscribe to date selection events2const unsubscribe = calendar.onDateSelected(date => {3 console.log("Selected date:", date);4 updateUI(date);5});67// Subscribe to month change events8calendar.onMonthChanged((month, year) => {9 console.log(`Month changed: ${month + 1}/${year}`);10});1112// Later, unsubscribe when needed13unsubscribe();
Services
Internal Services
Access specialized services for advanced calendar operations
- 1getDateSelectionService(): DateSelectionService
Gets the date selection service
- 1getNavigationService(): NavigationService
Gets the navigation service
- 1getDateValidationService(): DateValidationService
Gets the date validation service
Service Usage Example
1// Get the date validation service for advanced validation2const validationService = calendar.getDateValidationService();34// Add custom validation rules5validationService.addValidator(date => {6 // Disable weekends7 const day = date.getDay();8 return day !== 0 && day !== 6;9});1011// Get navigation service for advanced navigation12const navService = calendar.getNavigationService();13navService.setViewMode('month');