Skip to Content
CodeUI

Sheet

@codeui/styles v0.3.0

A panel that slides in from the bottom or a side, in plain HTML.

Load @codeui/styles/sheet.css, or all.css. The Solid component is documented in Sheet.

Demo

sheet/basic.html
<div class="cui-sheet-overlay" data-cui="sheet-overlay" data-expanded aria-hidden="true"></div><div role="dialog" aria-modal="true" aria-labelledby="basic-title" aria-describedby="basic-description" tabindex="-1" class="cui-sheet-content" data-cui="sheet-content" data-side="bottom" data-expanded>  <div class="cui-sheet-header" data-cui="sheet-header">    <h2 id="basic-title" class="cui-sheet-title" data-cui="sheet-title">Export options</h2>    <button type="button" aria-label="Close export options" class="cui-button cui-iconbutton cui-sheet-close-button" data-cui="sheet-close-button" data-size="xs" data-variant="secondary">      <svg class="cui-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">        <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />      </svg>    </button>  </div>  <p id="basic-description" class="cui-sheet-description" data-cui="sheet-description">Choose how to share your snippet.</p>  <div class="cui-sheet-body" data-cui="sheet-body">    PNG preserves the frame background. SVG keeps text sharp at any size.  </div>  <div class="cui-sheet-footer" data-cui="sheet-footer">    <button type="button" class="cui-button" data-cui="button" data-variant="primary">Done</button>  </div></div>

The overlay and the content are position: fixed, so in these demos they fill the frame. On a page they cover the viewport.

Markup

PartElementClassdata-cui
Overlaydivcui-sheet-overlaysheet-overlay
Contentdivcui-sheet-contentsheet-content
Handlebuttoncui-sheet-handlesheet-handle
Headerdivcui-sheet-headersheet-header
Titleh2cui-sheet-titlesheet-title
Close buttonbuttonIconButton classes and cui-sheet-close-buttonsheet-close-button
Descriptionpcui-sheet-descriptionsheet-description
Bodydivcui-sheet-bodysheet-body
Footerdivcui-sheet-footersheet-footer

The overlay and the content are siblings. Put the overlay first.

AttributeValuesDefault
data-side on the contentbottom, left, rightbottom
data-expanded on the overlay and the contentPresenceOff
data-motion on the overlay and the contentnoneNone
data-contained on the overlay and the contentPresenceOff

Variants

Sides

sheet/left.html
<div class="cui-sheet-overlay" data-cui="sheet-overlay" data-expanded aria-hidden="true"></div><div role="dialog" aria-modal="true" aria-labelledby="left-title" aria-describedby="left-description" tabindex="-1" class="cui-sheet-content" data-cui="sheet-content" data-side="left" data-expanded>  <div class="cui-sheet-header" data-cui="sheet-header">    <h2 id="left-title" class="cui-sheet-title" data-cui="sheet-title">Export options</h2>    <button type="button" aria-label="Close export options" class="cui-button cui-iconbutton cui-sheet-close-button" data-cui="sheet-close-button" data-size="xs" data-variant="secondary">      <svg class="cui-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">        <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />      </svg>    </button>  </div>  <p id="left-description" class="cui-sheet-description" data-cui="sheet-description">Choose how to share your snippet.</p>  <div class="cui-sheet-body" data-cui="sheet-body">    PNG preserves the frame background. SVG keeps text sharp at any size.  </div>  <div class="cui-sheet-footer" data-cui="sheet-footer">    <button type="button" class="cui-button" data-cui="button" data-variant="primary">Done</button>  </div></div>
sheet/right.html
<div class="cui-sheet-overlay" data-cui="sheet-overlay" data-expanded aria-hidden="true"></div><div role="dialog" aria-modal="true" aria-labelledby="right-title" aria-describedby="right-description" tabindex="-1" class="cui-sheet-content" data-cui="sheet-content" data-side="right" data-expanded>  <div class="cui-sheet-header" data-cui="sheet-header">    <h2 id="right-title" class="cui-sheet-title" data-cui="sheet-title">Export options</h2>    <button type="button" aria-label="Close export options" class="cui-button cui-iconbutton cui-sheet-close-button" data-cui="sheet-close-button" data-size="xs" data-variant="secondary">      <svg class="cui-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">        <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />      </svg>    </button>  </div>  <p id="right-description" class="cui-sheet-description" data-cui="sheet-description">Choose how to share your snippet.</p>  <div class="cui-sheet-body" data-cui="sheet-body">    PNG preserves the frame background. SVG keeps text sharp at any size.  </div>  <div class="cui-sheet-footer" data-cui="sheet-footer">    <button type="button" class="cui-button" data-cui="button" data-variant="primary">Done</button>  </div></div>

