@molecule/app-mini-calendar-angular

Feature · mini-calendar · App (browser) · v1.1.2 · Apache-2.0

Month-view calendar with day selection and prev/next navigation

npm install @molecule/app-mini-calendar-angular

npm · Source on GitHub

How it works

@molecule/app-mini-calendar-angular is a ready-made mini-calendar feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { Component } from '@angular/core'
import { MiniCalendar } from '@molecule/app-mini-calendar-angular'

@Component({
  selector: 'app-calendar',
  standalone: true,
  imports: [MiniCalendar],
  template: `<div
    mol-mini-calendar
    [selected]="selected"
    [locale]="'en-US'"
    [onSelect]="pick"
  ></div>`,
})
export class CalendarPage {
  selected = new Date(2026, 5, 15)
  pick = (date: Date) => {
    this.selected = date
    console.log(date.toISOString())
  }
}

Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular

Reference

Angular mini month-view calendar.

Exports MiniCalendar — compact day picker with prev/next navigation, Intl-localized weekday + month names, controlled-optional selected + month inputs, and an isDisabled day predicate. It is the Angular counterpart of @molecule/app-mini-calendar-react: same props (React names), same DOM for the same input, same ClassMap tokens and the same callbacks.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { Component } from '@angular/core'
import { MiniCalendar } from '@molecule/app-mini-calendar-angular'

@Component({
  selector: 'app-calendar',
  standalone: true,
  imports: [MiniCalendar],
  template: `<div
    mol-mini-calendar
    [selected]="selected"
    [locale]="'en-US'"
    [onSelect]="pick"
  ></div>`,
})
export class CalendarPage {
  selected = new Date(2026, 5, 15)
  pick = (date: Date) => {
    this.selected = date
    console.log(date.toISOString())
  }
}

Type

feature

Installation

npm install @molecule/app-mini-calendar-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

MiniCalendarProps

Props accepted by MiniCalendar — the same props @molecule/app-mini-calendar-react accepts.

interface MiniCalendarProps {
  /** Controlled selected date (ISO yyyy-mm-dd or Date). */
  selected?: Date | string
  /** Called when the user picks a day. */
  onSelect?: (date: Date) => void
  /** Controlled visible month. If omitted the component tracks its own. */
  month?: Date
  /** Called when the user navigates months. */
  onMonthChange?: (date: Date) => void
  /**
   * Locale for weekday + month name formatting. Defaults to the app's active
   * locale, which follows a locale switch; an explicit `locale` still wins.
   */
  locale?: string
  /** Optional day-disabled predicate. */
  isDisabled?: (date: Date) => boolean
  /** Extra classes. */
  className?: string
}

Classes

MiniCalendar

Compact month-view calendar (React parity).

The host IS React's root <div> (div[mol-mini-calendar]), carrying the stack class plus className. Supports controlled selected + month props or runs uncontrolled: the visible month is read once at init and tracked internally when month is omitted. Weekday / month names come from Intl.DateTimeFormat in the locale input, or the app's active locale when it is omitted. The prev/next buttons' aria-labels go through t() (miniCalendar.aria.*, English defaultValues). The 6×7 grid starts on the Sunday before the 1st; days outside the visible month render dimmed through the inline opacity style and stay clickable unless isDisabled filters them.

