igniteui-angular-theming

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Ignite 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
    igniteui-angular
    installed, or
    @infragistics/igniteui-angular
    for licensed users
  • Sass support enabled in the project (default for Angular CLI projects)
  • The Ignite UI Theming MCP server (
    igniteui-theming
    ) available as a tool provider
AGENT INSTRUCTION — MCP Server Setup (REQUIRED)
Before using any theming tools, you MUST verify the MCP server is available by calling
detect_platform
. If the tool is not available or the call fails, you MUST automatically configure it by following the setup process steps described below.
After 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.
  • 已安装
    igniteui-angular
    的Angular项目,或授权用户使用的
    @infragistics/igniteui-angular
  • 项目已启用Sass支持(Angular CLI项目默认支持)
  • 可获取Ignite UI Theming MCP服务器
    igniteui-theming
    )作为工具提供商
代理指令 — MCP服务器配置(必填)
在使用任何主题工具前,必须通过调用
detect_platform
验证MCP服务器是否可用。若工具不可用或调用失败,必须按照以下设置步骤自动完成配置。
配置文件编写完成后,告知用户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
.vscode/mcp.json
in your project:
json
{
  "servers": {
    "igniteui-theming": {
      "command": "npx",
      "args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
    }
  }
}
This works whether
igniteui-theming
is installed locally in
node_modules
or needs to be pulled from the npm registry —
npx -y
handles both cases.
在项目中创建或编辑
.vscode/mcp.json
json
{
  "servers": {
    "igniteui-theming": {
      "command": "npx",
      "args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
    }
  }
}
无论
igniteui-theming
是已本地安装在
node_modules
中还是需要从npm仓库拉取,此配置均可生效——
npx -y
会自动处理这两种情况。

Cursor

Cursor

Create or edit
.cursor/mcp.json
:
json
{
  "mcpServers": {
    "igniteui-theming": {
      "command": "npx",
      "args": ["-y", "igniteui-theming", "igniteui-theming-mcp"]
    }
  }
}
创建或编辑
.cursor/mcp.json
json
{
  "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

  1. Go to Settings → Tools → AI Assistant → MCP Servers
  2. Click + Add MCP Server
  3. Set Command to
    npx
    and Arguments to
    igniteui-theming igniteui-theming-mcp
  4. Click OK and restart the AI Assistant
  1. 进入设置 → 工具 → AI助手 → MCP服务器
  2. 点击**+ 添加MCP服务器**
  3. 设置命令为
    npx
    ,参数为
    igniteui-theming igniteui-theming-mcp
  4. 点击确定并重启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
detect_platform
tool will analyze your
package.json
and return the detected platform (e.g.,
angular
).
配置完成后,可向AI助手询问:
"检测我的项目使用的是哪个Ignite UI平台"
若MCP服务器已运行,
detect_platform
工具会分析你的
package.json
并返回检测到的平台(如
angular
)。

Theming Architecture

主题架构

The Ignite UI theming system is built on four pillars:
ConceptPurpose
PaletteColor system with primary, secondary, surface, gray, info, success, warn, error families, each with shades 50–900 + accents A100–A700
TypographyFont family, type scale (h1–h6, subtitle, body, button, caption, overline)
ElevationsBox-shadow levels 0–24 for visual depth
SchemaPer-component recipes mapping palette colors to component tokens
Ignite UI主题系统基于四大核心:
概念用途
调色板包含主色、辅助色、背景色、灰色、信息、成功、警告、错误色系的配色系统,每个色系包含50-900的色调以及A100-A700的强调色
排版字体族、字体层级(h1-h6、副标题、正文、按钮、说明文字、overline)
阴影层级0-24级的盒阴影,用于营造视觉深度
样式方案各组件的样式规则,将调色板颜色映射到组件令牌

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-schema
)。

Pre-built Themes

预构建主题

