- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Trace
Calendar
A date field component that allows users to enter and edit date.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmCalendar } from '@spartan-ng/helm/calendar';
import { HlmCard, HlmCardImports } from '@spartan-ng/helm/card';
@Component({
selector: 'spartan-calendar-preview',
imports: [HlmCalendar, HlmCardImports],
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [HlmCard],
host: {
class: 'p-0 w-fit mx-auto',
},
template: `
<div hlmCardContent class="p-0">
<hlm-calendar [(date)]="selectedDate" [min]="minDate" [max]="maxDate" />
</div>
`,
})
export class CalendarPreview {
/** The selected date */
public selectedDate = new Date();
/** The minimum date */
public minDate = new Date(new Date().setMonth(new Date().getMonth() - 2));
/** The maximum date */
public maxDate = new Date(new Date().setMonth(new Date().getMonth() + 2));
}
export const i18nRuntimeChange = `
import { injectBrnCalendarI18n } from '@spartan-ng/brain/calendar';
@Component({...})
export class CalendarPage {
private readonly _i18n = injectBrnCalendarI18n();
switchToFrench() {
this._i18n.use({
...,
labelNext: () => 'Mois suivant',
labelPrevious: () => 'Mois précédent',
...
});
}
}
`;
export const i18nProviders = `
import { bootstrapApplication } from '@angular/platform-browser';
import { provideBrnCalendarI18n } from '@spartan-ng/brain/calendar';
bootstrapApplication(App, {
providers: [
provideBrnCalendarI18n({
formatWeekdayName: (i) => ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'][i],
formatHeader: (m, y) =>
new Date(y, m).toLocaleDateString('de-DE', {
month: 'long',
year: 'numeric',
}),
labelPrevious: () => 'Vorheriger Monat',
labelNext: () => 'Nächster Monat',
labelPreviousYear: () => 'Vorheriges Jahr',
labelNextYear: () => 'Nächstes Jahr',
labelPreviousYears: () => 'Vorherige Jahre',
labelNextYears: () => 'Nächste Jahre',
labelWeekday: (i) => ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'][i],
firstDayOfWeek: () => 1,
}),
],
});
`;Installation
ng g @spartan-ng/cli:ui calendarnx g @spartan-ng/cli:ui calendarUsage
import { HlmCalendarImports } from '@spartan-ng/helm/calendar';<hlm-calendar [(date)]="selectedDate" [min]="minDate" [max]="maxDate" />Internationalization
The calendar supports internationalization (i18n) via the BrnCalendarI18nService . By default, weekday names and month headers are rendered in English. You can provide a custom configuration globally or swap it at runtime to support multiple locales.
Global Configuration
Use provideBrnCalendarI18n in your app bootstrap to configure labels and formats globally:
import { bootstrapApplication } from '@angular/platform-browser';
import { provideBrnCalendarI18n } from '@spartan-ng/brain/calendar';
bootstrapApplication(App, {
providers: [
provideBrnCalendarI18n({
formatWeekdayName: (i) => ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'][i],
formatHeader: (m, y) =>
new Date(y, m).toLocaleDateString('de-DE', {
month: 'long',
year: 'numeric',
}),
labelPrevious: () => 'Vorheriger Monat',
labelNext: () => 'Nächster Monat',
labelPreviousYear: () => 'Vorheriges Jahr',
labelNextYear: () => 'Nächstes Jahr',
labelPreviousYears: () => 'Vorherige Jahre',
labelNextYears: () => 'Nächste Jahre',
labelWeekday: (i) => ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'][i],
firstDayOfWeek: () => 1,
}),
],
});Runtime Configuration
You can dynamically switch calendar language at runtime by injecting BrnCalendarI18nService and calling use() :
import { injectBrnCalendarI18n } from '@spartan-ng/brain/calendar';
@Component({...})
export class CalendarPage {
private readonly _i18n = injectBrnCalendarI18n();
switchToFrench() {
this._i18n.use({
...,
labelNext: () => 'Mois suivant',
labelPrevious: () => 'Mois précédent',
...
});
}
}Examples
Multiple Selection
Use hlm-calendar-multi for multiple date selection. Limit the selectable dates using minSelection and maxSelection inputs.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmCalendarImports } from '@spartan-ng/helm/calendar';
import { HlmCard, HlmCardImports } from '@spartan-ng/helm/card';
@Component({
selector: 'spartan-calendar-multiple',
imports: [HlmCalendarImports, HlmCardImports],
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [HlmCard],
host: {
class: 'p-0 w-fit mx-auto',
},
template: `
<div hlmCardContent class="p-0">
<hlm-calendar-multi
[(date)]="selectedDates"
[min]="minDate"
[max]="maxDate"
[minSelection]="2"
[maxSelection]="6"
/>
</div>
`,
})
export class CalendarMultipleExample {
/** The selected date */
public selectedDates = [new Date()];
/** The minimum date */
public minDate = new Date(2023, 0, 1);
/** The maximum date */
public maxDate = new Date(2030, 11, 31);
}Range Selection
Use hlm-calendar-range for range date selection. Set the range by using startDate and endDate inputs. Use numberOfMonths to display multiple months, which are stacked vertically on small screens.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmCalendarImports } from '@spartan-ng/helm/calendar';
import { HlmCard, HlmCardImports } from '@spartan-ng/helm/card';
@Component({
selector: 'spartan-calendar-range',
imports: [HlmCalendarImports, HlmCardImports],
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [HlmCard],
host: {
class: 'p-0 w-fit mx-auto',
},
template: `
<div hlmCardContent class="p-0">
<hlm-calendar-range
[(startDate)]="start"
[(endDate)]="end"
[min]="minDate"
[max]="maxDate"
[numberOfMonths]="2"
/>
</div>
`,
})
export class CalendarRangeExample {
/** The selected date */
public start = new Date();
public end = new Date(this.start.getTime() + 5 * 24 * 60 * 60 * 1000);
/** The minimum date */
public minDate = new Date(2023, 0, 1);
/** The maximum date */
public maxDate = new Date(2030, 11, 31);
}Month and Year Selector
Caption layouts with a year dropdown use the years function from the calendar's i18n configuration. By default, the dropdown includes an inclusive range from 100 years in the past through 10 years in the future. Override years with provideBrnCalendarI18n if you need a different range.
See the Internationalization section for configuration examples.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { Component, model } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HlmCalendar } from '@spartan-ng/helm/calendar';
import { HlmCardImports } from '@spartan-ng/helm/card';
import { HlmSelectImports } from '@spartan-ng/helm/select';
@Component({
selector: 'spartan-calendar-year-and-month-dropdown',
imports: [HlmCalendar, HlmSelectImports, FormsModule, HlmCardImports],
host: {
class: 'flex flex-col gap-4',
},
template: `
<div hlmCard class="mx-auto w-fit p-0">
<div hlmCardContent class="p-0">
<hlm-calendar [captionLayout]="_captionLayout()" />
</div>
</div>
<hlm-select class="inline-block" [(ngModel)]="_captionLayout" [itemToString]="itemToString">
<hlm-select-trigger class="w-full">
<hlm-select-value placeholder="Select an option" />
</hlm-select-trigger>
<hlm-select-content *hlmSelectPortal>
<hlm-select-group>
<hlm-select-item value="dropdown">Month and Year</hlm-select-item>
<hlm-select-item value="dropdown-months">Only Month</hlm-select-item>
<hlm-select-item value="dropdown-years">Only Year</hlm-select-item>
</hlm-select-group>
</hlm-select-content>
</hlm-select>
`,
})
export class CalendarYearAndMonthDropdownsExample {
protected readonly _captionLayout = model<'dropdown' | 'label' | 'dropdown-months' | 'dropdown-years'>('dropdown');
public readonly options = [
{ value: 'dropdown', label: 'Month and Year' },
{ value: 'dropdown-months', label: 'Only Month' },
{ value: 'dropdown-years', label: 'Only Year' },
];
public readonly itemToString = (value: string) => this.options.find((option) => option.value === value)?.label || '';
}Month and Year
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmCalendarImports } from '@spartan-ng/helm/calendar';
import { HlmCard, HlmCardImports } from '@spartan-ng/helm/card';
@Component({
selector: 'spartan-month-year-example',
imports: [HlmCardImports, HlmCalendarImports],
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [HlmCard],
host: {
class: 'p-0 w-fit mx-auto',
},
template: `
<div hlmCardContent class="p-0">
<hlm-month-year-calendar [(date)]="selectedDate" />
</div>
`,
})
export class CalendarMonthAndYearExample {
/** The selected date */
public selectedDate = new Date();
}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
| ح | ن | ث | ر | خ | ج | س |
|---|---|---|---|---|---|---|
import { ChangeDetectionStrategy, Component, computed, effect, inject, untracked } from '@angular/core';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { injectBrnCalendarI18n, provideBrnCalendarI18n } from '@spartan-ng/brain/calendar';
import { HlmCalendar } from '@spartan-ng/helm/calendar';
import { HlmCard, HlmCardImports } from '@spartan-ng/helm/card';
import { DateTime } from 'luxon';
import { CALENDAR_I18N } from '../(date-picker)/date-picker--rtl.preview';
@Component({
selector: 'spartan-calendar-rtl',
imports: [HlmCalendar, HlmCardImports],
providers: [provideBrnCalendarI18n()],
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [HlmCard],
host: {
'[dir]': '_dir()',
class: 'p-0 w-fit mx-auto',
},
template: `
<div hlmCardContent class="p-0">
<hlm-calendar [(date)]="selectedDate" [min]="minDate" [max]="maxDate" captionLayout="dropdown" />
</div>
`,
})
export class CalendarRtl {
/** The selected date */
public selectedDate = new Date();
/** The minimum date */
public minDate = new Date(new Date().setMonth(new Date().getMonth() - 2));
/** The maximum date */
public maxDate = new Date(new Date().setMonth(new Date().getMonth() + 2));
private readonly _language = inject(TranslateService).language;
private readonly _calendarI18n = injectBrnCalendarI18n();
constructor() {
effect(() => {
const language = this._language();
untracked(() => this._calendarI18n.use(CALENDAR_I18N[language]));
});
}
protected readonly _formatDate = computed(() => {
const locale = this._language();
return (date: Date) => DateTime.fromJSDate(date).setLocale(locale).toLocaleString(DateTime.DATE_FULL);
});
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: {},
},
ar: {
dir: 'rtl',
values: {},
},
he: {
dir: 'rtl',
values: {},
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
}For another RTL example please look at the Jalali (Persian) calendar.
Brain API
BrnCalendarCellButton
Selector: button[brnCalendarCellButton]
ExportAs: brnCalendarCellButton
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| date* (required) | T | - | The date this cell represents |
BrnCalendarCell
Selector: [brnCalendarCell]
ExportAs: brnCalendarCell
BrnCalendarGrid
Selector: [brnCalendarGrid]
ExportAs: brnCalendarGrid
BrnCalendarHeader
Selector: [brnCalendarHeader]
ExportAs: brnCalendarHeader
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-calendar-header-${++uniqueId}` | The unique id for the header |
BrnCalendarMonthSelect
Selector: brnSelect[brnCalendarMonthSelect],hlm-select[brnCalendarMonthSelect]
ExportAs: brnCalendarMonthSelect
BrnCalendarMonth
Selector: [brnCalendarMonth]
ExportAs: brnCalendarMonth
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| offset | number | 0 | The offset of this month relative to the first displayed month. |
BrnCalendarNextButton
Selector: button[brnCalendarNextButton]
ExportAs: brnCalendarNextButton
BrnCalendarPreviousButton
Selector: button[brnCalendarPreviousButton]
ExportAs: brnCalendarPreviousButton
BrnCalendarWeek
Selector: [brnCalendarWeek]
ExportAs: brnCalendarWeek
BrnCalendarWeekday
Selector: [brnCalendarWeekday]
ExportAs: brnCalendarWeekday
BrnCalendarYearSelect
Selector: brnSelect[brnCalendarYearSelect],hlm-select[brnCalendarYearSelect]
ExportAs: brnCalendarYearSelect
BrnCalendar
Selector: [brnCalendar]
ExportAs: brnCalendar
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| highlightDays | T[] | [] | The days to highlight. |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| disabled | boolean | false | Determine if the date picker is disabled. |
| dateDisabled | (date: T) => boolean | () => false | Whether a specific date is disabled. |
| weekStartsOn | Weekday | undefined | The day the week starts on |
| defaultFocusedDate | T | - | The default focused date. |
| date | T | - | The selected value. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| focusedDateChange | T | - | Emits whenever the focused date changes. |
| dateChange | T | - | The selected value. |
BrnCalendarMulti
Selector: [brnCalendarMulti]
ExportAs: brnCalendarMulti
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| highlightDays | T[] | [] | The days to highlight. |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| minSelection | number | undefined | The minimum selectable dates. |
| maxSelection | number | undefined | The maximum selectable dates. |
| disabled | boolean | false | Determine if the date picker is disabled. |
| dateDisabled | (date: T) => boolean | () => false | Whether a specific date is disabled. |
| weekStartsOn | Weekday | undefined | The day the week starts on |
| defaultFocusedDate | T | - | The default focused date. |
| date | T[] | - | The selected value. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| focusedDateChange | T | - | Emits whenever the focused date changes. |
| dateChange | T[] | - | The selected value. |
BrnCalendarRange
Selector: [brnCalendarRange]
ExportAs: brnCalendarRange
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| highlightDays | T[] | [] | The days to highlight. |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| disabled | boolean | false | Determine if the date picker is disabled. |
| dateDisabled | (date: T) => boolean | () => false | Whether a specific date is disabled. |
| weekStartsOn | Weekday | undefined | The day the week starts on |
| defaultFocusedDate | T | - | The default focused date. |
| numberOfMonths | number | 1 | The number of months to display. |
| startDate | T | - | The selected start date |
| endDate | T | - | The selected end date |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| focusedDateChange | T | - | Emits whenever the focused date changes. |
| startDateChange | T | - | The selected start date |
| endDateChange | T | - | The selected end date |
BrnMonthYearCalendarGrid
Selector: [brnMonthYearCalendarGrid]
ExportAs: brnMonthYearCalendarGrid
BrnMonthYearCalendarHeader
Selector: button[brnMonthYearCalendarHeader]
ExportAs: brnMonthYearCalendarHeader
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-month-year-header-${++uniqueId}` | The unique id for the header |
BrnMonthYearCalendarMonthButton
Selector: button[brnMonthYearCalendarMonthButton]
ExportAs: brnMonthYearCalendarMonthButton
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| date* (required) | T | - | The month this cell represents. |
BrnMonthYearCalendarNextButton
Selector: button[brnMonthYearCalendarNextButton]
ExportAs: brnMonthYearCalendarNextButton
BrnMonthYearCalendarPreviousButton
Selector: button[brnMonthYearCalendarPreviousButton]
ExportAs: brnMonthYearCalendarPreviousButton
BrnMonthYearCalendarYearButton
Selector: button[brnMonthYearCalendarYearButton]
ExportAs: brnMonthYearCalendarYearButton
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| date* (required) | T | - | The year this cell represents. |
BrnMonthYearCalendar
Selector: [brnMonthYearCalendar]
ExportAs: brnMonthYearCalendar
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| disabled | boolean | false | Whether the month/year selector is disabled. |
| defaultFocusedDate | T | - | The default focused date. |
| view | BrnMonthYearCalendarView | 'year' | The current view. The year view is shown first. |
| date | T | - | The selected month. Represented by the first day of the month. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| focusedDateChange | T | - | Emits whenever the focused date changes. |
| dateChange | T | - | The selected month. Represented by the first day of the month. |
Helm API
HlmCalendarMulti
Selector: hlm-calendar-multi
ExportAs: hlmCalendarMulti
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| captionLayout | 'dropdown' | 'label' | 'dropdown-months' | 'dropdown-years' | 'label' | Show dropdowns to navigate between months or years. |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| minSelection | number | undefined | The minimum selectable dates. |
| maxSelection | number | undefined | The maximum selectable dates. |
| disabled | boolean | false | Determine if the date picker is disabled. |
| date | T[] | - | The selected value. |
| dateDisabled | (date: T) => boolean | () => false | Whether a specific date is disabled. |
| weekStartsOn | Weekday | undefined | The day the week starts on |
| highlightDays | T[] | [] | The days to highlight. |
| defaultFocusedDate | T | - | The default focused date. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| dateChange | T[] | - | The selected value. |
HlmCalendarRange
Selector: hlm-calendar-range
ExportAs: hlmCalendarRange
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| captionLayout | 'dropdown' | 'label' | 'dropdown-months' | 'dropdown-years' | 'label' | Show dropdowns to navigate between months or years. |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| disabled | boolean | false | Determine if the date picker is disabled. |
| startDate | T | - | The selected start date |
| endDate | T | - | The selected end date |
| dateDisabled | (date: T) => boolean | () => false | Whether a specific date is disabled. |
| weekStartsOn | Weekday | undefined | The day the week starts on |
| highlightDays | T[] | [] | The days to highlight. |
| defaultFocusedDate | T | - | The default focused date. |
| numberOfMonths | number | 1 | The number of months to display. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| endDateChange | T | - | The selected end date |
| startDateChange | T | - | The selected start date |
HlmCalendar
Selector: hlm-calendar
ExportAs: hlmCalendar
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| captionLayout | 'dropdown' | 'label' | 'dropdown-months' | 'dropdown-years' | 'label' | Show dropdowns to navigate between months or years. |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| disabled | boolean | false | Determine if the date picker is disabled. |
| date | T | - | The selected value. |
| dateDisabled | (date: T) => boolean | () => false | Whether a specific date is disabled. |
| weekStartsOn | Weekday | undefined | The day the week starts on |
| highlightDays | T[] | [] | The days to highlight. |
| defaultFocusedDate | T | - | The default focused date. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| dateChange | T | - | The selected value. |
HlmMonthYearCalendar
Selector: hlm-month-year-calendar
ExportAs: hlmMonthYearCalendar
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| disabled | boolean | false | Whether the month/year selector is disabled. |
| date | T | - | The selected month. Represented by the first day of the month. |
| defaultFocusedDate | T | - | The default focused date. |
| view | BrnMonthYearCalendarView | 'year' | The current view. The year view is shown first. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| dateChange | T | - | The selected month. Represented by the first day of the month. |
On This Page