import type { HomarrCustomWidgetV2Input } from "./custom-jsx-schema"; export interface CustomJsxExample { id: string; title: string; description: string; widget: HomarrCustomWidgetV2Input; } export const CUSTOM_JSX_STARTER = ` Service status {status.status?.loading ? : status.status?.error ? {status.status.error} : {data.status?.online ? "Online" : "Offline"}} `; export const CUSTOM_WIDGET_STARTER: HomarrCustomWidgetV2Input = { $schema: "homarr-custom-widget-v2", name: "New custom widget", description: "", sources: { default: { name: "API", baseUrl: "https://example.com", networkScope: "public", auth: "none" } }, requests: { status: { path: "/api/status" } }, options: {}, template: CUSTOM_JSX_STARTER, }; export const customJsxExamples: readonly CustomJsxExample[] = [ { id: "service-dashboard", title: "Service dashboard", description: "A polished responsive dashboard with clear loading and error states.", widget: { $schema: "homarr-custom-widget-v2", name: "Service dashboard", sources: { default: { name: "Service API", baseUrl: "https://example.com", networkScope: "public", auth: "none" }, }, requests: { overview: { path: "/api/overview", cacheSeconds: 30 } }, options: {}, template: ` System overviewLive service health {status.overview?.loading ? : status.overview?.error ? Service health is unavailable. Use Refresh service health to try again. {status.overview.error} : Services{data.overview?.services?.length ?? 0}Online{(data.overview?.services ?? []).filter(service => service.online).length}Offline{(data.overview?.services ?? []).filter(service => !service.online).length}Last checked{(data.overview?.checkedAt ?? data.overview?.lastCheckedAt) ? Date.toLocaleDateString(data.overview.checkedAt ?? data.overview.lastCheckedAt, "en-US") + " " + Date.toLocaleTimeString(data.overview.checkedAt ?? data.overview.lastCheckedAt, "en-US") : "Not reported"}{(data.overview?.services?.length ?? 0) > 0 ? {data.overview.services.map(service => {service.name}{service.latency != null ? service.latency + " ms" : "Latency unavailable"}{service.online ? "Online" : "Offline"})} : No services were returned. Use Refresh service health to try again.}} `, }, }, { id: "search-and-action", title: "Search and action", description: "A temporary search input, manual query, and explicit mutation.", widget: { $schema: "homarr-custom-widget-v2", name: "Series search", sources: { default: { name: "Media API", baseUrl: "https://example.com", networkScope: "private", auth: { type: "apiKeyHeader", name: "X-Api-Key" }, }, }, requests: { search: { path: "/api/series/search", trigger: "manual", query: { term: { $param: "query" } } }, monitor: { kind: "action", method: "POST", path: "/api/series/{param:id}/monitor", confirmation: "Monitor this series?", }, }, options: {}, template: ` {(results) => {(results ?? []).map(series => {series.title}{series.year ?? "Unknown year"}Monitor)}} `, }, }, ];