@dashboardpack/core

中文文档
1.7.0发布于 2026/07/31MITES Module近 30 天下载 7905

Shared UI components, providers, data modules, and utilities for DashboardPack templates

原始使用文档
文档目录9 节
  1. Installation
  2. What's inside
  3. Replacing the mock data
  4. Permissions are not security
  5. Peer dependencies
  6. Developing against a template
  7. Checks
  8. Contributing: React Server Component safety
  9. License

@dashboardpack/core

Shared UI components, providers, data modules, and utilities for DashboardPack templates (Apex, Zenith, Flux, Ember).

This is a source-only package. It ships untranspiled TypeScript and TSX — there is no build step and no dist/. Consuming apps compile it themselves.

Installation

npm install @dashboardpack/core

Add it to transpilePackages in next.config.ts so Next.js compiles the source:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  transpilePackages: ["@dashboardpack/core"],
};

export default nextConfig;

Because the package exports raw paths ("./*": "./*"), imports mirror the directory layout:

import { Button } from "@dashboardpack/core/components/ui/button";
import { PageHeader } from "@dashboardpack/core/components/shared/page-header";
import { orders } from "@dashboardpack/core/lib/data";
import { cn } from "@dashboardpack/core/lib/utils";

What's inside

PathContents
components/ui/35 shadcn/ui-style primitives (button, card, dialog, form, live-region, …)
components/shared/PageHeader, EmptyState, ConfirmDialog, DataTable, LazyChart, DateRangePicker
providers/ThemeProvider (dark/light/system + resolvedTheme), SidebarProvider (collapse, layout mode, container mode, direction)
lib/data-provider/DataProvider interface, mock / REST / fixture implementations, and useList / useOne / useMutation
lib/navigation/Node types plus toTree / toFlat / toSitemap / activeLeaf / validateRegistry
lib/rbac/can, effectivePermissions, permissionGroups, Can, RequirePermission, usePermissions
lib/schemas/Shared zod schemas for the user and role forms
lib/data/Mock data for every page (orders, products, customers, invoices, users, roles, analytics, chat, mail, kanban, calendar, files, notifications)
lib/data/paginate.tspaginate() and the perPage: "all" sentinel
lib/data/types.tsShared TypeScript interfaces, PERMISSION_KEYS and PermissionKey
lib/i18n/useTranslations() hook and message files (en, de, fr)
lib/utils.tscn() and generateInitials()

Replacing the mock data

Pages talk to a DataProvider, not to the mock modules, so switching to a real API is a one-line change in the template:

// src/lib/data/provider.ts
export const dataProvider = createMockProvider({ baseUrl: "/api" });
// export const dataProvider = createRestProvider({ baseUrl: process.env.NEXT_PUBLIC_API_URL! });

createMockProvider fetches static JSON over HTTP, so loading, error and retry states are real even with no backend. createRestProvider writes optimistically and rolls back on failure. createFixtureProvider is for tests, with failNext() and setLatency().

Mock mutations are in-memory and reset on reload. That is deliberate: persisting them would let a visitor's edits drift from the shipped fixtures, so the demo would stop being reproducible.

Permissions are not security

lib/rbac gates UI affordances. A template built on it ships as static HTML with its data in public JSON files, so everything is already on the client and no client-side check can change that. Use it to hide and disable controls, and enforce the same rules on your server. The module's source says the same thing, at the top, on purpose.

Peer dependencies

Everything the components import is a peer dependency, so the consuming template controls the versions. React 19 and Next.js 16 are the baseline. See peerDependencies in package.json for the full list and supported ranges.

The only runtime dependencies are @radix-ui/react-slot and sugar-high.

Developing against a template

Do not use npm link. This package keeps its peer dependencies installed so it can typecheck standalone, and under a link the consumer resolves them from here — so react-hook-form loads twice from two paths and TypeScript reports Control<T> from each copy as a distinct type, producing dozens of "not assignable" errors that do not exist in a real install. Consumers also set preserveSymlinks: true and resolve.symlinks = false, so a link resolves through the symlinked path regardless.

