Installation

  1. Set up the project

    Once per project: the packages, Tailwind CSS, the theme tokens and the cn helper. Follow Installation.

  2. Copy the component into your project

    The kit owns behaviour, ARIA and data attributes. This file is the look, written with Tailwind classes, and it is yours to change.

    src/ui/date-picker.ts
    import type { Component } from "@effect/ui"
    import type { Html } from "@effect/ui/html"
    import type { DatePicker } from "@effect/ui-kit"
    import type { DateTime } from "effect"
    import { cn } from "#lib/cn"
    import { CalendarGrid, CalendarHeader, CalendarRoot } from "#ui/calendar"
    import { DateFieldInput, type DateFieldSize } from "#ui/date-field"
    
    /** What the kit's `DatePicker` passes to its `view` closure. */
    export type DatePickerParts = Component.Headless.Parts<typeof DatePicker>
    
    /**
     * The box around the input and its trigger. It isn't a kit part, so inside a
     * `Field` it can be the `focusWithin` wrapper: `field.focusWithin(DatePickerControl(h))`.
     */
    export const DatePickerControl = <Msg>(h: Html.H<Msg>, options: { readonly class?: string | undefined } = {}) =>
      h.div.class(cn("relative inline-flex w-44 items-center", options.class))
    
    /** The typed date, with room for the trigger. Inside a `Field`, pass `element: field.member(h.input)`. */
    export const DatePickerInput = <Msg>(
      h: Html.H<Msg>,
      datePicker: DatePickerParts,
      options: {
        readonly size?: DateFieldSize | undefined
        readonly class?: string | undefined
        readonly element?: Html.H<Msg>["input"] | undefined
      } = {}
    ) => DateFieldInput(h, datePicker, { ...options, class: cn("w-full pe-9", options.class) })
    
    /** The calendar button at the end of the input. */
    export const DatePickerTrigger = <Msg>(
      h: Html.H<Msg>,
      datePicker: DatePickerParts,
      options: { readonly class?: string | undefined } = {}
    ) =>
      datePicker.trigger(
        h.button.class(
          cn(
            "absolute end-1 inline-grid size-6.5 place-items-center rounded-sm text-muted-foreground " +
              "transition-colors duration-150 hover:bg-accent hover:text-foreground " +
              "data-[popup-open]:bg-accent data-[popup-open]:text-foreground " +
              "data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 data-[disabled]:hover:bg-transparent " +
              "[&_svg]:size-4",
            options.class
          )
        )
      ).children(
        h.el("svg")
          .attrs({ viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "aria-hidden": "true" })
          .children(
            h.el("path").attr(
              "d",
              "M8 2v4M16 2v4M3 10h18M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z"
            )
          )
      )
    
    /**
     * The popup, already inside its positioner. Children go in the popup:
     * `DatePickerPopup(h, datePicker).children(DatePickerCalendar(h, datePicker))`.
     * Name it with `.attr("aria-label", ...)`.
     */
    export const DatePickerPopup = <Msg>(
      h: Html.H<Msg>,
      datePicker: DatePickerParts,
      options: { readonly class?: string | undefined } = {}
    ) =>
      datePicker.popup(
        h.div.class(
          cn(
            "flex origin-[var(--transform-origin)] gap-3 rounded-lg border bg-popover p-3 shadow-float outline-none " +
              "transition-[opacity,scale] duration-150 starting:scale-95 starting:opacity-0",
            options.class
          )
        )
      ).forward((popup) => datePicker.positioner(h.div.class("z-50")).children(popup))
    
    /** The calendar of the popup: header and grid, as `#ui/calendar` draws them. */
    export const DatePickerCalendar = <Msg>(
      h: Html.H<Msg>,
      datePicker: DatePickerParts,
      options: {
        readonly unavailable?: ((date: DateTime.Utc) => boolean) | undefined
        readonly class?: string | undefined
      } = {}
    ) =>
      CalendarRoot(h, datePicker, { variant: "ghost", class: options.class }).children(
        CalendarHeader(h, datePicker),
        CalendarGrid(h, datePicker, { unavailable: options.unavailable })
      )
    
  3. Import it

    import { DatePickerControl, DatePickerInput, DatePickerTrigger, DatePickerPopup, DatePickerCalendar } from "#ui/date-picker"
    

Usage

