Token导航 LogoToken导航

Agent Skill · 前端设计

white-label(白标)

white-label 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

white-label 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 9,918。

总安装 190周安装 8GitHub Stars 11下载 67核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:white-label(白标)
来源仓库:https://github.com/lobbi-docs/claude
仓库路径:skills/white-label
安装命令:
npx skills add https://github.com/lobbi-docs/claude --skill white-label
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/lobbi-docs/claude --skill white-label

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

white-label 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。通过 npx skills add 命令从指定 GitHub 仓库安装使用。

安装前需确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。建议结合原始 README 核验具体用法和功能边界。

来源仓库内路径:skills/white-label

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/lobbi-docs/claude --skill white-label;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

white-label 怎么安装?

在终端执行 npx skills add https://github.com/lobbi-docs/claude --skill white-label。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

white-label 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

white-label 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

white-label 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

white-label 用的人多吗?

公开数据是累计安装 190 次,近一周安装 8 次,下载 67 次,GitHub 11 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

white-label 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
white-label

白标 · 本页

19011需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

MUI White-Label and Multi-Theme Systems

Nested ThemeProvider

MUI's ThemeProvider can be nested. Inner providers merge with or override the outer theme. Use this to scope different visual treatments to different sections of the app.

import { ThemeProvider, createTheme } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import Button from '@mui/material/Button';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';

const mainTheme = createTheme({
  palette: {
    primary: { main: '#1976d2' },
    background: { default: '#fafafa' },
  },
});

// Admin sidebar uses a dark theme, scoped to its subtree
const adminSidebarTheme = createTheme({
  palette: {
    mode: 'dark',
    primary: { main: '#90caf9' },
    background: { default: '#1e1e1e', paper: '#2d2d2d' },
  },
});

export function AppShell() {
  return (
    <ThemeProvider theme={mainTheme}>
      <CssBaseline />
      <Box sx={{ display: 'flex' }}>
        {/* Dark sidebar — scoped theme */}
        <ThemeProvider theme={adminSidebarTheme}>
          <Paper sx={{ width: 280, minHeight: '100vh', p: 2 }}>
            <Typography variant="h6">Admin</Typography>
            <Button variant="contained">Dashboard</Button>
          </Paper>
        </ThemeProvider>

        {/* Main content — inherits mainTheme */}
        <Box sx={{ flex: 1, p: 3 }}>
          <Typography variant="h4">Welcome</Typography>
          <Button variant="contained">Main Action</Button>
        </Box>
      </Box>
    </ThemeProvider>
  );
}

Nested Theme with Callback (Merge Instead of Replace)

Pass a function to ThemeProvider to receive the outer theme and merge selectively:

<ThemeProvider theme={mainTheme}>
  <ThemeProvider
    theme={(outerTheme) =>
      createTheme({
        ...outerTheme,
        palette: {
          ...outerTheme.palette,
          primary: { main: '#e91e63' },  // override only primary
        },
      })
    }
  >
    <Button variant="contained">Pink Button, rest of theme inherited</Button>
  </ThemeProvider>
</ThemeProvider>

Dynamic Theme Loading

Load theme configuration from an API or database at runtime. This is the foundation of any white-label system.

import { ThemeProvider, createTheme, type ThemeOptions } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import CircularProgress from '@mui/material/CircularProgress';
import Box from '@mui/material/Box';
import { useState, useEffect, useMemo, type ReactNode } from 'react';

interface BrandConfig {
  primaryColor: string;
  secondaryColor: string;
  fontFamily: string;
  borderRadius: number;
  logoUrl: string;
  mode: 'light' | 'dark';
}

function buildThemeOptions(brand: BrandConfig): ThemeOptions {
  return {
    palette: {
      mode: brand.mode,
      primary: { main: brand.primaryColor },
      secondary: { main: brand.secondaryColor },
    },
    typography: {
      fontFamily: brand.fontFamily,
    },
    shape: {
      borderRadius: brand.borderRadius,
    },
  };
}

async function fetchBrandConfig(tenantId: string): Promise<BrandConfig> {
  const res = await fetch(`/api/tenants/${tenantId}/brand`);
  if (!res.ok) throw new Error(`Failed to load brand config for ${tenantId}`);
  return res.json();
}

interface DynamicThemeProviderProps {
  tenantId: string;
  children: ReactNode;
}

