Spartans get ready! v1 is coming!
We are very close to our first stable release. Expect more announcements in the coming weeks. v1 was made possible by our partner Zerops.
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Dropdown Menu
- Empty
- Form Field
- Hover Card
- Icon
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Menubar
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
Calendar
A date field component that allows users to enter and edit date.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { Component } from '@angular/core';
import { HlmCalendarImports } from '@spartan-ng/helm/calendar';
@Component({
selector: 'spartan-calendar-preview',
imports: [HlmCalendarImports],
template: `
<hlm-calendar [(date)]="selectedDate" [min]="minDate" [max]="maxDate" />
`,
})
export class CalendarPreview {
/** The selected date */
public selectedDate = new Date();
/** The minimum date */
public minDate = new Date(2023, 0, 1);
/** The maximum date */
public maxDate = new Date(2030, 11, 31);
}
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',
labelWeekday: (i) => ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'][i],
firstDayOfWeek: () => 1,
}),
],
});
`;Installation
npx nx g @spartan-ng/cli:ui calendar
ng g @spartan-ng/cli:ui calendar
Usage
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',
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 { Component } from '@angular/core';
import { HlmCalendarImports } from '@spartan-ng/helm/calendar';
@Component({
selector: 'spartan-calendar-multiple',
imports: [HlmCalendarImports],
template: `
<hlm-calendar-multi
[(date)]="selectedDates"
[min]="minDate"
[max]="maxDate"
[minSelection]="2"
[maxSelection]="6"
/>
`,
})
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.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { Component } from '@angular/core';
import { HlmCalendarImports } from '@spartan-ng/helm/calendar';
@Component({
selector: 'spartan-calendar-range',
imports: [HlmCalendarImports],
template: `
<hlm-calendar-range [(startDate)]="start" [(endDate)]="end" [min]="minDate" [max]="maxDate" />
`,
})
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
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { Component, model } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrnSelectImports } from '@spartan-ng/brain/select';
import { HlmCalendar } from '@spartan-ng/helm/calendar';
import { HlmSelectImports } from '@spartan-ng/helm/select';
@Component({
selector: 'spartan-calendar-year-and-month',
imports: [HlmCalendar, BrnSelectImports, HlmSelectImports, FormsModule],
template: `
<hlm-calendar [captionLayout]="_captionLayout()" />
<brn-select class="inline-block" placeholder="Select an option" [(ngModel)]="_captionLayout">
<hlm-select-trigger class="w-full">
<hlm-select-value />
</hlm-select-trigger>
<hlm-select-content>
<hlm-option value="dropdown">Month and Year</hlm-option>
<hlm-option value="dropdown-months">Only Month</hlm-option>
<hlm-option value="dropdown-years">Only Year</hlm-option>
</hlm-select-content>
</brn-select>
`,
host: {
class: 'flex flex-col gap-4',
},
})
export class CalendarYearAndMonthExample {
protected readonly _captionLayout = model<'dropdown' | 'label' | 'dropdown-months' | 'dropdown-years'>('dropdown');
}Brain API
BrnCalendarCellButton
Selector: button[brnCalendarCellButton]
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| date* (required) | T | - | The date this cell represents |
BrnCalendarCell
Selector: [brnCalendarCell]
BrnCalendarGrid
Selector: [brnCalendarGrid]
BrnCalendarHeader
Selector: [brnCalendarHeader]
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | unknown | `brn-calendar-header-${++uniqueId}` | The unique id for the header |
BrnCalendarMonthSelect
Selector: brn-select[brnCalendarMonthSelect]
BrnCalendarNextButton
Selector: [brnCalendarNextButton]
BrnCalendarPreviousButton
Selector: [brnCalendarPreviousButton]
BrnCalendarWeek
Selector: [brnCalendarWeek]
BrnCalendarWeekday
Selector: [brnCalendarWeekday]
BrnCalendarYearSelect
Selector: brn-select[brnCalendarYearSelect]
BrnCalendar
Selector: [brnCalendar]
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 | 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 |
|---|---|---|---|
| dateChanged | T | - | The selected value. |
BrnCalendarMulti
Selector: [brnCalendarMulti]
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| 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 |
|---|---|---|---|
| dateChanged | T[] | - | The selected value. |
BrnCalendarRange
Selector: [brnCalendarRange]
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 | 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. |
| startDate | T | - | The selected start date |
| endDate | T | - | The selected end date |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| startDateChanged | T | - | The selected start date |
| endDateChanged | T | - | The selected end date |
Helm API
HlmCalendarMulti
Selector: hlm-calendar-multi
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| calendarClass | ClassValue | - | - |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| captionLayout | 'dropdown' | 'label' | 'dropdown-months' | 'dropdown-years' | label | Show dropdowns to navigate between months or years. |
| 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 |
|---|---|---|---|
| dateChanged | T[] | - | The selected value. |
HlmCalendarRange
Selector: hlm-calendar-range
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| calendarClass | ClassValue | - | - |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| captionLayout | 'dropdown' | 'label' | 'dropdown-months' | 'dropdown-years' | label | Show dropdowns to navigate between months or years. |
| 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. |
| startDate | T | - | The start date of the range. |
| endDate | T | - | The end date of the range. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| startDateChanged | T | - | The start date of the range. |
| endDateChanged | T | - | The end date of the range. |
HlmCalendar
Selector: hlm-calendar
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| calendarClass | ClassValue | - | - |
| min | T | - | The minimum date that can be selected. |
| max | T | - | The maximum date that can be selected. |
| captionLayout | 'dropdown' | 'label' | 'dropdown-months' | 'dropdown-years' | label | Show dropdowns to navigate between months or years. |
| 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 |
|---|---|---|---|
| dateChanged | T | - | The selected value. |
On this page