Command palette

@yasinsensoy/web

Web · Components

Sheet

Panel that slides in from an edge of the screen: mobile navigation menu, filters, cart, detail panel, bottom sheet, result list over a map.

4 exports

Live example

Preview

Menu

You can close it by pushing it towards the edge.

Code

import { Sheet, Button } from "@yasinsensoy/web";

<Sheet
  trigger={<Button variant="outline">Open sheet</Button>}
  title="Menu"
  description="You can close it by pushing it towards the edge."
>
  {({ close }) => <nav onClick={close}>…</nav>}
</Sheet>

Events

  1. Events appear here when you interact with the preview.

Bottom sheet: opens halfway, grows when pulled up by the handle (mouse or finger)

Nearby stores

Pull up to grow, pull down to shrink or close.

  • Store 10.3 km
  • Store 20.7 km
  • Store 31.1 km
  • Store 41.5 km
  • Store 51.9 km
  • Store 62.3 km
  • Store 72.7 km
  • Store 83.1 km
  • Store 93.5 km
  • Store 103.9 km
  • Store 114.3 km
  • Store 124.7 km
  • Store 135.1 km
  • Store 145.5 km
  • Store 155.9 km
  • Store 166.3 km
  • Store 176.7 km
  • Store 187.1 km
  • Store 197.5 km
  • Store 207.9 km
  • Store 218.3 km
  • Store 228.7 km
  • Store 239.1 km
  • Store 249.5 km
  • Store 259.9 km
  • Store 2610.3 km
  • Store 2710.7 km
  • Store 2811.1 km
  • Store 2911.5 km
  • Store 3011.9 km

A panel that stays open: modal={false}, dismissible={false}

Results

  • Store 10.3 km
  • Store 20.7 km
  • Store 31.1 km
  • Store 41.5 km
  • Store 51.9 km
  • Store 62.3 km
  • Store 72.7 km
  • Store 83.1 km
  • Store 93.5 km
  • Store 103.9 km
  • Store 114.3 km
  • Store 124.7 km
  • Store 135.1 km
  • Store 145.5 km
  • Store 155.9 km
  • Store 166.3 km
  • Store 176.7 km
  • Store 187.1 km
  • Store 197.5 km
  • Store 207.9 km
  • Store 218.3 km
  • Store 228.7 km
  • Store 239.1 km
  • Store 249.5 km
  • Store 259.9 km
  • Store 2610.3 km
  • Store 2710.7 km
  • Store 2811.1 km
  • Store 2911.5 km
  • Store 3011.9 km

Import

import { Sheet } from "@yasinsensoy/web";

Sheet

componentClient component

Panel that slides in from an edge of the screen: mobile navigation menu, filters, cart, detail panel, bottom sheet, result list over a map. Has the same props as Dialog (title, icon, onConfirm, footer…); additionally snap points (snapPoints) and non-modal use (modal={false}).

  • Dragging: The panel is dragged from anywhere with a finger, from its handle with a mouse. Pushed toward the edge it opens from, it closes (right panels to the right, bottom panels down); a fast flick closes too.
  • Snap points: With snapPoints={[0.4, 0.92]} 40% of the screen opens first; pulling grows it, pushing back shrinks or closes it. A fast flick jumps to the next point. Clicking the handle, or focusing it and pressing ↑/↓ (←/→ on side panels), Home/End moves between points.
  • Content scrolling: While the list isn't at the top, dragging scrolls the list; at the top it shrinks the panel. At the largest point, movement in the growing direction scrolls the list too. Movements perpendicular to the drag direction (like a horizontal gallery) don't move the panel.
  • Edge: The edge it opens from always stays attached to the screen. When pulled past the largest point the panel doesn't detach but stretches attached to that edge; when the bottom panel sits above the keyboard, the area behind the keyboard doesn't look empty.
  • Esc, the back button and (when modal) clicking the backdrop close it; opening and closing are animated with CSS. It respects safe area insets of notched screens and the on-screen keyboard.
Sheet({ side, snapPoints, snap, defaultSnap, onSnapChange, modal, dismissible, handle, className, showCloseButton, closeOnBackdropClick, closeOnBackButton, swipeToClose, open, defaultOpen, onOpenChange, effect, ...props }: SheetProps): JSX.Element

Examples

// Side menu
<Sheet side="left" title="Menu"
  trigger={<IconButton icon="menu" label="Menu" variant="ghost" />}>
  {({ close }) => <nav onClick={close}>…</nav>}
</Sheet>

