Our
WebUI Example Project
contains a custom theme switcher addon. In this post I will explain how
to use and augment this, in order to create your own theme.
Custom addonsCustom addons and themes go into the "resources" folder of your Webui, as you can see here:
https://github.com/aimms/WebUI-Examples/tree/master/MealsRUsWebAppPRO/src/main/aimms/WebUI/resources
with themes going into the css folder, and custom widgets and addons
going into the javascript folder. Some HTML, CSS and JavaScript
knowledge is required to code your own addons and widgets. If you want
to use them in your own project, you should copy them over to your
project resources folder.
Custom ThemesThe theme switcher works by setting a class on the topmost element of the document, the
html element. This class is determined by prefixing the theme name with "theme-". This in effect allows you to
namespace your theme, like we did in the example project with our "dark" theme:
https://github.com/aimms/WebUI-Examples/blob/master/MealsRUsWebAppPRO/src/main/aimms/WebUI/resources/css/themes/dark/dark.css To
add your own theme, copy the "dark" folder in the themes, rename it (to
"yourcompany" for example) and rename the css file in it accordingly
(to yourcompany.css). In this CSS you have full control of the webui,
but we urge you to stay away from layout changes, as they will interfere
with the rest of the WebUI and may lead to problems. Good theming
options are (background)colors, fonts, shadows and borders. Make sure
that in your theme, you prefix all css selectors with
.theme-YourThemeName (for example, .theme-yourcompany)
It's
easiest to first add an empty theme css to the theme-switch-addon, and
then
customise it, as you can see the changes in the WebUI as you go. There
is no full documentation on the HTML and CSS structure yet, so we
suggest taking dark.css as a starting point and using the web inspector
to find out how to target specific elements.
After you have
created your own theme css, you will need to augment the
theme-switch-addon to make it aware of your new theme. To do so, you
need to add a new line in this file:
https://github.com/aimms/WebUI-Examples/blob/master/MealsRUsWebAppPRO/src/main/aimms/WebUI/resources/javascript/theme-switch-addon/src/jquery.aimms.theme-switch-addon.js#L17 On line 17 you will find this code:
<option value="dark">Dark theme</option>\
You
can copy this line (or overwrite it if you do not want users to choose
the dark theme, or you did not copy it over) and change the value="dark"
to the name of your css file, and the text inside the <option> to
a friendly version. So, in the yourcompany.css example, the value would
be "yourcompany", and the friendly name would be "Your Company theme".
Leading to this line:
<option value="yourcompany">Your Company Theme</option>\
After reloading (or re-uploading) the application you should now be able to select your own theme in the theme switcher.
FutureIn
the future we want to improve on theming by introducing support for
SCSS and providing an easier way to customise the entire theme.
As
always, if you have any questions let us know, and I personally look
forward to seeing all the different themes you will develop!
Regards,
Kilian