Skip to content

Commit b41338d

Browse files
authored
feat(toast): horizontal variant and dynamic content support
This PR adds - the horizontal variant - dynamic setting of title, message, icon or image to a toast template create out of an existing DOM node - makes the close duration time configurable just as it is possible for show/hide duration to the toast module.
1 parent 19806d4 commit b41338d

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/definitions/modules/toast.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ $.fn.toast = function(parameters) {
144144
create: {
145145
container: function() {
146146
module.verbose('Creating container');
147-
$context.append($('<div/>',{class: settings.position + ' ' + className.container}));
147+
$context.append($('<div/>',{class: settings.position + ' ' + className.container + ' ' +(settings.horizontal ? className.horizontal : '')}));
148148
},
149149
toast: function() {
150150
$toastBox = $('<div/>', {class: className.box});
151+
var iconClass = module.get.iconClass();
151152
if (!isToastComponent) {
152153
module.verbose('Creating toast');
153154
$toast = $('<div/>');
154155
var $content = $('<div/>', {class: className.content});
155-
var iconClass = module.get.iconClass();
156156
if (iconClass !== '') {
157157
$toast.append($('<i/>', {class: iconClass + ' ' + className.icon}));
158158
}
@@ -170,7 +170,7 @@ $.fn.toast = function(parameters) {
170170
}));
171171
}
172172

173-
$content.append($('<div/>', {html: module.helpers.escape(settings.message, settings.preserveHTML)}));
173+
$content.append($('<div/>', {class: className.message, html: module.helpers.escape(settings.message, settings.preserveHTML)}));
174174

175175
$toast
176176
.addClass(settings.class + ' ' + className.toast)
@@ -189,6 +189,18 @@ $.fn.toast = function(parameters) {
189189
$toast = settings.cloneModule ? $module.clone().removeAttr('id') : $module;
190190
$close = $toast.find('> i'+module.helpers.toClass(className.close));
191191
settings.closeIcon = ($close.length > 0);
192+
if (iconClass !== '') {
193+
$toast.find(selector.icon).attr('class',iconClass + ' ' + className.icon);
194+
}
195+
if (settings.showImage) {
196+
$toast.find(selector.image).attr('src',settings.showImage);
197+
}
198+
if (settings.title !== '') {
199+
$toast.find(selector.title).html(module.helpers.escape(settings.title, settings.preserveHTML));
200+
}
201+
if (settings.message !== '') {
202+
$toast.find(selector.message).html(module.helpers.escape(settings.message, settings.preserveHTML));
203+
}
192204
}
193205
if ($toast.hasClass(className.compact)) {
194206
settings.compact = true;
@@ -391,7 +403,7 @@ $.fn.toast = function(parameters) {
391403
if(settings.transition.closeEasing !== ''){
392404
if($toastBox) {
393405
$toastBox.css('opacity', 0);
394-
$toastBox.wrap('<div/>').parent().slideUp(500, settings.transition.closeEasing, function () {
406+
$toastBox.wrap('<div/>').parent().hide(settings.transition.closeDuration, settings.transition.closeEasing, function () {
395407
if ($toastBox) {
396408
$toastBox.parent().remove();
397409
callback.call($toastBox);
@@ -431,7 +443,7 @@ $.fn.toast = function(parameters) {
431443
has: {
432444
container: function() {
433445
module.verbose('Determining if there is already a container');
434-
return ($context.find(module.helpers.toClass(settings.position) + selector.container).length > 0);
446+
return ($context.find(module.helpers.toClass(settings.position) + selector.container + (settings.horizontal ? module.helpers.toClass(className.horizontal) : '')).length > 0);
435447
},
436448
toast: function(){
437449
return !!module.get.toast();
@@ -750,6 +762,7 @@ $.fn.toast.settings = {
750762
context : 'body',
751763

752764
position : 'top right',
765+
horizontal : false,
753766
class : 'neutral',
754767
classProgress : false,
755768
classActions : false,
@@ -780,7 +793,8 @@ $.fn.toast.settings = {
780793
showDuration : 500,
781794
hideMethod : 'scale',
782795
hideDuration : 500,
783-
closeEasing : 'easeOutCubic' //Set to empty string to stack the closed toast area immediately (old behaviour)
796+
closeEasing : 'easeOutCubic', //Set to empty string to stack the closed toast area immediately (old behaviour)
797+
closeDuration: 500
784798
},
785799

786800
error: {
@@ -798,13 +812,15 @@ $.fn.toast.settings = {
798812
visible : 'visible',
799813
content : 'content',
800814
title : 'ui header',
815+
message : 'message',
801816
actions : 'actions',
802817
extraContent : 'extra content',
803818
button : 'ui button',
804819
buttons : 'ui buttons',
805820
close : 'close icon',
806821
image : 'ui image',
807822
vertical : 'vertical',
823+
horizontal : 'horizontal',
808824
attached : 'attached',
809825
inverted : 'inverted',
810826
compact : 'compact',
@@ -828,6 +844,10 @@ $.fn.toast.settings = {
828844
container : '.ui.toast-container',
829845
box : '.toast-box',
830846
toast : '.ui.toast',
847+
title : '.header',
848+
message : '.message:not(.ui)',
849+
image : '> img.image, > .image > img',
850+
icon : '> i.icon',
831851
input : 'input:not([type="hidden"]), textarea, select, button, .ui.button, ui.dropdown',
832852
approve : '.actions .positive, .actions .approve, .actions .ok',
833853
deny : '.actions .negative, .actions .deny, .actions .cancel'

src/definitions/modules/toast.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
.toast-box {
6565
display: table !important;
6666
}
67+
&.horizontal when (@variationToastHorizontal) {
68+
display: flex;
69+
flex-direction: row;
70+
& .toast-box {
71+
margin-right: @toastBoxMarginRight;
72+
}
73+
}
6774
& .toast-box {
6875
margin-bottom: @toastBoxMarginBottom;
6976
border-radius: @defaultBorderRadius;

src/themes/default/globals/variation.variables

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@
529529
@variationToastWarning: true;
530530
@variationToastSuccess: true;
531531
@variationToastError: true;
532+
@variationToastHorizontal: true;
532533
@variationToastFloating: true;
533534
@variationToastProgress: true;
534535
@variationToastIcon: true;

src/themes/default/modules/toast.variables

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@toastMarginBottom: -0.01em;
1313
@toastLeftRightMargin: 1px;
1414
@toastBoxMarginBottom: 0.5em;
15+
@toastBoxMarginRight: @toastBoxMarginBottom;
1516
@toastMarginProgress: -0.2em;
1617
@toastMargin: 0 -@toastLeftRightMargin @toastMarginBottom;
1718
@toastTextColor: @invertedTextColor;

0 commit comments

Comments
 (0)