syncfusion-react-notifications
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Syncfusion React Notifications
实现Syncfusion React通知组件
Toast
Toast
The Syncfusion React Toast component displays brief, non-intrusive notifications that auto-dismiss after a configurable timeout. Toasts support rich content through templates, action buttons, animated entry/exit, precise positioning, and programmatic control via .
ToastUtilitySyncfusion React Toast组件用于展示简短、无侵入性的通知,可配置超时时间后自动关闭。Toast支持通过模板实现富内容、操作按钮、动画入场/退场效果、精准定位,还可通过进行程序化控制。
ToastUtilityPackage and Setup
包安装与初始化配置
📄 Read: references/getting-started.md
- Installing
@syncfusion/ej2-react-notifications - CSS imports for all required themes
- Basic usage (class and functional patterns)
ToastComponent - Rendering toast in a custom target container
- Triggering show in the event
created
📄 阅读: references/getting-started.md
- 安装
@syncfusion/ej2-react-notifications - 导入所有所需主题的CSS
- 基础用法(类组件与函数组件模式)
ToastComponent - 在自定义目标容器中渲染toast
- 在事件中触发展示
created
Documentation and Navigation Guide
文档与导航指南
Configuration and Layout
配置与布局
📄 Read: references/configuration.md
- Setting and
title(plain text, HTML, elements)content - Custom container for scoped notifications
target - for manual dismissal
showCloseButton - and
showProgressBar(Ltr / Rtl)progressDirection - stacking order
newestOnTop - and
widthdimensions (px, %, auto)height
📄 阅读: references/configuration.md
- 设置和
title(纯文本、HTML、DOM元素)content - 为作用域通知设置自定义容器
target - 配置支持手动关闭
showCloseButton - 和
showProgressBar(从左到右/从右到左)progressDirection - 堆叠顺序
newestOnTop - 和
width尺寸配置(px、%、auto)height
Positioning
定位
📄 Read: references/position.md
- Nine predefined X/Y positions (Left, Center, Right / Top, Bottom)
- Custom pixel and percentage coordinates
- Targeting a container element for relative positioning
- Multiple Toast instances at different screen positions
📄 阅读: references/position.md
- 9种预定义X/Y轴位置(左、中、右/上、下)
- 自定义像素和百分比坐标
- 绑定容器元素实现相对定位
- 屏幕不同位置同时展示多个Toast实例
Timeout and Dismissal
超时与关闭逻辑
📄 Read: references/timeout-and-dismissal.md
- property (default 5000 ms)
timeOut - on hover (default 1000 ms)
extendedTimeout - Static persistent toasts with
timeOut: 0 - Click-to-close via in the
clickToCloseeventclick - Preventing mobile swipe dismissal with
beforeClose
📄 阅读: references/timeout-and-dismissal.md
- 属性(默认5000毫秒)
timeOut - 悬停时的(默认1000毫秒)
extendedTimeout - 通过实现静态持久化toast
timeOut: 0 - 通过事件的
click实现点击关闭clickToClose - 通过禁止移动端滑动关闭
beforeClose
Templates and Styling
模板与样式
📄 Read: references/templates-and-styling.md
- property with HTML strings and DOM selectors
template - Dynamic templates passed at call time
show() - Semantic CSS classes: ,
e-toast-success,e-toast-info,e-toast-warninge-toast-danger - CSS selectors for title, content, icon, and background customization
📄 阅读: references/templates-and-styling.md
- 属性支持HTML字符串和DOM选择器
template - 调用时传入动态模板
show() - 语义化CSS类:、
e-toast-success、e-toast-info、e-toast-warninge-toast-danger - 支持通过CSS选择器自定义标题、内容、图标和背景
Animation
动画
📄 Read: references/animation.md
- property with
animationandshoweffect settingshide - Available effects: FadeIn, FadeZoomIn, SlideBottomIn, ZoomIn, FlipLeftUpIn, and more
- Default: FadeIn / FadeOut
- Accessibility: reduced-motion considerations
📄 阅读: references/animation.md
- 属性支持配置
animation和show效果hide - 可用效果:FadeIn、FadeZoomIn、SlideBottomIn、ZoomIn、FlipLeftUpIn等
- 默认效果:FadeIn / FadeOut
- 无障碍支持:减动模式适配
Toast Services and Advanced Patterns
Toast服务与高级用法
📄 Read: references/toast-services.md
- for quick toasts without component instantiation
ToastUtility.show() - Four predefined types: ,
Information,Success,ErrorWarning - Passing a full to
ToastModelToastUtility.show() - Playing audio on
beforeOpen - Restricting maximum simultaneous toasts with
beforeOpen - Preventing duplicate toasts using +
beforeOpenclose
📄 阅读: references/toast-services.md
- 无需实例化组件即可快速创建toast
ToastUtility.show() - 4种预定义类型:、
Information、Success、ErrorWarning - 向传入完整
ToastUtility.show()配置ToastModel - 在事件中播放提示音
beforeOpen - 通过限制同时展示的最大toast数量
beforeOpen - 通过+
beforeOpen事件避免重复toastclose
Accessibility
无障碍访问
📄 Read: references/accessibility.md
- WAI-ARIA: ,
role="alert",aria-live="assertive"aria-label - WCAG 2.2, Section 508, ADA compliance
- Screen reader support (JAWS, NVDA, VoiceOver)
- RTL support via
enableRtl - Mobile and accessibility checker validation
📄 阅读: references/accessibility.md
- WAI-ARIA:、
role="alert"、aria-live="assertive"aria-label - 符合WCAG 2.2、Section 508、ADA标准
- 屏幕阅读器支持(JAWS、NVDA、VoiceOver)
- 通过支持从右到左布局
enableRtl - 移动端与无障碍检测工具验证
API Reference
API参考
📄 Read: references/api.md
- All properties with types, defaults, and descriptions
- and
show()method signatureshide() - All events: ,
beforeOpen,open,click,beforeClose,close,created,destroyedbeforeSanitizeHtml
📄 阅读: references/api.md
- 所有属性的类型、默认值与说明
- 和
show()方法签名hide() - 所有事件:、
beforeOpen、open、click、beforeClose、close、created、destroyedbeforeSanitizeHtml
Quick Start Example
快速开始示例
tsx
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import '@syncfusion/ej2-base/styles/tailwind3.css';
import '@syncfusion/ej2-react-notifications/styles/tailwind3.css';
import { useRef } from 'react';
function App() {
const toastRef = useRef<ToastComponent>(null);
return (
<>
<button onClick={() => toastRef.current?.show()}>Show Toast</button>
<ToastComponent
ref={toastRef}
title="Success!"
content="Your changes have been saved."
cssClass="e-toast-success"
position={{ X: 'Right', Y: 'Bottom' }}
timeOut={4000}
showProgressBar={true}
showCloseButton={true}
/>
</>
);
}tsx
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import '@syncfusion/ej2-base/styles/tailwind3.css';
import '@syncfusion/ej2-react-notifications/styles/tailwind3.css';
import { useRef } from 'react';
function App() {
const toastRef = useRef<ToastComponent>(null);
return (
<>
<button onClick={() => toastRef.current?.show()}>Show Toast</button>
<ToastComponent
ref={toastRef}
title="Success!"
content="Your changes have been saved."
cssClass="e-toast-success"
position={{ X: 'Right', Y: 'Bottom' }}
timeOut={4000}
showProgressBar={true}
showCloseButton={true}
/>
</>
);
}Quick Utility Toast (No Component Needed)
工具类快速调用Toast(无需声明组件)
tsx
import { ToastUtility } from '@syncfusion/ej2-react-notifications';
// Show a success toast instantly
ToastUtility.show('File saved successfully', 'Success', 3000);
// Show an error toast
ToastUtility.show('Connection failed', 'Error', 5000);tsx
import { ToastUtility } from '@syncfusion/ej2-react-notifications';
// 立即展示成功toast
ToastUtility.show('File saved successfully', 'Success', 3000);
// 展示错误toast
ToastUtility.show('Connection failed', 'Error', 5000);Common Patterns
常用用法
Semantic type toasts
语义化类型toast
Use with , , , for visual differentiation — see references/templates-and-styling.md.
cssClasse-toast-successe-toast-infoe-toast-warninge-toast-danger搭配使用、、、实现视觉区分——参考references/templates-and-styling.md。
cssClasse-toast-successe-toast-infoe-toast-warninge-toast-dangerStatic/persistent toasts
静态/持久化toast
Set with for notifications users must explicitly dismiss — see references/timeout-and-dismissal.md.
timeOut: 0showCloseButton: true设置并开启,实现需要用户主动关闭的通知——参考references/timeout-and-dismissal.md。
timeOut: 0showCloseButton: trueAction-required toasts
需要操作的toast
Use the property to add Ignore/Confirm/Undo buttons — see references/configuration.md.
buttons使用属性添加忽略/确认/撤销按钮——参考references/configuration.md。
buttonsPrevent duplicates
避免重复toast
Use the event to cancel duplicate toasts already on screen — see references/toast-services.md.
beforeOpen使用事件取消已在屏幕上展示的重复toast——参考references/toast-services.md。
beforeOpenLimit max visible toasts
限制最大可见toast数量
Cap simultaneous toasts at N using and — see references/toast-services.md.
beforeOpenelement.childElementCount通过和将同时展示的toast数量限制为N——参考references/toast-services.md。
beforeOpenelement.childElementCountMessage
Message
The Syncfusion displays contextual messages with visual severity indicators—icons and colors—to communicate importance and context to end users. It supports five severity levels, three visual variants, close-icon dismissal, custom templates, and full accessibility compliance.
MessageComponentSyncfusion 用于展示上下文提示消息,带有视觉严重程度指示器(图标和颜色),向终端用户传递信息的重要性和上下文。它支持5种严重等级、3种视觉变体、关闭图标触发关闭、自定义模板,完全符合无障碍访问标准。
MessageComponentNavigation Guide
导航指南
Getting Started
快速开始
📄 Read: references/message-getting-started.md
- Installation of
@syncfusion/ej2-react-notifications - CSS imports and theme configuration
- Rendering the first
MessageComponent - Content via prop or JSX children
content - Running the Vite development server
📄 阅读: references/message-getting-started.md
- 安装
@syncfusion/ej2-react-notifications - CSS导入与主题配置
- 渲染第一个
MessageComponent - 通过属性或JSX子元素传入内容
content - 启动Vite开发服务器
Severity Levels
严重等级
📄 Read: references/message-severities.md
- Five severity levels: Normal, Success, Info, Warning, Error
- prop usage and valid values
severity - Visual distinctions (icons and colors per severity)
- Choosing the right severity for your use case
📄 阅读: references/message-severities.md
- 5种严重等级:Normal、Success、Info、Warning、Error
- 属性用法与有效值
severity - 视觉区别(不同严重等级对应不同图标和颜色)
- 不同场景下严重等级的选择建议
Display Variants
展示变体
📄 Read: references/message-variants.md
- Three variants: Text (default), Outlined, Filled
- prop usage
variant - Combining variant with severity
- Visual trade-offs and when to use each
📄 阅读: references/message-variants.md
- 3种变体:Text(默认)、Outlined、Filled
- 属性用法
variant - 变体与严重等级的组合使用
- 不同变体的视觉权衡与适用场景
Icons and Close Icon
图标与关闭图标
📄 Read: references/message-icons-and-close.md
- Severity icon visibility: prop (default
showIcon)true - Disabling severity icons
- Custom severity icons via CSS overrides
cssClass - Close icon: prop (default
showCloseIcon)false - event handler for dismiss callbacks
closed - Toggling visibility with the prop
visible
📄 阅读: references/message-icons-and-close.md
- 严重等级图标可见性:属性(默认
showIcon)true - 禁用严重等级图标
- 通过CSS覆盖实现自定义严重等级图标
cssClass - 关闭图标:属性(默认
showCloseIcon)false - 事件处理器用于关闭回调
closed - 通过属性切换可见性
visible
Customization and Templates
自定义与模板
📄 Read: references/message-customization.md
- Content alignment: left (default), center (), right (
e-content-center)e-content-right - Custom appearance with
cssClass - CSS-only message rendering (no JS, pure HTML + CSS)
- Content templates: JSX element or render function via prop
content - RTL support via
enableRtl - Persistence with
enablePersistence
📄 阅读: references/message-customization.md
- 内容对齐:左对齐(默认)、居中()、右对齐(
e-content-center)e-content-right - 通过自定义外观
cssClass - 仅用CSS渲染消息(无JS,纯HTML+CSS)
- 内容模板:通过属性传入JSX元素或渲染函数
content - 通过支持从右到左布局
enableRtl - 通过实现状态持久化
enablePersistence
Accessibility
无障碍访问
📄 Read: references/message-accessibility.md
- WCAG 2.2, Section 508, ADA compliance
- WAI-ARIA attributes (,
role=alert)aria-label - Keyboard navigation (Tab, Enter/Space)
- Screen reader support
📄 阅读: references/message-accessibility.md
- 符合WCAG 2.2、Section 508、ADA标准
- WAI-ARIA属性(、
role=alert)aria-label - 键盘导航(Tab、Enter/Space)
- 屏幕阅读器支持
API Reference
API参考
📄 Read: references/message-api.md
- All properties with types, defaults, and descriptions
- Methods: ,
destroygetPersistData - Events: ,
closed,createddestroyed - interface
MessageCloseEventArgs - and
Severityenum valuesVariant
📄 阅读: references/message-api.md
- 所有属性的类型、默认值与说明
- 方法:、
destroygetPersistData - 事件:、
closed、createddestroyed - 接口
MessageCloseEventArgs - 和
Severity枚举值Variant
Quick Start
快速开始
bash
npm install @syncfusion/ej2-react-notifications --savecss
/* src/App.css */
@import '../node_modules/@syncfusion/ej2-base/styles/tailwind3.css';
@import '../node_modules/@syncfusion/ej2-react-notifications/styles/tailwind3.css';tsx
import { MessageComponent } from '@syncfusion/ej2-react-notifications';
import './App.css';
function App() {
return (
<MessageComponent content="Please read the comments carefully" />
);
}
export default App;bash
npm install @syncfusion/ej2-react-notifications --savecss
/* src/App.css */
@import '../node_modules/@syncfusion/ej2-base/styles/tailwind3.css';
@import '../node_modules/@syncfusion/ej2-react-notifications/styles/tailwind3.css';tsx
import { MessageComponent } from '@syncfusion/ej2-react-notifications';
import './App.css';
function App() {
return (
<MessageComponent content="Please read the comments carefully" />
);
}
export default App;Common Patterns
常用用法
Severity Messages
不同严重等级的消息
tsx
<MessageComponent content="Editing is restricted" />
<MessageComponent content="Operation completed" severity="Success" />
<MessageComponent content="Read these notes" severity="Info" />
<MessageComponent content="Check your connection" severity="Warning" />
<MessageComponent content="Submission failed" severity="Error" />tsx
<MessageComponent content="Editing is restricted" />
<MessageComponent content="Operation completed" severity="Success" />
<MessageComponent content="Read these notes" severity="Info" />
<MessageComponent content="Check your connection" severity="Warning" />
<MessageComponent content="Submission failed" severity="Error" />Variant + Severity Combo
变体+严重等级组合
tsx
<MessageComponent content="Editing is restricted" variant="Filled" />
<MessageComponent content="Operation completed" severity="Success" variant="Outlined" />
<MessageComponent content="Submission failed" severity="Error" variant="Filled" />tsx
<MessageComponent content="Editing is restricted" variant="Filled" />
<MessageComponent content="Operation completed" severity="Success" variant="Outlined" />
<MessageComponent content="Submission failed" severity="Error" variant="Filled" />Dismissible Message
可关闭消息
tsx
import { useState } from 'react';
function App() {
const [visible, setVisible] = useState(true);
return (
<MessageComponent
content="Your session will expire soon"
severity="Warning"
showCloseIcon={true}
visible={visible}
closed={() => setVisible(false)}
/>
);
}tsx
import { useState } from 'react';
function App() {
const [visible, setVisible] = useState(true);
return (
<MessageComponent
content="Your session will expire soon"
severity="Warning"
showCloseIcon={true}
visible={visible}
closed={() => setVisible(false)}
/>
);
}Content Template
内容模板
tsx
const contentTemplate = () => (
<div>
<h4>Build succeeded</h4>
<p>All 42 tests passed.</p>
</div>
);
<MessageComponent content={contentTemplate} severity="Success" />tsx
const contentTemplate = () => (
<div>
<h4>Build succeeded</h4>
<p>All 42 tests passed.</p>
</div>
);
<MessageComponent content={contentTemplate} severity="Success" />Skeleton
Skeleton
The Syncfusion React renders animated placeholder shapes that mimic the layout of loading content. It reduces perceived load time and communicates progress to users with configurable shapes, shimmer animations, and full accessibility support.
SkeletonComponentPackage:
@syncfusion/ej2-react-notificationsSyncfusion React 用于渲染动画占位形状,模拟加载中内容的布局。它可以降低用户感知的加载时长,通过可配置的形状、微光动画向用户传递加载进度,完全支持无障碍访问。
SkeletonComponent包:
@syncfusion/ej2-react-notificationsNavigation Guide
导航指南
Getting Started
快速开始
📄 Read: references/skeleton-getting-started.md
- Installing
@syncfusion/ej2-react-notifications - CSS theme imports (tailwind3)
- Minimal setup with
SkeletonComponentandheightwidth - Running the Vite/React app
📄 阅读: references/skeleton-getting-started.md
- 安装
@syncfusion/ej2-react-notifications - CSS主题导入(tailwind3)
- 配置和
height的最简width实现SkeletonComponent - 启动Vite/React应用
Shapes
形状
📄 Read: references/skeleton-shapes.md
- prop:
shape,"Circle","Square","Rectangle"(default)"Text" - Dimension rules: width required for Circle/Square; width + height for Rectangle/Text
- Building multi-shape card skeleton layouts
- Choosing the right shape for avatar, image, text, and icon placeholders
📄 阅读: references/skeleton-shapes.md
- 属性:
shape、"Circle"、"Square"、"Rectangle"(默认)"Text" - 尺寸规则:圆形/正方形必须配置宽度;矩形/文本必须配置宽高
- 构建多形状卡片骨架布局
- 头像、图片、文本、图标占位符的形状选择建议
Shimmer Effects
微光效果
📄 Read: references/skeleton-shimmer-effect.md
- prop:
shimmerEffect(default),"Wave","Pulse""Fade" - Visual behavior of each effect type
- List skeleton example with Pulse effect
- Selecting an effect to match UI context
📄 阅读: references/skeleton-shimmer-effect.md
- 属性:
shimmerEffect(默认)、"Wave"、"Pulse""Fade" - 每种效果类型的视觉表现
- Pulse效果的列表骨架示例
- 匹配UI上下文的效果选择建议
Styles and Visibility
样式与可见性
📄 Read: references/skeleton-styles.md
- prop for custom CSS overrides (wave color, background, animation speed)
cssClass - prop to toggle skeleton on/off based on loading state
visible - Transition pattern: skeleton → actual content
- CSS variable customization
📄 阅读: references/skeleton-styles.md
- 属性用于自定义CSS覆盖(波浪颜色、背景、动画速度)
cssClass - 属性基于加载状态切换骨架屏显隐
visible - 过渡模式:骨架屏 → 实际内容
- CSS变量自定义
Accessibility
无障碍访问
📄 Read: references/skeleton-accessibility.md
- WCAG 2.2, Section 508, ADA compliance
- WAI-ARIA attributes: ,
role="status",aria-label,aria-livearia-busy - prop for accessible skeleton names
label - RTL support via
enableRtl - respect
prefers-reduced-motion
📄 阅读: references/skeleton-accessibility.md
- 符合WCAG 2.2、Section 508、ADA标准
- WAI-ARIA属性:、
role="status"、aria-label、aria-livearia-busy - 属性用于设置骨架屏的无障碍名称
label - 通过支持从右到左布局
enableRtl - 适配减动模式
prefers-reduced-motion
API Reference
API参考
📄 Read: references/skeleton-api.md
- All properties: ,
cssClass,enablePersistence,enableRtl,height,label,locale,shape,shimmerEffect,visiblewidth - Methods:
destroy() - and
SkeletonTypeenum valuesShimmerEffect
📄 阅读: references/skeleton-api.md
- 所有属性:、
cssClass、enablePersistence、enableRtl、height、label、locale、shape、shimmerEffect、visiblewidth - 方法:
destroy() - 和
SkeletonType枚举值ShimmerEffect
Quick Start
快速开始
bash
npm install @syncfusion/ej2-react-notifications --savecss
/* src/App.css */
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-notifications/styles/tailwind3.css";tsx
import { SkeletonComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
import './App.css';
function App() {
return (
<SkeletonComponent height="15px" width="100%" />
);
}
export default App;bash
npm install @syncfusion/ej2-react-notifications --savecss
/* src/App.css */
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-notifications/styles/tailwind3.css";tsx
import { SkeletonComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
import './App.css';
function App() {
return (
<SkeletonComponent height="15px" width="100%" />
);
}
export default App;Common Patterns
常用用法
Profile Card Skeleton
个人资料卡骨架屏
tsx
import { SkeletonComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function ProfileCardSkeleton() {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: '12px', padding: '16px' }}>
{/* Avatar placeholder */}
<SkeletonComponent shape="Circle" width="48px" />
{/* Name and subtitle placeholders */}
<div style={{ flex: 1 }}>
<SkeletonComponent width="60%" height="15px" />
<br />
<SkeletonComponent width="40%" height="12px" />
</div>
</div>
);
}
export default ProfileCardSkeleton;tsx
import { SkeletonComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function ProfileCardSkeleton() {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: '12px', padding: '16px' }}>
{/* 头像占位符 */}
<SkeletonComponent shape="Circle" width="48px" />
{/* 名称和副标题占位符 */}
<div style={{ flex: 1 }}>
<SkeletonComponent width="60%" height="15px" />
<br />
<SkeletonComponent width="40%" height="12px" />
</div>
</div>
);
}
export default ProfileCardSkeleton;Toggle Skeleton on Data Load
数据加载时切换骨架屏
tsx
import { SkeletonComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function DataCard() {
const [loading, setLoading] = React.useState(true);
const [content, setContent] = React.useState('');
React.useEffect(() => {
setTimeout(() => {
setContent('Data loaded successfully');
setLoading(false);
}, 2000);
}, []);
return (
<div>
{loading ? (
<SkeletonComponent width="80%" height="20px" />
) : (
<p>{content}</p>
)}
</div>
);
}
export default DataCard;tsx
import { SkeletonComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function DataCard() {
const [loading, setLoading] = React.useState(true);
const [content, setContent] = React.useState('');
React.useEffect(() => {
setTimeout(() => {
setContent('Data loaded successfully');
setLoading(false);
}, 2000);
}, []);
return (
<div>
{loading ? (
<SkeletonComponent width="80%" height="20px" />
) : (
<p>{content}</p>
)}
</div>
);
}
export default DataCard;Shimmer List with Pulse Effect
Pulse效果的列表微光骨架屏
tsx
import { SkeletonComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function ListSkeleton() {
return (
<ul style={{ listStyle: 'none', padding: 0 }}>
{[1, 2, 3].map((i) => (
<li key={i} style={{ display: 'flex', gap: '10px', marginBottom: '12px' }}>
<SkeletonComponent shape="Circle" width="40px" shimmerEffect="Pulse" />
<div style={{ flex: 1 }}>
<SkeletonComponent width="70%" height="14px" shimmerEffect="Pulse" />
<br />
<SkeletonComponent width="45%" height="12px" shimmerEffect="Pulse" />
</div>
</li>
))}
</ul>
);
}
export default ListSkeleton;tsx
import { SkeletonComponent } from '@syncfusion/ej2-react-notifications';
import * as React from 'react';
function ListSkeleton() {
return (
<ul style={{ listStyle: 'none', padding: 0 }}>
{[1, 2, 3].map((i) => (
<li key={i} style={{ display: 'flex', gap: '10px', marginBottom: '12px' }}>
<SkeletonComponent shape="Circle" width="40px" shimmerEffect="Pulse" />
<div style={{ flex: 1 }}>
<SkeletonComponent width="70%" height="14px" shimmerEffect="Pulse" />
<br />
<SkeletonComponent width="45%" height="12px" shimmerEffect="Pulse" />
</div>
</li>
))}
</ul>
);
}
export default ListSkeleton;Key Props at a Glance
核心属性速览
| Prop | Type | Default | Purpose |
|---|---|---|---|
| | | Skeleton shape variant |
| | | Width; required for Circle/Square |
| | | Height; used for Rectangle/Text |
| | | Animation style |
| | | Show/hide skeleton |
| | | Custom CSS class(es) |
| | | ARIA label for accessibility |
| | | Right-to-left rendering |
| | | Persist state across reloads |
| 属性 | 类型 | 默认值 | 作用 |
|---|---|---|---|
| | | Skeleton形状变体 |
| | | 宽度;圆形/正方形必填 |
| | | 高度;矩形/文本使用 |
| | | 动画样式 |
| | | 展示/隐藏骨架屏 |
| | | 自定义CSS类 |
| | | 无障碍ARIA标签 |
| | | 从右到左渲染 |
| | | 跨刷新持久化状态 |
Syncfusion React Spinner
Syncfusion React Spinner
A skill for implementing the Syncfusion React Spinner — a load indicator that blocks user interaction with a target element while an operation is in progress.
用于实现Syncfusion React Spinner的技能说明——这是一个加载指示器,可在操作进行中阻止用户与目标元素交互。
Documentation
文档
Getting Started
快速开始
📄 Read: references/spinner-getting-started.md
- Installation:
npm install @syncfusion/ej2-react-popups - CSS theme imports (ej2-base + ej2-react-popups)
- Basic functional and class component patterns
- →
createSpinnerworkflowshowSpinner - Show/hide control
- Full-page overlay spinner
- Troubleshooting missing styles and TypeScript errors
📄 阅读: references/spinner-getting-started.md
- 安装:
npm install @syncfusion/ej2-react-popups - CSS主题导入(ej2-base + ej2-react-popups)
- 基础函数组件与类组件模式
- →
createSpinner工作流showSpinner - 显示/隐藏控制
- 全屏覆盖spinner
- 样式缺失与TypeScript错误排查
Spinner Features
Spinner功能
📄 Read: references/spinner-features.md
- Global spinner configuration with
setSpinner - All values (Material, Bootstrap5, Fluent2, etc.)
SpinnerType - Spinner size via property
width - Label text alongside spinner
- Custom HTML template support
- Show/hide toggle patterns
- Multiple spinners on one page
- Async data fetching with cleanup
finally - React state + spinner synchronization
- Spinner inside cards and modals
📄 阅读: references/spinner-features.md
- 通过全局配置spinner
setSpinner - 所有取值(Material、Bootstrap5、Fluent2等)
SpinnerType - 通过属性设置spinner尺寸
width - spinner旁的标签文本
- 自定义HTML模板支持
- 显示/隐藏切换模式
- 单页多spinner实现
- 带清理的异步数据请求
finally - React状态与spinner同步
- 卡片和模态框内的spinner
API Reference
API参考
📄 Read: references/spinner-api.md
- — full signature and params
createSpinner(args: SpinnerArgs) - — signature
showSpinner(container: HTMLElement) - — signature
hideSpinner(container: HTMLElement) - — signature
setSpinner(args: SetSpinnerArgs) - interface (target, width, label, cssClass, template, type)
SpinnerArgs - interface (template, cssClass, type)
SetSpinnerArgs - All 11 values
SpinnerType - CSS import paths per theme
- Common invalid API gotchas
📄 阅读: references/spinner-api.md
- —— 完整签名与参数
createSpinner(args: SpinnerArgs) - —— 签名
showSpinner(container: HTMLElement) - —— 签名
hideSpinner(container: HTMLElement) - —— 签名
setSpinner(args: SetSpinnerArgs) - 接口(target、width、label、cssClass、template、type)
SpinnerArgs - 接口(template、cssClass、type)
SetSpinnerArgs - 所有11种取值
SpinnerType - 各主题的CSS导入路径
- 常见API使用误区
Customization
自定义
📄 Read: references/spinner-customization.md
- for CSS hook customization
cssClass - for spinner icon sizing
width - for custom HTML animations
template - for global defaults
setSpinner - Overriding spinner colors via CSS
- Label positioning with CSS
- Overlay backdrop customization
- Theme-specific type mapping
- Responsive spinner patterns
📄 阅读: references/spinner-customization.md
- 用于CSS自定义钩子
cssClass - 用于调整spinner图标大小
width - 用于自定义HTML动画
template - 用于设置全局默认值
setSpinner - 通过CSS覆盖spinner颜色
- 通过CSS调整标签位置
- 覆盖层背景自定义
- 主题对应类型映射
- 响应式spinner模式
Accessibility
无障碍访问
📄 Read: references/spinner-accessibility.md
- on the loading region
aria-busy - region for screen reader announcements
aria-live - for high contrast displays
type: 'HighContrast' - Keyboard accessibility (trigger focus, return focus)
- Focus management patterns
- Complete accessible spinner pattern
- WCAG 2.1 compliance checklist
📄 阅读: references/spinner-accessibility.md
- 加载区域的属性
aria-busy - 屏幕阅读器播报的区域
aria-live - 适配高对比度显示
type: 'HighContrast' - 键盘无障碍(触发焦点、返回焦点)
- 焦点管理模式
- 完整的无障碍spinner实现模式
- WCAG 2.1合规检查清单
Quick Start
快速开始
Minimal Spinner (Functional Component)
最简Spinner实现(函数组件)
tsx
import { createSpinner, showSpinner } from '@syncfusion/ej2-react-popups';
import * as React from 'react';
import { useEffect } from 'react';
import './App.css';
function App() {
useEffect(() => {
createSpinner({
target: document.getElementById('container') as HTMLElement
});
showSpinner(document.getElementById('container') as HTMLElement);
}, []);
return (
<div id="container" style={{ height: '200px' }} />
);
}
export default App;tsx
import { createSpinner, showSpinner } from '@syncfusion/ej2-react-popups';
import * as React from 'react';
import { useEffect } from 'react';
import './App.css';
function App() {
useEffect(() => {
createSpinner({
target: document.getElementById('container') as HTMLElement
});
showSpinner(document.getElementById('container') as HTMLElement);
}, []);
return (
<div id="container" style={{ height: '200px' }} />
);
}
export default App;Spinner with Show/Hide Toggle
带显示/隐藏切换的Spinner
tsx
import { createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-react-popups';
import { useEffect, useRef, useState } from 'react';
function DataLoader() {
const ref = useRef<HTMLDivElement>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (ref.current) {
createSpinner({ target: ref.current, label: 'Loading...' });
}
}, []);
const load = async () => {
setLoading(true);
showSpinner(ref.current as HTMLElement);
try {
await fetchData();
} finally {
hideSpinner(ref.current as HTMLElement);
setLoading(false);
}
};
return (
<div>
<button onClick={load} disabled={loading}>Load Data</button>
<div ref={ref} style={{ height: '200px', position: 'relative' }} />
</div>
);
}tsx
import { createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-react-popups';
import { useEffect, useRef, useState } from 'react';
function DataLoader() {
const ref = useRef<HTMLDivElement>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (ref.current) {
createSpinner({ target: ref.current, label: 'Loading...' });
}
}, []);
const load = async () => {
setLoading(true);
showSpinner(ref.current as HTMLElement);
try {
await fetchData();
} finally {
hideSpinner(ref.current as HTMLElement);
setLoading(false);
}
};
return (
<div>
<button onClick={load} disabled={loading}>Load Data</button>
<div ref={ref} style={{ height: '200px', position: 'relative' }} />
</div>
);
}Global Spinner Type
全局Spinner类型配置
tsx
import { setSpinner } from '@syncfusion/ej2-react-popups';
// Call BEFORE any createSpinner — sets global default type
setSpinner({ type: 'Bootstrap5' });tsx
import { setSpinner } from '@syncfusion/ej2-react-popups';
// 在所有createSpinner调用前执行 —— 设置全局默认类型
setSpinner({ type: 'Bootstrap5' });Common Patterns
常用用法
Pattern 1: Async Fetch with Cleanup
模式1:带清理的异步请求
tsx
const fetchWithSpinner = async (container: HTMLElement) => {
showSpinner(container);
try {
const data = await fetch('/api/data').then(r => r.json());
return data;
} finally {
hideSpinner(container); // Always hide, even on error
}
};tsx
const fetchWithSpinner = async (container: HTMLElement) => {
showSpinner(container);
try {
const data = await fetch('/api/data').then(r => r.json());
return data;
} finally {
hideSpinner(container); // 即使报错也始终隐藏
}
};Pattern 2: React State Sync
模式2:React状态同步
tsx
useEffect(() => {
if (!ref.current) return;
if (isLoading) {
showSpinner(ref.current);
} else {
hideSpinner(ref.current);
}
}, [isLoading]);tsx
useEffect(() => {
if (!ref.current) return;
if (isLoading) {
showSpinner(ref.current);
} else {
hideSpinner(ref.current);
}
}, [isLoading]);Pattern 3: Full-Page Loading
模式3:全屏加载
tsx
useEffect(() => {
createSpinner({ target: document.body, label: 'Initializing...' });
showSpinner(document.body);
initializeApp().finally(() => hideSpinner(document.body));
}, []);tsx
useEffect(() => {
createSpinner({ target: document.body, label: 'Initializing...' });
showSpinner(document.body);
initializeApp().finally(() => hideSpinner(document.body));
}, []);Pattern 4: Spinner with Custom Type
模式4:自定义类型Spinner
tsx
createSpinner({
target: el,
type: 'Fluent2',
width: '40px',
label: 'Processing...',
cssClass: 'my-overlay'
});tsx
createSpinner({
target: el,
type: 'Fluent2',
width: '40px',
label: 'Processing...',
cssClass: 'my-overlay'
});Key API Quick Reference
核心API速览
| Function | Signature | Purpose |
|---|---|---|
| | Initialize spinner on DOM element |
| | Show an existing spinner |
| | Hide a visible spinner |
| | Set global defaults for all spinners |
SpinnerArgs properties: (required), , , , ,
targetwidthlabelcssClasstemplatetypeSpinnerType values: | | | | | | | | | |
'Material''Material3''Fabric''Bootstrap''Bootstrap4''Bootstrap5''HighContrast''Tailwind''Tailwind3''Fluent''Fluent2'| 函数 | 签名 | 作用 |
|---|---|---|
| | 在DOM元素上初始化spinner |
| | 展示已存在的spinner |
| | 隐藏可见的spinner |
| | 为所有spinner设置全局默认值 |
SpinnerArgs属性: (必填)、、、、、
targetwidthlabelcssClasstemplatetypeSpinnerType取值: | | | | | | | | | |
'Material''Material3''Fabric''Bootstrap''Bootstrap4''Bootstrap5''HighContrast''Tailwind''Tailwind3''Fluent''Fluent2'Critical Rules
重要规则
- ❌ No class —
SpinnerComponentdoes NOT existimport { SpinnerComponent } - ✅ Only use: ,
createSpinner,showSpinner,hideSpinnersetSpinner - ❌ Do NOT use: ,
color,size,visibleas SpinnerArgs — they don't existisLoading - ✅ Valid SpinnerArgs: ,
target,width,label,cssClass,templatetype - ⚠️ Call BEFORE
createSpinner— order mattersshowSpinner - ⚠️ Put spinner logic in — the DOM element must exist before calling createSpinner
useEffect - ✅ Always call in
hideSpinner— prevents stuck loading statesfinally
- ❌ 不存在类 —— 没有
SpinnerComponent这种用法import { SpinnerComponent } - ✅ 仅可使用: 、
createSpinner、showSpinner、hideSpinnersetSpinner - ❌ 禁止使用: 、
color、size、visible作为SpinnerArgs参数 —— 这些属性不存在isLoading - ✅ 有效的SpinnerArgs参数: 、
target、width、label、cssClass、templatetype - ⚠️ 先调用再调用
createSpinner—— 顺序很重要showSpinner - ⚠️ 将spinner逻辑放在中 —— 调用createSpinner前必须确保DOM元素已存在
useEffect - ✅ 始终在中调用
finally—— 避免加载状态卡住hideSpinner
Troubleshooting
问题排查
| Issue | Solution |
|---|---|
| Spinner not showing | Ensure |
| Spinner stays visible | Call |
| No animation | Verify both |
| TypeScript error | Cast: |
| Spinner outside bounds | Add |
| Wrong theme | Set |
| 问题 | 解决方案 |
|---|---|
| Spinner不展示 | 确保 |
| Spinner一直可见 | 在 |
| 无动画 | 确认已导入 |
| TypeScript报错 | 强制类型转换: |
| Spinner超出边界 | 为目标元素添加 |
| 主题不匹配 | 将 |
Related Components
相关组件
- Progress Bar — For determinate progress with a percentage
- Skeleton — For content placeholder/shimmer loading patterns
- Toast — For non-blocking loading notifications
- Dialog — For modal loading states that require user acknowledgment
- Progress Bar —— 用于带百分比的确定性进度展示
- Skeleton —— 用于内容占位符/微光加载模式
- Toast —— 用于非阻塞加载通知
- Dialog —— 用于需要用户确认的模态加载状态
Resources
资源
- Official Docs: https://ej2.syncfusion.com/react/documentation/spinner/
- Getting Started: https://ej2.syncfusion.com/react/documentation/spinner/getting-started
- npm Package: @syncfusion/ej2-react-popups
undefined