Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 7 additions & 6 deletions src/components/Toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ class Toast extends React.Component {
style: PropTypes.oneOfType([
PropTypes.object,
PropTypes.bool
])
]),
stylesheet: PropTypes.object
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be of course PropTypes.shape(... to make it accommodate the shape being checked type checked 😄

};

state = {
containerStyle: stylesheet.styles.container
containerStyle: this.props.stylesheet?.container ?? stylesheet.styles.container
};

getToastStyle() {
let {type, color} = this.props;
let {styles} = stylesheet;
let {type, color, stylesheet: customStyle} = this.props;
let {styles} = {...stylesheet, ...customStyle};
let contentStyle = {};

/* If type is set, merge toast action styles with base */
Expand Down Expand Up @@ -56,7 +57,7 @@ class Toast extends React.Component {
}

animateState() {
let {styles} = stylesheet;
let {styles} = {...stylesheet, ...customStyle};

// Show
setTimeout(() => {
Expand All @@ -77,7 +78,7 @@ class Toast extends React.Component {
// Updates the style of the container with styles for a state (hide/show).
// This triggers animations.
updateStyle(stateStyle) {
let {styles} = stylesheet;
let {styles} = {...stylesheet, ...customStyle};

this.setState({containerStyle: assign({}, styles.container, stateStyle)});
}
Expand Down
4 changes: 3 additions & 1 deletion src/defaults.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assign from 'object-assign';
import stylesheet from './stylesheet';

let defaults = {
wrapperId: 'notification-wrapper',
Expand All @@ -23,7 +24,8 @@ let defaults = {
color: "#FFFFFF",
backgroundColor: '#4990E2'
}
}
},
stylesheet,
};

function mergeOptions(options) {
Expand Down
14 changes: 7 additions & 7 deletions src/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Container from './components/Container';
import {defaults} from './defaults';

/* Render React component */
function renderToast(text, type, timeout, color) {
function renderToast(text, type, timeout, color, stylesheet = {}) {
let target = document.getElementById(defaults.wrapperId);
ReactDOM.render(<Toast text={text} timeout={timeout} type={type} color={color}/>, target);
ReactDOM.render(<Toast text={text} timeout={timeout} type={type} color={color} stylesheet={stylesheet} />, target);
}

/* Unmount React component */
Expand All @@ -31,13 +31,13 @@ function hide() {
* style: {Object} [JS representation of CSS]
* }
*/
function show(text, type, timeout, color) {
function show(text, type, timeout, color, stylesheet) {
if (!document.getElementById(defaults.wrapperId).hasChildNodes()) {
// Use default timeout if not set.
let renderTimeout = timeout || defaults.timeout;

// Render Component with Props.
renderToast(text, type, renderTimeout, color);
renderToast(text, type, renderTimeout, color, stylesheet);

if (renderTimeout === -1) {
return false;
Expand Down Expand Up @@ -87,7 +87,7 @@ function createShowQueue(initialRecallDelay = 500, recallDelayIncrement = 500) {

// show will now return true if it is able to send the message,
// or false if there is an existing message
if (show(current.text, current.type, current.timeout, current.color)) {
if (show(current.text, current.type, current.timeout, current.color, current.stylesheet)) {
this.currentRecallDelay = initialRecallDelay;
if (current.timeout > 0) {
setTimeout(() => this.showNotify(), current.timeout + defaults.animationDuration);
Expand All @@ -100,8 +100,8 @@ function createShowQueue(initialRecallDelay = 500, recallDelayIncrement = 500) {
}
};

return (text, type = '', timeout = defaults.timeout, color) => {
this.msgs.push({text, type, timeout, color});
return (text, type = '', timeout = defaults.timeout, color, stylesheet) => {
this.msgs.push({text, type, timeout, color, stylesheet});
if (!this.isNotifying) {
this.showNotify();
}
Expand Down