Mobile shell (Pro)
ProIncluded in $99The phone shell for a chat app: swipe the chat aside for the sidebar, on a spring that carries the flick, with safe areas handled.
On this page
Installation
Needs chatcn Pro
This command works with a Pro license, along with every Pro component.
Or start free: sign up and get three Pro components on us, with a new one every month.
Usage
import { MobileShell, MobileShellTrigger } from "@/components/ui/chatcn/pro/mobile-shell"
<MobileShell sidebar={<ChatList />}>
<ChatScreen header={<MobileShellTrigger />} />
</MobileShell>Swipe the chat toward the end side and it slides over to show the sidebar underneath, which eases out a little behind it; the chat dims, goes inert and closes on a tap. The swipe follows the finger, resists past fully open, and on release carries its velocity into a critically damped spring that a new touch can catch. Only a clearly sideways move starts it, and a swipe toward the start on the closed shell is left to the chat, so swipe-actions rows keep working; swipe="edge" opens only from the start edge. MobileShellTrigger is the menu button for everyone not swiping, Escape closes, focus moves into the sidebar on open and back to the trigger on close. Safe areas come from the phone frame's --chatcn-safe-* or env(safe-area-inset-*). Mirrored in right to left layouts. useMobileShell reads and sets the open state from your own controls.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
sidebar | ReactNode | What slides in from the start side |
open, defaultOpen, onOpenChange | boolean | Controlled or not |
width | number | Sidebar width as a fraction of the screen. Default 0.84 |
swipe | "anywhere" | "edge" | Where an opening swipe may start |
labels | Partial<MobileShellLabels> | The sidebar's name |
Keyboard
| Key | Action |
|---|---|
| Enter on the trigger | Open or close |
| Escape | Close; focus returns to the trigger |
Accessibility
- The sidebar is a labelled region that is inert while closed; the chat is inert while it is open.
- The trigger reports whether the sidebar is expanded.
Motion
A critically damped spring, about 350 ms to rest, carrying the release velocity; the sidebar moves at 28% of the chat's speed for depth. Under reduced motion it opens and closes in place.