# Mobile shell

The phone shell for a chat app: swipe the chat aside for the sidebar, on a spring that carries the flick, with safe areas handled.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Mobile shell. Swipe the chat to the right, or tap the menu, for the sidebar. Flick it back or tap the chat to close. Preview: https://chatcn.dev/preview/mobile-shell-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/mobile-shell
```

## Usage

```tsx
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

Example: States. Open at real phone width, with swiping from the edge only. Preview: https://chatcn.dev/preview/mobile-shell-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.

Source: https://chatcn.dev/docs/components/mobile-shell