0.0.8 • Published 4 years ago
react-mui-notify v0.0.8
React Material UI Notify
Simple notification package using React and Material UI. An example can be found within with demo directory of this repo.
Install
npm install --save react-mui-notifyConfiguration
Config object have the following attributes:
| Name | Type | Description |
|---|---|---|
duration | Number | Set number of milliseconds to display notification before timeout |
anchorOrigin.vertical | String | Position of vertical alignment |
anchorOrigin.horizontal | String | Position of horizontal alignment |
The default config object is below.
const config = {
duration: 5000,
anchorOrigin: {
vertical: 'bottom',
horizontal: 'left',
},
};A global configuration object can be passed to the NotificationProvider as such
<NotificationProvider config={config}>
{children}
</NotificationProvider>or configuration options set per notification basis. If no config parameter is passed to the setNotification call the global config settings are used, eg. the config option passed to the NotificationProvider or default config if not object was passed as a prop on the NotificationProvider
const handleClick = () => {
setNotification({
...
...
config: config
});
};Usage
import React from 'react';
import { NotificationProvider } from 'react-mui-notify';
import Button from '@mui/material/Button';
import { useNotify } from 'react-mui-notify';
const NotifyButton = () => {
const { setNotification } = useNotify();
const handleClick = () => {
setNotification({
message: 'This is a notification',
type: 'success',
});
};
return (
<Button onClick={handleClick} variant="contained" color="success">
Demo Notify
</Button>
);
};
function App() {
return (
<NotificationProvider>
<NotifyButton />
</NotificationProvider>
);
}
export default App;Notes
- In order to use theming the
NotificationProviderwill have to be within theThemeProvidereg.
<ThemeProvider theme={theme}>
<NotificationProvider>
{children}
</NotificationProvider>
</ThemeProvider>License
MIT © subaquatic-pierre
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6-alpha
4 years ago
0.0.5-alpha
4 years ago
0.0.4-alpha
4 years ago
0.0.2-alpha
4 years ago
0.0.1-alpha
4 years ago