Skip to content

Commit f3fb845

Browse files
authored
feat(popup): loading variant
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
1 parent 52801a7 commit f3fb845

File tree

3 files changed

+72
-8
lines changed

3 files changed

+72
-8
lines changed

src/definitions/modules/popup.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@
125125
}
126126
}
127127
if (settings.popup) {
128-
$popup.addClass(className.loading);
128+
module.set.invisible();
129129
$offsetParent = module.get.offsetParent();
130-
$popup.removeClass(className.loading);
130+
module.remove.invisible();
131131
if (settings.movePopup && module.has.popup() && module.get.offsetParent($popup)[0] !== $offsetParent[0]) {
132132
module.debug('Moving popup to the same offset parent as target');
133133
$popup
@@ -901,8 +901,8 @@
901901
.css(positioning)
902902
.removeClass(className.position)
903903
.addClass(position)
904-
.addClass(className.loading)
905904
;
905+
module.set.invisible();
906906

907907
popupOffset = module.get.popupOffset();
908908

@@ -926,7 +926,7 @@
926926
module.debug('Popup could not find a position to display', $popup);
927927
module.error(error.cannotPlace, element);
928928
module.remove.attempts();
929-
module.remove.loading();
929+
module.remove.invisible();
930930
module.reset();
931931
settings.onUnplaceable.call($popup, element);
932932

@@ -935,7 +935,7 @@
935935
}
936936
module.debug('Position is on stage', position);
937937
module.remove.attempts();
938-
module.remove.loading();
938+
module.remove.invisible();
939939
if (settings.setFluidWidth && module.is.fluid()) {
940940
module.set.fluidWidth(calculations);
941941
}
@@ -949,6 +949,14 @@
949949
$popup.css('width', calculations.container.width);
950950
},
951951

952+
loading: function () {
953+
$popup.addClass(className.loading);
954+
},
955+
956+
invisible: function () {
957+
$popup.addClass(className.invisible);
958+
},
959+
952960
variation: function (variation) {
953961
variation = variation || module.get.variation();
954962
if (variation && module.has.popup()) {
@@ -966,6 +974,9 @@
966974
loading: function () {
967975
$popup.removeClass(className.loading);
968976
},
977+
invisible: function () {
978+
$popup.removeClass(className.invisible);
979+
},
969980
variation: function (variation) {
970981
variation = variation || module.get.variation();
971982
if (variation) {
@@ -1475,6 +1486,7 @@
14751486
basic: 'basic',
14761487
animating: 'animating',
14771488
dropdown: 'dropdown',
1489+
invisible: 'invisible',
14781490
fluid: 'fluid',
14791491
loading: 'loading',
14801492
popup: 'ui popup',

src/definitions/modules/popup.less

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,36 @@
704704
*******************************/
705705
& when (@variationPopupLoading) {
706706
.ui.loading.popup {
707-
display: block;
708-
visibility: hidden;
709-
z-index: @loadingZIndex;
707+
cursor: default;
708+
pointer-events: @loadingPointerEvents;
709+
user-select: none;
710+
& * {
711+
opacity: @loadingOpacity;
712+
}
713+
&::after {
714+
position: absolute;
715+
content: "";
716+
top: 50%;
717+
left: 50%;
718+
margin: @loaderMargin;
719+
width: @loaderSize;
720+
height: @loaderSize;
721+
animation: loader @loaderSpeed infinite linear;
722+
border: @loaderLineWidth solid @loaderLineColor;
723+
border-radius: @circularRadius;
724+
box-shadow: 0 0 0 1px transparent;
725+
visibility: visible;
726+
z-index: @loaderLineZIndex;
727+
}
710728
}
711729
}
712730

731+
.ui.invisible.popup {
732+
display: block;
733+
visibility: hidden !important;
734+
z-index: @invisibleZIndex;
735+
}
736+
713737
.ui.animating.popup,
714738
.ui.visible.popup {
715739
display: block;
@@ -807,13 +831,18 @@
807831
@color: @value;
808832
@c: @colors[@@color][color];
809833
@l: @colors[@@color][light];
834+
@cl: lighten(@c, @loadingColoredPercent);
835+
@ll: darken(@l, @loadingColoredPercent);
810836

811837
& when not (@variationPopupTooltip) {
812838
.ui.ui.ui.@{color}.popup::before,
813839
.ui.@{color}.popup {
814840
background: @c;
815841
color: @white;
816842
border: none;
843+
.loading& when (@variationPopupLoading) {
844+
background: @cl;
845+
}
817846
}
818847
.ui.ui.ui.@{color}.popup::before {
819848
box-shadow: none;
@@ -823,6 +852,9 @@
823852
.ui.inverted.@{color}.popup {
824853
background: @l;
825854
color: @black;
855+
.loading& when (@variationPopupLoading) {
856+
background: @ll;
857+
}
826858
}
827859
}
828860
}
@@ -835,6 +867,12 @@
835867
color: @white;
836868
border: none;
837869
}
870+
& when (@variationPopupLoading) {
871+
.ui.ui.ui.@{color}.loading.popup::before,
872+
.ui.@{color}.loading.popup {
873+
background: @cl;
874+
}
875+
}
838876
.ui.ui.ui.@{color}.popup::before,
839877
[data-tooltip][data-variation~="@{color}"]::before {
840878
box-shadow: none;
@@ -847,6 +885,12 @@
847885
background: @l;
848886
color: @black;
849887
}
888+
& when (@variationPopupLoading) {
889+
.ui.ui.ui.inverted.@{color}.loading.popup::before,
890+
.ui.inverted.@{color}.loading.popup {
891+
background: @ll;
892+
}
893+
}
850894
}
851895
}
852896
});

src/themes/default/modules/popup.variables

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,15 @@
109109
States
110110
-------------------- */
111111

112+
@loadingOpacity: 0.3;
113+
@loadingColoredPercent: 30%;
114+
@loadingPointerEvents: none;
112115
@loadingZIndex: -1;
116+
@loaderSize: 2em;
117+
@loaderLineZIndex: 101;
118+
119+
/* backward compatible just in case */
120+
@invisibleZIndex: @loadingZIndex;
113121

114122
/* -------------------
115123
Variations

0 commit comments

Comments
 (0)