The quickest way to theme an app is to include a pre-built CSS file in
angular.json
:
json
"styles": ["node_modules/igniteui-angular/styles/igniteui-angular.css"]
Licensed package users: replace
igniteui-angular
with
@infragistics/igniteui-angular
in the path:
json
"styles": ["node_modules/@infragistics/igniteui-angular/styles/igniteui-angular.css"]
Available pre-built CSS files:
FileTheme
igniteui-angular.css
Material Light
igniteui-angular-dark.css
Material Dark
igniteui-fluent-light.css
Fluent Light
igniteui-fluent-dark.css
Fluent Dark
igniteui-bootstrap-light.css
Bootstrap Light
igniteui-bootstrap-dark.css
Bootstrap Dark
igniteui-indigo-light.css
Indigo Light
igniteui-indigo-dark.css
Indigo Dark
All files are located under
node_modules/igniteui-angular/styles/
(or
node_modules/@infragistics/igniteui-angular/styles/
for the licensed package).
为应用设置主题最快的方式是在
angular.json
中引入预构建的CSS文件:
json
"styles": ["node_modules/igniteui-angular/styles/igniteui-angular.css"]
授权包用户:将路径中的
igniteui-angular
替换为
@infragistics/igniteui-angular
json
"styles": ["node_modules/@infragistics/igniteui-angular/styles/igniteui-angular.css"]
可用的预构建CSS文件:
文件主题
igniteui-angular.css
Material浅色主题
igniteui-angular-dark.css
Material深色主题
igniteui-fluent-light.css
Fluent浅色主题
igniteui-fluent-dark.css
Fluent深色主题
igniteui-bootstrap-light.css
Bootstrap浅色主题
igniteui-bootstrap-dark.css
Bootstrap深色主题
igniteui-indigo-light.css
Indigo浅色主题
igniteui-indigo-dark.css
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
styles.scss
file and include it in
angular.json
:
scss
// 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.scss
文件并将其引入
angular.json
scss
// 开源包
@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

组件级主题

