Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Add notistack demo to the snackbar page #13685

Merged
merged 4 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/src/pages/demos/snackbars/IntegrationNotistack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import PropTypes from 'prop-types';
import Button from '@material-ui/core/Button';
import { SnackbarProvider, withSnackbar } from 'notistack';

class App extends React.Component {
handleClick = () => {
this.props.enqueueSnackbar('I love snacks.');
};

handleClickVariant = variant => () => {
// variant could be success, error, warning or info
this.props.enqueueSnackbar('This is a warning message!', { variant });
};

render() {
return (
<React.Fragment>
<Button onClick={this.handleClick}>Show snackbar</Button>
<Button onClick={this.handleClickVariant('warning')}>Show warning snackbar</Button>
</React.Fragment>
);
}
}

App.propTypes = {
enqueueSnackbar: PropTypes.func.isRequired,
};

const MyApp = withSnackbar(App);

function IntegrationNotistack() {
return (
<SnackbarProvider maxSnack={3}>
<MyApp />
</SnackbarProvider>
);
}

export default IntegrationNotistack;
9 changes: 8 additions & 1 deletion docs/src/pages/demos/snackbars/snackbars.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,11 @@ Use a different transition all together.

For more advanced use cases you might be able to take advantage of:

- [notistack](https://github.com/iamhosseindhv/notistack) Highly customisable notification snackbars that can be stacked on top of each other.
### notistack

![stars](https://img.shields.io/github/stars/iamhosseindhv/notistack.svg?style=social&label=Stars)
![npm downloads](https://img.shields.io/npm/dm/notistack.svg)

In the following example, we demonstrate how to use [notistack](https://github.com/iamhosseindhv/notistack). notistack makes it easy to display snackbars (so you don't have to deal with open/close state of them). It also enables you to stack them on top of one another.

{{"demo": "pages/demos/snackbars/IntegrationNotistack.js"}}
7 changes: 6 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
const webpack = require('webpack');
const pkg = require('./package.json');
const withTM = require('@weco/next-plugin-transpile-modules');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { findPages } = require('./docs/src/modules/utils/find');

process.env.LIB_VERSION = pkg.version;

module.exports = {
webpack: config => {
webpack: (config, options) => {
config = withTM({
transpileModules: ['notistack'],
}).webpack(config, options);

const plugins = config.plugins.concat([
new webpack.DefinePlugin({
'process.env': {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@babel/register": "7.0.0",
"@types/enzyme": "^3.1.4",
"@types/react": "^16.3.14",
"@weco/next-plugin-transpile-modules": "0.0.2",
"accept-language": "^3.0.18",
"argos-cli": "^0.0.9",
"autoprefixer": "^9.0.0",
Expand Down Expand Up @@ -123,6 +124,7 @@
"material-ui-popup-state": "^1.0.1",
"mocha": "^5.0.0",
"next": "^7.0.0",
"notistack": "^0.3.9",
"nyc": "^13.0.0",
"postcss": "^7.0.0",
"prettier": "^1.8.2",
Expand Down
7 changes: 7 additions & 0 deletions pages/demos/snackbars.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ module.exports = require('fs')
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/demos/snackbars/CustomizedSnackbars'), 'utf8')
`,
},
'pages/demos/snackbars/IntegrationNotistack.js': {
js: require('docs/src/pages/demos/snackbars/IntegrationNotistack').default,
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/demos/snackbars/IntegrationNotistack'), 'utf8')
`,
},
}}
Expand Down
12 changes: 11 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,11 @@
"@webassemblyjs/wast-parser" "1.7.8"
"@xtuc/long" "4.2.1"

"@weco/[email protected]":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@weco/next-plugin-transpile-modules/-/next-plugin-transpile-modules-0.0.2.tgz#f8f8af6adc6a3c565ed6212ae82a383f18efc40e"
integrity sha1-+PivatxqPFZe1iEq6Co4PxjvxA4=

"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"
Expand Down Expand Up @@ -5637,7 +5642,7 @@ eslint-plugin-jsx-a11y@^6.0.3:
jsx-ast-utils "^2.0.1"

"eslint-plugin-material-ui@file:packages/eslint-plugin-material-ui":
version "1.0.0-beta.35"
version "3.0.0"

eslint-plugin-mocha@^5.0.0:
version "5.2.0"
Expand Down Expand Up @@ -9318,6 +9323,11 @@ normalize-scroll-left@^0.1.2:
resolved "https://registry.yarnpkg.com/normalize-scroll-left/-/normalize-scroll-left-0.1.2.tgz#6b79691ba79eb5fb107fa5edfbdc06b55caee2aa"
integrity sha512-F9YMRls0zCF6BFIE2YnXDRpHPpfd91nOIaNdDgrx5YMoPLo8Wqj+6jNXHQsYBavJeXP4ww8HCt0xQAKc5qk2Fg==

notistack@^0.3.9:
version "0.3.9"
resolved "https://registry.yarnpkg.com/notistack/-/notistack-0.3.9.tgz#622d89c0038b7cdebba2897b3018f89ada03551d"
integrity sha512-Xt55Jn2kq+1o34wS6y8ydj/84UpZrJhpWFfFqY5YqxZPdSiu5RgxhUcoTeq6XLQ8Mwg/TdhH+kRgn21Pxb6IlA==

npm-bundled@^1.0.1:
version "1.0.5"
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.5.tgz#3c1732b7ba936b3a10325aef616467c0ccbcc979"
Expand Down