ThemeConfigurator lets the user change the theme at runtime: preset, color scheme, input style, density, direction, primary color and the main tokens. The settings are kept in the browser and applied before the first paint of every page, so nothing flickers on load.
In the page, e.g. a settings page. The overlay of this showcase (palette button at the right edge) is the same
component with mode="overlay", both stay in sync.
A button with data-tc-toggle and the client id of an overlay configurator opens it.
1. Enable it in the web.xml: the head renders a small script that applies the stored settings
before the first paint, preset and direction are read from cookies on the server.
<context-param>
<param-name>primefaces.THEME_CONFIGURATOR</param-name>
<param-value>true</param-value>
</context-param>
2. Add the composite component, e.g. in the template (overlay) or on a settings page (inline). It needs no form.
<html xmlns:pc="jakarta.faces.composite/primefaces" dir="#{p:dir()}">
...
<pc:themeConfigurator/>
<pc:themeConfigurator mode="inline" presets="aura,lara" direction="false" export="false"/>
#{p:theme()} and #{p:dir()} return the preset and the direction of the request
(chosen by the user or primefaces.THEME / primefaces.DIR).
| Name | Default | Description |
|---|---|---|
| mode | overlay | overlay: a button at the edge of the window opens the panel; inline: the panel in the page. |
| presets | aura,lara,nora,material,metal,glass | The presets to choose from, comma separated (custom themes too); empty: no preset choice. |
| direction | true | Whether the user can choose the direction. |
| export | true | Whether the CSS of the changes is shown to copy. |
| style | null | Inline style of the container. |
| styleClass | null | Style class of the container. |
<div class="card">
<h5>Inline</h5>
<p>In the page, e.g. a settings page. The overlay of this showcase (palette button at the right edge) is the same
component with <code>mode="overlay"</code>, both stay in sync.</p>
<pc:themeConfigurator id="inlineConfigurator" mode="inline" export="false"/>
</div>
<div class="card">
<h5>Opened by another button</h5>
<p>A button with <code>data-tc-toggle</code> and the client id of an overlay configurator opens it.</p>
<button type="button" class="p-button p-component p-button-text-icon-left" data-tc-toggle="themeConfigurator"
aria-controls="themeConfigurator_panel">
<span class="p-button-icon-left p-c pi pi-palette"></span><span class="p-button-text p-c">Open theme configurator</span>
</button>
</div>