diff --git a/examples/demo/index.html b/examples/demo/index.html index d536cf5..2e5b422 100644 --- a/examples/demo/index.html +++ b/examples/demo/index.html @@ -753,7 +753,7 @@

Event Actions

diff --git a/examples/demo/src/index.css b/examples/demo/src/index.css index 8e56332..140d0da 100644 --- a/examples/demo/src/index.css +++ b/examples/demo/src/index.css @@ -343,3 +343,22 @@ .tg-time-grid-container::-webkit-scrollbar-thumb:hover { background: #333 !important; } + +/* Custom event render (renderEvent hook in main.ts) */ +.custom-event-icon { + margin-right: 4px; + font-size: 10px; + opacity: 0.8; +} + +.segment-badge { + margin-left: 4px; + font-size: 9px; + opacity: 0.6; +} + +.time-badge { + margin-top: 2px; + font-size: 9px; + opacity: 0.7; +} diff --git a/examples/demo/src/main.ts b/examples/demo/src/main.ts index dbc571b..4e62748 100644 --- a/examples/demo/src/main.ts +++ b/examples/demo/src/main.ts @@ -169,8 +169,6 @@ function createCalendar(): void { // Add custom icon based on event color const icon = document.createElement("span"); icon.className = "custom-event-icon"; - icon.style.cssText = - "margin-right: 4px; font-size: 10px; opacity: 0.8;"; // Choose icon based on color const color = ctx.event.color || "#3b82f6"; @@ -200,8 +198,6 @@ function createCalendar(): void { ) { const segmentBadge = document.createElement("span"); segmentBadge.className = "segment-badge"; - segmentBadge.style.cssText = - "font-size: 9px; opacity: 0.6; margin-left: 4px;"; segmentBadge.textContent = `(${ctx.segmentIndex + 1}/${ctx.totalSegments})`; ctx.el.appendChild(segmentBadge); } @@ -210,8 +206,6 @@ function createCalendar(): void { if (ctx.startTime && ctx.viewType !== "month") { const timeBadge = document.createElement("div"); timeBadge.className = "time-badge"; - timeBadge.style.cssText = - "font-size: 9px; opacity: 0.7; margin-top: 2px;"; timeBadge.textContent = `⏰ ${ctx.startTime}`; ctx.el.appendChild(timeBadge); } @@ -524,8 +518,13 @@ function log(message: string): void { minute: "2-digit", second: "2-digit", }); - const entry = `
[${timestamp}]${message}
`; - logEl.innerHTML = entry + logEl.innerHTML; + const entry = document.createElement("div"); + entry.className = "log-entry"; + const timestampEl = document.createElement("span"); + timestampEl.className = "log-timestamp"; + timestampEl.textContent = `[${timestamp}]`; + entry.append(timestampEl, message); + logEl.prepend(entry); // Limit log entries const entries = logEl.querySelectorAll(".log-entry"); @@ -670,18 +669,22 @@ function initDaysSelector(): void { if (!container) return; const labels = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - container.innerHTML = labels - .map( - (label, idx) => ` - - `, - ) - .join(""); + container.replaceChildren( + ...labels.map((label, idx) => { + const labelEl = document.createElement("label"); + labelEl.className = "day-checkbox"; + const input = document.createElement("input"); + input.type = "checkbox"; + input.className = "checkbox-brutal"; + input.dataset.day = String(idx); + input.checked = state.activeDays.includes(idx); + input.addEventListener("change", () => (window as any).toggleDay(idx)); + const text = document.createElement("span"); + text.textContent = label; + labelEl.append(input, text); + return labelEl; + }), + ); } function updateDayCheckboxes(): void { @@ -861,13 +864,13 @@ let eventCounter = 100; if (configDisplay && eventsDisplay && actionBtn) { if (tab === "config") { - configDisplay.style.display = "block"; - eventsDisplay.style.display = "none"; + configDisplay.hidden = false; + eventsDisplay.hidden = true; actionBtn.textContent = "Copy"; actionBtn.onclick = () => (window as any).copyConfig(); } else { - configDisplay.style.display = "none"; - eventsDisplay.style.display = "block"; + configDisplay.hidden = true; + eventsDisplay.hidden = false; actionBtn.textContent = "Copy"; actionBtn.onclick = () => (window as any).copyConfig(); updateEventsDisplay(); @@ -888,21 +891,23 @@ function initCustomViewsSection(): void { const viewsInfo = getCustomViewInfo(); - container.innerHTML = viewsInfo - .map( - (view) => ` - - `, - ) - .join(""); + container.replaceChildren( + ...viewsInfo.map((view) => { + const button = document.createElement("button"); + button.className = "btn-brutal custom-view-btn"; + button.id = `btn-${view.type}`; + button.title = view.description; + button.addEventListener("click", () => (window as any).setView(view.type)); + const label = document.createElement("span"); + label.className = "view-label"; + label.textContent = view.label; + const short = document.createElement("span"); + short.className = "view-short"; + short.textContent = view.shortLabel ?? ""; + button.append(label, short); + return button; + }), + ); } // =============================================================================