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

Add in custom settings argument #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 16 additions & 9 deletions src/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Toast extends React.Component {
style: PropTypes.oneOfType([
PropTypes.object,
PropTypes.bool
])
]),
settings: PropTypes.object
};

state = {
Expand All @@ -35,7 +36,6 @@ class Toast extends React.Component {

const containerStyle = {
position: 'fixed',
Copy link
Owner

Choose a reason for hiding this comment

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

What's the behaviour when this width is removed?. (I agree that 50% is not a very smart default here). But does it break layout if you don't pass the fullWidth setting?

Copy link
Author

Choose a reason for hiding this comment

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

I actually removed this as it didn't have an effect on the width. The 0px left and right on a fixed position element would override the width settings.

width: '50%',
margin: '0 auto',
right: '0px',
top: '-100px',
Expand Down Expand Up @@ -66,6 +66,13 @@ class Toast extends React.Component {
pointerEvents: 'all'
};

/* Allow custom definition of a width */
if (this.props.settings.fullWidth) {
contentStyle.width = '100%';
contentStyle.display = 'block';
contentStyle.margin = '0 auto';
}

/* If type is set, merge toast action styles with base */
switch (this.props.type) {
case 'success':
Expand Down Expand Up @@ -172,9 +179,9 @@ class Toast extends React.Component {
/* Private Functions */

/* Render React component */
function renderToast(text, type, timeout, color) {
function renderToast(text, type, timeout, color, settings) {
ReactDOM.render(
<Toast text={text} timeout={timeout} type={type} color={color}/>,
<Toast text={text} timeout={timeout} type={type} color={color} settings={settings}/>,
document.getElementById(notificationWrapperId)
);
}
Expand All @@ -188,7 +195,7 @@ function hideToast() {

/* Show Animated Toast Message */
/* Returns true if the toast was shown, or false if show failed due to an existing notification */
function show(text, type, timeout, color) {
function show(text, type, timeout, color, settings) {
if (!document.getElementById(notificationWrapperId).hasChildNodes()) {
let renderTimeout = timeout;

Expand All @@ -198,7 +205,7 @@ function show(text, type, timeout, color) {
}

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

if (timeout === -1) {
return false;
Expand Down Expand Up @@ -247,7 +254,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.settings)) {
this.currentRecallDelay = initialRecallDelay;
if (current.timeout > 0) {
setTimeout(() => this.showNotify(), current.timeout + animationDuration);
Expand All @@ -260,8 +267,8 @@ function createShowQueue(initialRecallDelay = 500, recallDelayIncrement = 500) {
}
};

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