Data
Calendar
A month of days to pick from, or with range, a range of them. It's the grid from the APG's date picker, with all the keyboard support you'd expect.
- Element
<slab-calendar>- Built on
<table role=grid>
Example
Here's a styled version, <slab-styled-calendar>. It's not
in the package — it's an example of what you can build with the
headless element. Copy it and make it yours at the
bottom of this page. Switch to "As it ships" to see the same markup
with the headless element and no CSS at all. That's your starting
point.
<div class="stack">
<slab-styled-calendar min="2026-10-12" max="2026-12-18" value="2026-10-16"></slab-styled-calendar>
<slab-styled-calendar range value="2026-10-19/2026-10-23"></slab-styled-calendar>
</div>
<div class="stack">
<slab-calendar min="2026-10-12" max="2026-12-18" value="2026-10-16"></slab-calendar>
<slab-calendar range value="2026-10-19/2026-10-23"></slab-calendar>
</div>
Usage
pnpm add slab-elements lit
import 'slab-elements/calendar.js';
export function MyCalendar() {
return (
<slab-calendar value="2026-03-14"></slab-calendar>
);
}
MyCalendar.jsx React 19 or later, which sets props on custom elements as properties.
import 'slab-elements/calendar.js';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('my-calendar')
export class MyCalendar extends LitElement {
render() {
return html`
<slab-calendar value="2026-03-14"></slab-calendar>
`;
}
}
my-calendar.ts Slab is built on Lit, so its elements are at home in Lit's templates.
<script setup>
import 'slab-elements/calendar.js';
</script>
<template>
<slab-calendar value="2026-03-14"></slab-calendar>
</template>
MyCalendar.vue Let Vue's compiler know slab- tags are custom elements with isCustomElement.
<script>
import 'slab-elements/calendar.js';
</script>
<slab-calendar value="2026-03-14"></slab-calendar>
MyCalendar.svelte Svelte binds properties and events to custom elements like any other element.
import 'slab-elements/calendar.js';
export const MyCalendar = <template>
<slab-calendar value="2026-03-14"></slab-calendar>
</template>;
MyCalendar.gjs Ember sets attributes, and a dynamic value like {{this.max}} sets the property when the element has one. {{on}} listens for any event by its name.
<script type="module">
import 'slab-elements/calendar.js';
</script>
<slab-calendar value="2026-03-14"></slab-calendar>
index.html Any bundler (or an import map) takes care of the imports.
Picking a day tells screenreaders which day is now selected, since a focused day’s selection changing isn’t read out on its own. Change what they’re told with selectedLabel, a function of the formatted day.
With range, the first day picked starts a range and the second ends it, in either order. Until the second is picked, the days between the first and the one focused or hovered are ::part(preview). Then value is the range as “yyyy-mm-dd/yyyy-mm-dd”, the ISO 8601 form of an interval, and “change” is dispatched. Its days are ::part(selected), and its ends ::part(range-start) and ::part(range-end). Screenreaders are told when the first day starts the range, and what the range is once the second ends it. Change what they’re told with rangeStartedLabel and rangeSelectedLabel, functions of the formatted day and range.
Keyboard
| Key | What it does |
|---|---|
| Left, Right | Moves a day, into the month before or after at an end. |
| Up, Down | Moves a week. |
| Home, End | Moves to the start or end of the week. |
| Page Up, Page Down | Moves back or forward a month. With Shift, a year. |
| Enter, Space | Selects the day and dispatches “change”. |
| Escape | With range, starts over after the first day is picked. |
Behavior
A calendar with no visual styles: a month of days in a [role=grid], to pick one from, as in the APG's date picker.
Dates are ISO "yyyy-mm-dd" strings, as on a Date Field, and are worked out in UTC, so a change to or from daylight saving time never skips or repeats a day.
One day is tabbable: the selected one, or else today, kept between min and max. The arrow keys move a day or a week, into the month before or after when they reach an end. Home and End go to the start and end of the week, Page Up and Page Down go back and forward a month, and with Shift a year. Enter, Space and a click select the day and dispatch "change". Days before min or after max can't be reached or selected. In a right-to-left page, Left goes forward a day and Right back.
With range, two days are picked rather than one: the first and the last of a range, in either order. "change" is dispatched once both are, and value is then the range as "yyyy-mm-dd/yyyy-mm-dd", the ISO 8601 form of an interval. Between the two, the days from the first to the one focused or hovered are ::part(preview), and Escape starts over. Screenreaders are told when the first day is picked, by rangeStartedLabel, and what the range is once the last is, by rangeSelectedLabel. Without range, they're told the day that's picked, by selectedLabel.
The month's name, the weekdays', each day's full date and its number are the browser's own, from Intl, in the language of the nearest lang attribute. The only words that aren't the browser's are the previous and next buttons', which previous-label and next-label set, and what screenreaders are told about a range, or else the strings registered for that language with registerStrings().
Style it through its parts. A day is also ::part(selected), ::part(today) and ::part(disabled) when it's those, and with range, ::part(range-start), ::part(range-end) and ::part(preview). The first day picked of a range is its start and end until the last is picked.
API
<slab-calendar>
| Name | Type | Default | Description |
|---|---|---|---|
max
|
string |
The latest date that can be selected, as "yyyy-mm-dd". | |
min
|
string |
The earliest date that can be selected, as "yyyy-mm-dd". | |
next-label
|
string |
The next month button's text and so its accessible name. "Next month" in English when unset. | |
previous-label
|
string |
The previous month button's text and so its accessible name. "Previous month" when unset. | |
range
|
boolean |
false |
Selects a range of days rather than one. |
value
|
string |
'' |
The selected date, as "yyyy-mm-dd", or with range the selected range, as "yyyy-mm-dd/yyyy-mm-dd". Otherwise an empty string. Like a native input, the attribute is the default value and the property is the current one. |
week-start
|
number |
0 |
The day weeks start on, from 0 for Sunday to 6 for Saturday. |
| Name | Type | Description |
|---|---|---|
rangeSelectedLabel
|
(range: string) => string |
With range, what screenreaders are told once its last day is picked, from the range, such as "Monday, January 5 – Friday, January 9, 2026" in the calendar's language. The range and "selected" in English when unset. |
rangeStartedLabel
|
(date: string) => string |
With range, what screenreaders are told once its first day is picked, from that day, in the calendar's language. That it's the range's start, and to pick its end, in English when unset. |
selectedLabel
|
(date: string) => string |
Without range, what screenreaders are told once a day is picked, from that day, such as "Friday, October 16, 2026" in the calendar's language. The day and "selected" in English when unset. |
| Signature | Description |
|---|---|
focus(options?: FocusOptions): void
|
Focuses it, or the part of it that takes focus. |
| Name | Type | Description |
|---|---|---|
change
|
Event |
When the user selects a day, or both ends of a range. Setting value doesn't dispatch it. |
| Name | Description |
|---|---|
day
|
A day of the month |
disabled
|
A day before the earliest date or after the latest |
empty
|
A cell before the first day of the month or after the last |
grid
|
The days |
header
|
The month and the buttons that change it |
heading
|
The month and year |
next
|
The button to the next month |
preview
|
With range, a day from the first one picked to the one focused or hovered, until the last is picked |
previous
|
The button to the previous month |
range-end
|
With range, the last day of the selected range |
range-start
|
With range, the first day of the selected range |
selected
|
The selected day, or with range a day of the selected range |
today
|
Today |
weekday
|
A day of the week, above the days |
Copy and own it
<slab-styled-calendar> isn't in the package. It's an example —
copy it into your project and change whatever you want. Keyboard,
focus, ARIA, forms, and events all come from the headless element,
and the styles only reach in through ::part() and
:state(), same as yours would.
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-calendar> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.
Calendar.jsx
import 'slab-elements/calendar.js';
import './calendar.css';
export function Calendar(props) {
return <slab-calendar {...props} />;
}
calendar.css
slab-calendar {
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: inline-block;
font-family: var(--font-body);
padding: 1rem;
}
slab-calendar::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
slab-calendar::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
slab-calendar::part(previous),
slab-calendar::part(next) {
align-items: center;
background-color: var(--paper);
block-size: 2.25rem;
border: var(--border);
color: var(--ink);
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 2.25rem;
justify-content: center;
padding: 0;
transition: background-color 100ms;
}
slab-calendar::part(previous)::before,
slab-calendar::part(next)::before {
block-size: 0.5rem;
border-block-end: 2px solid currentcolor;
border-inline-start: 2px solid currentcolor;
content: '';
inline-size: 0.5rem;
rotate: 45deg;
translate: 0.125rem 0;
}
slab-calendar::part(previous):hover,
slab-calendar::part(next):hover {
background-color: var(--chalk);
}
slab-calendar::part(previous):focus-visible,
slab-calendar::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-calendar::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
/*
Separate rather than collapsed, so each day draws its own border whole.
Collapsed, a day's border merges with its neighbors' and today's ring
breaks up.
*/
slab-calendar::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
slab-calendar::part(weekday) {
color: var(--ash);
font-family: var(--font-mono);
font-size: 0.75rem;
font-weight: 400;
padding-block-end: 0.375rem;
text-transform: uppercase;
}
slab-calendar::part(day) {
block-size: 2.5rem;
border: 2px solid transparent;
box-sizing: border-box;
cursor: pointer;
inline-size: 2.5rem;
text-align: center;
transition:
background-color 100ms,
color 100ms;
}
slab-calendar::part(day):hover {
background-color: var(--chalk);
}
slab-calendar::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
slab-calendar::part(today) {
border-color: var(--ember);
}
/*
The ring is inside the day, so on the selected one it's on ink, where
ember falls short of 3:1 in the dark. The text's color always has the
contrast.
*/
slab-calendar::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-calendar::part(selected):hover {
background-color: var(--ink);
}
slab-calendar::part(selected):focus-visible {
outline-color: currentcolor;
}
/*
While a range is being picked, the days it would cover are hatched, so
they don't read as chosen yet. Once it's picked, they're a band of chalk
between its ends, which are ink like a single selected day.
*/
slab-calendar::part(preview) {
background-image: repeating-linear-gradient(
-45deg,
var(--chalk) 0 4px,
transparent 4px 8px
);
}
slab-calendar[range]::part(selected) {
background-color: var(--chalk);
background-image: none;
color: var(--ink);
font-weight: 400;
}
slab-calendar[range]::part(selected):hover {
background-color: var(--chalk);
}
slab-calendar[range]::part(selected):focus-visible {
outline-color: var(--ember);
}
slab-calendar[range]::part(range-start),
slab-calendar[range]::part(range-end) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-calendar[range]::part(range-start):hover,
slab-calendar[range]::part(range-end):hover {
background-color: var(--ink);
}
slab-calendar[range]::part(range-start):focus-visible,
slab-calendar[range]::part(range-end):focus-visible {
outline-color: currentcolor;
}
slab-calendar::part(disabled) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
slab-calendar::part(disabled):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
slab-calendar::part(previous),
slab-calendar::part(next),
slab-calendar::part(day) {
transition: none;
}
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
Under the hood, it's just the headless element, subclassed,
with styles set. That's it. To use it, copy
these files, swap the tag in @customElement()
for one of your own, and import it.
tokens.styles.ts holds the colors and fonts
every styled example shares, so you only need it once.
calendar.ts
import { customElement } from 'lit/decorators.js';
import Calendar from 'slab-elements/calendar.js';
import styles from './calendar.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-calendar': StyledCalendar;
}
}
/**
* Calendar, styled: a raised slab of days, with today ringed in ember and
* the selected day in ink.
*/
@customElement('slab-styled-calendar')
export default class StyledCalendar extends Calendar {
static override styles = [tokens, styles];
}
calendar.styles.ts
import { css } from 'lit';
/*
The previous and next buttons' text is their accessible name, so it stays,
at no size, and a chevron is drawn in its place.
*/
export default css`
:host {
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: inline-block;
font-family: var(--font-body);
padding: 1rem;
}
[part~='header'] {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
[part~='heading'] {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
[part~='previous'],
[part~='next'] {
align-items: center;
background-color: var(--paper);
block-size: 2.25rem;
border: var(--border);
color: var(--ink);
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 2.25rem;
justify-content: center;
padding: 0;
transition: background-color 100ms;
&::before {
block-size: 0.5rem;
border-block-end: 2px solid currentcolor;
border-inline-start: 2px solid currentcolor;
content: '';
inline-size: 0.5rem;
rotate: 45deg;
translate: 0.125rem 0;
}
&:hover {
background-color: var(--chalk);
}
&:focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
}
[part~='next']::before {
rotate: -135deg;
translate: -0.125rem 0;
}
/*
Separate rather than collapsed, so each day draws its own border whole.
Collapsed, a day's border merges with its neighbors' and today's ring
breaks up.
*/
[part~='grid'] {
border-collapse: separate;
border-spacing: 0;
}
[part~='weekday'] {
color: var(--ash);
font-family: var(--font-mono);
font-size: 0.75rem;
font-weight: 400;
padding-block-end: 0.375rem;
text-transform: uppercase;
}
[part~='day'] {
block-size: 2.5rem;
border: 2px solid transparent;
box-sizing: border-box;
cursor: pointer;
inline-size: 2.5rem;
text-align: center;
transition:
background-color 100ms,
color 100ms;
&:hover {
background-color: var(--chalk);
}
&:focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
}
[part~='today'] {
border-color: var(--ember);
}
/*
The ring is inside the day, so on the selected one it's on ink, where
ember falls short of 3:1 in the dark. The text's color always has the
contrast.
*/
[part~='selected'] {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
&:hover {
background-color: var(--ink);
}
&:focus-visible {
outline-color: currentcolor;
}
}
/*
While a range is being picked, the days it would cover are hatched, so
they don't read as chosen yet. Once it's picked, they're a band of chalk
between its ends, which are ink like a single selected day.
*/
[part~='preview'] {
background-image: repeating-linear-gradient(
-45deg,
var(--chalk) 0 4px,
transparent 4px 8px
);
}
:host([range]) [part~='selected'] {
background-color: var(--chalk);
background-image: none;
color: var(--ink);
font-weight: 400;
&:hover {
background-color: var(--chalk);
}
&:focus-visible {
outline-color: var(--ember);
}
}
:host([range]) [part~='range-start'],
:host([range]) [part~='range-end'] {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
&:hover {
background-color: var(--ink);
}
&:focus-visible {
outline-color: currentcolor;
}
}
[part~='disabled'] {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
&:hover {
background-color: transparent;
}
}
@media (prefers-reduced-motion: reduce) {
[part~='previous'],
[part~='next'],
[part~='day'] {
transition: none;
}
}
`;
tokens.styles.ts
import { css } from 'lit';
/*
The styled components' palette and type, taken from the logo: ink for the
courses, ember for the base, paper behind them.
Each is a short alias for a "--slab-styled-*" property, with the default as
its fallback. Retheming is "--slab-styled-ember" and the rest on ":root",
which every shadow root inherits. Were the defaults declared under those
names here instead, each host's own declaration would shadow the page's.
Each default is "light-dark()", so the components follow the page's
"color-scheme": "dark" for dark, "light" for light, and "light dark" to
follow the operating system. Ink and paper trade places in the dark, so
ink is always the text and paper always what's behind it. Contrast is given
as light, then dark.
*/
export default css`
:host {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
`;
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-calendar> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.
Calendar.vue
<script setup>
import 'slab-elements/calendar.js';
import './calendar.css';
</script>
<template>
<slab-calendar><slot /></slab-calendar>
</template>
calendar.css
slab-calendar {
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: inline-block;
font-family: var(--font-body);
padding: 1rem;
}
slab-calendar::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
slab-calendar::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
slab-calendar::part(previous),
slab-calendar::part(next) {
align-items: center;
background-color: var(--paper);
block-size: 2.25rem;
border: var(--border);
color: var(--ink);
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 2.25rem;
justify-content: center;
padding: 0;
transition: background-color 100ms;
}
slab-calendar::part(previous)::before,
slab-calendar::part(next)::before {
block-size: 0.5rem;
border-block-end: 2px solid currentcolor;
border-inline-start: 2px solid currentcolor;
content: '';
inline-size: 0.5rem;
rotate: 45deg;
translate: 0.125rem 0;
}
slab-calendar::part(previous):hover,
slab-calendar::part(next):hover {
background-color: var(--chalk);
}
slab-calendar::part(previous):focus-visible,
slab-calendar::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-calendar::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
/*
Separate rather than collapsed, so each day draws its own border whole.
Collapsed, a day's border merges with its neighbors' and today's ring
breaks up.
*/
slab-calendar::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
slab-calendar::part(weekday) {
color: var(--ash);
font-family: var(--font-mono);
font-size: 0.75rem;
font-weight: 400;
padding-block-end: 0.375rem;
text-transform: uppercase;
}
slab-calendar::part(day) {
block-size: 2.5rem;
border: 2px solid transparent;
box-sizing: border-box;
cursor: pointer;
inline-size: 2.5rem;
text-align: center;
transition:
background-color 100ms,
color 100ms;
}
slab-calendar::part(day):hover {
background-color: var(--chalk);
}
slab-calendar::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
slab-calendar::part(today) {
border-color: var(--ember);
}
/*
The ring is inside the day, so on the selected one it's on ink, where
ember falls short of 3:1 in the dark. The text's color always has the
contrast.
*/
slab-calendar::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-calendar::part(selected):hover {
background-color: var(--ink);
}
slab-calendar::part(selected):focus-visible {
outline-color: currentcolor;
}
/*
While a range is being picked, the days it would cover are hatched, so
they don't read as chosen yet. Once it's picked, they're a band of chalk
between its ends, which are ink like a single selected day.
*/
slab-calendar::part(preview) {
background-image: repeating-linear-gradient(
-45deg,
var(--chalk) 0 4px,
transparent 4px 8px
);
}
slab-calendar[range]::part(selected) {
background-color: var(--chalk);
background-image: none;
color: var(--ink);
font-weight: 400;
}
slab-calendar[range]::part(selected):hover {
background-color: var(--chalk);
}
slab-calendar[range]::part(selected):focus-visible {
outline-color: var(--ember);
}
slab-calendar[range]::part(range-start),
slab-calendar[range]::part(range-end) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-calendar[range]::part(range-start):hover,
slab-calendar[range]::part(range-end):hover {
background-color: var(--ink);
}
slab-calendar[range]::part(range-start):focus-visible,
slab-calendar[range]::part(range-end):focus-visible {
outline-color: currentcolor;
}
slab-calendar::part(disabled) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
slab-calendar::part(disabled):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
slab-calendar::part(previous),
slab-calendar::part(next),
slab-calendar::part(day) {
transition: none;
}
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-calendar> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Import calendar.js once, such
as in your root layout, and use
<slab-calendar> as is. A Svelte component
around it would take slot="…" content as its
own slot and drop it.
calendar.js
import 'slab-elements/calendar.js';
import './calendar.css';
calendar.css
slab-calendar {
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: inline-block;
font-family: var(--font-body);
padding: 1rem;
}
slab-calendar::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
slab-calendar::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
slab-calendar::part(previous),
slab-calendar::part(next) {
align-items: center;
background-color: var(--paper);
block-size: 2.25rem;
border: var(--border);
color: var(--ink);
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 2.25rem;
justify-content: center;
padding: 0;
transition: background-color 100ms;
}
slab-calendar::part(previous)::before,
slab-calendar::part(next)::before {
block-size: 0.5rem;
border-block-end: 2px solid currentcolor;
border-inline-start: 2px solid currentcolor;
content: '';
inline-size: 0.5rem;
rotate: 45deg;
translate: 0.125rem 0;
}
slab-calendar::part(previous):hover,
slab-calendar::part(next):hover {
background-color: var(--chalk);
}
slab-calendar::part(previous):focus-visible,
slab-calendar::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-calendar::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
/*
Separate rather than collapsed, so each day draws its own border whole.
Collapsed, a day's border merges with its neighbors' and today's ring
breaks up.
*/
slab-calendar::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
slab-calendar::part(weekday) {
color: var(--ash);
font-family: var(--font-mono);
font-size: 0.75rem;
font-weight: 400;
padding-block-end: 0.375rem;
text-transform: uppercase;
}
slab-calendar::part(day) {
block-size: 2.5rem;
border: 2px solid transparent;
box-sizing: border-box;
cursor: pointer;
inline-size: 2.5rem;
text-align: center;
transition:
background-color 100ms,
color 100ms;
}
slab-calendar::part(day):hover {
background-color: var(--chalk);
}
slab-calendar::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
slab-calendar::part(today) {
border-color: var(--ember);
}
/*
The ring is inside the day, so on the selected one it's on ink, where
ember falls short of 3:1 in the dark. The text's color always has the
contrast.
*/
slab-calendar::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-calendar::part(selected):hover {
background-color: var(--ink);
}
slab-calendar::part(selected):focus-visible {
outline-color: currentcolor;
}
/*
While a range is being picked, the days it would cover are hatched, so
they don't read as chosen yet. Once it's picked, they're a band of chalk
between its ends, which are ink like a single selected day.
*/
slab-calendar::part(preview) {
background-image: repeating-linear-gradient(
-45deg,
var(--chalk) 0 4px,
transparent 4px 8px
);
}
slab-calendar[range]::part(selected) {
background-color: var(--chalk);
background-image: none;
color: var(--ink);
font-weight: 400;
}
slab-calendar[range]::part(selected):hover {
background-color: var(--chalk);
}
slab-calendar[range]::part(selected):focus-visible {
outline-color: var(--ember);
}
slab-calendar[range]::part(range-start),
slab-calendar[range]::part(range-end) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-calendar[range]::part(range-start):hover,
slab-calendar[range]::part(range-end):hover {
background-color: var(--ink);
}
slab-calendar[range]::part(range-start):focus-visible,
slab-calendar[range]::part(range-end):focus-visible {
outline-color: currentcolor;
}
slab-calendar::part(disabled) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
slab-calendar::part(disabled):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
slab-calendar::part(previous),
slab-calendar::part(next),
slab-calendar::part(day) {
transition: none;
}
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-calendar> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its attributes and its content go to the element.
Calendar.gjs
import 'slab-elements/calendar.js';
import './calendar.css';
export const Calendar = <template>
<slab-calendar ...attributes>{{yield}}</slab-calendar>
</template>;
calendar.css
slab-calendar {
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: inline-block;
font-family: var(--font-body);
padding: 1rem;
}
slab-calendar::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
slab-calendar::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
slab-calendar::part(previous),
slab-calendar::part(next) {
align-items: center;
background-color: var(--paper);
block-size: 2.25rem;
border: var(--border);
color: var(--ink);
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 2.25rem;
justify-content: center;
padding: 0;
transition: background-color 100ms;
}
slab-calendar::part(previous)::before,
slab-calendar::part(next)::before {
block-size: 0.5rem;
border-block-end: 2px solid currentcolor;
border-inline-start: 2px solid currentcolor;
content: '';
inline-size: 0.5rem;
rotate: 45deg;
translate: 0.125rem 0;
}
slab-calendar::part(previous):hover,
slab-calendar::part(next):hover {
background-color: var(--chalk);
}
slab-calendar::part(previous):focus-visible,
slab-calendar::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-calendar::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
/*
Separate rather than collapsed, so each day draws its own border whole.
Collapsed, a day's border merges with its neighbors' and today's ring
breaks up.
*/
slab-calendar::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
slab-calendar::part(weekday) {
color: var(--ash);
font-family: var(--font-mono);
font-size: 0.75rem;
font-weight: 400;
padding-block-end: 0.375rem;
text-transform: uppercase;
}
slab-calendar::part(day) {
block-size: 2.5rem;
border: 2px solid transparent;
box-sizing: border-box;
cursor: pointer;
inline-size: 2.5rem;
text-align: center;
transition:
background-color 100ms,
color 100ms;
}
slab-calendar::part(day):hover {
background-color: var(--chalk);
}
slab-calendar::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
slab-calendar::part(today) {
border-color: var(--ember);
}
/*
The ring is inside the day, so on the selected one it's on ink, where
ember falls short of 3:1 in the dark. The text's color always has the
contrast.
*/
slab-calendar::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-calendar::part(selected):hover {
background-color: var(--ink);
}
slab-calendar::part(selected):focus-visible {
outline-color: currentcolor;
}
/*
While a range is being picked, the days it would cover are hatched, so
they don't read as chosen yet. Once it's picked, they're a band of chalk
between its ends, which are ink like a single selected day.
*/
slab-calendar::part(preview) {
background-image: repeating-linear-gradient(
-45deg,
var(--chalk) 0 4px,
transparent 4px 8px
);
}
slab-calendar[range]::part(selected) {
background-color: var(--chalk);
background-image: none;
color: var(--ink);
font-weight: 400;
}
slab-calendar[range]::part(selected):hover {
background-color: var(--chalk);
}
slab-calendar[range]::part(selected):focus-visible {
outline-color: var(--ember);
}
slab-calendar[range]::part(range-start),
slab-calendar[range]::part(range-end) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-calendar[range]::part(range-start):hover,
slab-calendar[range]::part(range-end):hover {
background-color: var(--ink);
}
slab-calendar[range]::part(range-start):focus-visible,
slab-calendar[range]::part(range-end):focus-visible {
outline-color: currentcolor;
}
slab-calendar::part(disabled) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
slab-calendar::part(disabled):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
slab-calendar::part(previous),
slab-calendar::part(next),
slab-calendar::part(day) {
transition: none;
}
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}