Components

Calendar

A month of days to pick from, one day or a start and an end, with its months and years a press away.

Previews are drawn in the theme you made.

Edit it
size
outside
detail
scheme
direction

A day #

Sun
Mon
Tue
Wed
Thu
Fri
Sat
import { Bundles, Calendar, CalendarSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { today } from '../../snippets/today.js'

// The Bundle holds the month shown and the selection; `model.selection` is
// read with `Calendar.selectedDate`. One day is the default mode.
export default example({
  title: 'A day',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  state: Bundles.Calendar.with({ id: 'delivery', today, minDate: today }),
  view: ({ style, model, onMessage, h }) =>
    Calendar.view({ model, onMessage, label: 'Delivery day', style }, h),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

A range over two months, with presets #

Sun
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Mon
Tue
Wed
Thu
Fri
Sat
import { Bundles, Calendar, CalendarSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { today } from '../../snippets/today.js'

// The mode is the `selection` arg's tag. Two months page from their outer
// ends, a range previews under the pointer, and a preset is one press.
export default example({
  title: 'A range over two months, with presets',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  state: Bundles.Calendar.with({
    id: 'trip',
    today,
    selection: Calendar.empty('Range'),
    months: 2,
  }),
  view: ({ style, model, onMessage, h }) =>
    Calendar.view(
      {
        model,
        onMessage,
        label: 'Trip dates',
        presets: [
          { label: 'Last 7 days', selection: Calendar.lastDays(today, 7) },
          { label: 'Next 7 days', selection: Calendar.nextDays(today, 7) },
          { label: 'This month', selection: Calendar.monthOf(today) },
        ],
        style,
      },
      h,
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Sun
Mon
Tue
Wed
Thu
Fri
Sat
import { Bundles, Calendar, CalendarSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { today } from '../../snippets/today.js'

// Each of these is data on the view: a caption of two selects, a column of
// week numbers, and a button back to today that also picks it.
export default example({
  title: 'Month and year selects, week numbers, a Today button',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  state: Bundles.Calendar.with({ id: 'birthday', today }),
  view: ({ style, model, onMessage, h }) =>
    Calendar.view(
      {
        model,
        onMessage,
        label: 'Date of birth',
        caption: { dropdowns: { years: { from: today.year - 100, to: today.year } } },
        weekNumbers: true,
        today: { label: 'Today', selects: true },
        style,
      },
      h,
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Presets of your own #

Sun
Mon
Tue
Wed
Thu
Fri
Sat
import { Option } from 'effect'
import { Calendar as Dates } from 'foldkit'
import { Bundles, Calendar, CalendarSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { today } from '../../snippets/today.js'

// A preset is data: a label and a `Calendar.Selection`. These are the
// application's own, written from the published date helpers.
const weekendOf = (day: Dates.CalendarDate): Calendar.Selection => {
  const sunday = Dates.endOfWeek(day, 'Monday')
  return Calendar.Selection.Range({
    start: Option.some(Dates.addDays(sunday, -1)),
    end: Option.some(sunday),
  })
}
const presets: ReadonlyArray<Calendar.Preset> = [
  { label: 'This weekend', selection: weekendOf(today) },
  { label: 'Next weekend', selection: weekendOf(Dates.addDays(today, 7)) },
  { label: 'Next month', selection: Calendar.monthOf(today, 1) },
]

export default example({
  title: 'Presets of your own',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  state: Bundles.Calendar.with({ id: 'getaway', today, selection: Calendar.empty('Range') }),
  view: ({ style, model, onMessage, h }) =>
    Calendar.view({ model, onMessage, label: 'Getaway', presets, style }, h),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Composed: a day and a time #

Sun
Mon
Tue
Wed
Thu
Fri
Sat
import { Option, Schema } from 'effect'
import { Bundle } from 'foldkit-bundle'
import { modifyFields } from 'foldkit/struct'
import { Bundles, Button, Calendar, CalendarSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { stack } from '../../snippets/layout.js'
import { today } from '../../snippets/today.js'

const times = ['09:00', '10:30', '13:00', '15:30']
const TimeStyle = Recipes.Button.style({ tone: 'neutral', variant: 'outline' })

// The time is a fact of its own, so it is the application's field and its
// own buttons, and the calendar only places them, in `aside`.
const App = Bundle.compose({ time: Schema.Option(Schema.String) }).pipe(
  Bundle.withMessages({ PickedTime: { time: Schema.String } }),
  Bundle.withChild('day', Bundles.Calendar, {
    args: { id: 'appointment', today, minDate: today, disabledDaysOfWeek: ['Saturday', 'Sunday'] },
    onOut: Bundle.ignore,
  }),
)

export default example({
  title: 'Composed: a day and a time',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  state: App.placements.runtime({
    Model: App.Model,
    initial: { time: Option.none() },
    update: App.placements.update((model, { time }) => ({
      model: modifyFields(model, { time: () => Option.some(time) }),
    })),
  }),
  view: ({ style, model, onMessage, h }) =>
    Calendar.view(
      {
        model: model.day,
        onMessage: message => onMessage(App.Message.GotDayMessage({ message })),
        label: 'Appointment',
        aside: stack(
          h,
          times.map(time =>
            Button.view(
              {
                label: time,
                pressed: Option.contains(model.time, time),
                onClick: onMessage(App.Message.PickedTime({ time })),
                style: TimeStyle,
              },
              h,
            ),
          ),
          [h.Role('group'), h.AriaLabel('Time')],
        ),
        style,
      },
      h,
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Weekends, booked days and bounds #

Sun
Mon
Tue
Wed
Thu
Fri
Sat

Weekends and booked days are closed; book up to two months ahead.

import { Option } from 'effect'
import { Calendar as Dates } from 'foldkit'
import { Bundles, Calendar, CalendarSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { note } from '../../snippets/layout.js'
import { today } from '../../snippets/today.js'

// Days already taken, from the day the page was loaded.
const booked = [1, 2, 8, 9, 15, 22].map(days => Dates.addDays(today, days))

// The bounds and the closed days are the calendar's own: it draws them
// disabled and its keys skip them.
export default example({
  title: 'Weekends, booked days and bounds',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  state: Bundles.Calendar.with({
    id: 'unavailable',
    today,
    minDate: today,
    maxDate: Dates.addDays(today, 60),
    disabledDaysOfWeek: ['Saturday', 'Sunday'],
    disabledDates: booked,
  }),
  view: ({ style, model, onMessage, h }) =>
    Calendar.view(
      {
        model,
        onMessage,
        label: 'Delivery day',
        footer: note(h, [
          Option.match(Calendar.firstDate(model.selection), {
            onNone: () => 'Weekends and booked days are closed; book up to two months ahead.',
            onSome: date => `Delivery on ${Dates.formatLong(date, Dates.defaultEnglishLocale)}.`,
          }),
        ]),
        style,
      },
      h,
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Several days #

Sun
Mon
Tue
Wed
Thu
Fri
Sat

0 days chosen

import { Option } from 'effect'
import { Bundles, Button, Calendar, CalendarSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { note, row } from '../../snippets/layout.js'
import { today } from '../../snippets/today.js'

const ClearStyle = Recipes.Button.style({ tone: 'neutral', variant: 'outline', size: 'sm' })

// Any number of days: each press adds a day or takes it away again. Clearing
// is a pick of the empty selection, sent as the Calendar's own Message.
export default example({
  title: 'Several days',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  state: Bundles.Calendar.with({ id: 'several', today, selection: Calendar.empty('Multiple') }),
  view: ({ style, model, onMessage, h }) => {
    const count = Calendar.Selection.match(model.selection, {
      Single: ({ date }) => (Option.isSome(date) ? 1 : 0),
      Range: () => 0,
      Multiple: ({ dates }) => dates.length,
    })
    return Calendar.view(
      {
        model,
        onMessage,
        label: 'Days off',
        footer: row(h, [
          note(h, [count === 1 ? '1 day chosen' : `${count} days chosen`]),
          Button.view(
            {
              label: 'Clear',
              disabled: count === 0,
              onClick: onMessage(
                Calendar.Message.PickedPreset({ selection: Calendar.empty('Multiple') }),
              ),
              style: ClearStyle,
            },
            h,
          ),
        ]),
        style,
      },
      h,
    )
  },
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

A price on each day #

December 2026
Sun
Mon
Tue
Wed
Thu
Fri
Sat

Pick a check-in day, then a check-out day.

import { Option } from 'effect'
import { Calendar as Dates } from 'foldkit'
import { Bundles, Calendar, CalendarSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { note } from '../../snippets/layout.js'
import { today } from '../../snippets/today.js'

/** A night's price: dearer at the weekend, and varying through the month. */
const priceOf = (date: Dates.CalendarDate): number => {
  const weekend = ['Friday', 'Saturday'].includes(Dates.dayOfWeek(date))
  return 89 + (weekend ? 40 : 0) + ((date.day * 7) % 5) * 6
}

/** The nights from check-in to check-out, and what they cost together. */
const stayOf = (stay: Calendar.Selection): Option.Option<{ nights: number; total: number }> =>
  Option.flatMap(Calendar.rangeOf(stay), ({ start, end }) => {
    const nights = Math.max(1, Dates.daysUntil(start, end))
    const total = Array.from({ length: nights }, (_, night) =>
      priceOf(Dates.addDays(start, night)),
    ).reduce((sum, price) => sum + price, 0)
    return Option.some({ nights, total })
  })

// `detail` writes a line under each day's number; the recipe is pinned to
// `detail: 'text'`, a taller cell to hold it. A range previews under the pointer.
export default example({
  title: 'A price on each day',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  pins: { detail: 'text' },
  state: Bundles.Calendar.with({ id: 'prices', today, selection: Calendar.empty('Range') }),
  view: ({ style, model, onMessage, h }) =>
    Calendar.view(
      {
        model,
        onMessage,
        label: 'Stay',
        caption: 'label',
        // A day that can be booked shows its night's price; the past shows none.
        detail: date =>
          Option.liftPredicate(date, () => !Dates.isBefore(date, today)).pipe(
            Option.map(night => `$${priceOf(night)}`),
          ),
        footer: note(h, [
          Option.match(stayOf(model.selection), {
            onNone: () => 'Pick a check-in day, then a check-out day.',
            onSome: ({ nights, total }) =>
              `${nights} ${nights === 1 ? 'night' : 'nights'} · $${total} in all`,
          }),
        ]),
        style,
      },
      h,
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Events and a Today button #

Sun
Mon
Tue
Wed
Thu
Fri
Sat

December 1, 2026

Design review
10:00 – 11:00
Lunch with Sam
12:30
import { Option } from 'effect'
import { Calendar as Dates } from 'foldkit'
import { Bundles, Calendar, CalendarSlots, Item, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { note, stack } from '../../snippets/layout.js'
import { today } from '../../snippets/today.js'

const EventStyle = Recipes.Item.style({ density: 'compact' })

/** A few events, days from the day the page was loaded. */
const EVENTS = [
  { in: 0, title: 'Design review', time: '10:00 – 11:00' },
  { in: 0, title: 'Lunch with Sam', time: '12:30' },
  { in: 2, title: 'Sprint planning', time: '09:30 – 10:30' },
  { in: 5, title: 'Dentist', time: '16:00' },
  { in: 9, title: 'Team offsite', time: 'All day' },
  { in: 9, title: 'Dinner', time: '19:00' },
  { in: 13, title: 'Release', time: '15:00' },
]

const eventsOn = (date: Dates.CalendarDate) =>
  EVENTS.filter(each => Dates.isEqual(Dates.addDays(today, each.in), date))

// The day's events are a dot under its number (`detail`, the recipe pinned to
// `detail: 'dot'`), and the list beside the month is the placement's `aside`.
export default example({
  title: 'Events and a Today button',
  slots: CalendarSlots,
  recipe: Recipes.Calendar,
  pins: { detail: 'dot' },
  state: Bundles.Calendar.with({ id: 'events', today }),
  view: ({ style, model, onMessage, h }) => {
    const day = Option.getOrElse(Calendar.firstDate(model.selection), () => today)
    const events = eventsOn(day)
    return Calendar.view(
      {
        model,
        onMessage,
        label: 'Events',
        today: { label: 'Today', selects: false },
        detail: date => {
          const count = eventsOn(date).length
          return Option.liftPredicate(count === 1 ? '1 event' : `${count} events`, () => count > 0)
        },
        aside: stack(h, [
          note(h, [Dates.formatLong(day, Dates.defaultEnglishLocale)]),
          ...(events.length === 0
            ? [note(h, ['Nothing planned.'])]
            : events.map(event =>
                Item.view({ title: event.title, description: event.time, style: EventStyle }, h),
              )),
        ]),
        style,
      },
      h,
    )
  },
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Usage

Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.

The recipe ↗This code ↗