From 380ddef569fbdc127a5e5d4a817891cea5a9026e Mon Sep 17 00:00:00 2001
From: Chandler Prall
Date: Tue, 12 Mar 2019 09:12:50 -0600
Subject: [PATCH 1/2] Add a toast-specific toastLifeTimeMs override value on
EuiGlobalToastList
---
src-docs/src/views/toast/toast_list.js | 11 ++++++++
src/components/toast/global_toast_list.js | 13 ++++++++--
.../toast/global_toast_list.test.js | 26 +++++++++++++++++++
3 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/src-docs/src/views/toast/toast_list.js b/src-docs/src/views/toast/toast_list.js
index 095bf13a379..9a8796110a4 100644
--- a/src-docs/src/views/toast/toast_list.js
+++ b/src-docs/src/views/toast/toast_list.js
@@ -4,6 +4,7 @@ import React, {
} from 'react';
import {
+ EuiCode,
EuiGlobalToastList,
EuiLink,
} from '../../../../src/components';
@@ -97,6 +98,16 @@ export default class extends Component {
Sorry. We’ll try not to let it happen it again.
),
+ }, {
+ title: 'Long toast',
+ color: 'warning',
+ iconType: 'clock',
+ toastLifeTimeMs: 15000,
+ text: (
+
+ This toast overrides the default toastLifeTimeMs value and will be around for 15 seconds.
+
+ ),
}];
return {
diff --git a/src/components/toast/global_toast_list.js b/src/components/toast/global_toast_list.js
index 98d7f161f99..b1e789fb502 100644
--- a/src/components/toast/global_toast_list.js
+++ b/src/components/toast/global_toast_list.js
@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Timer } from '../../services/time';
+import { ICON_TYPES } from '../icon';
import { EuiGlobalToastListItem } from './global_toast_list_item';
import { EuiToast } from './toast';
@@ -32,7 +33,14 @@ export class EuiGlobalToastList extends Component {
static propTypes = {
className: PropTypes.string,
- toasts: PropTypes.array,
+ toasts: PropTypes.arrayOf(PropTypes.shape({
+ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
+ title: PropTypes.string,
+ text: PropTypes.node,
+ color: PropTypes.string,
+ iconType: PropTypes.oneOf(ICON_TYPES),
+ toastLifeTimeMs: PropTypes.number,
+ }).isRequired),
dismissToast: PropTypes.func.isRequired,
toastLifeTimeMs: PropTypes.number.isRequired,
};
@@ -111,7 +119,7 @@ export class EuiGlobalToastList extends Component {
scheduleToastForDismissal = (toast) => {
// Start fading the toast out once its lifetime elapses.
this.toastIdToTimerMap[toast.id] =
- new Timer(this.dismissToast.bind(this, toast), this.props.toastLifeTimeMs);
+ new Timer(this.dismissToast.bind(this, toast), toast.toastLifeTimeMs != null ? toast.toastLifeTimeMs : this.props.toastLifeTimeMs);
};
dismissToast = (toast) => {
@@ -201,6 +209,7 @@ export class EuiGlobalToastList extends Component {
const renderedToasts = toasts.map(toast => {
const {
text,
+ toastLifeTimeMs, // eslint-disable-line no-unused-vars
...rest
} = toast;
diff --git a/src/components/toast/global_toast_list.test.js b/src/components/toast/global_toast_list.test.js
index 2117dab7884..5bcbf1a6427 100644
--- a/src/components/toast/global_toast_list.test.js
+++ b/src/components/toast/global_toast_list.test.js
@@ -99,6 +99,32 @@ describe('EuiGlobalToastList', () => {
done();
}, TOAST_LIFE_TIME_MS + TOAST_FADE_OUT_MS + 10);
});
+
+ test('toastLifeTimeMs is overrideable by individidual toasts', done => {
+ const TOAST_LIFE_TIME_MS = 10;
+ const TOAST_LIFE_TIME_MS_OVERRIDE = 100;
+ const dismissToastSpy = sinon.spy();
+ mount(
+
+ );
+
+ // The callback is invoked once the toast fades from view.
+ setTimeout(() => {
+ expect(dismissToastSpy.called).toBe(false);
+ }, TOAST_LIFE_TIME_MS + TOAST_FADE_OUT_MS + 10);
+ setTimeout(() => {
+ expect(dismissToastSpy.called).toBe(true);
+ done();
+ }, TOAST_LIFE_TIME_MS_OVERRIDE + TOAST_FADE_OUT_MS + 10);
+ });
});
});
});
From abd20a54894e4a3534e1833b02211a86bbc2e368 Mon Sep 17 00:00:00 2001
From: Chandler Prall
Date: Tue, 12 Mar 2019 09:18:43 -0600
Subject: [PATCH 2/2] changelog
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f30adccc760..0c2c98dfb52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)
-No public interface changes since `9.2.1`.
+- Allow toasts in `EuiGlobalToastList` to override `toastLifeTimeMs` ([#1720](https://github.com/elastic/eui/pull/1720))
## [`9.2.1`](https://github.com/elastic/eui/tree/v9.2.1)