Components / Brand
ThemeToggle
Light/dark switch. Pair it with ThemeBootstrap in <head>: from one set of options it renders themeScript(), so the saved theme applies before first paint, and SavedPreferences, so it comes back on a page the browser draws from scratch, such as a 404. Every Somnia app uses the same storage key, so a choice carries across sites and explorer zones on one origin.
Extracted fromMarketing siteExplorer
Import
tsx
import { ThemeToggle, ThemeBootstrap, themeScript, THEME_KEY, SavedPreferences } from "@somnia-chain/ui"
// in a Next.js app, internal links use next/link:
import { ThemeToggle, ThemeBootstrap, themeScript, THEME_KEY, SavedPreferences } from "@somnia-chain/ui/next"Examples
Icon and labelled
examples/theme-toggle/default.tsxShow codeHide code
tsx
import { ThemeToggle } from "@somnia-chain/ui"
export default function ThemeToggleExample() {
return (
<div className="flex items-center gap-3">
<ThemeToggle />
<ThemeToggle withLabel />
</div>
)
}Props
themeScript(options)
ThemeBootstrap
SavedPreferences