# Calendar

> A Calendar widget to allow user to select a single date from an interactive calendar interface

Calendar widgets are [Input Fields](https://golemui.com/dx/widgets-reference/input-fields/overview.md) that allow the user to select a single date by interacting with a visual calendar grid.


```ts title="calendar.ts"

export default [
  gui.inputs.calendar('appointmentDate', {
    hint: 'Select a date',
    label: 'Calendar',
  }),
];
```

_Live demo on the docs page. Form definition: [calendar.ts](https://golemui.com/template/widgets-dx/calendar/calendar.ts)._

## Props

Use these `props` to customize your Calendar widget.

| prop                  | type   | description                                                                                                                    |
| --------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `disabledRanges`      | array  | Array of objects (`{ start: string, end?: string }`) defining disabled date ranges                                             |
| `hint`                | string | A description to display below the calendar                                                                                    |
| `maxDate`             | string | Maximum allowable date in ISO format                                                                                           |
| `minDate`             | string | Minimum allowable date in ISO format                                                                                           |
| `nextMonthAriaLabel`  | string | ARIA label for the next month button                                                                                           |
| `nextMonthIcon`       | string | Custom CSS class for the "next month" button icon                                                                              |
| `numberOfMonths`      | number | Number of months to display simultaneously. Defaults to 1                                                                      |
| `prevMonthAriaLabel`  | string | ARIA label for the previous month button                                                                                       |
| `prevMonthIcon`       | string | Custom CSS class for the "previous month" button icon                                                                          |
| `selectYearAriaLabel` | string | ARIA label for the year-selector toggle button in the calendar header; the current year is appended. Defaults to `Select year` |
| `yearGridAriaLabel`   | string | ARIA label for the year-selection grid. Defaults to `Year selection`                                                           |

### Hint

<Aside>A `label` is required for the `hint` to be displayed.</Aside>

Use the property `hint` to add a description.


```ts title="calendar.ts"

export default [
  gui.inputs.calendar('appointmentDate', {
    hint: 'Please select a valid date for your appointment',
    label: 'Appointment Date',
  }),
];
```

_Live demo on the docs page. Form definition: [calendar-hint.ts](https://golemui.com/template/widgets-dx/calendar/calendar-hint.ts)._

### Min and Max Dates

Use the properties `minDate` and `maxDate` to specify the boundaries for selectable dates.


```ts title="calendar.ts"

export default [
  gui.inputs.calendar('appointmentDate', {
    minDate: '2024-01-05T00:00:00.000Z',
    maxDate: '2024-02-21T23:59:59.999Z',
    defaultValue: '2024-01-21T00:00:00.000Z',
  }),
];
```

_Live demo on the docs page. Form definition: [calendar-minmax.ts](https://golemui.com/template/widgets-dx/calendar/calendar-minmax.ts)._

### Number of Months

Use the property `numberOfMonths` to display multiple months side-by-side.


```ts title="calendar.ts"

export default [
  gui.inputs.calendar('appointmentDate', {
    numberOfMonths: 2,
  }),
];
```

_Live demo on the docs page. Form definition: [calendar-months.ts](https://golemui.com/template/widgets-dx/calendar/calendar-months.ts)._

### Disabled Ranges

Use the property `disabledRanges` to selectively disable specific date blocks within the calendar.


```ts title="calendar.ts"

export default [
  gui.inputs.calendar('appointmentDate', {
    disabledRanges: [
      {
        start: '2024-03-10T00:00:00.000Z',
        end: '2024-03-15T23:59:59.999Z',
      },
    ],
    defaultValue: '2024-03-21',
  }),
];
```

_Live demo on the docs page. Form definition: [calendar-disabled.ts](https://golemui.com/template/widgets-dx/calendar/calendar-disabled.ts)._

### Custom Icons

Use `prevMonthIcon`, `nextMonthIcon`, `prevMonthAriaLabel` and `nextMonthAriaLabel` to customize the navigation buttons.


```ts title="calendar.ts"

export default [
  gui.inputs.calendar('date', {
    prevMonthIcon: 'chevron_left',
    nextMonthIcon: 'chevron_right',
    prevMonthAriaLabel: 'Go to previous month',
    nextMonthAriaLabel: 'Go to next month',
    label: 'Custom Icons Calendar',
    uid: 'calendar-icons',
  }),
];
```

_Live demo on the docs page. Form definition: [calendar-icons.ts](https://golemui.com/template/widgets-dx/calendar/calendar-icons.ts)._

## Styling

Calendars can be styled as explained in the [Styling Guide](https://golemui.com/dx/styling/overview.md).

### CSS Variables

Following you will find a list with the CSS Variables and a quick description of what you will style.

| CSS Variable                                | Description                                      |
| ------------------------------------------- | ------------------------------------------------ |
| `--gui-radius-md`                           | Calendar container and day button border radius  |
| `--gui-bg-default`                          | Calendar container background color              |
| `--gui-border-default`                      | Default border color and cell hover border color |
| `--gui-space-3`                             | Internal padding                                 |
| `--gui-calendar-change-month-button-width`  | Width of the next/prev buttons                   |
| `--gui-calendar-change-month-button-height` | Height of the next/prev buttons                  |
| `--gui-text-default`                        | Default text and focus border color              |
| `--gui-text-secondary`                      | Day button hover background color                |
| `--gui-intent-primary-active`               | "Today" border highlight color                   |
| `--gui-intent-primary`                      | Selected day background color                    |
| `--gui-bg-disabled`                         | Disabled day background color                    |

### Anatomy

This is the anatomy of the Calendar Widget in case you want to use your CSS styles.


```html title="calendar-anatomy.html"
<gui-calendar-input class="gui-calendar gui-field">
  <gui-calendar class="gui-field">
    <label class="gui-label" for="fieldUid" id="fieldUid_calendar_label">
      <span class="gui-label__text">Label</span>
      <div class="gui-widget-hint" id="fieldUid_hint" aria-hidden="true">Hint</div>
    </label>

    <div class="gui-widget">
      <div
        class="gui-calendar-input"
        role="group"
        id="fieldUid_calendar"
        aria-labelledby="fieldUid_calendar_label"
        aria-describedby="fieldUid_hint"
      >
        <div class="gui-visually-hidden" aria-live="polite">March 2024</div>

        <div class="gui-calendar__container">
          <button
            type="button"
            class="gui-button gui-calendar__month-button gui-calendar__month-button--prev"
            aria-label="Previous month"
          >
            <span class="gui-caret gui-caret--left" aria-hidden="true"></span>
          </button>

          <div class="gui-calendar__months-grid">
            <div class="gui-calendar__panel">
              <header class="gui-calendar__header">
                <h2>
                  <span class="gui-calendar__month-name">March</span>
                  <button
                    type="button"
                    class="gui-calendar__year-selector"
                    aria-expanded="false"
                    aria-label="Select year, 2024"
                  >
                    <span class="gui-calendar__year-value">2024</span>
                    <span class="gui-calendar__year-arrow" aria-hidden="true">
                      <span class="gui-caret" aria-hidden="true"></span>
                    </span>
                  </button>
                </h2>
              </header>

              <div class="gui-calendar__days-grid" role="grid" aria-label="March 2024">
                <div role="row" class="gui-calendar__rows">
                  <span class="gui-calendar__weekday" role="columnheader">S</span>
                  <span class="gui-calendar__weekday" role="columnheader">M</span>
                  <!-- More columnheader elements (7 in total) -->
                </div>

                <div role="row" class="gui-calendar__rows">
                  <button
                    type="button"
                    role="gridcell"
                    class="gui-calendar__day-button other-month"
                    tabindex="-1"
                    disabled=""
                    aria-label="Sunday, February 25, 2024"
                    data-date="2024-02-25"
                    aria-selected="false"
                  >
                    25
                  </button>

                  <button
                    type="button"
                    role="gridcell"
                    class="gui-calendar__day-button other-month"
                    tabindex="-1"
                    disabled=""
                    aria-label="Monday, February 26, 2024"
                    data-date="2024-02-26"
                    aria-selected="false"
                  >
                    26
                  </button>

                  <button
                    type="button"
                    role="gridcell"
                    class="gui-calendar__day-button other-month"
                    tabindex="-1"
                    disabled=""
                    aria-label="Tuesday, February 27, 2024"
                    data-date="2024-02-27"
                    aria-selected="false"
                  >
                    27
                  </button>

                  <button
                    type="button"
                    role="gridcell"
                    class="gui-calendar__day-button other-month"
                    tabindex="-1"
                    disabled=""
                    aria-label="Wednesday, February 28, 2024"
                    data-date="2024-02-28"
                    aria-selected="false"
                  >
                    28
                  </button>

                  <button
                    type="button"
                    role="gridcell"
                    class="gui-calendar__day-button other-month"
                    tabindex="-1"
                    disabled=""
                    aria-label="Thursday, February 29, 2024"
                    data-date="2024-02-29"
                    aria-selected="false"
                  >
                    29
                  </button>

                  <button
                    type="button"
                    role="gridcell"
                    class="gui-calendar__day-button"
                    tabindex="-1"
                    aria-label="Friday, March 1, 2024"
                    data-date="2024-03-01"
                    aria-selected="false"
                  >
                    1
                  </button>

                  <button
                    type="button"
                    role="gridcell"
                    class="gui-calendar__day-button"
                    tabindex="-1"
                    aria-label="Saturday, March 2, 2024"
                    data-date="2024-03-02"
                    aria-selected="false"
                  >
                    2
                  </button>
                </div>
                <!-- More row elements (7 in total) -->
              </div>
            </div>
          </div>

          <button
            type="button"
            class="gui-button gui-calendar__month-button gui-calendar__month-button--next"
            aria-label="Next month"
          >
            <span class="gui-caret gui-caret--right" aria-hidden="true"></span>
          </button>
        </div>
      </div>
    </div>
  </gui-calendar>
</gui-calendar-input>
```
