Loading...
Loading...
Compare original and translation side by side
ProgressBarComponentProgressBarComponentimport { ProgressBarComponent } from '@syncfusion/ej2-react-progressbar';
function App() {
return (
<div>
{/* Linear Determinate Progress Bar */}
<ProgressBarComponent
id="linear"
type="Linear"
height="60"
value={75}
animation={{
enable: true,
duration: 2000,
delay: 0
}}
/>
{/* Circular Progress Bar */}
<ProgressBarComponent
id="circular"
type="Circular"
height="160px"
value={60}
/>
{/* Indeterminate Loading Spinner */}
<ProgressBarComponent
id="indeterminate"
type="Linear"
height="60"
isIndeterminate={true}
animation={{
enable: true,
duration: 2000,
delay: 0
}}
/>
</div>
);
}
export default App;import { ProgressBarComponent } from '@syncfusion/ej2-react-progressbar';
function App() {
return (
<div>
{/* 线性确定进度条 */}
<ProgressBarComponent
id="linear"
type="Linear"
height="60"
value={75}
animation={{
enable: true,
duration: 2000,
delay: 0
}}
/>
{/* 圆形进度条 */}
<ProgressBarComponent
id="circular"
type="Circular"
height="160px"
value={60}
/>
{/* 不确定加载旋转器 */}
<ProgressBarComponent
id="indeterminate"
type="Linear"
height="60"
isIndeterminate={true}
animation={{
enable: true,
duration: 2000,
delay: 0
}}
/>
</div>
);
}
export default App;<ProgressBarComponent
id="upload"
type="Linear"
value={uploadPercentage}
showProgressValue={true}
progressValueFormat="N0 '%'"
/><ProgressBarComponent
id="upload"
type="Linear"
value={uploadPercentage}
showProgressValue={true}
progressValueFormat="N0 '%'"
/><ProgressBarComponent
id="spinner"
type="Circular"
isIndeterminate={true}
height="100px"
/><ProgressBarComponent
id="spinner"
type="Circular"
isIndeterminate={true}
height="100px"
/><ProgressBarComponent
id="buffer"
type="Linear"
value={40}
secondaryProgress={80}
height="60"
/><ProgressBarComponent
id="buffer"
type="Linear"
value={40}
secondaryProgress={80}
height="60"
/><ProgressBarComponent
id="task"
type="Linear"
value={taskCompletionPercentage}
showProgressValue={true}
animation={{
enable: true,
duration: 1500
}}
/><ProgressBarComponent
id="task"
type="Linear"
value={taskCompletionPercentage}
showProgressValue={true}
animation={{
enable: true,
duration: 1500
}}
/>| Prop | Type | Default | Purpose |
|---|---|---|---|
| string | - | Unique identifier for component |
| "Linear" | "Circular" | "Semicircle" | "Linear" | Shape of progress bar |
| number | 0 | Current progress value (0-100) |
| number | 0 | Secondary/buffer progress value |
| boolean | false | Indeterminate/loading mode |
| string | "100%" | Height of progress bar (CSS value) |
| string | "100%" | Width of progress bar (CSS value) |
| boolean | false | Display percentage text |
| 属性 | 类型 | 默认值 | 用途 |
|---|---|---|---|
| string | - | 组件的唯一标识符 |
| "Linear" | "Circular" | "Semicircle" | "Linear" | 进度条的形状 |
| number | 0 | 当前进度值(0-100) |
| number | 0 | 次级/缓冲进度值 |
| boolean | false | 不确定/加载模式 |
| string | "100%" | 进度条高度(CSS值) |
| string | "100%" | 进度条宽度(CSS值) |
| boolean | false | 显示百分比文本 |
| Prop | Type | Default | Purpose |
|---|---|---|---|
| AnimationModel | - | Animation config: |
| string | - | Color for progress fill (CSS color) |
| string | - | Color for track background |
| number | 4 | Progress bar thickness (pixels) |
| number | 4 | Track thickness (pixels) |
| boolean | false | Striped pattern appearance |
| boolean | false | Gradient fill effect |
| string | - | Custom CSS class for styling |
| 属性 | 类型 | 默认值 | 用途 |
|---|---|---|---|
| AnimationModel | - | 动画配置: |
| string | - | 进度填充颜色(CSS颜色) |
| string | - | 轨道背景颜色 |
| number | 4 | 进度条厚度(像素) |
| number | 4 | 轨道厚度(像素) |
| boolean | false | 条纹图案外观 |
| boolean | false | 渐变填充效果 |
| string | - | 自定义样式的CSS类 |
| Prop | Type | Default | Purpose |
|---|---|---|---|
| "Round" | "Auto" | "Auto" | Corner style for ends |
| boolean | false | Right-to-left layout |
| boolean | false | Pie view for circular type |
| boolean | false | Segmented progress rendering |
| number | 1 | Number of segments |
| RangeColorModel[] | - | Colors for different ranges |
| number | 0 | Minimum progress value |
| number | 100 | Maximum progress value |
| 属性 | 类型 | 默认值 | 用途 |
|---|---|---|---|
| "Round" | "Auto" | "Auto" | 两端的边角样式 |
| boolean | false | 从右到左布局 |
| boolean | false | 圆形进度条的饼图视图 |
| boolean | false | 分段进度渲染 |
| number | 1 | 分段数量 |
| RangeColorModel[] | - | 不同范围的颜色 |
| number | 0 | 最小进度值 |
| number | 100 | 最大进度值 |
| Prop | Type | Default | Purpose |
|---|---|---|---|
| string | "N0 '%'" | Format for value display (e.g., "N2 '%'") |
| boolean | true | Show label on the track |
| FontModel | - | Font styling for label |
| 属性 | 类型 | 默认值 | 用途 |
|---|---|---|---|
| string | "N0 '%'" | 值显示格式(例如:"N2 '%'") |
| boolean | true | 在轨道上显示标签 |
| FontModel | - | 标签的字体样式 |
const [uploadProgress, setUploadProgress] = useState(0);
<ProgressBarComponent
type="Linear"
value={uploadProgress}
showProgressValue={true}
progressValueFormat="N0 '%'"
height="30"
animation={{ enable: true, duration: 500 }}
/>secondaryProgressconst [uploadProgress, setUploadProgress] = useState(0);
<ProgressBarComponent
type="Linear"
value={uploadProgress}
showProgressValue={true}
progressValueFormat="N0 '%'"
height="30"
animation={{ enable: true, duration: 500 }}
/>secondaryProgress<ProgressBarComponent
type="Circular"
isIndeterminate={true}
height="100px"
animation={{ enable: true, duration: 2000 }}
/>isIndeterminate={true}<ProgressBarComponent
type="Circular"
isIndeterminate={true}
height="100px"
animation={{ enable: true, duration: 2000 }}
/>isIndeterminate={true}const [processProgress, setProcessProgress] = useState(0);
const totalItems = 100;
useEffect(() => {
processItems().then(processed => {
setProcessProgress((processed / totalItems) * 100);
});
}, []);
<ProgressBarComponent
type="Linear"
value={processProgress}
showProgressValue={true}
height="30"
/>const [processProgress, setProcessProgress] = useState(0);
const totalItems = 100;
useEffect(() => {
processItems().then(processed => {
setProcessProgress((processed / totalItems) * 100);
});
}, []);
<ProgressBarComponent
type="Linear"
value={processProgress}
showProgressValue={true}
height="30"
/>const [processedItems, setProcessedItems] = useState(30);
const [queuedItems, setQueuedItems] = useState(75);
const totalItems = 100;
<ProgressBarComponent
type="Linear"
value={(processedItems / totalItems) * 100}
secondaryProgress={(queuedItems / totalItems) * 100}
height="30"
/>const [processedItems, setProcessedItems] = useState(30);
const [queuedItems, setQueuedItems] = useState(75);
const totalItems = 100;
<ProgressBarComponent
type="Linear"
value={(processedItems / totalItems) * 100}
secondaryProgress={(queuedItems / totalItems) * 100}
height="30"
/>const steps = ['Validation', 'Processing', 'Upload', 'Confirmation'];
const [currentStep, setCurrentStep] = useState(0);
const progress = ((currentStep + 1) / steps.length) * 100;
<ProgressBarComponent
type="Linear"
value={progress}
showProgressValue={true}
height="30"
/>
<div>
{steps.map((step, i) => (
<div key={i}>
{step} {i === currentStep ? '🔄' : i < currentStep ? '✓' : '⏳'}
</div>
))}
</div>const steps = ['验证', '处理', '上传', '确认'];
const [currentStep, setCurrentStep] = useState(0);
const progress = ((currentStep + 1) / steps.length) * 100;
<ProgressBarComponent
type="Linear"
value={progress}
showProgressValue={true}
height="30"
/>
<div>
{steps.map((step, i) => (
<div key={i}>
{step} {i === currentStep ? '🔄' : i < currentStep ? '✓' : '⏳'}
</div>
))}
</div>import { useState, useEffect } from 'react';
import { ProgressBarComponent } from '@syncfusion/ej2-react-progressbar';
function ProgressManager() {
const [progress, setProgress] = useState(0);
const [isProcessing, setIsProcessing] = useState(false);
useEffect(() => {
if (!isProcessing) return;
const interval = setInterval(() => {
setProgress(prev => {
if (prev >= 100) {
setIsProcessing(false);
return 100;
}
return prev + Math.random() * 15;
});
}, 500);
return () => clearInterval(interval);
}, [isProcessing]);
return (
<div>
<ProgressBarComponent
type="Linear"
value={progress}
showProgressValue={true}
/>
<button
onClick={() => { setProgress(0); setIsProcessing(true); }}
disabled={isProcessing}
>
{isProcessing ? 'Processing...' : 'Start'}
</button>
</div>
);
}
export default ProgressManager;import { useState, useEffect } from 'react';
import { ProgressBarComponent } from '@syncfusion/ej2-react-progressbar';
function ProgressManager() {
const [progress, setProgress] = useState(0);
const [isProcessing, setIsProcessing] = useState(false);
useEffect(() => {
if (!isProcessing) return;
const interval = setInterval(() => {
setProgress(prev => {
if (prev >= 100) {
setIsProcessing(false);
return 100;
}
return prev + Math.random() * 15;
});
}, 500);
return () => clearInterval(interval);
}, [isProcessing]);
return (
<div>
<ProgressBarComponent
type="Linear"
value={progress}
showProgressValue={true}
/>
<button
onClick={() => { setProgress(0); setIsProcessing(true); }}
disabled={isProcessing}
>
{isProcessing ? '处理中...' : '开始'}
</button>
</div>
);
}
export default ProgressManager;// Real-time updates (no animation for smoothness)
animation={{ enable: false }}
// User interactions (quick feedback)
animation={{ enable: true, duration: 300, delay: 0 }}
// Page loads (smooth transition)
animation={{ enable: true, duration: 1500, delay: 0 }}
// Cascading effects (staggered)
animation={{ enable: true, duration: 1000, delay: 200 }}
// Loading spinners (continuous)
animation={{ enable: true, duration: 2000 }}// 实时更新(禁用动画以保证流畅性)
animation={{ enable: false }}
// 用户交互(快速反馈)
animation={{ enable: true, duration: 300, delay: 0 }}
// 页面加载(平滑过渡)
animation={{ enable: true, duration: 1500, delay: 0 }}
// 级联效果(交错动画)
animation={{ enable: true, duration: 1000, delay: 200 }}
// 加载旋转器(持续动画)
animation={{ enable: true, duration: 2000 }}function ConditionalProgress() {
const [state, setState] = useState('idle'); // idle | loading | success | error
const [value, setValue] = useState(0);
const getProgressType = () => {
if (state === 'loading') return 'Circular';
return 'Linear';
};
return (
<>
{state === 'loading' && (
<ProgressBarComponent
type={getProgressType()}
isIndeterminate={state === 'loading'}
height="100px"
/>
)}
{state === 'success' && (
<div style={{ color: 'green' }}>✓ Complete</div>
)}
{state === 'error' && (
<div style={{ color: 'red' }}>✗ Error occurred</div>
)}
</>
);
}
export default ConditionalProgress;function ConditionalProgress() {
const [state, setState] = useState('idle'); // idle | loading | success | error
const [value, setValue] = useState(0);
const getProgressType = () => {
if (state === 'loading') return 'Circular';
return 'Linear';
};
return (
<>
{state === 'loading' && (
<ProgressBarComponent
type={getProgressType()}
isIndeterminate={state === 'loading'}
height="100px"
/>
)}
{state === 'success' && (
<div style={{ color: 'green' }}>✓ 完成</div>
)}
{state === 'error' && (
<div style={{ color: 'red' }}>✗ 发生错误</div>
)}
</>
);
}
export default ConditionalProgress;function ProgressWithEvents() {
const handleStart = () => {
console.log('Progress started');
analytics.track('progress_started');
};
const handleComplete = () => {
console.log('Progress completed');
analytics.track('progress_completed');
showNotification('Task completed!');
};
const handleValueChange = (args) => {
console.log(`Progress: ${args.value}%`);
// Milestone tracking
if (args.value === 50) {
analytics.track('progress_midpoint');
}
};
return (
<ProgressBarComponent
type="Linear"
value={75}
progressStart={handleStart}
progressComplete={handleComplete}
valueChanged={handleValueChange}
/>
);
}
export default ProgressWithEvents;function ProgressWithEvents() {
const handleStart = () => {
console.log('进度已开始');
analytics.track('progress_started');
};
const handleComplete = () => {
console.log('进度已完成');
analytics.track('progress_completed');
showNotification('任务已完成!');
};
const handleValueChange = (args) => {
console.log(`进度:${args.value}%`);
// 里程碑跟踪
if (args.value === 50) {
analytics.track('progress_midpoint');
}
};
return (
<ProgressBarComponent
type="Linear"
value={75}
progressStart={handleStart}
progressComplete={handleComplete}
valueChanged={handleValueChange}
/>
);
}
export default ProgressWithEvents;function ResponsiveProgress() {
const [isMobile, setIsMobile] = useState(window.innerWidth < 768);
useEffect(() => {
const handleResize = () => setIsMobile(window.innerWidth < 768);
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return (
<ProgressBarComponent
type={isMobile ? 'Semicircle' : 'Linear'}
value={65}
height={isMobile ? '100px' : '40'}
showProgressValue={true}
/>
);
}
export default ResponsiveProgress;function ResponsiveProgress() {
const [isMobile, setIsMobile] = useState(window.innerWidth < 768);
useEffect(() => {
const handleResize = () => setIsMobile(window.innerWidth < 768);
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return (
<ProgressBarComponent
type={isMobile ? 'Semicircle' : 'Linear'}
value={65}
height={isMobile ? '100px' : '40'}
showProgressValue={true}
/>
);
}
export default ResponsiveProgress;async function uploadWithRetry(file, maxRetries = 3) {
const [attempts, setAttempts] = useState(0);
const [progress, setProgress] = useState(0);
const [error, setError] = useState(null);
for (let i = 0; i < maxRetries; i++) {
try {
setAttempts(i + 1);
const result = await uploadFile(file, (p) => setProgress(p));
return result;
} catch (err) {
if (i === maxRetries - 1) {
setError(`Failed after ${maxRetries} attempts`);
throw err;
}
// Retry with exponential backoff
await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
}
}
}async function uploadWithRetry(file, maxRetries = 3) {
const [attempts, setAttempts] = useState(0);
const [progress, setProgress] = useState(0);
const [error, setError] = useState(null);
for (let i = 0; i < maxRetries; i++) {
try {
setAttempts(i + 1);
const result = await uploadFile(file, (p) => setProgress(p));
return result;
} catch (err) {
if (i === maxRetries - 1) {
setError(`尝试${maxRetries}次后失败`);
throw err;
}
// 指数退避重试
await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
}
}
}import { useQuery } from '@tanstack/react-query';
function DataProcessing() {
const { data, isLoading, progress } = useQuery({
queryKey: ['processData'],
queryFn: async ({ signal }) => {
// Process with progress tracking
}
});
return (
<ProgressBarComponent
isIndeterminate={isLoading}
value={progress || 0}
/>
);
}import { useQuery } from '@tanstack/react-query';
function DataProcessing() {
const { data, isLoading, progress } = useQuery({
queryKey: ['processData'],
queryFn: async ({ signal }) => {
// 带进度跟踪的处理逻辑
}
});
return (
<ProgressBarComponent
isIndeterminate={isLoading}
value={progress || 0}
/>
);
}import { useSelector, useDispatch } from 'react-redux';
function ReduxProgress() {
const { progress, isLoading } = useSelector(state => state.upload);
const dispatch = useDispatch();
return (
<ProgressBarComponent
value={progress}
isIndeterminate={isLoading}
progressComplete={() => dispatch(resetProgress())}
/>
);
}import { useSelector, useDispatch } from 'react-redux';
function ReduxProgress() {
const { progress, isLoading } = useSelector(state => state.upload);
const dispatch = useDispatch();
return (
<ProgressBarComponent
value={progress}
isIndeterminate={isLoading}
progressComplete={() => dispatch(resetProgress())}
/>
);
}