React Admin - 如何创建一个大的模式窗口
我在 React-Admin 中打开一个对话框,供用户选择图像。问题是我希望这个对话框占据大部分屏幕,但 React Admin 使用一个名为 MuiDialog-paperWidthSm 的类打开该模式。这将宽度限制为 600px,并且 fullWidth 属性的应用不会影响这一点。
我尝试设置自定义属性,虽然这会增加模式的内部尺寸,但会导致水平滚动而不是更宽的窗口。
这是模态组件:
import React from "react";
import { Button, Toolbar, useGetList } from "react-admin";
import { makeStyles } from "@material-ui/core/styles";
import IconClose from "@material-ui/icons/CloseSharp";
import Dialog from "@material-ui/core/Dialog";
import DialogTitle from "@material-ui/core/DialogTitle";
import DialogContent from "@material-ui/core/DialogContent";
import DialogActions from "@material-ui/core/DialogActions";
import ArcImageGrid from "../arcimages/ArcImageGrid";
const CustomToolbar = (props) => (
<Toolbar {...props} className={useStyles().customToolbar}></Toolbar>
);
const useStyles = makeStyles({
button: {
marginLeft: "20px",
height: "100%",
marginTop: "1.25em",
minWidth: "200px"
},
closeButton: {
color: "#000000"
},
customToolbar: {
display: "flex",
justifyContent: "space-between",
backgroundColor: "white",
margin: "0px",
padding: "0px",
borderBottom: "1px solid #ECEFF1"
},
customFooter: {
backgroundColor: "#ECEFF1",
borderTop: "1px solid #BBC1C4"
},
arcEditButton: {
color: "#585858",
borderColor: "#585858",
marginRight: "1em"
},
modalWindow: {
maxWidth: "1400px !important",
minWidth: "1400px !important"
}
});
const ImageSelectionModal = ({ handleCloseClick, showDialog }) => {
const handleSaveClick = () => {};
const { data, loading, error } = useGetList("arcimage");
return (
<Dialog
open={showDialog}
onClose={handleCloseClick}
aria-label="Add Media"
className={useStyles().modalWindow}
fullWidth
>
<CustomToolbar className={useStyles().modalWindow}>
<DialogTitle
styles={{ justifyContent: "space-between" }}
className={useStyles().modalWindow}
>
Add Media
</DialogTitle>
<Button onClick={handleCloseClick}>
<IconClose className={useStyles().closeButton} />
</Button>
</CustomToolbar>
<DialogContent className={useStyles().modalWindow}>
{loading && <h2>Your images are loading</h2>}
{!loading && <ArcImageGrid imageData={data} />}
{error && <h2>There was an error loading your images</h2>}
</DialogContent>
<DialogActions className={useStyles().customFooter}>
<Button
label="Edit Image in Arc"
variant={"outlined"}
onClick={() => {}}
className={useStyles().arcEditButton}
/>
<Button label="Apply" variant={"outlined"} onClick={handleSaveClick} />
</DialogActions>
</Dialog>
);
};
export default ImageSelectionModal;
I open a dialog in React-Admin for the user to select an image. The issue is that I want this dialog to take up most of the screen but React Admin opens that modal with a class called MuiDialog-paperWidthSm. This limits the width to 600px and the application of the fullWidth property does not affect this.
I tried setting custom properties and while this increases the inner size of the modal, it results in horizontal scrolling instead of a wider window.
Here is the modal component:
import React from "react";
import { Button, Toolbar, useGetList } from "react-admin";
import { makeStyles } from "@material-ui/core/styles";
import IconClose from "@material-ui/icons/CloseSharp";
import Dialog from "@material-ui/core/Dialog";
import DialogTitle from "@material-ui/core/DialogTitle";
import DialogContent from "@material-ui/core/DialogContent";
import DialogActions from "@material-ui/core/DialogActions";
import ArcImageGrid from "../arcimages/ArcImageGrid";
const CustomToolbar = (props) => (
<Toolbar {...props} className={useStyles().customToolbar}></Toolbar>
);
const useStyles = makeStyles({
button: {
marginLeft: "20px",
height: "100%",
marginTop: "1.25em",
minWidth: "200px"
},
closeButton: {
color: "#000000"
},
customToolbar: {
display: "flex",
justifyContent: "space-between",
backgroundColor: "white",
margin: "0px",
padding: "0px",
borderBottom: "1px solid #ECEFF1"
},
customFooter: {
backgroundColor: "#ECEFF1",
borderTop: "1px solid #BBC1C4"
},
arcEditButton: {
color: "#585858",
borderColor: "#585858",
marginRight: "1em"
},
modalWindow: {
maxWidth: "1400px !important",
minWidth: "1400px !important"
}
});
const ImageSelectionModal = ({ handleCloseClick, showDialog }) => {
const handleSaveClick = () => {};
const { data, loading, error } = useGetList("arcimage");
return (
<Dialog
open={showDialog}
onClose={handleCloseClick}
aria-label="Add Media"
className={useStyles().modalWindow}
fullWidth
>
<CustomToolbar className={useStyles().modalWindow}>
<DialogTitle
styles={{ justifyContent: "space-between" }}
className={useStyles().modalWindow}
>
Add Media
</DialogTitle>
<Button onClick={handleCloseClick}>
<IconClose className={useStyles().closeButton} />
</Button>
</CustomToolbar>
<DialogContent className={useStyles().modalWindow}>
{loading && <h2>Your images are loading</h2>}
{!loading && <ArcImageGrid imageData={data} />}
{error && <h2>There was an error loading your images</h2>}
</DialogContent>
<DialogActions className={useStyles().customFooter}>
<Button
label="Edit Image in Arc"
variant={"outlined"}
onClick={() => {}}
className={useStyles().arcEditButton}
/>
<Button label="Apply" variant={"outlined"} onClick={handleSaveClick} />
</DialogActions>
</Dialog>
);
};
export default ImageSelectionModal;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出色地。我最终弄清楚了。您必须将这两个道具添加到对话框窗口中。
您也可以在MaxWidth属性中添加“ SM”,“ MD”或“ LG”
Well. I eventually figured this out. You have to add both of these props to the dialog window.
You could also add "sm", "md" or "lg" to the maxWidth property