|
| 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 | + |
0 commit comments