diff --git a/src/components/Toasts/index.js b/src/components/Toasts/index.js index 45e59947..57a00cb3 100644 --- a/src/components/Toasts/index.js +++ b/src/components/Toasts/index.js @@ -5,17 +5,24 @@ import * as colors from "@material-ui/core/colors" import Collapse from "@material-ui/core/Collapse" import Fade from "@material-ui/core/Fade" import classNames from "classnames" +import { + CheckCircle as SuccessIcon, + Close as CloseIcon, + Error as ErrorIcon, + Info as InfoIcon, + Warning as WarningIcon, +} from "@material-ui/icons" +import Typography from "@material-ui/core/Typography" +import IconButton from "@material-ui/core/IconButton" const useStyles = makeStyles({ root: { position: "fixed", display: "flex", flexDirection: "column", - bottom: 0, - left: 0, - right: 0, + bottom: 16, + right: 16, alignItems: "flex-start", - pointerEvents: "none", }, msgBox: { display: "flex", @@ -32,6 +39,35 @@ const useStyles = makeStyles({ backgroundColor: colors.red[700], }, }, + notificationPaper: { + display: "flex", + borderRadius: 10, + padding: 12, + boxShadow: `0 2.8px 2.2px rgba(0, 0, 0, 0.034), + 0 6.7px 5.3px rgba(0, 0, 0, 0.048);`, + backgroundColor: "#FFF", + margin: 6, + }, + icon: { + borderLeft: `3px solid ${colors.blue[700]}`, + color: colors.blue[700], + "&.warning": { + borderLeft: `3px solid ${colors.orange[700]}`, + color: colors.orange[700], + }, + "&.error": { + borderLeft: `3px solid ${colors.red[700]}`, + color: colors.red[700], + }, + "&.info": { + borderLeft: `3px solid ${colors.blue[700]}`, + color: colors.blue[700], + }, + "&.success": { + borderLeft: `3px solid ${colors.green[700]}`, + color: colors.green[700], + }, + }, }) const REFRESH_INTERVAL = 100 @@ -70,6 +106,13 @@ export const ToastProvider = ({ children }) => { life: msg.life - REFRESH_INTERVAL, })) .filter((msg) => msg.life > 0) + } else if (action.type === "remove") { + return state + .map((msg) => ({ + ...msg, + life: msg.life - REFRESH_INTERVAL, + })) + .filter((msg) => msg.id !== action.id) } return state }, []) @@ -95,9 +138,11 @@ export const ToastProvider = ({ children }) => { {toasts.map((msg) => ( 600}> -
- {msg.message} -
+ changeToasts({ type: "remove", id: msg.id })} + />
))} @@ -105,3 +150,47 @@ export const ToastProvider = ({ children }) => { ) } + +export const Notification = ({ type, message, onClose }) => { + const classes = useStyles() + let Icon = null + switch (type) { + case "success": + Icon = SuccessIcon + break + case "warning": + Icon = WarningIcon + break + case "error": + Icon = ErrorIcon + break + default: + Icon = InfoIcon + } + return ( + +
+ +
+
+ {message} +
+
+ + + +
+
+ ) +} diff --git a/src/components/Toasts/index.story.js b/src/components/Toasts/index.story.js new file mode 100644 index 00000000..918edef6 --- /dev/null +++ b/src/components/Toasts/index.story.js @@ -0,0 +1,38 @@ +// @flow + +import React from "react" + +import { storiesOf } from "@storybook/react" +import { action } from "@storybook/addon-actions" + +import { Notification } from "./" + +storiesOf("toast notification", module).add("Basic", () => ( +
+ + + + + +
+))