Date Range
Date range picker with a trigger button, a clear button and a calendar to pick the start and end day, with ControlValueAccessor support. The value is an IDateRange from @smartsoft001/domain-core ({ start, end }, both YYYY-MM-DD); clearing sets it to undefined.
This component has both a default concrete implementation (<smart-date-range>) and abstract base classes for custom extensions.
Usage
<smart-date-range [ngModel]="range()" (ngModelChange)="onRangeChange($event)" />
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.
Default Component Usage
Selector
<smart-date-range> (class DateRangeComponent), bound with [(ngModel)], formControlName or [formControl].
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
ngModel | ModelSignal<IDateRange | undefined> | undefined | The range (start, end in YYYY-MM-DD); also bound through ControlValueAccessor (formControlName). |
variant | DateRangeVariantName | 'standard' | 'standard' (trigger + scrollable calendar modal) or 'preset' (trigger + popover calendar). |
class | string | '' | Classes on the rendered variant (cssClass input, alias class). |
DateRangeVariantName is 'standard' | 'preset'.
Features
- Trigger button with a calendar icon, showing
start - end(or the translatedselectwhile empty) - Clear button (X) that resets the value to
undefined standard: a modal with a scrollable calendar of the months around today; pick a start, then an end day, and applypreset: a popover calendar with month navigation, then Apply / CancelControlValueAccessorfor template-driven and reactive forms- Dark mode
<smart-date-range> does not show the modal's quick-pick buttons (today, last 7 days, ...): the standard renders DateRangeModalStandardComponent without showFilterBtns and restrictSelectionTo, so both stay at their defaults. They take effect only when you render the modal yourself (see DateRangeModalBaseComponent).
DateRangePresetComponent (<smart-date-range-preset>)
A fully styled, drop-in variation based on the Preline "single calendar range" datepicker. The Preline JS plugin is not installed, so the range calendar is rendered entirely with Angular signals (no external runtime): click the trigger to open an inline popover, pick a start and end day to highlight the range, switch months via prev/next buttons or the month/year selects, then Apply.
It extends DateRangeBaseComponent (reuses onClick, onModalApply, onModalDismiss, onClear), so it has the same value API and ControlValueAccessor contract as the standard variant.
Selecting the variant
<smart-date-range> picks the rendering with its variant input and an internal @switch; it has no injection token. Use variant="preset" on the wrapper, or the <smart-date-range-preset> selector directly.
The wrapper binds [class]="cssClass()" on the variant it renders, so class on <smart-date-range> reaches either variant.
Base Classes API (for Extension)
DateRangeBaseComponent
Provides the value, the open/close state, the calendar state kept between opens, the clear/apply logic and ControlValueAccessor.
| Member | Type | Description |
|---|---|---|
ngModel | ModelSignal<IDateRange | undefined> | Date range value |
value | IDateRange | undefined | Current value (synced from ngModel via an effect) |
isOpen | WritableSignal<boolean> | Whether the picker is open |
calendarData | CalendarState | Calendar state the picker reopens with |
onClick() | method | Opens the picker with the current range |
onModalApply(data) | method | Sets the value from a CalendarState, emits it and closes |
onModalDismiss() | method | Closes without changing the value |
onClear() | method | Resets the value to undefined and emits it |
propagateChange(val) | method | The registered ControlValueAccessor change callback |
DateRangeModalBaseComponent
The modal's behaviour: calendar months, quick-pick buttons, date selection and range restriction. DateRangeModalStandardComponent (<smart-date-range-modal-standard>) is its implementation.
| Member | Type | Description |
|---|---|---|
showFilterBtns | InputSignal<boolean> | Shows the quick-pick buttons. Default false; modal only: <smart-date-range> does not set it. |
restrictSelectionTo | InputSignal<number> | When non-zero, only a range of exactly this many days can be applied. Default 0; modal only. |
previousState | InputSignal<CalendarState> | The state the modal opens with; without dateFrom it selects today |
apply | OutputEmitterRef<CalendarState> | Emits the picked state on apply |
dismiss | OutputEmitterRef<void> | Emits when the modal is closed without applying |
calendar | month[] | The months of the CalendarService |
dateForm | UntypedFormGroup | dateFrom / dateTo (shown dates) and the datesRefGroup of the picked days |
selectToday() … selectLastMonth() | method | Quick picks: today, yesterday, last 7 days, last 30 days, this month, last month |
isInRange(day) | method | Whether a day lies inside the picked range |
isSelectionStart(day) | method | Whether a day is the range start |
isSelectionEnd(day) | method | Whether a day is the range end |
isStartAndEndDateSame() | method | Whether start and end are the same day |
isSelectionInRestrictedRange() | method | Whether the range has exactly restrictSelectionTo days |
applyDates() | method | Emits apply with the current state |
dismissPage() | method | Emits dismiss and unsubscribes |
CalendarState
What the modal applies, and is reopened with.
| Field | Type | Default | Description |
|---|---|---|---|
dateFrom | moment.Moment | required | Start of the picked range (null while nothing is picked). |
dateTo | moment.Moment | required | End of the picked range. |
scrollPosition | number | required | Scroll position of the modal's calendar, restored on reopening. |
selectedButtonName | FilterBtnConstants | required | The quick-pick button that produced the range. |
FilterBtnConstants is a const enum: empthyString = '' (spelled that way in the code), today = 'Today', yesterday = 'Yesterday', lastSevenDays = 'LastSevenDays', lastThirtyDays = 'LastThirtyDays', thisMonth = 'ThisMonth', lastMonth = 'LastMonth'.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
forwardRef,
signal,
ViewEncapsulation,
} from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { DateRangeBaseComponent } from '@smartsoft001/angular';
import { IDateRange } from '@smartsoft001/domain-core';
/**
* A custom range picker built on `DateRangeBaseComponent`.
*
* The base owns the value (`ngModel` / `value`), the open state (`isOpen`,
* `onClick`, `onModalDismiss`), the reset (`onClear`) and the
* `ControlValueAccessor` contract. Here the full calendar modal is replaced
* with a short list of preset ranges.
*/
@Component({
selector: 'docs-custom-date-range',
template: `
<div class="docs-date-range">
<button
type="button"
class="docs-date-range__trigger"
(click)="onClick()"
>
@if (value) {
{{ value.start }} - {{ value.end }}
} @else {
Pick a range
}
</button>
@if (value) {
<button
type="button"
class="docs-date-range__clear"
(click)="onClear()"
>
Clear
</button>
}
@if (isOpen()) {
<ul class="docs-date-range__panel">
<li>
<button
type="button"
(click)="apply({ start: '2026-04-01', end: '2026-04-07' })"
>
First week of April
</button>
</li>
<li>
<button
type="button"
(click)="apply({ start: '2026-04-01', end: '2026-04-30' })"
>
Whole of April
</button>
</li>
<li>
<button type="button" (click)="onModalDismiss()">Cancel</button>
</li>
</ul>
}
</div>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => CustomDateRangeComponent),
multi: true,
},
],
})
export class CustomDateRangeComponent extends DateRangeBaseComponent {
/**
* The base also exposes `onModalApply()`, but that one expects a
* `CalendarState` carrying moment objects produced by the built-in calendar.
* A picker that does not use that calendar writes the value itself and keeps
* everything else the base provides.
*/
apply(range: IDateRange): void {
this.value = range;
this.ngModel.set(range);
this.propagateChange(range);
this.propagateTouched();
this.isOpen.set(false);
}
}
/**
* Date range has no injection token: `<smart-date-range>` picks between its
* `standard` and `preset` variations through the `variant` input, so a custom
* implementation is rendered directly rather than registered.
*/
@Component({
selector: 'docs-date-range-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [CustomDateRangeComponent],
template: `
<docs-custom-date-range
[ngModel]="range()"
(ngModelChange)="range.set($event)"
/>
`,
})
export class DateRangeCustomExampleComponent {
range = signal<IDateRange | undefined>({
start: '2026-04-01',
end: '2026-04-07',
});
}
Dependencies
@smartsoft001/domain-core—IDateRangeinterface@ngx-translate/core—TranslatePipefor i18nmoment— date operationsCalendarService— calendar month generation
Tailwind Classes
All classes use smart: prefix. Trigger: smart:inline-flex smart:rounded-md smart:border smart:border-gray-300. Modal backdrop: smart:fixed smart:inset-0 smart:bg-black/50. Calendar selection: smart:bg-indigo-600 smart:text-white.
Source
The component lives in packages/shared/angular/src/lib/components/date-range and is documented for Claude Code by the angular-components-date-range skill.
SmartDateRange picks a date range, an IDateRange from @smartsoft001/domain-core ({ start, end }, both YYYY-MM-DD). Its variant picks the rendering: standard (default) is a trigger with a clear button that opens SmartDateRangeModalStandard, a scrollable calendar of the months around today; preset is a trigger opening a popover calendar where the user picks a start and an end day and applies. Bind it with value + onValueChange (or defaultValue), or pass a form control. Clearing emits undefined.
Usage
import { useState } from 'react';
import { IDateRange } from '@smartsoft001/domain-core';
import { SmartDateRange } from '@smartsoft001/react';
export function DateRangeUsageExample() {
// `null` keeps the picker controlled once the range is cleared.
const [range, setRange] = useState<IDateRange | null>({
start: '2026-04-01',
end: '2026-04-30',
});
return (
<SmartDateRange
value={range}
onValueChange={(next) => setRange(next ?? null)}
/>
);
}
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 |
|---|---|---|
SmartDateRange | component | The date-range picker in the variant rendering (standard, a trigger opening a scrollable calendar modal, by default; or preset, a calendar popover). |
SmartDateRangePreset | component | Styled date-range variation (preset) based on the Preline "single calendar range" datepicker. |
SmartDateRangeModalStandard | component | The date-range picker modal: a scrollable calendar of the months around today. |
SmartDateRangeStandard | component | The default date-range rendering: a trigger showing the range and a clear button; the trigger opens <SmartDateRangeModalStandard>, rendered inline. |
useDateRangeModal | hook | The behaviour of the date-range modal: the scrollable calendar of the CalendarService, the picked range and the quick-pick buttons. |
useDateRange | hook | The behaviour every date-range variant shares: the range value, the open state of the picker and the calendar state the picker is reopened with. |
The preset's class helpers (DATE_RANGE_PRESET_TRIGGER, DATE_RANGE_PRESET_CLEAR, DATE_RANGE_PRESET_POPOVER, DATE_RANGE_PRESET_NAV_BUTTON, DATE_RANGE_PRESET_SELECT, DATE_RANGE_PRESET_WEEKDAY, DATE_RANGE_PRESET_DAY_DEFAULT, DATE_RANGE_PRESET_DAY_MUTED, DATE_RANGE_PRESET_DAY_SELECTED, DATE_RANGE_PRESET_RANGE_BG, DATE_RANGE_PRESET_FOOTER, DATE_RANGE_PRESET_CANCEL_BUTTON, DATE_RANGE_PRESET_APPLY_BUTTON) are exported too, for a custom implementation that wants the preset look.
Props and Types
SmartDateRangeProps
Props of <SmartDateRange>. Extends SmartDateRangeVariantProps.
| Prop | Type | Default | Description |
|---|---|---|---|
variant? | DateRangeVariantName | 'standard' | standard (trigger + modal) or preset (popover calendar). |
control? | SmartAbstractControl | — | Binds the range to a form control: the control's value is shown, a change sets it and marks the control dirty and touched. |
SmartDateRangeVariantProps
Props of the date-range variants: the range as a controlled value + onValueChange pair, or kept internally from defaultValue.
| Prop | Type | Default | Description |
|---|---|---|---|
value? | IDateRange | null | — | The range. undefined leaves the component uncontrolled, starting from defaultValue; null is an empty controlled value. |
defaultValue? | IDateRange | null | — | The initial range when uncontrolled. |
onValueChange? | (value: IDateRange | undefined) => void | — | Emits the applied range, or undefined once cleared. |
className? | string | — | Classes on the root element. |
SmartDateRangeModalProps
Props of the date-range modal (SmartDateRangeModalStandard). SmartDateRange renders the modal with none of them but previousState, onApply and onDismiss, so showFilterBtns and restrictSelectionTo only take effect when you render the modal yourself, e.g. <SmartDateRangeModalStandard showFilterBtns ... /> in a picker built on useDateRange.
| Prop | Type | Default | Description |
|---|---|---|---|
showFilterBtns? | boolean | false | Shows the quick-pick buttons (today, last 7 days, ...). Modal only. |
restrictSelectionTo? | number | 0 | When set, only a range of exactly this many days can be applied. Modal only. |
previousState? | CalendarState | — | The state the modal opens with; without dateFrom it selects today. |
onApply? | (state: CalendarState) => void | — | Called with the picked state when the user applies. |
onDismiss? | () => void | — | Called when the modal is closed without applying (backdrop or close button). |
CalendarState
What the date-range modal applies, and is reopened with.
| Field | Type | Default | Description |
|---|---|---|---|
dateFrom | moment.Moment | null | required | Start of the picked range. |
dateTo | moment.Moment | null | required | End of the picked range. |
scrollPosition | number | required | Scroll position of the modal's calendar, restored on reopening. |
selectedButtonName | FilterBtnConstants | required | The quick-pick button that produced the range. |
DateRangeModalForm
The modal's form: the shown dates and the picked days.
| Field | Type | Default | Description |
|---|---|---|---|
dateFrom | string | null | required | The shown start date. |
dateTo | string | null | required | The shown end date. |
startDateRef | moment.Moment | null | required | The picked start day. |
endDateRef | moment.Moment | null | required | The picked end day. |
Related types
DateRangeVariantName:'standard' \| 'preset'— The renderingsSmartDateRangecan pick.FilterBtnConstants(enum):empthyString = '', today = 'Today', yesterday = 'Yesterday', lastSevenDays = 'LastSevenDays', lastThirtyDays = 'LastThirtyDays', thisMonth = 'ThisMonth', lastMonth = 'LastMonth'— The quick-pick buttons of the modal (theempthyStringmember is spelled that way in the code).
SmartAbstractControl is described in the react-forms and react-provider skills.
Binding
- Controlled:
value(IDateRange,nullfor empty) andonValueChange(range | undefined). - Uncontrolled: leave
valueundefined; the picker starts fromdefaultValue. - Form control:
control={someControl}shows the control's value; a change sets it, marks the control dirty and touched, and still callsonValueChange.
Replacing the Implementation
SmartDateRange has no SmartProvider registry key: the variant prop picks SmartDateRangeStandard or SmartDateRangePreset, and both can be rendered directly with SmartDateRangeVariantProps. A form's dateRange fields render it through the input field components (see react-components-input). For another look, write a component on useDateRange (and useDateRangeModal for the modal's calendar) and render it in place of SmartDateRange.
Hooks
useDateRangeModal
The behaviour of the date-range modal: the scrollable calendar of the CalendarService, the picked range and the quick-pick buttons.
| Returns | Type | Description |
|---|---|---|
elementRef | RefObject<HTMLDivElement | null> | Attach to the scrollable calendar element. |
calendar | month[] | The months of the CalendarService shown in the modal. |
dateForm | DateRangeModalForm | The shown dates and the picked days. |
selectedButtonName | FilterBtnConstants | The active quick pick. |
onDayClick | (date: moment.Moment | null) => void | Picks a start, then an end day. |
isInRange | (day: moment.Moment | null) => boolean | Whether a day lies inside the picked range. |
isSelectionStart | (day: moment.Moment | null) => boolean | Whether a day is the range start. |
isSelectionEnd | (day: moment.Moment | null) => boolean | Whether a day is the range end. |
isStartAndEndDateSame | () => boolean | Whether start and end are the same day. |
isSelectionInRestrictedRange | () => boolean | Whether the range has exactly restrictSelectionTo days (always true without a restriction). |
selectToday | () => void | Quick pick: today. |
selectYesterday | () => void | Quick pick: yesterday. |
selectLastSevenDays | () => void | Quick pick: the last 7 days. |
selectLastThirtyDays | () => void | Quick pick: the last 30 days. |
selectThisMonth | () => void | Quick pick: this month. |
selectLastMonth | () => void | Quick pick: last month. |
dismissPage | () => void | undefined | Calls onDismiss. |
applyDates | () => void | Calls onApply with the picked state. |
useDateRange
The behaviour every date-range variant shares: the range value, the open state of the picker and the calendar state the picker is reopened with.
| Returns | Type | Description |
|---|---|---|
value | IDateRange | undefined | The current range (controlled or internal), undefined when empty. |
isOpen | boolean | Whether the picker is open. |
calendarData | CalendarState | The CalendarState the picker reopens with. |
onClick | () => void | Opens the picker. |
onModalApply | (data: CalendarState) => void | Applies a picked CalendarState: sets the range, calls onValueChange and closes. |
onModalDismiss | () => void | Closes the picker without changing the range. |
onClear | () => void | Clears the range and calls onValueChange(undefined). |
import { useState } from 'react';
import { IDateRange } from '@smartsoft001/domain-core';
import { SmartDateRangeVariantProps, useDateRange } from '@smartsoft001/react';
/**
* A custom range picker built on `useDateRange`.
*
* The hook owns the range (controlled or not), the open state (`isOpen`,
* `onClick`, `onModalDismiss`) and the reset (`onClear`). Here the calendar
* modal is replaced with a short list of preset ranges.
*/
export function CustomDateRange(props: SmartDateRangeVariantProps) {
const { value, isOpen, onClick, onModalDismiss, onClear } =
useDateRange(props);
// The hook's onModalApply() takes the CalendarState (moment objects) of the
// built-in calendar. A picker without that calendar reports the range
// through onValueChange and closes; the parent's `value` brings it back in.
const apply = (range: IDateRange) => {
props.onValueChange?.(range);
onModalDismiss();
};
return (
<div
className={['docs-date-range', props.className].filter(Boolean).join(' ')}
>
<button
type="button"
className="docs-date-range__trigger"
onClick={onClick}
>
{value ? `${value.start} - ${value.end}` : 'Pick a range'}
</button>
{value && (
<button
type="button"
className="docs-date-range__clear"
onClick={onClear}
>
Clear
</button>
)}
{isOpen && (
<ul className="docs-date-range__panel">
<li>
<button
type="button"
onClick={() => apply({ start: '2026-04-01', end: '2026-04-07' })}
>
First week of April
</button>
</li>
<li>
<button
type="button"
onClick={() => apply({ start: '2026-04-01', end: '2026-04-30' })}
>
Whole of April
</button>
</li>
<li>
<button type="button" onClick={onModalDismiss}>
Cancel
</button>
</li>
</ul>
)}
</div>
);
}
// SmartDateRange has no SmartProvider registry key: its `variant` prop picks
// the standard or preset rendering, so a custom implementation is rendered
// directly in place of <SmartDateRange>.
export function DateRangeCustomExample() {
const [range, setRange] = useState<IDateRange | null>({
start: '2026-04-01',
end: '2026-04-07',
});
return (
<CustomDateRange
value={range}
onValueChange={(next) => setRange(next ?? null)}
/>
);
}
Styling
SmartDateRangeModalStandardisfixedpositioned and rendered inline by the standard trigger; a backdrop click or its close button dismisses it.- Both variants carry
smart:dark:variants;classNameis appended to the root element.
Source
The component lives in packages/shared/react/src/lib/components/date-range and is documented for Claude Code by the react-components-date-range skill.