Theme toggle
The top bar button that switches between light and dark mode; it is the button form of the theme switcher.
zb:theme-switcher · button zubazar/ui · free (MIT)
Basic usage
BLADE
A moon shows in light mode and a sun in dark mode; clicking switches to the opposite of the mode on screen.
<zb:theme-switcher />
In the layout
BLADE
The ready-made layouts show the button in the top bar themselves; to move it, pass :theme-toggle="false" to the layout and put the button in the slot you want.
<zb:layout.sidebar :theme-toggle="false">
<zb:slot:drawerFooter>
<zb:theme-switcher class="ms-auto" />
</zb:slot:drawerFooter>
{{ $slot }}
</zb:layout.sidebar>
| Prop | Values |
|---|---|
theme-toggle | true | false (layout prop) |
Light, dark and system
BLADE
The button only switches between light and dark; for the system option, use the theme switcher's mode section or $store.appearance.set('system').
<zb:theme-switcher as="inline" :sections="['mode']" :reset="false" />
| Prop | Values |
|---|---|
$store.appearance.set() | light | dark | system |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
(attributes) | — | — | Attributes such as class and aria-* are added to the button; the other props are on the Theme switcher page |
Developer notes
- Since the icon is chosen with CSS, it looks right as soon as the page opens; for screen readers the button text also changes with the mode ("Switch to dark mode" / "Switch to light mode").
- The preference is kept in the browser, and saved to the account too when the layout has a
preference-url. The panel and in-page forms are on the Theme switcher page. - The 1.x tag
zb:theme-togglekeeps working until 3.0; write<zb:theme-switcher />in new code.