Override individual component appearance using component theme functions and the
tokens
mixin.
AGENT INSTRUCTION — No Hardcoded Colors (CRITICAL)
Once a palette has been generated (via
palette()
in Sass or
create_palette
/
create_theme
via MCP), every color reference MUST come from the generated palette tokens — never hardcode hex/RGB/HSL values.
Use
var(--ig-primary-500)
,
var(--ig-secondary-300)
,
var(--ig-surface-500)
, etc. in CSS, or the
get_color
MCP tool to obtain the correct token reference.
WRONG (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, Angular
host
bindings, and inline styles. The only place raw hex values belong is the initial
palette()
call
that seeds the color system. Everything downstream must reference the 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的
palette()
函数或MCP的
create_palette
/
create_theme
工具生成了调色板,所有颜色引用必须来自生成的调色板令牌——绝对不能硬编码十六进制/RGB/HSL值。
在CSS中使用
var(--ig-primary-500)
var(--ig-secondary-300)
var(--ig-surface-500)
等,或使用MCP的
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
get_component_design_tokens
to discover them.
每个组件都有自己的设计令牌(可主题化的CSS自定义属性)。在为组件设置主题前,必须先了解可用的令牌。使用MCP工具
get_component_design_tokens
来查看。

Compound Components

复合组件

Some components (e.g.,
combo
,
grid
,
date-picker
,
select
) are compound — they contain internal child components, each requiring their own theme. For example,
date-picker
uses
calendar
,
flat-button
, and
input-group
internally.
Workflow for compound components:
  1. Call
    get_component_design_tokens
    for the parent (e.g.,
    date-picker
    )
  2. The response lists related themes and scope selectors
  3. Call
    create_component_theme
    for each child, using the parent's selector as the wrapper
部分组件(如
combo
grid
date-picker
select
)属于复合组件——它们包含内部子组件,每个子组件都需要单独设置主题。例如,
date-picker
内部使用了
calendar
flat-button
input-group
复合组件的主题设置流程:
  1. 为父组件(如
    date-picker
    )调用
    get_component_design_tokens
  2. 响应结果会列出相关主题和作用域选择器
  3. 为每个子组件调用
    create_component_theme
    ,使用父组件的选择器作为包裹器

Layout Controls

布局控件

Sizing

尺寸

Controls the size of components via
--ig-size
(values: 1 = small, 2 = medium, 3 = large):
css
/* Global */
:root { --ig-size: 2; }

/* Component-scoped */
igx-grid { --ig-size: 1; }
通过
--ig-size
控制组件尺寸(取值:1=小,2=中,3=大):
css
/* 全局设置 */
:root { --ig-size: 2; }

/* 组件级设置 */
igx-grid { --ig-size: 1; }

Spacing

间距

Docs: Spacing
Controls internal padding via
--ig-spacing
(1 = default, 0.5 = compact, 2 = spacious):
css
:root { --ig-spacing: 1; }
.compact-section { --ig-spacing: 0.75; }
文档间距
通过
--ig-spacing
控制内部边距(1=默认,0.5=紧凑,2=宽松):
css
:root { --ig-spacing: 1; }
.compact-section { --ig-spacing: 0.75; }

Roundness

圆角

Controls border-radius via
--ig-radius-factor
(0 = square, 1 = maximum radius):
css
:root { --ig-radius-factor: 1; }
igx-avatar { --ig-radius-factor: 0.5; }
通过
--ig-radius-factor
控制边框圆角(0=方形,1=最大圆角):
css
: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
styles.scss
(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.
Always follow this workflow:
Ignite UI Theming MCP服务器提供AI辅助的主题代码生成工具。
重要 — 文件安全规则:生成或更新主题代码时,绝对不能直接覆盖现有样式文件。应始终将变更作为更新建议,让用户审核并批准后再写入磁盘。若
styles.scss
(或任何目标文件)已存在,应将生成的代码作为差异或建议展示,而非替换文件内容。这可避免意外丢失用户已编写的自定义样式。
请始终遵循以下流程:

Step 1 — Detect Platform

步骤1 — 检测平台

Tool: detect_platform
This auto-detects
angular
from
package.json
and sets the correct import paths.
工具: detect_platform
该工具会自动从
package.json
中检测
angular
平台,并设置正确的导入路径。

Step 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
theme()
mixin call.
工具: create_theme
参数: {
  platform: "angular",
  designSystem: "material",
  primaryColor: "#1976D2",
  secondaryColor: "#FF9800",
  surfaceColor: "#FAFAFA",
  variant: "light",
  fontFamily: "'Roboto', sans-serif",
  includeTypography: true,
  includeElevations: true
}
生成包含调色板、排版、阴影层级和
theme()
混合宏调用的完整Sass文件。

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 to
create_component_theme
must reference palette CSS custom properties (e.g.,
var(--ig-primary-500)
,
var(--ig-secondary-A200)
,
var(--ig-gray-100)
). Never pass raw hex values like
"#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)"
  }
}
提醒:生成调色板后,传递给
create_component_theme
的所有令牌值必须引用调色板的CSS自定义属性(如
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
create_custom_palette
with
mode: "explicit"
for full control over each shade.
对于中等亮度的基础颜色:
工具: create_palette
参数: {
  platform: "angular",
  primary: "#1976D2",
  secondary: "#FF9800",
  surface: "#FAFAFA",
  variant: "light"
}
对于品牌特定的精确色调,可使用
create_custom_palette
并设置
mode: "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
get_color
tool to obtain the correct CSS custom property reference. Never hardcode hex/RGB/HSL values in component themes, custom CSS, or Sass variables.
Tool: 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
    tokens
    values
  • Custom CSS rules (
    color
    ,
    background
    ,
    border-color
    ,
    fill
    ,
    stroke
    , etc.)
  • Sass variables for derived values (
    $sidebar-bg: var(--ig-surface-500);
    )
  • Angular
    host
    style bindings
The only place raw hex values are acceptable is in the initial
palette()
call or the
create_palette
/
create_theme
MCP tool inputs that seed the color system.
生成调色板后,必须使用
get_color
工具获取正确的CSS自定义属性引用。绝对不能在组件主题、自定义CSS或Sass变量中硬编码十六进制/RGB/HSL值。
工具: 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
    样式绑定
唯一允许使用原始十六进制值的地方是初始化
palette()
调用,或
create_palette
/
create_theme
MCP工具的输入参数,即为配色系统提供初始值的地方。

Loading Reference Data

加载参考数据

Use
read_resource
with these URIs for preset values and documentation:
URIContent
theming://presets/palettes
Preset palette colors
theming://presets/typography
Typography presets
theming://presets/elevations
Elevation shadow presets
theming://guidance/colors/usage
Which shades for which purpose
theming://guidance/colors/roles
Semantic color roles
theming://guidance/colors/rules
Light/dark theme rules
theming://platforms/angular
Angular platform specifics
使用
read_resource
工具并传入以下URI获取预设值和文档:
URI内容
theming://presets/palettes
预设调色板颜色
theming://presets/typography
排版预设
theming://presets/elevations
阴影层级预设
theming://guidance/colors/usage
各色调的使用场景
theming://guidance/colors/roles
语义化颜色角色
theming://guidance/colors/rules
浅色/深色主题规则
theming://platforms/angular
Angular平台专属内容

Referencing Colors in Custom Styles

自定义样式中的颜色引用

After a theme is applied, the palette is available as CSS custom properties on
:root
. Use these tokens in all custom CSS — never introduce standalone hex/RGB variables for colors that the palette already provides.
应用主题后,调色板会以CSS自定义属性的形式存在于
:root
上。在所有自定义CSS中都应使用这些令牌——绝对不能为调色板已包含的颜色单独定义十六进制/RGB变量。

Correct: 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:
  1. palette()
    call
    — the initial seed colors that generate the full palette
  2. create_palette
    /
    create_theme
    MCP tool inputs
    — the base colors passed to the tool
  3. Non-palette decorative values — e.g., a one-off SVG illustration color that intentionally stays fixed regardless of theme
Everything else must use
var(--ig-<family>-<shade>)
tokens.
仅在以下场景中允许使用原始十六进制值:
  1. palette()
    调用
    ——生成完整调色板的初始种子颜色
  2. create_palette
    /
    create_theme
    MCP工具输入
    ——传递给工具的基础颜色
  3. 非调色板装饰性值——例如,独立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
@infragistics/igniteui-angular
package, set
licensed: true
on MCP tool calls and change the Sass import:
scss
@use '@infragistics/igniteui-angular/theming' as *;
若使用授权版
@infragistics/igniteui-angular
包,在调用MCP工具时设置
licensed: true
,并修改Sass导入路径:
scss
@use '@infragistics/igniteui-angular/theming' as *;

Key Rules

关键规则

  1. Never overwrite existing files directly — always propose theme code as an update for user review; do not replace existing style files without confirmation
  2. Always call
    detect_platform
    first
    when using MCP tools
  3. Always call
    get_component_design_tokens
    before
    create_component_theme
    to discover valid token names
  4. Palette shades 50 = lightest, 900 = darkest for all chromatic colors — never invert for dark themes (only gray inverts)
  5. Surface color must match the variant — light color for
    light
    , dark color for
    dark
  6. Use
    @include core()
    once
    before
    @include theme()
    in your global styles
  7. Component themes use
    @include tokens($theme)
    inside a selector to emit CSS custom properties
  8. For compound components, follow the full checklist returned by
    get_component_design_tokens
    — theme each child component with its scoped selector
  9. Never hardcode colors after palette generation — once a palette is created, every color in component themes, custom CSS, and Sass variables must use
    var(--ig-<family>-<shade>)
    palette tokens (e.g.,
    var(--ig-primary-500)
    ,
    var(--ig-gray-200)
    ). Raw hex/RGB/HSL values are only acceptable in the initial
    palette()
    seed call. This ensures themes remain consistent, switchable (light/dark), and maintainable
  1. 绝对不能直接覆盖现有文件——始终将主题代码作为更新建议提交给用户审核;未经确认,不得替换现有样式文件
  2. 使用MCP工具前必须先调用
    detect_platform
  3. **调用
    create_component_theme
    前必须先调用
    get_component_design_tokens
    **以获取有效的令牌名称
  4. 调色板色调50=最浅,900=最深(所有彩色系)——深色主题中绝对不能反转此规则(仅灰色系会反转)
  5. 背景色必须与主题变体匹配——浅色主题使用浅色,深色主题使用深色
  6. 全局样式中
    @include core()
    必须在
    @include theme()
    前调用一次
  7. **组件主题需在选择器内使用
    @include tokens($theme)
    **以生成CSS自定义属性
  8. 对于复合组件,需遵循
    get_component_design_tokens
    返回的完整清单——为每个子组件设置带作用域选择器的主题
  9. 生成调色板后绝对不能硬编码颜色——调色板创建完成后,组件主题、自定义CSS和Sass变量中的所有颜色必须使用
    var(--ig-<family>-<shade>)
    调色板令牌(如
    var(--ig-primary-500)
    var(--ig-gray-200)
    )。原始十六进制/RGB/HSL值仅允许在初始化
    palette()
    的种子调用中使用。此规则可确保主题保持一致性、可切换(深浅主题)且易于维护