data-side="left" and data-side="right" float the sheet 8px in from the top, bottom and that edge, with every corner rounded. It is 24rem wide, or --cui-sheet-width, and never wider than the area less the insets. At 768px and below it is a bottom sheet.

Contained

data-contained on the overlay and the content positions them absolute instead of fixed, so they cover their nearest positioned ancestor instead of the viewport. A bottom sheet spans the width and stops 40px below the top of the viewport. Omitting data-side renders a bottom sheet.

Handle

sheet/handle.html
<div class="cui-sheet-overlay" data-cui="sheet-overlay" data-expanded aria-hidden="true"></div><div role="dialog" aria-modal="true" aria-labelledby="handle-title" aria-describedby="handle-description" tabindex="-1" class="cui-sheet-content" data-cui="sheet-content" data-side="bottom" data-expanded>  <button type="button" aria-label="Close export options" class="cui-sheet-handle" data-cui="sheet-handle"></button>  <div class="cui-sheet-header" data-cui="sheet-header">    <h2 id="handle-title" class="cui-sheet-title" data-cui="sheet-title">Export options</h2>    <button type="button" aria-label="Close export options" class="cui-button cui-iconbutton cui-sheet-close-button" data-cui="sheet-close-button" data-size="xs" data-variant="secondary">      <svg class="cui-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">        <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />      </svg>    </button>  </div>  <p id="handle-description" class="cui-sheet-description" data-cui="sheet-description">Choose how to share your snippet.</p>  <div class="cui-sheet-body" data-cui="sheet-body">    PNG preserves the frame background. SVG keeps text sharp at any size.  </div>  <div class="cui-sheet-footer" data-cui="sheet-footer">    <button type="button" class="cui-button" data-cui="button" data-variant="primary">Done</button>  </div></div>

Put a button.cui-sheet-handle first in a bottom sheet. It is a 40px tall hit area with a 40×4 bar. Give it an accessible name, because it has no text. Above 768px a left or right sheet hides its handle; render it there only at 768px and below, or focus may land on a hidden button. The handle has touch-action: none, so a script can track a drag on it while the body still scrolls.

Non-modal

sheet/non-modal.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Copy snippet</button>  <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Change theme</button></div><div role="dialog" aria-modal="false" aria-labelledby="non-modal-title" aria-describedby="non-modal-description" tabindex="-1" class="cui-sheet-content" data-cui="sheet-content" data-side="bottom" data-expanded>  <div class="cui-sheet-header" data-cui="sheet-header">    <h2 id="non-modal-title" class="cui-sheet-title" data-cui="sheet-title">Export options</h2>    <button type="button" aria-label="Close export options" class="cui-button cui-iconbutton cui-sheet-close-button" data-cui="sheet-close-button" data-size="xs" data-variant="secondary">      <svg class="cui-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">        <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />      </svg>    </button>  </div>  <p id="non-modal-description" class="cui-sheet-description" data-cui="sheet-description">Choose how to share your snippet.</p>  <div class="cui-sheet-body" data-cui="sheet-body">    PNG preserves the frame background. SVG keeps text sharp at any size.  </div>  <div class="cui-sheet-footer" data-cui="sheet-footer">    <button type="button" class="cui-button" data-cui="button" data-variant="primary">Done</button>  </div></div>

Leave out the overlay and the page behind stays visible and usable. Set aria-modal="false", or leave it out, and do not trap focus.

States

Open

data-expanded on the content slides it in from its side, over 260ms on --cui-motion-ease-drawer. data-expanded on the overlay fades the scrim in. Both are transitions that start from @starting-style, so adding data-expanded again mid-exit turns them around. Without data-expanded, both transition out over 200ms ease-out and stay hidden: the content off screen and the scrim transparent. Set it on an open sheet even without a script.

Closing

Remove data-expanded from both while they are still in the page. The content slides out and the overlay fades. Remove the markup on the content's transitionend.

No motion

data-motion="none" on the overlay and the content turns off both animations. Set it when the sheet opens or closes from the keyboard. With reduced motion, the slide becomes a fade.

What you supply

  • Opening and closing, and data-expanded while open.
  • role="dialog", aria-modal, aria-labelledby, and aria-describedby on the content.
  • For a modal sheet, a focus trap and inert on the rest of the page. Return focus to the opener on close.
  • Escape, the close button, and a click on the overlay close the sheet.
  • The drag gesture on the handle: move the content with transform while the pointer is down, and close it past a distance or a flick.

Helper

import "@codeui/styles/sheet.css";
import { applyStyleProps } from "@codeui/styles";
import { sheetStyleProps } from "@codeui/styles/sheet";

const content = document.querySelector<HTMLElement>("[role=dialog]")!;
applyStyleProps(content, sheetStyleProps({ side: "right" }));
// class="cui-sheet-content" data-cui="sheet-content" data-side="right"

On this page