Skip to content

Commit

Permalink
feat(popup): loading variant
Browse files Browse the repository at this point in the history
Added set loading behavior as remove loading already exists and used them (only) internally as well.
This is now also properly displayed with the usual loading spinner supporting slow/fast/double/colors

This might come in handy when someone want to lazy load popups manually
  • Loading branch information
lubber-de authored Jan 31, 2023
1 parent 52801a7 commit f3fb845
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
22 changes: 17 additions & 5 deletions src/definitions/modules/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@
}
}
if (settings.popup) {
$popup.addClass(className.loading);
module.set.invisible();
$offsetParent = module.get.offsetParent();
$popup.removeClass(className.loading);
module.remove.invisible();
if (settings.movePopup && module.has.popup() && module.get.offsetParent($popup)[0] !== $offsetParent[0]) {
module.debug('Moving popup to the same offset parent as target');
$popup
Expand Down Expand Up @@ -901,8 +901,8 @@
.css(positioning)
.removeClass(className.position)
.addClass(position)
.addClass(className.loading)
;
module.set.invisible();

popupOffset = module.get.popupOffset();

Expand All @@ -926,7 +926,7 @@
module.debug('Popup could not find a position to display', $popup);
module.error(error.cannotPlace, element);
module.remove.attempts();
module.remove.loading();
module.remove.invisible();
module.reset();
settings.onUnplaceable.call($popup, element);

Expand All @@ -935,7 +935,7 @@
}
module.debug('Position is on stage', position);
module.remove.attempts();
module.remove.loading();
module.remove.invisible();
if (settings.setFluidWidth && module.is.fluid()) {
module.set.fluidWidth(calculations);
}
Expand All @@ -949,6 +949,14 @@
$popup.css('width', calculations.container.width);
},

loading: function () {
$popup.addClass(className.loading);
},

invisible: function () {
$popup.addClass(className.invisible);
},

variation: function (variation) {
variation = variation || module.get.variation();
if (variation && module.has.popup()) {
Expand All @@ -966,6 +974,9 @@
loading: function () {
$popup.removeClass(className.loading);
},
invisible: function () {
$popup.removeClass(className.invisible);
},
variation: function (variation) {
variation = variation || module.get.variation();
if (variation) {
Expand Down Expand Up @@ -1475,6 +1486,7 @@
basic: 'basic',
animating: 'animating',
dropdown: 'dropdown',
invisible: 'invisible',
fluid: 'fluid',
loading: 'loading',
popup: 'ui popup',
Expand Down
50 changes: 47 additions & 3 deletions src/definitions/modules/popup.less
Original file line number Diff line number Diff line change
Expand Up @@ -704,12 +704,36 @@
*******************************/
& when (@variationPopupLoading) {
.ui.loading.popup {
display: block;
visibility: hidden;
z-index: @loadingZIndex;
cursor: default;
pointer-events: @loadingPointerEvents;
user-select: none;
& * {
opacity: @loadingOpacity;
}
&::after {
position: absolute;
content: "";
top: 50%;
left: 50%;
margin: @loaderMargin;
width: @loaderSize;
height: @loaderSize;
animation: loader @loaderSpeed infinite linear;
border: @loaderLineWidth solid @loaderLineColor;
border-radius: @circularRadius;
box-shadow: 0 0 0 1px transparent;
visibility: visible;
z-index: @loaderLineZIndex;
}
}
}

.ui.invisible.popup {
display: block;
visibility: hidden !important;
z-index: @invisibleZIndex;
}

.ui.animating.popup,
.ui.visible.popup {
display: block;
Expand Down Expand Up @@ -807,13 +831,18 @@
@color: @value;
@c: @colors[@@color][color];
@l: @colors[@@color][light];
@cl: lighten(@c, @loadingColoredPercent);
@ll: darken(@l, @loadingColoredPercent);

& when not (@variationPopupTooltip) {
.ui.ui.ui.@{color}.popup::before,
.ui.@{color}.popup {
background: @c;
color: @white;
border: none;
.loading& when (@variationPopupLoading) {
background: @cl;
}
}
.ui.ui.ui.@{color}.popup::before {
box-shadow: none;
Expand All @@ -823,6 +852,9 @@
.ui.inverted.@{color}.popup {
background: @l;
color: @black;
.loading& when (@variationPopupLoading) {
background: @ll;
}
}
}
}
Expand All @@ -835,6 +867,12 @@
color: @white;
border: none;
}
& when (@variationPopupLoading) {
.ui.ui.ui.@{color}.loading.popup::before,
.ui.@{color}.loading.popup {
background: @cl;
}
}
.ui.ui.ui.@{color}.popup::before,
[data-tooltip][data-variation~="@{color}"]::before {
box-shadow: none;
Expand All @@ -847,6 +885,12 @@
background: @l;
color: @black;
}
& when (@variationPopupLoading) {
.ui.ui.ui.inverted.@{color}.loading.popup::before,
.ui.inverted.@{color}.loading.popup {
background: @ll;
}
}
}
}
});
Expand Down
8 changes: 8 additions & 0 deletions src/themes/default/modules/popup.variables
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@
States
-------------------- */

@loadingOpacity: 0.3;
@loadingColoredPercent: 30%;
@loadingPointerEvents: none;
@loadingZIndex: -1;
@loaderSize: 2em;
@loaderLineZIndex: 101;

/* backward compatible just in case */
@invisibleZIndex: @loadingZIndex;

/* -------------------
Variations
Expand Down

0 comments on commit f3fb845

Please sign in to comment.