@ah-automation.nl/component-lib

中文文档
0.0.179发布于 2026/10/30TypeScriptES Module近 30 天下载 2205

Reusable React component library built with TypeScript, Tailwind v4, and shadcn/ui.

原始使用文档
文档目录6 节
  1. Development
  2. Publishing
  3. Library Output
  4. Consumer Usage
  5. SidebarNav In Another React Project
  6. DropdownHeader in another React project

component-lib

Reusable React component library built with TypeScript, Tailwind v4, and shadcn/ui.

Development

  • npm run dev: starts local playground (index.html + src/main.tsx) for manual component testing.
  • npm run build: runs typecheck, emits declaration files, and builds the library bundle.
  • npm run lint: runs ESLint across the codebase.
  • npm run format:check: checks formatting without rewriting files.

Publishing

Package publishing runs from GitHub Actions and publishes publicly to npm.

Before using the workflow, add a repository secret named NPM_TOKEN in GitHub:

  1. Create an npm access token with publish permission for @ah-automation.nl/component-lib.
  2. In GitHub, open the repository settings.
  3. Go to Secrets and variables > Actions.
  4. Add the token as a repository secret named NPM_TOKEN.

To publish a new version:

  1. Open the GitHub repository.
  2. Go to Actions.
  3. Select Publish package.
  4. Click Run workflow.
  5. Choose patch, minor, or major.
  6. Run the workflow.

The workflow validates the library, bumps package.json and package-lock.json, creates a vX.Y.Z git tag, publishes with npm publish --access public, then pushes the release commit and tag back to main.

Library Output

Build output is generated in dist/:

  • dist/index.js: ESM library entry. It re-exports one module per source file (dist/components/…, dist/hooks/…, dist/lib/…), so consumer bundlers only include the components an app imports.
  • dist/index.d.ts: exported TypeScript types.
  • dist/styles.css: compiled styles for consumers.

Runtime dependencies (recharts, cmdk, …) are not bundled into dist/; they stay as imports and are installed alongside the package. package.json marks only CSS as having side effects, so unused modules are tree-shaken.

Consumer Usage

import { Button } from "component-lib";
import "component-lib/styles.css";

export function Example() {
  return <Button>Click me</Button>;
}

SidebarNav In Another React Project

import * as React from "react";
import { Home, FolderKanban, Settings, LogOut } from "lucide-react";
import {
  Button,
  SidebarNav,
  type SidebarNavGroup,
  type SidebarNavItem,
} from "component-lib";
import "component-lib/styles.css";

const items: SidebarNavItem[] = [
  { label: "Home", route: "/home", icon: Home, order: 0 },
  { label: "Settings", route: "/settings", icon: Settings, order: 20 },
];

const groups: SidebarNavGroup[] = [
  {
    id: "projects",
    label: "Projects",
    icon: FolderKanban,
    order: 10,
    items: [
      { label: "Overview", route: "/projects", badge: "3" },
      { label: "Active", route: "/projects/active" },
    ],
  },
];

export function AppLayout() {
  const [activeRoute, setActiveRoute] = React.useState("/home");

  return (
    <div className="flex min-h-screen">
      <SidebarNav
        items={items}
        groups={groups}
        activeRoute={activeRoute}
        defaultCollapsed={false}
        onItemClick={(item, event) => {
          // remove this preventDefault if you want normal anchor navigation
          event.preventDefault();
          setActiveRoute(item.route);
        }}
        logo={
          <div className="flex items-center gap-2">
            <div className="size-7 rounded-md bg-primary" />
            <span className="text-sm font-semibold">My Product</span>
          </div>
        }
        footer={
          <Button
            variant="outline"
            className="w-full justify-start group-data-[collapsible=icon]:justify-center"
          >
            <LogOut />
            <span className="group-data-[collapsible=icon]:hidden">Logout</span>
          </Button>
        }
      />

      <main className="min-w-0 flex-1 p-6">
        <h1 className="text-xl font-semibold">Active route: {activeRoute}</h1>
      </main>
    </div>
  );
}

Notes:

  • Import "component-lib/styles.css" once at app root.
  • defaultCollapsed sets the initial sidebar state.
  • onItemClick is optional. Keep href behavior, or intercept and route manually.
  • groups supports one-level nested routes using collapsible SidebarGroup sections.
  • order supports mixed sorting between flat items and groups (stable fallback preserves input order on ties).

DropdownHeader in another React project

import { Fish } from "lucide-react";
import {
  DropdownHeader,
  type DropdownHeaderGroup,
  type DropdownHeaderItem,
} from "@ah-automation.nl/component-lib";

const items: DropdownHeaderItem[] = [
  { label: "Orders", route: "/orders", order: 2 },
  {
    label: "Refresh",
    order: 3,
    onClick: (event) => {
      event.preventDefault();
      refreshData();
    },
  },
];

const groups: DropdownHeaderGroup[] = [
  {
    id: "purchase",
    label: "Purchase",
    order: 1,
    items: [
      { label: "Inventory", route: "/inventory" },
      { label: "Add item", route: "/inventory/new" },
    ],
  },
];

export function Navigation() {
  return (
    <DropdownHeader
      items={items}
      groups={groups}
      activeRoute="/inventory"
      logo={<Fish className="size-6" />}
      onItemClick={(item, event) => {
        if (item.route == null) {
          return;
        }
        event.preventDefault();
        window.history.pushState(null, "", item.route);
      }}
    />
  );
}

The component renders dropdown groups on large screens and an inline, collapsible navigation menu on smaller screens. Pass translated labels and intercept link clicks when the consuming app uses client-side routing. Items without a route require an onClick handler and render as buttons.

版本与发布记录

@ah-automation.nl/component-lib 共发布 173 个版本,首次发布于 2026/03/15;过去 12 个月发布了 173 个版本。

版本发布日期距今
0.0.179latest2026/10/308 天前
0.0.1782026/10/308 天前
0.0.1772026/10/308 天前
0.0.1762026/10/299 天前
0.0.1752026/10/299 天前
0.0.1742026/10/2711 天前

关于 @ah-automation.nl/component-lib 的常见问题

@ah-automation.nl/component-lib 是什么?

Reusable React component library built with TypeScript, Tailwind v4, and shadcn/ui.

如何安装 @ah-automation.nl/component-lib?

在项目目录运行 npm install @ah-automation.nl/component-lib,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.2.4)、zustand(^5.0.12)、radix-ui(^1.4.3)、react-dom(^19.2.4)、@tanstack/react-query(^5.90.21)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ah-automation.nl/component-lib 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ah-automation.nl/component-lib 支持 ESM 还是 CommonJS?

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

@ah-automation.nl/component-lib 可以商用吗?

@ah-automation.nl/component-lib 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@ah-automation.nl/component-lib 的下载量有多少?

根据 npm 官方下载统计,@ah-automation.nl/component-lib 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,205 次,日均约 74 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ah-automation.nl/component-lib 还在维护吗?

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