theme.tsx
app/theme.tsx giữ giao diện của app (màu chính, bo góc, mật độ, dark mode, bộ icon, token antd) trong một object APP_THEME mà chủ app sửa được.
app/
├── theme.tsx # APP_THEME
├── layout.tsx # ConfigProvider nhận theme tự động
└── orders/page.tsx # đọc token bằng theme.useToken()Vai trò
manh.run áp APP_THEME lên ConfigProvider ngoài cùng của app, nên mọi component antd, pro-components và lớp Tailwind theo token (bg-surface, text-primary) đổi theo. Chủ app sửa ở mục Giao diện trên thanh bên của project; trình sửa đó đọc và ghi đúng file này.
Export
APP_THEME, một JSON nằm giữa hai dấu /* ft-theme */ và /* /ft-theme */:
colorPrimary: màu chính. Chọn màu giữ chữ trắng đọc được (tương phản ≥ 4,5:1).borderRadius: bo góc, tính bằng px.compact:truecho giao diện dày.dark:truecho dark mode.icons(tuỳ chọn):"antd"(mặc định) hoặc"lucide".antd(tuỳ chọn):{ token, components }cùng dạng với trình sửa theme của antd, cho mọi token còn lại nhưfontFamily.kit(tuỳ chọn): tên bộ theme chủ app chọn ở Giao diện (clean,minimal,corporate,warm,fresh,nature,rose,luxe,night). Bộ theme ghi sẵn màu nền, viền, chữ vàoantd.token, nên code app đừng tự đặt lại các màu đó.
Ví dụ
app/theme.tsx
export const APP_THEME: { colorPrimary: string; borderRadius: number; compact: boolean; dark: boolean } =
/* ft-theme */ {"colorPrimary":"#0f766e","borderRadius":8,"compact":false,"dark":false} /* /ft-theme */;app/components/KpiCard.tsx
import { Card, theme } from "antd";
export function KpiCard({ label, value }: { label: string; value: string }) {
const { token } = theme.useToken();
return (
<Card>
<div style={{ color: token.colorTextSecondary }}>{label}</div>
<div style={{ color: token.colorPrimary, fontSize: 24 }}>{value}</div>
</Card>
);
}Cần biết
- Giữ nguyên hai dấu
ft-themevà JSON hợp lệ, nếu không chủ app không sửa được giao diện. - Không viết mã hex trong
style. Đọc màu bằngtheme.useToken()hoặc lớp Tailwind theo token;checkcảnh báocode.hardcoded-colorvàcode.tw-hardcoded-neutral. - Layout có
ConfigProviderkhông đặtthemethì nhậnAPP_THEME. Layout tự đặtthemethì phải đọcAPP_THEME. - Với
icons: "lucide", vẫn import icon từ@ant-design/iconsbằng tên antd; manh.run tự đổi sang bản Lucide. Không importlucide-react. - Tên token không có trong antd bị cảnh báo
theme.unknown-token. - Chỉ dùng tên icon có thật trong
@ant-design/icons. Tên tự đặt nhưLeafOutlinedhiện thành dấu ”?”,checkbáoui.unknown-icon.
Bước tiếp theo
- Giao diện: antd, Tailwind, theme — chọn bộ theme và dùng lớp Tailwind theo token.
- layout.tsx — nơi
AppShellnhậnAPP_THEME.
Cập nhật