Back to Skills

modal

verified

Modal imperative API guide. Use when creating modal dialogs using createModal from @lobehub/ui. Triggers on modal component implementation or dialog creation tasks.

View on GitHub

Repository
Verified Org

lobehub/lobe-chat
70.5kstars

.agents/skills/modal/SKILL.md

Last Verified

January 25, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/lobehub/lobe-chat/blob/c0ffd8fab3fa59e614556a755ff49662846c5a0f/.agents/skills/modal/SKILL.md -a claude-code --skill modal

Installation paths:

Claude
.claude/skills/modal/
Powered by add-skill CLI

Instructions

# Modal Imperative API Guide

Use `createModal` from `@lobehub/ui` for imperative modal dialogs.

## Why Imperative?

| Mode | Characteristics | Recommended |
|------|-----------------|-------------|
| Declarative | Need `open` state, render `<Modal />` | ❌ |
| Imperative | Call function directly, no state | ✅ |

## File Structure

```
features/
└── MyFeatureModal/
    ├── index.tsx           # Export createXxxModal
    └── MyFeatureContent.tsx # Modal content
```

## Implementation

### 1. Content Component (`MyFeatureContent.tsx`)

```tsx
'use client';

import { useModalContext } from '@lobehub/ui';
import { useTranslation } from 'react-i18next';

export const MyFeatureContent = () => {
  const { t } = useTranslation('namespace');
  const { close } = useModalContext(); // Optional: get close method

  return <div>{/* Modal content */}</div>;
};
```

### 2. Export createModal (`index.tsx`)

```tsx
'use client';

import { createModal } from '@lobehub/ui';
import { t } from 'i18next'; // Note: use i18next, not react-i18next

import { MyFeatureContent } from './MyFeatureContent';

export const createMyFeatureModal = () =>
  createModal({
    allowFullscreen: true,
    children: <MyFeatureContent />,
    destroyOnHidden: false,
    footer: null,
    styles: { body: { overflow: 'hidden', padding: 0 } },
    title: t('myFeature.title', { ns: 'setting' }),
    width: 'min(80%, 800px)',
  });
```

### 3. Usage

```tsx
import { createMyFeatureModal } from '@/features/MyFeatureModal';

const handleOpen = useCallback(() => {
  createMyFeatureModal();
}, []);

return <Button onClick={handleOpen}>Open</Button>;
```

## i18n Handling

- **Content component**: `useTranslation` hook (React context)
- **createModal params**: `import { t } from 'i18next'` (non-hook, imperative)

## useModalContext Hook

```tsx
const { close, setCanDismissByClickOutside } = useModalContext();
```

## Common Config

| Property | Type | Description |
|----------|------|-------------|
| `allowFullscreen

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
2215 chars