@Component({
  selector: 'div[mol-mini-calendar]',
  standalone: true,
  imports: [Button],
  inputs: ['selected', 'onSelect', 'month', 'onMonthChange', 'locale', 'isDisabled', 'className'],
  host: {
    '[class]': 'classes()',
  },
  // prettier-ignore
  template: `<header [class]="headerClasses()"><button mol-button [variant]="'ghost'" [size]="'sm'" [attr.aria-label]="previousLabel()" (click)="navigate(-1)">‹</button><span [class]="monthClasses()">{{ monthLabel() }}</span><button mol-button [variant]="'ghost'" [size]="'sm'" [attr.aria-label]="nextLabel()" (click)="navigate(1)">›</button></header><div [class]="gridClasses()">@for (d of weekdayHeader(); track $index) {<span [class]="weekdayClasses()">{{ weekdayLabel(d) }}</span>}@for (d of days(); track $index) {<button type="button" (click)="selectDay(d)" [disabled]="disabled(d)" [attr.aria-current]="isSelected(d) ? 'date' : null" [class]="dayClasses(d)" [attr.style]="outOfMonth(d) ? 'opacity: 0.3' : null">{{ d.getDate() }}</button>}</div>`,
})
export class MiniCalendar implements OnInit, MiniCalendarProps {
  /** Controlled selected date (ISO yyyy-mm-dd or Date). */
  selected?: Date | string
  /** Called when the user picks a day. */
  onSelect?: (date: Date) => void
  /** Controlled visible month. If omitted the component tracks its own. */
  month?: Date
  /** Called when the user navigates months. */
  onMonthChange?: (date: Date) => void
  /** Locale for weekday + month name formatting (see `MiniCalendarProps.locale`). */
  locale?: string
  /** Optional day-disabled predicate. */
  isDisabled?: (date: Date) => boolean
  /** Extra classes on the root element. */
  className?: string

  /** The internally tracked visible month (uncontrolled mode). */
  private readonly internalMonth = signal<Date | null>(null)

  /** The i18n handle (locale-reactive), read in an injection context. */
  private readonly i18n = useTranslation()

  /** The app's active locale — the default when the `locale` input is unset. */
  private readonly activeLocale = useLocale()

  /**
   * Reads the initial visible month once — React's `useState` semantics.
   */
  ngOnInit(): void {
    this.internalMonth.set(startOfMonth(this.month ?? this.selectedDate() ?? new Date()))
  }

  /**
   * The current class map.
   * @returns The UIClassMap.
   */
  cm(): UIClassMap {
    return getClassMap()
  }

  /**
   * The root class list (stack plus `className`).
   * @returns The class string.
   */
  classes(): string {
    return this.cm().cn(this.cm().stack(2), this.className)
  }

  /**
   * The header row class list (between / center / small gap).
   * @returns The class string.
   */
  headerClasses(): string {
    return this.cm().flex({ justify: 'between', align: 'center', gap: 'sm' })
  }

  /**
   * The month label class list.
   * @returns The class string.
   */
  monthClasses(): string {
    return this.cm().cn(this.cm().textSize('sm'), this.cm().fontWeight('semibold'))
  }

  /**
   * The grid class list (7 columns, extra-small gap).
   * @returns The class string.
   */
  gridClasses(): string {
    return this.cm().grid({ cols: 7, gap: 'xs' })
  }

  /**
   * A weekday header cell's class list.
   * @returns The class string.
   */
  weekdayClasses(): string {
    return this.cm().cn(
      this.cm().textSize('xs'),
      this.cm().fontWeight('semibold'),
      this.cm().textCenter,
    )
  }

  /**
   * One day button's class list (selected days are bold, others medium).
   * @param d - The day.
   * @returns The class string.
   */
  dayClasses(d: Date): string {
    const cm = this.cm()
    return cm.cn(
      cm.textSize('xs'),
      cm.sp('py', 1),
      cm.textCenter,
      cm.roundedFull,
      this.isSelected(d) ? cm.fontWeight('bold') : cm.fontWeight('medium'),
    )
  }

  /**
   * The selected date, coerced from the `selected` prop.
   * @returns The date, or undefined.
   */
  selectedDate(): Date | undefined {
    return toDate(this.selected)
  }

  /**
   * The visible month: the controlled prop, else the internal month.
   * @returns The first day of the visible month.
   */
  visibleMonth(): Date {
    if (this.month) return startOfMonth(this.month)
    return this.internalMonth() ?? startOfMonth(new Date())
  }

  /**
   * The locale the names format in: the `locale` input, else the app's active
   * locale (which follows a locale switch).
   * @returns The locale code.
   */
  resolvedLocale(): string {
    return this.locale ?? this.activeLocale()
  }

  /**
   * The visible month's formatted name.
   * @returns The month and year text (`March 2026`).
   */
  monthLabel(): string {
    return new Intl.DateTimeFormat(this.resolvedLocale(), {
      month: 'long',
      year: 'numeric',
    }).format(this.visibleMonth())
  }

