自动安装
使用以下命令之一自动安装组件,根据你的包管理器选择:
npx tofu-ui-cli@latest add circular-progress
手动安装 (可选)
注意
如果你使用手动安装,将无法获取更新
如果你需要手动安装,请在项目目录中创建如下路径文件:
components/ui/tofu/circular-progress.tsx然后复制此代码:
import * as React from 'react';
/**
* TofuUI CircularProgress 数据Icon
* @author shuakami
* @version 1.0.0
* @copyright ByteFreeze&TofuUI
* ️ 🤔移植自@material-ui/core/CircularProgress 🐳支持传入style
*/
/**
* ⚠️免责声明:
* 本组件是基于 @material-ui/core 的 CircularProgress 组件进行的本地化和修改。
* 本组件的初始代码来源于使用 MIT 许可证的开源项目 @material-ui/core。
* 本组件的所有修改和自定义实现均由<shuakami>完成,与原始作者或原项目无关。
* 对于因使用本组件可能引起的任何形式的损害或法律问题,本人不承担任何责任。
* 使用者应在遵守适用法律和规定的前提下使用本组件。
*
* Disclaimer:
* This component is a locally modified and optimized version of the CircularProgress component from @material-ui/core.
* The initial code of this component is based on the open-source project @material-ui/core, which is licensed under the MIT License.
* All modifications and custom implementations of this component have been made by <shuakami> and are not associated with the original authors or the original project.
* I am not responsible for any form of damage or legal issues that may arise from the use of this component.
* Users should use this component in compliance with applicable laws and regulations.
*/
interface CircularProgressProps {
color?: 'primary' | 'secondary' | 'inherit';
disableShrink?: boolean;
size?: number | string;
thickness?: number;
value?: number;
variant?: 'determinate' | 'indeterminate' | 'static';
style?: React.CSSProperties;
}
const SIZE = 44;
const CircularProgress: React.FC<CircularProgressProps> = ({
color = 'primary',
disableShrink = false,
size = 40,
thickness = 3.6,
value = 0,
variant = 'indeterminate',
style
}) => {
const circleStyle: React.CSSProperties = {};
const rootStyle: React.CSSProperties = {};
const rootProps: { 'aria-valuenow'?: number } = {};
if (variant === 'determinate' || variant === 'static') {
const circumference = 2 * Math.PI * ((SIZE - thickness) / 2);
circleStyle.strokeDasharray = `${circumference.toFixed(3)}px`;
rootProps['aria-valuenow'] = Math.round(value);
circleStyle.strokeDashoffset = `${((100 - value) / 100 * circumference).toFixed(3)}px`;
rootStyle.transform = 'rotate(-90deg)';
}
return (
<div
style={{
width: size,
height: size,
color: color === 'primary' ? '#0072F5' : color === 'secondary' ? '#F50057' : 'inherit',
display: 'inline-block',
...style,
...rootStyle
}}
role="progressbar"
{...rootProps}
>
<svg
style={{
display: 'block',
width: '100%',
height: '100%'
}}
viewBox={`${SIZE / 2} ${SIZE / 2} ${SIZE} ${SIZE}`}
>
<circle
style={{
stroke: 'currentColor',
strokeLinecap: 'butt',
fill: 'none',
strokeWidth: thickness,
...circleStyle
}}
cx={SIZE}
cy={SIZE}
r={(SIZE - thickness) / 2}
/>
</svg>
</div>
);
};
export default CircularProgress;导入组件
import CircularProgress from '@tofu-ui/circular-progress';使用组件
<CircularProgress
color="primary"
size={40}
thickness={3.6}
value={75}
variant="determinate"
/>搭配DataTable使用
使用CircularProgress组件可以有效地展示加载状态或进度。
产品使用情况
流量
818.94 MB / 100 GB
存储空间
15.6 GB / 200 GB
参数说明
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| color | 'primary' | 'secondary' | 'inherit' | 'primary' | 圆环的颜色 |
| disableShrink | boolean | false | 如果设置为true,将禁止圆环动画中的缩放效果 |
| size | number | string | 40 | 圆环的大小,可为数值或字符串,如 '40px' |
| thickness | number | 3.6 | 圆环的线条厚度 |
| value | number | 0 | 当 variant 为 'determinate' 或 'static' 时,表示进度的数值 |
| variant | 'determinate' | 'indeterminate' | 'static' | 'indeterminate' | 圆环的显示类型 |
| style | React.CSSProperties | undefined | 可选,直接应用于组件的样式对象 |
免责声明
本组件是基于 @material-ui/core 的 CircularProgress 组件进行的本地化和修改。初始代码来源于使用 MIT 许可证的开源项目 @material-ui/core。所有的修改和自定义实现均由 TofuUI 团队完成,与原始作者或原项目无关。
对于因使用本组件可能引起的任何形式的损害或法律问题,TofuUI 团队不承担任何责任。使用者应在遵守适用法律和规定的前提下使用本组件。