DEV: Refactor popup-tip component (#15257)

This commit is contained in:
Penar Musaraj 2021-12-13 11:22:02 -05:00 committed by GitHub
parent 7d72041fff
commit 954ab4e0ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 63 deletions

View File

@ -1,17 +1,16 @@
import { alias, not } from "@ember/object/computed"; import { alias, not, or } from "@ember/object/computed";
import discourseComputed, { observes } from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import Component from "@ember/component"; import Component from "@ember/component";
import { iconHTML } from "discourse-common/lib/icon-library"; import { getOwner } from "discourse-common/lib/get-owner";
export default Component.extend({ export default Component.extend({
classNameBindings: [":popup-tip", "good", "bad", "lastShownAt::hide"], classNameBindings: [":popup-tip", "good", "bad", "lastShownAt::hide"],
attributeBindings: ["role"], attributeBindings: ["role"],
animateAttribute: null,
bouncePixels: 6,
bounceDelay: 100,
rerenderTriggers: ["validation.reason"], rerenderTriggers: ["validation.reason"],
closeIcon: `${iconHTML("times-circle")}`.htmlSafe(),
tipReason: null, tipReason: null,
lastShownAt: or("shownAt", "validation.lastShownAt"),
bad: alias("validation.failed"),
good: not("bad"),
@discourseComputed("bad") @discourseComputed("bad")
role(bad) { role(bad) {
@ -22,30 +21,8 @@ export default Component.extend({
click() { click() {
this.set("shownAt", null); this.set("shownAt", null);
this.set("validation.lastShownAt", null); const composer = getOwner(this).lookup("controller:composer");
}, composer.clearLastValidatedAt();
bad: alias("validation.failed"),
good: not("bad"),
@discourseComputed("shownAt", "validation.lastShownAt")
lastShownAt(shownAt, lastShownAt) {
return shownAt || lastShownAt;
},
@observes("lastShownAt")
bounce() {
if (this.lastShownAt) {
let $elem = $(this.element);
if (!this.animateAttribute) {
this.animateAttribute = $elem.css("left") === "auto" ? "right" : "left";
}
if (this.animateAttribute === "left") {
this.bounceLeft($elem);
} else {
this.bounceRight($elem);
}
}
}, },
didReceiveAttrs() { didReceiveAttrs() {
@ -57,20 +34,4 @@ export default Component.extend({
this.set("tipReason", null); this.set("tipReason", null);
} }
}, },
bounceLeft($elem) {
for (let i = 0; i < 5; i++) {
$elem
.animate({ left: "+=" + this.bouncePixels }, this.bounceDelay)
.animate({ left: "-=" + this.bouncePixels }, this.bounceDelay);
}
},
bounceRight($elem) {
for (let i = 0; i < 5; i++) {
$elem
.animate({ right: "-=" + this.bouncePixels }, this.bounceDelay)
.animate({ right: "+=" + this.bouncePixels }, this.bounceDelay);
}
},
}); });

View File

@ -1415,4 +1415,8 @@ export default Controller.extend({
visible(state) { visible(state) {
return state && state !== "closed"; return state && state !== "closed";
}, },
clearLastValidatedAt() {
this.set("lastValidatedAt", null);
},
}); });

View File

@ -1 +1 @@
<span class="close">{{closeIcon}}</span>{{tipReason}} {{tipReason}} {{d-icon "times-circle"}}

View File

@ -307,10 +307,6 @@
z-index: z("composer", "dropdown"); z-index: z("composer", "dropdown");
} }
.popup-tip {
z-index: z("composer", "dropdown") + 1;
}
.wmd-controls { .wmd-controls {
position: relative; position: relative;
display: flex; display: flex;

View File

@ -1,8 +1,22 @@
@keyframes slidein {
0% {
transform: translateX(0px);
}
50% {
transform: translateX(5px);
}
100% {
transform: translateX(0px);
}
}
.popup-tip { .popup-tip {
@include form-item-sizing;
position: absolute; position: absolute;
display: block; z-index: z("composer", "dropdown") + 1;
padding: 5px 10px; cursor: pointer;
z-index: z("tooltip"); animation: 0.15s slidein 3;
&.bad { &.bad {
background: var(--danger-medium); background: var(--danger-medium);
color: white; color: white;
@ -12,15 +26,12 @@
&.good { &.good {
display: none; display: none;
} }
.close { .d-icon {
float: right;
color: var(--primary); color: var(--primary);
opacity: 0.5; opacity: 0.5;
font-size: $font-0; font-size: var(--font-0);
margin: 0 0 0 4px; &:hover {
cursor: pointer;
}
.close:hover {
opacity: 1; opacity: 1;
} }
} }
}