CLI
手动安装
CLI 将组件源(及其内部依赖项)复制到您的项目中并安装任何所需的 npm 包。
npx boardui@latest add theme-toggle使用共享 UI 包或自定义导入别名? 配置您的安装路径 在运行 CLI 之前。复制粘贴示例使用默认导入。
项目设置
光是默认值。应用保存的 boardui:theme 水化前的值,以防止第一次油漆闪光,并添加 suppressHydrationWarning 因为根类是在 React 水合之前在浏览器中设置的。
// app/layout.tsximport Script from "next/script";import "@/styles/globals.css";
const themeScript = '(function(){try{var dark=localStorage.getItem("boardui:theme")==="dark";document.documentElement.classList.toggle("dark",dark)}catch(e){document.documentElement.classList.remove("dark")}})();';
export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en" suppressHydrationWarning> <body> <Script id="boardui-theme" strategy="beforeInteractive"> {themeScript} </Script> {children} </body> </html> );}该切换只能手动进行:它不会读取操作系统主题。它的简化动作和不受支持的浏览器后备会立即切换,而不会出现圆形显示。
折叠的侧边栏
套装 collapsed 用于 36px 仅图标控件,适合紧凑的侧边栏导轨,同时保持相同的可访问按下状态。
<ThemeToggle collapsed />