Form
Date Time Picker
A Date Time Field with a button that opens a Calendar and a time input in a popover, so the picker is the same in every browser and yours to style.
- Element
<slab-date-time-picker>- Built on
<input type=datetime-local>
Example
Here's a styled version, <slab-styled-date-time-picker>. 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. Open either one in StackBlitz to change it and watch it run.
<slab-styled-date-time-picker label="Pour starts" min="2026-11-30T06:00" time-zone="America/Chicago" time-zones="America/New_York America/Chicago America/Denver America/Los_Angeles" value="2026-12-02T07:30">
<span slot="description">In the job site's time zone. Trucks leave the plant an hour before.</span>
</slab-styled-date-time-picker>
<slab-date-time-picker label="Pour starts" min="2026-11-30T06:00" time-zone="America/Chicago" time-zones="America/New_York America/Chicago America/Denver America/Los_Angeles" value="2026-12-02T07:30">
<span slot="description">In the job site's time zone. Trucks leave the plant an hour before.</span>
</slab-date-time-picker>
Usage
pnpm add slab-elements lit
import 'slab-elements/date-time-picker.js';
export function MyDateTimePicker() {
return (
<slab-date-time-picker label="Starts" name="starts" time-zone-name="starts-time-zone" required></slab-date-time-picker>
);
}
MyDateTimePicker.jsx React 19 or later, which sets props on custom elements as properties.
import 'slab-elements/date-time-picker.js';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('my-date-time-picker')
export class MyDateTimePicker extends LitElement {
render() {
return html`
<slab-date-time-picker label="Starts" name="starts" time-zone-name="starts-time-zone" required></slab-date-time-picker>
`;
}
}
my-date-time-picker.ts Slab is built on Lit, so its elements are at home in Lit's templates.
<script setup>
import 'slab-elements/date-time-picker.js';
</script>
<template>
<slab-date-time-picker label="Starts" name="starts" time-zone-name="starts-time-zone" required></slab-date-time-picker>
</template>
MyDateTimePicker.vue Let Vue's compiler know slab- tags are custom elements with isCustomElement.
<script>
import 'slab-elements/date-time-picker.js';
</script>
<slab-date-time-picker label="Starts" name="starts" time-zone-name="starts-time-zone" required></slab-date-time-picker>
MyDateTimePicker.svelte Svelte binds properties and events to custom elements like any other element.
import 'slab-elements/date-time-picker.js';
export const MyDateTimePicker = <template>
<slab-date-time-picker label="Starts" name="starts" time-zone-name="starts-time-zone" required></slab-date-time-picker>
</template>;
MyDateTimePicker.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/date-time-picker.js';
</script>
<slab-date-time-picker label="Starts" name="starts" time-zone-name="starts-time-zone" required></slab-date-time-picker>
index.html Any bundler (or an import map) takes care of the imports.
It’s Date Time Field, so the input, the value, the time zone select, validity and the form all work the same. The browser’s own picker is hidden where it can be, and the button beside the input opens a Calendar and a native time input in a non-modal dialog named by the label. Firefox keeps its own icon in the input, which can’t be hidden.
Picking a day and a time
Picking a day sets the value’s date and keeps its time. Changing the time sets the value’s time. Each dispatches “input” and “change”, as typing does, and the picker stays open, so a day and then a time can be picked in one go. Escape and a click outside close it, and focus goes back to the button when it closes from inside.
Like a native datetime-local input, it has no value until it has a date and a time. With no value, a time picked first waits in the time input until a day is picked, and a day picked first takes midnight, which the time input then changes.
const picker = document.querySelector('slab-date-time-picker');
picker.addEventListener('change', () => {
picker.value; // "2026-12-02T07:30"
});
Opening it focuses the selected day, or else today, kept between the days of min and max. open reflects whether it’s open, and showPicker() and hidePicker() open and close it. Like a native input’s, showPicker() only works from a user gesture, such as a click, and throws while it’s disabled or read-only.
The Calendar gets the days of min and max, so days outside them can’t be picked. A time before min on its day, or after max on its, can still be picked, and is a rangeUnderflow or rangeOverflow, as it would be typed into the input. step is passed to the time input. months, week-start and isDateUnavailable are passed to the Calendar, as on Date Picker.
The button is named “Choose date and time” and the time input “Time”, which button-label and time-label, or registerStrings()’s dateTimePickerButton and dateTimePickerTime, change. The Calendar’s parts are exported with the same names, so style its days with ::part(day), ::part(selected) and the rest, and the time input with ::part(time).
Keyboard
| Key | What it does |
|---|---|
| Alt+Down | In the input, opens the picker. |
| Enter, Space | On the button, opens or closes the picker. On a day, picks it. |
| Tab | Moves from the Calendar to the time input, and back. |
| Up, Down | In the time input, steps the focused part of the time. |
| Escape | Closes the picker, and focuses the button. |
| Arrows, Page Up/Down | On the Calendar, moves between days and months, as on Calendar. |
| Enter (in the input) | Submits the form. |
Behavior
A date and time picker with no visual styles: a Date Time Field, with a button beside its input that opens a Calendar and a time input in a popover, as Date Picker does for a date.
It's Date Time Field, so everything a Date Time Field does it does too: the native <input type="datetime-local"> to type into, its value, its time zone select, min, max, step, required, validity, and taking part in a form. Only the picker is different. The browser's own is hidden where it can be, and a Calendar and a native <input type="time"> are used instead, so the picker is the same in every browser and can be styled. Firefox keeps an icon of its own in the input, which can't be hidden.
The button opens and closes a non-modal role="dialog", named by the field's label, with a Calendar and a time input in it. The button says "Choose date and time" unless button-label is set, and is aria-expanded while the picker is open. Alt+ArrowDown in the input opens it too. Opening it focuses the selected day, or else today, kept between the days of min and max.
Picking a day sets the value's date and keeps its time, or takes the time input's, or midnight when that's empty too. Changing the time sets the value's time once there's a day, as a native datetime-local input has no value until it has both. Each dispatches "input" and "change" as typing does. The picker stays open, so a day and then a time can be picked, and Escape and a click outside close it, the way a native popover closes. Focus goes back to the button when it closes from inside.
week-start, months and isDateUnavailable are passed to the Calendar, and so are the days of min and max, so days outside them can't be picked. A time outside them on the first or last day can, and is a rangeUnderflow or rangeOverflow, as on the input. step is passed to the time input. The Calendar's language is the field's nearest lang.
open reflects whether the picker is open, and setting it opens or closes the picker, as showPicker() and hidePicker() do.
Style the field through Date Time Field's parts and states, the button through ::part(button) and :host([open]), the popover through ::part(popover), the time input through ::part(time), and the Calendar through its own parts, which are exported with the same names.
API
<slab-date-time-picker>
| Name | Type | Default | Description |
|---|---|---|---|
button-label
|
string |
The button's text and so its accessible name. "Choose date and time" in English when unset. | |
months
|
number |
1 |
How many months the Calendar shows side by side. |
open
|
boolean |
false |
Whether the picker is open, however it got there or went away. Setting it opens or closes the picker. |
time-label
|
string |
The time input's label, and so its accessible name. "Time" in English when unset. | |
week-start
|
number |
0 |
The day the Calendar's weeks start on, from 0 for Sunday to 6 for Saturday. |
label
Required
|
string |
Names it. It's the accessible name, and the visible label where there is one. | |
autocomplete
|
HTMLInputElement['autocomplete'] |
What the browser may fill it with, as a native input's autocomplete says. |
|
disabled
|
boolean |
false |
Disables it, as disabled does a native control: the user can't focus or use it, and a form control's value isn't submitted. |
hide-label
|
boolean |
false |
Hides the label visually and leaves it as the accessible name, for a design that shows the label some other way. |
max
|
string |
The latest date and time allowed, as "yyyy-mm-ddThh:mm". | |
min
|
string |
The earliest date and time allowed, as "yyyy-mm-ddThh:mm". Also where step counts from. |
|
name
|
string |
'' |
The name its value is submitted under, as a native control's name. |
readonly
|
boolean |
false |
Lets the user select the value but not change it, as readonly does a native input. The value is still submitted. |
required
|
boolean |
false |
Makes it invalid while it has no value, as required does a native control. |
step
|
string |
In seconds, or "any". 60 when unset, so there's no seconds to fill in. Counted from min when there is one. |
|
time-zone
|
string |
An IANA time zone name, such as "America/New_York". The browser's own when unset, and when it's a time zone the browser doesn't know. Like value, the attribute is the default and the property is the current one, so the attribute doesn't change as the person picks another. |
|
time-zone-label
|
string |
The select's label, and so its accessible name along with label. "Time zone" in English when unset. |
|
time-zone-name
|
string |
The name the time zone is submitted under. It isn't submitted when unset, as a native select without a name isn't. |
|
time-zones
|
string |
The time zones to choose from, as space-separated IANA names, in the order they're listed. Every time zone the browser knows when unset. The current one is always listed, even when it isn't one of these. | |
value
|
string |
'' |
A "yyyy-mm-ddThh:mm" string, with ":ss" and ".sss" when it has them. Like a native input, the attribute is the default value and the property is the current one, so the attribute doesn't change as the field is edited. |
custom-validity
|
string |
Makes it invalid with this message, as setCustomValidity() does, and shows the message at once rather than once validity is reported, for an error the page already knows about, such as one from a server. Removing it, or setting it to an empty string, makes it valid again, unless something else makes it invalid. |
| Name | Type | Description |
|---|---|---|
isDateUnavailable
|
(date: string) => boolean | undefined |
Whether a day can't be picked in the Calendar, from that day as "yyyy-mm-dd", for days such as weekends or ones already booked. It's passed to the Calendar. A day typed into the input isn't checked against it, as validity is the native input's. |
defaultValue
|
string |
The value it starts with, and goes back to when its form resets. It's the value attribute, as a native input's defaultValue is, so setting it sets the attribute, and value with it. |
form
Read-only
|
HTMLFormElement | null |
The form it belongs to, or null. |
labels
Read-only
|
NodeList |
The <label> elements associated with it, as a native control's labels: each <label for> that names its id, and a <label> around it. |
validationMessage
Read-only
|
string |
What's wrong, as the validity message says it: the message given to setCustomValidity() or setValidity(), or else the browser's own. Empty while it's valid. |
validity
Read-only
|
ValidityState |
Its ValidityState, as a native control's. |
willValidate
Read-only
|
boolean |
Whether its validity is checked when its form submits. It isn't while it's disabled or read-only. |
valueAsDate
|
Date | null |
The moment value is in timeZone, as a Date, or null when empty. A native datetime-local input's is always null, since it has no time zone. A time that happens twice, when clocks go back, is the earlier one, and a time that never happens, when they go forward, is moved forward by the gap. Setting it sets value to the Date's wall-clock time in timeZone. |
| Signature | Description |
|---|---|
checkValidity(): boolean
|
Whether its value is valid. Dispatches "invalid" when it isn't, as a native control's does. |
click(): void
|
Clicks it, as a native element's click() does. |
focus(options?: FocusOptions): void
|
Focuses it, or the part of it that takes focus. |
hidePicker(): void
|
Closes the picker. |
reportValidity(): boolean
|
Whether its value is valid. When it isn't, dispatches "invalid" and shows the validity message, as a native control's does. |
resetValidityFeedback(): void
|
Clears the validity feedback without changing validity. |
setCustomValidity(message: string): void
|
Makes it invalid with a message of your own, or valid again with an empty one, as a native control's does. |
setValidity(flags?: ValidityStateFlags, message?: string): void
|
Sets its validity and message, as ElementInternals.setValidity() does, for checks of your own beyond setCustomValidity(). |
showPicker(): void
|
Opens the picker and focuses the Calendar's tabbable day. As a native input's, it throws without a user gesture, or while it's disabled or read-only. |
| Name | Type | Description |
|---|---|---|
input
|
Event |
As the user changes its value or its time zone, as a native control's does. Setting either from code doesn't dispatch it. |
change
|
Event |
When the user changes its value or its time zone, as a native control's does. Setting either from code doesn't dispatch it. |
beforetoggle
|
ToggleEvent |
Before it opens or closes, as a ToggleEvent that doesn't bubble. Cancel it while it's opening to keep it closed. |
toggle
|
ToggleEvent |
When it opens or closes, as a ToggleEvent with oldState and newState that doesn't bubble, as a popover's does. |
invalid
|
Event |
When a check finds its value invalid, as a native control's does. Cancel it to leave the validity message unshown, after a blur, a submit or reportValidity(), and focus where it is. |
| Name | Type | Description |
|---|---|---|
description
|
Element | string |
Text that describes it, such as a hint or what the validity message means. It's its accessible description. |
validity-message
|
Element | string |
Shown in place of the validity message's text while it's invalid and the message shows, for wording of your own, a translation, or a link. It's part of its accessible description, and validationMessage stays the browser's or setCustomValidity()'s. |
| Name | Description |
|---|---|
button
|
Opens and closes the picker |
calendar
|
The Calendar in the popover |
control
|
The input and the button |
description
|
Text about the field, and its validity message when it has one |
fields
|
The input, and the select with its label |
input
|
The input |
label
|
The label |
popover
|
The popover the Calendar and the time input are in |
time
|
The time input |
time-field
|
The time input and its label |
time-label
|
The time input's label |
time-zone
|
The time zone select |
time-zone-field
|
The select and its label |
time-zone-label
|
The select's label |
validity-message
|
The validity message, which says why the value is invalid |
| Name | Description |
|---|---|
:state(disabled)
|
While it's disabled. |
:state(error)
|
While it's invalid and its validity message shows, which is once its validity is reported, as when its form is submitted. |
:state(open)
|
While it's open. |
:state(readonly)
|
While it's read-only. |
:state(required)
|
While it's required, for styles such as an asterisk. |
Copy and own it
<slab-styled-date-time-picker> 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-date-time-picker> 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.
DateTimePicker.jsx
import 'slab-elements/date-time-picker.js';
import './date-time-picker.css';
export function DateTimePicker(props) {
return <slab-date-time-picker {...props} />;
}
date-time-picker.css
slab-date-time-picker {
color: var(--ink);
display: grid;
font-family: var(--font-body);
}
slab-date-time-picker::part(label) {
font-family: var(--font-display);
font-size: 1.0625rem;
font-weight: 600;
margin-block-end: 0.375rem;
}
slab-date-time-picker:state(required)::part(label)::after {
color: var(--ember-deep);
content: ' *' / '';
}
slab-date-time-picker::part(input),
slab-date-time-picker::part(textarea) {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
/* A fixed height, shared with Select, so fields line up in a row. */
padding: 0 0.75rem;
transition:
background-color 100ms,
border-color 100ms,
box-shadow 100ms,
translate 100ms;
}
slab-date-time-picker::part(input)::placeholder,
slab-date-time-picker::part(textarea)::placeholder {
color: var(--ash);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(input):focus-visible,
slab-date-time-picker::part(textarea):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(input):disabled,
slab-date-time-picker::part(textarea):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker::part(textarea) {
block-size: auto;
min-block-size: 7rem;
padding: 0.625rem 0.75rem;
resize: vertical;
}
slab-date-time-picker:state(readonly)::part(input),
slab-date-time-picker:state(readonly)::part(textarea) {
background-color: var(--chalk);
}
slab-date-time-picker:state(error)::part(input),
slab-date-time-picker:state(error)::part(textarea) {
border-color: var(--ember-deep);
}
/*
Spaced by what's in it rather than by a gap, so a description with
nothing in it takes no room, and a control beside the field lines up
with its bottom edge.
*/
slab-date-time-picker::part(description) {
color: var(--ash);
display: grid;
font-size: 0.875rem;
}
slab-date-time-picker > [slot='description'] {
margin-block-start: 0.375rem;
}
slab-date-time-picker::part(validity-message) {
color: var(--ember-deep);
font-weight: 600;
margin-block-start: 0.375rem;
}
slab-date-time-picker::part(validity-message)::before {
content: '■ ' / '';
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(input),
slab-date-time-picker::part(textarea) {
transition: none;
}
}
/*
The input and the select share a row, lined up along their bottom edges,
since only the select has a small label above it.
*/
slab-date-time-picker::part(fields) {
align-items: end;
display: grid;
gap: 0.75rem;
grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}
slab-date-time-picker::part(time-zone-field) {
display: grid;
gap: 0.25rem;
}
slab-date-time-picker::part(time-zone-label) {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
/*
The select's own chevron is the browser's, and sits wherever the browser
puts it. It's drawn here instead, as two strokes of the text color, so it
lines up with the input's calendar icon and follows dark mode and forced
colors.
*/
slab-date-time-picker::part(time-zone) {
appearance: none;
background-color: var(--paper);
background-image:
linear-gradient(
to top right,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
),
linear-gradient(
to top left,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
);
background-position:
right 1.375rem center,
right 1rem center;
background-repeat: no-repeat;
background-size: 0.375rem 0.375rem;
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
cursor: pointer;
font: inherit;
inline-size: 100%;
min-inline-size: 0;
padding-block: 0;
padding-inline: 0.75rem 2.5rem;
transition:
border-color 100ms,
box-shadow 100ms,
translate 100ms;
}
slab-date-time-picker::part(time-zone):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(time-zone):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker:state(readonly)::part(time-zone) {
border-style: solid;
color: inherit;
cursor: default;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(time-zone) {
transition: none;
}
}
slab-date-time-picker::part(control) {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
}
/*
Butted against the input, sharing its border. It has no height of its own
and is stretched to the input's, so the two match in every browser, even
one that sizes a date input its own way. Its text is its accessible name,
so it stays, at no size, and a calendar is drawn in its place.
*/
slab-date-time-picker::part(button) {
align-items: center;
align-self: stretch;
background-color: var(--paper);
border: var(--border);
border-radius: 0;
color: inherit;
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 3rem;
justify-content: center;
margin-inline-start: -2px;
padding: 0;
transition:
background-color 100ms,
box-shadow 100ms,
color 100ms,
translate 100ms;
}
slab-date-time-picker::part(button)::before {
block-size: 0.875rem;
border: 2px solid currentcolor;
border-block-start-width: 5px;
content: '';
inline-size: 1rem;
}
slab-date-time-picker::part(button):hover {
background-color: var(--chalk);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(button):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(button):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker[open]::part(button) {
background-color: var(--ink);
color: var(--paper);
}
slab-date-time-picker:state(error)::part(button) {
border-color: var(--ember-deep);
}
/* A closed popover isn't displayed, so the entrance runs each time it opens. */
slab-date-time-picker::part(popover) {
animation: slab-date-time-picker-drop 150ms ease-out;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
margin-block: 0.5rem;
padding: 1rem;
}
@keyframes slab-date-time-picker-drop {
from {
opacity: 0;
translate: 0 -0.375rem;
}
}
slab-date-time-picker::part(calendar)::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
slab-date-time-picker::part(calendar)::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
slab-date-time-picker::part(calendar)::part(previous),
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(previous)::before,
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
slab-date-time-picker::part(calendar)::part(previous):hover,
slab-date-time-picker::part(calendar)::part(next):hover {
background-color: var(--chalk);
}
slab-date-time-picker::part(calendar)::part(previous):focus-visible,
slab-date-time-picker::part(calendar)::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
/*
With months, the months sit side by side, and wrap where there isn't room
for them all.
*/
slab-date-time-picker::part(calendar)::part(months) {
display: flex;
flex-wrap: wrap;
gap: 1rem 1.5rem;
}
slab-date-time-picker::part(calendar)::part(month-heading) {
display: block;
font-family: var(--font-mono);
font-size: 0.75rem;
margin-block-end: 0.5rem;
text-align: center;
text-transform: uppercase;
}
/*
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-date-time-picker::part(calendar)::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
slab-date-time-picker::part(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-date-time-picker::part(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-date-time-picker::part(calendar)::part(day):hover {
background-color: var(--chalk);
}
slab-date-time-picker::part(calendar)::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-date-time-picker::part(calendar)::part(selected):focus-visible {
outline-color: currentcolor;
}
slab-date-time-picker::part(calendar)::part(disabled),
slab-date-time-picker::part(calendar)::part(unavailable) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
slab-date-time-picker::part(calendar)::part(disabled):hover,
slab-date-time-picker::part(calendar)::part(unavailable):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(button),
slab-date-time-picker::part(popover),
slab-date-time-picker::part(calendar)::part(previous),
slab-date-time-picker::part(calendar)::part(next),
slab-date-time-picker::part(calendar)::part(day) {
animation: none;
transition: none;
}
}
slab-date-time-picker::part(time-field) {
border-block-start: var(--border);
display: grid;
gap: 0.25rem;
margin-block-start: 1rem;
padding-block-start: 1rem;
}
slab-date-time-picker::part(time-label) {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
slab-date-time-picker::part(time) {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
padding: 0 0.75rem;
transition:
box-shadow 100ms,
translate 100ms;
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(time):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(time) {
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.
date-time-picker.ts
import { customElement } from 'lit/decorators.js';
import DateTimePicker from 'slab-elements/date-time-picker.js';
import datePicker from './date-picker.styles.js';
import dateTimeField from './date-time-field.styles.js';
import styles from './date-time-picker.styles.js';
import textInput from './text-input.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-date-time-picker': StyledDateTimePicker;
}
}
/**
* Date Time Picker, styled: Date Time Field's look, with Date Picker's
* calendar button butted against the input and its styled Calendar in a
* raised popover below, with the time input under the Calendar.
*/
@customElement('slab-styled-date-time-picker')
export default class StyledDateTimePicker extends DateTimePicker {
static override styles = [
tokens,
textInput,
dateTimeField,
datePicker,
styles,
];
}
date-picker.styles.ts
import { css } from 'lit';
/*
The Calendar is in this shadow root rather than slotted, so its days are
styled through the parts it exports, the way the styled Calendar styles
them from inside its own.
*/
export default css`
[part~='control'] {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
}
/*
Butted against the input, sharing its border. It has no height of its own
and is stretched to the input's, so the two match in every browser, even
one that sizes a date input its own way. Its text is its accessible name,
so it stays, at no size, and a calendar is drawn in its place.
*/
[part~='button'] {
align-items: center;
align-self: stretch;
background-color: var(--paper);
border: var(--border);
border-radius: 0;
color: inherit;
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 3rem;
justify-content: center;
margin-inline-start: -2px;
padding: 0;
transition:
background-color 100ms,
box-shadow 100ms,
color 100ms,
translate 100ms;
&::before {
block-size: 0.875rem;
border: 2px solid currentcolor;
border-block-start-width: 5px;
content: '';
inline-size: 1rem;
}
&:hover {
background-color: var(--chalk);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
&:focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
&:disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
}
:host([open]) [part~='button'] {
background-color: var(--ink);
color: var(--paper);
}
:host(:state(error)) [part~='button'] {
border-color: var(--ember-deep);
}
/* A closed popover isn't displayed, so the entrance runs each time it opens. */
[part~='popover'] {
animation: drop 150ms ease-out;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
margin-block: 0.5rem;
padding: 1rem;
}
@keyframes drop {
from {
opacity: 0;
translate: 0 -0.375rem;
}
}
[part~='calendar']::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
[part~='calendar']::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
[part~='calendar']::part(previous),
[part~='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;
}
[part~='calendar']::part(previous)::before,
[part~='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;
}
[part~='calendar']::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
[part~='calendar']::part(previous):hover,
[part~='calendar']::part(next):hover {
background-color: var(--chalk);
}
[part~='calendar']::part(previous):focus-visible,
[part~='calendar']::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
/*
With months, the months sit side by side, and wrap where there isn't room
for them all.
*/
[part~='calendar']::part(months) {
display: flex;
flex-wrap: wrap;
gap: 1rem 1.5rem;
}
[part~='calendar']::part(month-heading) {
display: block;
font-family: var(--font-mono);
font-size: 0.75rem;
margin-block-end: 0.5rem;
text-align: center;
text-transform: uppercase;
}
/*
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~='calendar']::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
[part~='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;
}
[part~='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;
}
[part~='calendar']::part(day):hover {
background-color: var(--chalk);
}
[part~='calendar']::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
[part~='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.
*/
[part~='calendar']::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
[part~='calendar']::part(selected):focus-visible {
outline-color: currentcolor;
}
[part~='calendar']::part(disabled),
[part~='calendar']::part(unavailable) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
[part~='calendar']::part(disabled):hover,
[part~='calendar']::part(unavailable):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
[part~='button'],
[part~='popover'],
[part~='calendar']::part(previous),
[part~='calendar']::part(next),
[part~='calendar']::part(day) {
animation: none;
transition: none;
}
}
`;
date-time-field.styles.ts
import { css } from 'lit';
export default css`
/*
The input and the select share a row, lined up along their bottom edges,
since only the select has a small label above it.
*/
[part~='fields'] {
align-items: end;
display: grid;
gap: 0.75rem;
grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}
[part~='time-zone-field'] {
display: grid;
gap: 0.25rem;
}
[part~='time-zone-label'] {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
/*
The select's own chevron is the browser's, and sits wherever the browser
puts it. It's drawn here instead, as two strokes of the text color, so it
lines up with the input's calendar icon and follows dark mode and forced
colors.
*/
[part~='time-zone'] {
appearance: none;
background-color: var(--paper);
background-image:
linear-gradient(
to top right,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
),
linear-gradient(
to top left,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
);
background-position:
right 1.375rem center,
right 1rem center;
background-repeat: no-repeat;
background-size: 0.375rem 0.375rem;
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
cursor: pointer;
font: inherit;
inline-size: 100%;
min-inline-size: 0;
padding-block: 0;
padding-inline: 0.75rem 2.5rem;
transition:
border-color 100ms,
box-shadow 100ms,
translate 100ms;
&:focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
&:disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
}
:host(:state(readonly)) [part~='time-zone'] {
border-style: solid;
color: inherit;
cursor: default;
}
@media (prefers-reduced-motion: reduce) {
[part~='time-zone'] {
transition: none;
}
}
`;
date-time-picker.styles.ts
import { css } from 'lit';
/*
On top of Date Time Field's and Date Picker's: the time input sits under the
Calendar, with a small label of its own like the time zone select's, and
takes the input's look.
*/
export default css`
[part~='time-field'] {
border-block-start: var(--border);
display: grid;
gap: 0.25rem;
margin-block-start: 1rem;
padding-block-start: 1rem;
}
[part~='time-label'] {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
[part~='time'] {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
padding: 0 0.75rem;
transition:
box-shadow 100ms,
translate 100ms;
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
&:focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
@media (prefers-reduced-motion: reduce) {
transition: none;
}
}
`;
text-input.styles.ts
import { css } from 'lit';
/*
The look shared by everything typed into: Text Field, Password Field,
Search Field, Textarea, Number, Date Field, Time Field, Combobox and Tags
Input, whose fields are "::part(input)", or "::part(textarea)" for Textarea.
File Drop starts from it too, for its label and description.
*/
export default css`
:host {
color: var(--ink);
display: grid;
font-family: var(--font-body);
}
[part~='label'] {
font-family: var(--font-display);
font-size: 1.0625rem;
font-weight: 600;
margin-block-end: 0.375rem;
}
:host(:state(required)) [part~='label']::after {
color: var(--ember-deep);
content: ' *' / '';
}
[part~='input'],
[part~='textarea'] {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
/* A fixed height, shared with Select, so fields line up in a row. */
padding: 0 0.75rem;
transition:
background-color 100ms,
border-color 100ms,
box-shadow 100ms,
translate 100ms;
&::placeholder {
color: var(--ash);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
&:focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
&:disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
}
[part~='textarea'] {
block-size: auto;
min-block-size: 7rem;
padding: 0.625rem 0.75rem;
resize: vertical;
}
:host(:state(readonly)) [part~='input'],
:host(:state(readonly)) [part~='textarea'] {
background-color: var(--chalk);
}
:host(:state(error)) [part~='input'],
:host(:state(error)) [part~='textarea'] {
border-color: var(--ember-deep);
}
/*
Spaced by what's in it rather than by a gap, so a description with
nothing in it takes no room, and a control beside the field lines up
with its bottom edge.
*/
[part~='description'] {
color: var(--ash);
display: grid;
font-size: 0.875rem;
}
::slotted([slot='description']) {
margin-block-start: 0.375rem;
}
[part~='validity-message'] {
color: var(--ember-deep);
font-weight: 600;
margin-block-start: 0.375rem;
&::before {
content: '■ ' / '';
}
}
@media (prefers-reduced-motion: reduce) {
[part~='input'],
[part~='textarea'] {
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-date-time-picker> 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.
DateTimePicker.vue
<script setup>
import 'slab-elements/date-time-picker.js';
import './date-time-picker.css';
</script>
<template>
<slab-date-time-picker><slot /></slab-date-time-picker>
</template>
date-time-picker.css
slab-date-time-picker {
color: var(--ink);
display: grid;
font-family: var(--font-body);
}
slab-date-time-picker::part(label) {
font-family: var(--font-display);
font-size: 1.0625rem;
font-weight: 600;
margin-block-end: 0.375rem;
}
slab-date-time-picker:state(required)::part(label)::after {
color: var(--ember-deep);
content: ' *' / '';
}
slab-date-time-picker::part(input),
slab-date-time-picker::part(textarea) {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
/* A fixed height, shared with Select, so fields line up in a row. */
padding: 0 0.75rem;
transition:
background-color 100ms,
border-color 100ms,
box-shadow 100ms,
translate 100ms;
}
slab-date-time-picker::part(input)::placeholder,
slab-date-time-picker::part(textarea)::placeholder {
color: var(--ash);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(input):focus-visible,
slab-date-time-picker::part(textarea):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(input):disabled,
slab-date-time-picker::part(textarea):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker::part(textarea) {
block-size: auto;
min-block-size: 7rem;
padding: 0.625rem 0.75rem;
resize: vertical;
}
slab-date-time-picker:state(readonly)::part(input),
slab-date-time-picker:state(readonly)::part(textarea) {
background-color: var(--chalk);
}
slab-date-time-picker:state(error)::part(input),
slab-date-time-picker:state(error)::part(textarea) {
border-color: var(--ember-deep);
}
/*
Spaced by what's in it rather than by a gap, so a description with
nothing in it takes no room, and a control beside the field lines up
with its bottom edge.
*/
slab-date-time-picker::part(description) {
color: var(--ash);
display: grid;
font-size: 0.875rem;
}
slab-date-time-picker > [slot='description'] {
margin-block-start: 0.375rem;
}
slab-date-time-picker::part(validity-message) {
color: var(--ember-deep);
font-weight: 600;
margin-block-start: 0.375rem;
}
slab-date-time-picker::part(validity-message)::before {
content: '■ ' / '';
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(input),
slab-date-time-picker::part(textarea) {
transition: none;
}
}
/*
The input and the select share a row, lined up along their bottom edges,
since only the select has a small label above it.
*/
slab-date-time-picker::part(fields) {
align-items: end;
display: grid;
gap: 0.75rem;
grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}
slab-date-time-picker::part(time-zone-field) {
display: grid;
gap: 0.25rem;
}
slab-date-time-picker::part(time-zone-label) {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
/*
The select's own chevron is the browser's, and sits wherever the browser
puts it. It's drawn here instead, as two strokes of the text color, so it
lines up with the input's calendar icon and follows dark mode and forced
colors.
*/
slab-date-time-picker::part(time-zone) {
appearance: none;
background-color: var(--paper);
background-image:
linear-gradient(
to top right,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
),
linear-gradient(
to top left,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
);
background-position:
right 1.375rem center,
right 1rem center;
background-repeat: no-repeat;
background-size: 0.375rem 0.375rem;
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
cursor: pointer;
font: inherit;
inline-size: 100%;
min-inline-size: 0;
padding-block: 0;
padding-inline: 0.75rem 2.5rem;
transition:
border-color 100ms,
box-shadow 100ms,
translate 100ms;
}
slab-date-time-picker::part(time-zone):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(time-zone):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker:state(readonly)::part(time-zone) {
border-style: solid;
color: inherit;
cursor: default;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(time-zone) {
transition: none;
}
}
slab-date-time-picker::part(control) {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
}
/*
Butted against the input, sharing its border. It has no height of its own
and is stretched to the input's, so the two match in every browser, even
one that sizes a date input its own way. Its text is its accessible name,
so it stays, at no size, and a calendar is drawn in its place.
*/
slab-date-time-picker::part(button) {
align-items: center;
align-self: stretch;
background-color: var(--paper);
border: var(--border);
border-radius: 0;
color: inherit;
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 3rem;
justify-content: center;
margin-inline-start: -2px;
padding: 0;
transition:
background-color 100ms,
box-shadow 100ms,
color 100ms,
translate 100ms;
}
slab-date-time-picker::part(button)::before {
block-size: 0.875rem;
border: 2px solid currentcolor;
border-block-start-width: 5px;
content: '';
inline-size: 1rem;
}
slab-date-time-picker::part(button):hover {
background-color: var(--chalk);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(button):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(button):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker[open]::part(button) {
background-color: var(--ink);
color: var(--paper);
}
slab-date-time-picker:state(error)::part(button) {
border-color: var(--ember-deep);
}
/* A closed popover isn't displayed, so the entrance runs each time it opens. */
slab-date-time-picker::part(popover) {
animation: slab-date-time-picker-drop 150ms ease-out;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
margin-block: 0.5rem;
padding: 1rem;
}
@keyframes slab-date-time-picker-drop {
from {
opacity: 0;
translate: 0 -0.375rem;
}
}
slab-date-time-picker::part(calendar)::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
slab-date-time-picker::part(calendar)::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
slab-date-time-picker::part(calendar)::part(previous),
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(previous)::before,
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
slab-date-time-picker::part(calendar)::part(previous):hover,
slab-date-time-picker::part(calendar)::part(next):hover {
background-color: var(--chalk);
}
slab-date-time-picker::part(calendar)::part(previous):focus-visible,
slab-date-time-picker::part(calendar)::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
/*
With months, the months sit side by side, and wrap where there isn't room
for them all.
*/
slab-date-time-picker::part(calendar)::part(months) {
display: flex;
flex-wrap: wrap;
gap: 1rem 1.5rem;
}
slab-date-time-picker::part(calendar)::part(month-heading) {
display: block;
font-family: var(--font-mono);
font-size: 0.75rem;
margin-block-end: 0.5rem;
text-align: center;
text-transform: uppercase;
}
/*
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-date-time-picker::part(calendar)::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
slab-date-time-picker::part(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-date-time-picker::part(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-date-time-picker::part(calendar)::part(day):hover {
background-color: var(--chalk);
}
slab-date-time-picker::part(calendar)::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-date-time-picker::part(calendar)::part(selected):focus-visible {
outline-color: currentcolor;
}
slab-date-time-picker::part(calendar)::part(disabled),
slab-date-time-picker::part(calendar)::part(unavailable) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
slab-date-time-picker::part(calendar)::part(disabled):hover,
slab-date-time-picker::part(calendar)::part(unavailable):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(button),
slab-date-time-picker::part(popover),
slab-date-time-picker::part(calendar)::part(previous),
slab-date-time-picker::part(calendar)::part(next),
slab-date-time-picker::part(calendar)::part(day) {
animation: none;
transition: none;
}
}
slab-date-time-picker::part(time-field) {
border-block-start: var(--border);
display: grid;
gap: 0.25rem;
margin-block-start: 1rem;
padding-block-start: 1rem;
}
slab-date-time-picker::part(time-label) {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
slab-date-time-picker::part(time) {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
padding: 0 0.75rem;
transition:
box-shadow 100ms,
translate 100ms;
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(time):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(time) {
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-date-time-picker> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Import date-time-picker.js once, such
as in your root layout, and use
<slab-date-time-picker> as is. A Svelte component
around it would take slot="…" content as its
own slot and drop it.
date-time-picker.js
import 'slab-elements/date-time-picker.js';
import './date-time-picker.css';
date-time-picker.css
slab-date-time-picker {
color: var(--ink);
display: grid;
font-family: var(--font-body);
}
slab-date-time-picker::part(label) {
font-family: var(--font-display);
font-size: 1.0625rem;
font-weight: 600;
margin-block-end: 0.375rem;
}
slab-date-time-picker:state(required)::part(label)::after {
color: var(--ember-deep);
content: ' *' / '';
}
slab-date-time-picker::part(input),
slab-date-time-picker::part(textarea) {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
/* A fixed height, shared with Select, so fields line up in a row. */
padding: 0 0.75rem;
transition:
background-color 100ms,
border-color 100ms,
box-shadow 100ms,
translate 100ms;
}
slab-date-time-picker::part(input)::placeholder,
slab-date-time-picker::part(textarea)::placeholder {
color: var(--ash);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(input):focus-visible,
slab-date-time-picker::part(textarea):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(input):disabled,
slab-date-time-picker::part(textarea):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker::part(textarea) {
block-size: auto;
min-block-size: 7rem;
padding: 0.625rem 0.75rem;
resize: vertical;
}
slab-date-time-picker:state(readonly)::part(input),
slab-date-time-picker:state(readonly)::part(textarea) {
background-color: var(--chalk);
}
slab-date-time-picker:state(error)::part(input),
slab-date-time-picker:state(error)::part(textarea) {
border-color: var(--ember-deep);
}
/*
Spaced by what's in it rather than by a gap, so a description with
nothing in it takes no room, and a control beside the field lines up
with its bottom edge.
*/
slab-date-time-picker::part(description) {
color: var(--ash);
display: grid;
font-size: 0.875rem;
}
slab-date-time-picker > [slot='description'] {
margin-block-start: 0.375rem;
}
slab-date-time-picker::part(validity-message) {
color: var(--ember-deep);
font-weight: 600;
margin-block-start: 0.375rem;
}
slab-date-time-picker::part(validity-message)::before {
content: '■ ' / '';
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(input),
slab-date-time-picker::part(textarea) {
transition: none;
}
}
/*
The input and the select share a row, lined up along their bottom edges,
since only the select has a small label above it.
*/
slab-date-time-picker::part(fields) {
align-items: end;
display: grid;
gap: 0.75rem;
grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}
slab-date-time-picker::part(time-zone-field) {
display: grid;
gap: 0.25rem;
}
slab-date-time-picker::part(time-zone-label) {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
/*
The select's own chevron is the browser's, and sits wherever the browser
puts it. It's drawn here instead, as two strokes of the text color, so it
lines up with the input's calendar icon and follows dark mode and forced
colors.
*/
slab-date-time-picker::part(time-zone) {
appearance: none;
background-color: var(--paper);
background-image:
linear-gradient(
to top right,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
),
linear-gradient(
to top left,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
);
background-position:
right 1.375rem center,
right 1rem center;
background-repeat: no-repeat;
background-size: 0.375rem 0.375rem;
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
cursor: pointer;
font: inherit;
inline-size: 100%;
min-inline-size: 0;
padding-block: 0;
padding-inline: 0.75rem 2.5rem;
transition:
border-color 100ms,
box-shadow 100ms,
translate 100ms;
}
slab-date-time-picker::part(time-zone):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(time-zone):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker:state(readonly)::part(time-zone) {
border-style: solid;
color: inherit;
cursor: default;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(time-zone) {
transition: none;
}
}
slab-date-time-picker::part(control) {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
}
/*
Butted against the input, sharing its border. It has no height of its own
and is stretched to the input's, so the two match in every browser, even
one that sizes a date input its own way. Its text is its accessible name,
so it stays, at no size, and a calendar is drawn in its place.
*/
slab-date-time-picker::part(button) {
align-items: center;
align-self: stretch;
background-color: var(--paper);
border: var(--border);
border-radius: 0;
color: inherit;
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 3rem;
justify-content: center;
margin-inline-start: -2px;
padding: 0;
transition:
background-color 100ms,
box-shadow 100ms,
color 100ms,
translate 100ms;
}
slab-date-time-picker::part(button)::before {
block-size: 0.875rem;
border: 2px solid currentcolor;
border-block-start-width: 5px;
content: '';
inline-size: 1rem;
}
slab-date-time-picker::part(button):hover {
background-color: var(--chalk);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(button):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(button):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker[open]::part(button) {
background-color: var(--ink);
color: var(--paper);
}
slab-date-time-picker:state(error)::part(button) {
border-color: var(--ember-deep);
}
/* A closed popover isn't displayed, so the entrance runs each time it opens. */
slab-date-time-picker::part(popover) {
animation: slab-date-time-picker-drop 150ms ease-out;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
margin-block: 0.5rem;
padding: 1rem;
}
@keyframes slab-date-time-picker-drop {
from {
opacity: 0;
translate: 0 -0.375rem;
}
}
slab-date-time-picker::part(calendar)::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
slab-date-time-picker::part(calendar)::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
slab-date-time-picker::part(calendar)::part(previous),
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(previous)::before,
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
slab-date-time-picker::part(calendar)::part(previous):hover,
slab-date-time-picker::part(calendar)::part(next):hover {
background-color: var(--chalk);
}
slab-date-time-picker::part(calendar)::part(previous):focus-visible,
slab-date-time-picker::part(calendar)::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
/*
With months, the months sit side by side, and wrap where there isn't room
for them all.
*/
slab-date-time-picker::part(calendar)::part(months) {
display: flex;
flex-wrap: wrap;
gap: 1rem 1.5rem;
}
slab-date-time-picker::part(calendar)::part(month-heading) {
display: block;
font-family: var(--font-mono);
font-size: 0.75rem;
margin-block-end: 0.5rem;
text-align: center;
text-transform: uppercase;
}
/*
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-date-time-picker::part(calendar)::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
slab-date-time-picker::part(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-date-time-picker::part(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-date-time-picker::part(calendar)::part(day):hover {
background-color: var(--chalk);
}
slab-date-time-picker::part(calendar)::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-date-time-picker::part(calendar)::part(selected):focus-visible {
outline-color: currentcolor;
}
slab-date-time-picker::part(calendar)::part(disabled),
slab-date-time-picker::part(calendar)::part(unavailable) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
slab-date-time-picker::part(calendar)::part(disabled):hover,
slab-date-time-picker::part(calendar)::part(unavailable):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(button),
slab-date-time-picker::part(popover),
slab-date-time-picker::part(calendar)::part(previous),
slab-date-time-picker::part(calendar)::part(next),
slab-date-time-picker::part(calendar)::part(day) {
animation: none;
transition: none;
}
}
slab-date-time-picker::part(time-field) {
border-block-start: var(--border);
display: grid;
gap: 0.25rem;
margin-block-start: 1rem;
padding-block-start: 1rem;
}
slab-date-time-picker::part(time-label) {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
slab-date-time-picker::part(time) {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
padding: 0 0.75rem;
transition:
box-shadow 100ms,
translate 100ms;
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(time):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(time) {
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-date-time-picker> 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.
DateTimePicker.gjs
import 'slab-elements/date-time-picker.js';
import './date-time-picker.css';
export const DateTimePicker = <template>
<slab-date-time-picker ...attributes>{{yield}}</slab-date-time-picker>
</template>;
date-time-picker.css
slab-date-time-picker {
color: var(--ink);
display: grid;
font-family: var(--font-body);
}
slab-date-time-picker::part(label) {
font-family: var(--font-display);
font-size: 1.0625rem;
font-weight: 600;
margin-block-end: 0.375rem;
}
slab-date-time-picker:state(required)::part(label)::after {
color: var(--ember-deep);
content: ' *' / '';
}
slab-date-time-picker::part(input),
slab-date-time-picker::part(textarea) {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
/* A fixed height, shared with Select, so fields line up in a row. */
padding: 0 0.75rem;
transition:
background-color 100ms,
border-color 100ms,
box-shadow 100ms,
translate 100ms;
}
slab-date-time-picker::part(input)::placeholder,
slab-date-time-picker::part(textarea)::placeholder {
color: var(--ash);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(input):focus-visible,
slab-date-time-picker::part(textarea):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(input):disabled,
slab-date-time-picker::part(textarea):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker::part(textarea) {
block-size: auto;
min-block-size: 7rem;
padding: 0.625rem 0.75rem;
resize: vertical;
}
slab-date-time-picker:state(readonly)::part(input),
slab-date-time-picker:state(readonly)::part(textarea) {
background-color: var(--chalk);
}
slab-date-time-picker:state(error)::part(input),
slab-date-time-picker:state(error)::part(textarea) {
border-color: var(--ember-deep);
}
/*
Spaced by what's in it rather than by a gap, so a description with
nothing in it takes no room, and a control beside the field lines up
with its bottom edge.
*/
slab-date-time-picker::part(description) {
color: var(--ash);
display: grid;
font-size: 0.875rem;
}
slab-date-time-picker > [slot='description'] {
margin-block-start: 0.375rem;
}
slab-date-time-picker::part(validity-message) {
color: var(--ember-deep);
font-weight: 600;
margin-block-start: 0.375rem;
}
slab-date-time-picker::part(validity-message)::before {
content: '■ ' / '';
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(input),
slab-date-time-picker::part(textarea) {
transition: none;
}
}
/*
The input and the select share a row, lined up along their bottom edges,
since only the select has a small label above it.
*/
slab-date-time-picker::part(fields) {
align-items: end;
display: grid;
gap: 0.75rem;
grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}
slab-date-time-picker::part(time-zone-field) {
display: grid;
gap: 0.25rem;
}
slab-date-time-picker::part(time-zone-label) {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
/*
The select's own chevron is the browser's, and sits wherever the browser
puts it. It's drawn here instead, as two strokes of the text color, so it
lines up with the input's calendar icon and follows dark mode and forced
colors.
*/
slab-date-time-picker::part(time-zone) {
appearance: none;
background-color: var(--paper);
background-image:
linear-gradient(
to top right,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
),
linear-gradient(
to top left,
transparent calc(50% - 1px),
currentcolor calc(50% - 1px) calc(50% + 1px),
transparent calc(50% + 1px)
);
background-position:
right 1.375rem center,
right 1rem center;
background-repeat: no-repeat;
background-size: 0.375rem 0.375rem;
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
cursor: pointer;
font: inherit;
inline-size: 100%;
min-inline-size: 0;
padding-block: 0;
padding-inline: 0.75rem 2.5rem;
transition:
border-color 100ms,
box-shadow 100ms,
translate 100ms;
}
slab-date-time-picker::part(time-zone):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(time-zone):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker:state(readonly)::part(time-zone) {
border-style: solid;
color: inherit;
cursor: default;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(time-zone) {
transition: none;
}
}
slab-date-time-picker::part(control) {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
}
/*
Butted against the input, sharing its border. It has no height of its own
and is stretched to the input's, so the two match in every browser, even
one that sizes a date input its own way. Its text is its accessible name,
so it stays, at no size, and a calendar is drawn in its place.
*/
slab-date-time-picker::part(button) {
align-items: center;
align-self: stretch;
background-color: var(--paper);
border: var(--border);
border-radius: 0;
color: inherit;
cursor: pointer;
display: flex;
font-size: 0;
inline-size: 3rem;
justify-content: center;
margin-inline-start: -2px;
padding: 0;
transition:
background-color 100ms,
box-shadow 100ms,
color 100ms,
translate 100ms;
}
slab-date-time-picker::part(button)::before {
block-size: 0.875rem;
border: 2px solid currentcolor;
border-block-start-width: 5px;
content: '';
inline-size: 1rem;
}
slab-date-time-picker::part(button):hover {
background-color: var(--chalk);
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(button):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
slab-date-time-picker::part(button):disabled {
background-color: var(--chalk);
border-style: dashed;
color: var(--ash);
cursor: not-allowed;
}
slab-date-time-picker[open]::part(button) {
background-color: var(--ink);
color: var(--paper);
}
slab-date-time-picker:state(error)::part(button) {
border-color: var(--ember-deep);
}
/* A closed popover isn't displayed, so the entrance runs each time it opens. */
slab-date-time-picker::part(popover) {
animation: slab-date-time-picker-drop 150ms ease-out;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
margin-block: 0.5rem;
padding: 1rem;
}
@keyframes slab-date-time-picker-drop {
from {
opacity: 0;
translate: 0 -0.375rem;
}
}
slab-date-time-picker::part(calendar)::part(header) {
align-items: center;
display: flex;
gap: 1rem;
justify-content: space-between;
margin-block-end: 0.75rem;
}
slab-date-time-picker::part(calendar)::part(heading) {
font-family: var(--font-display);
font-size: 1.125rem;
font-weight: 600;
}
slab-date-time-picker::part(calendar)::part(previous),
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(previous)::before,
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(next)::before {
rotate: -135deg;
translate: -0.125rem 0;
}
slab-date-time-picker::part(calendar)::part(previous):hover,
slab-date-time-picker::part(calendar)::part(next):hover {
background-color: var(--chalk);
}
slab-date-time-picker::part(calendar)::part(previous):focus-visible,
slab-date-time-picker::part(calendar)::part(next):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
/*
With months, the months sit side by side, and wrap where there isn't room
for them all.
*/
slab-date-time-picker::part(calendar)::part(months) {
display: flex;
flex-wrap: wrap;
gap: 1rem 1.5rem;
}
slab-date-time-picker::part(calendar)::part(month-heading) {
display: block;
font-family: var(--font-mono);
font-size: 0.75rem;
margin-block-end: 0.5rem;
text-align: center;
text-transform: uppercase;
}
/*
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-date-time-picker::part(calendar)::part(grid) {
border-collapse: separate;
border-spacing: 0;
}
slab-date-time-picker::part(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-date-time-picker::part(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-date-time-picker::part(calendar)::part(day):hover {
background-color: var(--chalk);
}
slab-date-time-picker::part(calendar)::part(day):focus-visible {
outline: 3px solid var(--ember);
outline-offset: -3px;
}
slab-date-time-picker::part(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-date-time-picker::part(calendar)::part(selected) {
background-color: var(--ink);
color: var(--paper);
font-weight: 600;
}
slab-date-time-picker::part(calendar)::part(selected):focus-visible {
outline-color: currentcolor;
}
slab-date-time-picker::part(calendar)::part(disabled),
slab-date-time-picker::part(calendar)::part(unavailable) {
color: var(--ash);
cursor: not-allowed;
text-decoration: line-through;
}
slab-date-time-picker::part(calendar)::part(disabled):hover,
slab-date-time-picker::part(calendar)::part(unavailable):hover {
background-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(button),
slab-date-time-picker::part(popover),
slab-date-time-picker::part(calendar)::part(previous),
slab-date-time-picker::part(calendar)::part(next),
slab-date-time-picker::part(calendar)::part(day) {
animation: none;
transition: none;
}
}
slab-date-time-picker::part(time-field) {
border-block-start: var(--border);
display: grid;
gap: 0.25rem;
margin-block-start: 1rem;
padding-block-start: 1rem;
}
slab-date-time-picker::part(time-label) {
color: var(--ash);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
slab-date-time-picker::part(time) {
background-color: var(--paper);
block-size: 3rem;
border: var(--border);
border-radius: 0;
box-sizing: border-box;
color: inherit;
font: inherit;
padding: 0 0.75rem;
transition:
box-shadow 100ms,
translate 100ms;
}
/*
The outline is transparent rather than gone, so it still shows in forced
colors, where box shadows don't.
*/
slab-date-time-picker::part(time):focus-visible {
box-shadow: 4px 4px 0 var(--ember);
outline: 2px solid transparent;
translate: -2px -2px;
}
@media (prefers-reduced-motion: reduce) {
slab-date-time-picker::part(time) {
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;
}
}