> ## Documentation Index
> Fetch the complete documentation index at: https://prefab.prefect.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Calendar

> Date selection calendar with single, multiple, and range modes.

export const ComponentPreview = ({json, height, resizable, bare, hideJson, playground, children}) => {
  const hostRef = React.useRef(null);
  const handleRef = React.useRef(null);
  const cardRef = React.useRef(null);
  const containerRef = React.useRef(null);
  const [previewWidth, setPreviewWidth] = React.useState(null);
  const [isDragging, setIsDragging] = React.useState(false);
  const [playgroundHref, setPlaygroundHref] = React.useState(null);
  React.useEffect(function () {
    if (!playground) return;
    var isLocal = location.hostname === "localhost" || location.hostname === "127.0.0.1";
    var path = isLocal ? "/playground" : "/docs/playground";
    var url = new URL(path, window.location.href);
    url.hash = "code=" + playground;
    setPlaygroundHref(url.href);
  }, [playground]);
  var jsonStr = typeof json === "string" ? json : JSON.stringify(json, null, 2);
  React.useEffect(function () {
    if (cardRef.current) {
      var card = cardRef.current.closest(".group");
      if (card) card.classList.remove("group");
    }
    var host = hostRef.current;
    if (!host || !json) return;
    function mount() {
      if (!window.__prefab || !host) return;
      var dark = document.documentElement.classList.contains("dark");
      handleRef.current = window.__prefab.mountPreview(host, jsonStr, {
        dark: dark
      });
      if (bare && host.shadowRoot) {
        var m = host.shadowRoot.querySelector("[data-prefab-mount]");
        if (m) m.style.background = "transparent";
      }
    }
    if (window.__prefab) {
      mount();
    } else {
      if (!window.__prefabLoading) {
        if (!window.__prefabReady) {
          var s = document.createElement("script");
          s.src = "/renderer.js";
          document.head.appendChild(s);
        }
        window.__prefabLoading = new Promise(function (resolve) {
          function check() {
            if (window.__prefabReady) {
              window.__prefabReady.then(resolve);
            } else {
              setTimeout(check, 10);
            }
          }
          check();
        });
      }
      window.__prefabLoading.then(mount);
    }
    var observer = new MutationObserver(function () {
      var dark = document.documentElement.classList.contains("dark");
      if (handleRef.current) handleRef.current.setDark(dark);
    });
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return function () {
      observer.disconnect();
      if (handleRef.current) {
        handleRef.current.unmount();
        handleRef.current = null;
      }
    };
  }, [json]);
  function startResize(e) {
    e.preventDefault();
    var startX = e.clientX;
    var startW = hostRef.current ? hostRef.current.offsetWidth : 0;
    var maxW = containerRef.current ? containerRef.current.offsetWidth - 10 : startW;
    setIsDragging(true);
    function onMove(ev) {
      var w = Math.max(260, Math.min(startW + (ev.clientX - startX), maxW));
      setPreviewWidth(w);
    }
    function onUp() {
      document.removeEventListener("mousemove", onMove);
      document.removeEventListener("mouseup", onUp);
      setIsDragging(false);
    }
    document.addEventListener("mousemove", onMove);
    document.addEventListener("mouseup", onUp);
  }
  if (bare) {
    return <div ref={hostRef} />;
  }
  if (resizable) {
    return <Card>
        <div ref={cardRef} />
        <div ref={containerRef} style={{
      display: "flex",
      position: "relative",
      overflow: "hidden"
    }}>
          <div ref={hostRef} style={{
      flex: previewWidth ? "none" : 1,
      width: previewWidth ? previewWidth + "px" : undefined,
      minWidth: 0
    }} />
          <div onMouseDown={startResize} style={{
      width: "14px",
      flexShrink: 0,
      cursor: "col-resize",
      background: isDragging ? "var(--border, #e5e7eb)" : "color-mix(in srgb, var(--border, #e5e7eb) 40%, transparent)",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      transition: "background 0.15s",
      userSelect: "none"
    }}>
            <svg width="6" height="24" style={{
      opacity: 0.5
    }}>
              <circle cx="2" cy="4" r="1.2" fill="currentColor" />
              <circle cx="2" cy="9" r="1.2" fill="currentColor" />
              <circle cx="2" cy="14" r="1.2" fill="currentColor" />
              <circle cx="2" cy="19" r="1.2" fill="currentColor" />
              <circle cx="5" cy="4" r="1.2" fill="currentColor" />
              <circle cx="5" cy="9" r="1.2" fill="currentColor" />
              <circle cx="5" cy="14" r="1.2" fill="currentColor" />
              <circle cx="5" cy="19" r="1.2" fill="currentColor" />
            </svg>
          </div>
          <div style={{
      flex: previewWidth ? 1 : "0 0 24px",
      minWidth: "24px",
      background: "repeating-linear-gradient(-45deg, transparent, transparent 3px, var(--border, #e5e7eb) 3px, var(--border, #e5e7eb) 4px)",
      opacity: 0.4
    }} />
          {previewWidth && <div style={{
      position: "absolute",
      bottom: "8px",
      right: "8px",
      background: "var(--background, white)",
      border: "1px solid var(--border, #e5e7eb)",
      borderRadius: "4px",
      padding: "1px 6px",
      fontSize: "11px",
      fontFamily: "monospace",
      color: "var(--muted-foreground, #6b7280)",
      pointerEvents: "none"
    }}>
              {previewWidth}px
            </div>}
        </div>
        {playgroundHref && <div style={{
      display: "flex",
      justifyContent: "flex-end",
      padding: "4px 0 8px"
    }}>
            <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
      fontSize: "11px",
      opacity: 0.4,
      textDecoration: "none",
      textDecorationLine: "none",
      borderBottom: "none",
      boxShadow: "none",
      display: "inline-flex",
      alignItems: "center",
      gap: "3px",
      transition: "opacity 0.15s",
      fontWeight: 400
    }} onMouseOver={function (e) {
      e.currentTarget.style.opacity = "0.6";
    }} onMouseOut={function (e) {
      e.currentTarget.style.opacity = "0.4";
    }}>
              Edit in Playground
              <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
            </a>
          </div>}
        <div style={{
      marginBottom: "-2rem"
    }}>{children}</div>
      </Card>;
  }
  return <Card>
      <div ref={cardRef} />
      <div ref={hostRef} />
      {playgroundHref && <div style={{
    display: "flex",
    justifyContent: "flex-end",
    padding: "4px 0 8px"
  }}>
          <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
    fontSize: "11px",
    opacity: 0.4,
    textDecoration: "none",
    textDecorationLine: "none",
    borderBottom: "none",
    boxShadow: "none",
    display: "inline-flex",
    alignItems: "center",
    gap: "3px",
    transition: "opacity 0.15s",
    fontWeight: 400
  }} onMouseOver={function (e) {
    e.currentTarget.style.opacity = "0.6";
  }} onMouseOut={function (e) {
    e.currentTarget.style.opacity = "0.4";
  }}>
            Edit in Playground
            <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
          </a>
        </div>}
      <div style={{
    marginBottom: "-2rem"
  }}>{children}</div>
    </Card>;
};