export function DynamicThemeProvider({ tenantId, children }: DynamicThemeProviderProps) {
  const [brandConfig, setBrandConfig] = useState<BrandConfig | null>(null);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    fetchBrandConfig(tenantId)
      .then(setBrandConfig)
      .catch((err) => setError(err.message));
  }, [tenantId]);

  const theme = useMemo(
    () => (brandConfig ? createTheme(buildThemeOptions(brandConfig)) : null),
    [brandConfig],
  );

  if (error) return <Box sx={{ p: 4, color: 'error.main' }}>Theme load failed: {error}</Box>;
  if (!theme) {
    return (
      <Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
        <CircularProgress />
      </Box>
    );
  }

  return (
    <ThemeProvider theme={theme}>
      <CssBaseline />
      {children}
    </ThemeProvider>
  );
}

Theme Composition

Use deepmerge (shipped with MUI as @mui/utils/deepmerge) to layer tenant overrides on top of a base theme. This ensures tenants only override what they need and inherit everything else.

import { createTheme, type ThemeOptions } from '@mui/material/styles';
import deepmerge from '@mui/utils/deepmerge';

// Shared base — every tenant gets this as the foundation
const baseThemeOptions: ThemeOptions = {
  typography: {
    fontFamily: '"Inter", "Helvetica", "Arial", sans-serif',
    h1: { fontSize: '2.5rem', fontWeight: 700 },
    h2: { fontSize: '2rem', fontWeight: 600 },
    button: { textTransform: 'none', fontWeight: 600 },
  },
  shape: { borderRadius: 8 },
  components: {
    MuiButton: {
      defaultProps: { disableElevation: true },
      styleOverrides: {
        root: { borderRadius: 8, padding: '8px 20px' },
      },
    },
    MuiCard: {
      defaultProps: { elevation: 0 },
      styleOverrides: {
        root: { border: '1px solid', borderColor: 'rgba(0,0,0,0.12)' },
      },
    },
    MuiTextField: {
      defaultProps: { variant: 'outlined', size: 'small' },
    },
  },
};

// Tenant-specific overrides — only the diff
const acmeOverrides: ThemeOptions = {
  palette: {
    primary: { main: '#ff5722' },
    secondary: { main: '#ff9800' },
  },
  typography: {
    fontFamily: '"Poppins", sans-serif',
  },
  components: {
    MuiButton: {
      styleOverrides: {
        root: { borderRadius: 24 },   // pill buttons for Acme
      },
    },
  },
};

const globexOverrides: ThemeOptions = {
  palette: {
    mode: 'dark',
    primary: { main: '#00bcd4' },
    secondary: { main: '#7c4dff' },
  },
  shape: { borderRadius: 4 },
};

// Compose: base + tenant overrides via deepmerge
export function createTenantTheme(overrides: ThemeOptions) {
  const merged = deepmerge(baseThemeOptions, overrides);
  return createTheme(merged);
}

// Usage
const acmeTheme = createTenantTheme(acmeOverrides);
const globexTheme = createTenantTheme(globexOverrides);

Tenant-Specific Branding

A token-based approach: load brand colors, fonts, logos, and favicon from a config object. This separates brand identity from theme mechanics.

import { createTheme, type Theme, type ThemeOptions } from '@mui/material/styles';
import deepmerge from '@mui/utils/deepmerge';

// Brand tokens — everything that varies per tenant
export interface BrandTokens {
  id: string;
  name: string;
  primaryColor: string;
  secondaryColor: string;
  errorColor?: string;
  warningColor?: string;
  successColor?: string;
  fontFamily: string;
  headingFontFamily?: string;
  borderRadius: number;
  logoUrl: string;
  logoHeight: number;         // px
  faviconUrl: string;
  mode: 'light' | 'dark';
  customShadows?: boolean;    // use flat design (no shadows)
}

const baseThemeOptions: ThemeOptions = {
  typography: {
    button: { textTransform: 'none' },
  },
  components: {
    MuiButton: { defaultProps: { disableElevation: true } },
    MuiTextField: { defaultProps: { variant: 'outlined', size: 'small' } },
  },
};

