add expandedText prop to MessageManager

This commit is contained in:
AlicjaSzu 2020-06-23 18:02:59 +02:00
parent b3eb13a785
commit 49df188703
4 changed files with 139 additions and 39 deletions

View file

@ -24,11 +24,13 @@ export const MessageManager = props => {
text: "" text: ""
}); });
const [opened, setOpened] = useState(false); const [opened, setOpened] = useState(false);
const [expand, setExpand] = useState(false);
const classes = useStyles({}); const classes = useStyles({});
const { const {
action, actionBtn,
autohide = 3000, autohide = 9000,
expandText,
title, title,
text, text,
key, key,
@ -105,7 +107,46 @@ export const MessageManager = props => {
} }
title={title} title={title}
action={[ action={[
!!onUndo ? ( !!expandText ? (
<div
className={classNames(classes.expandedContainer, {
[classes.expandedContainerInfo]: status === "info"
})}
>
<div
className={classNames(
classes.expandedContainerContent,
expand ? classes.expandedText : classes.hiddenText
)}
>
<p>{expandText}</p>
</div>
<button
className={classNames(classes.expandBtn, {
[classes.expandBtnInfo]: status === "info"
})}
onClick={() => {
setExpand(expand => !expand);
}}
>
{!expand ? (
<FormattedMessage
defaultMessage="Expand"
description="snackbar expand"
/>
) : (
<FormattedMessage
defaultMessage="Collapse"
description="snackbar collapse"
/>
)}
</button>
</div>
) : (
undefined
),
<div key="actions" className={classes.actionContainer}>
{!!onUndo && (
<Button <Button
key="undo" key="undo"
color="default" color="default"
@ -118,34 +159,27 @@ export const MessageManager = props => {
description="snackbar button undo" description="snackbar button undo"
/> />
</Button> </Button>
) : ( )}
undefined {!!actionBtn && (
),
!!action ? (
<Button <Button
key="action" key="action"
color="default" color="default"
size="small" size="small"
onClick={() => { onClick={actionBtn.action}
action();
handleClose(null, null);
}}
data-tc="button-action" data-tc="button-action"
> >
<FormattedMessage {actionBtn.label}
defaultMessage="Action"
description="snackbar button action"
/>
</Button> </Button>
) : ( )}
undefined </div>,
),
<IconButton <IconButton
key="close" key="close"
aria-label="Close" aria-label="Close"
color="inherit" color="inherit"
onClick={handleClose as any} onClick={handleClose as any}
className={classes.closeBtn} className={classNames(classes.closeBtn, {
[classes.closeBtnInfo]: status === "info"
})}
> >
<CloseIcon /> <CloseIcon />
</IconButton>, </IconButton>,

View file

@ -1,8 +1,12 @@
import { createContext } from "react"; import { createContext } from "react";
export interface IMessage { export interface IMessage {
action?: () => void; actionBtn?: {
label: string;
action: () => void;
};
autohide?: number; autohide?: number;
expandText?: string;
title?: string; title?: string;
text: string; text: string;
onUndo?: () => void; onUndo?: () => void;

View file

@ -15,10 +15,22 @@ export const useStyles = makeStyles(
from: { transform: "translateX(-100%)" }, from: { transform: "translateX(-100%)" },
to: { transform: "translateX(0)" } to: { transform: "translateX(0)" }
}, },
actionContainer: {
marginLeft: -8
},
closeBtn: { closeBtn: {
"& svg": {
maxHeight: 18,
maxWidth: 18
},
color: "#fff",
padding: 10,
position: "absolute", position: "absolute",
right: 0, right: 0,
top: 0 top: 7
},
closeBtnInfo: {
color: theme.palette.text.primary
}, },
error: { error: {
"& > div": { "& > div": {
@ -28,11 +40,60 @@ export const useStyles = makeStyles(
"&:before": { "&:before": {
backgroundImage: `url(${errorIcon})` backgroundImage: `url(${errorIcon})`
}, },
backgroundColor: theme.palette.error.main, backgroundColor: theme.palette.error.main,
color: "#fff" color: "#fff"
} }
}, },
expandBtn: {
"&:before": {
borderLeft: "4px solid transparent",
borderRight: "4px solid transparent",
borderTop: "8px solid #fff",
content: "''",
display: "block",
height: 0,
position: "absolute",
right: 0,
top: "50%",
transform: "translateY(-50%)",
width: 0
},
background: "transparent",
border: "none",
color: "#fff",
cursor: "pointer",
fontSize: theme.spacing(2),
outline: "none",
padding: 0,
paddingRight: 15,
position: "relative"
},
expandBtnInfo: {
"&:before": {
borderTop: `8px solid ${theme.palette.text.primary}`
},
color: theme.palette.text.primary
},
expandedContainer: {
"& p": {
margin: theme.spacing(1, 0)
},
color: "#fff",
marginBottom: 5
},
expandedContainerContent: {
overflow: "hidden",
transition: "max-height .6s ease"
},
expandedContainerInfo: {
color: theme.palette.text.secondary
},
expandedText: {
maxHeight: 500
},
hiddenText: {
maxHeight: 0
},
progressBar: { progressBar: {
backgroundColor: infoColor, backgroundColor: infoColor,
height: 8, height: 8,

View file

@ -344,8 +344,9 @@ export default (colors: IThemeColors): Theme =>
} }
}, },
display: "block", display: "block",
paddingBottom: 15, paddingBottom: 10,
paddingLeft: 0 paddingLeft: 0,
paddingRight: 45
}, },
message: { message: {
fontSize: 16 fontSize: 16