The ZK Theme Template serves as a base theme, allowing developers to make changes and create custom ZK themes. It comes with continuous/incremental compile and live-reload features to minimize the turn-around time when developing a theme. We assume you already know Less.
If you just want to customize some components' looking (not all components), please read ZK Style Customization Guide.
Require Node.js >= 10.16
Check version with node -v
fork this repository to another git repository, so this will make it easier to merge bug fixes from the original repository and migrate to the new version in the future.
- initialize the project with a theme name.
./init.sh
- install zkless-engine. The LESS processor customized for ZK.
npm install
mvn clean package
It will compile .less
files and package the source into jar. The jar file will be at target/___THEME_NAME___.jar
This project contains the default theme (iceblue
) .less files.
The suggested steps:
- Switch to a theme as a base theme
- Add a new
.less
file to override the existing variables.
- Open
src/archive/web/zul/less/_zkvariables.less
- Modify
@themeProfile
tocompact
.
@themeProfile: "compact";
@themePalette: "iceblue";
- now the theme uses the compact profile.
Switch to a theme of Theme Pack
The theme pack contains extra 23 themes, you can choose one theme that is closer to your target theme as a base theme and start to customize it. So that it can save some efforts for you. (Notice: you need to purchase ZK EE or theme pack to access the theme pack source code.)
- Download Theme Pack source jar at the premium repository: [THEME_NAME]-[VERSION]-sources.jar
- Get theme color palette less at
source.jar/palettes/*.less
- Copy the theme less to
zkThemeTemplate/src/archive/web/zul/less/colors
.
For example,montana.less
- prepend
_
at the file name
For example,_montana.less
- Specify the theme name at
src/archive/web/zul/less/_zkvariables.less
@themePalette: "montana";
We suggest you customize a theme by overriding existing variables instead of modifying the variable value directly. So that you can easily merge the future changes from the original repository and easily differentiate the customized style and default styles. The steps are:
- create a new
.less
file and add those variables you want to override. - import the new
.less
file in_header.less
at the bottom to override the previous one like:
@import "_zkvariables.less"; // variables needed for ZK
@import "_zkmixins.less";
@import "_mytheme.less" // your new theme variables
- compile run preview app
mvn test exec:java@preview-app
- open a simple preview page in a browser: http://localhost:8080
- add your own pages containing the components to preview under
/preview/web
in a separate console:
npm run zklessc-dev
-
Put
___THEME_NAME___.jar
inWEB-INF/lib
, then___THEME_NAME___.jar
will become your default theme if there is no other theme. -
Now you can also dynamically switch between different themes by cookie or library property
-
Use library-property
<!-- in WEB-INF/zk.xml --> <library-property> <name>org.zkoss.theme.preferred</name> <value>___THEME_NAME___</value> </library-property>
-
Use cookie to switch theme, add a cookie
zktheme=___THEME_NAME___
It does not require a server restart, but user has to refresh the browser.
Please refer to ZK Developer's Reference/Theming and Styling/Switching Themes.
src/archive/web/zul/less/_zkvariables.less
> @colorPrimary
src/archive/web/zul/less/_zkvariables.less
> @baseFontSize
, @baseTitleFontFamily
, @baseContentFontFamily
Different components have different margin and padding, search "margin" and "padding" among all .less
files.
check out the branch breeze
of this repository
visit https://github.com/zkoss/atlantic and follow the readme.
visit https://github.com/zkoss/zkthemes and follow the readme.