ConfigProvider
常规设置:区域设置、RTL、维度、主题、组件设置和容器。
何时使用
ConfigProvider 指定 Svelte 树的常规设置:主题、语言、方向、大小和组件设计。将其放置在应用程序周围或具有自己的设置的单独区域。嵌套提供程序允许独立设计部分和示例的样式。
提供者将上下文传递给子组件并创建主题 DOM 包装器。组件的本地 props 指定公共值;组合主题、语言环境和组件配置的规则是不同的。
常规设置和继承
未指定的值从最近的提供者继承。显式的本地 size 或 disabled 指定通用的 componentSize/componentDisabled。 direction 指定ltr/rtl,locale 是组件的部分字典。
| 问题 | 设置 | 示例 |
|---|---|---|
| 配置区域大小和可用性 | componentSize、componentDisabled |
尺寸和可用性 |
| 翻译组件签名 | locale |
语言环境 |
| 改变方向 | direction |
方向 |
| 隔离嵌套主题 | theme.inherit |
继承与隔离 |
| 组建单亲家庭 | 组件配置 | 组件设置 |
传递的组件配置将替换整个相应的父记录。例如,嵌套 button 不会自动填写外部 button 的每个字段。 theme.token 和 locale 使用它们自己的部分继承。 设置示例 显示本地异常和记录替换。
通过 ConfigProvider.modal 可以为声明式对话框和上下文确认框设置共用的类名和样式。实例的类名会追加到共用类名中,实例的 CSS 最后应用。在备注编辑器示例中,两个窗口继承相同的内边距,编辑窗口还可以将其缩小。
ConfigProvider.upload 指定通用 class/style、classNames/styles、accept、customRequest 和 progress。 示例上传 显示继承、空嵌套记录和本地覆盖。本地 accept,包括空字符串,customRequest 优先于一般的。课程积累;通用槽 CSS 行在本地槽 CSS 行之前应用,常规 style 应用于触发器。进度跨字段合并:局部空对象并不能清除整体 progress。新的请求处理程序将应用于以下文件,并保存当前请求。完整的合约在 Upload 中描述。
ConfigProvider.tree 为 Tree 和 DirectoryTree 提供 class/style 和 semantic classNames/styles。Tree 样式示例 展示局部 callback 以及通过 tree={} 替换嵌套配置。TreeSelect 的内部树不继承此配置对象。
ConfigProvider.virtual 为 Tree/DirectoryTree、TreeSelect、Listy、Select 和 AutoComplete 设置共用模式。Tree 和 TreeSelect 在高度与行高估计非零时使用窗口,Listy 默认保持 raw mode。Select 和 AutoComplete 默认开启虚拟化。分组提示展示了继承方式。Select/AutoComplete 显式传入 virtual=undefined 时启用 default=true,Tree/TreeSelect/Listy 则继承共用模式。 虚拟树.
ConfigProvider.form 设置默认标签、requiredMark、tooltip、语义 classNames/styles 和 scrollToFirstError。本地道具 form 优先。空的嵌套形式替换整个记录; Form.tooltip 分别组合了全局和本地工具提示选项。大小和 disabled 由表单或最近的 ConfigProvider 设置,而不是由表单记录字段设置。 表格示例 显示了语义默认值的应用。
错误模板是通过 locale.Form.defaultValidateMessages 之上的 form.validateMessages 设置的。本地 Form.validateMessages 优先,rule.message 优先级最高。嵌套提供程序组与区域设置相结合;本地表单组替换整个相应的组。 表单模板示例 显示了差异。
对于字段,variant 顺序为:本地 prop、最接近的 Form.variant、组件配置、常规 ConfigProvider.variant、outlined。对于InputPassword/InputSearch/InputOTP,在其自身配置后,会检查 input.variant。没有 variant 的嵌套表单会重置外部表单的 variant。卡片的本地版本仅限于有 outlined/borderless;继承的 filled/underlined 保留边框。
统计、步骤和时间线支持自己的记录 statistic/步骤/时间线:class、style、classNames 和 styles。本地设计优先;嵌套的空记录替换祖先的默认记录。 Statistic、Steps 和 Timeline 显示优先级。对于 timeline,保存根 steps.class/style,但不保存 steps 的语义设置。本地 prefixCls 由组件自己设置; theme.cssVar.prefix 不会取代它。
ConfigProvider.layout 仅指定布局容器的 class/style。页眉/内容/页脚和侧边部分不直接接收记录。地方风格先于通用 style;空的嵌套 layout 将替换整个记录。 布局示例 显示更新设置时的优先级和状态保存。
可以从 @woodger/antd/locale 导入现成的语言字典。切换语言示例导入简体中文字典,切换日历、分页和对话框的文字。
通用类前缀
内置图标使用最近的提供器所设置的 iconPrefixCls,默认值为 anticon。该设置适用于 Select、AutoComplete、TreeSelect、Cascader、CascaderPanel、Input 及其变体、InputNumber、Form、Alert、Progress、Result 以及 Button 的加载图标。在面板和 Affix 示例中,此设置会更改 Alert 图标的类名前缀。
ConfigProvider.prefixCls 设置基本 CSS 前缀,默认为 ant。undefined 和空字符串继承父前缀。当前连接的有App、Layout、LayoutSider、LayoutHeader/Content/Footer、Statistic/Timer、QRCode、Steps、Timeline、Divider、Flex、Segmented、Avatar/AvatarGroup、Badge/BadgeRibbon、Tag/CheckableTag/CheckableTagGroup、Empty、Skeleton及其元素、Spin、Progress、Result、Alert、Collapse、Affix、Tooltip、Popover、 Popconfirm、Slider、BorderBeam、Masonry、Splitter、Anchor、Space、SpaceCompact、SpaceAddon、Breadcrumb、Row、Typography、Carousel 和说明。例如,suite 提供 suite-app、suite-layout-header 和 suite-segmented。下面列出了其他连接的族及其前缀功能。
组件的非空本地 prefixCls 优先并指定完整的类。例如,LayoutHeader prefixCls="region" 获取区域而不添加后缀。空的本地 prop 返回提供者的后备,而不一定是蚂蚁。 常用前缀 显示嵌套继承、本地 Sider、独立邻居和草稿/collapse 保存。
指标和历史 显示统计/计时器、QRCode、步骤和时间线。 Timeline 的内部 Steps 分别继承公共 prefix:使用 suite 和 local Timeline.prefixCls="local-history" 根接收 local-history 和 suite-steps。时间轴本地前缀不会重命名 Steps 类。
布局和选择 显示分隔线、Flex和分段线。空嵌套提供程序和实例 prefixCls 继承父前缀。更改通用或本地前缀会保留所选值和 radio DOM;它本身不会调用 onChange。 name Segmented 保留当前形式的契约:本机 radio 发送,因此应用程序值应从 bind:value 或 onChange 获取。
状态和头像 显示头像/组、徽章/丝带、标签/可检查标签/组、Empty、具有五个独立元素的骨架、Spin、进度和结果。对于Badge来说,本地 prefixCls 不会改变 ScrollNumber:它单独继承通用前缀或 scrollNumberPrefixCls。 CSS ScrollNumber 和 Ribbon 几何图形遵循通用的提供程序前缀。本地 prefixCls AvatarGroup 不会重命名成员的头像。
面板和固定物 在独立的 scroll target 中显示警报、折叠和活动固定。更改前缀会保留展开的面板和编辑器 DOM、其值、焦点和选择。在 SSR 中,Affix 保留在线程中,没有附件类。
弹出窗口和滑块 显示工具提示、弹出窗口、Popconfirm 和 single/range 滑块。 Slider工具提示分别继承Tooltip前缀或者 tooltip.prefixCls;本地比例前缀不会影响它们。本地 Popconfirm.prefixCls 更改确认类,外部Popover单独继承公共前缀。软件更新保留打开的 popup、trigger 和编辑器的 DOM;面板外的常规 pointerdown 仍然会关闭它。在 SSR 中,shell 保持隐藏状态,无需打开 popup 并调用容器。
BorderBeam、Masonry 和 Splitter 还共享服务几何的本地类和公共命名空间。它们的服务变量的前缀取自 ConfigProvider.prefixCls,不带点,与本地 prefixCls 和 theme.cssVar.prefix 无关。组件页面上的示例在不同范围内显示相同的本地类,并保留 DOM、焦点和维度。
在 Anchor 中,缺少的 item.prefixCls 继承了所有者的前缀,并且显式的空字符串选择了提供者的前缀。对于Space / Compact / Addon,每个组件独立选择一个前缀; local Compact 不会重命名子单元格和字段。插件服务变量使用不带点的通用前缀,与主题的命名空间分开。
Breadcrumb 将允许的前缀传递给子句和所有分隔符,包括 type:separator。本地路径前缀不会更改单个下拉菜单/菜单的外观。更改通用或本地前缀会保留链接和打开的菜单。
Row 更改行和布局状态类,同时保持 responsive gutter 和列上下文。 Col还支持独立的本地 prefixCls;响应类更改,服务变量使用不带点的公共提供者前缀。所有Typography变体单独选择一个前缀;操作和编辑器遵循其文本前缀,工具提示遵循其自己的设置。更改前缀会保留活动输入和复制状态。
Carousel 更改外部包装和进度动画,保留 Slick 类。嵌套单选/复选框选择器取决于全局前缀提供程序,而不是本地 Carousel.prefixCls 或主题命名空间。当前幻灯片、编辑器和公共 ref 将被保存。
Descriptions 将解析后的前缀传递给所有单元格和标头,保留 DOM、字段和 FormData。在展开的表格行中,样式尊重本地描述前缀,与通用表格前缀分开;该示例为 Table 保留了一个独立的 ant 作用域。
Table 继承带有 -table 的公共前缀或完全限定的本地名称 prefixCls。包装器、行、单元格、排序和过滤项使用表名称; Checkbox、Button、Pagination 和 popup shell 是它们的常见前缀。 dropdownPrefixCls 仅通过添加 -menu 更改过滤器列表的基本名称。更改名称会保留打开的行及其编辑器、选择、页面、打开的过滤器和滚动。 theme.components.Table、标记 ant-table-css-var 和命名空间 theme.cssVar.prefix 独立于本地类; nested-border-top 服务变量使用不带点的通用前缀。
Button、Tabs 和 Card 支持本地和全局前缀。 CardGrid/CardMeta 没有自己的 prop 继承 Card;空行选择提供者。 FloatButton同样继承了Group。所有者本地类不会重命名单个按钮、输入或版式。
Radio、Checkbox 和 Switch 保留数值和本机控件。 Group 将基本前缀传递给其 options;任意 children 独立选择。 Input 和 TextArea 共享基本的 Input 命名空间; Password/Search有独立的 inputPrefixCls,OTP有自己的 prefixCls。 InputNumber、Mentions 和 Form 也已连接。 FormItem选择前缀与Form无关; FormList.prefixCls 设置 ErrorList 的样式。媒体 CSS 表单尊重其主题的屏幕*max设计令牌(design tokens)。
Rate、Listy、Tour 和 Image 有命名空间更改的示例。 Image.previewPrefixCls - 完整查看器前缀; ImagePreviewGroup.previewPrefixCls 被赋予一个会自动添加 -preview 后缀的基本名称。嵌套按钮/工具提示和组缩略图保留自己的前缀。
Dropdown、Menu、Pagination、Drawer 和 Modal 支持更改 prefixCls 而无需重置打开状态。 MessageHolder 和 NotificationHolder 接受本地 prefixCl。在 App 中,无论 App.prefixCls 如何,都通过 message.prefixCls 和 notification.prefixCls 指定相同的设置。确认前缀在 ModalConfirmConfig 中设置。
Upload/Dragger、Tree、Transfer、Select、AutoComplete 和 TreeSelect 也已连接。 AutoComplete的Select命名空间发生变化,嵌套编辑器是独立的。 TreeSelect 从同一本地 prop 解析 Select 和 TreeSelect 命名空间,保留本机 Tree 适配器。
Cascader 和 CascaderPanel 对字段使用 common -select,对列使用 common -cascader。非空本地 prefixCls 成为两个部分的完整前缀;搜索 render 获取允许的 Cascader 前缀。更新名称时,将保存选定的路径、编辑器和打开的弹出窗口。
ColorPicker 允许本地前缀,无论 Popover、字段和预设组如何。嵌套输入/选择/输入编号、滑块、分隔符、分段和折叠继承通用提供程序前缀。更改名称会保留不完整的十六进制、颜色和打开的面板;本机按钮和容器在同一区域运行。
Calendar 与 -picker 共享前缀; local prefixCls 指定Picker的完整基本名称,根附加 -calendar。单元格和渲染器遵循此名称,Select/Radio 标头是独立的公共前缀。更新名称时,保留毫秒日期、DOM 和焦点。
DatePicker / RangePicker 和 TimePicker / TimeRangePicker 使用带有 -picker 的公共前缀或完全限定的本地名称。字段、popup、日历和列遵循其选择器的名称; OK 按钮独立继承 Button 前缀。此时 cellRender.info.prefixCls 和 originNode 使用已解析的 Picker 名称。更改前缀后,面板会保持打开,并保留输入、选区和尚未确认的时间。受控时间范围也支持这一行为。prefix/suffix 颜色服务变量使用与 theme.cssVar.prefix 分开的通用无点前缀;保留规范的主题标记。即使没有主题源设置,自己的前缀也可以工作:mode/primary/compact 继续设计字段、面板和日历。
prefixCls 类和 theme.cssVar.prefix 是不同的设置。对于源主题,后备命名空间遵循当前提供程序的基本前缀。继承的 cssVar.prefix 优先于新的 prefixCls;本地 cssVar.prefix - 两者。显式 cssVar.prefix:undefined 删除继承的值并返回当前范围的回退,包括当 inherit=false 时。如果没有本地主题,则保留父 theme 范围和命名空间。
CSS variables 通过 theme.useToken().cssVar 显示这些优先级。在没有源主题设置的树中,仅使用 mode/primary/compact,保存命名空间 ant。规范标记和 --ant-* 桥未重命名。更改公共前缀可以保留 DOM 控件、焦点和值; SSR 立即接收所需的类和源变量。
主题和令牌读取
theme.token 指定初始和共享令牌。算法接受一个 algorithm 或它们的序列; theme.defaultAlgorithm、theme.darkAlgorithm 和 theme.compactAlgorithm 可用。 算法示例 反应式切换黑暗和紧凑的设计。
全局 theme.token.screen* 控制 Descriptions 的 responsive 列/span,就像网格一样。嵌套提供程序继承阈值,inherit:false 返回默认值。更改令牌即可替换媒体查询,无需重新挂载;在安装之前,后备将保存在三列中。 screenSMMin 参与查序,请求sm使用 screenSM; SSR 已拒绝错误的边界顺序。
相同的令牌控制 responsive Pagination 和 Masonry 的 columns/两个 gutter 轴。分页使用 screenXSMax,无需显式设置 size 或 componentSize;迷你班不保证较低的身高。在 Masonry 中,如果没有匹配,columns 将回退到 xs 或一列,并且 gutter 将单独解析。更改 token 会保留 DOM 和状态;继承和 inherit:false 也适用于此。这些规则适用于主题的源引擎正在启用;正常模式使用标准边界。
theme.components 指定特定系列的设置。检查每个组件令牌页面的帮助部分以获取支持:将令牌使用移植到 CSS 仍在进行中。组件配置对象和 theme.components 解决不同的问题:第一个设置 props/defaults,第二个设置设计标记。
当 theme.inherit=false 时,父令牌、算法和 components 将被重置。 locale、direction 和 componentSize 保留其正常继承。 hashed、cssVar 和 zeroRuntime 有单独的继承;inherit=false 不会自动重置它们。
theme.useToken。同一组件标记中的 ConfigProvider 不会更改已执行脚本的上下文。因此,该示例使用单独的 TokenReadout。读取标记或 $derived 中的结果字段以保持反应性。
theme.getDesignToken 根据传递的设置执行静态计算,不会更改页面的主题。 静态计算 将其与上下文 useToken 分开显示。
样式的 nonce
如果服务器在 Content-Security-Policy 中为每次响应生成一个 nonce,请在服务端渲染和水合时将同一个值传给 csp。组件库会将它添加到为主题、CSS 类名前缀以及 ShadowRoot 内对话框滚动锁定生成的 <style> 元素上。
<script lang="ts">
import { Button, ConfigProvider } from '@woodger/antd';
let { nonce }: { nonce: string } = $props();
</script>
<ConfigProvider csp={{ nonce }} prefixCls="docs">
<Button type="primary">OK</Button>
</ConfigProvider>
嵌套的提供器会在省略 csp 或其值为 undefined 时继承该设置。传入 csp={{}} 可以清除继承的 nonce。值发生变化时,组件库会替换样式元素并保留焦点。打包生成的样式表和 style 属性的策略由应用设置。
容器、空状态和支架
popupMatchSelectWidth 设置 Select、AutoComplete 和 TreeSelect 的共用面板宽度。true 匹配字段宽度,false 按内容自适应,数字指定像素宽度。字段宽度始终是最小值。省略属性或传入 undefined 会继承父级;没有共用设置时使用 true。共用面板宽度展示继承、嵌套 true 重置和局部属性优先级。
Cascader 使用自己的局部 popupMatchSelectWidth。Pagination 默认传入局部 false,可由 showSizeChanger 设置覆盖。Calendar 继承共用宽度,菜单保留在日历头部。ColorPicker 为内部 Select 设置局部宽度 68 px 和独立容器。
popupOverflow 设置 Select、TreeSelect、Cascader 和 AutoComplete 计算溢出时使用的区域:PopupOverflow = 'viewport' | 'scroll'。默认为 viewport;省略属性或传入 undefined 会继承父级,显式 viewport 则重置 scroll。scroll 模式使用文档区域,垂直移位仍考虑可见区域。它不会选择最近的滚动容器。
面板溢出区域展示嵌套提供者下的四种控件。切换模式保留 DOM、值和焦点;坐标会在下次打开、resize 或 scroll 时更新,仅修改属性不会立即更新。该设置也影响其他组件中的嵌套 Select;Tooltip、DatePicker、Mentions 和 CascaderPanel 自身的面板不使用它。
GetPopupContainer 从连接的消费者中选择一个容器;组件的本地配置优先。 Getter 可能会收到丢失的 trigger,因此请在您自己的代码中注意这一点。在浏览器回调中使用 DOM,而不是在 SSR 初始化期间使用。单独迁移到 ShadowRoot 并不会提供 CSS。
嵌套列表、表格筛选、提示和对话框都会考虑父面板的层级。Drawer 示例在父面板上设置 zIndex,Select 的下拉列表会显示在子面板之上。getPopupContainer 仍用于选择 DOM 容器。
GetTargetContainer 设置 HTMLElement 或 Affix/Anchor 窗口的可滚动区域。这是一个单独的设置,而不是弹出容器。 滚动区域 和 弹出容器 独立显示。
RenderEmpty 是一个常规函数,它返回给定使用者名称的空状态的文本或片段。 一般空状态 显示了支持组件的应用。
将 MessageHolder 和 NotificationHolder 放在提供主题和语言的配置提供者下。容器示例使用 getContainer 将消息列表挂载到提供者以外,同时保留其文字颜色。通过 ConfigProvider.message 可以设置通用消息样式。
通过 ConfigProvider.notification 可以统一设置关闭图标和卡片各部分的样式。notification 样式示例。
ConfigProvider.app 指定 App 包装器的 class/style。它自己的记录(包括 {})将替换整个父记录;本地 styleApp优先。对于一般的 message/notification/modal API,将 App 放在 ConfigProvider 下,并在其子组件初始化时调用 useApp。这是手动连接各个支架的替代方法。
配置静态对话框
Modal.confirm() 会在独立的根节点中打开对话框。要与页面共用主题和语言,可在应用挂载时调用一次 ConfigProvider.config({ holderRender })。holderRender 片段接收对话框内容,并在你的 ConfigProvider 内调用 {@render content()}。对话框默认挂载到 document.body。即使通过 getContainer 指定其他节点,也会保留配置提供者的主题颜色。静态确认框示例使用了这种配置。
全局配置还接受 prefixCls、iconPrefixCls 和 theme。Modal 方法在调用时记录外层片段,在渲染时读取前缀和主题。如果片段属于某个页面区域,离开该区域时可以传入 holderRender: undefined,以清除后续对话框使用的片段。
示例
尺寸和可用性
一般默认值和局部异常 size/disabled。
<script lang="ts">
import { Button, Checkbox, ConfigProvider, Input, RadioGroup } from '@woodger/antd';
import type { ComponentSize } from '@woodger/antd';
let size = $state<ComponentSize>('medium');
let disabled = $state(false);
let value = $state(("文档"));
</script>
<style>
.settings {
display: grid;
gap: 16px;
margin-bottom: 24px;
}
.controls {
display: grid;
gap: 16px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<div class="settings">
<RadioGroup aria-label={("ConfigProvider 的总大小")} bind:value={size}
options={(['small', 'medium', 'large'])} />
<Checkbox bind:checked={disabled}>{("禁用嵌套控件")}</Checkbox>
</div>
<ConfigProvider componentSize={size} componentDisabled={disabled}>
<div class="controls">
<Input aria-label={("常规设置字段")} bind:value />
<div class="actions">
<Button type="primary">{("一般尺寸纽扣")}</Button>
<Button size="small" disabled={false}>{("局部异常")}</Button>
</div>
</div>
</ConfigProvider>
语言环境
在俄语、英语和简体中文之间切换日历、分页和对话框的语言。
<script lang="ts">
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn.js';
import zhCN from '@woodger/antd/locale/zh_CN';
import { Button, ConfigProvider, DatePicker, Empty, Modal, Pagination, RadioGroup, enUS, ruRU }
from '@woodger/antd';
const locales = { ru: ruRU, en: enUS, zh: zhCN };
let language = $state<keyof typeof locales>('ru');
let open = $state(false);
</script>
<style>
.settings { margin-bottom: 24px; }
.controls {
display: grid;
gap: 16px;
}
</style>
<div class="settings">
<RadioGroup aria-label={("语言配置提供者")} bind:value={language}
options={([
{ value: 'ru', label: "俄语" },
{ value: 'en', label: 'English' },
{ value: 'zh', label: '简体中文' }
])} />
</div>
<ConfigProvider locale={locales[language]}>
<div class="controls">
<DatePicker aria-label={("提供者区域设置的日期")}
defaultPickerValue={dayjs('2026-11-06')} />
<Pagination total={30} aria-label={("使用提供者区域设置进行分页")} />
<Empty image="simple" />
<Button onclick={() => { open = true; }}>{("打开带有区域设置的窗口")}</Button>
</div>
<Modal title={("Locale ConfigProvider")} bind:open>
<p>{("窗口按钮使用当前提供程序区域设置。")}</p>
</Modal>
</ConfigProvider>
方向
子控件的 LTR 和 RTL。
<script lang="ts">
import { ConfigProvider, Input, Pagination, RadioGroup } from '@woodger/antd';
let direction = $state<'ltr' | 'rtl'>('ltr');
</script>
<style>
.settings { margin-bottom: 24px; }
.controls {
display: grid;
gap: 16px;
}
</style>
<div class="settings">
<RadioGroup aria-label={("方向配置提供者")} bind:value={direction}
options={(['ltr', 'rtl'])} />
</div>
<ConfigProvider {direction}>
<div class="controls">
<Input aria-label={("提供商方向字段")} defaultValue="Svelte" />
<Pagination total={50} aria-label={("具有提供商指导的分页")} />
</div>
</ConfigProvider>
主题算法
浅色/深色主题、compact 和反应式 theme.useToken。
Theme.svelte<script lang="ts"> import { Button, Checkbox, ConfigProvider, Input, theme } from '@woodger/antd'; import TokenReadout from './TokenReadout.svelte'; let dark = $state(false); let compact = $state(false); const algorithms = $derived([ dark ? theme.darkAlgorithm : theme.defaultAlgorithm, ...(compact ? [theme.compactAlgorithm] : []) ]); </script> <style> .settings { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 24px; } .surface { display: grid; gap: 16px; padding: 16px; border-radius: 8px; background: var(--ant-color-bg-container); } </style> <div class="settings"> <Checkbox bind:checked={dark}>{("提供商的暗算法")}</Checkbox> <Checkbox bind:checked={compact}>{("紧凑的提供商算法")}</Checkbox> </div> <ConfigProvider theme={{ inherit: false, mode: dark ? 'dark' : 'light', algorithm: algorithms, token: { colorPrimary: '#389e0d', borderRadius: 12 } }}> <div class="surface"> <Input aria-label={("主题提供者字段")} defaultValue="Собственная тема" /> <Button type="primary">{("应用主题")}</Button> </div> <TokenReadout /> </ConfigProvider>TokenReadout.svelte<script lang="ts"> import { theme } from '@woodger/antd'; let { label = "嵌套提供商令牌" }: { label?: string } = $props(); const result = theme.useToken(); </script> <style> output { display: block; margin-top: 16px; overflow-wrap: anywhere; font-size: 12px; } </style> <output aria-label={(label)}> primary: {(result.token.colorPrimary)}; radius: {(result.token.borderRadius)}; height: {(result.token.controlHeight)}; background: {(result.token.colorBgContainer)} </output>
继承与隔离
嵌套 token 覆盖并通过 inherit=false 重置父主题。
Nested.svelte<script lang="ts"> import { Button, ConfigProvider } from '@woodger/antd'; import TokenReadout from './TokenReadout.svelte'; </script> <style> .layers { display: grid; gap: 24px; } </style> <ConfigProvider theme={{ inherit: false, token: { colorPrimary: '#389e0d', borderRadius: 12 } }}> <div class="layers"> <div> <Button type="primary">{("家长主题")}</Button> <TokenReadout label={("父代币")} /> </div> <ConfigProvider theme={{ token: { colorPrimary: '#d48806' } }}> <Button type="primary">{("旧版主题")}</Button> <TokenReadout label={("遗留代币")} /> </ConfigProvider> <ConfigProvider theme={{ inherit: false, token: { colorPrimary: '#722ed1' } }}> <Button type="primary">{("孤立的主题")}</Button> <TokenReadout label={("孤立的代币")} /> </ConfigProvider> </div> </ConfigProvider>TokenReadout.svelte<script lang="ts"> import { theme } from '@woodger/antd'; let { label = "嵌套提供商令牌" }: { label?: string } = $props(); const result = theme.useToken(); </script> <style> output { display: block; margin-top: 16px; overflow-wrap: anywhere; font-size: 12px; } </style> <output aria-label={(label)}> primary: {(result.token.colorPrimary)}; radius: {(result.token.borderRadius)}; height: {(result.token.controlHeight)}; background: {(result.token.colorBgContainer)} </output>
常规和本地设置
继承的拖拽者
空嵌套记录
Sample.txt - 42% 的样本条。新文件在本地处理:单击“结束请求”。在重置范围内,beforeUpload 返回 false 以避免运行标准 XHR。
空上传继承整个记录;空的嵌套记录将替换它。类是累积的,局部 CSS 行在通用 CSS 行之后应用。进度跨字段合并:一个空的本地对象存储总体进度。更改customRequest会影响以下文件,当前请求继续;隐藏上传会取消不完整的上传。
ProviderUpload.svelte<script lang="ts"> import { Button, Checkbox, ConfigProvider, Input, type UploadConfig, type UploadProps, type UploadRequestOptions } from '@woodger/antd'; import ProviderUploadScope from './ProviderUploadScope.svelte'; let localRequest = $state(false); let localStyles = $state(true); let clearAccept = $state(false); let wide = $state(false); let mounted = $state(true); let progressMode = $state('inherit'); let draft = $state(("提供者旁边的注释")); let requests = $state<string[]>([]); let aborted = $state<string[]>([]); let pending = $state.raw<{ source: string; options: UploadRequestOptions; active: boolean; }[]>([]); function transport(source: string): NonNullable<UploadProps['customRequest']> { return options => { const job = { source, options, active: true }; pending = [...pending, job]; requests.push(`${source}: ${options.file.name}`); options.onProgress?.({ percent: 30 }); return { abort: () => { job.active = false; pending = pending.filter(entry => entry !== job); aborted.push(`${source}: ${options.file.name}`); } }; }; } const providerRequest = transport('provider'); const ownRequest = transport('local'); const shared = $derived<UploadConfig>({ accept: '.txt', class: 'provider-upload-record', classNames: { root: 'provider-upload-root', item: 'provider-upload-item' }, styles: { root: ` display: block; min-width: 0; padding: 12px; border: 1px solid var(--ant-color-primary); border-radius: 8px; `, item: 'min-height:36px', trigger: 'padding-top:6px' }, style: 'padding-top:10px', progress: { size: [-1, wide ? 7 : 5], showInfo: true, strokeColor: '#d46b08' }, customRequest: providerRequest }); const localProgress = $derived.by<UploadProps['progress']>(() => { if (progressMode === 'empty') { return {}; } if (progressMode === 'hide') { return { showInfo: false }; } if (progressMode === 'thick') { return { size: [-1, 9] }; } return undefined; }); const local = $derived<UploadConfig>({ accept: clearAccept ? '' : undefined, customRequest: localRequest ? ownRequest : undefined, classNames: localStyles ? { root: 'local-upload-root', item: 'local-upload-item' } : {}, styles: localStyles ? { root: 'padding-top:8px', trigger: 'padding-top:14px' } : {}, progress: localProgress }); function complete() { const jobs = pending; pending = []; for (const job of jobs) { if (!job.active) { continue; } job.active = false; job.options.onSuccess?.({ source: job.source }); } } </script> <style> .example, .scopes { display: grid; gap: 20px; min-width: 0; } .controls { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; } label { display: grid; gap: 6px; min-width: 0; } select { max-width: 100%; padding: 4px 8px; border: 1px solid var(--ant-color-border); border-radius: 6px; background: var(--ant-color-bg-container); color: var(--ant-color-text); font: inherit; } p { margin: 0; } output { overflow-wrap: anywhere; } </style> <div class="example"> <div class="controls"> <Checkbox bind:checked={localRequest} >{("第一次上传的本地customRequest")}</Checkbox> <Checkbox bind:checked={localStyles} >{("第一次上传的本地样式")}</Checkbox> <Checkbox bind:checked={clearAccept}>{("空本地接受")}</Checkbox> <Checkbox bind:checked={wide}>{("提高整体进度")}</Checkbox> <Checkbox bind:checked={mounted}>{("显示带有设置的上传")}</Checkbox> <label>{("第一次上传的本地进度\n ")}<select bind:value={progressMode} > <option value="inherit" >{("继承")}</option> <option value="empty" >{("空物体")}</option> <option value="hide"> {("无签名")} </option> <option value="thick"> {("厚度 9 像素")} </option> </select> </label> </div> <Input aria-label={("注意 ConfigProvider.upload 旁边的内容")} bind:value={draft} /> <ConfigProvider upload={shared}> {#if mounted} <div class="scopes"> <ProviderUploadScope id="local" title={("常规和本地设置")} overrides={local} /> <ConfigProvider> <ProviderUploadScope id="inherited" title={("继承的拖拽者")} dragger /> </ConfigProvider> <ConfigProvider upload={{}}> <ProviderUploadScope id="reset" title={("空嵌套记录")} manual /> </ConfigProvider> </div> {/if} </ConfigProvider> <Button disabled={pending.length === 0} onclick={complete} >{("结束请求")}</Button> <output aria-label={("ConfigProvider.上传请求")}>{(requests.join('; ') || ("没有要求"))}</output> <output aria-label={("待处理的上传请求")} >{("期待: ")}{(pending.length)}</output> <output aria-label={("已取消的上传请求")}>{(aborted.join('; ') || ("不可取消"))}</output> <p> {("Sample.txt - 42% 的样本条。新文件在本地处理:单击“结束请求”。在重置范围内,beforeUpload 返回 false 以避免运行标准 XHR。")} </p> <p> {("空上传继承整个记录;空的嵌套记录将替换它。类是累积的,局部 CSS 行在通用 CSS 行之后应用。进度跨字段合并:一个空的本地对象存储总体进度。更改customRequest会影响以下文件,当前请求继续;隐藏上传会取消不完整的上传。")} </p> </div>ProviderUploadScope.svelte<script lang="ts"> import { untrack } from 'svelte'; import { Button, Upload, UploadDragger, type UploadConfig, type UploadFile } from '@woodger/antd'; let { id, title, overrides = {}, manual = false, dragger = false }: { id: string; title: string; overrides?: UploadConfig; manual?: boolean; dragger?: boolean; } = $props(); let files = $state.raw<UploadFile[]>(untrack(() => [ { uid: `${id}-sample`, name: 'sample.txt', status: 'uploading', percent: 42, 'aria-label': `进度示例: ${title}` } ])); let root = $state<HTMLSpanElement>(); let input = $state<HTMLInputElement>(); </script> <style> section { display: grid; gap: 12px; min-width: 0; padding: 12px; border: 1px solid var(--ant-color-border-secondary); border-radius: 8px; } h4, p { margin: 0; } .widget { min-width: 0; padding-bottom: 24px; } output { overflow-wrap: anywhere; } </style> <section aria-label={(title)}> <h4>{(title)}</h4> <div class="widget"> {#if dragger} <UploadDragger {...overrides} fileList={(files)} bind:nativeElement={root} bind:inputElement={input} beforeUpload={() => manual ? false : undefined} onChange={info => { files = info.fileList; }}> <p>{("单击或拖动文件")}</p> </UploadDragger> {:else} <Upload {...overrides} fileList={(files)} bind:nativeElement={root} bind:inputElement={input} beforeUpload={() => manual ? false : undefined} onChange={info => { files = info.fileList; }}> <Button>{("选择文件")}</Button> </Upload> {/if} </div> <output aria-label={("文件: " + String((title)) + "")}> {files.map(file => `${file.name}: ${file.status ?? "不发送"}`).join('; ')} </output> <output aria-label={("DOM: " + String((title)) + "")}>{(root && input ? "已连接" : "等待挂载")}</output> </section>
<script lang="ts">
import { Button, ConfigProvider, Input } from '@woodger/antd';
let value = $state(("可以清洗"));
</script>
<style>
.controls {
display: grid;
gap: 16px;
}
</style>
<ConfigProvider button={{ class: 'provider-button', style: 'font-weight: 700' }}
input={{ variant: 'filled', allowClear: true }}>
<div class="controls">
<Button>{("常规按钮设置")}</Button>
<Button style="font-weight: 400">{("本地按钮样式")}</Button>
<Input aria-label={("输入常见变体")} bind:value />
<ConfigProvider button={{ class: 'nested-provider-button' }}>
<div class="controls">
<Button>{("嵌套设置")}</Button>
<Input
aria-label={("输入继承相邻设置")}
defaultValue="filled сохранён"
/>
</div>
</ConfigProvider>
</div>
</ConfigProvider>
<script lang="ts">
import {
Checkbox,
ConfigProvider,
Form,
Input,
RadioGroup,
Select,
createForm
} from '@woodger/antd';
import type { Variant } from '@woodger/antd';
let variant = $state<Variant>('filled');
let local = $state(false);
const form = createForm({ initialValues: {} });
const options = [{ value: 'anna', label: "安娜" }, { value: 'boris', label: "鲍里斯" }];
</script>
<style>
.settings, .examples {
display: grid;
gap: 20px;
}
.settings { margin-bottom: 24px; }
label {
display: grid;
gap: 8px;
}
</style>
<div class="settings">
<RadioGroup aria-label={("通用变体 ConfigProvider")} bind:value={variant}
options={(['outlined', 'filled', 'borderless', 'underlined'])}
style="
display: flex;
flex-wrap: wrap;
gap: 8px;
" />
<Checkbox bind:checked={local}>{("表格内局部概述")}</Checkbox>
</div>
<ConfigProvider {variant} select={{ variant: 'underlined' }}>
<div class="examples">
<label>{("一般变型\n ")}<Input aria-label={("通用变量输入")} defaultValue="Наследует провайдер" />
</label>
<label>{("组件设置\n ")}<Select
options={(options)}
defaultValue="anna"
aria-label={("组件变体 选择")}
/>
</label>
<Form {form} variant="borderless" aria-label={("优先权表格变体")}>
<div class="examples">
<Input aria-label={("形式的变体")} defaultValue="Form имеет приоритет" />
<Select options={(options)} defaultValue="anna" variant={local
? 'outlined'
: undefined}
aria-label={("本地变体 选择")} />
</div>
</Form>
<ConfigProvider variant="filled">
<Select options={(options)} defaultValue="anna" aria-label={("旧配置选择")} />
</ConfigProvider>
</div>
</ConfigProvider>
<script lang="ts">
import { Button, ConfigProvider, Input } from '@woodger/antd';
</script>
<style>
.controls {
display: grid;
gap: 16px;
}
</style>
<ConfigProvider theme={{
components: {
Button: {
defaultBg: '#fff7e6',
defaultColor: '#874d00',
defaultBorderColor: '#d48806'
}
}
}}>
<div class="controls">
<Button>{("按钮标记")}</Button>
<Input
aria-label={("不带按钮令牌的输入")}
defaultValue="Сохраняет свою тему"
/>
</div>
</ConfigProvider>
静态计算
theme.getDesignToken 计算调色板,不会更改页面上下文。
<script lang="ts">
import { Button, Checkbox, theme } from '@woodger/antd';
let dark = $state(false);
const token = $derived(theme.getDesignToken({
token: { colorPrimary: '#d48806' },
algorithm: dark ? theme.darkAlgorithm : theme.defaultAlgorithm
}));
</script>
<style>
.controls {
display: grid;
gap: 16px;
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
font-size: 12px;
}
</style>
<div class="controls">
<Checkbox bind:checked={dark}>{("计算深色调色板")}</Checkbox>
<Button type="primary">{("页面主题")}</Button>
</div>
<output aria-label={("代币静态计算")}>
primary: {(token.colorPrimary)}; background: {(token.colorBgContainer)}
</output>
参加者 |
|---|
提供者一般为空状态 |
参加者 |
|---|
| 表本地空状态 |
<script lang="ts">
import { ConfigProvider, Empty, Table } from '@woodger/antd';
const columns = [{ key: 'name', title: "参加者", dataIndex: 'name' as const }];
const rows: { name: string }[] = [];
</script>
<style>
.tables {
display: grid;
gap: 16px;
}
</style>
{#snippet empty()}
<Empty image="simple" description={("提供者一般为空状态")} />
{/snippet}
{#snippet localEmpty()}{("表本地空状态")}{/snippet}
<ConfigProvider renderEmpty={() => empty}>
<div class="tables">
<Table columns={(columns)} dataSource={(rows)} pagination={(false)} caption={("表的一般空状态")} />
<Table columns={(columns)} dataSource={(rows)} pagination={(false)} caption={("表本地空状态")}
empty={localEmpty} />
</div>
</ConfigProvider>
<script lang="ts">
import { Button, ConfigProvider, Tooltip } from '@woodger/antd';
let host = $state<HTMLDivElement>();
function popupContainer() {
return host ?? document.body;
}
</script>
<style>
.host {
position: relative;
min-height: 160px;
padding: 16px;
border: 1px dashed var(--ant-color-border);
border-radius: 8px;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 16px;
}
</style>
<div class="host" bind:this={host} data-provider-popup-host>
<ConfigProvider getPopupContainer={popupContainer}>
<div class="controls">
<Tooltip trigger="click" title={("给定容器内的弹出窗口")}>
<Button>{("容器中的弹出窗口")}</Button>
</Tooltip>
<Tooltip trigger="click" title={("体内的本地弹出窗口")}
getPopupContainer={() => document.body}>
<Button>{("你的弹出窗口")}</Button>
</Tooltip>
</div>
</ConfigProvider>
</div>
Select
TreeSelect
Cascader
AutoComplete
面板溢出区域
Viewport 使用可见区域,scroll 使用文档区域。在窗口底部附近重新打开控件,比较两种模式。嵌套 viewport 重置继承的 scroll。
<script lang="ts">
import {
AutoComplete,
Cascader,
Checkbox,
ConfigProvider,
RadioGroup,
Select,
TreeSelect,
type PopupOverflow
} from '@woodger/antd';
const options = ['Button', 'Input', 'Select', 'TreeSelect'].map(value => ({
value,
label: value
}));
const treeData = options.map(option => ({ value: option.value, title: option.label }));
let overflow = $state<PopupOverflow>('viewport');
let reset = $state(false);
</script>
<style>
.settings {
display: grid;
gap: 12px;
margin-bottom: 16px;
}
.scroll-area {
height: 240px;
overflow: auto;
border: 1px dashed var(--ant-color-border);
border-radius: var(--ant-border-radius);
}
.fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 128px), 1fr));
gap: 16px;
padding: 16px;
}
.field { min-width: 0; }
p { margin: 0 0 8px; }
.scroll-area:focus-visible {
outline: 2px solid var(--ant-color-primary);
outline-offset: 2px;
}
</style>
<div class="settings">
<RadioGroup
aria-label={("面板溢出区域")}
options={['viewport', 'scroll']}
bind:value={overflow}
/>
<Checkbox bind:checked={reset}>
{("嵌套提供者:viewport")}
</Checkbox>
</div>
<ConfigProvider popupOverflow={overflow}>
<ConfigProvider popupOverflow={reset ? 'viewport' : undefined}>
<div
class="scroll-area"
role="region"
aria-label={("popupOverflow 示例区域")}
tabindex="0"
>
<div class="fields">
<div class="field">
<p>Select</p>
<Select
aria-label={("使用 popupOverflow 的 Select")}
{options}
style="
width: 100%;
min-width: 0;
"
placeholder={("选择组件")}
/>
</div>
<div class="field">
<p>TreeSelect</p>
<TreeSelect
aria-label={("使用 popupOverflow 的 TreeSelect")}
{treeData}
style="
width: 100%;
min-width: 0;
"
placeholder={("选择组件")}
/>
</div>
<div class="field">
<p>Cascader</p>
<Cascader
aria-label={("使用 popupOverflow 的 Cascader")}
{options}
style="
width: 100%;
min-width: 0;
"
placeholder={("选择组件")}
/>
</div>
<div class="field">
<p>AutoComplete</p>
<AutoComplete
aria-label={("使用 popupOverflow 的 AutoComplete")}
{options}
style="
width: 100%;
min-width: 0;
"
placeholder={("输入组件名称")}
/>
</div>
</div>
</div>
</ConfigProvider>
</ConfigProvider>
Select
AutoComplete
TreeSelect
Select (240 px)
共用面板宽度
Select、AutoComplete 和 TreeSelect 继承 popupMatchSelectWidth。嵌套 true 恢复字段宽度,Select 的局部 240 优先。
<script lang="ts">
import {
AutoComplete,
Checkbox,
ConfigProvider,
RadioGroup,
Select,
TreeSelect
} from '@woodger/antd';
const widths = [true, false, 320].map(value => ({ value, label: String(value) }));
const options = [
{ value: 'button', label: 'Button' },
{ value: 'settings', label: "组件设置与本地化" }
];
const treeData = options.map(option => ({ value: option.value, title: option.label }));
let width = $state<boolean | number>(true);
let reset = $state(false);
</script>
<style>
.settings {
display: grid;
gap: 12px;
margin-bottom: 16px;
}
.fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 128px), 1fr));
gap: 16px;
}
.field { min-width: 0; }
p { margin: 0 0 8px; }
</style>
<div class="settings">
<RadioGroup
aria-label={("共用面板宽度")}
options={widths}
bind:value={width}
/>
<Checkbox bind:checked={reset}>
{("嵌套提供者:true")}
</Checkbox>
</div>
<ConfigProvider popupMatchSelectWidth={width}>
<ConfigProvider popupMatchSelectWidth={reset ? true : undefined}>
<div class="fields">
<div class="field">
<p>Select</p>
<Select
aria-label={("使用共用面板宽度的 Select")}
options={(options)}
style="
width: 100%;
min-width: 0;
"
placeholder={("选择组件")}
/>
</div>
<div class="field">
<p>AutoComplete</p>
<AutoComplete
aria-label={("使用共用面板宽度的 AutoComplete")}
options={(options)}
style="
width: 100%;
min-width: 0;
"
placeholder={("输入组件名称")}
/>
</div>
<div class="field">
<p>TreeSelect</p>
<TreeSelect
aria-label={("使用共用面板宽度的 TreeSelect")}
treeData={(treeData)}
style="
width: 100%;
min-width: 0;
"
placeholder={("选择组件")}
/>
</div>
<div class="field">
<p>Select (240 px)</p>
<Select
aria-label={("使用局部面板宽度的 Select")}
options={(options)}
popupMatchSelectWidth={240}
style="
width: 100%;
min-width: 0;
"
placeholder={("选择组件")}
/>
</div>
</div>
</ConfigProvider>
</ConfigProvider>
<script lang="ts">
import { Affix, Button, ConfigProvider } from '@woodger/antd';
let area = $state<HTMLDivElement>();
let affixed = $state(false);
const offset = 16;
</script>
<style>
.frame {
transform: translate(0);
isolation: isolate;
overflow: hidden;
border-radius: 8px;
background: var(--ant-color-fill-quaternary);
}
.scroll {
height: 180px;
overflow: auto;
}
.frame :global(.provider-affix-fixed) { top: 16px !important; }
output {
display: block;
margin-top: 16px;
}
</style>
<div class="frame">
<div class="scroll" bind:this={area} role="region" aria-label={("通用提供商滚动区域")}
tabindex="0">
<ConfigProvider getTargetContainer={() => area ?? window}>
<div style="height: 56px"></div>
<Affix offsetTop={offset} rootClassName="provider-affix-fixed"
onChange={next => { affixed = Boolean(next); }}>
<Button>{("一般目标词缀")}</Button>
</Affix>
<div style="height: 360px"></div>
</ConfigProvider>
</div>
</div>
<output aria-label={("通用绑定ConfigProvider")}>{(affixed ? "已固定" : "在流动中")}</output>
设置波
禁用、标准效果和自定义 showEffect 以及动画清理。
<script lang="ts">
import { onDestroy } from 'svelte';
import { Button, ConfigProvider, type ShowWaveEffect } from '@woodger/antd';
let effect = $state(("单击按钮即可比较效果。"));
const animations = new Set<Animation>();
const holders = new Set<HTMLElement>();
function playAnimation(node: HTMLElement, frames: Keyframe[], cleanup = () => {}) {
const animation = node.animate(frames, { duration: 500, easing: 'ease-out' });
animations.add(animation);
const finish = () => {
animations.delete(animation);
cleanup();
};
void animation.finished.then(finish, finish);
}
const showInsetEffect: ShowWaveEffect = (node, { component, event }) => {
if (component !== 'Button') {
return;
}
effect = ("内波");
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
return;
}
const rect = node.getBoundingClientRect();
const x = event.detail === 0 ? rect.width / 2 : event.clientX - rect.left;
const y = event.detail === 0 ? rect.height / 2 : event.clientY - rect.top;
const diameter = Math.hypot(rect.width, rect.height) * 2;
const holder = document.createElement('span');
holder.setAttribute('aria-hidden', 'true');
holder.style.cssText = `
position: absolute;
inset: 0;
overflow: hidden;
border-radius: inherit;
pointer-events: none;
z-index: 1;
`;
const dot = document.createElement('span');
dot.style.cssText = `
position: absolute;
left: ${x}px;
top: ${y}px;
width: ${diameter}px;
height: ${diameter}px;
border-radius: 50%;
background: rgba(255,255,255,0.65);
pointer-events: none;
`;
holder.append(dot);
node.append(holder);
holders.add(holder);
playAnimation(dot, [
{
transform: 'translate(-50%, -50%) scale(0)',
opacity: 1
},
{
transform: 'translate(-50%, -50%) scale(1)',
opacity: 0
}
], () => {
holder.remove();
holders.delete(holder);
});
};
const showShakeEffect: ShowWaveEffect = (node, { component }) => {
if (component !== 'Button') {
return;
}
effect = ("摇晃");
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
return;
}
for (const animation of node.getAnimations()) {
if (animations.has(animation)) animation.cancel();
}
playAnimation(node, [0, -12, 12, -5, 5, 0].map(angle => ({
transform: `rotate(${angle}deg)`
})));
};
onDestroy(() => {
for (const animation of animations) animation.cancel();
for (const holder of holders) holder.remove();
animations.clear();
holders.clear();
});
</script>
<style>
.row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 16px;
}
output {
display: block;
margin-top: 16px;
color: var(--ant-color-text-secondary);
font-size: 12px;
}
</style>
<div class="row">
<ConfigProvider wave={{ disabled: true }}>
<Button type="primary" onclick={() => { effect = ("波浪已禁用"); }}>
{("无波无浪")}
</Button>
</ConfigProvider>
<ConfigProvider>
<Button
type="primary"
onclick={() => { effect = ("标准波"); }}
>{("标准")}</Button>
</ConfigProvider>
<ConfigProvider wave={{ showEffect: showInsetEffect }}>
<Button type="primary">{("内波")}</Button>
</ConfigProvider>
<ConfigProvider wave={{ showEffect: showShakeEffect }}>
<Button type="primary">{("摇晃")}</Button>
</ConfigProvider>
</div>
<output aria-label={("波浪效应")}>{effect}</output>
消息上下文
MessageHolder 位于提供者内部;不使用 React 静态函数。
<script lang="ts">
import { onDestroy } from 'svelte';
import { Button, ConfigProvider, MessageHolder, createMessage } from '@woodger/antd';
const message = createMessage();
let container = $state<HTMLDivElement>();
onDestroy(() => message.destroy());
</script>
<div bind:this={container}>
<ConfigProvider theme={{ token: { colorText: '#874d00' } }}>
<MessageHolder {message} top={240} id="provider-context-messages"
getContainer={() => container} />
<Button onclick={() => message.info(("来自 ConfigProvider 上下文的消息"))}>
{("带有上下文的消息")}
</Button>
</ConfigProvider>
</div>
输入尚未继承公共 prefixCls 并保留其类。上面的描述中列出了受支持的家庭。
<script lang="ts">
import {
App, Checkbox, ConfigProvider, Input, Layout, LayoutContent,
LayoutFooter, LayoutHeader, LayoutSider
} from '@woodger/antd';
let custom = $state(true);
let localSider = $state(true);
let collapsed = $state(false);
let draft = $state('');
const prefix = $derived(custom ? 'suite' : 'ant');
</script>
<style>
.example, .scopes {
display: grid;
gap: 16px;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.preview {
min-width: 0;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
isolation: isolate;
transform: translate(0);
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("前缀套件")}</Checkbox>
<Checkbox bind:checked={localSider}>{("您的面板前缀Cls")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{
token: { motion: false }, components: {
Layout: {
headerHeight: 44, headerPadding: '0 12px',
headerBg: 'var(--ant-color-fill-secondary)', footerPadding: '12px'
}
}
}}>
<div class="scopes">
<div class="preview" role="region" aria-label={("公共前缀区")}>
<App aria-label={("应用通用前缀")}>
<Layout aria-label={("通用前缀布局")} style="min-height: 220px">
<LayoutSider
prefixCls={localSider ? 'local-panel' : ''}
width={96}
collapsedWidth={48}
theme="light"
collapsible
bind:collapsed
collapseLabel={("折叠公共前缀面板")}
expandLabel={("展开公共前缀面板")}
styles={{ body: `
padding: 12px;
overflow-wrap: anywhere;
` }}
>{("菜单")}</LayoutSider>
<Layout style="min-width: 0">
<LayoutHeader
style="
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
"
>{("地区 ")}{prefix}</LayoutHeader>
<LayoutContent style="
padding: 12px;
min-width: 0;
">
<Input
bind:value={draft}
aria-label={("通用前缀草案")}
placeholder={("草稿")}
/>
</LayoutContent>
<LayoutFooter>{("节继承一个公共前缀。")}</LayoutFooter>
</Layout>
</Layout>
</App>
</div>
<div class="preview">
<ConfigProvider prefixCls="">
<Layout aria-label={("传统布局")} style="padding: 12px">{("\n 空的 prefixCls 继承 ")}{prefix}.
</Layout>
</ConfigProvider>
</div>
</div>
</ConfigProvider>
<ConfigProvider prefixCls="ant">
<div class="preview">
<App aria-label={("附近的标准应用程序")}>
<Layout aria-label={("附近标准布局")}>
<LayoutContent
style="padding: 12px"
>{("邻近地区救了蚂蚁。")}</LayoutContent>
</Layout>
</App>
</div>
</ConfigProvider>
<output aria-label={("通用前缀状态")}>
{prefix}; {(collapsed ? "倒塌" : "揭晓")};
Sider: {(localSider ? 'local-panel' : prefix + '-layout-sider')}
</output>
<p>
{("输入尚未继承公共 prefixCls 并保留其类。上面的描述中列出了受支持的家庭。")}
</p>
</div>
- 完全的
- 进行中
- 预期的
- 已收到申请已接受
- 已验证文件已准备好
本地 prefixCls 时间轴更改其类。内部步骤单独继承 suite-steps.
<script lang="ts">
import {
Checkbox,
ConfigProvider,
QRCode,
Statistic,
StatisticTimer,
Steps,
Timeline
} from '@woodger/antd';
let custom = $state(true);
let localTimeline = $state(false);
let current = $state(1);
const prefix = $derived(custom ? 'suite' : 'ant');
const items = [{ title: "数据" }, { title: "考试" }, { title: "准备好" }];
</script>
<style>
.example, .scope {
display: grid;
gap: 20px;
min-width: 0;
}
.controls, .metrics {
display: flex;
flex-wrap: wrap;
gap: 16px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("套件指标通用前缀")}</Checkbox>
<Checkbox bind:checked={localTimeline}>{("自定义时间线前缀")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ token: { motion: false } }}>
<div class="scope">
<div class="metrics">
<Statistic title={("应用领域")} value={1280} aria-label={("通用前缀指示符")} />
<StatisticTimer type="countdown" title={("直到2100年")} value={4102444800000}
format={("D [日] HH:mm:ss")} aria-label={("通用前缀定时器")} />
</div>
<QRCode type="svg" value="https://woodger.org/ant-design" size={128}
aria-label={("通用前缀二维码")} />
<Steps items={(items)} {current} onChange={value => { current = value; }}
aria-label={("公共前缀阶段")} />
<Timeline prefixCls={localTimeline ? 'local-history' : ''} items={([
{ title: "已收到", content: "申请已接受" },
{ title: "已验证", content: "文件已准备好" }
])} aria-label={("通用前缀的历史")} />
</div>
</ConfigProvider>
<ConfigProvider prefixCls="ant">
<Statistic title={("独立指标")} value={1280} aria-label={("附近的标准指示器")} />
</ConfigProvider>
<output aria-label={("指标前缀状态")}>{prefix}{(";当前阶段: ")}{current}</output>
<p>{("本地 prefixCls 时间轴更改其类。内部步骤单独继承 ")}{prefix}-steps.</p>
</div>
嵌套 Provider 和 Divider 的空 prefixCl 被继承 suite。更改类别会保留分段选择。
<script lang="ts">
import { Checkbox, ConfigProvider, Divider, Flex, Segmented } from '@woodger/antd';
let custom = $state(true);
let localSegmented = $state(false);
let value = $state('week');
let changes = $state(0);
const prefix = $derived(custom ? 'suite' : 'ant');
const options = [{ label: "天", value: 'day' }, { label: "周", value: 'week' }];
</script>
<style>
.example {
display: grid;
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("通用套件布局前缀")}</Checkbox>
<Checkbox
bind:checked={localSegmented}
>{("局部前缀Cls分段")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix}>
<Divider prefixCls="" titlePlacement="start" aria-label={("常用前缀分隔符")}>
{("时期")}
</Divider>
<ConfigProvider prefixCls="">
<Flex orientation="vertical" gap="small" align="start" aria-label={("通用前缀布局")}>
<Segmented
options={(options)}
bind:value
prefixCls={localSegmented ? 'local-period' : ''}
name="prefix-period"
aria-label={("公共前缀周期")}
onChange={() => { changes += 1; }}
/>
<output aria-label={("选择带有前缀的句点")}>{value}{(";事件: ")}{changes}</output>
</Flex>
</ConfigProvider>
</ConfigProvider>
<ConfigProvider prefixCls="ant">
<Flex
gap="small"
wrap
aria-label={("标准并排布局")}
><span>{("天")}</span><span>{("周")}</span></Flex>
</ConfigProvider>
<p>{("嵌套 Provider 和 Divider 的空 prefixCl 被继承 ")}{prefix}{("。更改类别会保留分段选择。")}</p>
</div>
验证完成
Local Badge更改其命名空间,ScrollNumber单独继承 suite-滚动编号。功能区几何 CSS 遵循一个共同的前缀。
<script lang="ts">
import {
Avatar, AvatarGroup, Badge, BadgeRibbon, Button, CheckableTag, CheckableTagGroup,
Checkbox, ConfigProvider, Empty, Progress, Result, Skeleton, SkeletonAvatar,
SkeletonButton, SkeletonImage, SkeletonInput, SkeletonNode, Spin, Tag
} from '@woodger/antd';
let custom = $state(true);
let localBadge = $state(false);
let count = $state(5);
let checked = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
</script>
<style>
.example, .scope {
display: grid;
gap: 20px;
min-width: 0;
}
.row, .controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
}
.badge-anchor {
display: inline-block;
padding: 12px;
border-radius: 6px;
background: var(--ant-color-fill-secondary);
}
.ribbon-content {
min-height: 72px;
padding: 36px 12px 12px;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 6px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("套件状态的通用前缀")}</Checkbox>
<Checkbox bind:checked={localBadge}>{("本地 prefixCls 徽章")}</Checkbox>
<Button
onclick={() => { count += 1; }}
>{("带前缀的增量计数器")}</Button>
</div>
<ConfigProvider prefixCls={prefix}>
<div class="scope">
<div class="row">
<Avatar aria-label={("常用前缀头像")}>W</Avatar>
<AvatarGroup aria-label={("通用前缀组")} items={([
{ key: 'anna', label: "安娜", text: "一个" },
{ key: 'ivan', label: "伊万", text: "和" }
])} />
<Badge prefixCls={localBadge ? 'local-counter' : ''} {count}
aria-label={("公共前缀计数器")}>
<span class="badge-anchor">
{("应用领域")}
</span>
</Badge>
</div>
<BadgeRibbon text={("准备好")}>
<div class="ribbon-content">{("磁带继承 ")}{prefix}-ribbon.</div>
</BadgeRibbon>
<div class="row">
<Tag>{("新的")}</Tag>
<CheckableTag
{checked}
onChange={next => { checked = next; }}
>{("已验证")}</CheckableTag>
</div>
<CheckableTagGroup role="group" aria-label={("常见前缀类别")}
options={(["代码", "布局"])} defaultValue="Код" />
<Empty image="simple" description={("还没有申请")} />
<Skeleton loading avatar paragraph={false} />
<div class="row">
<SkeletonAvatar /><SkeletonButton /><SkeletonInput style="width: 120px" />
<SkeletonImage /><SkeletonNode>{("日程")}</SkeletonNode>
</div>
<Spin />
<Progress percent={60} />
<Result status="success" title={("验证完成")} styles={{
root: 'padding: 12px'
}} />
</div>
</ConfigProvider>
<ConfigProvider
prefixCls="ant"
><Avatar
aria-label={("附近的标准头像")}
>W</Avatar></ConfigProvider>
<output aria-label={("状态前缀状态")}>
{prefix}{(";柜台: ")}{count}; {(checked ? "已验证" : "未验证")}
</output>
<p>{("Local Badge更改其命名空间,ScrollNumber单独继承 ")}{prefix}{("-滚动编号。功能区几何 CSS 遵循一个共同的前缀。")}</p>
</div>
<script lang="ts">
import { Affix, Alert, Button, Checkbox, Collapse, ConfigProvider, Input } from '@woodger/antd';
let custom = $state(true);
let localCollapse = $state(false);
let area = $state<HTMLDivElement>();
let affixed = $state(false);
let draft = $state('');
const prefix = $derived(custom ? 'suite' : 'ant');
</script>
<style>
.example, .scope {
display: grid;
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.frame {
transform: translate(0);
isolation: isolate;
overflow: hidden;
border-radius: 8px;
background: var(--ant-color-fill-quaternary);
}
.scroll {
height: 144px;
overflow: auto;
}
.frame :global(.prefix-structure-fixed) { top: 8px !important; }
output { overflow-wrap: anywhere; }
</style>
{#snippet editor()}
<Input
bind:value={draft}
aria-label={("带前缀的草稿面板")}
placeholder={("草稿")}
/>
{/snippet}
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("套件面板的通用前缀")}</Checkbox>
<Checkbox
bind:checked={localCollapse}
>{("本地 prefixCls")}</Checkbox>
<Button onclick={() => { if (area) area.scrollTop = area.scrollTop ? 0 : 96; }}>
{("\n 带前缀的滚动词缀\n ")}
</Button>
</div>
<ConfigProvider prefixCls={prefix} iconPrefixCls={custom ? 'suite-icon' : undefined}>
<div class="scope">
<Alert title={("面板继承一个公共前缀")} showIcon />
<Collapse
prefixCls={localCollapse ? 'local-panels' : ''}
aria-label={("通用前缀面板")}
defaultActiveKey={['draft']}
items={([
{ key: 'draft', label: "编辑", children: editor },
{
key: 'note',
label: "笔记",
children: "更改类别可以使面板保持打开状态。"
}
])}
/>
<div class="frame">
<div class="scroll" bind:this={area} role="region" aria-label={("为容器添加前缀")} tabindex="0">
<div style="height: 40px"></div>
<Affix target={() => area ?? null} offsetTop={8} rootClassName="prefix-structure-fixed"
onChange={next => { affixed = Boolean(next); }}>
<Button>{("固定动作")}</Button>
</Affix>
<div style="height: 320px"></div>
</div>
</div>
</div>
</ConfigProvider>
<output aria-label={("面板前缀状态")}>
{prefix}; {(affixed ? "安全的" : "在流中")}{(";草稿: ")}{(draft
|| ("空的"))}
</output>
</div>
工具提示滑块继承了与比例分开的公共前缀。本地 Popconfirm 更改确认类;它的外部 Popover 继承 suite-popover.
<script lang="ts">
import {
Button,
Checkbox,
ConfigProvider,
Input,
Popconfirm,
Popover,
Slider,
Tooltip
} from '@woodger/antd';
let custom = $state(true);
let local = $state(false);
let tips = $state(false);
let draft = $state('');
let value = $state(30);
let range = $state<number[]>([25, 75]);
let confirmations = $state(0);
const prefix = $derived(custom ? 'suite' : 'ant');
</script>
<style>
.example, .scope {
display: grid;
gap: 24px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
{#snippet content()}
<Input
bind:value={draft}
aria-label={("带前缀的草稿弹出窗口")}
placeholder={("草稿")}
/>
{/snippet}
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("通用弹出套件前缀")}</Checkbox>
<Checkbox bind:checked={local}>{("弹出窗口和滑块本地前缀")}</Checkbox>
<Checkbox
bind:checked={tips}
>{("显示带前缀的滑块工具提示")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix}>
<div class="scope">
<div class="controls">
<Tooltip prefixCls={local ? 'local-tip' : ''} title={("常用前缀提示")}
trigger="click" classNames={{ root: 'prefix-tooltip-popup' }}>
<Button>{("带有公共前缀的工具提示")}</Button>
</Tooltip>
<Popover prefixCls={local ? 'local-card' : ''} title={("通用前缀卡")}
content={(content)} trigger="click" classNames={{
root: 'prefix-popover-popup'
}}>
<Button>{("具有公共前缀的弹出窗口")}</Button>
</Popover>
<Popconfirm prefixCls={local ? 'local-confirm' : ''} title={("确认前缀更改?")}
okText={("确认")} cancelText={("取消")}
classNames={{ root: 'prefix-popconfirm-popup' }}
onConfirm={() => { confirmations += 1; }}>
<Button>{("Popconfirm 带有公共前缀")}</Button>
</Popconfirm>
</div>
<Slider prefixCls={local ? 'local-slider' : ''} bind:value
aria-label={("公共前缀滑块数量")} tooltip={({
open: tips
})} />
<Slider prefixCls={local ? 'local-range' : ''} range bind:value={range}
ariaLabelForHandle={["公共前缀范围的开始", "公共前缀范围结束"]}
tooltip={({ open: tips })} />
</div>
</ConfigProvider>
<output aria-label={("弹出前缀状态")}>
{prefix}{(";数字: ")}{value}{(";范围: [")}{range.join(', ')}{("];确认信息: ")}{confirmations}
</output>
<p>{("工具提示滑块继承了与比例分开的公共前缀。本地 Popconfirm 更改确认类;它的外部 Popover 继承 ")}{prefix}-popover.</p>
</div>
家长:
重置主题:
显式前缀:
没有本地主题:
即使inherit=false,继承的cssVar.prefix也会被保留。显式未定义返回当前提供程序的后备 - 内部。
前缀和 CSS 变量
继承命名空间,inherit=false,显式 prefix 且 undefined。两个文件:PrefixVariables.svelte 和 PrefixVariableReadout.svelte。
PrefixVariables.svelte<script lang="ts"> import { Checkbox, ConfigProvider } from '@woodger/antd'; import PrefixVariableReadout from './PrefixVariableReadout.svelte'; let clear = $state(false); </script> <style> .example, .scopes { display: grid; gap: 12px; } p { margin: 0; } </style> <div class="example"> <Checkbox bind:checked={clear} >{("清除继承的变量前缀")}</Checkbox> <ConfigProvider prefixCls="suite" theme={{ cssVar: { prefix: 'base-vars' }, token: { fontSize: 16 } }}> <div class="scopes"> <PrefixVariableReadout name="Родитель" /> <ConfigProvider prefixCls="inner" theme={{ inherit: false, cssVar: clear ? { prefix: undefined } : {} }}> <PrefixVariableReadout name="Сброс темы" /> </ConfigProvider> <ConfigProvider prefixCls="inner" theme={{ cssVar: { prefix: 'local-vars' } }}> <PrefixVariableReadout name="Явный prefix" /> </ConfigProvider> <ConfigProvider prefixCls="without-theme"> <PrefixVariableReadout name="Без локальной темы" /> </ConfigProvider> </div> </ConfigProvider> <p> {("即使inherit=false,继承的cssVar.prefix也会被保留。显式未定义返回当前提供程序的后备 - 内部。")} </p> </div>PrefixVariableReadout.svelte<script lang="ts"> import { theme } from '@woodger/antd'; let { name }: { name: string } = $props(); const current = theme.useToken(); </script> <style> p { margin: 0; padding: 8px 12px; border-radius: 6px; background: var(--ant-color-bg-container); overflow-wrap: anywhere; } code { font-size: 12px; } </style> <p>{(name)}: <code><output aria-label={("CSS variables: " + String((name)) + "")} >{(String(current.cssVar.fontSize))}</output></code></p>
API
子组件会读取最近一层 ConfigProvider 的配置。
| 主题 | 示例或限制 |
|---|---|
| Locale | 现成的组件语言字典。 |
| Direction | 子组件的方向。 |
| popupOverflow | Select、TreeSelect、Cascader 和 AutoComplete 的溢出计算区域;继承与显式 viewport。 |
| popupMatchSelectWidth | Select、AutoComplete 和 TreeSelect 的共用宽度;嵌套提供者与局部优先级。 |
| Component size | 大小和 disabled,但局部例外。 |
| Variant | 常规设计选项、组件设置和表单优先级。 |
| Theme | 算法、一般和组件标记、嵌套主题。 |
| Custom Wave | WaveConfig.disabled/showEffect 和动画生命周期。 |
| Static function | ConfigProvider.config 设置 Modal 静态对话框的外观。 |
| Content Security Policy | 将文档策略中的 nonce 传给组件样式。 |
| ConfigProvider.useConfig() | 在子组件初始化时调用 ConfigProvider.useConfig(),从返回对象中读取响应式的 componentSize 和 componentDisabled。 |
| Component Config | 已发布的组件设置。 |
| Component prefixCls | 通用应用程序/布局前缀、本地优先级和独立范围。 |
| Display component prefixCls | 统计/定时器、QRCode、步骤和时间线的继承;内部步骤的独立前缀。 |
| Layout and selection prefixCls | 继承 Divider、Flex 和 Segmented,无需重置选择。 |
| Status component prefixCls | 头像/组、徽章/丝带、标签、空、骨架、旋转、进度和结果;独立的 ScrollNumber。 |
| Panel and Affix prefixCls | Alert、折叠和Affix;保存编辑器和打开的面板。 |
| Popup and Slider prefixCls | Tooltip、Popover、Popconfirm 和 single/range滑块;内部弹出窗口的独立前缀。 |
| CSS variable prefix | 继承当前提供者的 cssVar.prefix 和后备。 |
常规 ConfigProvider 选项
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
iconPrefixCls | 内置图标的 CSS 类名前缀。空值继承最近的提供器的前缀。 | string | anticon |
children | 上下文可用的子树。 | Snippet | 必需的 |
prefixCls | 公共类前缀部分中列出的连接系列的基本 CSS 前缀。其余家庭分别相连。undefined/空字符串继承父级;组件的非空本地 prefixCls 优先。 | string | 父母/蚂蚁 |
componentSize | 支持它的控件的总大小。本地 size 和紧凑优先。 | small | medium | large | 家长/媒体 |
componentDisabled | 一般禁用控制装置;本地 disabled 指定了含义。 | boolean | 父/假 |
variant | 带 outlined、filled、borderless 或 underlined。本地 variant、最近的 Form.variant 和组件配置优先。 | Variant | 家长/概述 |
direction | 布局和子组件的方向。 | ltr | rtl | 父/ltr |
locale | 来自 @woodger/antd/locale 的语言字典或组件的部分语言设置。 | Partial<Locale> | AntDesignLocale | 家长 / 茹茹 |
theme | 令牌、算法和组件主题。 | ThemeConfig | 父主题 |
csp | 设置组件库生成的样式的 nonce。嵌套的提供器会继承此设置。 | CSPConfig | — |
getPopupContainer | 容器支持弹出窗口。浏览器中调用回调;triggerNode 可能丢失。 | (triggerNode?) => HTMLElement | ShadowRoot | 父/身体 |
getTargetContainer | 常规Affix/锚点滚动区域。本地 target/getContainer 优先。 | () => HTMLElement | Window | 父/窗口 |
popupOverflow | Select、TreeSelect、Cascader 和 AutoComplete 的溢出计算区域。undefined 继承模式,显式 viewport 重置 scroll。DOM 容器不变,坐标在下次对齐时更新。 | PopupOverflow | 父级 / viewport |
popupMatchSelectWidth | Select、AutoComplete 和 TreeSelect 的共用面板宽度。undefined 继承值,组件的局部属性优先。Cascader 使用自己的属性。 | boolean | number | 父级 / true |
renderEmpty | 空状态的生产者,包括片段。支持和后备取决于组件。 | (componentName?) => RenderEmptyContent | 父/空 |
virtual | Tree/DirectoryTree、TreeSelect、Listy、Select 和 AutoComplete 的共用 virtual 设置。 | boolean | 父/没有共同含义 |
class | 提供者 div 类。 | string | — |
style | 计算 CSS 变量后根 CSS。 | string | — |
ConfigProvider.config()
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
holderRender | 为静态方法打开的对话框提供外层片段。 | Snippet<[content: Snippet]> | — |
prefixCls | 独立根节点中组件的类名前缀。 | string | ant |
iconPrefixCls | 内置确认图标的类名前缀。 | string | anticon |
theme | 静态对话框独立根节点的主题。 | ThemeConfig | — |
ThemeConfig
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
token | 算法中涉及种子覆盖;别名与计算值重叠。 | Partial<AliasToken> | 父/defaultSeed + 算法 |
algorithm | 算法按数组顺序执行;default/dark/compact 可用。 | MappingAlgorithm | readonly MappingAlgorithm[] | 父/默认算法 |
components | 覆盖选定的组件。具体代币的连接由家族的实现决定。 | ComponentsConfig | 父配置 |
inherit | false 会重置父令牌/算法/components,但不会重置整个 ConfigProvider。 | boolean | true |
hashed | false 返回空的 hashId。它不是应用程序的自定义 CSS 隔离。 | boolean | true |
cssVar | 命名空间 CSS 变量。继承的前缀优先于新的 prefixCls,本地 cssVar.prefix 优先于两者;显式 undefined 返回当前提供程序的后备。 | {prefix?: string; key?: string} | 主题/提供商前缀;重点区域 |
zeroRuntime | 继承源 theme 设置;包的已发布 CSS 仍然是必需的。 | boolean | 父/假 |
mode | 兼容的速记主题 Svelte。 | light | dark | 父/光 |
primary | 兼容的预设。使用 token.colorPrimary 设置任意颜色。 | blue | purple | green | 父级/蓝色 |
compact | 兼容的速记紧凑指标。 | boolean | 父/假 |
WaveConfig
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
disabled | 禁用波浪效果。 | boolean | false |
showEffect | 自己的动画;创建的资源由回调的所有者释放。 | ShowWaveEffect | 标准效应 |
triggerType | 触发波浪的事件。 | click | pointerdown | pointerup | mousedown | mouseup | click |
组件设置
upload: UploadConfig 设置 class/style、classNames/styles、accept、customRequest 和上传/拖动器的 progress。嵌套的上传记录被完全替换;局部类与通用类一起累积,CSS 行在通用类之后应用。进步是按领域组合起来的。 例子 显示嵌套区域和无服务器传输。
嵌套记录设置相应组件的默认值。下面列出了已发布的密钥;系列页面和封装类型上描述了具体选项。
| 钥匙 | 目的 |
|---|---|
| app | class/style 包装应用程序。 Record 替换整个父记录;当地 style 优先。 |
| layout | 仅布局容器的 class/style;部分和 Sider 不直接接收记录。 |
| statistic | class/style 和对象或功能 classNames/styles Statistic 和 StatisticTimer。 |
| steps | class/style 和对象或功能 classNames/styles 步骤。 |
| timeline | class/style 和对象或功能 classNames/styles时间线。 |
| form | 标题、requiredMark、tooltip、class/style、语义默认值、validateMessages 和 scrollToFirstError。 |
| button | 外观、形状、语义默认值和 autoInsertSpace。 |
| input | variant、allowClear 和语义默认值。 |
| inputPassword | 输入密码设置。 |
| inputSearch | 输入搜索设置。 |
| otp | 输入OTP设置。 |
| textArea | 文本区域设置。 |
| inputNumber | 数字字段设置。 |
| select | Select/AutoComplete 共享 variant、class/style、classNames/styles、showSearch 和图标。只有 Select 继承 boolean 或对象形式的 allowClear。 |
| tree | TreeConfig:Tree/DirectoryTree 的 class/style 和五个 semantic slots。TreeSelect 不继承此配置。 |
| treeSelect | 选择树的唯一 variant。 |
| mentions | Mentions 字段的样式变体、清除按钮,以及根节点和各个部分的类名与样式。 |
| checkbox | 通用 class/style 和语义默认值。 |
| radio | 通用 class/style 和语义默认值。 |
| switch | 通用 class/style 和语义默认值。 |
| slider | 比例设置和语义默认值。 |
| colorPicker | 调色板和弹出窗口设置。 |
| datePicker | 只是单个 DatePicker 的 variant。 |
| rangePicker | RangePicker 和 TimeRangePicker 设置。 |
| timePicker | 时间设置。 |
| cascader | 级联/面板设置。 |
| transfer | 传输列表设置。 |
| rate | 评价设置。 |
| segmented | 选项开关设置。 |
| space | size、class/style 和语义默认空间。 |
| divider | 分隔符设置。 |
| flex | 弹性设置。 |
| masonry | 砌体设置。 |
| splitter | 共享面板的设置。 |
| affix | 外部 Affix 节点的 class/style。 |
| pagination | 分页和语义默认设置。 |
| table | 共享行键、滚动配置、样式和展开按钮。 |
| drawer | 遮罩、焦点、关闭按钮及面板各部分的样式。 |
| modal | 遮罩、焦点、对齐方式、对话框各部分样式,以及按钮和确认图标。 |
| message | 消息列表、图标和文字的通用类名与样式。 |
| notification | 通知共用的类名、样式和关闭图标。 |
| tabs | 选项卡和语义默认设置。 |
| tooltip | 工具提示和弹出窗口设置。 |
| popover | Popover 和弹出窗口设置。 |
| popconfirm | 确认和弹出设置。 |
| badge | 徽章设置。 |
| ribbon | 徽章功能区设置。 |
| avatar | 头像设置。 |
| card | variant、class/style 和对象或功能 classNames/styles卡。 |
| cardMeta | class/style 和对象或功能 classNames/styles CardMeta。 |
| descriptions | class/style 和对象或功能 classNames/styles描述。 |
| anchor | class/style 和对象或函数 classNames/styles 锚点。 |
| tag | 标签设置。 |
| typography | 文本设置和语义默认值。 |
| calendar | 日历设置。 |
| carousel | 轮播设置。 |
| collapse | 折叠和语义默认设置。 |
| listy | 列表设置,包括 virtual 设置。 |
| tour | 游览设置;全局弹出容器不被它继承。 |
| floatButton | 单独浮动按钮的设置。 |
| floatButtonGroup | 一组浮动按钮的设置。 |
| qrcode | 二维码设置。 |
| watermark | 水印设置。 |
| borderBeam | 装饰层的 class/style。 |
| spin | 旋转设置。 |
| progress | 进度设置。 |
| upload | UploadConfig:上传/拖动器的 class/style、语义槽、accept、customRequest 和 progress。嵌套记录被完全替换。 |
| skeleton | 骨架设置。 |
| empty | 设置为空。 |
| result | 结果设置。 |
| alert | 警报设置。 |
Semantic DOM
命名语义槽未发布。 ConfigProvider 创建
div.ant-svelte-theme 和 dir、主题班、
data-ant-theme, data-ant-primary 和 CSS 变量。class/style 指的是这个根。包装器不会更改子控件的语义。
上下文遵循 Svelte 组件树。对于 popup,受支持的组件在包装 DOM 时保留其主题; getPopupContainer 本身不会替换上下文。
注册令牌
ConfigProvider 没有自己的组件令牌。 theme.token 设置一般值,theme.components — 覆盖各个系列。 theme.useToken 返回一个响应式 token/theme/hashId/cssVar 对象。当前页面主题的值如下所示。
| 代币 | 意义 |
|---|---|
colorPrimary | #2f54eb |
colorPrimaryHover | #597ef7 |
colorBgContainer | #ffffff |
colorText | rgba(0,0,0,0.88) |
fontSize | 14 |
lineHeight | 1.5714285714285714 |
controlHeight | 32 |
borderRadius | 6 |
padding | 16 |
margin | 16 |
FAQ
如何选择 variant?
本地属性优先于最近的表单、组件配置和通用 variant。嵌套表单的详细顺序和功能在常规设置部分描述。
设置是如何继承的?
未指定的值取自父级。传入的组件配置会替换整个对应的记录;主题和语言环境有单独的部分继承规则。
在哪里调用 theme.useToken?
在子Svelte组件下需要ConfigProvider。标记中下面的提供程序不会更改其父组件的脚本上下文。
getDesignToken 与 useToken 有何不同?
第一个静态计算标记,第二个读取即时上下文。静态计算不会改变页面设计。
我需要切换 Dayjs 全局语言环境吗?
组件字典由提供者 locale 指定。本地化操作和控件之外的Day.js插件分开配置;日期模型仍然是 Dayjs。
popup 容器和 scroll 容器如何工作?
GetPopupContainer 更改支持的 popup 的容器,getTargetContainer 更改 Affix/Anchor 滚动区域。本地设置优先,回调在浏览器中执行。
如何使用消息和确认?
可使用 App.useApp() 打开消息和上下文确认框。独立对话框使用 Modal.confirm() 和静态对话框设置。
官方ConfigProvider的所有参数都已经支持了吗?
支持的属性见 API 表格。
是否有单独的令牌和语义 DOM 提供程序插槽?
没有自己的组件标记和 classNames/styles。提供程序创建一个带有 dir 和 class/style 的主题包装器,并传入常见的 CSS 变量和上下文。