React Admin - 如何创建大型模态 window

React Admin - how to create a large modal window

我在 React-Admin 中打开一个对话框,供用户 select 图片。问题是我希望此对话框占据大部分屏幕,但 React Admin 使用名为 MuiDialog-paperWidthSm 的 class 打开该模式。这将宽度限制为 600px,应用全宽 属性 不会影响这一点。

我尝试设置自定义属性,虽然这会增加模态框的内部尺寸,但会导致水平滚动而不是更宽 window。

模态组件如下:

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;

嗯。我最终想通了。您必须将这两个道具添加到对话框 window。

fullWidth
maxWidth="xl"

您还可以将“sm”、“md”或“lg”添加到最大宽度属性