generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusPicker.ts
45 lines (37 loc) · 1.21 KB
/
statusPicker.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
import { setIcon } from "obsidian";
import * as Status from "statusTypes";
import tippy from "tippy.js";
export class StatusPicker {
constructor(
public taskNode: Element,
public onSelect: (value: string) => {}
) {
}
build() {
const taskNode = this.taskNode
const input = taskNode.querySelector("input")
const wrapper = createSpan({ cls: "checkboxStatusWrapper" })
const btnContainer = createDiv({ cls: "btn-container" })
for (const status in Status.Status) {
const btn = createDiv()
btn.addClass("taskBtn")
setIcon(btn, Status.statusIcon[status as keyof typeof Status.Status])
btn.onclick = async (e) => {
this.onSelect(status)
e.stopPropagation();
}
btnContainer.appendChild(btn)
}
if (input) {
input?.parentElement?.insertBefore(wrapper, input)
const instance = tippy(input, {
content: btnContainer,
theme: 'light',
appendTo: wrapper,
interactive: true,
arrow: false,
placement: 'top'
})
}
}
}