v0.0.2
Demos (demo panel, opens in a new tab)

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

Basic usage: view
BLADE

A moon shows in light mode and a sun in dark mode; clicking switches to the opposite of the mode on screen.

blade
<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.

blade
<zb:layout.sidebar :theme-toggle="false">
    <zb:slot:drawerFooter>
        <zb:theme-switcher class="ms-auto" />
    </zb:slot:drawerFooter>

    {{ $slot }}
</zb:layout.sidebar>
PropValues
theme-toggletrue | false (layout prop)

Light, dark and system

Light, dark and system: view
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').

blade
<zb:theme-switcher as="inline" :sections="['mode']" :reset="false" />
PropValues
$store.appearance.set()light | dark | system

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
(attributes)— — Attributes such as class and aria-* are added to the button; the other props are on the Theme switcher page

Developer notes

Events, hooks and details
  • 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-toggle keeps working until 3.0; write <zb:theme-switcher /> in new code.
Zubazar UI · ZubazarDesigned for people.