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

Support MUI v5 alpha #333

Merged
merged 36 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dad1e61
Add mat snackbar
iamhosseindhv May 8, 2020
207bb40
Merge branch 'master' into testable-config
iamhosseindhv May 9, 2020
936ee3f
Add snackbar component
iamhosseindhv May 9, 2020
0f01325
Allow any
iamhosseindhv May 9, 2020
2722900
Merge provider props. Remove Content props
iamhosseindhv May 9, 2020
943401e
Minor
iamhosseindhv May 9, 2020
f96efc0
Simpler content props
iamhosseindhv May 9, 2020
63e5b5a
Move helper functions to their own file
iamhosseindhv May 9, 2020
ade524d
Revert some changes
iamhosseindhv May 9, 2020
b2c6ce8
Move transition component one level up
iamhosseindhv May 9, 2020
b94e49d
Move defaults to constants file
iamhosseindhv May 9, 2020
4a78dd6
Minor
iamhosseindhv May 9, 2020
1d12b98
Dont spread callbacks
iamhosseindhv May 9, 2020
1cf8189
Minor
iamhosseindhv May 9, 2020
c830d71
sort out transition component, duration and props properties
iamhosseindhv May 10, 2020
464e417
Merge branch 'master' into testable-config
iamhosseindhv May 12, 2020
5c208b1
Merge branch 'master' into testable-config
iamhosseindhv May 12, 2020
645835b
Merge branch 'master' into testable-config
iamhosseindhv May 14, 2020
01cb700
Merge branch 'master' into testable-config
iamhosseindhv May 15, 2020
d994e76
Update tsdocs
iamhosseindhv May 15, 2020
d191a51
Use transformer for container anchor origin
iamhosseindhv May 15, 2020
76d9cf4
Add comment
iamhosseindhv May 16, 2020
69166b3
Merge branch 'master' into testable-config
iamhosseindhv May 16, 2020
277a300
Merge branch 'master' into testable-config
iamhosseindhv May 17, 2020
0452950
Merge branch 'master' into testable-config
iamhosseindhv May 17, 2020
cd2e2a0
Merge branch 'master' into testable-config
iamhosseindhv May 17, 2020
fe9f598
Merge branch 'master' into testable-config
iamhosseindhv May 23, 2020
8029efd
Merge branch 'master' into testable-config
iamhosseindhv Jun 10, 2020
fd982c0
Merge branch 'master' into testable-config
iamhosseindhv Aug 22, 2020
83605c8
Update typedoc
iamhosseindhv Aug 22, 2020
b8ddf1f
Merge branch 'master' into future
iamhosseindhv Oct 6, 2020
bd61e8e
Attempt to stop spreading props
iamhosseindhv Nov 24, 2020
cb79587
TSDX transpileOnly
iamhosseindhv Nov 24, 2020
a81faed
Credit mui snackbar
iamhosseindhv Nov 24, 2020
094c416
Update docs
iamhosseindhv Nov 24, 2020
d1d190e
Update changelog
iamhosseindhv Nov 26, 2020
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
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
},
"rules": {
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Thanks to all contributers who improved notistack by opening an issue/PR.

### `[email protected].2`
### `[email protected].3`
###### to be published
* **@pctestjfarz**: Add swipe to dismiss feature [#138](https://github.com/iamhosseindhv/notistack/issues/138)
* **@molynerd**: Add support to update content of snackbar in place [#50](https://github.com/iamhosseindhv/notistack/issues/50)
Expand All @@ -9,6 +9,14 @@ Thanks to all contributers who improved notistack by opening an issue/PR.
<br />


### `[email protected]`
###### November 26, 2020
* Add support MUI v5 [#333](https://github.com/iamhosseindhv/notistack/pull/333)


<br />


### `[email protected]`
###### October 6, 2020
* **@thierrysantos**: EnqueueSnackbar supports snackbar with key zero [#318](https://github.com/iamhosseindhv/notistack/pull/318)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"type": "git"
},
"scripts": {
"build": "tsdx build --entry ./src/index.js",
"build": "tsdx build --transpileOnly --entry ./src/index.js",
"prebuild": "npm run docs",
"prepublishOnly": "npm run build",
"docs": "rimraf typedoc.json && typedoc --tsconfig",
Expand Down
113 changes: 113 additions & 0 deletions src/SnackbarItem/Snackbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* @link https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/Snackbar/Snackbar.js
*/
import * as React from 'react';
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
import { REASONS } from '../utils/constants';
import useEventCallback from '../utils/useEventCallback';

const Snackbar = React.forwardRef((props, ref) => {
const {
children,
autoHideDuration,
ClickAwayListenerProps,
disableWindowBlurListener = false,
onClose,
onMouseEnter,
onMouseLeave,
open,
resumeHideDuration,
...other
} = props;

const timerAutoHide = React.useRef();

const handleClose = useEventCallback((...args) => {
if (onClose) {
onClose(...args);
}
});

const setAutoHideTimer = useEventCallback((autoHideDurationParam) => {
if (!onClose || autoHideDurationParam == null) {
return;
}

clearTimeout(timerAutoHide.current);
timerAutoHide.current = setTimeout(() => {
handleClose(null, REASONS.TIMEOUT);
}, autoHideDurationParam);
});

React.useEffect(() => {
if (open) {
setAutoHideTimer(autoHideDuration);
}

return () => {
clearTimeout(timerAutoHide.current);
};
}, [open, autoHideDuration, setAutoHideTimer]);

/**
* Pause the timer when the user is interacting with the Snackbar
* or when the user hide the window.
*/
const handlePause = () => {
clearTimeout(timerAutoHide.current);
};

/**
* Restart the timer when the user is no longer interacting with the Snackbar
* or when the window is shown back.
*/
const handleResume = React.useCallback(() => {
if (autoHideDuration != null) {
setAutoHideTimer(resumeHideDuration != null ? resumeHideDuration : autoHideDuration * 0.5);
}
}, [autoHideDuration, resumeHideDuration, setAutoHideTimer]);

const handleMouseEnter = (event) => {
if (onMouseEnter) {
onMouseEnter(event);
}
handlePause();
};

const handleMouseLeave = (event) => {
if (onMouseLeave) {
onMouseLeave(event);
}
handleResume();
};

const handleClickAway = (event) => {
if (onClose) {
onClose(event, REASONS.CLICKAWAY);
}
};

React.useEffect(() => {
if (!disableWindowBlurListener && open) {
window.addEventListener('focus', handleResume);
window.addEventListener('blur', handlePause);

return () => {
window.removeEventListener('focus', handleResume);
window.removeEventListener('blur', handlePause);
};
}

return undefined;
}, [disableWindowBlurListener, handleResume, open]);

return (
<ClickAwayListener onClickAway={handleClickAway} {...ClickAwayListenerProps}>
<div onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} ref={ref} {...other}>
{children}
</div>
</ClickAwayListener>
);
});

export default Snackbar;
Loading