-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
highlightElement
utility (#538)
* Create `highlightElement` utility * Update highlight-element.ts
- Loading branch information
Showing
2 changed files
with
40 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Ember from "ember"; | ||
import { timeout } from "ember-concurrency"; | ||
|
||
/** | ||
* Adds a temporary highlight to a relatively positioned element. | ||
* Used to draw attention to an item, such as a related resource | ||
* that's been added or modified. | ||
*/ | ||
|
||
export default async function highlightElement(target: Element) { | ||
const highlight = document.createElement("div"); | ||
|
||
highlight.setAttribute("aria-hidden", "true"); | ||
highlight.classList.add("highlight-affordance"); | ||
|
||
target.appendChild(highlight); | ||
|
||
const fadeInAnimation = highlight.animate([{ opacity: 0 }, { opacity: 1 }], { | ||
duration: Ember.testing ? 0 : 50, | ||
fill: "forwards", | ||
}); | ||
|
||
await timeout(Ember.testing ? 0 : 2000); | ||
|
||
const fadeOutAnimation = highlight.animate([{ opacity: 1 }, { opacity: 0 }], { | ||
duration: Ember.testing ? 0 : 400, | ||
fill: "forwards", | ||
}); | ||
|
||
try { | ||
await fadeInAnimation.finished; | ||
await fadeOutAnimation.finished; | ||
} finally { | ||
fadeInAnimation.cancel(); | ||
fadeOutAnimation.cancel(); | ||
highlight.remove(); | ||
} | ||
} |