Draw something for an icon or colour name nothing maps to

An unknown name indexed the map, got undefined and drew nothing — the same
as no icon at all, so a typo was invisible. It resolves to a placeholder
glyph and the default tint now, and warns once per bad name: both lookups
sit in a render, so a bound widget would otherwise warn per value.

An empty name still draws nothing, which is what "no icon" means.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYM38KSb4V4v2T71eifnZv
This commit is contained in:
2026-08-30 16:29:46 +02:00
co-authored by Claude Opus 5
parent 7f78d541ab
commit 0c17f1fea9
3 changed files with 55 additions and 7 deletions
@@ -5,6 +5,7 @@ import {
Bed,
Check,
CircleCheck,
CircleHelp,
CloudDrizzle,
CloudFog,
CloudLightning,
@@ -81,6 +82,24 @@ export const ICONS: Record<string, LucideIcon> = {
export const ICON_NAMES = Object.keys(ICONS)
/**
* A tile's glyph, or the neutral placeholder for a name nothing maps to.
*
* A flow author names an icon by guess as often as by picking one from the
* panel, so a name outside {@link ICONS} is a typo, not "no icon" — unlike an
* empty name, which stays undrawn rather than warning. The warning is what
* makes the typo findable; the placeholder is what makes it visible.
*/
export function resolveIcon(name: string): LucideIcon | null {
if (!name) return null
const icon = ICONS[name]
if (icon) return icon
warnOnce(
`Dashboard: unknown icon "${name}", expected one of: ${ICON_NAMES.join(", ")}`,
)
return CircleHelp
}
/**
* What an icon may be tinted, by name.
*
@@ -94,3 +113,28 @@ export const ICON_COLORS: Record<string, string> = {
success: "text-status-success",
danger: "text-destructive",
}
/** A tile's tint, or the widget's own default for a name nothing maps to. */
export function resolveIconColor(name: string): string {
const color = ICON_COLORS[name]
if (color) return color
if (name) {
warnOnce(
`Dashboard: unknown icon color "${name}", expected one of: ${Object.keys(ICON_COLORS).join(", ")}`,
)
}
return ICON_COLORS.default
}
/**
* Both lookups sit in a render, and a bound widget renders as often as its
* value arrives — so a typo would otherwise be a warning a second, for as long
* as the panel is open.
*/
const warned = new Set<string>()
function warnOnce(message: string) {
if (warned.has(message)) return
warned.add(message)
console.warn(message)
}