Sheet
A panel that comes up from the bottom edge of a phone with a few options, close to the thumb.
import { Sheet } from '@sypnia/ui/react'
More sections
Press «More»: the sections that do not fit in the bar.
Code
import { useState } from 'react';
import { Button, Sheet } from '@sypnia/ui/react';
// It comes up from the bottom edge. A press outside or Escape closes it.
export default function Options() {
const [open, setOpen] = useState(false);
const [section, setSection] = useState('Tables');
const go = (s: string) => { setSection(s); setOpen(false); };
return (
<div className="sy-row">
<Button icon="more" onClick={() => setOpen(true)}>More</Button>
<span className="sy-text--sm sy-text--soft">You are in: {section}</span>
<Sheet open={open} onClose={() => setOpen(false)} title="More sections">
<Button block variant="quiet" icon="key" onClick={() => go('API keys')}>API keys</Button>
<Button block variant="quiet" icon="users" onClick={() => go('Team')}>Team</Button>
<Button block variant="quiet" icon="shield" onClick={() => go('Access rules')}>Access rules</Button>
<Button block onClick={() => setOpen(false)}>Close</Button>
</Sheet>
</div>
);
} A quick choice
Sort a list with one press.
Code
import { useState } from 'react';
import { Button, Fieldset, Radio, Sheet } from '@sypnia/ui/react';
const orders = ['Newest first', 'Oldest first', 'Highest total', 'Lowest total'];
// A short choice on a phone: the options are large and close to the thumb.
export default function Choice() {
const [open, setOpen] = useState(false);
const [order, setOrder] = useState(orders[0]);
return (
<>
<Button icon="sort" onClick={() => setOpen(true)}>Sort: {order}</Button>
<Sheet open={open} onClose={() => setOpen(false)} title="Sort the orders">
<Fieldset legend="Sort the orders">
{orders.map((o) => <Radio key={o} name="sheet-order" label={o} checked={o === order} onChange={() => setOrder(o)} />)}
</Fieldset>
<Button block variant="primary" onClick={() => setOpen(false)}>Show orders</Button>
</Sheet>
</>
);
} When to use it
Use it when
- On phones: the «More» of the navigation, a short list of actions, a quick choice.
- The options are few and each is a large target.
Do not use it when
- On a desktop: a Menu or a Popover sits next to what opened it.
- It holds a form with several fields: a Drawer fills the phone screen and gives it room.
- It asks to confirm something: ConfirmDialog.
For everyone
- It is a dialog named by its
title, which is read by screen readers though it is not shown. - Escape or a press on the backdrop closes it (a drag that starts inside does not), and focus returns to what opened it. Include a visible «Close» button for people who do not know that gesture.
- It never takes more than 85% of the height, and its content scrolls inside.
Props
| Sheet | Type | Default |
|---|---|---|
onCloserequired | () => void | |
titlerequired | ReactNode | |
dirtyThe form inside has changes that are not saved. A press outside or Escape then does not close it and does not lose them: the panel nudges and says to save or cancel. Only the buttons close it. | boolean | |
dismissableWhether a press on the backdrop (outside the panel) closes it. On by default; Escape always closes it too. Set false for a form that must be finished or cancelled with its buttons. | boolean | |
linesHow many lines of skeleton the body shows while loading. | number | |
loadingWhat it shows is on its way: the title and the buttons stay, the body is lines of skeleton. | boolean | |
openWhether it is open. It can also simply be mounted and unmounted: it is open while mounted. | boolean |