Basic.ts
import { UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { DatePicker } from "@effect/ui-kit"
import { DateTime, Schema } from "effect"
import {
  DatePickerCalendar,
  DatePickerControl,
  DatePickerInput,
  DatePickerPopup,
  DatePickerTrigger
} from "#ui/date-picker"

const DatePickerBasicMessage = UiSchema.TaggedEnum({
  PickedDatePickerDate: { date: Schema.NullOr(Schema.DateTimeUtc) },
  RequestedOpenDatePicker: {},
  RequestedCloseDatePicker: {},
  RequestedDatePickerMonth: { month: Schema.DateTimeUtc }
})

const today = DateTime.makeUnsafe("2026-11-26T00:00:00Z")

export const DatePickerBasic = Html.component({
  name: "DatePickerBasic",
  model: Schema.Struct({
    date: Schema.NullOr(Schema.DateTimeUtc),
    month: Schema.DateTimeUtc,
    open: Schema.Boolean
  }),
  message: DatePickerBasicMessage
}).make({
  init: () => ({ date: today, month: today, open: false }),
  update: {
    PickedDatePickerDate: ($, { date }) => $.evolve({ date }),
    RequestedOpenDatePicker: ($) => $.evolve({ open: true }),
    RequestedCloseDatePicker: ($) => $.evolve({ open: false }),
    RequestedDatePickerMonth: ($, { month }) => $.evolve({ month })
  },
  view: (h, model) =>
    DatePicker(h, {
      props: { value: model.date, open: model.open, month: model.month, today, locale: "en-US", sideOffset: 6 },
      onEmit: {
        Picked: ({ date }) => DatePickerBasicMessage.PickedDatePickerDate({ date }),
        RequestedOpen: () => DatePickerBasicMessage.RequestedOpenDatePicker(),
        RequestedClose: () => DatePickerBasicMessage.RequestedCloseDatePicker(),
        RequestedMonth: ({ month }) => DatePickerBasicMessage.RequestedDatePickerMonth({ month })
      },
      view: (datePicker) =>
        DatePickerControl(h).children(
          DatePickerInput(h, datePicker).attr("aria-label", "Date"),
          DatePickerTrigger(h, datePicker),
          DatePickerPopup(h, datePicker).attr("aria-label", "Choose date").children(
            DatePickerCalendar(h, datePicker)
          )
        )
    })
})

Examples

In a field

A Field adds the label, a description and the consumer's error; focus may move into the popup.

Type a date or pick one from the calendar.

Bounded

min and max apply to the calendar and to typed dates.

Pickup is possible within the next 14 days.

With presets

Buttons in the popup write the date, the month and open in one update.

Disabled and read-only

Disabled suppresses everything; read-only still opens the calendar for browsing.

Disabled
Read-only

Anatomy

The parts the view closure receives. Apply each one to an element of your own.

PartDescription
inputThe <input>, the DateField's typed date. The popup anchors to it.
triggerThe <button> that opens and closes the popup.
positionerA <div>, a manual popover placed next to the input.
popupA <div> with role="dialog" inside the positioner. Give it an aria-label.
root, heading, previous, next, grid, weekday, cell, dayThe Calendar's parts, drawn inside the popup.
open, side, alignValues: whether the popup shows and where it ended up.
pattern, weeks, weekdays, month, titleValues of DateField and Calendar.

API reference

Props

PropTypeDescription
valueDateTime | nullThe date, or null for none.
openbooleanWhether the popup shows. Required and controlled.
monthDateTimeAny date in the month the calendar shows.
todayDateTimeThe current day.
min / maxDateTimeInclusive bounds for the calendar and for typed dates.
localestring | string[]The locale of the input and the calendar.
name / form / requiredstring / string / booleanAs DateField takes them.
disabledbooleanDisables the input, the trigger and the calendar.
readOnlybooleanThe popup opens for browsing, but nothing asks for a date.
side / align / sideOffsetPositioning optionsWhere the popup goes: bottom and start by default.

Events

EventDescription
Picked{ date }: a typed commit or a day press within the bounds; null when cleared.
RequestedOpen{ reason }: the trigger was pressed.
RequestedClose{ reason }: a day press, Escape, the trigger, an outside press or focus leaving.
RequestedMonth{ month }: calendar navigation, or a pick outside the shown month.

Data attributes

AttributeDescription
data-popup-openOn trigger: the popup is open.
data-open / data-closedOn positioner and popup.
data-side / data-alignOn positioner and popup: the placement after collisions.
data-disabled / data-readonlyOn trigger, input and the calendar's parts.
data-selected, data-today, ...On day, as Calendar lists them.

The components this page's file and examples import.

  • Button: A native button that can stay focusable while disabled.
  • Calendar: A controlled month grid for picking one date, with full keyboard navigation.
  • DateField: A text input that formats and parses a calendar date for a locale and commits it on blur or Enter.

effectcn is built with Effect UI and @effect/ui-kit. Not affiliated with Effectful Technologies.