# Calendar

Single/range APG day grid with native day and caption controls.

[All components](https://rickylabs.github.io/netscript/design-system/components/) · [Theme builder](https://rickylabs.github.io/netscript/create/) · [Implementation source](https://github.com/rickylabs/netscript/blob/main/packages/fresh-ui/registry/components/ui/calendar.tsx)

## Live preview

[Open live calendar preview](https://rickylabs.github.io/netscript/assets/fresh-ui/preview/?component=calendar&theme=studio-utility)

## Install

```bash
netscript ui:add calendar
```

## Usage and examples

The preview runs this JSX with the installed components. Import any composed primitives from your UI directory.

```tsx
import { useState } from 'preact/hooks';
import { Calendar } from '@app/components/ui/calendar.tsx';

export function Example() {
  const [value, setValue] = useState('standard');
  const [open, setOpen] = useState(false);
  const [notice, report] = useState('');
  return (<><div><Calendar aria-label="Delivery date" defaultMonth="2026-11-01" /></div><p role="status">{notice}</p></>);
}
```

## Props

Generated from native `deno doc --json --private` over the shipped implementation. Compound component props retain their owning interface; native attributes pass through where declared.

| Owner | Prop | Type | Optional | Description |
| --- | --- | --- | --- | --- |
| `CalendarProps` | `mode` | `"single" \| "range"` | Yes |  |
| `CalendarProps` | `months` | `1 \| 2` | Yes |  |
| `CalendarProps` | `caption` | `"label" \| "dropdown"` | Yes |  |
| `CalendarProps` | `value` | `[object Object]` | Yes |  |
| `CalendarProps` | `defaultValue` | `[object Object]` | Yes |  |
| `CalendarProps` | `defaultMonth` | `string` | Yes |  |
| `CalendarProps` | `today` | `string` | Yes |  |
| `CalendarProps` | `onValueChange` | `(dates: [object Object]) => void` | Yes |  |
| `CalendarProps` | `min` | `string` | Yes |  |
| `CalendarProps` | `max` | `string` | Yes |  |
| `CalendarProps` | `disabled` | `boolean` | Yes |  |
| `CalendarProps` | `isDateDisabled` | `(date: string) => boolean` | Yes |  |
| `CalendarProps` | `weekStartsOn` | `0 \| 1` | Yes |  |
| `CalendarProps` | `locale` | `string` | Yes |  |
| `CalendarProps` | `autoFocus` | `boolean` | Yes |  |
| `CalendarProps` | `class` | `string` | Yes |  |

```typescript
CalendarProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "class" | "onChange">
```

## Keyboard

| Key | Action |
| --- | --- |
| `Arrow keys` | Move between cells |
| `Home/End` | Move to first/last cell |
| `PageUp/PageDown` | Move one month, preserving or clamping the day; Shift moves one year. |
| `Enter/Space` | Select the focused enabled day. |

## Tokens

Semantic contract roles: `primary/default`, `primary/fg`, `radius/input`, `surface/muted`, `surface/selected`, `text/fg`, `text/muted`.

CSS custom properties referenced directly: `--ns-border-width`, `--ns-card`, `--ns-control-gap`, `--ns-control-height-sm`, `--ns-fg`, `--ns-hover`, `--ns-input-border`, `--ns-muted`, `--ns-muted-fg`, `--ns-primary`, `--ns-primary-fg`, `--ns-primary-hover`, `--ns-radius-control`, `--ns-radius-input`, `--ns-ring`, `--ns-selected`, `--ns-space-2`, `--ns-space-4`, `--ns-text-caption`, `--ns-text-small`, `--ns-text-strong`, `--ns-weight-strong`.

## Contract and compatibility

Accessibility pattern: [WAI-ARIA guidance](https://www.w3.org/WAI/ARIA/apg/patterns/grid/)

- UTC Gregorian ISO API; native buttons and select captions. Day state/range are derived, with CSS hover/focus; no caller state simulation. Only endpoints get selected visual state; middle cells remain aria-selected with range fill.
- Hydrate inside an island. Disabled/out-of-bounds dates are skipped; browsing alone never changes selection.

Design contract values marked planned are not implementation props. The props above describe what ships today.