export function createBrandTheme(tokens: BrandTokens): Theme {
  const brandOverrides: ThemeOptions = {
    palette: {
      mode: tokens.mode,
      primary: { main: tokens.primaryColor },
      secondary: { main: tokens.secondaryColor },
      ...(tokens.errorColor && { error: { main: tokens.errorColor } }),
      ...(tokens.warningColor && { warning: { main: tokens.warningColor } }),
      ...(tokens.successColor && { success: { main: tokens.successColor } }),
    },
    typography: {
      fontFamily: tokens.fontFamily,
      h1: { fontFamily: tokens.headingFontFamily ?? tokens.fontFamily },
      h2: { fontFamily: tokens.headingFontFamily ?? tokens.fontFamily },
      h3: { fontFamily: tokens.headingFontFamily ?? tokens.fontFamily },
    },
    shape: { borderRadius: tokens.borderRadius },
    ...(tokens.customShadows === false && {
      shadows: Array(25).fill('none') as Theme['shadows'],
    }),
  };

  return createTheme(deepmerge(baseThemeOptions, brandOverrides));
}

// React context to expose brand tokens (logo, favicon, etc.) outside the theme
import { createContext, useContext, type ReactNode } from 'react';

const BrandContext = createContext<BrandTokens | null>(null);

export function useBrand(): BrandTokens {
  const brand = useContext(BrandContext);
  if (!brand) throw new Error('useBrand must be used within BrandProvider');
  return brand;
}

export function BrandProvider({ tokens, children }: { tokens: BrandTokens; children: ReactNode }) {
  return <BrandContext.Provider value={tokens}>{children}</BrandContext.Provider>;
}

Usage in a header component:

import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Box from '@mui/material/Box';
import { useBrand } from './brand';

export function BrandedHeader() {
  const brand = useBrand();
  return (
    <AppBar position="static">
      <Toolbar>
        <Box
          component="img"
          src={brand.logoUrl}
          alt={`${brand.name} logo`}
          sx={{ height: brand.logoHeight, mr: 2 }}
        />
      </Toolbar>
    </AppBar>
  );
}

CSS Variables Approach

MUI v5.1+ supports CssVarsProvider which uses CSS custom properties for palette values. This enables theme switching without React re-renders — the browser just swaps variable values.

import {
  Experimental_CssVarsProvider as CssVarsProvider,
  experimental_extendTheme as extendTheme,
  useColorScheme,
} from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
import DarkModeIcon from '@mui/icons-material/DarkMode';
import LightModeIcon from '@mui/icons-material/LightMode';
import type { ReactNode } from 'react';

// extendTheme replaces createTheme when using CssVarsProvider
const theme = extendTheme({
  colorSchemes: {
    light: {
      palette: {
        primary: { main: '#1976d2' },
        background: { default: '#fafafa', paper: '#ffffff' },
      },
    },
    dark: {
      palette: {
        primary: { main: '#90caf9' },
        background: { default: '#121212', paper: '#1e1e1e' },
      },
    },
  },
  typography: {
    fontFamily: '"Inter", sans-serif',
    button: { textTransform: 'none' },
  },
});

// Toggle component — switches mode via CSS variables, zero re-render
function ModeToggle() {
  const { mode, setMode } = useColorScheme();
  return (
    <IconButton
      onClick={() => setMode(mode === 'light' ? 'dark' : 'light')}
      aria-label={`Switch to ${mode === 'light' ? 'dark' : 'light'} mode`}
    >
      {mode === 'light' ? <DarkModeIcon /> : <LightModeIcon />}
    </IconButton>
  );
}

export function CssVarsApp({ children }: { children: ReactNode }) {
  return (
    <CssVarsProvider theme={theme} defaultMode="system">
      <CssBaseline enableColorScheme />
      <ModeToggle />
      {children}
    </CssVarsProvider>
  );
}

Accessing CSS Variables in sx

<Box
  sx={{
    // These reference the CSS variable, not a JS value
    color: 'var(--mui-palette-primary-main)',
    bgcolor: 'var(--mui-palette-background-paper)',
    borderRadius: 'var(--mui-shape-borderRadius)',
  }}
/>

CssVarsProvider with Multi-Tenant

Combine extendTheme with tenant overrides:

import { experimental_extendTheme as extendTheme } from '@mui/material/styles';
import deepmerge from '@mui/utils/deepmerge';

const baseExtended = {
  colorSchemes: {
    light: { palette: { primary: { main: '#1976d2' } } },
    dark: { palette: { primary: { main: '#90caf9' } } },
  },
};

function createTenantCssVarsTheme(overrides: Record<string, unknown>) {
  return extendTheme(deepmerge(baseExtended, overrides));
}

// Tenant override — only changes primary color for both schemes
const acmeCssVarsTheme = createTenantCssVarsTheme({
  colorSchemes: {
    light: { palette: { primary: { main: '#ff5722' } } },
    dark: { palette: { primary: { main: '#ff8a65' } } },
  },
});

Theme Registry Pattern

Map tenant IDs to theme objects. Useful when you have a known set of tenants at build time, or when you cache API-loaded themes.

import { createTheme, type Theme, type ThemeOptions } from '@mui/material/styles';
import deepmerge from '@mui/utils/deepmerge';

const baseOptions: ThemeOptions = {
  typography: { button: { textTransform: 'none' } },
  shape: { borderRadius: 8 },
};

// Registry: tenant ID -> theme options (only the diff from base)
const tenantThemeOverrides: Record<string, ThemeOptions> = {
  acme: {
    palette: { primary: { main: '#ff5722' }, secondary: { main: '#ff9800' } },
    typography: { fontFamily: '"Poppins", sans-serif' },
  },
  globex: {
    palette: { mode: 'dark', primary: { main: '#00bcd4' } },
    shape: { borderRadius: 4 },
  },
  initech: {
    palette: { primary: { main: '#4caf50' }, secondary: { main: '#8bc34a' } },
    typography: { fontFamily: '"Roboto Mono", monospace' },
  },
};

// Cache to avoid re-creating themes on every render
const themeCache = new Map<string, Theme>();

export function getTenantTheme(tenantId: string): Theme {
  const cached = themeCache.get(tenantId);
  if (cached) return cached;

  const overrides = tenantThemeOverrides[tenantId];
  if (!overrides) {
    console.warn(`No theme registered for tenant "${tenantId}", using base theme`);
    const fallback = createTheme(baseOptions);
    themeCache.set(tenantId, fallback);
    return fallback;
  }

  const theme = createTheme(deepmerge(baseOptions, overrides));
  themeCache.set(tenantId, theme);
  return theme;
}

// Dynamic registration for API-loaded tenants
export function registerTenantTheme(tenantId: string, overrides: ThemeOptions): void {
  tenantThemeOverrides[tenantId] = overrides;
  themeCache.delete(tenantId);  // invalidate cache
}

Usage:

import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import { getTenantTheme } from './theme-registry';

function App({ tenantId }: { tenantId: string }) {
  const theme = getTenantTheme(tenantId);
  return (
    <ThemeProvider theme={theme}>
      <CssBaseline />
      {/* app content */}
    </ThemeProvider>
  );
}

Component Variant Overrides per Tenant

Tenants may need different component appearances beyond colors — pill buttons for one brand, square for another, outlined defaults for a third.

import { createTheme, type ThemeOptions, type Components, type Theme } from '@mui/material/styles';
import deepmerge from '@mui/utils/deepmerge';

// Each tenant defines component overrides
type TenantComponents = Components<Omit<Theme, 'components'>>;

const acmeComponents: TenantComponents = {
  MuiButton: {
    defaultProps: { variant: 'contained', disableElevation: true },
    styleOverrides: {
      root: { borderRadius: 24, padding: '10px 28px', fontWeight: 700 },
      containedPrimary: {
        background: 'linear-gradient(45deg, #ff5722, #ff9800)',
        '&:hover': { background: 'linear-gradient(45deg, #e64a19, #f57c00)' },
      },
    },
  },
  MuiCard: {
    defaultProps: { elevation: 0 },
    styleOverrides: {
      root: {
        borderRadius: 16,
        border: '2px solid',
        borderColor: 'rgba(255, 87, 34, 0.2)',
      },
    },
  },
  MuiChip: {
    defaultProps: { variant: 'filled' },
    styleOverrides: {
      root: { borderRadius: 24, fontWeight: 600 },
    },
  },
};

const initechComponents: TenantComponents = {
  MuiButton: {
    defaultProps: { variant: 'outlined' },
    styleOverrides: {
      root: { borderRadius: 0, textTransform: 'uppercase', letterSpacing: 1 },
    },
  },
  MuiCard: {
    defaultProps: { elevation: 2 },
    styleOverrides: {
      root: { borderRadius: 0 },
    },
  },
};

// Compose with base theme
const baseOptions: ThemeOptions = {
  typography: { button: { textTransform: 'none' } },
};

export const acmeTheme = createTheme(
  deepmerge(baseOptions, {
    palette: { primary: { main: '#ff5722' } },
    components: acmeComponents,
  }),
);

export const initechTheme = createTheme(
  deepmerge(baseOptions, {
    palette: { primary: { main: '#4caf50' } },
    components: initechComponents,
  }),
);

TypeScript for Multi-Theme

Generic Theme Factory Function

import { createTheme, type Theme, type ThemeOptions } from '@mui/material/styles';
import deepmerge from '@mui/utils/deepmerge';

// Shared base type for all tenant configs
interface TenantThemeConfig {
  tenantId: string;
  palette: {
    primary: string;
    secondary: string;
    mode?: 'light' | 'dark';
  };
  typography?: {
    fontFamily?: string;
    headingFontFamily?: string;
  };
  shape?: {
    borderRadius?: number;
  };
  components?: ThemeOptions['components'];
}

const baseThemeOptions: ThemeOptions = {
  typography: {
    fontFamily: '"Inter", sans-serif',
    button: { textTransform: 'none' },
  },
  shape: { borderRadius: 8 },
  components: {
    MuiButton: { defaultProps: { disableElevation: true } },
    MuiTextField: { defaultProps: { variant: 'outlined', size: 'small' } },
  },
};

export function createThemeFromConfig(config: TenantThemeConfig): Theme {
  const overrides: ThemeOptions = {
    palette: {
      mode: config.palette.mode ?? 'light',
      primary: { main: config.palette.primary },
      secondary: { main: config.palette.secondary },
    },
    ...(config.typography && {
      typography: {
        fontFamily: config.typography.fontFamily,
        ...(config.typography.headingFontFamily && {
          h1: { fontFamily: config.typography.headingFontFamily },
          h2: { fontFamily: config.typography.headingFontFamily },
          h3: { fontFamily: config.typography.headingFontFamily },
          h4: { fontFamily: config.typography.headingFontFamily },
        }),
      },
    }),
    ...(config.shape && { shape: config.shape }),
    ...(config.components && { components: config.components }),
  };

  return createTheme(deepmerge(baseThemeOptions, overrides));
}

// Type-safe tenant registry
const configs: Record<string, TenantThemeConfig> = {
  acme: {
    tenantId: 'acme',
    palette: { primary: '#ff5722', secondary: '#ff9800' },
    typography: { fontFamily: '"Poppins", sans-serif' },
  },
  globex: {
    tenantId: 'globex',
    palette: { primary: '#00bcd4', secondary: '#7c4dff', mode: 'dark' },
    shape: { borderRadius: 4 },
  },
};

export function getThemeForTenant(tenantId: string): Theme {
  const config = configs[tenantId];
  if (!config) throw new Error(`Unknown tenant: ${tenantId}`);
  return createThemeFromConfig(config);
}

Augmenting the Theme Type for Custom Tokens

import { createTheme } from '@mui/material/styles';

// Declare custom tokens on the theme
declare module '@mui/material/styles' {
  interface Theme {
    brand: {
      logoUrl: string;
      logoHeight: number;
      appName: string;
    };
  }
  interface ThemeOptions {
    brand?: {
      logoUrl?: string;
      logoHeight?: number;
      appName?: string;
    };
  }
}

const acmeTheme = createTheme({
  palette: { primary: { main: '#ff5722' } },
  brand: {
    logoUrl: '/brands/acme/logo.svg',
    logoHeight: 40,
    appName: 'Acme Portal',
  },
});

// Now type-safe in any component:
// const theme = useTheme();
// theme.brand.logoUrl  <-- autocompletes

Performance

Memoize Theme Creation

createTheme is expensive. Never call it inside a render function without memoization.

import { useMemo } from 'react';
import { createTheme, ThemeProvider, type ThemeOptions } from '@mui/material/styles';
import deepmerge from '@mui/utils/deepmerge';

const baseOptions: ThemeOptions = { /* ... */ };

function TenantApp({ overrides, children }: { overrides: ThemeOptions; children: React.ReactNode }) {
  // GOOD — only re-creates when overrides reference changes
  const theme = useMemo(
    () => createTheme(deepmerge(baseOptions, overrides)),
    [overrides],
  );

  return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
}

Avoid Re-Creating Overrides Object

// BAD — new object on every render, theme re-created every time
function App({ primaryColor }: { primaryColor: string }) {
  return (
    <TenantApp overrides={{ palette: { primary: { main: primaryColor } } }}>
      {/* ... */}
    </TenantApp>
  );
}

// GOOD — stable reference
function App({ primaryColor }: { primaryColor: string }) {
  const overrides = useMemo(
    () => ({ palette: { primary: { main: primaryColor } } }),
    [primaryColor],
  );
  return <TenantApp overrides={overrides}>{/* ... */}</TenantApp>;
}

Cache Themes for Known Tenants

See the Theme Registry Pattern section above. The Map-based cache prevents re-creating the same theme on navigation or re-mount.


Complete White-Label Architecture

Full example tying together theme factory, tenant loader, brand context, and provider.

File: lib/brand/types.ts

export interface TenantBrandConfig {
  tenantId: string;
  name: string;
  domain: string;
  logoUrl: string;
  logoHeight: number;
  faviconUrl: string;
  palette: {
    mode: 'light' | 'dark';
    primary: string;
    secondary: string;
    error?: string;
    warning?: string;
    success?: string;
  };
  typography: {
    fontFamily: string;
    headingFontFamily?: string;
    googleFontsUrl?: string;   // link to Google Fonts CSS
  };
  shape: {
    borderRadius: number;
  };
  components?: {
    buttonVariant?: 'contained' | 'outlined' | 'text';
    buttonBorderRadius?: number;
    cardElevation?: number;
    cardBorderRadius?: number;
  };
}

File: lib/brand/theme-factory.ts

import { createTheme, type Theme, type ThemeOptions } from '@mui/material/styles';
import deepmerge from '@mui/utils/deepmerge';
import type { TenantBrandConfig } from './types';

const BASE_THEME: ThemeOptions = {
  typography: {
    button: { textTransform: 'none', fontWeight: 600 },
    h1: { fontWeight: 800 },
    h2: { fontWeight: 700 },
  },
  components: {
    MuiButton: { defaultProps: { disableElevation: true } },
    MuiTextField: { defaultProps: { variant: 'outlined', size: 'small' } },
    MuiCssBaseline: {
      styleOverrides: {
        body: { scrollBehavior: 'smooth' },
      },
    },
  },
};

const cache = new Map<string, Theme>();

export function createBrandTheme(config: TenantBrandConfig): Theme {
  const cached = cache.get(config.tenantId);
  if (cached) return cached;

  const overrides: ThemeOptions = {
    palette: {
      mode: config.palette.mode,
      primary: { main: config.palette.primary },
      secondary: { main: config.palette.secondary },
      ...(config.palette.error && { error: { main: config.palette.error } }),
      ...(config.palette.warning && { warning: { main: config.palette.warning } }),
      ...(config.palette.success && { success: { main: config.palette.success } }),
    },
    typography: {
      fontFamily: config.typography.fontFamily,
      ...(config.typography.headingFontFamily && {
        h1: { fontFamily: config.typography.headingFontFamily },
        h2: { fontFamily: config.typography.headingFontFamily },
        h3: { fontFamily: config.typography.headingFontFamily },
        h4: { fontFamily: config.typography.headingFontFamily },
      }),
    },
    shape: { borderRadius: config.shape.borderRadius },
    components: {
      ...(config.components?.buttonVariant && {
        MuiButton: {
          defaultProps: { variant: config.components.buttonVariant },
          ...(config.components.buttonBorderRadius != null && {
            styleOverrides: {
              root: { borderRadius: config.components.buttonBorderRadius },
            },
          }),
        },
      }),
      ...(config.components?.cardElevation != null && {
        MuiCard: {
          defaultProps: { elevation: config.components.cardElevation },
          ...(config.components.cardBorderRadius != null && {
            styleOverrides: {
              root: { borderRadius: config.components.cardBorderRadius },
            },
          }),
        },
      }),
    },
  };

  const theme = createTheme(deepmerge(BASE_THEME, overrides));
  cache.set(config.tenantId, theme);
  return theme;
}

export function invalidateBrandCache(tenantId?: string): void {
  if (tenantId) {
    cache.delete(tenantId);
  } else {
    cache.clear();
  }
}

File: lib/brand/BrandProvider.tsx

import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import CircularProgress from '@mui/material/CircularProgress';
import Box from '@mui/material/Box';
import {
  createContext,
  useContext,
  useState,
  useEffect,
  useMemo,
  type ReactNode,
} from 'react';
import type { TenantBrandConfig } from './types';
import { createBrandTheme } from './theme-factory';

// --- Brand Context ---
const BrandContext = createContext<TenantBrandConfig | null>(null);

export function useBrand(): TenantBrandConfig {
  const ctx = useContext(BrandContext);
  if (!ctx) throw new Error('useBrand() must be used within <BrandProvider>');
  return ctx;
}

// --- Tenant Loader ---
async function loadTenantConfig(tenantId: string): Promise<TenantBrandConfig> {
  const res = await fetch(`/api/tenants/${tenantId}/brand`);
  if (!res.ok) throw new Error(`Brand config fetch failed (${res.status})`);
  return res.json();
}

// --- Font Loader ---
function loadGoogleFonts(url: string): void {
  if (document.querySelector(`link[href="${url}"]`)) return;
  const link = document.createElement('link');
  link.rel = 'stylesheet';
  link.href = url;
  document.head.appendChild(link);
}

// --- Favicon Setter ---
function setFavicon(url: string): void {
  let link = document.querySelector<HTMLLinkElement>('link[rel="icon"]');
  if (!link) {
    link = document.createElement('link');
    link.rel = 'icon';
    document.head.appendChild(link);
  }
  link.href = url;
}

// --- Provider Component ---
interface BrandProviderProps {
  tenantId: string;
  fallbackConfig?: TenantBrandConfig;   // optional static fallback
  children: ReactNode;
}

export function BrandProvider({ tenantId, fallbackConfig, children }: BrandProviderProps) {
  const [config, setConfig] = useState<TenantBrandConfig | null>(fallbackConfig ?? null);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    let cancelled = false;
    loadTenantConfig(tenantId)
      .then((cfg) => {
        if (cancelled) return;
        setConfig(cfg);

        // Side effects: load fonts, set favicon, set document title
        if (cfg.typography.googleFontsUrl) loadGoogleFonts(cfg.typography.googleFontsUrl);
        if (cfg.faviconUrl) setFavicon(cfg.faviconUrl);
        document.title = cfg.name;
      })
      .catch((err) => {
        if (!cancelled) setError(err.message);
      });
    return () => { cancelled = true; };
  }, [tenantId]);

  const theme = useMemo(() => (config ? createBrandTheme(config) : null), [config]);

  if (error && !config) {
    return (
      <Box sx={{ p: 4, textAlign: 'center' }}>
        <Box sx={{ color: 'error.main', mb: 1 }}>Failed to load brand: {error}</Box>
      </Box>
    );
  }

  if (!theme || !config) {
    return (
      <Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', minHeight: '100vh' }}>
        <CircularProgress />
      </Box>
    );
  }

  return (
    <BrandContext.Provider value={config}>
      <ThemeProvider theme={theme}>
        <CssBaseline />
        {children}
      </ThemeProvider>
    </BrandContext.Provider>
  );
}

File: App.tsx (entry point)

import { BrandProvider } from './lib/brand/BrandProvider';
import { BrandedHeader } from './components/BrandedHeader';
import { Dashboard } from './pages/Dashboard';

// Tenant ID typically comes from subdomain, URL param, or env variable
function getTenantId(): string {
  const subdomain = window.location.hostname.split('.')[0];
  return subdomain === 'localhost' ? 'acme' : subdomain;
}

export default function App() {
  const tenantId = getTenantId();

  return (
    <BrandProvider tenantId={tenantId}>
      <BrandedHeader />
      <Dashboard />
    </BrandProvider>
  );
}

File: components/BrandedHeader.tsx

import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import { useBrand } from '../lib/brand/BrandProvider';

export function BrandedHeader() {
  const brand = useBrand();

  return (
    <AppBar position="static" color="primary">
      <Toolbar>
        <Box
          component="img"
          src={brand.logoUrl}
          alt={`${brand.name} logo`}
          sx={{ height: brand.logoHeight, mr: 2 }}
        />
        <Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
          {brand.name}
        </Typography>
      </Toolbar>
    </AppBar>
  );
}

平台分布

Codex

35.1%
按下载量换算24

Claude

30.8%
按下载量换算21

Cursor

17.34%
按下载量换算12

Gemini CLI

8.88%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills