Files
t/ts/main.ts

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-12-21 07:26:27 -08:00
import { ElemWrapper } from "./elemwrapper";
2024-12-22 10:23:37 -08:00
import { SLCard } from "./slcard";
2024-12-21 21:49:43 -08:00
import { SLIcon } from "./slicon";
2024-12-22 10:23:37 -08:00
import { SLInput } from "./slinput";
2024-12-21 21:42:54 -08:00
import { SLTabGroup } from "./sltabgroup";
2024-12-21 07:17:19 -08:00
2024-12-21 07:26:27 -08:00
async function main() {
2024-12-21 07:17:19 -08:00
const root = new ElemWrapper(document.body);
2024-12-21 21:42:54 -08:00
const tabGroup = new SLTabGroup();
root.append(tabGroup);
2024-12-21 07:17:19 -08:00
2024-12-21 21:42:54 -08:00
const [tasksTab, tasksPanel] = tabGroup.addTabSet("tasks");
2024-12-22 10:23:37 -08:00
tasksTab.append(new SLIcon("list-task"));
const tasksCard = new SLCard();
tasksPanel.append(tasksCard);
const tasksInput = new SLInput();
tasksCard.append(tasksInput);
tasksInput.setPill();
const tasksAddIcon = tasksInput.addSuffixIcon("plus-circle");
const addTask = () => {
const task = tasksInput.getValue();
if (task.length === 0) {
return;
}
tasksInput.clear();
tasksInput.focus();
tasksAddIcon.classList.remove("highlight");
void tasksAddIcon.elem.offsetWidth; // force reflow
tasksAddIcon.classList.add("highlight");
};
tasksAddIcon.addEventListener("click", () => {
addTask();
});
tasksInput.addEventListener("keydown", (e) => {
if ((e as KeyboardEvent).key === "Enter") {
addTask();
}
});
2024-12-21 07:17:19 -08:00
2024-12-21 21:42:54 -08:00
const [tagsTab, tagsPanel] = tabGroup.addTabSet("tags");
2024-12-21 21:49:43 -08:00
tagsTab.append(new SLIcon("tags"));
2024-12-21 21:42:54 -08:00
}
2024-12-21 06:35:49 -08:00
2024-12-21 06:58:13 -08:00
document.addEventListener("DOMContentLoaded", main);