Date Picker

A date picker component.

Installation

The Date Picker component is built with the Popover and the Calendar components.

ng g @spartan-ng/cli:ui date-picker

Usage

import { HlmDatePickerImports } from '@spartan-ng/helm/date-picker';
<hlm-date-picker [min]="minDate" [max]="maxDate">
  <hlm-date-picker-trigger buttonId="date">Pick a date</hlm-date-picker-trigger>
</hlm-date-picker>

Examples

Custom Configs

Use provideHlmDatePickerConfig to provide custom configs for the date picker component throughout the application.

  • autoCloseOnSelect: boolean; if true , the date picker will close when a date is selected.
  • formatDate: (date: T) => string; defines the default format how the date should be displayed in the UI.
  • transformDate: (date: T) => T; defines the default format how the date should be transformed before saving to model/form.

Multiple Selection

Use hlm-date-picker-multi for multiple date selection. Limit the selectable dates using minSelection and maxSelection inputs.

Range Picker

Use hlm-date-range-picker for range date selection. Set the range by using startDate and endDate inputs.

Format Date

Use formatDate input to override the global date format for the date picker component.

Input Picker

Use hlm-date-picker-input instead of hlm-date-picker-trigger to let users type a date directly. Provide a parseDate input (or set it globally via provideHlmDatePickerConfig ) to control how typed strings are parsed into dates - typically pair it with a matching formatDate .

Date and Time picker

Form

Sync the date to a form by adding formControlName to hlm-date-picker .

Your date of birth is used to calculate your age.

Form with Input Picker

Combine formControlName with hlm-date-picker-input to let users type a date or pick one from the calendar while syncing the value to a reactive form.

Type a date (dd.MM.yyyy) or pick one from the calendar.

Form Multiple Selection

Sync the dates to a form by adding formControlName to hlm-date-picker-multi .

Form Range Picker

Sync the dates to a form by adding formControlName to hlm-date-range-picker .

RTL

To enable RTL support in spartan-ng, see the RTL configuration guide.

Helm API

HlmDatePickerAnchor

Selector: [hlmDatePickerAnchor]

Inputs

PropTypeDefaultDescription
hlmDatePickerAnchorFor BrnPopover | undefined undefined -

HlmDatePickerInput

Selector: hlm-date-picker-input

Inputs

PropTypeDefaultDescription
inputId unknown `hlm-date-picker-input-${HlmDatePickerInput._nextId++}` -
placeholder unknown --
inputValue string --
parseDate (value: string) => T | undefined this._config.parseDate Parses input text into a date value. Return `undefined` for invalid input - the picker's date is cleared while the text is preserved so the user can fix it. Defaults to `parseDate` from `HlmDatePickerConfig`.
forceInvalid boolean false -
showClear boolean true Show a clear button that resets the input and picker date. Hidden when empty.
openOnClick boolean false Open the popover on input click.
clearAriaLabel string Clear date Accessible label for the clear button.
calendarAriaLabel string Open calendar Accessible label for the calendar trigger button.

HlmDatePickerMulti

Selector: hlm-date-picker-multi

Inputs

PropTypeDefaultDescription
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.
autoCloseOnMaxSelection boolean this._config.autoCloseOnMaxSelection If true, the date picker will close when the max selection of dates is reached.
formatDates (date: T[]) => string this._config.formatDates Defines how the date should be displayed in the UI.
transformDates (date: T[]) => T[] this._config.transformDates Defines how the date should be transformed before saving to model/form.

Outputs

PropTypeDefaultDescription
dateChange T[] --

HlmDatePickerTrigger

Selector: hlm-date-picker-trigger

Inputs

PropTypeDefaultDescription
class ClassValue --
buttonId string `hlm-date-picker-${++HlmDatePickerTrigger._nextId}` The id of the button that opens the date picker.
forceInvalid boolean false Forces the invalid state visually, regardless of form control state.
variant ButtonVariants['variant'] outline -
showTrigger boolean true -

HlmDatePicker

Selector: hlm-date-picker

Inputs

PropTypeDefaultDescription
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.
defaultFocusedDate T - The date the calendar focuses on first open when no date is selected.
autoCloseOnSelect boolean this._config.autoCloseOnSelect If true, the date picker will close when a date is selected.
formatDate (date: T) => string this._config.formatDate Defines how the date should be displayed in the UI.
transformDate (date: T) => T this._config.transformDate Defines how the date should be transformed before saving to model/form.

Outputs

PropTypeDefaultDescription
dateChange T --

HlmDateRangePicker

Selector: hlm-date-range-picker

Inputs

PropTypeDefaultDescription
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, T] - The selected value.
autoCloseOnEndSelection boolean this._config.autoCloseOnEndSelection If true, the date picker will close when the end date is selected
formatDates (dates: [T | undefined, T | undefined]) => string this._config.formatDates Defines how the date should be displayed in the UI.
transformDates (date: [T, T]) => [T, T] this._config.transformDates Defines how the date should be transformed before saving to model/form.

Outputs

PropTypeDefaultDescription
dateChange [T, T] | null --
Dialog Data Table