The Calendar component renders a month view for selecting dates. It supports single date, multiple date, and date range selection. Selected dates are stored in client state as ISO strings.

## Basic Usage

<ComponentPreview json={{"view":{"name":"calendar_1","type":"Calendar","mode":"single"}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQ2FsZW5kYXIKCkNhbGVuZGFyKCkK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Calendar

    Calendar()
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {"view": {"name": "calendar_1", "type": "Calendar", "mode": "single"}}
    ```
  </CodeGroup>
</ComponentPreview>

## Initial Value

Pass a `datetime.date` to `value` to pre-select a date:

<ComponentPreview json={{"view":{"name":"calendar_2","value":"2026-07-04T12:00:00.000Z","type":"Calendar","mode":"single"},"state":{"calendar_2":"2026-07-04T12:00:00.000Z"}}} playground="aW1wb3J0IGRhdGV0aW1lCmZyb20gcHJlZmFiX3VpLmNvbXBvbmVudHMgaW1wb3J0IENhbGVuZGFyCgpDYWxlbmRhcih2YWx1ZT1kYXRldGltZS5kYXRlKDIwMjYsIDcsIDQpKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    import datetime
    from prefab_ui.components import Calendar

    Calendar(value=datetime.date(2026, 7, 4))
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "name": "calendar_2",
        "value": "2026-07-04T12:00:00.000Z",
        "type": "Calendar",
        "mode": "single"
      },
      "state": {"calendar_2": "2026-07-04T12:00:00.000Z"}
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Range Selection

Set `mode="range"` to let users select a start and end date. The value is a dict with `"from"` and `"to"` keys:

<ComponentPreview json={{"view":{"name":"calendar_3","value":"{\"from\": \"2025-06-10T12:00:00.000Z\", \"to\": \"2025-06-20T12:00:00.000Z\"}","type":"Calendar","mode":"range"},"state":{"calendar_3":"{\"from\": \"2025-06-10T12:00:00.000Z\", \"to\": \"2025-06-20T12:00:00.000Z\"}"}}} playground="aW1wb3J0IGRhdGV0aW1lCmZyb20gcHJlZmFiX3VpLmNvbXBvbmVudHMgaW1wb3J0IENhbGVuZGFyCgpDYWxlbmRhcigKICAgIG1vZGU9InJhbmdlIiwKICAgIHZhbHVlPXsKICAgICAgICAiZnJvbSI6IGRhdGV0aW1lLmRhdGUoMjAyNSwgNiwgMTApLAogICAgICAgICJ0byI6IGRhdGV0aW1lLmRhdGUoMjAyNSwgNiwgMjApLAogICAgfSwKKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    import datetime
    from prefab_ui.components import Calendar

    Calendar(
        mode="range",
        value={
            "from": datetime.date(2025, 6, 10),
            "to": datetime.date(2025, 6, 20),
        },
    )
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "name": "calendar_3",
        "value": "{\"from\": \"2025-06-10T12:00:00.000Z\", \"to\": \"2025-06-20T12:00:00.000Z\"}",
        "type": "Calendar",
        "mode": "range"
      },
      "state": {
        "calendar_3": "{\"from\": \"2025-06-10T12:00:00.000Z\", \"to\": \"2025-06-20T12:00:00.000Z\"}"
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Multiple Selection

Select multiple individual dates with `mode="multiple"`. The value is a list of dates:

<ComponentPreview json={{"view":{"name":"calendar_4","value":"[\"2025-06-10T12:00:00.000Z\", \"2025-06-15T12:00:00.000Z\", \"2025-06-22T12:00:00.000Z\"]","type":"Calendar","mode":"multiple"},"state":{"calendar_4":"[\"2025-06-10T12:00:00.000Z\", \"2025-06-15T12:00:00.000Z\", \"2025-06-22T12:00:00.000Z\"]"}}} playground="aW1wb3J0IGRhdGV0aW1lCmZyb20gcHJlZmFiX3VpLmNvbXBvbmVudHMgaW1wb3J0IENhbGVuZGFyCgpDYWxlbmRhcigKICAgIG1vZGU9Im11bHRpcGxlIiwKICAgIHZhbHVlPVsKICAgICAgICBkYXRldGltZS5kYXRlKDIwMjUsIDYsIDEwKSwKICAgICAgICBkYXRldGltZS5kYXRlKDIwMjUsIDYsIDE1KSwKICAgICAgICBkYXRldGltZS5kYXRlKDIwMjUsIDYsIDIyKSwKICAgIF0sCikK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    import datetime
    from prefab_ui.components import Calendar

    Calendar(
        mode="multiple",
        value=[
            datetime.date(2025, 6, 10),
            datetime.date(2025, 6, 15),
            datetime.date(2025, 6, 22),
        ],
    )
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "name": "calendar_4",
        "value": "[\"2025-06-10T12:00:00.000Z\", \"2025-06-15T12:00:00.000Z\", \"2025-06-22T12:00:00.000Z\"]",
        "type": "Calendar",
        "mode": "multiple"
      },
      "state": {
        "calendar_4": "[\"2025-06-10T12:00:00.000Z\", \"2025-06-15T12:00:00.000Z\", \"2025-06-22T12:00:00.000Z\"]"
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Reading the Value

Use `.rx` to get a reactive reference to the calendar's current selection. What `.rx` holds depends on the mode: an ISO date string for single mode, a `{"from": ..., "to": ...}` object for range mode, or an array of ISO strings for multiple mode. The `.date()` pipe formats a single ISO string for display:

<ComponentPreview json={{"view":{"cssClass":"gap-6","type":"Row","children":[{"name":"calendar_5","value":"2026-07-04T12:00:00.000Z","type":"Calendar","mode":"single"},{"cssClass":"gap-2 justify-center","type":"Column","children":[{"type":"Label","text":"Selected date","optional":false},{"name":"input_1","value":"{{ calendar_5 | date:long }}","type":"Input","inputType":"text","disabled":false,"readOnly":true,"required":false}]}]},"state":{"calendar_5":"2026-07-04T12:00:00.000Z"}}} playground="aW1wb3J0IGRhdGV0aW1lCmZyb20gcHJlZmFiX3VpLmNvbXBvbmVudHMgaW1wb3J0IENhbGVuZGFyLCBDb2x1bW4sIElucHV0LCBMYWJlbCwgUm93Cgp3aXRoIFJvdyhnYXA9Nik6CiAgICBjYWwgPSBDYWxlbmRhcih2YWx1ZT1kYXRldGltZS5kYXRlKDIwMjYsIDcsIDQpKQogICAgd2l0aCBDb2x1bW4oZ2FwPTIsIGp1c3RpZnk9ImNlbnRlciIpOgogICAgICAgIExhYmVsKCJTZWxlY3RlZCBkYXRlIikKICAgICAgICBJbnB1dCh2YWx1ZT1jYWwucnguZGF0ZSgibG9uZyIpLCByZWFkX29ubHk9VHJ1ZSkK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    import datetime
    from prefab_ui.components import Calendar, Column, Input, Label, Row

    with Row(gap=6):
        cal = Calendar(value=datetime.date(2026, 7, 4))
        with Column(gap=2, justify="center"):
            Label("Selected date")
            Input(value=cal.rx.date("long"), read_only=True)
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-6",
        "type": "Row",
        "children": [
          {
            "name": "calendar_5",
            "value": "2026-07-04T12:00:00.000Z",
            "type": "Calendar",
            "mode": "single"
          },
          {
            "cssClass": "gap-2 justify-center",
            "type": "Column",
            "children": [
              {"type": "Label", "text": "Selected date", "optional": false},
              {
                "name": "input_1",
                "value": "{{ calendar_5 | date:long }}",
                "type": "Input",
                "inputType": "text",
                "disabled": false,
                "readOnly": true,
                "required": false
              }
            ]
          }
        ]
      },
      "state": {"calendar_5": "2026-07-04T12:00:00.000Z"}
    }
    ```
  </CodeGroup>
</ComponentPreview>

Click a date and the input updates instantly. The `.date("long")` pipe formats an ISO string like `"2025-01-15"` into `"January 15, 2025"`.

## API Reference

<Card icon="code" title="Calendar Parameters">
  <ParamField body="mode" type="str" default="single">
    Selection mode: `"single"`, `"multiple"`, or `"range"`.
  </ParamField>

  <ParamField body="value" type="date | Rx | dict | list[date] | None" default="None">
    Initial selected date(s). Single: a `datetime.date`. Range: `{"from": date, "to": date}`. Multiple: a list of dates. Any position also accepts an `Rx` for reactive binding.
  </ParamField>

  <ParamField body="name" type="str | None" default="None">
    State key for storing the selected date. Single mode stores an ISO string; range mode stores `{"from": "...", "to": "..."}`.
  </ParamField>

  <ParamField body="on_change" type="Action | list[Action] | None" default="None">
    Action(s) triggered when the selection changes.
  </ParamField>

  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes.
  </ParamField>
</Card>

## Protocol Reference

```json Calendar theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "Calendar",
  "id?": "string",
  "onMount?": "any",
  "name?": "string",
  "value?": "string | object | string[]",
  "mode?": "single | multiple | range",
  "onChange?": "Action | Action[]",
  "cssClass?": "string"
}
```

For the complete protocol schema, see [Calendar](/protocol/calendar).
