Theme
Applies appearance settings at runtime.
When to use
- Let users change density or apply a brand color across Kor controls.
Examples
Toggle density
Loading the example
<k:Button text="Switch cozy or compact" press=".onDensity"/>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Theme", "kor/ui/Toast"], (Controller, Theme, Toast) => Controller.extend("sample.ThemeDensity", {
onDensity() {
const density = Theme.get().density === "cozy" ? "compact" : "cozy";
Theme.set({ density });
Toast.show(density === "compact" ? "Compact density" : "Cozy density");
}
}));Preview and restore a brand color
Appearance settings apply to the whole page.
Loading the example
<k:Stack row="true" gap="8">
<k:Button kind="accent" text="Preview green" press=".onPreview"/>
<k:Button text="Restore color" press=".onRestore"/>
</k:Stack>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Theme"], (Controller, Theme) => Controller.extend("sample.ThemeAccent", {
onPreview() {
this.previousAccent ??= Theme.get().accent;
Theme.set({ accent: "#0B7A5B" });
},
onRestore() {
if (this.previousAccent) Theme.set({ accent: this.previousAccent });
this.previousAccent = undefined;
},
onExit() {
this.onRestore();
}
}));API
Methods
| Name | Description |
|---|---|
get(): ThemeSettings | Returns a copy of the current theme settings |
isDark(): boolean | Returns whether dark mode is active, including the system preference |
set(next: Partial<ThemeSettings>): void | Updates the supplied theme settings and applies them to the page |
type ThemeSettings = { mode: "light" | "dark" | "system"; accent: string; density: "cozy" | "compact"; radius: number };