2019-06-19 14:40:52 +00:00
|
|
|
import Button from "@material-ui/core/Button";
|
|
|
|
import Dialog from "@material-ui/core/Dialog";
|
|
|
|
import DialogActions from "@material-ui/core/DialogActions";
|
|
|
|
import DialogContent from "@material-ui/core/DialogContent";
|
|
|
|
import DialogTitle from "@material-ui/core/DialogTitle";
|
2019-10-30 14:34:24 +00:00
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
2019-08-09 11:14:35 +00:00
|
|
|
import classNames from "classnames";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-26 21:54:03 +00:00
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-08-26 21:54:03 +00:00
|
|
|
import { buttonMessages } from "@saleor/intl";
|
2019-11-08 10:25:17 +00:00
|
|
|
import { DialogProps } from "@saleor/types";
|
2019-06-19 14:40:52 +00:00
|
|
|
import ConfirmButton, {
|
|
|
|
ConfirmButtonTransitionState
|
|
|
|
} from "../ConfirmButton/ConfirmButton";
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
2019-06-19 14:40:52 +00:00
|
|
|
deleteButton: {
|
|
|
|
"&:hover": {
|
|
|
|
backgroundColor: theme.palette.error.main
|
|
|
|
},
|
|
|
|
backgroundColor: theme.palette.error.main,
|
|
|
|
color: theme.palette.error.contrastText
|
|
|
|
}
|
2019-10-30 14:34:24 +00:00
|
|
|
}),
|
|
|
|
{ name: "ActionDialog" }
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-11-08 10:25:17 +00:00
|
|
|
interface ActionDialogProps extends DialogProps {
|
2019-06-19 14:40:52 +00:00
|
|
|
children?: React.ReactNode;
|
|
|
|
confirmButtonLabel?: string;
|
|
|
|
confirmButtonState: ConfirmButtonTransitionState;
|
2019-11-04 13:36:25 +00:00
|
|
|
maxWidth?: "xs" | "sm" | "md" | "lg" | "xl" | false;
|
2019-06-19 14:40:52 +00:00
|
|
|
title: string;
|
|
|
|
variant?: "default" | "delete";
|
|
|
|
onConfirm();
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const ActionDialog: React.FC<ActionDialogProps> = props => {
|
|
|
|
const {
|
2019-06-19 14:40:52 +00:00
|
|
|
children,
|
|
|
|
confirmButtonLabel,
|
|
|
|
confirmButtonState,
|
|
|
|
open,
|
|
|
|
title,
|
|
|
|
variant,
|
|
|
|
onConfirm,
|
2019-11-04 13:36:25 +00:00
|
|
|
onClose,
|
|
|
|
...rest
|
2019-10-30 14:34:24 +00:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
const classes = useStyles(props);
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
2019-11-05 14:39:52 +00:00
|
|
|
<Dialog fullWidth onClose={onClose} open={open} {...rest}>
|
2019-10-30 14:34:24 +00:00
|
|
|
<DialogTitle>{title}</DialogTitle>
|
|
|
|
<DialogContent>{children}</DialogContent>
|
|
|
|
<DialogActions>
|
|
|
|
<Button onClick={onClose}>
|
|
|
|
<FormattedMessage {...buttonMessages.back} />
|
|
|
|
</Button>
|
|
|
|
<ConfirmButton
|
|
|
|
transitionState={confirmButtonState}
|
|
|
|
color="primary"
|
|
|
|
variant="contained"
|
|
|
|
onClick={onConfirm}
|
|
|
|
className={classNames({
|
|
|
|
[classes.deleteButton]: variant === "delete"
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{confirmButtonLabel ||
|
|
|
|
(variant === "delete"
|
|
|
|
? intl.formatMessage(buttonMessages.delete)
|
|
|
|
: intl.formatMessage(buttonMessages.confirm))}
|
|
|
|
</ConfirmButton>
|
|
|
|
</DialogActions>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|
2019-08-26 21:54:03 +00:00
|
|
|
|
2019-11-04 13:36:25 +00:00
|
|
|
ActionDialog.defaultProps = {
|
|
|
|
maxWidth: "xs",
|
|
|
|
variant: "default"
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
ActionDialog.displayName = "ActionDialog";
|
|
|
|
export default ActionDialog;
|