Skip to Content

自定义主题

源码位置: apps/web

NextFaka 的前端应用位于 apps/web,基于 Next.js 构建。目前的架构中,主题是作为核心应用的一部分直接实现的,而不是作为独立的外部包加载。


前端架构

NextFaka 前端架构主要包含以下部分:

nextfaka/ ├── apps/web/ # Next.js 核心应用(页面、路由、业务逻辑) ├── packages/ui/ # UI 组件库(基于 Shadcn/ui) └── packages/core/ # 核心业务逻辑(作为依赖引入)

要自定义外观,你主要会从修改 apps/web 和 packages/ui 入手。


定制指南

1. 样式定制 (Tailwind CSS)

项目使用 Tailwind CSS 进行样式管理。主要的全局样式定义在 apps/web/app/globals.css 中,而样式配置位于 apps/web/tailwind.config.ts。

/* apps/web/app/globals.css */ @tailwind base; @tailwind components; @tailwind utilities; :root { --background: 0 0% 100%; --foreground: 222.2 84% 4.9%; /* ...其他 CSS 变量 */ }

你可以通过修改 tailwind.config.ts 来调整颜色主题、字体等设计 Token。

2. 修改 UI 组件

通用的 UI 组件(如按钮、输入框、对话框)位于 packages/ui。

例如,要修改按钮样式,可以编辑 packages/ui/src/button.tsx:

// packages/ui/src/button.tsx import * as React from "react"; import { Slot } from "@radix-ui/react-slot"; import { cva, type VariantProps } from "class-variance-authority"; import { cn } from "@nextfaka/ui/lib/utils"; const buttonVariants = cva( "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors ...", { variants: { variant: { default: "bg-primary text-primary-foreground hover:bg-primary/90", destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90", // ... }, // ... }, }, );

3. 页面布局与逻辑

页面逻辑位于 apps/web/app 目录下,遵循 Next.js App Router 规范。

  • apps/web/app/(store)/page.tsx: 首页
  • apps/web/app/(store)/products/[slug]/page.tsx: 商品详情页
  • apps/web/app/(store)/orders/[orderNo]/page.tsx: 订单详情页

核心代码示例

以下是 apps/web/app/layout.tsx 的一部分,展示了如何组织全局布局和 Providers:

// apps/web/app/layout.tsx (示例) import "@nextfaka/ui/styles/globals.css"; import { ThemeProvider } from "@/components/theme-provider"; export default function RootLayout({ children, }: { children: React.ReactNode; }) { return ( <html lang="zh-CN" suppressHydrationWarning> <body> <ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange > {children} </ThemeProvider> </body> </html> ); }

下一步

最后更新于