Skip to content
Merged
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
76 changes: 36 additions & 40 deletions src/components/ToastNotification/ToastNotification.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,47 @@ stories.add(
class ToastNotificationStoryWrapper extends React.Component {
constructor(props) {
super(props);
const notificationList = [
{
key: 1,
type: 'info',
persistent: false,
timerdelay: 8000,
message: `By default, a toast notification's timer expires after eight seconds.`
},
{
key: 2,
type: 'warning',
persistent: false,
message: `Additionally, if the user hovers any toast notification each timer is reset.`
}
];

this.state = {
infoNotificationDismissed: false,
warningNotificationDismissed: false,
notifications: notificationList,
persistentNotificationDismissed: false
};

this.infoNotificationDismissed = () => {
action('info notification: onDismiss fired')();
this.setState({ infoNotificationDismissed: true });
};

this.warningNotificationDismissed = () => {
action('warning notification: onDismiss fired')();
this.setState({ warningNotificationDismissed: true });
};

this.persistentNotificationDismissed = () => {
action('persistent notification: onDismiss fired')();
this.setState({ persistentNotificationDismissed: true });
};

this.resetStateClicked = () => {
this.setState({
infoNotificationDismissed: false,
warningNotificationDismissed: false,
notifications: notificationList,
persistentNotificationDismissed: false
});
};

this.removeNotificationAction = notificationToRemove => {
action(`${notificationToRemove.type} notification: onDismiss fired`)();
this.setState({
notifications: this.state.notifications.filter(
notification => notificationToRemove.key !== notification.key
)
});
};
}

render() {
Expand All @@ -119,37 +132,20 @@ class ToastNotificationStoryWrapper extends React.Component {
onMouseOver={action('notification list: onMouseOver fired')}
onFocus={action('notification list: onFocus fired')}
>
{!this.state.infoNotificationDismissed && (
<TimedToastNotification
timerdelay={8000}
type="info"
onDismiss={this.infoNotificationDismissed}
onMouseEnter={action('info notification: onMouseEnter fired')}
onMouseLeave={action('info notification: onMouseLeave fired')}
>
<span>
{text(
'Message',
"By default, a toast notification's timer expires after eight seconds."
)}
</span>
</TimedToastNotification>
)}
<br />
{!this.state.warningNotificationDismissed && (
{this.state.notifications.map(notification => (
<TimedToastNotification
timerdelay={8000}
type="warning"
onDismiss={this.warningNotificationDismissed}
onMouseEnter={action('warning notification: onMouseEnter fired')}
onMouseLeave={action('warning notification: onMouseLeave fired')}
key={notification.key}
type={notification.type}
persistent={notification.persistent}
onDismiss={() => this.removeNotificationAction(notification)}
timerdelay={notification.timerdelay}
>
<span>
Additionally, if the user hovers any toast notification each
timer is reset.
{notification.header && <strong>{notification.header}</strong>}
{notification.message}
</span>
</TimedToastNotification>
)}
))}
{!this.state.persistentNotificationDismissed && (
<TimedToastNotification
persistent
Expand Down