Skip to content

feat(amis-core): 导出 ThemeContext,支持局部主题设置 - #21486

Open
tianyk wants to merge 1 commit into
baidu:masterfrom
tianyk:feat/export-theme-context
Open

feat(amis-core): 导出 ThemeContext,支持局部主题设置#21486
tianyk wants to merge 1 commit into
baidu:masterfrom
tianyk:feat/export-theme-context

Conversation

@tianyk

@tianyk tianyk commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

问题

此前 ThemeContext 仅在 theme.ts 模块内部定义,未从 index.tsx 导出。导致只用 amis-ui 的场景无法通过 ThemeContext.Provider 局部设置主题,只能依赖 setDefaultTheme 全局修改。

改动

packages/amis-core/src/index.tsx 导出 ThemeContext,使用方可以直接通过 Context 局部设置主题。

用法

import {ThemeContext} from 'amis-core';

<ThemeContext.Provider value="antd">
  <Button>primary</Button>
  <Select options={[...]} />
</ThemeContext.Provider>

为什么需要这个改动

  • setDefaultTheme 是全局修改,影响所有 amis-ui 组件实例
  • ThemeContext 可以局部生效,不影响其他组件
  • render(schema, {theme: 'antd'}) 只对 amis 渲染树生效,不影响直接使用的 amis-ui 组件

此前 ThemeContext 仅在 theme.ts 模块内部定义,未从 index 导出,
导致只用 amis-ui 的场景无法通过 ThemeContext.Provider 局部设置主题,
只能依赖 setDefaultTheme 全局修改。

导出后可直接使用:
  import {ThemeContext} from 'amis-core';
  <ThemeContext.Provider value=antd>
    <Button>primary</Button>
  </ThemeContext.Provider>
@github-actions github-actions Bot added the feat label Jul 23, 2026
@github-actions

Copy link
Copy Markdown

👍 Thanks for this!
🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant