igniteui-angular-theming
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseIgnite UI for Angular — Theming Skill
Ignite UI for Angular — 主题定制技能
Description
说明
This skill teaches AI agents how to theme Ignite UI for Angular applications using the Sass-based theming system and the Ignite UI Theming MCP server. It covers global themes, palettes, typography, elevations, component-level theming, layout controls (spacing, sizing, roundness), and how to use the MCP tools for code generation.
本技能旨在教会AI代理如何使用基于Sass的主题系统和Ignite UI Theming MCP服务器为Ignite UI for Angular应用设置主题。内容涵盖全局主题、调色板、排版、阴影层级、组件级主题、布局控件(间距、尺寸、圆角),以及如何使用MCP工具生成代码。
Prerequisites
前置要求
- An Angular project with installed, or
igniteui-angularfor licensed users@infragistics/igniteui-angular - Sass support enabled in the project (default for Angular CLI projects)
- The Ignite UI Theming MCP server () available as a tool provider
igniteui-theming
AGENT INSTRUCTION — MCP Server Setup (REQUIRED)Before using any theming tools, you MUST verify the MCP server is available by calling. If the tool is not available or the call fails, you MUST automatically configure it by following the setup process steps described below.detect_platformAfter writing the file, inform the user that the MCP server has been configured and they may need to reload the editor for the tools to activate. Start the MCP server and wait for that MCP server to start before continuing the theming related work. Do NOT skip this step or ask the user to do it manually.
- 已安装的Angular项目,或授权用户使用的
igniteui-angular@infragistics/igniteui-angular - 项目已启用Sass支持(Angular CLI项目默认支持)
- 可获取Ignite UI Theming MCP服务器()作为工具提供商
igniteui-theming
代理指令 — MCP服务器配置(必填)在使用任何主题工具前,必须通过调用验证MCP服务器是否可用。若工具不可用或调用失败,必须按照以下设置步骤自动完成配置。detect_platform配置文件编写完成后,告知用户MCP服务器已配置,可能需要重新加载编辑器以激活工具。启动MCP服务器并等待其运行后,再继续主题相关操作。 请勿跳过此步骤或让用户手动操作。
Setting Up the Theming MCP Server
配置主题MCP服务器
The Ignite UI Theming MCP server enables AI assistants to generate production-ready theming code. It must be configured in your editor before the theming tools become available.
Ignite UI Theming MCP服务器可让AI助手生成可用于生产环境的主题代码。在主题工具可用前,必须先在编辑器中完成配置。
VS Code
VS Code
Create or edit in your project:
.vscode/mcp.jsonjson
{
"servers": {
"igniteui-theming": {
"command": "npx",
"args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
}
}
}This works whether is installed locally in or needs to be pulled from the npm registry — handles both cases.
igniteui-themingnode_modulesnpx -y在项目中创建或编辑:
.vscode/mcp.jsonjson
{
"servers": {
"igniteui-theming": {
"command": "npx",
"args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
}
}
}无论是已本地安装在中还是需要从npm仓库拉取,此配置均可生效——会自动处理这两种情况。
igniteui-themingnode_modulesnpx -yCursor
Cursor
Create or edit :
.cursor/mcp.jsonjson
{
"mcpServers": {
"igniteui-theming": {
"command": "npx",
"args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
}
}
}创建或编辑:
.cursor/mcp.jsonjson
{
"mcpServers": {
"igniteui-theming": {
"command": "npx",
"args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
}
}
}Claude Desktop
Claude Desktop
Edit the Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
json
{
"mcpServers": {
"igniteui-theming": {
"command": "npx",
"args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
}
}
}编辑Claude Desktop配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
json
{
"mcpServers": {
"igniteui-theming": {
"command": "npx",
"args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
}
}
}WebStorm / JetBrains IDEs
WebStorm / JetBrains IDEs
- Go to Settings → Tools → AI Assistant → MCP Servers
- Click + Add MCP Server
- Set Command to and Arguments to
npxigniteui-theming igniteui-theming-mcp - Click OK and restart the AI Assistant
- 进入设置 → 工具 → AI助手 → MCP服务器
- 点击**+ 添加MCP服务器**
- 设置命令为,参数为
npxigniteui-theming igniteui-theming-mcp - 点击确定并重启AI助手
Verifying the Setup
验证配置
After configuring the MCP server, ask your AI assistant:
"Detect which Ignite UI platform my project uses"
If the MCP server is running, the tool will analyze your and return the detected platform (e.g., ).
detect_platformpackage.jsonangular配置完成后,可向AI助手询问:
"检测我的项目使用的是哪个Ignite UI平台"
若MCP服务器已运行,工具会分析你的并返回检测到的平台(如)。
detect_platformpackage.jsonangularTheming Architecture
主题架构
The Ignite UI theming system is built on four pillars:
| Concept | Purpose |
|---|---|
| Palette | Color system with primary, secondary, surface, gray, info, success, warn, error families, each with shades 50–900 + accents A100–A700 |
| Typography | Font family, type scale (h1–h6, subtitle, body, button, caption, overline) |
| Elevations | Box-shadow levels 0–24 for visual depth |
| Schema | Per-component recipes mapping palette colors to component tokens |
Design Systems
设计系统
Four built-in design systems are available:
- Material (default) — Material Design 3
- Bootstrap — Bootstrap-inspired
- Fluent — Microsoft Fluent Design
- Indigo — Infragistics Indigo Design
Each has light and dark variants (e.g., , ).
$light-material-schema$dark-fluent-schema内置四种设计系统:
- Material(默认)—— Material Design 3
- Bootstrap —— 受Bootstrap启发
- Fluent —— Microsoft Fluent Design
- Indigo —— Infragistics Indigo Design
每个设计系统都有浅色和深色变体(如、)。
$light-material-schema$dark-fluent-schemaPre-built Themes
预构建主题
The quickest way to theme an app is to include a pre-built CSS file in :
angular.jsonjson
"styles": ["node_modules/igniteui-angular/styles/igniteui-angular.css"]Licensed package users: replacewithigniteui-angularin the path:@infragistics/igniteui-angularjson"styles": ["node_modules/@infragistics/igniteui-angular/styles/igniteui-angular.css"]
Available pre-built CSS files:
| File | Theme |
|---|---|
| Material Light |
| Material Dark |
| Fluent Light |
| Fluent Dark |
| Bootstrap Light |
| Bootstrap Dark |
| Indigo Light |
| Indigo Dark |
All files are located under (or for the licensed package).
node_modules/igniteui-angular/styles/node_modules/@infragistics/igniteui-angular/styles/为应用设置主题最快的方式是在中引入预构建的CSS文件:
angular.jsonjson
"styles": ["node_modules/igniteui-angular/styles/igniteui-angular.css"]授权包用户:将路径中的替换为igniteui-angular:@infragistics/igniteui-angularjson"styles": ["node_modules/@infragistics/igniteui-angular/styles/igniteui-angular.css"]
可用的预构建CSS文件:
| 文件 | 主题 |
|---|---|
| Material浅色主题 |
| Material深色主题 |
| Fluent浅色主题 |
| Fluent深色主题 |
| Bootstrap浅色主题 |
| Bootstrap深色主题 |
| Indigo浅色主题 |
| Indigo深色主题 |
所有文件均位于(授权包用户则位于)。
node_modules/igniteui-angular/styles/node_modules/@infragistics/igniteui-angular/styles/Custom Sass Theme (Manual)
自定义Sass主题(手动)
AGENT INSTRUCTION — Sass Theming Docs: If the user explicitly asks to build a Sass-based theme or configure Sass, refer to the dedicated Sass documentation:
Create a file and include it in :
styles.scssangular.jsonscss
// Open-source package
@use 'igniteui-angular/theming' as *;
// Licensed package — same Sass API, different import path
// @use '@infragistics/igniteui-angular/theming' as *;
$my-palette: palette(
$primary: #1976D2,
$secondary: #FF9800,
$surface: #FAFAFA
);
// 2. Typography (optional)
@include typography(
$font-family: $material-typeface,
$type-scale: $material-type-scale
);
// 3. Core reset & base styles
@include core();
// 4. Apply theme
@include theme(
$palette: $my-palette,
$schema: $light-material-schema
);For dark themes, use a dark surface color and a dark schema:
scss
$dark-palette: palette(
$primary: #90CAF9,
$secondary: #FFB74D,
$surface: #121212
);
@include theme(
$palette: $dark-palette,
$schema: $dark-material-schema
);代理指令 — Sass主题文档:若用户明确要求构建基于Sass的主题或配置Sass,请参考专门的Sass文档:
创建文件并将其引入:
styles.scssangular.jsonscss
// 开源包
@use 'igniteui-angular/theming' as *;
// 授权包 — Sass API相同,仅导入路径不同
// @use '@infragistics/igniteui-angular/theming' as *;
$my-palette: palette(
$primary: #1976D2,
$secondary: #FF9800,
$surface: #FAFAFA
);
// 2. 排版(可选)
@include typography(
$font-family: $material-typeface,
$type-scale: $material-type-scale
);
// 3. 核心重置与基础样式
@include core();
// 4. 应用主题
@include theme(
$palette: $my-palette,
$schema: $light-material-schema
);若要设置深色主题,需使用深色背景色和深色样式方案:
scss
$dark-palette: palette(
$primary: #90CAF9,
$secondary: #FFB74D,
$surface: #121212
);
@include theme(
$palette: $dark-palette,
$schema: $dark-material-schema
);Component-Level Theming
组件级主题
Docs: Component Themes
Override individual component appearance using component theme functions and the mixin.
tokensAGENT INSTRUCTION — No Hardcoded Colors (CRITICAL)Once a palette has been generated (viain Sass orpalette()/create_palettevia MCP), every color reference MUST come from the generated palette tokens — never hardcode hex/RGB/HSL values.create_themeUse,var(--ig-primary-500),var(--ig-secondary-300), etc. in CSS, or thevar(--ig-surface-500)MCP tool to obtain the correct token reference.get_colorWRONG (hardcoded hex — breaks theme switching, ignores the palette):scss$custom-avatar: avatar-theme( $background: #E91E63, $color: #FFFFFF );RIGHT (palette token — stays in sync with the theme):scss$custom-avatar: avatar-theme( $schema: $light-material-schema, $background: var(--ig-primary-500), $color: var(--ig-primary-500-contrast) );This applies to all style code: component themes, custom CSS rules, Sass variables used for borders/backgrounds/text, Angularbindings, and inline styles. The only place raw hex values belong is the initialhostcall that seeds the color system. Everything downstream must reference the palette.palette()
scss
@use 'igniteui-angular/theming' as *;
$custom-avatar: avatar-theme(
$schema: $light-material-schema,
$background: var(--ig-primary-500),
$color: var(--ig-primary-500-contrast)
);
igx-avatar {
@include tokens($custom-avatar);
}文档:组件主题
可使用组件主题函数和混合宏覆盖单个组件的外观。
tokens代理指令 — 禁止硬编码颜色(关键规则)一旦通过Sass的函数或MCP的palette()/create_palette工具生成了调色板,所有颜色引用必须来自生成的调色板令牌——绝对不能硬编码十六进制/RGB/HSL值。create_theme在CSS中使用、var(--ig-primary-500)、var(--ig-secondary-300)等,或使用MCP的var(--ig-surface-500)工具获取正确的令牌引用。get_color错误示例(硬编码十六进制值——会破坏主题切换,脱离调色板控制):scss$custom-avatar: avatar-theme( $background: #E91E63, $color: #FFFFFF );正确示例(使用调色板令牌——与主题保持同步):scss$custom-avatar: avatar-theme( $schema: $light-material-schema, $background: var(--ig-primary-500), $color: var(--ig-primary-500-contrast) );此规则适用于所有样式代码:组件主题、自定义CSS规则、用于边框/背景/文本的Sass变量、Angular绑定和内联样式。 唯一允许使用原始十六进制值的地方是初始化host调用,用于为配色系统提供初始值。 后续所有内容都必须引用调色板。palette()
scss
@use 'igniteui-angular/theming' as *;
$custom-avatar: avatar-theme(
$schema: $light-material-schema,
$background: var(--ig-primary-500),
$color: var(--ig-primary-500-contrast)
);
igx-avatar {
@include tokens($custom-avatar);
}Discovering Available Tokens
查看可用令牌
Each component has its own set of design tokens (themeable CSS custom properties). Before theming a component, you must know which tokens exist. Use the MCP tool to discover them.
get_component_design_tokens每个组件都有自己的设计令牌(可主题化的CSS自定义属性)。在为组件设置主题前,必须先了解可用的令牌。使用MCP工具来查看。
get_component_design_tokensCompound Components
复合组件
Some components (e.g., , , , ) are compound — they contain internal child components, each requiring their own theme. For example, uses , , and internally.
combogriddate-pickerselectdate-pickercalendarflat-buttoninput-groupWorkflow for compound components:
- Call for the parent (e.g.,
get_component_design_tokens)date-picker - The response lists related themes and scope selectors
- Call for each child, using the parent's selector as the wrapper
create_component_theme
部分组件(如、、、)属于复合组件——它们包含内部子组件,每个子组件都需要单独设置主题。例如,内部使用了、和。
combogriddate-pickerselectdate-pickercalendarflat-buttoninput-group复合组件的主题设置流程:
- 为父组件(如)调用
date-pickerget_component_design_tokens - 响应结果会列出相关主题和作用域选择器
- 为每个子组件调用,使用父组件的选择器作为包裹器
create_component_theme
Layout Controls
布局控件
Sizing
尺寸
Docs: Display Density / Sizing
Controls the size of components via (values: 1 = small, 2 = medium, 3 = large):
--ig-sizecss
/* Global */
:root { --ig-size: 2; }
/* Component-scoped */
igx-grid { --ig-size: 1; }文档:显示密度/尺寸
通过控制组件尺寸(取值:1=小,2=中,3=大):
--ig-sizecss
/* 全局设置 */
:root { --ig-size: 2; }
/* 组件级设置 */
igx-grid { --ig-size: 1; }Spacing
间距
Docs: Spacing
Controls internal padding via (1 = default, 0.5 = compact, 2 = spacious):
--ig-spacingcss
:root { --ig-spacing: 1; }
.compact-section { --ig-spacing: 0.75; }文档:间距
通过控制内部边距(1=默认,0.5=紧凑,2=宽松):
--ig-spacingcss
:root { --ig-spacing: 1; }
.compact-section { --ig-spacing: 0.75; }Roundness
圆角
Controls border-radius via (0 = square, 1 = maximum radius):
--ig-radius-factorcss
:root { --ig-radius-factor: 1; }
igx-avatar { --ig-radius-factor: 0.5; }通过控制边框圆角(0=方形,1=最大圆角):
--ig-radius-factorcss
:root { --ig-radius-factor: 1; }
igx-avatar { --ig-radius-factor: 0.5; }Using the Theming MCP Server
使用主题MCP服务器
The Ignite UI Theming MCP server provides tools for AI-assisted theme code generation.
IMPORTANT — File Safety Rule: When generating or updating theme code, never overwrite existing style files directly. Instead, always propose the changes as an update and let the user review and approve before writing to disk. If a(or any target file) already exists, show the generated code as a diff or suggestion rather than replacing the file contents. This prevents accidental loss of custom styles the user has already written.styles.scss
Always follow this workflow:
Ignite UI Theming MCP服务器提供AI辅助的主题代码生成工具。
重要 — 文件安全规则:生成或更新主题代码时,绝对不能直接覆盖现有样式文件。应始终将变更作为更新建议,让用户审核并批准后再写入磁盘。若(或任何目标文件)已存在,应将生成的代码作为差异或建议展示,而非替换文件内容。这可避免意外丢失用户已编写的自定义样式。styles.scss
请始终遵循以下流程:
Step 1 — Detect Platform
步骤1 — 检测平台
Tool: detect_platformThis auto-detects from and sets the correct import paths.
angularpackage.json工具: detect_platform该工具会自动从中检测平台,并设置正确的导入路径。
package.jsonangularStep 2 — Generate a Full Theme
步骤2 — 生成完整主题
Tool: create_theme
Params: {
platform: "angular",
designSystem: "material",
primaryColor: "#1976D2",
secondaryColor: "#FF9800",
surfaceColor: "#FAFAFA",
variant: "light",
fontFamily: "'Roboto', sans-serif",
includeTypography: true,
includeElevations: true
}Generates a complete Sass file with palette, typography, elevations, and the mixin call.
theme()工具: create_theme
参数: {
platform: "angular",
designSystem: "material",
primaryColor: "#1976D2",
secondaryColor: "#FF9800",
surfaceColor: "#FAFAFA",
variant: "light",
fontFamily: "'Roboto', sans-serif",
includeTypography: true,
includeElevations: true
}生成包含调色板、排版、阴影层级和混合宏调用的完整Sass文件。
theme()Step 3 — Customize Individual Components
步骤3 — 自定义单个组件
Tool: get_component_design_tokens
Params: { component: "grid" }Then use palette token references (not hardcoded hex values) for every color:
Tool: create_component_theme
Params: {
platform: "angular",
designSystem: "material",
variant: "light",
component: "grid",
tokens: {
"header-background": "var(--ig-primary-50)",
"header-text-color": "var(--ig-primary-800)"
}
}Reminder: After a palette is generated, all token values passed tomust reference palette CSS custom properties (e.g.,create_component_theme,var(--ig-primary-500),var(--ig-secondary-A200)). Never pass raw hex values likevar(--ig-gray-100)."#E3F2FD"
工具: get_component_design_tokens
参数: { component: "grid" }然后使用调色板令牌引用(而非硬编码的十六进制值)设置所有颜色:
工具: create_component_theme
参数: {
platform: "angular",
designSystem: "material",
variant: "light",
component: "grid",
tokens: {
"header-background": "var(--ig-primary-50)",
"header-text-color": "var(--ig-primary-800)"
}
}提醒:生成调色板后,传递给的所有令牌值必须引用调色板的CSS自定义属性(如create_component_theme、var(--ig-primary-500)、var(--ig-secondary-A200))。绝对不能传递像var(--ig-gray-100)这样的原始十六进制值。"#E3F2FD"
Step 4 — Generate a Palette
步骤4 — 生成调色板
For simple mid-luminance base colors:
Tool: create_palette
Params: {
platform: "angular",
primary: "#1976D2",
secondary: "#FF9800",
surface: "#FAFAFA",
variant: "light"
}For brand-specific exact shade values, use with for full control over each shade.
create_custom_palettemode: "explicit"对于中等亮度的基础颜色:
工具: create_palette
参数: {
platform: "angular",
primary: "#1976D2",
secondary: "#FF9800",
surface: "#FAFAFA",
variant: "light"
}对于品牌特定的精确色调,可使用并设置以完全控制每个色调。
create_custom_palettemode: "explicit"Step 5 — Adjust Layout
步骤5 — 调整布局
Tool: set_size → { size: "medium" }
Tool: set_spacing → { spacing: 0.75, component: "grid" }
Tool: set_roundness → { radiusFactor: 0.8 }工具: set_size → { size: "medium" }
工具: set_spacing → { spacing: 0.75, component: "grid" }
工具: set_roundness → { radiusFactor: 0.8 }Step 6 — Reference Palette Colors (MANDATORY for All Color Usage)
步骤6 — 引用调色板颜色(所有颜色使用的强制规则)
After a palette is generated, always use the tool to obtain the correct CSS custom property reference. Never hardcode hex/RGB/HSL values in component themes, custom CSS, or Sass variables.
get_colorTool: get_color
Params: { color: "primary", variant: "600" }
→ var(--ig-primary-600)
Params: { color: "primary", variant: "600", contrast: true }
→ var(--ig-primary-600-contrast)
Params: { color: "primary", opacity: 0.5 }
→ hsl(from var(--ig-primary-500) h s l / 0.5)Use these token references everywhere:
- Component theme values
tokens - Custom CSS rules (,
color,background,border-color,fill, etc.)stroke - Sass variables for derived values ()
$sidebar-bg: var(--ig-surface-500); - Angular style bindings
host
The only place raw hex values are acceptable is in the initial call or the / MCP tool inputs that seed the color system.
palette()create_palettecreate_theme生成调色板后,必须使用工具获取正确的CSS自定义属性引用。绝对不能在组件主题、自定义CSS或Sass变量中硬编码十六进制/RGB/HSL值。
get_color工具: get_color
参数: { color: "primary", variant: "600" }
→ var(--ig-primary-600)
参数: { color: "primary", variant: "600", contrast: true }
→ var(--ig-primary-600-contrast)
参数: { color: "primary", opacity: 0.5 }
→ hsl(from var(--ig-primary-500) h s l / 0.5)以下场景均需使用这些令牌引用:
- 组件主题的值
tokens - 自定义CSS规则(、
color、background、border-color、fill等)stroke - 用于派生值的Sass变量(如)
$sidebar-bg: var(--ig-surface-500); - Angular样式绑定
host
唯一允许使用原始十六进制值的地方是初始化调用,或/ MCP工具的输入参数,即为配色系统提供初始值的地方。
palette()create_palettecreate_themeLoading Reference Data
加载参考数据
Use with these URIs for preset values and documentation:
read_resource| URI | Content |
|---|---|
| Preset palette colors |
| Typography presets |
| Elevation shadow presets |
| Which shades for which purpose |
| Semantic color roles |
| Light/dark theme rules |
| Angular platform specifics |
使用工具并传入以下URI获取预设值和文档:
read_resource| URI | 内容 |
|---|---|
| 预设调色板颜色 |
| 排版预设 |
| 阴影层级预设 |
| 各色调的使用场景 |
| 语义化颜色角色 |
| 浅色/深色主题规则 |
| Angular平台专属内容 |
Referencing Colors in Custom Styles
自定义样式中的颜色引用
After a theme is applied, the palette is available as CSS custom properties on . Use these tokens in all custom CSS — never introduce standalone hex/RGB variables for colors that the palette already provides.
:root应用主题后,调色板会以CSS自定义属性的形式存在于上。在所有自定义CSS中都应使用这些令牌——绝对不能为调色板已包含的颜色单独定义十六进制/RGB变量。
:rootCorrect: Palette Tokens
正确示例:使用调色板令牌
scss
// All colors come from the theme — respects palette changes and dark/light switching
.sidebar {
background: var(--ig-surface-500);
color: var(--ig-gray-900);
border-right: 1px solid var(--ig-gray-200);
}
.accent-badge {
background: var(--ig-secondary-500);
color: var(--ig-secondary-500-contrast);
}
.hero-section {
// Semi-transparent primary overlay
background: hsl(from var(--ig-primary-500) h s l / 0.12);
}scss
// 所有颜色均来自主题——会随调色板变更和深浅主题切换自动适配
.sidebar {
background: var(--ig-surface-500);
color: var(--ig-gray-900);
border-right: 1px solid var(--ig-gray-200);
}
.accent-badge {
background: var(--ig-secondary-500);
color: var(--ig-secondary-500-contrast);
}
.hero-section {
// 半透明主色覆盖层
background: hsl(from var(--ig-primary-500) h s l / 0.12);
}Incorrect: Hardcoded Values
错误示例:硬编码值
scss
// WRONG — these break when the palette changes and ignore dark/light mode
$primary-color: #00838F; // ✗ hardcoded
$secondary-color: #3D5AFE; // ✗ hardcoded
$surface-color: #F0F5FA; // ✗ hardcoded
.sidebar {
background: $surface-color; // ✗ not a palette token
color: #333; // ✗ not a palette token
}scss
// 错误——调色板变更时会失效,且不支持深浅主题切换
$primary-color: #00838F; // ✗ 硬编码
$secondary-color: #3D5AFE; // ✗ 硬编码
$surface-color: #F0F5FA; // ✗ 硬编码
.sidebar {
background: $surface-color; // ✗ 未使用调色板令牌
color: #333; // ✗ 未使用调色板令牌
}When Raw Hex Values Are OK
允许使用原始十六进制值的场景
Raw hex values are acceptable only in these contexts:
- call — the initial seed colors that generate the full palette
palette() - /
create_paletteMCP tool inputs — the base colors passed to the toolcreate_theme - Non-palette decorative values — e.g., a one-off SVG illustration color that intentionally stays fixed regardless of theme
Everything else must use tokens.
var(--ig-<family>-<shade>)仅在以下场景中允许使用原始十六进制值:
- 调用——生成完整调色板的初始种子颜色
palette() - /
create_paletteMCP工具输入——传递给工具的基础颜色create_theme - 非调色板装饰性值——例如,独立SVG插图的颜色,无论主题如何都保持固定
其他所有场景都必须使用令牌。
var(--ig-<family>-<shade>)Common Patterns
常见模式
Switching Between Light and Dark Themes
深浅主题切换
scss
@use 'igniteui-angular/theming' as *;
$light-palette: palette($primary: #1976D2, $secondary: #FF9800, $surface: #FAFAFA);
$dark-palette: palette($primary: #90CAF9, $secondary: #FFB74D, $surface: #121212);
@include core();
@include typography($font-family: $material-typeface, $type-scale: $material-type-scale);
// Light is default
@include theme($palette: $light-palette, $schema: $light-material-schema);
// Dark via class on <body> or <html>
.dark-theme {
@include theme($palette: $dark-palette, $schema: $dark-material-schema);
}scss
@use 'igniteui-angular/theming' as *;
$light-palette: palette($primary: #1976D2, $secondary: #FF9800, $surface: #FAFAFA);
$dark-palette: palette($primary: #90CAF9, $secondary: #FFB74D, $surface: #121212);
@include core();
@include typography($font-family: $material-typeface, $type-scale: $material-type-scale);
// 默认使用浅色主题
@include theme($palette: $light-palette, $schema: $light-material-schema);
// 为<body>或<html>添加类以启用深色主题
.dark-theme {
@include theme($palette: $dark-palette, $schema: $dark-material-schema);
}Scoping a Theme to a Container
为容器设置专属主题
scss
.admin-panel {
@include theme($palette: $admin-palette, $schema: $light-indigo-schema);
}scss
.admin-panel {
@include theme($palette: $admin-palette, $schema: $light-indigo-schema);
}Licensed Package Users
授权包用户
If using the licensed package, set on MCP tool calls and change the Sass import:
@infragistics/igniteui-angularlicensed: truescss
@use '@infragistics/igniteui-angular/theming' as *;若使用授权版包,在调用MCP工具时设置,并修改Sass导入路径:
@infragistics/igniteui-angularlicensed: truescss
@use '@infragistics/igniteui-angular/theming' as *;Key Rules
关键规则
- Never overwrite existing files directly — always propose theme code as an update for user review; do not replace existing style files without confirmation
- Always call first when using MCP tools
detect_platform - Always call before
get_component_design_tokensto discover valid token namescreate_component_theme - Palette shades 50 = lightest, 900 = darkest for all chromatic colors — never invert for dark themes (only gray inverts)
- Surface color must match the variant — light color for , dark color for
lightdark - Use once before
@include core()in your global styles@include theme() - Component themes use inside a selector to emit CSS custom properties
@include tokens($theme) - For compound components, follow the full checklist returned by — theme each child component with its scoped selector
get_component_design_tokens - Never hardcode colors after palette generation — once a palette is created, every color in component themes, custom CSS, and Sass variables must use palette tokens (e.g.,
var(--ig-<family>-<shade>),var(--ig-primary-500)). Raw hex/RGB/HSL values are only acceptable in the initialvar(--ig-gray-200)seed call. This ensures themes remain consistent, switchable (light/dark), and maintainablepalette()
- 绝对不能直接覆盖现有文件——始终将主题代码作为更新建议提交给用户审核;未经确认,不得替换现有样式文件
- 使用MCP工具前必须先调用
detect_platform - **调用前必须先调用
create_component_theme**以获取有效的令牌名称get_component_design_tokens - 调色板色调50=最浅,900=最深(所有彩色系)——深色主题中绝对不能反转此规则(仅灰色系会反转)
- 背景色必须与主题变体匹配——浅色主题使用浅色,深色主题使用深色
- 全局样式中必须在
@include core()前调用一次@include theme() - **组件主题需在选择器内使用**以生成CSS自定义属性
@include tokens($theme) - 对于复合组件,需遵循返回的完整清单——为每个子组件设置带作用域选择器的主题
get_component_design_tokens - 生成调色板后绝对不能硬编码颜色——调色板创建完成后,组件主题、自定义CSS和Sass变量中的所有颜色必须使用调色板令牌(如
var(--ig-<family>-<shade>)、var(--ig-primary-500))。原始十六进制/RGB/HSL值仅允许在初始化var(--ig-gray-200)的种子调用中使用。此规则可确保主题保持一致性、可切换(深浅主题)且易于维护palette()