-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractivity.ts
More file actions
32 lines (30 loc) · 881 Bytes
/
Copy pathinteractivity.ts
File metadata and controls
32 lines (30 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Asynchronously waits for given number of seconds
* @param seconds number of seconds to wait
* @example wait(5); // waits 5 seconds
*/
export const wait = async (seconds: number) =>
new Promise((_) => setTimeout(_, seconds * 1000));
/**
* Smoothly scrolls to top of given element
* @param element element to scroll to
* @example smoothScroll(document.getElementById("jumbotron"));
*/
export const smoothScroll = (element: HTMLElement) => {
window.scrollTo({
behavior: "smooth",
top: element.offsetTop,
});
};
/**
* Copies given text to user's clipboard
* @param text text to copy
* @example copyToClipboard("matt@bierman.io");
*/
export const copyToClipboard = async (text: string): Promise<void> => {
try {
await navigator.clipboard.writeText(text);
} catch (err) {
console.error("Failed to copy text to clipboard", text, err);
}
};