sgds-theming
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSGDS Theming Skill
SGDS主题定制指南
How to customise the product theme — brand colours, day/night mode, and font — using SGDS CSS token overrides.
如何通过覆盖SGDS CSS令牌来定制产品主题——包括品牌色彩、日夜模式及字体。
Prerequisites
前提条件
Import before your custom CSS. See sgds-getting-started for the full import order.
themes/day.css在自定义CSS之前导入。完整的导入顺序请参考**sgds-getting-started**。
themes/day.cssQuick Decision Guide
快速决策指南
| What you want to change | Token / mechanism |
|---|---|
| Product brand colour (custom) | Override |
| Product brand colour (GovTech) | Import one |
| Enable dark/night mode | Import |
| Font typeface | Override |
| 需更改的内容 | 令牌/实现方式 |
|---|---|
| 自定义产品品牌色彩 | 覆盖 |
| GovTech产品品牌色彩 | 导入 |
| 启用深色/夜间模式 | 导入 |
| 字体类型 | 覆盖 |
Changing the Product Brand Colour
更改产品品牌色彩
The default product colour is purple (). Override the full 100–900 scale with your brand colour to retheme all primary UI elements at once.
--sgds-product-primary-*Create a custom CSS file and override the primitive tokens in :
:rootcss
/* yourCustomCss.css */
:root {
--sgds-product-primary-100: #F5B6DA;
--sgds-product-primary-200: #F186C0;
--sgds-product-primary-300: #EE4FA6;
--sgds-product-primary-400: #EE0290;
--sgds-product-primary-500: #EF0078;
--sgds-product-primary-600: #DD0074;
--sgds-product-primary-700: #C6006E;
--sgds-product-primary-800: #B0006A;
--sgds-product-primary-900: #880061;
}Import your custom CSS after the SGDS theme file so the overrides take effect:
js
import "@govtechsg/sgds-web-component/themes/day.css";
import "./yourCustomCss.css";css
@import "@govtechsg/sgds-web-component/themes/day.css";
@import "./yourCustomCss.css";The semantic tokens () reference the primitive scale, so changing the primitive values automatically flows through to all components that use the primary colour.
--sgds-primary-*默认产品色彩为紫色()。通过覆盖100–900全范围的品牌色彩,可一次性重新设置所有主UI元素的主题。
--sgds-product-primary-*创建自定义CSS文件,在中覆盖基础令牌:
:rootcss
/* yourCustomCss.css */
:root {
--sgds-product-primary-100: #F5B6DA;
--sgds-product-primary-200: #F186C0;
--sgds-product-primary-300: #EE4FA6;
--sgds-product-primary-400: #EE0290;
--sgds-product-primary-500: #EF0078;
--sgds-product-primary-600: #DD0074;
--sgds-product-primary-700: #C6006E;
--sgds-product-primary-800: #B0006A;
--sgds-product-primary-900: #880061;
}在SGDS主题文件之后导入自定义CSS,确保覆盖生效:
js
import "@govtechsg/sgds-web-component/themes/day.css";
import "./yourCustomCss.css";css
@import "@govtechsg/sgds-web-component/themes/day.css";
@import "./yourCustomCss.css";语义令牌()引用基础令牌体系,因此修改基础值会自动应用到所有使用主色调的组件。
--sgds-primary-*GovTech Brand Colours
GovTech品牌色彩
GovTech products should use one of the pre-approved colour palettes in rather than defining custom hex values. Each product picks exactly one colour — mixing multiple GT palettes is not allowed.
themes/gt/GovTech产品应使用中预先批准的调色板之一,而非自定义十六进制值。每个产品只能选择一种颜色——不允许混合多种GT调色板。
themes/gt/Available colours
可用颜色
| File | Colour |
|---|---|
| Blue |
| Cyan |
| Magenta |
| Pink |
| Purple |
| Red |
| 文件 | 颜色 |
|---|---|
| 蓝色 |
| 青色 |
| 品红色 |
| 粉色 |
| 紫色 |
| 红色 |
How to apply
应用方法
Each GT file defines through in . Map those onto the SGDS product primary scale in your custom CSS file:
--gt-color-100--gt-color-900:rootcss
/* yourCustomCss.css */
:root {
--sgds-product-primary-100: var(--gt-color-100);
--sgds-product-primary-200: var(--gt-color-200);
--sgds-product-primary-300: var(--gt-color-300);
--sgds-product-primary-400: var(--gt-color-400);
--sgds-product-primary-500: var(--gt-color-500);
--sgds-product-primary-600: var(--gt-color-600);
--sgds-product-primary-700: var(--gt-color-700);
--sgds-product-primary-800: var(--gt-color-800);
--sgds-product-primary-900: var(--gt-color-900);
}Import order — the GT file must come before your custom CSS so the variables are defined when the mapping runs:
--gt-color-*js
import "@govtechsg/sgds-web-component/themes/day.css";
import "@govtechsg/sgds-web-component/themes/gt/blue.css"; // pick one colour only
import "./yourCustomCss.css";css
@import "@govtechsg/sgds-web-component/themes/day.css";
@import "@govtechsg/sgds-web-component/themes/gt/blue.css"; /* pick one colour only */
@import "./yourCustomCss.css";The same flow-through behaviour applies: changing automatically updates all components that use the primary colour.
--sgds-product-primary-*每个GT文件在中定义了至。在自定义CSS文件中将这些映射到SGDS产品主色调体系:
:root--gt-color-100--gt-color-900css
/* yourCustomCss.css */
:root {
--sgds-product-primary-100: var(--gt-color-100);
--sgds-product-primary-200: var(--gt-color-200);
--sgds-product-primary-300: var(--gt-color-300);
--sgds-product-primary-400: var(--gt-color-400);
--sgds-product-primary-500: var(--gt-color-500);
--sgds-product-primary-600: var(--gt-color-600);
--sgds-product-primary-700: var(--gt-color-700);
--sgds-product-primary-800: var(--gt-color-800);
--sgds-product-primary-900: var(--gt-color-900);
}导入顺序——GT文件必须在自定义CSS之前导入,这样在执行映射时变量已被定义:
--gt-color-*js
import "@govtechsg/sgds-web-component/themes/day.css";
import "@govtechsg/sgds-web-component/themes/gt/blue.css"; // 仅选择一种颜色
import "./yourCustomCss.css";css
@import "@govtechsg/sgds-web-component/themes/day.css";
@import "@govtechsg/sgds-web-component/themes/gt/blue.css"; /* 仅选择一种颜色 */
@import "./yourCustomCss.css";同样的联动规则适用:修改会自动更新所有使用主色调的组件。
--sgds-product-primary-*Day Mode (Default)
日间模式(默认)
Day mode is the default. Importing is all that is needed — no extra configuration required.
themes/day.csscss
@import "@govtechsg/sgds-web-component/themes/day.css";日间模式为默认模式。只需导入即可——无需额外配置。
themes/day.csscss
@import "@govtechsg/sgds-web-component/themes/day.css";Night Mode (Optional)
夜间模式(可选)
Night mode is opt-in. It is applied by adding the class to the element, which activates the selector defined in .
sgds-night-theme<html>:root.sgds-night-themethemes/night.css夜间模式为可选功能。通过为元素添加类来启用,该类会激活中定义的选择器。
<html>sgds-night-themethemes/night.css:root.sgds-night-themeSetup
设置步骤
Import both theme files:
js
import "@govtechsg/sgds-web-component/themes/day.css";
import "@govtechsg/sgds-web-component/themes/night.css";css
@import "@govtechsg/sgds-web-component/themes/day.css";
@import "@govtechsg/sgds-web-component/themes/night.css";同时导入两个主题文件:
js
import "@govtechsg/sgds-web-component/themes/day.css";
import "@govtechsg/sgds-web-component/themes/night.css";css
@import "@govtechsg/sgds-web-component/themes/day.css";
@import "@govtechsg/sgds-web-component/themes/night.css";Activating night mode
启用夜间模式
Add the class to the element to switch all tokens to their dark equivalents:
<html>html
<html class="sgds-night-theme">Toggle it at runtime via JavaScript:
js
document.documentElement.classList.toggle("sgds-night-theme");为元素添加类,即可将所有令牌切换为深色等效值:
<html>html
<html class="sgds-night-theme">通过JavaScript在运行时切换:
js
document.documentElement.classList.toggle("sgds-night-theme");How it works
工作原理
themes/night.cssthemes/day.css:root.sgds-night-themethemes/night.cssthemes/day.css:root.sgds-night-themeChanging the Font
更改字体
SGDS uses Inter by default via . Override this token to use a different typeface:
--sgds-font-family-brandcss
:root {
--sgds-font-family-brand: "Your Font", system-ui, sans-serif;
}You are responsible for loading the font assets — either via a tag or . SGDS does not load custom fonts automatically. See sgds-getting-started for the optimised Inter Google Fonts URL if you are keeping the default font.
<link>@font-faceSGDS默认使用Inter字体,通过令牌定义。覆盖此令牌即可使用其他字体:
--sgds-font-family-brandcss
:root {
--sgds-font-family-brand: "Your Font", system-ui, sans-serif;
}您需要自行负责加载字体资源——可通过标签或实现。SGDS不会自动加载自定义字体。如果保留默认字体,可参考**sgds-getting-started**获取优化后的Inter Google Fonts链接。
<link>@font-faceFor AI Agents
面向AI Agent的提示
- Always tell users to import their custom CSS after — otherwise the override will be overwritten.
themes/day.css - Brand colour overrides target primitive tokens (), not semantic tokens. Changing the primitives is the correct approach; do not override individual semantic tokens directly.
--sgds-product-primary-{100–900} - Night mode requires both the import and the
themes/night.cssclass onsgds-night-theme. Either alone is not enough.<html> - Night mode is optional — only add when the user explicitly needs dark mode support.
themes/night.css - Day mode is always active by default; there is no class to add.
sgds-day-theme - When overriding , remind the user to also load the font file themselves.
--sgds-font-family-brand - Custom overrides apply to both day and night mode simultaneously because they target , which both theme selectors inherit from.
:root - GovTech products must use a colour from — not custom hex values. If a user is building a GovTech product and asks about brand colours, guide them to pick one GT colour and apply the
themes/gt/→--gt-color-*mapping pattern. Never let them import more than one GT colour file.--sgds-product-primary-* - The GT colour file must be imported after and before the custom mapping CSS so that
themes/day.cssvariables are defined in time.--gt-color-*
- 务必告知用户在之后导入自定义CSS——否则覆盖设置会被覆盖。
themes/day.css - 品牌色彩覆盖需针对基础令牌(),而非语义令牌。修改基础令牌是正确的做法;请勿直接覆盖单个语义令牌。
--sgds-product-primary-{100–900} - 启用夜间模式需要同时导入并为
themes/night.css添加<html>类。仅其中一项不足以生效。sgds-night-theme - 夜间模式为可选——仅当用户明确需要深色模式支持时才添加。
themes/night.css - 日间模式始终默认激活;无需添加类。
sgds-day-theme - 覆盖时,提醒用户需自行加载字体文件。
--sgds-font-family-brand - 自定义覆盖会同时应用于日间和夜间模式,因为它们针对的是,而两个主题选择器均继承自
:root。:root - GovTech产品必须使用中的颜色——而非自定义十六进制值。如果用户正在构建GovTech产品并询问品牌色彩,引导他们选择一种GT颜色并应用
themes/gt/→--gt-color-*的映射模式。绝不允许导入多个GT颜色文件。--sgds-product-primary-* - GT颜色文件必须在之后、自定义映射CSS之前导入,确保
themes/day.css变量及时定义。--gt-color-*