Skip to content

Commit

Permalink
feat(toast): horizontal variant and dynamic content support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lubber-de authored Nov 19, 2020
1 parent 19806d4 commit b41338d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/definitions/modules/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ $.fn.toast = function(parameters) {
create: {
container: function() {
module.verbose('Creating container');
$context.append($('<div/>',{class: settings.position + ' ' + className.container}));
$context.append($('<div/>',{class: settings.position + ' ' + className.container + ' ' +(settings.horizontal ? className.horizontal : '')}));
},
toast: function() {
$toastBox = $('<div/>', {class: className.box});
var iconClass = module.get.iconClass();
if (!isToastComponent) {
module.verbose('Creating toast');
$toast = $('<div/>');
var $content = $('<div/>', {class: className.content});
var iconClass = module.get.iconClass();
if (iconClass !== '') {
$toast.append($('<i/>', {class: iconClass + ' ' + className.icon}));
}
Expand All @@ -170,7 +170,7 @@ $.fn.toast = function(parameters) {
}));
}

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

$toast
.addClass(settings.class + ' ' + className.toast)
Expand All @@ -189,6 +189,18 @@ $.fn.toast = function(parameters) {
$toast = settings.cloneModule ? $module.clone().removeAttr('id') : $module;
$close = $toast.find('> i'+module.helpers.toClass(className.close));
settings.closeIcon = ($close.length > 0);
if (iconClass !== '') {
$toast.find(selector.icon).attr('class',iconClass + ' ' + className.icon);
}
if (settings.showImage) {
$toast.find(selector.image).attr('src',settings.showImage);
}
if (settings.title !== '') {
$toast.find(selector.title).html(module.helpers.escape(settings.title, settings.preserveHTML));
}
if (settings.message !== '') {
$toast.find(selector.message).html(module.helpers.escape(settings.message, settings.preserveHTML));
}
}
if ($toast.hasClass(className.compact)) {
settings.compact = true;
Expand Down Expand Up @@ -391,7 +403,7 @@ $.fn.toast = function(parameters) {
if(settings.transition.closeEasing !== ''){
if($toastBox) {
$toastBox.css('opacity', 0);
$toastBox.wrap('<div/>').parent().slideUp(500, settings.transition.closeEasing, function () {
$toastBox.wrap('<div/>').parent().hide(settings.transition.closeDuration, settings.transition.closeEasing, function () {
if ($toastBox) {
$toastBox.parent().remove();
callback.call($toastBox);
Expand Down Expand Up @@ -431,7 +443,7 @@ $.fn.toast = function(parameters) {
has: {
container: function() {
module.verbose('Determining if there is already a container');
return ($context.find(module.helpers.toClass(settings.position) + selector.container).length > 0);
return ($context.find(module.helpers.toClass(settings.position) + selector.container + (settings.horizontal ? module.helpers.toClass(className.horizontal) : '')).length > 0);
},
toast: function(){
return !!module.get.toast();
Expand Down Expand Up @@ -750,6 +762,7 @@ $.fn.toast.settings = {
context : 'body',

position : 'top right',
horizontal : false,
class : 'neutral',
classProgress : false,
classActions : false,
Expand Down Expand Up @@ -780,7 +793,8 @@ $.fn.toast.settings = {
showDuration : 500,
hideMethod : 'scale',
hideDuration : 500,
closeEasing : 'easeOutCubic' //Set to empty string to stack the closed toast area immediately (old behaviour)
closeEasing : 'easeOutCubic', //Set to empty string to stack the closed toast area immediately (old behaviour)
closeDuration: 500
},

error: {
Expand All @@ -798,13 +812,15 @@ $.fn.toast.settings = {
visible : 'visible',
content : 'content',
title : 'ui header',
message : 'message',
actions : 'actions',
extraContent : 'extra content',
button : 'ui button',
buttons : 'ui buttons',
close : 'close icon',
image : 'ui image',
vertical : 'vertical',
horizontal : 'horizontal',
attached : 'attached',
inverted : 'inverted',
compact : 'compact',
Expand All @@ -828,6 +844,10 @@ $.fn.toast.settings = {
container : '.ui.toast-container',
box : '.toast-box',
toast : '.ui.toast',
title : '.header',
message : '.message:not(.ui)',
image : '> img.image, > .image > img',
icon : '> i.icon',
input : 'input:not([type="hidden"]), textarea, select, button, .ui.button, ui.dropdown',
approve : '.actions .positive, .actions .approve, .actions .ok',
deny : '.actions .negative, .actions .deny, .actions .cancel'
Expand Down
7 changes: 7 additions & 0 deletions src/definitions/modules/toast.less
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
.toast-box {
display: table !important;
}
&.horizontal when (@variationToastHorizontal) {
display: flex;
flex-direction: row;
& .toast-box {
margin-right: @toastBoxMarginRight;
}
}
& .toast-box {
margin-bottom: @toastBoxMarginBottom;
border-radius: @defaultBorderRadius;
Expand Down
1 change: 1 addition & 0 deletions src/themes/default/globals/variation.variables
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
@variationToastWarning: true;
@variationToastSuccess: true;
@variationToastError: true;
@variationToastHorizontal: true;
@variationToastFloating: true;
@variationToastProgress: true;
@variationToastIcon: true;
Expand Down
1 change: 1 addition & 0 deletions src/themes/default/modules/toast.variables
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@toastMarginBottom: -0.01em;
@toastLeftRightMargin: 1px;
@toastBoxMarginBottom: 0.5em;
@toastBoxMarginRight: @toastBoxMarginBottom;
@toastMarginProgress: -0.2em;
@toastMargin: 0 -@toastLeftRightMargin @toastMarginBottom;
@toastTextColor: @invertedTextColor;
Expand Down

0 comments on commit b41338d

Please sign in to comment.