Data
Draggable
Something the user drags onto a drop zone, by its handle or with the keyboard, with the same drag events native drag and drop has.
- Element
<slab-draggable>- Built on
handle <button> + [role=group]
Example
Here's a styled version, <slab-styled-draggable>. 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.
<div style="display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr))">
<slab-styled-drop-zone label="To do" data-move style="min-block-size: 12rem">
<slab-styled-draggable label="Footings">Footings</slab-styled-draggable>
<slab-styled-draggable label="Garage slab">Garage slab</slab-styled-draggable>
</slab-styled-drop-zone>
<slab-styled-drop-zone label="Pouring" data-move style="min-block-size: 12rem">
<slab-styled-draggable label="Foundation walls">Foundation walls</slab-styled-draggable>
</slab-styled-drop-zone>
<slab-styled-drop-zone label="Cured" data-move style="min-block-size: 12rem"></slab-styled-drop-zone>
</div>
<div style="display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr))">
<slab-drop-zone label="To do" data-move style="min-block-size: 12rem">
<slab-draggable label="Footings">Footings</slab-draggable>
<slab-draggable label="Garage slab">Garage slab</slab-draggable>
</slab-drop-zone>
<slab-drop-zone label="Pouring" data-move style="min-block-size: 12rem">
<slab-draggable label="Foundation walls">Foundation walls</slab-draggable>
</slab-drop-zone>
<slab-drop-zone label="Cured" data-move style="min-block-size: 12rem"></slab-drop-zone>
</div>
Usage
pnpm add slab-elements lit
import 'slab-elements/draggable.js';
import 'slab-elements/drop-zone.js';
export function MyDraggable() {
return (
<slab-drop-zone label="To do" accept="application/x-task">
<slab-draggable label="Footings">
<svg slot="handle" aria-hidden="true">…</svg>
Footings
</slab-draggable>
</slab-drop-zone>
<slab-drop-zone label="Done" accept="application/x-task"></slab-drop-zone>
);
}
MyDraggable.jsx React 19 or later, which sets props on custom elements as properties.
import 'slab-elements/draggable.js';
import 'slab-elements/drop-zone.js';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('my-draggable')
export class MyDraggable extends LitElement {
render() {
return html`
<slab-drop-zone label="To do" accept="application/x-task">
<slab-draggable label="Footings">
<svg slot="handle" aria-hidden="true">…</svg>
Footings
</slab-draggable>
</slab-drop-zone>
<slab-drop-zone label="Done" accept="application/x-task"></slab-drop-zone>
`;
}
}
my-draggable.ts Slab is built on Lit, so its elements are at home in Lit's templates.
<script setup>
import 'slab-elements/draggable.js';
import 'slab-elements/drop-zone.js';
</script>
<template>
<slab-drop-zone label="To do" accept="application/x-task">
<slab-draggable label="Footings">
<svg slot="handle" aria-hidden="true">…</svg>
Footings
</slab-draggable>
</slab-drop-zone>
<slab-drop-zone label="Done" accept="application/x-task"></slab-drop-zone>
</template>
MyDraggable.vue Let Vue's compiler know slab- tags are custom elements with isCustomElement.
<script>
import 'slab-elements/draggable.js';
import 'slab-elements/drop-zone.js';
</script>
<slab-drop-zone label="To do" accept="application/x-task">
<slab-draggable label="Footings">
<svg slot="handle" aria-hidden="true">…</svg>
Footings
</slab-draggable>
</slab-drop-zone>
<slab-drop-zone label="Done" accept="application/x-task"></slab-drop-zone>
MyDraggable.svelte Svelte binds properties and events to custom elements like any other element.
import 'slab-elements/draggable.js';
import 'slab-elements/drop-zone.js';
export const MyDraggable = <template>
<slab-drop-zone label="To do" accept="application/x-task">
<slab-draggable label="Footings">
<svg slot="handle" aria-hidden="true">…</svg>
Footings
</slab-draggable>
</slab-drop-zone>
<slab-drop-zone label="Done" accept="application/x-task"></slab-drop-zone>
</template>;
MyDraggable.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/draggable.js';
import 'slab-elements/drop-zone.js';
</script>
<slab-drop-zone label="To do" accept="application/x-task">
<slab-draggable label="Footings">
<svg slot="handle" aria-hidden="true">…</svg>
Footings
</slab-draggable>
</slab-drop-zone>
<slab-drop-zone label="Done" accept="application/x-task"></slab-drop-zone>
index.html Any bundler (or an import map) takes care of the imports.
Drag a Draggable by its handle, a <button> named “Drag” and its label, and it follows the pointer until it’s dropped. Or press Space or Enter on the handle to pick it up, move it between the Drop Zones that take it with the arrow keys, and press Space or Enter again to drop it. Escape, or moving focus away, cancels. What’s in the handle is yours, such as a grip icon in its handle slot.
It dispatches the drag events native drag and drop does, as DragEvents with a DataTransfer, whether it’s dragged by a mouse, a finger or the keyboard: “dragstart” on the Draggable, “dragenter”, “dragover”, “dragleave” and “drop” on the Drop Zones, then “dragend” on the Draggable. So a single “drop” listener covers every way of dragging. Pointer drags follow the pointer by the Draggable’s translate. Set translate: none on it to keep it in place.
Neither element moves anything. Only your page knows what a drop means, so do it in the Drop Zone’s “drop”, as a page with native drag and drop does:
draggable.addEventListener('dragstart', (event) => {
event.dataTransfer.setData('application/x-task', 'footings');
});
done.addEventListener('drop', (event) => {
const task = event.dataTransfer.getData('application/x-task');
// Move the task to Done.
});
A Draggable carries its label as “text/plain” to start, and whatever you set in “dragstart” too. Cancel “dragstart” to stop the drag. A Drop Zone takes a drop only of what matches its accept, a comma-separated list of data types such as “application/x-task” or “text/*”, and of anything when it’s unset. It takes nothing while it’s disabled. drop-effect, “move” by default, is set as the drag’s dropEffect, so “dragend” can tell whether the Draggable was moved, copied or not dropped at all (“none”), and a drag’s effectAllowed keeps it off Drop Zones whose effect it doesn’t allow.
Drop Zones also take native drags from outside Slab, such as a link or some text from another window, by the same accept, so the same “drop” listener handles those too. For files, use File Drop.
Screenreaders hear each step with the keyboard, such as “Footings picked up”, “Footings over Pouring, 2 of 3” and “Footings dropped on Pouring”, and the handle is described with how to drag it. Word them yourself with instructions-label and the grabbedLabel, overLabel, droppedLabel, canceledLabel and noDropZonesLabel functions.
A Draggable has :state(grabbed) while it’s picked up or dragged. A Drop Zone has :state(droppable) while a Draggable it would take is dragged, so the places it can go stand out, and :state(over) while that drag is over it. To put items in order within a list, use Sortable List.
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves to each handle, then to what’s in the Draggable. |
| Space, Enter | On a handle, picks it up. While it’s picked up, drops it. |
| Right Arrow, Down Arrow | Moves a picked up Draggable to the next Drop Zone that takes it. |
| Left Arrow, Up Arrow | Moves it to the previous Drop Zone that takes it. |
| Home, End | Moves it to the first or the last Drop Zone that takes it. |
| Escape | Cancels a drag, by the keyboard or a pointer. |
Behavior
<slab-draggable>
A Draggable with no visual styles: something the user drags onto a Drop Zone, by its handle or with the keyboard, such as a card onto a column or a file onto a folder.
It has a handle, a <button>. Drag it and the Draggable follows the pointer, by its translate, until it's dropped. Or press Space or Enter on it to pick the Draggable up, the arrow keys to move it between the Drop Zones that take it, Space or Enter to drop it, and Escape to cancel. Moving focus away cancels as well.
It dispatches the drag events a native drag does, as DragEvents with a DataTransfer, whichever way it's dragged: "dragstart" on it, then "dragenter", "dragover", "dragleave" and "drop" on Drop Zones, then "dragend" on it. Set what's dragged in "dragstart", with the event's dataTransfer.setData(), as you would natively. It starts out with its label as "text/plain". Cancel "dragstart" to stop the drag.
Neither it nor a Drop Zone moves anything. Do what a drop means in the Drop Zone's "drop". "dragend"'s dataTransfer.dropEffect is the Drop Zone's drop-effect when it was dropped, and "none" when it wasn't.
Screenreaders are told what happens as it's picked up, moved, dropped or canceled, such as "Pour over Done, 2 of 3". Change what they're told with grabbedLabel, overLabel, droppedLabel, canceledLabel and noDropZonesLabel.
Style it through its parts and :state(grabbed), which it has while it's picked up or dragged.
<slab-drop-zone>
A Drop Zone with no visual styles: somewhere a Draggable can be dropped, such as a column of a board, a folder, or a trash can.
It's dispatched the drag events a native drop target is, as DragEvents: "dragenter" and "dragleave" as a drag comes and goes, "dragover" while it's over it, and "drop" when it's dropped on it. Read what was dropped from the event's dataTransfer, with getData(), as you would from a native drop. Drop Zone doesn't move anything itself. What a drop means is yours.
It takes a drop of what matches accept, a comma-separated list of data types, such as "application/x-task" or "text/*", and of anything when it's unset. It's never dropped on while it's disabled, or when the drag's effectAllowed doesn't allow its drop-effect.
Drags from outside Slab, such as a link or text from another window, are native drags, and it accepts those the same way, so one "drop" listener covers both. For files, use File Drop.
Style it through its part, :state(droppable), which it has while a Draggable it would take is being dragged, and :state(over), which it has while that drag is over it.
API
<slab-draggable>
| Name | Type | Default | Description |
|---|---|---|---|
label
Required
|
string |
Names it, in its handle's name, in what screenreaders are told as it moves, and as the "text/plain" it starts out carrying. | |
disabled
|
boolean |
false |
Stops it being dragged, and disables its handle. |
handle-label
|
string |
Names the handle. "Drag" and label in English when unset. |
|
instructions-label
|
string |
Describes the handle to screenreaders. "Press Space to pick it up…" in English when unset. |
| Name | Type | Description |
|---|---|---|
canceledLabel
|
(label: string) => string |
What screenreaders are told when a drag is canceled, from its label. "Drag canceled…" in English when unset. |
droppedLabel
|
(label: string, target: string) => string |
What screenreaders are told when it's dropped, from its label and the Drop Zone's. "Pour dropped on Done" and so on in English when unset. |
grabbedLabel
|
(label: string) => string |
What screenreaders are told when it's picked up with the keyboard, from its label. "Pour picked up" and so on in English when unset. |
noDropZonesLabel
|
(label: string) => string |
What screenreaders are told when it's picked up with the keyboard and no Drop Zone takes it, from its label. "Nowhere to drop Pour" and so on in English when unset. |
overLabel
|
OverAnnouncement |
What screenreaders are told when it's moved to a Drop Zone with the keyboard, from its label, the Drop Zone's, and where that is among the ones that take it, from 1. "Pour over Done, 2 of 3" and so on in English when unset. |
| Name | Type | Description |
|---|---|---|
dragend
|
DragEvent |
When the drag ends, as a DragEvent, dropped or not. Its dataTransfer.dropEffect is the Drop Zone's drop-effect when it was dropped, and "none" when it wasn't. |
dragstart
|
DragEvent |
When a drag starts, as a DragEvent. Set what's dragged with its dataTransfer.setData(), or cancel it to stop the drag. |
| Name | Type | Description |
|---|---|---|
handle
|
Element | string |
Shown in the handle, such as a grip icon |
(default)
|
Element | string |
Its content |
| Name | Description |
|---|---|
content
|
Holds the content |
handle
|
The button that drags it |
| Name | Description |
|---|---|
:state(grabbed)
|
While it's picked up or dragged. |
<slab-drop-zone>
| Name | Type | Default | Description |
|---|---|---|---|
label
Required
|
string |
Names it, as a group, and in what screenreaders are told as a Draggable is moved to it with the keyboard. | |
accept
|
string |
The data types it takes a drop of, comma-separated, such as "application/x-task" or "text/*". Anything when unset. | |
disabled
|
boolean |
false |
Stops it being dropped on. |
drop-effect
|
'copy' | 'link' | 'move' |
'move' |
What a drop on it does, set as the drag's dropEffect, so the Draggable's "dragend" can tell whether to remove what was moved. |
| Name | Type | Description |
|---|---|---|
dragenter
|
DragEvent |
When a drag it would take comes over it, as a DragEvent. |
dragleave
|
DragEvent |
When a drag it would take leaves it, or ends over it without a drop, as a DragEvent. |
dragover
|
DragEvent |
While a drag it would take is over it, as a DragEvent. |
drop
|
DragEvent |
When what's dragged is dropped on it, as a DragEvent. Read what it is from its dataTransfer. |
| Name | Type | Description |
|---|---|---|
(default)
|
Element | string |
What's in it |
| Name | Description |
|---|---|
zone
|
Holds what's in it |
| Name | Description |
|---|---|
:state(disabled)
|
While it's disabled. |
:state(droppable)
|
While a Draggable it would take is dragged. |
:state(over)
|
While a drag it would take is over it. |
Copy and own it
<slab-styled-draggable> 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-draggable> 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.
Draggable.jsx
import 'slab-elements/draggable.js';
import './draggable.css';
import 'slab-elements/drop-zone.js';
import './drop-zone.css';
export function Draggable(props) {
return <slab-draggable {...props} />;
}
export function DropZone(props) {
return <slab-drop-zone {...props} />;
}
draggable.css
slab-draggable {
align-items: center;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: flex;
font-family: var(--font-body);
gap: 0.75rem;
padding: 0.5rem 0.75rem 0.5rem 0.25rem;
transition: box-shadow 100ms;
}
slab-draggable:state(grabbed) {
box-shadow: 6px 6px 0 var(--ember);
}
slab-draggable::part(handle) {
align-items: center;
align-self: stretch;
background: none;
border: none;
color: var(--ash);
cursor: grab;
display: flex;
flex: none;
font: inherit;
font-size: 1.25rem;
justify-content: center;
line-height: 1;
margin: 0;
min-block-size: 2.25rem;
min-inline-size: 2rem;
padding: 0;
}
/* Six dots, in two columns. */
slab-draggable::part(handle)::before {
content: '⠿' / '';
}
slab-draggable::part(handle):hover {
color: var(--ink);
}
slab-draggable::part(handle):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-draggable::part(handle):disabled {
cursor: not-allowed;
opacity: 0.4;
}
slab-draggable:state(grabbed)::part(handle) {
color: var(--ember-deep);
cursor: grabbing;
}
slab-draggable::part(content) {
flex: 1 1 auto;
min-inline-size: 0;
overflow-wrap: anywhere;
}
@media (prefers-reduced-motion: reduce) {
slab-draggable {
transition: none;
}
}
drop-zone.css
slab-drop-zone {
color: var(--ink);
font-family: var(--font-body);
}
slab-drop-zone::part(zone) {
border: 2px dashed var(--ash);
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 0.5rem;
min-block-size: 100%;
padding: 0.75rem;
transition:
background-color 100ms,
border-color 100ms;
}
slab-drop-zone:state(droppable)::part(zone) {
border-color: var(--ember);
}
slab-drop-zone:state(over)::part(zone) {
background-color: var(--chalk);
border-style: solid;
}
slab-drop-zone:state(disabled)::part(zone) {
opacity: 0.5;
}
@media (prefers-reduced-motion: reduce) {
slab-drop-zone::part(zone) {
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.
draggable.ts
import { customElement } from 'lit/decorators.js';
import Draggable from 'slab-elements/draggable.js';
import styles from './draggable.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-draggable': StyledDraggable;
}
}
/**
* Draggable, styled: a raised card with a dotted grip at its start. It's
* lifted and outlined in ember while it's picked up or dragged.
*/
@customElement('slab-styled-draggable')
export default class StyledDraggable extends Draggable {
static override styles = [tokens, styles];
}
draggable.styles.ts
import { css } from 'lit';
/*
Sortable List Item's look: a raised card with a dotted grip at its start,
lifted and outlined in ember while it's picked up or dragged. The grip's
dots are the handle's own, hidden from screenreaders, which read its name
instead.
*/
export default css`
:host {
align-items: center;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: flex;
font-family: var(--font-body);
gap: 0.75rem;
padding: 0.5rem 0.75rem 0.5rem 0.25rem;
transition: box-shadow 100ms;
}
:host(:state(grabbed)) {
box-shadow: 6px 6px 0 var(--ember);
}
[part~='handle'] {
align-items: center;
align-self: stretch;
background: none;
border: none;
color: var(--ash);
cursor: grab;
display: flex;
flex: none;
font: inherit;
font-size: 1.25rem;
justify-content: center;
line-height: 1;
margin: 0;
min-block-size: 2.25rem;
min-inline-size: 2rem;
padding: 0;
/* Six dots, in two columns. */
&::before {
content: '⠿' / '';
}
&:hover {
color: var(--ink);
}
&:focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
&:disabled {
cursor: not-allowed;
opacity: 0.4;
}
}
:host(:state(grabbed)) [part~='handle'] {
color: var(--ember-deep);
cursor: grabbing;
}
[part~='content'] {
flex: 1 1 auto;
min-inline-size: 0;
overflow-wrap: anywhere;
}
@media (prefers-reduced-motion: reduce) {
:host {
transition: none;
}
}
`;
drop-zone.ts
import { customElement } from 'lit/decorators.js';
import DropZone from 'slab-elements/drop-zone.js';
import styles from './drop-zone.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-drop-zone': StyledDropZone;
}
}
/**
* Drop Zone, styled: a dashed outline around a column of what's in it. It
* turns ember while something it would take is dragged, and fills with chalk
* while that's over it.
*/
@customElement('slab-styled-drop-zone')
export default class StyledDropZone extends DropZone {
static override styles = [tokens, styles];
}
drop-zone.styles.ts
import { css } from 'lit';
/*
A dashed outline with room inside for what's dropped, stacked in a column.
It turns ember while something it would take is dragged, so the places it
can go stand out, and fills with chalk, its outline solid, while that's
over it.
*/
export default css`
:host {
color: var(--ink);
font-family: var(--font-body);
}
[part~='zone'] {
border: 2px dashed var(--ash);
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 0.5rem;
min-block-size: 100%;
padding: 0.75rem;
transition:
background-color 100ms,
border-color 100ms;
}
:host(:state(droppable)) [part~='zone'] {
border-color: var(--ember);
}
:host(:state(over)) [part~='zone'] {
background-color: var(--chalk);
border-style: solid;
}
:host(:state(disabled)) [part~='zone'] {
opacity: 0.5;
}
@media (prefers-reduced-motion: reduce) {
[part~='zone'] {
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-draggable> 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.
Draggable.vue
<script setup>
import 'slab-elements/draggable.js';
import './draggable.css';
</script>
<template>
<slab-draggable><slot /></slab-draggable>
</template>
DropZone.vue
<script setup>
import 'slab-elements/drop-zone.js';
import './drop-zone.css';
</script>
<template>
<slab-drop-zone><slot /></slab-drop-zone>
</template>
draggable.css
slab-draggable {
align-items: center;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: flex;
font-family: var(--font-body);
gap: 0.75rem;
padding: 0.5rem 0.75rem 0.5rem 0.25rem;
transition: box-shadow 100ms;
}
slab-draggable:state(grabbed) {
box-shadow: 6px 6px 0 var(--ember);
}
slab-draggable::part(handle) {
align-items: center;
align-self: stretch;
background: none;
border: none;
color: var(--ash);
cursor: grab;
display: flex;
flex: none;
font: inherit;
font-size: 1.25rem;
justify-content: center;
line-height: 1;
margin: 0;
min-block-size: 2.25rem;
min-inline-size: 2rem;
padding: 0;
}
/* Six dots, in two columns. */
slab-draggable::part(handle)::before {
content: '⠿' / '';
}
slab-draggable::part(handle):hover {
color: var(--ink);
}
slab-draggable::part(handle):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-draggable::part(handle):disabled {
cursor: not-allowed;
opacity: 0.4;
}
slab-draggable:state(grabbed)::part(handle) {
color: var(--ember-deep);
cursor: grabbing;
}
slab-draggable::part(content) {
flex: 1 1 auto;
min-inline-size: 0;
overflow-wrap: anywhere;
}
@media (prefers-reduced-motion: reduce) {
slab-draggable {
transition: none;
}
}
drop-zone.css
slab-drop-zone {
color: var(--ink);
font-family: var(--font-body);
}
slab-drop-zone::part(zone) {
border: 2px dashed var(--ash);
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 0.5rem;
min-block-size: 100%;
padding: 0.75rem;
transition:
background-color 100ms,
border-color 100ms;
}
slab-drop-zone:state(droppable)::part(zone) {
border-color: var(--ember);
}
slab-drop-zone:state(over)::part(zone) {
background-color: var(--chalk);
border-style: solid;
}
slab-drop-zone:state(disabled)::part(zone) {
opacity: 0.5;
}
@media (prefers-reduced-motion: reduce) {
slab-drop-zone::part(zone) {
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-draggable> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Import draggable.js once, such
as in your root layout, and use
<slab-draggable> as is. A Svelte component
around it would take slot="…" content as its
own slot and drop it.
draggable.js
import 'slab-elements/draggable.js';
import './draggable.css';
import 'slab-elements/drop-zone.js';
import './drop-zone.css';
draggable.css
slab-draggable {
align-items: center;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: flex;
font-family: var(--font-body);
gap: 0.75rem;
padding: 0.5rem 0.75rem 0.5rem 0.25rem;
transition: box-shadow 100ms;
}
slab-draggable:state(grabbed) {
box-shadow: 6px 6px 0 var(--ember);
}
slab-draggable::part(handle) {
align-items: center;
align-self: stretch;
background: none;
border: none;
color: var(--ash);
cursor: grab;
display: flex;
flex: none;
font: inherit;
font-size: 1.25rem;
justify-content: center;
line-height: 1;
margin: 0;
min-block-size: 2.25rem;
min-inline-size: 2rem;
padding: 0;
}
/* Six dots, in two columns. */
slab-draggable::part(handle)::before {
content: '⠿' / '';
}
slab-draggable::part(handle):hover {
color: var(--ink);
}
slab-draggable::part(handle):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-draggable::part(handle):disabled {
cursor: not-allowed;
opacity: 0.4;
}
slab-draggable:state(grabbed)::part(handle) {
color: var(--ember-deep);
cursor: grabbing;
}
slab-draggable::part(content) {
flex: 1 1 auto;
min-inline-size: 0;
overflow-wrap: anywhere;
}
@media (prefers-reduced-motion: reduce) {
slab-draggable {
transition: none;
}
}
drop-zone.css
slab-drop-zone {
color: var(--ink);
font-family: var(--font-body);
}
slab-drop-zone::part(zone) {
border: 2px dashed var(--ash);
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 0.5rem;
min-block-size: 100%;
padding: 0.75rem;
transition:
background-color 100ms,
border-color 100ms;
}
slab-drop-zone:state(droppable)::part(zone) {
border-color: var(--ember);
}
slab-drop-zone:state(over)::part(zone) {
background-color: var(--chalk);
border-style: solid;
}
slab-drop-zone:state(disabled)::part(zone) {
opacity: 0.5;
}
@media (prefers-reduced-motion: reduce) {
slab-drop-zone::part(zone) {
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-draggable> 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.
Draggable.gjs
import 'slab-elements/draggable.js';
import './draggable.css';
export const Draggable = <template>
<slab-draggable ...attributes>{{yield}}</slab-draggable>
</template>;
DropZone.gjs
import 'slab-elements/drop-zone.js';
import './drop-zone.css';
export const DropZone = <template>
<slab-drop-zone ...attributes>{{yield}}</slab-drop-zone>
</template>;
draggable.css
slab-draggable {
align-items: center;
background-color: var(--paper);
border: var(--border);
box-shadow: var(--shadow);
color: var(--ink);
display: flex;
font-family: var(--font-body);
gap: 0.75rem;
padding: 0.5rem 0.75rem 0.5rem 0.25rem;
transition: box-shadow 100ms;
}
slab-draggable:state(grabbed) {
box-shadow: 6px 6px 0 var(--ember);
}
slab-draggable::part(handle) {
align-items: center;
align-self: stretch;
background: none;
border: none;
color: var(--ash);
cursor: grab;
display: flex;
flex: none;
font: inherit;
font-size: 1.25rem;
justify-content: center;
line-height: 1;
margin: 0;
min-block-size: 2.25rem;
min-inline-size: 2rem;
padding: 0;
}
/* Six dots, in two columns. */
slab-draggable::part(handle)::before {
content: '⠿' / '';
}
slab-draggable::part(handle):hover {
color: var(--ink);
}
slab-draggable::part(handle):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 2px;
}
slab-draggable::part(handle):disabled {
cursor: not-allowed;
opacity: 0.4;
}
slab-draggable:state(grabbed)::part(handle) {
color: var(--ember-deep);
cursor: grabbing;
}
slab-draggable::part(content) {
flex: 1 1 auto;
min-inline-size: 0;
overflow-wrap: anywhere;
}
@media (prefers-reduced-motion: reduce) {
slab-draggable {
transition: none;
}
}
drop-zone.css
slab-drop-zone {
color: var(--ink);
font-family: var(--font-body);
}
slab-drop-zone::part(zone) {
border: 2px dashed var(--ash);
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 0.5rem;
min-block-size: 100%;
padding: 0.75rem;
transition:
background-color 100ms,
border-color 100ms;
}
slab-drop-zone:state(droppable)::part(zone) {
border-color: var(--ember);
}
slab-drop-zone:state(over)::part(zone) {
background-color: var(--chalk);
border-style: solid;
}
slab-drop-zone:state(disabled)::part(zone) {
opacity: 0.5;
}
@media (prefers-reduced-motion: reduce) {
slab-drop-zone::part(zone) {
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;
}
}