Procházet zdrojové kódy

Merge branch 'master' into t/238

Szymon Kupś před 8 roky
rodič
revize
c35cadeb96

+ 31 - 4
packages/ckeditor5-ui/src/notification/notification.js

@@ -52,16 +52,23 @@ export default class Notification extends Plugin {
 	 * 		} );
 	 *
 	 * will fire `show:success:upload:image` event.
+	 * Title of the notification can be provided:
+	 *
+	 *		showSuccess( 'Image is uploaded.', {
+	 *			title: 'Image upload success'
+	 *		});
 	 *
 	 * @param {String} message Content of the notification.
 	 * @param {Object} [data={}] Additional data.
 	 * @param {String} [data.namespace] Additional event namespace.
+	 * @param {String} [data.title] Title of the notification.
 	 */
 	showSuccess( message, data = {} ) {
 		this._showNotification( {
 			message,
 			type: 'success',
-			namespace: data.namespace
+			namespace: data.namespace,
+			title: data.title
 		} );
 	}
 
@@ -76,16 +83,23 @@ export default class Notification extends Plugin {
 	 * 		} );
 	 *
 	 * will fire `show:info:editor:status` event.
+	 * Title of the notification can be provided:
+	 *
+	 *		showInfo( 'Editor is offline.', {
+	 *			title: 'Network information'
+	 *		});
 	 *
 	 * @param {String} message Content of the notification.
 	 * @param {Object} [data={}] Additional data.
 	 * @param {String} [data.namespace] Additional event namespace.
+	 * @param {String} [data.title] Title of the notification.
 	 */
 	showInfo( message, data = {} ) {
 		this._showNotification( {
 			message,
 			type: 'info',
-			namespace: data.namespace
+			namespace: data.namespace,
+			title: data.title
 		} );
 	}
 
@@ -100,6 +114,11 @@ export default class Notification extends Plugin {
 	 * 		} );
 	 *
 	 * will fire `show:warning:upload:image` event.
+	 * Title of the notification can be provided:
+	 *
+	 *		showWarning( 'Image upload error.', {
+	 *			title: 'Upload failed'
+	 *		});
 	 *
 	 * Note that each unhandled and not stopped `warning` notification will be displayed as system alert.
 	 * Plugin responsible for displaying warnings should `stop()` the event to prevent of displaying it as alert:
@@ -127,12 +146,14 @@ export default class Notification extends Plugin {
 	 * @param {String} message Content of the notification.
 	 * @param {Object} [data={}] Additional data.
 	 * @param {String} [data.namespace] Additional event namespace.
+	 * @param {String} [data.title] Title of the notification.
 	 */
 	showWarning( message, data = {} ) {
 		this._showNotification( {
 			message,
 			type: 'warning',
-			namespace: data.namespace
+			namespace: data.namespace,
+			title: data.title
 		} );
 	}
 
@@ -144,13 +165,15 @@ export default class Notification extends Plugin {
 	 * @param {String} data.message Content of the notification.
 	 * @param {'success'|'info'|'warning'} data.type Type of message.
 	 * @param {String} [data.namespace] Additional event namespace.
+	 * @param {String} [data.title=''] Title of the notification.
 	 */
 	_showNotification( data ) {
 		const event = `show:${ data.type }` + ( data.namespace ? `:${ data.namespace }` : '' );
 
 		this.fire( event, {
 			message: data.message,
-			type: data.type
+			type: data.type,
+			title: data.title || ''
 		} );
 	}
 
@@ -160,6 +183,7 @@ export default class Notification extends Plugin {
 	 * @event show
 	 * @param {Object} data Notification data.
 	 * @param {String} data.message Content of the notification.
+	 * @param {String} data.title Title of the notification.
 	 * @param {'success'|'info'|'warning'} data.type Type of notification.
 	 */
 
@@ -169,6 +193,7 @@ export default class Notification extends Plugin {
 	 * @event show:success
 	 * @param {Object} data Notification data.
 	 * @param {String} data.message Content of the notification.
+	 * @param {String} data.title Title of the notification.
 	 * @param {'success'} data.type Type of notification.
 	 */
 
@@ -178,6 +203,7 @@ export default class Notification extends Plugin {
 	 * @event show:info
 	 * @param {Object} data Notification data.
 	 * @param {String} data.message Content of the notification.
+	 * @param {String} data.title Title of the notification.
 	 * @param {'info'} data.type Type of notification.
 	 */
 
@@ -190,6 +216,7 @@ export default class Notification extends Plugin {
 	 * @event show:warning
 	 * @param {Object} data Notification data.
 	 * @param {String} data.message Content of the notification.
+	 * @param {String} data.title Title of the notification.
 	 * @param {'warning'} data.type Type of notification.
 	 */
 }

+ 63 - 6
packages/ckeditor5-ui/tests/notification/notification.js

@@ -42,7 +42,8 @@ describe( 'Notification', () => {
 			sinon.assert.calledOnce( spy );
 			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
 				message: 'foo bar',
-				type: 'success'
+				type: 'success',
+				title: ''
 			} );
 		} );
 
@@ -58,7 +59,25 @@ describe( 'Notification', () => {
 			sinon.assert.calledOnce( spy );
 			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
 				message: 'foo bar',
-				type: 'success'
+				type: 'success',
+				title: ''
+			} );
+		} );
+
+		it( 'should fire `show:success` event with title', () => {
+			const spy = testUtils.sinon.spy();
+
+			notification.on( 'show:success', spy );
+
+			notification.showSuccess( 'foo bar', {
+				title: 'foo bar baz'
+			} );
+
+			sinon.assert.calledOnce( spy );
+			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
+				message: 'foo bar',
+				type: 'success',
+				title: 'foo bar baz'
 			} );
 		} );
 	} );
@@ -74,7 +93,8 @@ describe( 'Notification', () => {
 			sinon.assert.calledOnce( spy );
 			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
 				message: 'foo bar',
-				type: 'info'
+				type: 'info',
+				title: ''
 			} );
 		} );
 
@@ -90,7 +110,25 @@ describe( 'Notification', () => {
 			sinon.assert.calledOnce( spy );
 			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
 				message: 'foo bar',
-				type: 'info'
+				type: 'info',
+				title: ''
+			} );
+		} );
+
+		it( 'should fire `show:info` event with title', () => {
+			const spy = testUtils.sinon.spy();
+
+			notification.on( 'show:info', spy );
+
+			notification.showInfo( 'foo bar', {
+				title: 'foo bar baz'
+			} );
+
+			sinon.assert.calledOnce( spy );
+			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
+				message: 'foo bar',
+				type: 'info',
+				title: 'foo bar baz'
 			} );
 		} );
 	} );
@@ -112,7 +150,8 @@ describe( 'Notification', () => {
 			sinon.assert.calledOnce( spy );
 			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
 				message: 'foo bar',
-				type: 'warning'
+				type: 'warning',
+				title: ''
 			} );
 		} );
 
@@ -128,7 +167,25 @@ describe( 'Notification', () => {
 			sinon.assert.calledOnce( spy );
 			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
 				message: 'foo bar',
-				type: 'warning'
+				type: 'warning',
+				title: ''
+			} );
+		} );
+
+		it( 'should fire `show:warning` event with title', () => {
+			const spy = testUtils.sinon.spy();
+
+			notification.on( 'show:warning', spy );
+
+			notification.showWarning( 'foo bar', {
+				title: 'foo bar baz'
+			} );
+
+			sinon.assert.calledOnce( spy );
+			expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
+				message: 'foo bar',
+				type: 'warning',
+				title: 'foo bar baz'
 			} );
 		} );