-
Notifications
You must be signed in to change notification settings - Fork 379
feat(toastNotification): adds toast notification component #48
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,30 @@ | ||
| import { Dropdown } from 'react-bootstrap' | ||
| import ClassNames from 'classnames' | ||
| import React from 'react' | ||
| import PropTypes from 'prop-types' | ||
|
|
||
| const DropdownKebab = ({ children, id, pullRight }) => { | ||
| /** | ||
| * DropdownKebab Component for Patternfly React | ||
| */ | ||
| const DropdownKebab = ({ className, children, id, pullRight }) => { | ||
| const kebabClass = ClassNames('dropdown-kebab-pf', className) | ||
| return ( | ||
| <Dropdown className="dropdown-kebab-pf" id={id} pullRight={pullRight}> | ||
| <Dropdown className={kebabClass} id={id} pullRight={pullRight}> | ||
| <Dropdown.Toggle bsStyle="link" noCaret> | ||
| <span className="fa fa-ellipsis-v" /> | ||
| </Dropdown.Toggle> | ||
| <Dropdown.Menu> | ||
| {children} | ||
| </Dropdown.Menu> | ||
| <Dropdown.Menu>{children}</Dropdown.Menu> | ||
| </Dropdown> | ||
| ) | ||
| } | ||
| DropdownKebab.propTypes = { | ||
| /** additional kebab dropdown classes */ | ||
| className: PropTypes.string, | ||
| /** children nodes */ | ||
| children: PropTypes.node, | ||
| /** kebab dropdown id */ | ||
| id: PropTypes.string.isRequired, | ||
| /** menu right aligned */ | ||
| pullRight: PropTypes.bool | ||
| } | ||
| export default DropdownKebab |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import React from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import helpers from '../common/helpers' | ||
| import Timer from '../common/Timer' | ||
| import { TOAST_NOTIFICATION_TYPES } from '../common/constants' | ||
| import { ToastNotification } from '../index.js' | ||
|
|
||
| /** | ||
| * TimedToastNotification Component for Patternfly React | ||
| */ | ||
| class TimedToastNotification extends React.Component { | ||
| constructor(props) { | ||
| super(props) | ||
| helpers.bindMethods(this, ['onMouseEnter', 'onMouseLeave']) | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| const { paused, persistent, onDismiss, timerdelay } = this.props | ||
|
|
||
| if (!persistent) { | ||
| this.timer = new Timer(onDismiss, timerdelay) | ||
| this.timer.startTimer() | ||
| } | ||
|
|
||
| /** if we are paused on mount, then clear the timer | ||
| * after having initialized with the correct delay */ | ||
| if (paused) { | ||
| this.timer && this.timer.clearTimer() | ||
| } | ||
| } | ||
|
|
||
| componentWillReceiveProps(nextProps) { | ||
| /** | ||
| * If paused prop changes, update our timer | ||
| */ | ||
| if (nextProps.paused !== this.props.paused) { | ||
| if (nextProps.paused) { | ||
| this.timer && this.timer.clearTimer() | ||
| } else { | ||
| this.timer && this.timer.startTimer() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| this.timer && this.timer.clearTimer() | ||
| } | ||
|
|
||
| onMouseEnter() { | ||
| const { onMouseEnter } = this.props | ||
| onMouseEnter && onMouseEnter() | ||
| } | ||
|
|
||
| onMouseLeave() { | ||
| const { onMouseLeave } = this.props | ||
| onMouseLeave && onMouseLeave() | ||
| } | ||
| render() { | ||
| const { children } = this.props | ||
| return ( | ||
| <ToastNotification | ||
| {...this.props} | ||
| onMouseEnter={this.onMouseEnter} | ||
| onMouseLeave={this.onMouseLeave} | ||
| > | ||
| {children} | ||
| </ToastNotification> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| TimedToastNotification.propTypes = { | ||
| /** pauses notification from dismissing */ | ||
| paused: PropTypes.bool, | ||
| /** persistent keeps the notification up endlessly until closed */ | ||
| persistent: PropTypes.bool, | ||
| /** timer delay until dismiss */ | ||
| timerdelay: PropTypes.number, | ||
| /** additional notification classes */ | ||
| className: PropTypes.string, // eslint-disable-line react/no-unused-prop-types | ||
| /** callback when alert is dismissed */ | ||
| onDismiss: PropTypes.func, | ||
| /** onMouseEnter callback */ | ||
| onMouseEnter: PropTypes.func, | ||
| /** onMouseLeave callback */ | ||
| onMouseLeave: PropTypes.func, | ||
| /** the type of alert */ | ||
| type: PropTypes.oneOf(TOAST_NOTIFICATION_TYPES).isRequired, // eslint-disable-line react/no-unused-prop-types | ||
| /** children nodes */ | ||
| children: PropTypes.node | ||
| } | ||
| TimedToastNotification.defaultProps = { | ||
| paused: false, | ||
| type: 'error', | ||
| timerdelay: 8000 | ||
| } | ||
|
|
||
| export default TimedToastNotification | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import ClassNames from 'classnames' | ||
| import React from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import { Button } from '../index' | ||
| import { TOAST_NOTIFICATION_TYPES } from '../common/constants' | ||
|
|
||
| /** | ||
| * ToastNotification Component for Patternfly React | ||
| */ | ||
| const ToastNotification = ({ | ||
| className, | ||
| onDismiss, | ||
| type, | ||
| onMouseEnter, | ||
| onMouseLeave, | ||
| children, | ||
| ...props | ||
| }) => { | ||
| const notificationClasses = ClassNames( | ||
| { | ||
| alert: true, | ||
| 'toast-pf': true, | ||
| 'alert-danger': type === 'danger' || type === 'error', | ||
| 'alert-warning': type === 'warning', | ||
| 'alert-success': type === 'success', | ||
| 'alert-info': type === 'info', | ||
| 'alert-dismissable': onDismiss | ||
| }, | ||
| className | ||
| ) | ||
| const iconClass = ClassNames({ | ||
| pficon: true, | ||
| 'pficon-error-circle-o': type === 'danger' || type === 'error', | ||
| 'pficon-warning-triangle-o': type === 'warning', | ||
| 'pficon-ok': type === 'success', | ||
| 'pficon-info': type === 'info' | ||
| }) | ||
|
|
||
| return ( | ||
| <div | ||
| className={notificationClasses} | ||
| onMouseEnter={onMouseEnter} | ||
| onMouseLeave={onMouseLeave} | ||
| {...props} | ||
| > | ||
| {onDismiss && | ||
| <Button bsClass="close" aria-hidden="true" onClick={onDismiss}> | ||
| <span className="pficon pficon-close" /> | ||
| </Button>} | ||
| <span className={iconClass} /> | ||
| {children} | ||
| </div> | ||
| ) | ||
| } | ||
| ToastNotification.propTypes = { | ||
| /** additional notification classes */ | ||
| className: PropTypes.string, | ||
| /** callback when alert is dismissed */ | ||
| onDismiss: PropTypes.func, | ||
| /** the type of alert */ | ||
| type: PropTypes.oneOf(TOAST_NOTIFICATION_TYPES).isRequired, | ||
| /** onMouseEnter callback */ | ||
| onMouseEnter: PropTypes.func, | ||
| /** onMouseLeave callback */ | ||
| onMouseLeave: PropTypes.func, | ||
| /** children nodes */ | ||
| children: PropTypes.node | ||
| } | ||
| ToastNotification.defaultProps = { | ||
| type: 'error' | ||
| } | ||
|
|
||
| export default ToastNotification |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onMouseEnter and onMouseLeave functions should be run when user hovers on ToastNotificationList rather than each individual ToastNotification. User wants to pause all notifications timers when hovering over ToastNotificationList.
So to achieve this, ToastNotificationList will keep 'paused' boolean in its state and toggle it with it's onMouseEnter and onMouseLeave callbacks.
TimedToastNotification will receive 'paused' prop from ToastNotificationList via passing props to children:
TimedToastNotification then updates it's timer in componentWillReceiveProps instead of doing it in onMouseEnter/Leave functions.
With this onMouseEnter/Leave props are not needed in ToastNotification unless we really want to keep it around for flexibility.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the detailed feedback @jtomasek ... i think this works better (and agree it would be weird to see other alerts dismiss if not hovered while hovering another one). I prefer with leaving the onMouseEnter/Leave available at the ToastNotification level as well as providing onMouseEnter/Leave on the ToastNotificationList (for more fine grained control if desired). i will make this update soon :)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtomasek i've made updates to account for this now...
ToastNotificationListnow haspausedstate and propogates this to childrenTimeToastNotification(ensuring that no other toast notifications will dismiss if a single one is hovered). If any notification is hovered, all notifications will reset their timer.I am also allowing the consumer to observe onMouseEnter/onMouseLeave on the entire list or on each individual notification. I am aiming for as much flexibility as possible!