Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix(custom-widgets): support all Tabler icons with local SVG sprites (#7198)

Thomas3fc4abcc2347
diff --git a/.github/renovate.json5 b/.github/renovate.json5
index 716d400d3..1b745662d 100644
--- a/.github/renovate.json5
+++ b/.github/renovate.json5
@@ -2,6 +2,10 @@
$schema: "https://docs.renovatebot.com/renovate-schema.json",
extends: ["config:recommended", ":dependencyDashboardApproval"],
packageRules: [
+ {
+ matchPackageNames: ["@tabler/icons-react", "@tabler/icons-sprite"],
+ groupName: "Tabler icons",
+ },
{
matchPackageNames: ["^@homarr/"],
enabled: false,
diff --git a/.gitignore b/.gitignore
index bf9bea80a..4c9cfefa1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,6 +69,7 @@ e2e/shared/tmp
#personal backgrounds
apps/nextjs/public/images/background.png
+apps/nextjs/public/tabler-icons/
diff --git a/apps/nextjs/next.config.ts b/apps/nextjs/next.config.ts
index d675877af..19fbf2dc9 100644
--- a/apps/nextjs/next.config.ts
+++ b/apps/nextjs/next.config.ts
@@ -101,6 +101,10 @@ const nextConfig: NextConfig = {
// eslint-disable-next-line @typescript-eslint/require-await,no-restricted-syntax
async headers() {
return [
+ {
+ source: "/tabler-icons/:version/:asset",
+ headers: [{ key: "Cache-Control", value: "public, max-age=31536000, immutable" }],
+ },
{
source: "/sw.js",
headers: [
diff --git a/apps/nextjs/package.json b/apps/nextjs/package.json
index 2ba067918..7d7bdf0e8 100644
--- a/apps/nextjs/package.json
+++ b/apps/nextjs/package.json
@@ -4,9 +4,9 @@
"private": true,
"type": "module",
"scripts": {
- "build": "node scripts/assemble-standalone.mjs",
+ "build": "node scripts/prepare-tabler-icons.mjs && node scripts/assemble-standalone.mjs",
"clean": "git clean -xdf .next .output .turbo node_modules",
- "dev": "bun run with-env node ../../node_modules/next/dist/bin/next dev",
+ "dev": "node scripts/prepare-tabler-icons.mjs && bun run with-env node ../../node_modules/next/dist/bin/next dev",
"format": "oxfmt .",
"lint": "oxlint",
"start": "bun run with-env node ../../node_modules/next/dist/bin/next start",
@@ -124,6 +124,7 @@
},
"devDependencies": {
"@homarr/tsconfig": "workspace:^0.1.0",
+ "@tabler/icons-sprite": "catalog:",
"@types/adm-zip": "catalog:",
"@types/better-sqlite3": "catalog:",
"@types/chroma-js": "catalog:",
diff --git a/apps/nextjs/scripts/prepare-tabler-icons.mjs b/apps/nextjs/scripts/prepare-tabler-icons.mjs
new file mode 100644
index 000000000..3eec5f0c0
--- /dev/null
+++ b/apps/nextjs/scripts/prepare-tabler-icons.mjs
@@ -0,0 +1,25 @@
+import { copyFile, mkdir, readFile, rm } from "node:fs/promises";
+import { createRequire } from "node:module";
+import { dirname, join, resolve } from "node:path";
+
+const require = createRequire(import.meta.url);
+const spritePackagePath = require.resolve("@tabler/icons-sprite/package.json");
+const spritePackage = JSON.parse(await readFile(spritePackagePath, "utf8"));
+const reactPackage = JSON.parse(await readFile(require.resolve("@tabler/icons-react/package.json"), "utf8"));
+if (spritePackage.version !== reactPackage.version) {
+ throw new Error("Tabler React and sprite packages must use the same version so every registered icon can render.");
+}
+
+const assetDirectory = resolve(import.meta.dirname, "../public/tabler-icons");
+const versionDirectory = join(assetDirectory, spritePackage.version);
+await rm(assetDirectory, { recursive: true, force: true });
+await mkdir(versionDirectory, { recursive: true });
+await Promise.all(
+ [
+ ["dist/tabler-sprite-nostroke.svg", "outline.svg"],
+ ["dist/tabler-sprite-filled.svg", "filled.svg"],
+ ["LICENSE", "LICENSE"],
+ ].map(([source, destination]) =>
+ copyFile(join(dirname(spritePackagePath), source), join(versionDirectory, destination)),
+ ),
+);
diff --git a/apps/nextjs/src/app/api/assistant/chat/assistant-tool-policy.ts b/apps/nextjs/src/app/api/assistant/chat/assistant-tool-policy.ts
index 074cea071..c8594dfb4 100644
--- a/apps/nextjs/src/app/api/assistant/chat/assistant-tool-policy.ts
+++ b/apps/nextjs/src/app/api/assistant/chat/assistant-tool-policy.ts
@@ -32,7 +32,7 @@ ${Object.values(CUSTOM_WIDGET_SKILL_REFERENCES).join("\n\n")}
${CUSTOM_WIDGET_ASSISTANT_COMPONENT_REFERENCE}
-Function-call spread arguments are unsupported: use values.reduce((maximum, value) => Math.max(maximum, value), 0), not Math.max(...values). Use only the supplied iconNames (for example server, database, bell, cloud, circle-check), never React names such as IconServer.
+Function-call spread arguments are unsupported: use values.reduce((maximum, value) => Math.max(maximum, value), 0), not Math.max(...values). Use installed Tabler kebab-case icon names (for example server, database, bell, cloud, circle-check), never React names such as IconServer. The supplied iconNames are examples; filled icons end in -filled.
Start the template directly with its root JSX element or fragment, without wrapping parentheses or Markdown fences; characters outside JSX render as literal text.
Design for a roughly 320px-wide compact tile. Keep essential dates, readings and action labels visible: shorten their format or use rows instead of truncating them with lineClamp. Screen-width breakpoints do not measure a dashboard tile's width.
diff --git a/bun.lock b/bun.lock
index aa9cbb21e..85f558afb 100644
--- a/bun.lock
+++ b/bun.lock
@@ -202,6 +202,7 @@
},
"devDependencies": {
"@homarr/tsconfig": "workspace:^0.1.0",
+ "@tabler/icons-sprite": "catalog:",
"@types/adm-zip": "catalog:",
"@types/better-sqlite3": "catalog:",
"@types/chroma-js": "catalog:",
@@ -1267,6 +1268,7 @@
"@shadcn/react": "^0.2.1",
"@t3-oss/env-nextjs": "0.13.11",
"@tabler/icons-react": "3.44.0",
+ "@tabler/icons-sprite": "3.44.0",
"@tanstack/query-async-storage-persister": "5.101.2",
"@tanstack/react-devtools": "0.10.9",
"@tanstack/react-query": "5.101.2",
@@ -2667,6 +2669,8 @@
"@tabler/icons-react": ["@tabler/[email protected]", "", { "dependencies": { "@tabler/icons": "3.44.0" }, "peerDependencies": { "react": ">= 16" } }, "sha512-8+rvzBbVm/1Z3sG3x7GUNAaxIKxwgz8xaMhRs23nrCnMTKRFAhEC+82zAIFeAA0seXdrAGX5HFCkaLpGK2rVHg=="],
+ "@tabler/icons-sprite": ["@tabler/[email protected]", "", { "dependencies": { "@tabler/icons": "3.44.0" } }, "sha512-+6eag3is1gOW8II/1iYad7ZLLXrBO4skNuDDI/vNTKr4WmiDCpLf8d9OBRTve95TXYkjJrClJuFMrOsgmI+HKA=="],
+
"@tailwindcss/node": ["@tailwindcss/[email protected]", "", { "dependencies": { "@jridgewell/remapping": "2.3.5", "enhanced-resolve": "5.21.6", "jiti": "2.7.0", "lightningcss": "1.32.0", "magic-string": "0.30.21", "source-map-js": "1.2.1", "tailwindcss": "4.3.2" } }, "sha512-yWP/sqEcBLaD8JuA6zNwxoYKr75qxTioYwlRwekj5Jr/I5GXnoJfjetH/psLUIv74cYTH2lBUEzBkinthoYcBg=="],
"@tailwindcss/oxide": ["@tailwindcss/[email protected]", "", { "optionalDependencies": { "@tailwindcss/oxide-android-arm64": "4.3.2", "@tailwindcss/oxide-darwin-arm64": "4.3.2", "@tailwindcss/oxide-darwin-x64": "4.3.2", "@tailwindcss/oxide-freebsd-x64": "4.3.2", "@tailwindcss/oxide-linux-arm-gnueabihf": "4.3.2", "@tailwindcss/oxide-linux-arm64-gnu": "4.3.2", "@tailwindcss/oxide-linux-arm64-musl": "4.3.2", "@tailwindcss/oxide-linux-x64-gnu": "4.3.2", "@tailwindcss/oxide-linux-x64-musl": "4.3.2", "@tailwindcss/oxide-wasm32-wasi": "4.3.2", "@tailwindcss/oxide-win32-arm64-msvc": "4.3.2", "@tailwindcss/oxide-win32-x64-msvc": "4.3.2" } }, "sha512-z8ZgnzX8gdNoWLBLqBPoh/sjnxkwvf9ZuWjnO0l0yIzbLa5/9S+eC5QxGZKRobVHIC3/1BoMWjHblqWjcgFgag=="],
diff --git a/package.json b/package.json
index ce37735ec..7c0c904f9 100644
--- a/package.json
+++ b/package.json
@@ -74,6 +74,7 @@
"@shadcn/react": "^0.2.1",
"@t3-oss/env-nextjs": "0.13.11",
"@tabler/icons-react": "3.44.0",
+ "@tabler/icons-sprite": "3.44.0",
"@tanstack/query-async-storage-persister": "5.101.2",
"@tanstack/react-devtools": "0.10.9",
"@tanstack/react-query": "5.101.2",
diff --git a/packages/custom-widgets/package.json b/packages/custom-widgets/package.json
index 80f467748..2e2b6c71b 100644
--- a/packages/custom-widgets/package.json
+++ b/packages/custom-widgets/package.json
@@ -21,6 +21,7 @@
"./jsx/analyzer": "./src/jsx/analyzer.ts",
"./runtime": "./src/runtime/index.ts",
"./server": "./src/server/index.ts",
+ "./tabler-icons": "./src/core/tabler-icons.ts",
"./workbench": "./src/workbench/index.ts"
},
"scripts": {
diff --git a/packages/custom-widgets/src/core/authoring-catalog.ts b/packages/custom-widgets/src/core/authoring-catalog.ts
index 5c529f2ce..00a839655 100644
--- a/packages/custom-widgets/src/core/authoring-catalog.ts
+++ b/packages/custom-widgets/src/core/authoring-catalog.ts
@@ -5,7 +5,7 @@ import {
} from "./component-catalog";
import { BUNDLED_CUSTOM_WIDGETS } from "./bundled-widgets";
import { customJsxExamples } from "./examples";
-import { customJsxTablerIconNames } from "./tabler-icons";
+import { customJsxTablerIconExamples, customJsxTablerIconNames } from "./tabler-icons";
type BundledCustomWidget = (typeof BUNDLED_CUSTOM_WIDGETS)[number];
@@ -115,7 +115,15 @@ export function getCustomWidgetComponent(name: string) {
maxPerRequest: 64,
appliesExceptBlockedProps: true as const,
},
- knownValues: component.name === "TablerIcon" ? { name: customJsxTablerIconNames } : undefined,
+ ...(component.name === "TablerIcon" && {
+ knownValues: { name: customJsxTablerIconExamples },
+ iconNaming: {
+ availableCount: customJsxTablerIconNames.length,
+ knownValuesAreExamples: true,
+ filledSuffix: "-filled",
+ browseUrl: "https://tabler.io/icons",
+ },
+ }),
deniedReason: component.deniedReason,
};
}
diff --git a/packages/custom-widgets/src/core/authoring-resources.ts b/packages/custom-widgets/src/core/authoring-resources.ts
index db80d314d..7a1aaa31d 100644
--- a/packages/custom-widgets/src/core/authoring-resources.ts
+++ b/packages/custom-widgets/src/core/authoring-resources.ts
@@ -1,6 +1,6 @@
import { customJsxAuthoringCatalog } from "./component-catalog";
import { CUSTOM_WIDGET_SCHEMA } from "./custom-jsx-schema";
-import { customJsxTablerIconNames } from "./tabler-icons";
+import { customJsxTablerIconExamples } from "./tabler-icons";
export {
findCustomWidgetComponents,
@@ -53,7 +53,9 @@ const assistantReferenceTypeIds = new Set(
export const CUSTOM_WIDGET_ASSISTANT_COMPONENT_REFERENCE = JSON.stringify({
mantineVersion: customJsxAuthoringCatalog.mantineVersion,
- iconNames: customJsxTablerIconNames,
+ iconNames: customJsxTablerIconExamples,
+ iconNaming:
+ "All installed Tabler kebab-case names are supported; iconNames are examples. Filled icons end in -filled.",
format: "Props are [name, type ID, required]. Shared props apply unless blocked. Type IDs resolve through types.",
types: Object.fromEntries([...assistantReferenceTypeIds].map((id) => [id, customJsxAuthoringCatalog.types[id]])),
registeredNames: customJsxAuthoringCatalog.components
diff --git a/packages/custom-widgets/src/core/tabler-icons.ts b/packages/custom-widgets/src/core/tabler-icons.ts
index 4e691a57b..cf0051bc4 100644
--- a/packages/custom-widgets/src/core/tabler-icons.ts
+++ b/packages/custom-widgets/src/core/tabler-icons.ts
@@ -1,105 +1,17 @@
-export const customJsxTablerIconNames = [
- "activity",
- "alert-circle",
- "alert-triangle",
- "api",
- "arrow-down",
- "arrow-left",
- "arrow-right",
- "arrow-up",
+import { iconsList } from "@tabler/icons-react";
+import tablerPackage from "@tabler/icons-react/package.json";
+
+export const customJsxTablerIconNames = Object.freeze([...iconsList.default, "pulse"].toSorted());
+
+export const customJsxTablerIconExamples = [
+ "server",
+ "database",
"bell",
- "bluetooth",
- "bolt",
- "bookmark",
- "brand-docker",
- "bug",
- "calendar",
- "camera",
- "chart-bar",
- "chart-line",
- "chart-pie",
- "check",
- "chevron-down",
- "chevron-left",
- "chevron-right",
- "chevron-up",
- "circle-check",
- "circle-x",
- "clipboard",
- "clock",
"cloud",
- "cloud-off",
- "code",
- "compass",
- "copy",
- "cpu",
- "database",
- "device-desktop",
- "device-mobile",
- "download",
- "droplet",
- "edit",
- "external-link",
- "eye",
- "eye-off",
- "file",
- "flag",
- "flame",
- "folder",
- "gauge",
- "git-branch",
- "heart",
- "heartbeat",
- "history",
- "home",
- "info-circle",
- "key",
- "link",
- "loader",
- "lock",
- "lock-open",
- "mail",
- "map",
- "map-pin",
- "minus",
- "moon",
- "music",
- "network",
- "photo",
- "pin",
- "player-pause",
- "player-play",
- "player-skip-back",
- "player-skip-forward",
- "player-stop",
- "plus",
- "pokeball",
- "power",
- "progress",
- "pulse",
- "refresh",
- "reload",
- "search",
- "server",
- "settings",
- "shield",
- "speedboat",
- "star",
- "sun",
- "terminal",
- "thermometer",
- "trash",
- "trending-down",
- "trending-up",
- "upload",
- "user",
- "users",
- "video",
- "volume",
- "volume-2",
- "volume-off",
- "wifi",
- "wifi-off",
- "world",
- "x",
+ "circle-check",
+ "air-conditioning",
+ "brand-github",
+ "star-filled",
] as const;
+
+export const customJsxTablerIconSpriteBasePath = `/tabler-icons/${tablerPackage.version}`;
diff --git a/packages/custom-widgets/src/test/authoring-resources.spec.ts b/packages/custom-widgets/src/test/authoring-resources.spec.ts
index 100f42e93..97715f5f1 100644
--- a/packages/custom-widgets/src/test/authoring-resources.spec.ts
+++ b/packages/custom-widgets/src/test/authoring-resources.spec.ts
@@ -88,7 +88,7 @@ describe("authoring resources", () => {
});
expect(stack?.props.some(({ source }) => source === "global")).toBe(false);
expect(Buffer.byteLength(JSON.stringify(stack), "utf8")).toBeLessThan(20_000);
- expect(getCustomWidgetComponent("Icon")?.knownValues?.name.length).toBeGreaterThan(100);
+ expect(getCustomWidgetComponent("Icon")?.iconNaming?.availableCount).toBeGreaterThan(100);
const largestComponentPayload = Math.max(
...catalog.components.map(({ name }) =>
diff --git a/packages/custom-widgets/src/test/jsx-policy.spec.ts b/packages/custom-widgets/src/test/jsx-policy.spec.ts
index 311b54b1c..1219e37f2 100644
--- a/packages/custom-widgets/src/test/jsx-policy.spec.ts
+++ b/packages/custom-widgets/src/test/jsx-policy.spec.ts
@@ -91,22 +91,19 @@ describe("shared Custom JSX policy", () => {
});
test("accepts the concise Icon alias used by the AI prompt", () => {
- expect(validateCustomJsxTemplate('<ThemeIcon><Icon name="brand-docker" /></ThemeIcon>')).toEqual([]);
+ expect(validateCustomJsxTemplate('<ThemeIcon><Icon name="cloud-rain" /></ThemeIcon>')).toEqual([]);
});
- test.each(["IconCloudUpload", "cloud-rain", "not-a-real-icon"])(
- "rejects invisible unsupported icon names: %s",
- (name) => {
- expect(validateCustomJsxTemplate(`<Icon name="${name}" />`)).toEqual(
- expect.arrayContaining([
- expect.objectContaining({
- severity: "error",
- message: expect.stringContaining("registered kebab-case icon name"),
- }),
- ]),
- );
- },
- );
+ test.each(["IconCloudUpload", "not-a-real-icon"])("rejects invisible unsupported icon names: %s", (name) => {
+ expect(validateCustomJsxTemplate(`<Icon name="${name}" />`)).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ severity: "error",
+ message: expect.stringContaining("registered kebab-case icon name"),
+ }),
+ ]),
+ );
+ });
test.each(["Anchor", "Button", "TextInput"])("rejects %s inside a manual SubFetch trigger", (component) => {
const template = `<SubFetch requestId="search" trigger="manual" triggerContent={<Card><${component} /></Card>} />`;
diff --git a/packages/custom-widgets/src/workbench/code-language.ts b/packages/custom-widgets/src/workbench/code-language.ts
index 4f480d242..c65fed3a1 100644
--- a/packages/custom-widgets/src/workbench/code-language.ts
+++ b/packages/custom-widgets/src/workbench/code-language.ts
@@ -92,6 +92,7 @@ export const customJsxComponentHover = hoverTooltip((view, position) => {
function activeOpeningComponent(source: string, position: number): string | undefined {
const match = source.slice(0, position).match(/<([A-Z][A-Za-z0-9.]*)\b[^<>]*$/u);
const name = match?.[1];
+ if (name === "Icon") return "TablerIcon";
return name && customJsxCatalogComponentByName.get(name)?.safety !== "denied" ? name : undefined;
}
diff --git a/packages/widgets/src/custom-api/jsx-icon-adapter.tsx b/packages/widgets/src/custom-api/jsx-icon-adapter.tsx
index 52a23c868..b6b9c29b2 100644
--- a/packages/widgets/src/custom-api/jsx-icon-adapter.tsx
+++ b/packages/widgets/src/custom-api/jsx-icon-adapter.tsx
@@ -1,248 +1,45 @@
-import {
- IconActivity,
- IconAlertCircle,
- IconAlertTriangle,
- IconApi,
- IconArrowDown,
- IconArrowLeft,
- IconArrowRight,
- IconArrowUp,
- IconBell,
- IconBluetooth,
- IconBolt,
- IconBookmark,
- IconBrandDocker,
- IconBug,
- IconCalendar,
- IconCamera,
- IconChartBar,
- IconChartLine,
- IconChartPie,
- IconCheck,
- IconChevronDown,
- IconChevronLeft,
- IconChevronRight,
- IconChevronUp,
- IconCircleCheck,
- IconCircleX,
- IconClipboard,
- IconClock,
- IconCloud,
- IconCloudOff,
- IconCode,
- IconCompass,
- IconCopy,
- IconCpu,
- IconDatabase,
- IconDeviceDesktop,
- IconDeviceMobile,
- IconDownload,
- IconDroplet,
- IconEdit,
- IconExternalLink,
- IconEye,
- IconEyeOff,
- IconFile,
- IconFlag,
- IconFlame,
- IconFolder,
- IconGauge,
- IconGitBranch,
- IconHeart,
- IconHistory,
- IconHome,
- IconInfoCircle,
- IconKey,
- IconLink,
- IconLoader,
- IconLock,
- IconLockOpen,
- IconMail,
- IconMap,
- IconMapPin,
- IconMinus,
- IconMoon,
- IconMusic,
- IconNetwork,
- IconPhoto,
- IconPokeball,
- IconPin,
- IconPlayerPause,
- IconPlayerPlay,
- IconPlayerSkipBack,
- IconPlayerSkipForward,
- IconPlayerStop,
- IconPlus,
- IconPower,
- IconProgress,
- IconHeartbeat,
- IconRefresh,
- IconReload,
- IconSearch,
- IconServer,
- IconSettings,
- IconShield,
- IconStar,
- IconSun,
- IconTerminal,
- IconThermometer,
- IconTrash,
- IconTrendingDown,
- IconTrendingUp,
- IconUpload,
- IconUser,
- IconUsers,
- IconVideo,
- IconVolume,
- IconVolume2,
- IconVolumeOff,
- IconWifi,
- IconWifiOff,
- IconWorld,
- IconX,
- IconSpeedboat,
-} from "@tabler/icons-react";
+import { customJsxTablerIconNames, customJsxTablerIconSpriteBasePath } from "@homarr/custom-widgets/tabler-icons";
-function tablerIconExportToKey(exportName: string): string {
- return exportName
- .slice(4)
- .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
- .replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2")
- .replace(/([A-Za-z])(\d)/g, "$1-$2")
- .toLowerCase();
-}
-
-const TABLER_ICON_IMPORTS = {
- IconCheck,
- IconX,
- IconPlus,
- IconMinus,
- IconArrowUp,
- IconArrowDown,
- IconArrowLeft,
- IconArrowRight,
- IconChevronUp,
- IconChevronDown,
- IconChevronLeft,
- IconChevronRight,
- IconHome,
- IconSettings,
- IconUser,
- IconUsers,
- IconSearch,
- IconBell,
- IconMail,
- IconHeart,
- IconStar,
- IconBookmark,
- IconBrandDocker,
- IconFlag,
- IconPin,
- IconPlayerPlay,
- IconPlayerPause,
- IconPlayerStop,
- IconPlayerSkipForward,
- IconPlayerSkipBack,
- IconVolume,
- IconVolumeOff,
- IconVolume2,
- IconWifi,
- IconWifiOff,
- IconBluetooth,
- IconCloud,
- IconCloudOff,
- IconServer,
- IconDatabase,
- IconCpu,
- IconDeviceDesktop,
- IconDeviceMobile,
- IconFolder,
- IconFile,
- IconDownload,
- IconUpload,
- IconRefresh,
- IconReload,
- IconPower,
- IconBolt,
- IconFlame,
- IconDroplet,
- IconSun,
- IconMoon,
- IconEye,
- IconEyeOff,
- IconLock,
- IconLockOpen,
- IconShield,
- IconKey,
- IconAlertTriangle,
- IconAlertCircle,
- IconInfoCircle,
- IconCircleCheck,
- IconCircleX,
- IconTrash,
- IconEdit,
- IconCopy,
- IconClipboard,
- IconExternalLink,
- IconLink,
- IconPhoto,
- IconPokeball,
- IconCamera,
- IconMusic,
- IconVideo,
- IconCalendar,
- IconClock,
- IconHistory,
- IconMap,
- IconMapPin,
- IconCompass,
- IconTerminal,
- IconCode,
- IconBug,
- IconGitBranch,
- IconNetwork,
- IconWorld,
- IconApi,
- IconChartBar,
- IconChartLine,
- IconChartPie,
- IconTrendingUp,
- IconTrendingDown,
- IconActivity,
- IconProgress,
- IconLoader,
- IconThermometer,
- IconGauge,
- IconSpeedboat,
- IconHeartbeat,
-} as const;
-
-const TABLER_ICON_MAP: Record<string, ComponentType<never>> = {
- ...Object.fromEntries(
- Object.entries(TABLER_ICON_IMPORTS).map(([exportName, IconComponent]) => [
- tablerIconExportToKey(exportName),
- IconComponent,
- ]),
- ),
- pulse: IconHeartbeat,
-};
-
-export const SAFE_TABLER_ICON_NAMES = Object.freeze(Object.keys(TABLER_ICON_MAP).toSorted());
+export const SAFE_TABLER_ICON_NAMES = customJsxTablerIconNames;
+const supportedIconNames: ReadonlySet<string> = new Set(SAFE_TABLER_ICON_NAMES);
function isValidIconProp(value: unknown): value is string | number {
return typeof value === "number" || typeof value === "string";
}
export function SafeTablerIcon(props: Record<string, unknown>) {
- const name = props.name;
- if (typeof name !== "string") return null;
- const IconComponent = TABLER_ICON_MAP[name];
- if (!IconComponent) return null;
- const iconProps: Record<string, unknown> = {};
- if (isValidIconProp(props.size)) iconProps.size = props.size;
- if (typeof props.color === "string") iconProps.color = props.color;
- if (isValidIconProp(props.stroke)) iconProps.stroke = props.stroke;
- return createElement(IconComponent as never, iconProps);
+ if (typeof props.name !== "string" || !supportedIconNames.has(props.name)) return null;
+ let name = props.name;
+ // Preserve Homarr's legacy pulse alias (previously IconHeartbeat) for existing saved widgets.
+ if (name === "pulse") name = "heartbeat";
+
+ let sprite = "outline";
+ let symbol = `tabler-${name}`;
+ if (name.endsWith("-filled")) {
+ sprite = "filled";
+ symbol = `tabler-filled-${name.slice(0, -"-filled".length)}`;
+ }
+
+ let size: string | number = 24;
+ let color = "currentColor";
+ let stroke: string | number = 2;
+ if (isValidIconProp(props.size)) size = props.size;
+ if (typeof props.color === "string") color = props.color;
+ if (isValidIconProp(props.stroke)) stroke = props.stroke;
+
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width={size}
+ height={size}
+ viewBox="0 0 24 24"
+ color={color}
+ strokeWidth={stroke}
+ className={`tabler-icon tabler-icon-${name}`}
+ aria-hidden="true"
+ focusable="false"
+ >
+ <use href={`${customJsxTablerIconSpriteBasePath}/${sprite}.svg#${symbol}`} />
+ </svg>
+ );
}
-import { createElement } from "react";
-import type { ComponentType } from "react";