通过实际操作产品验证交付内容,记录用户可查看的证据,并发布验收报告。可检查已有验证计划或创建检查项,选择合适的操作界面,并使用 `lh` CLI 发布结果。
- 实际检查更改后的产品行为
- 收集截图或其他验证证据
- 编写验证计划和报告
介绍如何使用 `@lobehub/ui/base-ui` 实现模态框和确认对话框,涵盖内容组织、必需的 `ModalHost`、关闭回调及常用选项,帮助正确处理关闭行为和状态清理。
Use for modals, dialogs and confirmations with createModal, confirmModal, ModalHost or base-ui modal APIs.
实测评分 未实测
查看安装方法这份指南介绍如何使用 @lobehub/ui/base-ui 中的 createModal、confirmModal 和 ModalHost 实现模态框。它说明如何拆分模态框容器和内容,如何在内容中通过 useModalContext 关闭模态框,以及如何设置标题、宽度和点击背景关闭等选项。指南还解释了通过不同方式关闭模态框时,onOpenChange 与 onOpenChangeComplete 的触发情况并不相同,帮助开发者为调用方的状态清理选择合适的回调。
要添加确认对话框或某项功能专用的模态框时,可以参考本指南。模态框关闭后状态仍然残留时,也可以用它检查清理逻辑。
要让 createModal 显示内容,必须在应用根部附近挂载一次来自 @lobehub/ui/base-ui 的 ModalHost。新代码应使用 base-ui,避免继续使用根包的旧 API。
本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。
AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。
不计入评分。 由 AI(OpenAI Codex)于 2026年10月26日 评估。仅供参考,安装前请同时查看原文。
安装前可以查看交给 AI 代理的指令内容。
@lobehub/ui/base-uiNew code should use the base-ui modal stack (headless primitives, not antd Modal):
createModal, confirmModal, ModalHost from @lobehub/ui/base-uiuseModalContext from @lobehub/ui/base-ui inside modal contentBody slot: pass content (or children; runtime uses content ?? children).
ModalHost (required)Base-ui createModal renders through a separate host from the root package. The app must mount ModalHost from @lobehub/ui/base-ui once near the root (e.g. next to other global hosts). Without it, createModal calls will not appear.
If the project only mounts ModalHost from @lobehub/ui, add a second lazy ModalHost from @lobehub/ui/base-ui until all imperative modals are migrated.
| Mode | Characteristics | Recommended |
|---|---|---|
| Declarative | open state + <Modal /> | ❌ |
| Imperative | Call createModal(), no local state | ✅ |
features/
└── MyFeatureModal/
├── index.tsx # export createXxxModal
└── MyFeatureContent.tsx # modal body
MyFeatureContent.tsx)'use client';
import { useModalContext } from '@lobehub/ui/base-ui';
import { useTranslation } from 'react-i18next';
export const MyFeatureContent = () => {
const { t } = useTranslation('namespace');
const { close } = useModalContext();
return <div>{/* ... */}</div>;
};
createModal (index.tsx)'use client';
import { createModal } from '@lobehub/ui/base-ui';
import { t } from 'i18next';
import { MyFeatureContent } from './MyFeatureContent';
export const createMyFeatureModal = () =>
createModal({
content: <MyFeatureContent />,
footer: null,
maskClosable: true,
styles: {
content: { overflow: 'hidden', padding: 0 },
},
title: t('myFeature.title', { ns: 'setting' }),
width: 'min(80%, 800px)',
});
import { createMyFeatureModal } from '@/features/MyFeatureModal';
const handleOpen = useCallback(() => {
createMyFeatureModal();
}, []);
return <Button onClick={handleOpen}>Open</Button>;
useTranslation in components.createModal options: import { t } from 'i18next' where hooks are unavailable.useModalContextconst { close, setCanDismissByClickOutside } = useModalContext();
close() — from useModalContext() inside the content, or from the returned
ModalInstance — only flips the stack entry to open: false. It does not go
through base-ui's dismissal path, so:
| callback | user dismissal (Esc / backdrop / header ✕) | close() from content or instance |
|---|---|---|
onOpenChange | fires | does not fire |
onOpenChangeComplete | fires with false | fires with false |
Put caller-side cleanup (clearing an editing flag, resetting the provider's
open state) on onOpenChangeComplete. Wiring it to onOpenChange looks
correct until a footer button closes the modal, and then the caller never learns
it went away — typically leaving a flag set so the modal cannot be reopened.
createModal only ever completes with false (the imperative renderer supplies
the argument itself and never forwards the prop to base-ui), but still guard on
it — other base-ui primitives such as DropdownMenu do report both directions,
and the guard keeps the call site from depending on that difference:
onOpenChangeComplete: (open) => {
if (!open) onClosed?.();
},
ImperativeModalProps builds on BaseModalProps: title, width, maskClosable, open, onOpenChange, footer, styles / classNames (keys: backdrop, popup, header, title, close, content, …).
| Property | Notes |
|---|---|
content | Main body (preferred name vs children) |
maskClosable | Click outside to dismiss |
styles.* | Semantic regions, not antd styles.body |
import { confirmModal } from '@lobehub/ui/base-ui';
confirmModal({
title: '…',
content: '…',
okText: '…',
cancelText: '…',
onOk: async () => {},
});
@lobehub/ui (root)createModal from the root @lobehub/ui entry is typed as antd Modal props (children, allowFullscreen, getContainer, destroyOnHidden, styles.body, etc.). App code no longer imports it; do not reintroduce it — use @lobehub/ui/base-ui.
ModalHost is mounted.src/features/SkillStore/index.tsx, src/features/LibraryModal/CreateNew/index.tsx还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
通过实际操作产品验证交付内容,记录用户可查看的证据,并发布验收报告。可检查已有验证计划或创建检查项,选择合适的操作界面,并使用 `lh` CLI 发布结果。
本技能指导在 LobeHub 中接入 AI 模型提供商,涵盖运行时、模型信息、设置、品牌展示、文档和验收,并帮助判断新增模型是否需要新的提供商集成。
本技能指导如何用服务器端环境变量设置用户偏好默认值,涵盖变量校验、服务器配置、写入用户状态,以及更新 `.env.example` 和自托管文档。
说明如何在智能体执行步骤、工具调用、人工审批、上下文压缩和子智能体调用时注册钩子。钩子可观察事件、模拟本地工具结果,也可通过 Webhook 按配置策略允许或拒绝工具调用。
此技能用于为智能体设计事件驱动的后台工作流,划分来源、信号、动作和策略的职责,并处理异步交接、去重、执行范围、完成记录与运行观测。
本技能在 macOS 桌面聊天应用中测试机器人频道:打开应用、进入频道或联系人、发送消息、等待回复并截图。支持 Discord、Slack、Telegram、微信、飞书和 QQ;iMessage 使用 BlueBubbles 桥接。