diff --git a/package/src/components/Toast/Toast.js b/package/src/components/Toast/Toast.js index c7d9fb59..69db1d8f 100644 --- a/package/src/components/Toast/Toast.js +++ b/package/src/components/Toast/Toast.js @@ -1,18 +1,39 @@ import React from "react"; import PropTypes from "prop-types"; -import { Snackbar } from "@material-ui/core"; +import { Snackbar, IconButton } from "@material-ui/core"; +import CloseIcon from "mdi-material-ui/Close"; +import { makeStyles } from "@material-ui/core/styles"; import { ToastWrapper } from "./helpers"; +const useStyles = makeStyles((theme) => ({ + close: { + padding: 4, + marginRight: -8 + } +})); + /** * @name Toast * @param {Object} props Component props * @returns {React.Component} returns a React component */ const Toast = React.forwardRef(function Toast(props, ref) { + const classes = useStyles(); const { className, message, variant, title, ...otherProps } = props; + const [open, setOpen] = React.useState(false); + + const handleClose = (event, reason) => { + if (reason === "clickaway") { + return; + } + + setOpen(false); + }; + return ( + + } /> ); @@ -34,9 +66,12 @@ Toast.propTypes = { */ className: PropTypes.string, /** - * Message + * Message: Node + */ + message: PropTypes.node, + /** + * Title: Optional */ - message: PropTypes.string, title: PropTypes.string, /** * Variant: Info, Success, Warning, Error diff --git a/package/src/components/Toast/Toast.md b/package/src/components/Toast/Toast.md index b363c715..04dc0e95 100644 --- a/package/src/components/Toast/Toast.md +++ b/package/src/components/Toast/Toast.md @@ -1,36 +1,34 @@ ### Overview - +Toasts are used to give action-based feedback messages and convey critical or informational account-related messages. Use Toasts when a user needs more detailed information for an action. -The X component inherits from the Material-UI [X component](https://material-ui.com/components/X/). Refer to the Material-UI [X docs](https://material-ui.com/api/X/) for more information. +The Toast component inherits from the Material-UI [Snackbar component](https://material-ui.com/components/snackbars/). Refer to the Material-UI [Snackbar docs](https://material-ui.com/api/snackbar/) for more information. ### Usage - - ```jsx ``` +Toasts are most often used when the user has taken an action. Messages appear in context and communicate when that action is successful, unsuccessful, or that it otherwise needs attention and further context. + +Language should be polite, clear and concise. Optionally, a title can be added to a Toast to give clarity, or when there are 2 or more lines of information to display. + +Toasts should guide the user into taking corrective action if necessary. + +Users should be able to dismiss Toasts when appropriate. Information and success alerts can close automatically after 10 seconds. Error alerts should be persistent, and close only when action is resolved. + #### Types ##### Information - - -Use a X component to allow a user to XX, such as XYXY. +- Used when there is information or tips that users can benefit from +- Can close automatically after 10 seconds ```jsx import Button from "../Button"; @@ -73,14 +71,15 @@ function OpenToast(props) { ); } - +Information toast} title="Info" variant="info" /> ``` ##### Success -Use a X component to allow a user to XX, such as XYXY. +- Used when an action has been completed successfully +- Can close automatically after 10 seconds ```jsx import Button from "../Button"; @@ -122,14 +121,13 @@ function OpenToast(props) { ); } - +Success toast} variant="success" /> ``` ##### Warning - - -Use a X component to allow a user to XX, such as XYXY. +- Used when an action or item needs attention +- Should not close automatically, unless the action has been resolved ```jsx import Button from "../Button"; @@ -171,14 +169,13 @@ function OpenToast(props) { ); } - +Warning toast} variant="warning" /> ``` ##### Error - - -Use a X component to allow a user to XX, such as XYXY. +- Used when the system has failed to complete an action, or the user has made an error +- Should not close automatically, unless the action has been resolved ```jsx import Button from "../Button"; @@ -220,5 +217,5 @@ function OpenToast(props) { ); } - +Error toast} variant="error" /> ``` \ No newline at end of file diff --git a/package/src/components/Toast/helpers/ToastWrapper.js b/package/src/components/Toast/helpers/ToastWrapper.js index ed47ce22..ea3eccb4 100644 --- a/package/src/components/Toast/helpers/ToastWrapper.js +++ b/package/src/components/Toast/helpers/ToastWrapper.js @@ -5,19 +5,15 @@ import { Paper, Typography } from "@material-ui/core"; import { makeStyles } from "@material-ui/core/styles"; const useStyles = makeStyles((theme) => ({ - message: { - padding: "8px 0" + messageWrapper: { + // padding: "8px 0" }, title: { - padding: "8px 0 0 0", + padding: "4px 0 8px 0", fontWeight: theme.typography.fontWeightSemiBold }, action: { - display: "flex", - alignItems: "center", - marginLeft: "auto", - paddingLeft: 16, - marginRight: -8 + marginLeft: "auto" }, success: { fontSize: theme.typography.fontSize, @@ -27,7 +23,7 @@ const useStyles = makeStyles((theme) => ({ padding: "8px 16px", borderRadius: theme.shape.borderRadius, display: "flex", - flexDirection: "column", + flexDirection: "row", minWidth: 288 }, error: { @@ -38,7 +34,7 @@ const useStyles = makeStyles((theme) => ({ padding: "8px 16px", borderRadius: theme.shape.borderRadius, display: "flex", - flexDirection: "column", + flexDirection: "row", minWidth: 288 }, info: { @@ -49,7 +45,7 @@ const useStyles = makeStyles((theme) => ({ padding: "8px 16px", borderRadius: theme.shape.borderRadius, display: "flex", - flexDirection: "column", + flexDirection: "row", minWidth: 288 }, warning: { @@ -60,7 +56,7 @@ const useStyles = makeStyles((theme) => ({ padding: "8px 16px", borderRadius: theme.shape.borderRadius, display: "flex", - flexDirection: "column", + flexDirection: "row", minWidth: 288 } })); @@ -76,7 +72,7 @@ export default function ToastWrapper(props) { return ( - { title ? {title} : null } -
{message}
+
+ { title ? {title} : null } + {message} +
{action ?
{action}
: null }
); @@ -95,7 +93,7 @@ export default function ToastWrapper(props) { ToastWrapper.propTypes = { action: PropTypes.node, className: PropTypes.string, - message: PropTypes.string, + message: PropTypes.node, title: PropTypes.string, variant: PropTypes.oneOf(["error", "info", "success", "warning"]).isRequired };