Calendar
The <smart-calendar> component renders a date calendar with shared month-grid logic, navigation (prev/next/today), single-day selection, and per-day event awareness. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract CalendarBaseComponent defines the shared API and contains the date logic (pure month-grid construction, period navigation, day selection, event filtering). CalendarStandardComponent is a barebones placeholder concrete implementation that renders a 6×7 month grid. CalendarComponent is the public wrapper that renders CalendarStandardComponent by default and accepts a custom replacement via CALENDAR_STANDARD_COMPONENT_TOKEN.
Usage
<smart-calendar
[options]="options"
[referenceDate]="referenceDate"
[events]="events"
[(value)]="selectedDate"
/>
@if (selectedDate(); as date) {
<p>Selected: {{ date.toDateString() }}</p>
}
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
CalendarComponent (<smart-calendar>)
Main wrapper component. Renders CalendarStandardComponent by default. When CALENDAR_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet. The wrapper exposes a two-way value model (Date | null), an optional referenceDate input (today when omitted), an events input, options and class. It passes all of them to the injected component (referenceDate included) and writes the injected component's value changes back to its own value model, so [(value)] works the same with the standard, the preset or an implementation of your own.
CalendarStandardComponent (<smart-calendar-standard>)
Barebones placeholder concrete implementation. Renders a wrapper <div> (carrying the external classes) containing a <div class="calendar" data-view> with an optional toolbar (<button.prev>, <button.today-btn>, <button.next>, optional toolbarActionsTpl slot) and a <div class="view-grid"> with one <div class="week"> per week and one <button class="day"> per day. Each day exposes data-current-month, data-today, and data-selected attributes plus an aria-label of the date string. The standard marks event days: a day with eventsForDay(date).length > 0 gets data-events="<count>", its aria-label gains the count (e.g. "Thu Sep 03 2026, 1 event", ", 2 events"; built by the base's dayAriaLabel(date), which the preset uses too), and — without dayCellTpl — a <span class="smart-calendar-event" data-role="event-dot" aria-hidden="true"> marker after the day number. If dayCellTpl is provided in options, it replaces the default day content (day number and marker). The toolbar labels (Prev / Today / Next) are not translated. It does not include any visual styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.
CalendarPresetComponent (<smart-calendar-preset>)
Styled single date-picker variation that extends CalendarBaseComponent and is a drop-in replacement for CalendarStandardComponent. Register it via CALENDAR_STANDARD_COMPONENT_TOKEN ({ provide: CALENDAR_STANDARD_COMPONENT_TOKEN, useValue: CalendarPresetComponent }) to restyle every <smart-calendar>, register every preset at once with provideSmartPresets(), or use the <smart-calendar-preset> selector directly (it takes the extra classes as class or [cssClass]). It reproduces Preline's single date-picker visual (a w-80 rounded popover card: month/year navigation header with chevron prev/next buttons, a weekday header row, and a 6×7 grid of circular day buttons) translated to smart:-prefixed vanilla Tailwind with explicit dark: variants. Month navigation (prevPeriod/nextPeriod) and day selection (selectDay) are driven entirely by Angular signals — the Preline datepicker JS plugin is not required. It honors options.weekStart (rotates the weekday header; default 1 → Monday) and options.showToolbar (toggles the navigation header); it does not render toolbarActionsTpl. Selected, today, default, and out-of-month day states each get distinct styling; out-of-month days are rendered disabled. Days that have matching events show a small dot marker, and options.dayCellTpl overrides the default day content. The month name and the weekday labels are English and not translated.
CalendarBaseComponent (abstract)
Abstract base directive containing the shared calendar logic. Exposes inputs and signals for state, plus methods for navigation and selection.
Inputs: options (ICalendarOptions | undefined), value (Date | null, two-way model), referenceDate (Date | undefined; the class property is referenceDateInput), events (ICalendarEvent[]), class (string, the cssClass property)
Computed signals: view (current view from options, default 'month'), weekStart (0 | 1, default 1), showToolbar (default true), reference (the navigated reference date, read-only; it starts at referenceDate or today and jumps back to referenceDate whenever that input changes), monthGrid (current 6×7 grid).
Methods: selectDay(date) (sets value), goToToday(), prevPeriod() / nextPeriod() (move reference one view period: a month, 7 days, a day or a year), eventsForDay(day), dayAriaLabel(day) (date string plus ", N event(s)" when the day has events).
Static method: buildMonthGrid(reference, weekStart, selected): ICalendarDayCell[][] — pure function returning a 6×7 grid suitable for rendering.
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<ICalendarOptions | undefined> | - | Configuration (view, weekStart, toolbar, slot templates) |
value | ModelSignal<Date | null> | null | Selected day (two-way binding); valueChange reports every selection |
referenceDate | InputSignal<Date | undefined> | today | The day whose month is shown first; the calendar navigates from there and jumps back to it whenever it changes |
events | InputSignal<ICalendarEvent[]> | [] | Events for eventsForDay(); the standard and preset mark days that have events |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
ICalendarOptions
| Field | Type | Default | Description |
|---|---|---|---|
view | SmartCalendarView | 'month' | The period Prev / Next move by ('month', 'week', 'day', 'year'). The grid is always a month grid; the standard also exposes the value as data-view. |
monthsCount | 1 | 2 | 12 | undefined | Not read by the built-in implementations (standard and preset); available to a custom implementation. |
weekStart | 0 | 1 | 1 | First day of the week: 1 Monday, 0 Sunday. |
showToolbar | boolean | true | Shows the navigation toolbar (the standard's Prev / Today / Next, the preset's month header). |
toolbarActionsTpl | TemplateRef<unknown> | undefined | Standard only: extra content at the end of the toolbar. The preset does not render it. |
eventListTpl | TemplateRef<unknown> | undefined | Not read by the built-in implementations; available to a custom implementation. |
sidePanelTpl | TemplateRef<unknown> | undefined | Not read by the built-in implementations; available to a custom implementation. |
dayCellTpl | TemplateRef<unknown> | undefined | Replaces the content of every day button. Its context is the day cell as $implicit (ICalendarDayCell) and the day's events as events (ICalendarEvent[]): <ng-template #day let-cell let-events="events">. |
eventTpl | TemplateRef<unknown> | undefined | Not read by the built-in implementations; available to a custom implementation. |
ICalendarEvent
An event marks the day of its start.
| Field | Type | Default | Description |
|---|---|---|---|
id | string | number | required | Identifies the event. |
start | Date | required | Decides the day the event is listed on (eventsForDay). |
end | Date | undefined | Not read by the built-in implementations; available to a custom implementation or your dayCellTpl. |
title | string | undefined | Not rendered by the built-in implementations (the day's accessible name only counts the events); available to a custom implementation or your dayCellTpl. |
meta | Record<string, unknown> | undefined | Free data for a custom implementation or your dayCellTpl. |
ICalendarDayCell
One day of the month grid (monthGrid(), and the $implicit context of dayCellTpl).
| Field | Type | Default | Description |
|---|---|---|---|
date | Date | required | The day. |
isCurrentMonth | boolean | required | false for the leading / trailing days of the neighbouring months. |
isToday | boolean | required | The day is today. |
isSelected | boolean | required | The day is the selected value. |
CALENDAR_STANDARD_COMPONENT_TOKEN
InjectionToken that allows replacing the default CalendarStandardComponent with a custom implementation. Provide a Type<CalendarBaseComponent> to override. The wrapper passes it every input it declares (referenceDate and class included) and writes its value changes back to the wrapper's value model, so [(value)] on <smart-calendar> keeps working.
Extending the base class
import { DatePipe } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
computed,
ViewEncapsulation,
} from '@angular/core';
import {
CalendarBaseComponent,
CalendarComponent,
CALENDAR_STANDARD_COMPONENT_TOKEN,
ICalendarEvent,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-calendar',
imports: [DatePipe],
template: `
<div [class]="containerClasses()">
@if (showToolbar()) {
<div class="docs-calendar__toolbar">
<button
type="button"
class="docs-calendar__prev"
(click)="prevPeriod()"
>
Previous
</button>
<h2 class="docs-calendar__title">
{{ reference() | date: 'LLLL yyyy' }}
</h2>
<button
type="button"
class="docs-calendar__today"
(click)="goToToday()"
>
Today
</button>
<button
type="button"
class="docs-calendar__next"
(click)="nextPeriod()"
>
Next
</button>
</div>
}
<div class="docs-calendar__grid">
@for (week of monthGrid(); track $index) {
<div class="docs-calendar__week">
@for (cell of week; track cell.date.getTime()) {
<button
type="button"
class="docs-calendar__day"
[class.docs-calendar__day--outside]="!cell.isCurrentMonth"
[attr.data-today]="cell.isToday ? 'true' : null"
[attr.data-selected]="cell.isSelected ? 'true' : null"
(click)="selectDay(cell.date)"
>
{{ cell.date.getDate() }}
@for (event of eventsForDay(cell.date); track event.id) {
<span class="docs-calendar__event">{{ event.title }}</span>
}
</button>
}
</div>
}
</div>
</div>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomCalendarComponent extends CalendarBaseComponent {
containerClasses = computed(() =>
['docs-calendar', this.cssClass()].filter(Boolean).join(' '),
);
}
@Component({
selector: 'docs-calendar-custom-example',
imports: [CalendarComponent],
providers: [
{
provide: CALENDAR_STANDARD_COMPONENT_TOKEN,
useValue: CustomCalendarComponent,
},
],
template: `
<smart-calendar [referenceDate]="referenceDate" [events]="events" />
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CalendarCustomExampleComponent {
referenceDate = new Date(2026, 0, 1);
// The standard and the preset never render `title`; this implementation does.
events: ICalendarEvent[] = [
{
id: 'review',
title: 'Design review',
start: new Date(2026, 0, 15, 10, 0),
},
];
}
Source
The component lives in packages/shared/angular/src/lib/components/calendar and is documented for Claude Code by the angular-components-calendar skill.
SmartCalendar renders a month grid (6 x 7 days) with a toolbar to move between periods, lets the user select a day, and marks the days that have events. The selection is controlled (value + onValueChange) or kept inside (defaultValue). options.dayCellTpl is a render function called for every day with { cell, events }. SmartCalendarStandard is barebones native HTML; SmartCalendarPreset is a styled single date picker.
Usage
import { useState } from 'react';
import {
ICalendarEvent,
SmartCalendar,
SmartCalendarOptions,
} from '@smartsoft001/react';
// Weeks start on Sunday (the default is Monday).
const options: SmartCalendarOptions = { weekStart: 0 };
const referenceDate = new Date(2026, 8, 1);
// Each event marks the day of its `start`.
const events: ICalendarEvent[] = [
{ id: 1, start: new Date(2026, 8, 3, 10) },
{ id: 2, start: new Date(2026, 8, 17, 14) },
];
export function CalendarUsageExample() {
const [selectedDate, setSelectedDate] = useState<Date | null>(null);
return (
<>
<SmartCalendar
options={options}
referenceDate={referenceDate}
events={events}
value={selectedDate}
onValueChange={setSelectedDate}
/>
{selectedDate && <p>Selected: {selectedDate.toDateString()}</p>}
</>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartCalendar | component | Renders the implementation registered as components.calendar on SmartProvider, SmartCalendarStandard by default. |
SmartCalendarPreset | component | Styled calendar variation (preset) — a single date picker. |
SmartCalendarStandard | component | Barebones native-HTML month calendar. |
useCalendar | hook | The behaviour every calendar variant shares: the options with their defaults (month view, Monday week start, toolbar shown), the selected day (value, controlled or uncontrolled), the navigated reference date with its 6 x 7 monthGrid, the events of a day and the day's accessible name. |
buildMonthGrid | function | The 6 x 7 day grid of the month of reference, starting on weekStart (0 = Sunday, 1 = Monday), with the leading / trailing days of the neighbouring months. |
The preset's class helpers (getCalendarPresetDayClasses, CALENDAR_PRESET_CONTAINER, CALENDAR_PRESET_INNER, CALENDAR_PRESET_HEADER, CALENDAR_PRESET_NAV_BUTTON, CALENDAR_PRESET_MONTH_LABEL, CALENDAR_PRESET_WEEK_ROW, CALENDAR_PRESET_DAY_ROW, CALENDAR_PRESET_WEEKDAY, CALENDAR_PRESET_EVENT_DOT) are exported too, for a custom implementation that wants the preset look.
Props and Types
SmartCalendarProps
| Prop | Type | Default | Description |
|---|---|---|---|
options? | SmartCalendarOptions | — | View, week start, toolbar and the custom templates. |
className? | string | — | Classes on the root element. |
value? | Date | null | — | The selected day. Controlled when defined (null = nothing selected); leave it undefined to let the calendar keep the selection itself, starting from defaultValue. |
defaultValue? | Date | null | null | The initial selection of an uncontrolled calendar. |
onValueChange? | (value: Date | null) => void | — | Called with the day the user selects. |
referenceDate? | Date | today | The day whose month is shown first; the calendar navigates from there and jumps back to it whenever it changes. Today when omitted. |
events? | ICalendarEvent[] | [] | Events to mark; a day lists the events whose start falls on it. |
SmartCalendarOptions
ICalendarOptions with dayCellTpl as a render function, called for every day with SmartCalendarDayCellContext. toolbarActionsTpl has no context, so it stays a ReactNode. eventListTpl, sidePanelTpl, eventTpl and monthsCount are not read by the built-in implementations; they are available to a custom implementation. Extends Omit<ICalendarOptions, 'dayCellTpl'>.
| Field | Type | Default | Description |
|---|---|---|---|
dayCellTpl? | (context: SmartCalendarDayCellContext) => ReactNode | — | Renders the content of every day cell. |
ICalendarOptions
The base options; SmartCalendarOptions replaces its dayCellTpl with a render function.
| Field | Type | Default | Description |
|---|---|---|---|
view? | SmartCalendarView | 'month' | The period Prev / Next move by (month, week, day, year). The grid is always a month grid. |
monthsCount? | 1 | 2 | 12 | — | Not read by the built-in implementations; available to a custom implementation. |
weekStart? | 0 | 1 | 1 | 1 Monday, 0 Sunday. |
showToolbar? | boolean | true | Shows the Prev / Today / Next toolbar. |
toolbarActionsTpl? | ReactNode | — | Extra content in the toolbar of the standard calendar (the preset does not render it). |
eventListTpl? | ReactNode | — | Not read by the built-in implementations; available to a custom implementation. |
sidePanelTpl? | ReactNode | — | Not read by the built-in implementations; available to a custom implementation. |
dayCellTpl? | ReactNode | — | Overridden by SmartCalendarOptions.dayCellTpl (a render function). |
eventTpl? | ReactNode | — | Not read by the built-in implementations; available to a custom implementation. |
SmartCalendarDayCellContext
The context dayCellTpl renders with: the day cell and its events.
| Field | Type | Default | Description |
|---|---|---|---|
cell | ICalendarDayCell | required | The day: date, isCurrentMonth, isToday, isSelected. |
events | ICalendarEvent[] | required | The events starting on cell.date (eventsForDay(cell.date)). |
ICalendarDayCell
One day of the month grid.
| Field | Type | Default | Description |
|---|---|---|---|
date | Date | required | The day. |
isCurrentMonth | boolean | required | false for the leading / trailing days of the neighbouring months. |
isToday | boolean | required | The day is today. |
isSelected | boolean | required | The day is the selected value. |
ICalendarEvent
An event shown on the day of its start.
| Field | Type | Default | Description |
|---|---|---|---|
id | string | number | required | Identifies the event. |
start | Date | required | Start; decides the day the event is listed on. |
end? | Date | — | Not read by the built-in implementations; available to a custom implementation or your dayCellTpl. |
title? | string | — | Not rendered by the built-in implementations (the day's accessible name only counts the events); available to a custom implementation or your dayCellTpl. |
meta? | Record<string, unknown> | — | Free data for a custom implementation or your dayCellTpl. |
Related types
SmartCalendarView:'month' \| 'week' \| 'day' \| 'year'
Behaviour
SmartCalendarreplaces a missingreferenceDatewith the date it was mounted, so a registered implementation always gets one. WhenreferenceDatechanges to another day, the calendar jumps back to it.- The toolbar labels (Prev / Today / Next) of the standard calendar and the English month and weekday names of the preset are not translated.
SmartCalendarPresetdisables days outside the shown month; the standard grid marks days with events withdata-events="<count>".
Replacing the Implementation
SmartCalendar renders the component registered under the 'calendar' key of SmartProvider's components, and SmartCalendarStandard when nothing is registered there. Every SmartCalendar below the provider then renders the registered component, which receives the same props.
SmartCalendarPreset is the styled (preset) implementation: register it under the 'calendar' key of SmartProvider's components, render it directly in place of SmartCalendar, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The useCalendar hook
The behaviour every calendar variant shares: the options with their defaults (month view, Monday week start, toolbar shown), the selected day (value, controlled or uncontrolled), the navigated reference date with its 6 x 7 monthGrid, the events of a day and the day's accessible name. The reference starts at referenceDate (today when omitted), moves with prevPeriod / nextPeriod / goToToday, and jumps back to referenceDate whenever that prop changes to another point in time.
| Returns | Type | Description |
|---|---|---|
view | SmartCalendarView | options.view ?? 'month'. |
weekStart | 0 | 1 | options.weekStart ?? 1. |
showToolbar | boolean | options.showToolbar ?? true. |
value | Date | null | The selected day (controlled or internal). |
reference | Date | The navigated reference date (the shown month). |
monthGrid | ICalendarDayCell[][] | The 6 x 7 grid of the reference month (buildMonthGrid). |
eventsForDay | (day: Date) => ICalendarEvent[] | The events starting on a day. |
dayAriaLabel | (day: Date) => string | The accessible name of a day (with the event count). |
selectDay | (date: Date) => void | Selects a day and calls onValueChange. |
goToToday | () => void | Moves the reference to today. |
prevPeriod | () => void | Moves the reference one view period back. |
nextPeriod | () => void | Moves the reference one view period forward. |
import {
ICalendarEvent,
SmartCalendar,
SmartCalendarProps,
SmartProvider,
useCalendar,
} from '@smartsoft001/react';
export function CustomCalendar(props: SmartCalendarProps) {
const {
showToolbar,
reference,
monthGrid,
eventsForDay,
selectDay,
goToToday,
prevPeriod,
nextPeriod,
} = useCalendar(props);
return (
<div
className={['docs-calendar', props.className].filter(Boolean).join(' ')}
>
{showToolbar && (
<div className="docs-calendar__toolbar">
<button
type="button"
className="docs-calendar__prev"
onClick={prevPeriod}
>
Previous
</button>
<h2 className="docs-calendar__title">
{reference.toLocaleDateString('en-US', {
month: 'long',
year: 'numeric',
})}
</h2>
<button
type="button"
className="docs-calendar__today"
onClick={goToToday}
>
Today
</button>
<button
type="button"
className="docs-calendar__next"
onClick={nextPeriod}
>
Next
</button>
</div>
)}
<div className="docs-calendar__grid">
{monthGrid.map((week, index) => (
<div key={index} className="docs-calendar__week">
{week.map((cell) => (
<button
key={cell.date.getTime()}
type="button"
className={
cell.isCurrentMonth
? 'docs-calendar__day'
: 'docs-calendar__day docs-calendar__day--outside'
}
data-today={cell.isToday ? 'true' : undefined}
data-selected={cell.isSelected ? 'true' : undefined}
onClick={() => selectDay(cell.date)}
>
{cell.date.getDate()}
{eventsForDay(cell.date).map((event) => (
<span key={event.id} className="docs-calendar__event">
{event.title}
</span>
))}
</button>
))}
</div>
))}
</div>
</div>
);
}
// A module constant: a new object on every render would change the context.
const components = { calendar: CustomCalendar };
const referenceDate = new Date(2026, 0, 1);
// The standard and the preset never render `title`; this implementation does.
const events: ICalendarEvent[] = [
{
id: 'review',
title: 'Design review',
start: new Date(2026, 0, 15, 10, 0),
},
];
export function CalendarCustomExample() {
return (
<SmartProvider components={components}>
<SmartCalendar referenceDate={referenceDate} events={events} />
</SmartProvider>
);
}
Styling
SmartCalendarStandardis unstyled native HTML (.calendar,data-view,data-events);SmartCalendarPresetcarries the date-picker look withsmart:dark:variants.classNameis appended to the root element.
Source
The component lives in packages/shared/react/src/lib/components/calendar and is documented for Claude Code by the react-components-calendar skill.