Layout
Theme Menu
A round button that opens a menu with the light, dark and system themes.
Layout
A round button that opens a menu with the light, dark and system themes.
import { ThemeMenu } from 'ferry-ui'
export default function ThemeMenuHero() {
// With no `value`, the menu reads and changes the nearest ThemeProvider.
return <ThemeMenu />
}This menu changes the theme of this site.
actions of a Top Bar, or on a sign-in page.value, the menu reads and changes the nearest ThemeProvider.useTheme().The menu has one part. The icon of the button shows the current preference: a sun, a moon or a monitor.
import { ThemeMenu } from 'ferry-ui'
<ThemeMenu />To control the menu, pass value and onValueChange. The menu then does not change the provider. Your code holds the preference.
import * as React from 'react'
import { ThemeMenu, type ThemePreference } from 'ferry-ui'
export default function ThemeMenuControlled() {
// Your code holds the preference. The menu does not change the ThemeProvider.
const [preference, setPreference] = React.useState<ThemePreference>('system')
return (
<>
<ThemeMenu value={preference} onValueChange={setPreference} />
<span className="text-[13px] text-foreground-light">Preference: {preference}</span>
</>
)
}label sets the heading of the menu and the text of the tooltip. labels sets the names of the three options.
import { ThemeMenu } from 'ferry-ui'
export default function ThemeMenuLabels() {
return <ThemeMenu label="Thème" labels={{ light: 'Clair', dark: 'Sombre', system: 'Système' }} />
}align sets the side of the button that the menu aligns to. The default is end. tooltip={false} hides the tooltip.
import { ThemeMenu } from 'ferry-ui'
export default function ThemeMenuAlign() {
return (
<>
<ThemeMenu align="start" tooltip={false} />
<ThemeMenu align="center" tooltip={false} />
<ThemeMenu align="end" tooltip={false} />
</>
)
}className goes to the button. Use it to hide the menu on a phone.
<TopBar
actions={
<>
<TopBarSearch />
<ThemeMenu className="max-sm:hidden" />
<TopBarUserMenu name="Maya Chen" />
</>
}
/>TooltipProvider above the menu. See Tooltip.ThemeMenu accepts only the props of this table. The button has data-slot="theme-menu-trigger", and the panel has data-slot="theme-menu".
| Prop | Type | Default |
|---|---|---|
value | "light" | "dark" | "system" | - |
Controlled theme preference. When omitted the menu reads and writes the nearest | ||
onValueChange | ((value: ThemePreference) => void) | - |
Called with the chosen preference. In uncontrolled mode the | ||
label | string | Theme |
Heading of the menu, tooltip and accessible name prefix (default "Theme"). | ||
labels | Partial<Record<ThemePreference, string>> | - |
Translated option names, e.g. | ||
tooltip | boolean | true |
Show the label as a tooltip on the trigger (default | ||
open | boolean | - |
Controlled open state of the menu (pair with | ||
defaultOpen | boolean | - |
Initial open state when uncontrolled. | ||
onOpenChange | ((open: boolean) => void) | - |
Called with the next open state. | ||
modal | boolean | - |
Radix modal mode (default | ||
align | "center" | "start" | "end" | end |
Alignment of the menu against the trigger (default "end"). | ||
className | string | - |
Classes for the round trigger button (e.g. | ||
contentClassName | string | - |
Classes for the menu panel (default width 160px). | ||