// Filter form
<Sheet title="Filter" trigger={<Button>Filters</Button>}
  confirmLabel="Apply" onConfirm={(data) => filter(data)}>
  <CheckboxField name="inStock" label="In stock only" />
</Sheet>

// Bottom sheet that opens halfway and grows when pulled up
<Sheet side="bottom" title="Nearby stores" snapPoints={[0.35, 0.9]}
  trigger={<Button>Open list</Button>}>
  <StoreList />
</Sheet>

// Panel that always stays open over a map
<Sheet side="bottom" title="Results" open modal={false} dismissible={false}
  snapPoints={["120px", 0.5, 0.9]} showCloseButton={false}>…</Sheet>

Edge the panel opens from. In right-to-left languages too, left/right are the physical edges.

type SheetSide = "top" | "right" | "bottom" | "left"

Snap point: a number between 0–1 is that fraction of the screen (0.5 = half), text like "320px" is a fixed size.

type SheetSnapPoint = number | `${number}px`

SheetProps

interface

Props of the Sheet component.

NameTypeDefaultDescription
side?SheetSide"right"Edge the panel opens from.
snapPoints?readonly SheetSnapPoint[]Sizes the panel can stop at when dragged with a finger (or the handle with a mouse), from small to large (e.g. [0.4, 0.92]: first 40% of the screen, nearly all of it when pulled up). If omitted, the panel opens to its content size (3/4 of the screen on the sides, at most max-w-sm) and is dragged only to close.
snap?numberIndex of the active snap point in controlled use.
defaultSnap?number0Index of the point to stop at on open in uncontrolled use.
onSnapChange?(index: number) => voidCalled with the new index when the active snap point changes.
modal?booleantrueIf false the backdrop isn't dimmed and stays interactive (like a list over a map). Focus isn't trapped in the panel.
dismissible?booleantrueIf false pulling below the smallest point doesn't close it; the panel always stays open (a persistent bottom panel with modal={false}).
handle?booleantrueWhether to show the drag handle. The handle can be dragged with a mouse too; with several snap points, clicking it and ↑/↓ keys move between points. Not shown while swipeToClose={false}.
effect?EffectPropEffect or effects of the panel surface (e.g. "beam", "glow"). If omitted, UIProvider appearance.defaults.sheet.effect. See BuiltinEffect.
open?booleanWhether it is open when controlled.
defaultOpen?booleanfalseIs it initially open when uncontrolled?
onOpenChange?(open: boolean) => voidCalled with the new state when it opens or closes.
trigger?ReactElementElement that opens the window, usually a Button. The window opens on click; aria-expanded and aria-controls are added automatically.
titleReactNodeTitle. Screen readers announce the window with this name, so it is required. To hide it, use classNames={{ title: "sr-only" }}.
description?ReactNodeDescription under the title; screen readers read it when the window opens.
icon?IconPropIcon next to the title: a name or an element.
children?ModalSlotBody. If a function is given it receives { close, pending }; for example to close the window when a link is clicked.
onConfirm?(data: FormData) => unknownCalled when the confirm button is pressed. The body works like a form: the values of its fields arrive as FormData, and it is not called until browser validation (required etc.) passes. - If it returns a Promise, the confirm button shows loading until it settles and the window does not close (Esc, backdrop and back button wait too). - If it returns false or throws, the window stays open. - Otherwise the window closes.
confirmLabel?ReactNodeText of the confirm button. If onConfirm is given but this isn't, the UIProvider text ("Onayla") is used.
cancelLabel?ReactNode{@link UIProvider} text ("İptal")Text of the cancel button. With null the button is not shown.
tone?Tone"primary"Color of the confirm button. "danger" for irreversible actions such as deleting.
footer?ModalSlotFooter shown instead of the ready-made buttons. If a function is given it receives { close, pending }. With null no footer is drawn at all.
showCloseButton?booleantrueShow a close (×) button in the top right corner?
closeOnBackdropClick?booleantrueClose on backdrop click? Pass false for forms where you don't want the user to lose data by accident.
closeOnBackButton?booleantrueShould the browser or phone back button close the window?
swipeToClose?booleantrueSwipe to close with a finger.
stickyHeader?booleantrueShould the header (title, description, icon) stay fixed? When true, only the body scrolls with long content and the header is always visible. When false, the header scrolls with the body.
stickyFooter?booleantrueShould the footer (buttons) stay fixed? When true, the buttons are always visible with long content and the body scrolls above them. When false, the footer is at the end of the content and scrolls with the body.
className?stringClasses added to the window itself.
classNames?ModalClassNamesClasses added to the inner parts.