  /**
   * A weekday header cell's narrow name.
   * @param d - The day.
   * @returns The narrow weekday text.
   */
  weekdayLabel(d: Date): string {
    return new Intl.DateTimeFormat(this.resolvedLocale(), { weekday: 'narrow' }).format(d)
  }

  /**
   * The previous-month button's aria-label (prop > `t()` > default).
   * @returns The label text.
   */
  previousLabel(): string {
    return this.i18n.t('miniCalendar.aria.previousMonth', undefined, {
      defaultValue: 'Previous month',
    })
  }

  /**
   * The next-month button's aria-label (prop > `t()` > default).
   * @returns The label text.
   */
  nextLabel(): string {
    return this.i18n.t('miniCalendar.aria.nextMonth', undefined, { defaultValue: 'Next month' })
  }

  /**
   * The 42 days of the grid, starting on the Sunday before the 1st.
   * @returns The days, in render order.
   */
  days(): Date[] {
    const visible = this.visibleMonth()
    const first = startOfMonth(visible)
    const gridStart = new Date(first)
    gridStart.setDate(1 - first.getDay())
    const out: Date[] = []
    for (let i = 0; i < 42; i++) {
      const d = new Date(gridStart)
      d.setDate(gridStart.getDate() + i)
      out.push(d)
    }
    return out
  }

  /**
   * The first week of the grid (the weekday header).
   * @returns Seven days.
   */
  weekdayHeader(): Date[] {
    return this.days().slice(0, 7)
  }

  /**
   * Whether the day falls outside the visible month (React dims it).
   * @param d - The day.
   * @returns True when the day is outside the visible month.
   */
  outOfMonth(d: Date): boolean {
    return d.getMonth() !== this.visibleMonth().getMonth()
  }

  /**
   * Whether the day is the selected one.
   * @param d - The day.
   * @returns True when selected.
   */
  isSelected(d: Date): boolean {
    const selected = this.selectedDate()
    return !!selected && isSameDay(d, selected)
  }

  /**
   * Whether the day is disabled by the predicate.
   * @param d - The day.
   * @returns True when disabled.
   */
  disabled(d: Date): boolean {
    return this.isDisabled?.(d) ?? false
  }

  /**
   * Picks a day (React's `onClick`): disabled days are ignored.
   * @param d - The clicked day.
   */
  selectDay(d: Date): void {
    if (this.disabled(d)) return
    this.onSelect?.(d)
  }

  /**
   * Advances the visible month by the given number of months (negative to go back).
   * @param delta - Months to advance.
   */
  navigate(delta: number): void {
    const current = this.visibleMonth()
    const next = new Date(current.getFullYear(), current.getMonth() + delta, 1)
    if (!this.month) this.internalMonth.set(next)
    this.onMonthChange?.(next)
  }
}

Injection Notes

Requirements

Peer dependencies:

  • @angular/common ^22.0.0
  • @angular/core ^22.0.0
  • @angular/platform-browser ^22.0.0
  • @molecule/app-angular ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-angular ^1.1.0

Runtime Dependencies

  • @angular/common
  • @angular/core
  • @angular/platform-browser
  • @molecule/app-angular
  • @molecule/app-ui
  • @molecule/app-ui-angular

Requires a wired ClassMap bond (setClassMap(...) at startup) — getClassMap() throws before wiring, and the prev/next buttons come from @molecule/app-ui-angular.

Weekday and month names come from Intl.DateTimeFormat(locale) — an explicit locale input wins, otherwise the app's active locale, so they follow a locale switch. The prev/next buttons' aria-labels go through t() (miniCalendar.aria.previousMonth / miniCalendar.aria.nextMonth, English defaultValues); translations live in the @molecule/app-locales-mini-calendar bond.

When month is supplied the visible month is fully controlled — wire onMonthChange too or the arrows will appear dead. The grid always renders 6 weeks; days outside the visible month render dimmed and remain clickable unless isDisabled filters them.

Translations

Translation strings are provided by @molecule/app-locales-mini-calendar.