Skip to content

Commit cdab106

Browse files
authored
docs: document custom theme integration (#1556)
1 parent 3b7b439 commit cdab106

File tree

2 files changed

+90
-24
lines changed

2 files changed

+90
-24
lines changed

docs/CustomTheming.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Custom Theming with `SAP Theme Designer`
2+
3+
UI5 Web Components are fully compatible with `SAP Theme Designer`. You can create your own theme and effortlessly
4+
integrate it in your UI5 Web Components project on HTML level! On top, this does not prevent you from switching to
5+
and from officially supported themes, while having your own.
6+
7+
Follow this simple tutorial to get a custom theme running with UI5 Web Components in 5 minutes:
8+
9+
1. Open **SAP Theme Designer**.
10+
11+
Go to [ui5.sap.com](https://ui5.sap.com) and select `Tools` -> `UI Theme Designer` from the menu, or just follow the
12+
[direct link](https://themedesigner-themedesigner.dispatcher.hanatrial.ondemand.com/index.html).
13+
14+
2. Create your **custom theme** in `SAP Theme Designer`.
15+
16+
- Click the **Create a New Theme** button.
17+
18+
- Choose which SAP stock theme will serve as the base of your custom theme and click the **Create Theme** button in the footer of the dialog.
19+
20+
- Proceed to change as many parameters as you wish.
21+
22+
- Once you are done customizing, choose **Theme** -> **Export** from the main menu on top. A dialog will appear,
23+
asking for **Theme ID** (technical name of your new theme) and a title.
24+
25+
The Theme ID you chose at this point will be the one you'll use in order to switch to your custom theme, for example if you chose `mytheme`:
26+
27+
`index.html?sap-ui-theme=mytheme`
28+
29+
**Important:** Before clicking the **Export** button, thus dismissing the dialog and finishing theme creation,
30+
it is *mandatory* that you expand the **Optional Settings (for Experts)** panel, and select the **Source Files + CSS Resources** option.
31+
Otherwise, no CSS Variables will be generated.
32+
33+
3. Download the custom theme `.zip` file:
34+
35+
Your browser will then download a `.zip` file with the name of your new theme, e.g. `mytheme.zip`.
36+
37+
4. Copy the `css_variables.css` file with all CSS Variables for your custom theme to your project.
38+
39+
You can find this file inside the `.zip` in the `\Base\baseLib\<your theme name>\` directory.
40+
41+
For example: `mytheme.zip\Base\baseLib\mytheme\css_variables.css`.
42+
43+
Just copy this file to a directory in your project where it can be statically served.
44+
45+
5. Include the file in your project's `.html` page:
46+
47+
The simplest option would be to use a `<link>` tag and point to where you copied the file:
48+
49+
```html
50+
<link rel="stylesheet" type="text/css" href="<path-to-your-css-file>/css_variables.css">
51+
```
52+
53+
but you could as well use a `<style>` tag and paste the content of `css_variables.css` inside,
54+
if that's what you prefer:
55+
56+
```html
57+
<style>
58+
/* Here goes the content of css_variables.css */
59+
</style>
60+
```
61+
62+
And that's it! Now you can use your custom theme by setting it either in the URL of your page,
63+
or in your configuration script:
64+
65+
`index.html?sap-ui-theme=mytheme`
66+
67+
or
68+
69+
```html
70+
<script data-ui5-config type="application/json">
71+
{
72+
"theme": "mytheme"
73+
}
74+
</script>
75+
```
76+
77+
*Note:* Using a custom theme does not prevent you from using the official themes. You can freely switch to and from them.
78+
79+
```js
80+
import { setTheme } from "@ui5/webcomponents-base/dist/config/Theme.js";
81+
setTheme("sap_fiori_3");
82+
...
83+
setTheme("mytheme");
84+
...
85+
setTheme("sap_fiori_3_dark");
86+
```
87+
88+
For more on configuring themes, see [Configuration](Configuration.md).
89+

docs/Public Module Imports.md

+1-24
Original file line numberDiff line numberDiff line change
@@ -346,30 +346,7 @@ import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSet
346346

347347
For more details, please check [Configuration](https://sap.github.io/ui5-webcomponents/playground/docs/configuration/).
348348

349-
### 6. Assets registration
350-
351-
In order to register a **custom theme**:
352-
353-
```js
354-
import { registerThemeProperties } from "@ui5/webcomponents-base/dist/AssetRegistry.js"
355-
```
356-
357-
And then call the method above to register CSS Variables for each theme/package pair.
358-
359-
You can pass the parameters directly, as an object, or as a URL:
360-
1) Pass the CSS Vars as a string directly.
361-
362-
`registerThemeProperties("my-package", "my_theme", ":root{--var1: red;}");`
363-
364-
2) Pass the CSS Vars as an object directly. The object must have a "_" property, pointing to a string with the CSS Vars.
365-
366-
`registerThemeProperties("my-package", "my_theme", {"_": ":root{--var1: red;}"});`
367-
368-
3) Pass a URL to a JSON file, containing the CSS Vars in its "_" property. Will be fetched on demand, not upon registration.
369-
370-
`registerThemeProperties("my-package", "my_theme", "http://url/to/my/theme.json");`
371-
372-
### 7. OpenUI5 integration
349+
### 6. OpenUI5 integration
373350

374351
```js
375352
import "@ui5/webcomponents-base/dist/features/OpenUI5Support.js";

0 commit comments

Comments
 (0)