# Mini-Calendar

Component of the SBB design system Lyne.

- Package: `@sbb-esta/lyne-elements` (Angular: `@sbb-esta/lyne-angular`)
- Structure: main element with parts; use parts only within the element they belong to
- Categories: Form
- Status: Design guidelines complete

## Links

- Page on digital.sbb.ch: https://digital.sbb.ch/en/design-system/lyne/components/mini-calendar/
- Storybook: https://lyne-elements.app.sbb.ch/?path=/docs/elements-mini-calendar--docs
- Angular (`@sbb-esta/lyne-angular`): https://lyne-angular.app.sbb.ch/angular/components/mini-calendar/overview (API: https://lyne-angular.app.sbb.ch/angular/components/mini-calendar/api)
- Figma: https://www.figma.com/design/mWknI2rC5DJmOgRO61WKai/Lyne-Components?node-id=7491-69
- GitHub: https://github.com/sbb-design-systems/lyne-components/tree/v5.12.0/src/elements/mini-calendar

## Elements

- `sbb-mini-calendar`: It displays a minimal calendar, together with the `sbb-mini-calendar-month` and `sbb-mini-calendar-day`.
  - `sbb-mini-calendar-month`, only within `sbb-mini-calendar`: It displays a month in the `sbb-mini-calendar`.
    - `sbb-mini-calendar-day`, only within `sbb-mini-calendar-month`: It displays a day in the `sbb-mini-calendar-month`.

## Related components

- Similar: [Calendar](https://digital.sbb.ch/en/design-system/lyne/components/calendar/index.md), [Datepicker](https://digital.sbb.ch/en/design-system/lyne/components/datepicker/index.md)

## Overview

### What does the component do?
The mini calendar displays date information very compactly. Each day is a small dot that can be coloured or marked. Days can optionally be selected.

### When should the component be used?
* To show many days, several months or entire years in little space.
* To make recurring events and patterns visible, e.g. days of operation.

### Rules.
* The mini calendar is not a replacement for the [calendar](https://digital.sbb.ch/en/design-system/lyne/components/calendar/) or [datepicker](https://digital.sbb.ch/en/design-system/lyne/components/datepicker/). Use those to pick a specific date.
* Colours and markers need a legend. Meaning must not be conveyed by colour alone.
* The component is only partially accessible (small days, grid structure). If accessibility is required, provide the information in an additional way, or use the component only in internal applications.

## Implementation (web components)

The `<sbb-mini-calendar>`, together with `<sbb-mini-calendar-month>` and `<sbb-mini-calendar-day>`,
are components used to display a minimal calendar.

The `<sbb-mini-calendar-month>` requires usage of the `date` property/attribute in ISO string format (YYYY-MM).
The `<sbb-mini-calendar-day>` requires usage of the `date` property/attribute in ISO string format (YYYY-MM-DD).

```html
<sbb-mini-calendar>
  <sbb-mini-calendar-month date="2025-01">
    <sbb-mini-calendar-day date="2025-01-01"></sbb-mini-calendar-day>
    ...
  </sbb-mini-calendar-month>
  <sbb-mini-calendar-month date="2025-02">
    <sbb-mini-calendar-day date="2025-02-01"></sbb-mini-calendar-day>
    ...
  </sbb-mini-calendar-month>
  ...
</sbb-mini-calendar>
```

Consumers should check the accuracy of the slotted data, since there's no check on missing or wrongly formatted data.

It's also possible to display a tooltip on hover using the `sbb-tooltip` attribute (when using the
`tooltip` module), passing the date with the desired format.
For better usability, it's suggested to set the `sbb-tooltip-open-delay` attribute too.

```html
<sbb-mini-calendar-day
  date="2025-01-01"
  sbb-tooltip="01.01.2025"
  sbb-tooltip-open-delay="200"
></sbb-mini-calendar-day>
```

### Style

The orientation of the days in each month can be set using the `orientation` property, which default value is `horizontal`.

```html
<sbb-mini-calendar orientation="vertical"> ... </sbb-mini-calendar>
```

For the `<sbb-mini-calendar-month>` the month name is always displayed at the component's bottom;
the year is displayed on top only for January and for the first slotted month in the `<sbb-mini-calendar>`.

The `orientation` value of the `<sbb-mini-calendar>` parent controls the component's orientation via CSS rules.

The `<sbb-mini-calendar-day>` component has a `color` property, which is used to change the dot color.
Default colors are provided for `charcoal`, `cloud`, `orange`, `red` and `sky` values;
moreover, consumers can write their own CSS rules for custom values.

```css
sbb-mini-calendar-day[color='my-custom-color'] {
  color: lightskyblue;
}
```

```html
<!-- default style -->
<sbb-mini-calendar-day date="2025-01-01" color="orange"></sbb-mini-calendar-day>

<!-- custom value -->
<sbb-mini-calendar-day date="2025-01-01" color="my-custom-color"></sbb-mini-calendar-day>
```

Similarly, a property named `marker` determines the shape of the dot.
Default styles are provided for `target`, `circle`, `slash` and `cross` values.
Consumers can write their own CSS rules for different values.

### Keyboard interaction

It's possible to move within the component using the keyboard.

#### Horizontal orientation

| Keyboard               | Action                                                                                                                      |
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| <kbd>Left Arrow</kbd>  | Go to previous day.                                                                                                         |
| <kbd>Right Arrow</kbd> | Go to next day.                                                                                                             |
| <kbd>Up Arrow</kbd>    | Go to the same day in the previous week (eg. from Monday to previous Monday).<br/>Allows movement between different months. |
| <kbd>Down Arrow</kbd>  | Go to the same day in the next week (eg. from Monday to next Monday).<br/>Allows movement between different months.         |
| <kbd>Home</kbd>        | Go to the first day of the month.                                                                                           |
| <kbd>End</kbd>         | Go to the last day of the month.                                                                                            |
| <kbd>Page Up</kbd>     | Go to the same day in the first week (eg. from Monday to the first Monday of the month).                                    |
| <kbd>Page Down</kbd>   | Go to the same day in the last week (eg. from Monday to the last Monday of the month).                                      |

#### Vertical orientation

| Keyboard               | Action                                                                                                              |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------- |
| <kbd>Left Arrow</kbd>  | Go to the same day in the next week (eg. from Monday to next Monday).<br/>Allows movement between different months. |
| <kbd>Right Arrow</kbd> | Go to the same day in the next week (eg. from Monday to next Monday).<br/>Allows movement between different months. |
| <kbd>Up Arrow</kbd>    | Go to previous day.                                                                                                 |
| <kbd>Down Arrow</kbd>  | Go to next day.                                                                                                     |
| <kbd>Home</kbd>        | Go to the first day of the month.                                                                                   |
| <kbd>End</kbd>         | Go to the last day of the month.                                                                                    |
| <kbd>Page Up</kbd>     | Go to the first day of the week (eg. from any day to Monday of the same week).                                      |
| <kbd>Page Down</kbd>   | Go to the last day of the week (eg. from any day to Sunday of the same week).                                       |

### Accessibility

Even though some WCAG rules have been followed
(e.g., `aria-label`s on `<sbb-mini-calendar-day>`s, keyboard navigation, visible focus indicator, correct contrast...),
the component may not be fully accessible due to the small dimensions of `<sbb-mini-calendar-day>`s and
the usage of a grid implementation for the `<sbb-mini-calendar-month>`
(differently from the `<sbb-calendar>`, which has a table implementation).

## API (web components)

Full API tables (attributes, events, slots, CSS properties): https://digital.sbb.ch/en/design-system/lyne/components/mini-calendar/api.md
