Skip to content

Commit 8401fd1

Browse files
committed
Add Popovers
1 parent 6026fb6 commit 8401fd1

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/Component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ export abstract class Component extends EventTarget {
1616
this.wrapper.classList.add(...classes);
1717
return this;
1818
}
19+
setAnchorName(name: string) {
20+
this.setAttribute("anchor", name);
21+
return this;
22+
}
1923
setAttribute(key: string, value: Refable<string | undefined> = "") {
2024
asRef(value).listen((val) => {
21-
if(val === undefined) {
25+
if (val === undefined) {
2226
this.wrapper.removeAttribute(key);
2327
return;
2428
}

src/components/Popover.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Component } from "../Component.ts";
2+
3+
export const Popover = (content: Component) => new class extends Component {
4+
constructor() {
5+
super();
6+
this.addClass("wpopover");
7+
this.wrapper.append(content.draw());
8+
this.setAttribute("popover");
9+
}
10+
11+
protected showPopover() {
12+
this.wrapper.showPopover();
13+
return this;
14+
};
15+
16+
protected hidePopover() {
17+
this.wrapper.hidePopover();
18+
return this;
19+
};
20+
21+
protected togglePopover(force: boolean) {
22+
this.wrapper.togglePopover(force);
23+
return this;
24+
};
25+
26+
protected pullingAnchorPositioning(anchorName: `--${string}`, positioning: (rect: DOMRect, style: CSSStyleDeclaration) => void, interval = 20) {
27+
setInterval(() => {
28+
const anchor = document.querySelector(`[anchor="${anchorName}"]`);
29+
if (!anchor) return;
30+
const rect = anchor.getBoundingClientRect();
31+
positioning(rect, this.wrapper.style);
32+
}, interval);
33+
return this;
34+
}
35+
};

0 commit comments

Comments
 (0)