SidePanel
A row's detail and its edit form, a drawer from the inline-end edge on a desktop and a bottom sheet on a phone.
'use client';
import {
Button,
CopyText,
KeyValueList,
SidePanel,
StatusChip,
} from '@nyxon/nasim';
import { useState } from 'react';
const copy = {
open: 'جزئیات سرویس',
title: 'ماهانه ۵۰ گیگ',
description: 'خریدهشده در ۱ آبان ۱۴۰۵',
status: 'وضعیت',
active: 'فعال',
left: 'باقیمانده',
leftValue: '۱۸ روز، ۳۲ گیگابایت',
id: 'شناسهٔ سرویس',
close: 'بستن',
renew: 'تمدید',
};
// A sample id; a real one comes from the API.
const serviceId = 'srv-1042';
// A row's detail: a drawer from the inline-end edge on a desktop, the bottom sheet on a phone.
export default function Detail() {
const [isOpen, setOpen] = useState(false);
return (
<>
<Button variant="secondary" onPress={() => setOpen(true)}>
{copy.open}
</Button>
<SidePanel
isOpen={isOpen}
onOpenChange={setOpen}
title={copy.title}
description={copy.description}
footer={
<>
<Button variant="tertiary" onPress={() => setOpen(false)}>
{copy.close}
</Button>
<Button onPress={() => setOpen(false)}>{copy.renew}</Button>
</>
}
>
<KeyValueList
layout="stacked"
items={[
{
label: copy.status,
value: <StatusChip tone="success" label={copy.active} />,
},
{ label: copy.left, value: copy.leftValue },
{
label: copy.id,
value: <CopyText value={serviceId} label={copy.id} isLtr />,
},
]}
/>
</SidePanel>
</>
);
}Import
import { SidePanel } from '@nyxon/nasim';Usage
Controlled only: isOpen and onOpenChange. title, an optional description (also its accessible
description), children (the body, which scrolls) and footer (the cancel first, the main action last;
it stays under the body, so it is always in reach). size is "sm" (420 px), "md" (480 px, the default)
or "lg" (560 px); a narrower screen takes what it has. It is a client component.
From sm up it is a drawer from the inline-end edge: the left in a right-to-left page, the right with
dir="ltr". On a phone it is the bottom sheet, with its drag handle and its safe areas.
<SidePanel
isOpen={open}
onOpenChange={setOpen}
title={t.services.detailTitle}
footer={actions}
>
{details}
</SidePanel>Examples
A row's detail
Shown above. Switch the preview to LTR to see the drawer change sides, or to 390 px to see the sheet.
A long body
The body scrolls inside the panel and the page behind it does not move. A panel without a footer draws
none.
'use client';
import { Button, SidePanel } from '@nyxon/nasim';
import { useState } from 'react';
const copy = {
open: 'گزارش فعالیت',
title: 'فعالیتهای این هفته',
};
const events = [
'ورود از دستگاه تازه، تهران',
'تمدید خودکار «ماهانه ۵۰ گیگ»',
'تغییر رمز عبور',
'افزودن کارت بانکی',
'خرید «هفتگی ۱۰ گیگ»',
'ورود از تلگرام',
'درخواست بازگشت وجه',
'پاسخ پشتیبانی به تیکت ۸۸',
'ورود از دستگاه تازه، شیراز',
'تغییر شمارهٔ تماس',
'خروج از همهٔ دستگاهها',
'خرید «ماهانه ۵۰ گیگ»',
];
// A long body scrolls inside the panel (a named, focusable region); the page behind does not move.
// No footer: a panel without one draws none.
export default function Activity() {
const [isOpen, setOpen] = useState(false);
return (
<>
<Button variant="ghost" onPress={() => setOpen(true)}>
{copy.open}
</Button>
<SidePanel
isOpen={isOpen}
onOpenChange={setOpen}
title={copy.title}
size="sm"
>
<ol className="flex flex-col divide-y divide-separator">
{events.map((event) => (
<li key={event} className="py-3">
{event}
</li>
))}
</ol>
</SidePanel>
</>
);
}Rules
- A good detail panel, read from the top: who or what it is, small muted labels over the groups, the
fields as a
KeyValueListwith aCopyTextbeside every id. isDismissable={false}for a form with unsaved input: only its own buttons and the host's Back close it.isBusycloses it by nothing while a request runs; after ten seconds busy the close button and the host's Back work again (the backdrop, a drag and Escape stay blocked), and the request is not cancelled, so report its outcome from your own handlers.
Accessibility
It behaves like Modal: a modal dialog named by its title, the focus inside while it is open and back on
the opener when it closes. A body that scrolls is a named, focusable region, so a keyboard can scroll it,
and scrolling stays inside it (overscroll-behavior: contain). It registers as a layer, so Telegram's Back
button closes it. Under prefers-reduced-motion: reduce it fades in and out without travelling.
API
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | required | |
onOpenChange | (isOpen: boolean) => void | required | |
title | string | required | |
description | ReactNode | — | Under the title; the panel is described by it. |
children | ReactNode | required | The scrolling body. |
footer | ReactNode | — | Action buttons: the cancel first, the main action last. It stays in view under the body. |
size | "lg" | "md" | "sm" | — | 420, 480 or 560 px wide from sm up; a phone gets the bottom sheet. Default "md". |
isDismissable | boolean | — | false for a form with unsaved input: a backdrop press, a drag and Escape close nothing. |
isBusy | boolean | — | A request is running: nothing closes the panel until it is over. |
closeLabel | string | — | Names the close button; defaults to «بستن». |
className | string | — |
Related
BottomSheet (what it is on a phone), Modal, KeyValueList and CopyText (what a detail holds).