Skip to main content

Starwind UI v3.0 is now available! Migration guide

Theme Toggle

Runtime adjustment

Theme Toggle now uses the shared theme controller from @starwind-ui/astro/theme. Controls with the same sync group stay aligned across navigation and system-theme changes.

Installation

Usage

---
import { ThemeToggle } from "@/components/starwind/theme-toggle";
---
<ThemeToggle ariaLabel="Toggle theme" />

Preventing a theme flash

Render ThemeInitScript in your document head. It applies the persisted or system theme before the page becomes visible.

---
import { ThemeInitScript } from "@starwind-ui/astro/theme";
---
<html>
<head>
<ThemeInitScript />
</head>
<body>
<slot />
</body>
</html>

Custom icons

Info

Custom icon visibility follows the Runtime-owned data-state and data-ready attributes. Keep data-theme-icon on each icon so the controller can synchronize it.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Theme Toggle

Inherits button attributes. Omits `aria-pressed`, `defaultPressed`, `disabled`, `onChange`, `type`, and `value`.

Contains the following additional props:

Prop Type Default Toggle details
ariaLabel string "Toggle theme"
Description
Provides an accessible label when visible text is not available.
Classification
Wrapper prop
defaultPressed boolean —
Description
Sets the initial pressed state when the control is uncontrolled.
Classification
Wrapper prop
disabled boolean false
Description
Disables interaction with the component.
Classification
Wrapper prop
pressed boolean —
Description
Controls the pressed state.
Classification
Wrapper prop
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant
syncGroup string "starwind-theme"
Description
Synchronizes pressed state across Theme Toggles in the same named group.
Classification
Wrapper prop
value string —
Description
Controls or identifies the component value.
Classification
Wrapper prop
variant "default" | "outline" "outline"
Description
Selects the component's visual variant.
Classification
Styled variant

Changelog

View version history v2.0.1 2 releases

v2.0.1

  • In Astro, an attribute that you set on ThemeToggle now wins over the component’s own default for the same attribute, such as role or aria-label.
  • In Vue, a Boolean prop that you leave out, such as defaultPressed or pressed, no longer becomes false. The default of the underlying component applies.
  • Fixed a ThemeToggle trigger on a link or span that stayed disabled when a framework wrote disabled="false". On a native form control, any disabled attribute still disables it.

v2.0.0

  • Theme Toggle is now available for React as well as Astro. It now saves and applies the theme with the shared Starwind Runtime theme code and ThemeInitScript. Before, each page had its own storage script.
  • See the Runtime theme reference for the shared theme behavior and helpers.
  • Theme Toggle now uses the shared theme code from @starwind-ui/astro/theme. Toggles in the same sync group stay in step when you move between Astro pages and when the system theme changes.