Skip to content

Commit 5f948a9

Browse files
emyarodtw15egan
authored andcommitted
feat(Notification): Add timeout prop to ToastNotification, closes #846 (carbon-design-system#971)
* feat(Notification): Add `timeout` prop to ToastNotification, closes #846 * fix(Notification): set default ToastNotification timeout to 0
1 parent de65fa6 commit 5f948a9

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/components/Notification/Notification-story.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const notificationProps = {
1717
captionNode: <Link href="#">The caption can be any node.</Link>,
1818
iconDescription: 'describes the close button',
1919
style: { minWidth: '30rem', marginBottom: '.5rem' },
20+
timeout: 0,
2021
},
2122
inline: {
2223
onCloseButtonClick: action('onCloseButtonClick'),

src/components/Notification/Notification.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class ToastNotification extends Component {
108108
iconDescription: PropTypes.string.isRequired,
109109
notificationType: PropTypes.string,
110110
hideCloseButton: PropTypes.bool,
111+
timeout: PropTypes.number,
111112
};
112113

113114
static defaultProps = {
@@ -120,12 +121,21 @@ export class ToastNotification extends Component {
120121
iconDescription: 'closes notification',
121122
onCloseButtonClick: () => {},
122123
hideCloseButton: false,
124+
timeout: 0,
123125
};
124126

125127
state = {
126128
open: true,
127129
};
128130

131+
componentDidMount() {
132+
if (this.props.timeout) {
133+
setTimeout(() => {
134+
this.handleCloseButtonClick();
135+
}, this.props.timeout);
136+
}
137+
}
138+
129139
handleCloseButtonClick = evt => {
130140
this.setState({ open: false });
131141
this.props.onCloseButtonClick(evt);

yarn.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,8 +2761,9 @@ caniuse-lite@^1.0.30000791, caniuse-lite@^1.0.30000792:
27612761
version "1.0.30000792"
27622762
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000792.tgz#d0cea981f8118f3961471afbb43c9a1e5bbf0332"
27632763

2764-
"carbon-components@file:../carbon-components":
2765-
version "7.2.1"
2764+
carbon-components@^9.0.0:
2765+
version "9.0.2"
2766+
resolved "https://registry.yarnpkg.com/carbon-components/-/carbon-components-9.0.2.tgz#7e959808974cc464fad6098e791230e1972162d8"
27662767
dependencies:
27672768
carbon-icons "^6.0.4"
27682769
flatpickr "2.6.3"

0 commit comments

Comments
 (0)