主题令牌(Theme)
主题令牌:Theme 是 IDL 定义的跨端 UI 组件,props / events / behaviors 在各平台语义一致。本页给出契约属性、事件、渲染行为、数据源与 Web 端绑定/示例。
契约属性(props)
| 属性 | 类型 | 必填 | 说明 |
|---|---|---|---|
mode | 'light'|'dark' | 是 | light / dark |
colors | {primary,background,surface,text,textSecondary,bubbleMine,bubbleOther,danger,mention} | 是 | 主题颜色令牌集合:{ primary:, background:, surface:, text:, textSecondary:, bubbleMine:, bubbleOther:, danger:, mention: } |
事件
该组件未声明事件;交互通过属性和宿主回调完成。
渲染行为
- 默认跟随系统;宿主可覆盖令牌;暗色对比度满足可读性
数据源
未在 IDL 声明 dataSource;由宿主从 IMLib 拉取(getConversationList / getHistoryMessages / MESSAGES / CONVERSATION 事件)。
依赖边界
组件不直连网络与数据库:会话/消息由宿主从 IMLib 拉取后传入,组件只做排序、角标、格式化与渲染。
平台绑定
| 项 | 值 |
|---|---|
| 公开符号 / 签名 | IMKit.mount(container, 'Theme', props) |
| 导出列表包含 | 是 |
| UI 框架 | 纯 DOM 组件(无框架依赖),CSS 变量主题,IMKit.mount(container, component, props) |
使用示例
JavaScript (ESM)
import { IMKit, Theme } from '@ni-paas/im-web/imkit';
const theme = Theme.dark({ primary: '#818CF8', bubbleMine: '#4f46e5' });
IMKit.setup({ theme, locale: 'zh-CN' });
IMKit.mount(document.getElementById('app'), 'ConversationListView', { conversations });