Skip to Content

components/

Thư mục app/components/ chứa component giao diện dùng ở từ hai trang trở lên, chạy trong trình duyệt.

app/ ├── components/ │ ├── StatusTag.tsx # nhãn trạng thái │ └── MoneyCell.tsx # ô tiền trong bảng └── orders/ └── page.tsx # import { StatusTag } from "app/components/StatusTag"

Vai trò

Phần giao diện mà hai trang trở lên cùng dùng (nhãn trạng thái, thẻ khách hàng, ô chọn sản phẩm) nằm ở đây. Component chỉ một trang dùng thì để luôn trong page.tsx của trang đó.

Mọi file trong thư mục là .tsx, chạy trong trình duyệt như trang. Đặt tên file theo tên component, viết PascalCase: component StatusTag nằm ở StatusTag.tsx.

Export

Component React, export có tên hoặc default. Import bằng đường dẫn app/components/<Tên>.

Ví dụ

app/components/StatusTag.tsx
import { Tag } from "antd"; import { OrderStatus } from "app/shared/order"; export function StatusTag({ value }: { value: string }) { return <Tag color={OrderStatus.color(value)}>{OrderStatus.label(value)}</Tag>; }
app/orders/[id:int]/page.tsx
import { StatusTag } from "app/components/StatusTag"; // … <StatusTag value={order.status} />

Cần biết

  • Component không import app/db, *.table.ts, repository.ts hay manh/env. Dữ liệu lấy qua useApiClient() hoặc nhận qua props.
  • Dùng antd và pro-components làm nền. Không dựng lại bảng, form hay modal bằng div.
  • Màu lấy từ token (theme.useToken(), lớp bg-surface, text-fg-secondary), không viết mã hex. check cảnh báo code.hardcoded-color.
  • Không có module app/ui hay app/_ui. Khung app và màn hình dựng sẵn (AppShell, ResourceList, StatRow…) nằm ở manh/shell.

Bước tiếp theo

Cập nhật