- buildRevalidateHook skips outside Next (no NEXT_RUNTIME) and with context.disableRevalidate - BuilderForm focuses only on a real step change (no scroll to the form on remount) - mediaImageProps: placeholder colour only for JPEG (placeholderColor); hook stores no colour for transparent images - buildLinkField: interface name per shape (CmsLink, CmsLinkPlain, CmsLinkNoLabel) + interfaceName option - Cookie Settings: buttons.save -> buttons.savePreferences (Mongoose reserved name) - ThemeScript, ThemeSwitcher, useTheme; Site Settings defaultTheme 'system' + themeToggleLabel; Turnstile follows page theme - extractHeadings, RenderRichText headingIds, TableOfContents, buildTableOfContentsField - createPageRoute onMissing: 'redirectHome' - Form builder: localized placeholder on text/email/textarea/number, new time field - ipal-audit: no false positive for object keys between JSX elements; /md route not reported as dynamic Co-Authored-By: Claude Opus 5.5 <[email protected]>
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
|
|
import { Moon, Sun } from 'lucide-react'
|
|
|
|
import type { Theme } from './theme.js'
|
|
|
|
import { useTheme } from './useTheme.js'
|
|
|
|
export type ThemeSwitcherClassNames = {
|
|
/** Wrapper of the dark icon. */
|
|
dark?: string
|
|
/** Wrapper of the light icon. */
|
|
light?: string
|
|
/** The <button>. */
|
|
root?: string
|
|
}
|
|
|
|
export type ThemeSwitcherProps = {
|
|
classNames?: ThemeSwitcherClassNames
|
|
/** Accessible name — Site Settings → Theme → Toggle label (shell.theme.toggleLabel). */
|
|
label?: null | string
|
|
/** Your icons. Default lucide Sun / Moon. `null` → no icon. */
|
|
renderIcon?: (theme: Theme) => ReactNode
|
|
}
|
|
|
|
/**
|
|
* Light / dark switch with no styles: a <button role="switch"> (checked = dark)
|
|
* holding a light and a dark icon. Which one looks active is CSS's job — from
|
|
* the attribute on <html> (`[data-theme=dark] …`, Tailwind `dark:`), so the
|
|
* server HTML is already right and nothing jumps after hydration.
|
|
* Hooks: data-ipal="theme-switch", data-ipal-theme-icon="light|dark".
|
|
*/
|
|
export function ThemeSwitcher({ classNames: cn = {}, label, renderIcon }: ThemeSwitcherProps) {
|
|
const { theme, toggle } = useTheme()
|
|
const icon = (t: Theme) => (renderIcon ? renderIcon(t) : t === 'light' ? <Sun aria-hidden size="1.25em" /> : <Moon aria-hidden size="1.15em" />)
|
|
return (
|
|
<button
|
|
aria-checked={theme === 'dark'}
|
|
aria-label={label ?? undefined}
|
|
className={cn.root}
|
|
data-ipal="theme-switch"
|
|
onClick={toggle}
|
|
role="switch"
|
|
type="button"
|
|
>
|
|
<span className={cn.light} data-ipal-theme-icon="light">{icon('light')}</span>
|
|
<span className={cn.dark} data-ipal-theme-icon="dark">{icon('dark')}</span>
|
|
</button>
|
|
)
|
|
}
|