From 665c353081563d879be764497028fcedfdd14aeb Mon Sep 17 00:00:00 2001 From: Hossein Dehnokhalaji Date: Wed, 15 Jun 2022 21:40:24 +0100 Subject: [PATCH] Add custom content example --- examples/custom-content-example/.gitignore | 21 ++++ examples/custom-content-example/App.js | 9 ++ .../custom-content-example/MessageButtons.js | 44 ++++++++ .../custom-content-example/ReportComplete.js | 102 ++++++++++++++++++ examples/custom-content-example/index.js | 7 ++ examples/custom-content-example/package.json | 54 ++++++++++ .../custom-content-example/public/index.html | 38 +++++++ 7 files changed, 275 insertions(+) create mode 100644 examples/custom-content-example/.gitignore create mode 100644 examples/custom-content-example/App.js create mode 100644 examples/custom-content-example/MessageButtons.js create mode 100644 examples/custom-content-example/ReportComplete.js create mode 100644 examples/custom-content-example/index.js create mode 100644 examples/custom-content-example/package.json create mode 100644 examples/custom-content-example/public/index.html diff --git a/examples/custom-content-example/.gitignore b/examples/custom-content-example/.gitignore new file mode 100644 index 00000000..d30f40ef --- /dev/null +++ b/examples/custom-content-example/.gitignore @@ -0,0 +1,21 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +/node_modules + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/examples/custom-content-example/App.js b/examples/custom-content-example/App.js new file mode 100644 index 00000000..231a6295 --- /dev/null +++ b/examples/custom-content-example/App.js @@ -0,0 +1,9 @@ +import React from 'react'; +import { SnackbarProvider } from 'notistack'; +import MessageButtons from './MessageButtons'; + +export default () => ( + + + +); diff --git a/examples/custom-content-example/MessageButtons.js b/examples/custom-content-example/MessageButtons.js new file mode 100644 index 00000000..0511a52a --- /dev/null +++ b/examples/custom-content-example/MessageButtons.js @@ -0,0 +1,44 @@ +import React from 'react'; +import Button from '@mui/material/Button'; +import Paper from '@mui/material/Paper'; +import { useSnackbar } from 'notistack'; +import ReportComplete from './ReportComplete'; + +const styles = { + root: { + flexGrow: 1, + display: 'flex', + margin: 16, + justifyContent: 'center', + alignItems: 'middle', + }, + button: { + margin: 8, + borderColor: '#313131', + color: '#313131', + }, +}; + +const MessageButtons = () => { + const { enqueueSnackbar } = useSnackbar(); + + const handleClick = () => { + enqueueSnackbar("You're report is ready", { + anchorOrigin: { + vertical: 'bottom', + horizontal: 'right', + }, + content: (key, message) => , + }); + }; + + return ( + + + + ); +}; + +export default MessageButtons; diff --git a/examples/custom-content-example/ReportComplete.js b/examples/custom-content-example/ReportComplete.js new file mode 100644 index 00000000..13ad4136 --- /dev/null +++ b/examples/custom-content-example/ReportComplete.js @@ -0,0 +1,102 @@ +import React, { useState, forwardRef, useCallback } from "react"; +import { makeStyles } from "@mui/styles"; +import { useSnackbar, SnackbarContent } from "notistack"; +import Collapse from "@mui/material/Collapse"; +import Paper from "@mui/material/Paper"; +import Typography from "@mui/material/Typography"; +import Card from "@mui/material/Card"; +import CardActions from "@mui/material/CardActions"; +import Button from "@mui/material/Button"; +import IconButton from "@mui/material/IconButton"; +import CloseIcon from "@mui/icons-material/Close"; +import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; +import CheckCircleIcon from "@mui/icons-material/CheckCircle"; + +const useStyles = makeStyles(() => ({ + root: { + "@media (min-width:600px)": { + minWidth: "344px !important" + } + }, + card: { + backgroundColor: "#fddc6c", + width: "100%" + }, + typography: { + fontWeight: "bold" + }, + actionRoot: { + padding: "8px 8px 8px 16px", + justifyContent: "space-between" + }, + icons: { + marginLeft: "auto" + }, + expand: { + padding: "8px 8px", + transform: "rotate(0deg)", + transition: "all .2s" + }, + collapse: { + padding: 16 + }, + checkIcon: { + fontSize: 20, + color: "#b3b3b3", + paddingRight: 4 + }, + button: { + padding: 0, + textTransform: "none" + } +})); + +const ReportComplete = forwardRef((props, ref) => { + const classes = useStyles(); + const { closeSnackbar } = useSnackbar(); + const [expanded, setExpanded] = useState(false); + + const handleExpandClick = useCallback(() => { + setExpanded((oldExpanded) => !oldExpanded); + }, []); + + const handleDismiss = useCallback(() => { + closeSnackbar(props.id); + }, [props.id, closeSnackbar]); + + return ( + + + + + {props.message} + +
+ + + + + + +
+
+ + + PDF ready + + + +
+
+ ); +}); + +export default ReportComplete; diff --git a/examples/custom-content-example/index.js b/examples/custom-content-example/index.js new file mode 100644 index 00000000..48342b59 --- /dev/null +++ b/examples/custom-content-example/index.js @@ -0,0 +1,7 @@ +import React from 'react'; +import { createRoot } from 'react-dom/client'; +import App from './App'; + +const container = document.getElementById('root'); +const root = createRoot(container); +root.render(); diff --git a/examples/custom-content-example/package.json b/examples/custom-content-example/package.json new file mode 100644 index 00000000..54b415bd --- /dev/null +++ b/examples/custom-content-example/package.json @@ -0,0 +1,54 @@ +{ + "name": "notistack-custom-content-example", + "description": "notistack example of a custom Snackbar content", + "repository": { + "url": "git+https://github.com/iamhosseindhv/notistack.git", + "type": "git" + }, + "author": { + "name": "Hossein Dehnokhalaji", + "email": "hossein.dehnavi98@yahoo.com", + "url": "https://github.com/iamhosseindhv/notistack" + }, + "homepage": "https://github.com/iamhosseindhv/notistack", + "bugs": { + "url": "https://github.com/iamhosseindhv/notistack/issues" + }, + "contributors": [ + "Hossein Dehnokhalaji (https://iamhosseindhv.com/)" + ], + "license": "MIT", + "keywords": [ + "react", + "javascript", + "material-ui", + "mui", + "@mui/material", + "emotion", + "@emotion/react", + "@emotion/styled", + "stacked", + "snackbar", + "notification" + ], + "dependencies": { + "@emotion/react": "latest", + "@emotion/styled": "latest", + "@mui/icons-material": "latest", + "@mui/material": "latest", + "@mui/styles": "5.8.4", + "notistack": "latest", + "react": "latest", + "react-dom": "latest" + }, + "version": "0.0.0", + "devDependencies": { + "react-scripts": "1.0.0" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test --env=jsdom", + "eject": "react-scripts eject" + } +} \ No newline at end of file diff --git a/examples/custom-content-example/public/index.html b/examples/custom-content-example/public/index.html new file mode 100644 index 00000000..21e08c31 --- /dev/null +++ b/examples/custom-content-example/public/index.html @@ -0,0 +1,38 @@ + + + + + + + + + + + React App + + + +
+ + +