Copy the published files instead, which reproduces npm install exactly:

./tools/sync-to-consumer.sh ../apex-dashboard

Then run the template's own npm run verify.

Checks

npm run verify   # typecheck + check:rsc + check:package + tests
  • check:rsc — fails if a module without "use client" imports the radix-ui barrel. See the Server Component safety section below; this is the guard for the crash that shipped in 1.1.3.
  • check:package — fails if the tarball would ship test files, dev tooling or a build cache, or if a documented entry point is missing. exports: { "./*": "./*" } gives no import-time safety net, so a missing file is a runtime failure for the customer.

Contributing: React Server Component safety

Most components here are client components and carry a "use client" directive. A few are deliberately not client components — button.tsx, breadcrumb.tsx, card.tsx, badge.tsx, avatar.tsx, input.tsx, textarea.tsx, progress.tsx, skeleton.tsx — so that templates can render them from Server Components such as not-found.tsx, layout.tsx, or error pages.

Never import from the radix-ui barrel in a file without "use client".

The barrel eagerly evaluates every Radix primitive on import, and several of them call React.createContext() at module scope. In the React Server Component graph createContext does not exist, so the import crashes the page:

TypeError: React.createContext is not a function

Whether it actually crashes depends on whether the consuming bundler tree-shakes the barrel, which makes it fail on some machines and not others. Import the individual primitive package instead:

// Wrong — pulls in every Radix primitive
import { Slot } from "radix-ui";

// Right — only what is needed, and free of module-scope createContext
import * as Slot from "@radix-ui/react-slot";

You can verify a change with:

node --conditions=react-server -e "require('<package-name>')"

If that throws createContext is not a function, the package is not safe to import from a Server Component.

This rule caused a shipped regression in 1.2.0 — see CHANGELOG.md.

License

MIT

版本与发布记录

@dashboardpack/core 共发布 12 个版本,首次发布于 2026/03/10;过去 12 个月发布了 12 个版本。

版本发布日期距今
1.7.0latest2026/07/313 个月前
1.6.12026/07/303 个月前
1.6.02026/07/293 个月前
1.5.02026/07/293 个月前
1.4.02026/07/293 个月前
1.3.22026/07/293 个月前

关于 @dashboardpack/core 的常见问题

@dashboardpack/core 是什么?

Shared UI components, providers, data modules, and utilities for DashboardPack templates

如何安装 @dashboardpack/core?

在项目目录运行 npm install @dashboardpack/core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@hookform/resolvers(^5.4.0)、@tanstack/react-table(^8.21.3)、class-variance-authority(^0.7.1)、clsx(^2.1.1)、cmdk(^1.1.1)、date-fns(^4.4.0)、input-otp(^1.4.2)、libphonenumber-js(^1.13.7)、lucide-react(^1.0.0)、next(^16.0.0)、radix-ui(^1.6.0)、react(^19.0.0)、react-colorful(^5.7.0)、react-day-picker(^10.0.0)、react-dom(^19.0.0)、react-dropzone(>=15.0.0)、react-hook-form(^7.80.0)、recharts(^3.9.0)、sonner(^2.0.7)、tailwind-merge(^3.6.0)、zod(^4.4.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dashboardpack/core 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dashboardpack__core 是否存在。

@dashboardpack/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dashboardpack/core 可以商用吗?

@dashboardpack/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dashboardpack/core 的下载量有多少?

根据 npm 官方下载统计,@dashboardpack/core 在 2026/10/12 – 2026/11/10 这 30 天内被下载 7,905 次,日均约 264 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dashboardpack/core 还在维护吗?

最新版本 1.7.0 发布于 2026/07/31(3 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 12 个;首次发布于 2026/03/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。