Feature(toast): fix toast positioning
This commit is contained in:
@ -8,11 +8,19 @@ import { submitChallenge } from '../routes/challenges/redux/actions';
|
|||||||
|
|
||||||
const registeredActions = { submitChallenge };
|
const registeredActions = { submitChallenge };
|
||||||
const mapStateToProps = state => ({ toasts: state.toasts });
|
const mapStateToProps = state => ({ toasts: state.toasts });
|
||||||
|
// we use styles here to overwrite those built into the library
|
||||||
|
// but there are some styles applied using
|
||||||
|
// regular css in /client/less/toastr.less
|
||||||
const barStyle = {
|
const barStyle = {
|
||||||
fontSize: '2rem',
|
fontSize: '2rem',
|
||||||
// null values let our css set the style prop
|
// null values let our css set the style prop
|
||||||
padding: null
|
padding: null
|
||||||
};
|
};
|
||||||
|
const rightBarStyle = {
|
||||||
|
...barStyle,
|
||||||
|
left: null,
|
||||||
|
right: '-100%'
|
||||||
|
};
|
||||||
const actionStyle = {
|
const actionStyle = {
|
||||||
fontSize: '2rem'
|
fontSize: '2rem'
|
||||||
};
|
};
|
||||||
@ -21,16 +29,18 @@ const addDispatchableActionsToToast = createSelector(
|
|||||||
state => state.dispatch,
|
state => state.dispatch,
|
||||||
(toasts, dispatch) => toasts.map(({ position, actionCreator, ...toast }) => {
|
(toasts, dispatch) => toasts.map(({ position, actionCreator, ...toast }) => {
|
||||||
const activeBarStyle = {};
|
const activeBarStyle = {};
|
||||||
|
let finalBarStyle = barStyle;
|
||||||
if (position !== 'left') {
|
if (position !== 'left') {
|
||||||
activeBarStyle.left = null;
|
activeBarStyle.left = null;
|
||||||
activeBarStyle.right = '1rem';
|
activeBarStyle.right = '1rem';
|
||||||
|
finalBarStyle = rightBarStyle;
|
||||||
}
|
}
|
||||||
const onClick = registeredActions[actionCreator] ?
|
const onClick = registeredActions[actionCreator] ?
|
||||||
() => dispatch(registeredActions[actionCreator]()) :
|
() => dispatch(registeredActions[actionCreator]()) :
|
||||||
null;
|
null;
|
||||||
return {
|
return {
|
||||||
...toast,
|
...toast,
|
||||||
barStyle,
|
barStyle: finalBarStyle,
|
||||||
activeBarStyle,
|
activeBarStyle,
|
||||||
actionStyle,
|
actionStyle,
|
||||||
onClick
|
onClick
|
||||||
@ -49,6 +59,10 @@ export class Toasts extends React.Component {
|
|||||||
dispatch: PropTypes.func
|
dispatch: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
|
styleFactory(index, style) {
|
||||||
|
return { ...style, bottom: `${4 + index * 8}rem` };
|
||||||
|
}
|
||||||
|
|
||||||
handleDismiss(notification) {
|
handleDismiss(notification) {
|
||||||
this.props.dispatch(removeToast(notification));
|
this.props.dispatch(removeToast(notification));
|
||||||
}
|
}
|
||||||
@ -57,6 +71,8 @@ export class Toasts extends React.Component {
|
|||||||
const { toasts = [], dispatch } = this.props;
|
const { toasts = [], dispatch } = this.props;
|
||||||
return (
|
return (
|
||||||
<NotificationStack
|
<NotificationStack
|
||||||
|
activeBarStyle={ this.styleFactory }
|
||||||
|
barStyle={ this.styleFactory }
|
||||||
notifications={
|
notifications={
|
||||||
addDispatchableActionsToToast({ toasts, dispatch })
|
addDispatchableActionsToToast({ toasts, dispatch })
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ export const makeToast = createAction(
|
|||||||
// assign current value of key to new toast
|
// assign current value of key to new toast
|
||||||
// and then increment key value
|
// and then increment key value
|
||||||
key: key++,
|
key: key++,
|
||||||
dismissAfter: timeout || 40000,
|
dismissAfter: timeout || 10000,
|
||||||
position: rest.position === 'left' ? 'left' : 'right'
|
position: rest.position === 'left' ? 'left' : 'right'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
"react-images": "^0.4.6",
|
"react-images": "^0.4.6",
|
||||||
"react-motion": "~0.4.2",
|
"react-motion": "~0.4.2",
|
||||||
"react-no-ssr": "^1.0.1",
|
"react-no-ssr": "^1.0.1",
|
||||||
"react-notification": "^5.0.7",
|
"react-notification": "https://github.com/BerkeleyTrue/react-notification#freecodecamp",
|
||||||
"react-pure-render": "^1.0.2",
|
"react-pure-render": "^1.0.2",
|
||||||
"react-redux": "^4.0.6",
|
"react-redux": "^4.0.6",
|
||||||
"react-router": "^2.0.0",
|
"react-router": "^2.0.0",
|
||||||
|
Reference in New Issue
Block a user