Spin
等待指示器:大小、延迟、百分比和全屏模式。
何时使用
待机模式及内容
spinning 控件等待并默认为 true。description 指定带有文本或片段的解释。size 接受 small/medium/large。 children 允许您在等待层下存储数据。
| 问题 | 机会 | 示例 |
|---|---|---|
| 显示个人状态 | spinning,可用名称 |
主要指标 |
| 更新字段而不丢失草稿 | children |
嵌套模式 |
| 不显示短路指示器 | delay |
延迟 |
| 替换等待模式 | indicator 片段 |
您自己的指标 |
| 转移百分比 | 编号或 auto |
百分比 |
| 待机层占屏 | fullscreen |
全屏模式 |
在嵌套模式下,children 保留在 DOM 中。在等待的过程中,内容处于 inert 状态,并设置 aria-busy;草稿已保存,暂时不可用的焦点由组件处理。这与 Skeleton 不同,骷髅取代了 children。
延迟、百分比和完成情况
delay 以毫秒为单位测量并延迟指示器的出现。请求的 spinning 会立即阻止嵌套内容。如果您在 delay 到期之前结束等待,则该指示器将不会出现。
数字 percent 必须来自应用程序。auto 模拟运动直到等待结束并且不测量网络或处理。成功、错误、取消,根据操作结果改变 spinning;组件本身不会启动它。
个人资料更新 保存草稿并显示重播错误。取消和离开页面不会受到延迟结果的影响。全屏示例的计时器在卸载时被清除;这是一个演示,Spin 没有强制等待期。
fullscreen、指示器和主题
fullscreen - 当前 DOM 分支中的固定层,没有门户和焦点陷阱。它不是一个成熟的模式窗口。在阻止的内容之外放置明确的取消操作或确保操作完成。
indicator - 带有 class/style、prefixCls 和 percent 的被动 Svelte 片段。常规选项可以通过 ConfigProvider.spin 设置。 Spin.setDefaultIndicator 存在,但 setter 不会更新已挂载的实例;对于反应式和隔离设置,请使用提供程序。
classNames/样式的 styles 为 root/section/indicator/description/container;styles 由 CSS 字符串设置。旋转设计令牌(design tokens)控制点的大小和区域的高度。标准指标和可用内容通过SSR显示;水合后,delay、auto 和控制装置开始工作。
非空本地 prefixCls 指定 Spin CSS 类,并传递给 info.prefixCls 中的自定义 indicator。空字符串和 undefined 继承ConfigProvider.prefixCls,带有 -spin 后缀,默认为 ant-spin。delay、加载状态和命名空间 CSS 变量与类更改无关。 示例 ConfigProvider 显示继承。
示例
常规下载
独立地位,名称通俗易懂。
<script lang="ts">
import { Spin } from '@woodger/antd';
</script>
<Spin aria-label={("加载列表")} />
方面
small、medium、large。
<script lang="ts">
import { Spin } from '@woodger/antd';
const sizes = ['small', 'medium', 'large'] as const;
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 32px;
}
.item {
display: grid;
justify-items: center;
gap: 16px;
}
</style>
<div class="examples">
{#each sizes as size (size)}
<div
class="item"
><Spin
{size}
aria-label={("加载中 " + String((size)) + "")}
/><span>{(size)}</span></div>
{/each}
</div>
加载后保存该值。
加载现有内容
该草稿仍保留在 DOM 中。
<script lang="ts">
import { Checkbox, Input, Spin } from '@woodger/antd';
let spinning = $state(false);
let draft = $state<string | undefined>(("草稿仍保留在 DOM 中"));
</script>
<style>
.settings { margin-bottom: 24px; }
.document {
display: grid;
gap: 16px;
min-height: 160px;
padding: 24px;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
</style>
<div
class="settings"
><Checkbox
bind:checked={spinning}
>{("加载内容")}</Checkbox></div>
<Spin {spinning} description={("更新文档")} aria-label={("文档")}>
<div
class="document"
><Input
aria-label={("文件草案")}
bind:value={draft}
/><p>{("加载后保存该值。")}</p></div>
</Spin>
等待的描述
通过 Svelte Snippet 进行描述。
<script lang="ts">
import { Spin } from '@woodger/antd';
</script>
<style>
.document {
min-height: 160px;
padding: 24px;
}
strong {
display: block;
margin-bottom: 4px;
}
</style>
{#snippet description()}<strong>
{("数据准备")}
</strong><span>
{("这将需要几秒钟。")}
</span>{/snippet}
<Spin
description={(description)}
aria-label={("数据准备")}
><div
class="document"
>{("章节内容。")}</div></Spin>
出现延迟
等待 500 毫秒并明确取消。
<script lang="ts">
import { Button, Checkbox, Spin } from '@woodger/antd';
let spinning = $state(false);
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-bottom: 24px;
}
.document {
min-height: 160px;
padding: 24px;
}
</style>
<div class="settings">
<Checkbox bind:checked={spinning}>{("预计回复延迟")}</Checkbox>
<Button onclick={() => { spinning = false; }}>{("取消等待")}</Button>
</div>
<Spin {spinning} delay={500} description={("我们正在等待回复")} aria-label={("延迟加载")}>
<div class="document">{("该指示器会在 500 毫秒后出现。在此日期之前取消将不会显示该日期。")}</div>
</Spin>
您自己的指标
本地和通过 ConfigProvider.spin 的片段。
<script lang="ts">
import { ConfigProvider, Spin, type SpinIndicatorInfo } from '@woodger/antd';
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 32px;
}
</style>
{#snippet indicator(info: SpinIndicatorInfo)}
<svg
class={info.class}
style={info.style}
viewBox="0 0 32 32"
width="1em"
height="1em"
aria-hidden="true"
>
<circle
cx="16"
cy="16"
r="12"
fill="none"
stroke="currentColor"
stroke-width="3"
stroke-dasharray="48 28"
/>
</svg>
{/snippet}
<div class="examples">
<Spin {indicator} aria-label={("自带指标")} />
<ConfigProvider spin={{ indicator }}>
<Spin aria-label={("提供商指标")} />
</ConfigProvider>
</div>
下载百分比
可测量百分比和条件 auto 模式。
<script lang="ts">
import { Checkbox, InputNumber, Spin } from '@woodger/antd';
let percent = $state(35);
let auto = $state(false);
let spinning = $state(true);
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 24px;
}
.document {
min-height: 180px;
padding: 24px;
}
</style>
<div class="settings">
<InputNumber aria-label={("旋转负载百分比")} value={percent} min={0} max={100}
onValueChange={next => { percent = next ?? 0; }} />
<Checkbox bind:checked={auto}>{("自动进度")}</Checkbox>
<Checkbox bind:checked={spinning}>{("显示进度")}</Checkbox>
</div>
<Spin
{spinning}
percent={auto ? 'auto' : percent}
description={("处理文件")}
aria-label={("文件处理")}
>
<div class="document">{("自动显示期望的有条件进度,并不衡量实际任务。")}</div>
</Spin>
Semantic DOM
样式对象和功能。
<script lang="ts">
import { ConfigProvider, Spin } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
gap: 24px;
}
.document {
min-height: 140px;
padding: 24px;
}
</style>
<ConfigProvider spin={{ styles: { description: 'font-weight: 600' } }}>
<div class="examples">
<Spin
description={("样式对象")}
aria-label={("旋转物体")}
classNames={{ root: 'spin-object' }}
styles={{
root: `
border: 1px dashed #d48806;
border-radius: 8px;
`,
indicator: 'color: #d48806'
}}
>
<div class="document">{("带框架的文档。")}</div>
</Spin>
<Spin
description={("款式特色")}
aria-label={("自旋功能")}
classNames={{ root: 'spin-function' }}
styles={({ props }) => ({ description: props.spinning ? 'font-weight: 700' : '' })}
>
<div class="document">{("风格取决于道具。")}</div>
</Spin>
</div>
</ConfigProvider>
全屏等待
该示例在两秒后关闭。
<script lang="ts">
import { onDestroy } from 'svelte';
import { Button, Spin } from '@woodger/antd';
let spinning = $state(false);
let timer: ReturnType<typeof setTimeout> | undefined;
function show() {
clearTimeout(timer);
spinning = true;
timer = setTimeout(() => { spinning = false; }, 2000);
}
onDestroy(() => clearTimeout(timer));
</script>
<Button onclick={show}>{("显示全屏加载")}</Button>
<Spin
{spinning}
fullscreen
description={("页面加载 2 秒")}
aria-label={("全屏加载")}
/>
代币和 RTL
点的大小和装载区域的高度。
<script lang="ts">
import { ConfigProvider, Spin } from '@woodger/antd';
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 32px;
margin-bottom: 24px;
}
.document {
min-height: 160px;
padding: 24px;
}
</style>
<ConfigProvider direction="rtl" theme={{
token: { colorPrimary: '#d48806' }, components: {
Spin: { dotSize: 28, dotSizeSM: 18, dotSizeLG: 40, contentHeight: 240 }
}
}}>
<div class="examples"><Spin size="small" aria-label={("主题小旋转")} />
<Spin aria-label={("主题旋转")} /><Spin size="large" aria-label={("主题大旋转")} /></div>
<Spin description={("文件准备")} aria-label={("议题文件")}>
<div class="document">{("嵌套主题和 RTL 方向。")}</div>
</Spin>
</ConfigProvider>
卡的变化: 0。数据版本: 0.
个人资料更新
成功、错误、重做、取消和保存草稿。
SpinExample.svelte<script lang="ts"> import { onDestroy, tick } from 'svelte'; import { Alert, Button, Checkbox, Input, Select, Spin, type SpinSize } from '@woodger/antd'; import { createSpinLoad } from './spin-load.model.svelte'; const model = createSpinLoad(); let delay = $state<0 | 200 | 500>(200); let size = $state<SpinSize>('medium'); let name = $state<string | undefined>(("安娜")); let notifications = $state(true); let edits = $state(0); let active = true; const sizes = ['small', 'medium', 'large'] .map((value) => ({ value: value as SpinSize, label: value })); let result = $derived( model.status === 'loading' ? "个人资料正在更新中..." : model.status === 'ready' ? `数据已更新。版本: ${model.revision}.` : model.status === 'error' ? "无法加载配置文件。" : model.status === 'cancelled' ? "下载已取消。" : "编辑草稿并更新数据。" ); async function cancel() { if (!model.cancel()) { return; } await tick(); if (active) { const startButton = document.getElementById('spin-example-start'); startButton?.focus({ preventScroll: true }); } } async function retryLoad() { if (!model.load()) { return; } await tick(); if (active && model.loading) { const card = document.getElementById('showcase-spin'); card?.focus({ preventScroll: true }); } } function reset() { model.reset(); name = ("安娜"); notifications = true; edits = 0; } onDestroy(() => { active = false; model.destroy(); }); </script> <style> .controls, .sizes { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; } .sizes { margin-block: 24px; gap: 32px; } .size { display: flex; flex-direction: column; align-items: center; gap: 8px; } .field { width: 160px; } .card { display: grid; gap: 16px; min-height: 190px; padding: 20px; border: 1px solid var(--ant-color-border-secondary); border-radius: var(--ant-border-radius-lg); } .card p { margin: 0; } .draft { max-width: 340px; } .loading { margin-block: 24px; } output { display: block; margin-top: 20px; color: var(--ant-color-text-secondary); } </style> {#snippet retry()} <Button onclick={() => { void retryLoad(); }}> {("再次重新加载配置文件")} </Button> {/snippet} <div class="controls"><Button id="spin-example-start" type="primary" loading={model.loading} onclick={() => model.load()} >{("上传个人资料")}</Button><Button disabled={model.loading} onclick={() => model.load('fast')} >{("快速响应")}</Button><Button disabled={model.loading} onclick={() => model.load('error')} >{("加载配置文件时出错")}</Button><Button disabled={!model.loading} onclick={() => { void cancel(); }} >{("取消下载")}</Button><Button onclick={reset} >{("重置旋转示例")}</Button><div class="field" ><Select aria-label={("旋转延迟")} bind:value={delay} options={([ { value: 0, label: "无延迟" }, { value: 200, label: "200毫秒" }, { value: 500, label: "500毫秒" } ])} /></div><div class="field" ><Select aria-label={("旋转尺寸")} bind:value={size} options={(sizes)} /></div></div> <div class="sizes" aria-label={("旋转指示器尺寸")} >{#each sizes as item}<div class="size" ><Spin size={item.value} aria-hidden /><span>{(item.label)}</span></div>{/each}</div> <div class="loading"> <Spin spinning={model.loading} {delay} {size} description={("正在加载个人资料...")} aria-label={("会员简介")} id="showcase-spin" > <div class="card" ><label for="spin-example-name" >{("草稿中的名字")}</label><div class="draft" ><Input id="spin-example-name" bind:value={name} /></div><Checkbox bind:checked={notifications} > {("个人资料通知")} </Checkbox><p>{("卡的变化: ")}{edits}{("。数据版本: ")}{(model.revision)}.</p><div class="controls" ><Button onclick={() => { edits++; }} >{("换卡")}</Button><Button onclick={() => model.load()} >{("从卡更新")}</Button></div></div> </Spin> </div> {#if model.status === 'error'}<Alert type="error" title={("加载配置文件时出错")} description={("草稿已保存。再次尝试更新数据。")} action={retry} showIcon />{/if} <output aria-label={("自旋示例结果")}>{result}</output>spin-load.model.svelte.tstype LoadStatus = 'idle' | 'loading' | 'ready' | 'error' | 'cancelled'; export type SpinLoadKind = 'normal' | 'fast' | 'error'; export function createSpinLoad() { let state = $state.raw<{ status: LoadStatus; revision: number }>({ status: 'idle', revision: 0 }); let timer: ReturnType<typeof setTimeout> | undefined; let generation = 0; let active = true; function clear() { generation++; clearTimeout(timer); timer = undefined; } return { get status() { return state.status; }, get loading() { return state.status === 'loading'; }, get revision() { return state.revision; }, load(kind: SpinLoadKind = 'normal') { if (!active || state.status === 'loading') { return false; } clear(); const current = generation; state = { ...state, status: 'loading' }; timer = setTimeout(() => { if (!active || current !== generation) { return; } timer = undefined; state = kind === 'error' ? { ...state, status: 'error' } : { status: 'ready', revision: state.revision + 1 }; }, kind === 'fast' ? 50 : 700); return true; }, cancel() { if (state.status !== 'loading') { return false; } clear(); state = { ...state, status: 'cancelled' }; return true; }, reset() { clear(); state = { status: 'idle', revision: 0 }; }, destroy() { active = false; clear(); } }; }
API
ant.design 6.7.0 官方页面的九个主题映射到公共 Svelte API。
| 主题 | 示例或限制 |
|---|---|
| Basic Usage | 具有可访问名称的单独指示器。 |
| Size | small、medium、large。 |
| Embedded mode | 保存草稿并锁定占用区域。 |
| Customized description | 通过 Svelte Snippet 进行描述。 |
| Delay | 延迟出现和取消。 |
| Custom spinning indicator | 本地 indicator 和ConfigProvider.spin。 |
| Progress | 已知百分比并明确启用 auto。 |
| Custom semantic dom styling | 对象和回调样式。 |
| Fullscreen | 全屏等待并自动完成。 |
Spin
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | Spin 及其状态的完整本地 CSS 前缀;也被传送到 indicator info。空字符串和 undefined 继承ConfigProvider.prefixCls;默认是 ant-spin。 | string | ConfigProvider + -spin |
spinning | 请求的等待状态。 | boolean | true |
delay | 出现延迟(以毫秒为单位)。内容立即被屏蔽。 | number | 0 |
size | 指标大小。 | small | medium | large | medium |
description | 文本或片段描述。 | SpinContent | — |
indicator | 被动指示器;获取 class/style、prefixCls 和 percent。 | Snippet<[SpinIndicatorInfo]> | null | 四点 |
percent | 预期的循环百分比或有条件进展。 | number | auto | — |
fullscreen | 当前 DOM 分支中的固定层。 | boolean | false |
children | 嵌套模式的内容存储在DOM中。 | SpinContent | — |
classNames | 命名元素类,包括根。 | SpinSemanticSlots | callback | — |
styles | CSS 字符串;回调获取当前道具。 | SpinSemanticSlots | callback | — |
nativeElement | bind:nativeElement 挂载后获取根。 | HTMLDivElement | — |
ref | 通过 bind:ref 获取 nativeElement 字段。 | SpinRef | — |
indicator - 带有 SpinIndicatorInfo 参数的片段;description/children 接受文本和片段。 ConfigProvider.spin指定公共类、样式和 indicator。
Semantic DOM
单独可见的 Spin 报告 status;嵌套的容器有组、status 描述和 inert/aria-busy。内容未卸载。 Mask 是全屏图层的附加插槽。
| Slot | 目的 |
|---|---|
root | 单屏、嵌套或全屏模式的根。 |
section | 指示器和描述区域。 |
indicator | 标准或自定义图标。 |
description | 指示器下方的文字。 |
container | 内容持续 inert 且 aria-busy。 |
注册令牌
ConfigProvider.theme.components.Spin 指定四个令牌。 colorPrimary 控制标准指标;fullscreen 使用遮罩颜色和弹出元素的基础层。
| 代币 | 目的 |
|---|---|
contentHeight | 嵌套模式下指示器区域的最大高度。 |
dotSize | 常规图标。 |
dotSizeSM | 小图标。 |
dotSizeLG | 大图标。 |
| 代币 | 意义 |
|---|---|
colorPrimary | #2f54eb |
colorBgMask | rgba(0,0,0,0.45) |
colorBgContainer | #ffffff |
colorTextDescription | rgba(0,0,0,0.45) |
fontSize | 14 |
zIndexPopupBase | 1000 |
FAQ
等待时字段会消失吗?
不会。嵌套 DOM 会被保留并变得 inert 且 aria-busy;草案仍然存在。
delay 控制什么?
仅指示器的外观。请求的 spinning 会立即阻止内容。
auto 测量实际负载吗?
否。对于实际数量,请传递一个数字。
如何更换某个区域的指标?
使用 ConfigProvider.spin。静态设置器不会更新已安装的实例。
fullscreen 是否创建模态窗口?
不。这是一个固定层,没有传送门或焦点陷阱。
没有 JavaScript 可以做什么?
服务器显示标准指标和内容。水合后延迟、auto 和控制工作。