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

InputTypeDefaultDescription
ngModelModelSignal<IDateRange | undefined>undefinedThe range (start, end in YYYY-MM-DD); also bound through ControlValueAccessor (formControlName).
variantDateRangeVariantName'standard''standard' (trigger + scrollable calendar modal) or 'preset' (trigger + popover calendar).
classstring''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 translated select while 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 apply
  • preset: a popover calendar with month navigation, then Apply / Cancel
  • ControlValueAccessor for 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.

MemberTypeDescription
ngModelModelSignal<IDateRange | undefined>Date range value
valueIDateRange | undefinedCurrent value (synced from ngModel via an effect)
isOpenWritableSignal<boolean>Whether the picker is open
calendarDataCalendarStateCalendar state the picker reopens with
onClick()methodOpens the picker with the current range
onModalApply(data)methodSets the value from a CalendarState, emits it and closes
onModalDismiss()methodCloses without changing the value
onClear()methodResets the value to undefined and emits it
propagateChange(val)methodThe 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.

MemberTypeDescription
showFilterBtnsInputSignal<boolean>Shows the quick-pick buttons. Default false; modal only: <smart-date-range> does not set it.
restrictSelectionToInputSignal<number>When non-zero, only a range of exactly this many days can be applied. Default 0; modal only.
previousStateInputSignal<CalendarState>The state the modal opens with; without dateFrom it selects today
applyOutputEmitterRef<CalendarState>Emits the picked state on apply
dismissOutputEmitterRef<void>Emits when the modal is closed without applying
calendarmonth[]The months of the CalendarService
dateFormUntypedFormGroupdateFrom / dateTo (shown dates) and the datesRefGroup of the picked days
selectToday() … selectLastMonth()methodQuick picks: today, yesterday, last 7 days, last 30 days, this month, last month
isInRange(day)methodWhether a day lies inside the picked range
isSelectionStart(day)methodWhether a day is the range start
isSelectionEnd(day)methodWhether a day is the range end
isStartAndEndDateSame()methodWhether start and end are the same day
isSelectionInRestrictedRange()methodWhether the range has exactly restrictSelectionTo days
applyDates()methodEmits apply with the current state
dismissPage()methodEmits dismiss and unsubscribes

CalendarState

What the modal applies, and is reopened with.

FieldTypeDefaultDescription
dateFrommoment.MomentrequiredStart of the picked range (null while nothing is picked).
dateTomoment.MomentrequiredEnd of the picked range.
scrollPositionnumberrequiredScroll position of the modal's calendar, restored on reopening.
selectedButtonNameFilterBtnConstantsrequiredThe 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 — IDateRange interface
  • @ngx-translate/core — TranslatePipe for i18n
  • moment — date operations
  • CalendarService — 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.

ExportKindWhat it is
SmartDateRangecomponentThe date-range picker in the variant rendering (standard, a trigger opening a scrollable calendar modal, by default; or preset, a calendar popover).
SmartDateRangePresetcomponentStyled date-range variation (preset) based on the Preline "single calendar range" datepicker.
SmartDateRangeModalStandardcomponentThe date-range picker modal: a scrollable calendar of the months around today.
SmartDateRangeStandardcomponentThe default date-range rendering: a trigger showing the range and a clear button; the trigger opens <SmartDateRangeModalStandard>, rendered inline.
useDateRangeModalhookThe behaviour of the date-range modal: the scrollable calendar of the CalendarService, the picked range and the quick-pick buttons.
useDateRangehookThe 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.

PropTypeDefaultDescription
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.

PropTypeDefaultDescription
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.

PropTypeDefaultDescription
showFilterBtns?booleanfalseShows the quick-pick buttons (today, last 7 days, ...). Modal only.
restrictSelectionTo?number0When 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.

FieldTypeDefaultDescription
dateFrommoment.Moment | nullrequiredStart of the picked range.
dateTomoment.Moment | nullrequiredEnd of the picked range.
scrollPositionnumberrequiredScroll position of the modal's calendar, restored on reopening.
selectedButtonNameFilterBtnConstantsrequiredThe quick-pick button that produced the range.

DateRangeModalForm

The modal's form: the shown dates and the picked days.

FieldTypeDefaultDescription
dateFromstring | nullrequiredThe shown start date.
dateTostring | nullrequiredThe shown end date.
startDateRefmoment.Moment | nullrequiredThe picked start day.
endDateRefmoment.Moment | nullrequiredThe picked end day.
  • DateRangeVariantName: 'standard' \| 'preset' — The renderings SmartDateRange can pick.
  • FilterBtnConstants (enum): empthyString = '', today = 'Today', yesterday = 'Yesterday', lastSevenDays = 'LastSevenDays', lastThirtyDays = 'LastThirtyDays', thisMonth = 'ThisMonth', lastMonth = 'LastMonth' — The quick-pick buttons of the modal (the empthyString member is spelled that way in the code).

SmartAbstractControl is described in the react-forms and react-provider skills.

Binding

  • Controlled: value (IDateRange, null for empty) and onValueChange(range | undefined).
  • Uncontrolled: leave value undefined; the picker starts from defaultValue.
  • Form control: control={someControl} shows the control's value; a change sets it, marks the control dirty and touched, and still calls onValueChange.

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.

ReturnsTypeDescription
elementRefRefObject<HTMLDivElement | null>Attach to the scrollable calendar element.
calendarmonth[]The months of the CalendarService shown in the modal.
dateFormDateRangeModalFormThe shown dates and the picked days.
selectedButtonNameFilterBtnConstantsThe active quick pick.
onDayClick(date: moment.Moment | null) => voidPicks a start, then an end day.
isInRange(day: moment.Moment | null) => booleanWhether a day lies inside the picked range.
isSelectionStart(day: moment.Moment | null) => booleanWhether a day is the range start.
isSelectionEnd(day: moment.Moment | null) => booleanWhether a day is the range end.
isStartAndEndDateSame() => booleanWhether start and end are the same day.
isSelectionInRestrictedRange() => booleanWhether the range has exactly restrictSelectionTo days (always true without a restriction).
selectToday() => voidQuick pick: today.
selectYesterday() => voidQuick pick: yesterday.
selectLastSevenDays() => voidQuick pick: the last 7 days.
selectLastThirtyDays() => voidQuick pick: the last 30 days.
selectThisMonth() => voidQuick pick: this month.
selectLastMonth() => voidQuick pick: last month.
dismissPage() => void | undefinedCalls onDismiss.
applyDates() => voidCalls 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.

ReturnsTypeDescription
valueIDateRange | undefinedThe current range (controlled or internal), undefined when empty.
isOpenbooleanWhether the picker is open.
calendarDataCalendarStateThe CalendarState the picker reopens with.
onClick() => voidOpens the picker.
onModalApply(data: CalendarState) => voidApplies a picked CalendarState: sets the range, calls onValueChange and closes.
onModalDismiss() => voidCloses the picker without changing the range.
onClear() => voidClears 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

  • SmartDateRangeModalStandard is fixed positioned and rendered inline by the standard trigger; a backdrop click or its close button dismisses it.
  • Both variants carry smart:dark: variants; className is 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.