Commit 8f457bea authored by chenshouchao's avatar chenshouchao

feat: 丰富loading组件使用方法

parent 036c942f
// 局部loading组件 挂载在目标块下,目标块最少要添加一个position: relative; 或者absolute // 局部loading组件
// 使用方法1 用一个div包裹children,在children上加一个蒙层和loading
// <MyCircularProgress loading={loading}>children</MyCircularProgress>
// 使用方法2 挂载在目标块下,目标块最少要添加一个position: relative; 或者absolute
// <MyCircularProgress loading={loading}/>
import CircularProgress from "@mui/material/CircularProgress"; import CircularProgress from "@mui/material/CircularProgress";
type IMyCircularProgressProps = { type IMyCircularProgressProps = {
loading: boolean; loading: boolean;
children?: React.ReactNode;
minHeight?: string; minHeight?: string;
maxHeight?: string; maxHeight?: string;
zIndex?: number; zIndex?: number;
...@@ -14,18 +21,56 @@ const MyCircularProgress = (props: IMyCircularProgressProps) => { ...@@ -14,18 +21,56 @@ const MyCircularProgress = (props: IMyCircularProgressProps) => {
minHeight = "none", minHeight = "none",
maxHeight = "100vh", maxHeight = "100vh",
zIndex = "100", zIndex = "100",
children,
} = props; } = props;
if (loading) { if (loading) {
if (children) {
return ( return (
<div <div
style={{ style={{
minHeight: minHeight, position: "relative",
}}
>
<div
style={{
width: "100%", width: "100%",
height: "100%", height: "100%",
position: "absolute", position: "absolute",
top: 0, top: 0,
opacity: 0.6,
background: "#fff",
zIndex: zIndex, zIndex: zIndex,
}} }}
></div>
<div
style={{
width: "100%",
height: "100%",
display: "flex",
justifyContent: "center",
alignItems: "center",
position: "absolute",
top: 0,
zIndex: zIndex,
maxHeight: maxHeight,
}}
>
<CircularProgress></CircularProgress>
</div>
{children}
</div>
);
} else {
return (
<div
style={{
width: "100%",
height: "100%",
position: "absolute",
top: 0,
zIndex: zIndex,
minHeight: minHeight,
}}
> >
<div <div
style={{ style={{
...@@ -41,16 +86,17 @@ const MyCircularProgress = (props: IMyCircularProgressProps) => { ...@@ -41,16 +86,17 @@ const MyCircularProgress = (props: IMyCircularProgressProps) => {
style={{ style={{
width: "100%", width: "100%",
height: "100%", height: "100%",
maxHeight: maxHeight,
display: "flex", display: "flex",
justifyContent: "center", justifyContent: "center",
alignItems: "center", alignItems: "center",
maxHeight: maxHeight,
}} }}
> >
<CircularProgress></CircularProgress> <CircularProgress></CircularProgress>
</div> </div>
</div> </div>
); );
}
} else { } else {
return null; return null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment