@brainfish-ai/components

中文文档
0.37.1发布于 2026/11/05MITTypeScriptES Module近 30 天下载 2653

脑鱼成分

中文使用文档
文档目录27 节
  1. 安装
  2. 使用量
  3. 单个组件导入(建议)
  4. 批量导入( Legacy)
  5. 可用个人进口
  6. 样式
  7. 发展
  8. 开始
  9. 发展中国家
  10. 大楼
  11. 发展指南
  12. 颜色系统
  13. 尾风 CSS 整合
  14. 组件模式(阴影/井)
  15. 故事书要求
  16. Typescript 的 Linting 和代码格式化
  17. 测试
  18. 将您的图书馆发布给国家预防机制
  19. 故事书
  20. 脚本
  21. 资源
  22. 邦德勒语Name
  23. 代码格式
  24. 故事书
  25. 测试
  26. 线性
  27. 编译器

脑鱼成分

Brainfish组件是一个Resact组件库,支持批量进口和单个组件进口(类似于shadcn/ui),以优化树摇和捆绑尺寸.

安装

npm install @brainfish-ai/components
# or
yarn add @brainfish-ai/components

使用量

仅导入最佳捆绑大小所需的组件 :

// Import individual UI components
import { Button } from '@brainfish-ai/components/ui/button';
import { Dialog } from '@brainfish-ai/components/ui/dialog';
import { Input } from '@brainfish-ai/components/ui/input';

// Import other components
import { ChatSearch } from '@brainfish-ai/components/chat-search';
import { DatePicker } from '@brainfish-ai/components/date-picker';
import { Filter } from '@brainfish-ai/components/filter';

function MyApp() {
  return (
    <div>
      <Button>Click me</Button>
      <Input placeholder="Enter text..." />
      <DatePicker />
    </div>
  );
}

批量导入( Legacy)

立即导入所有组件( 更大的捆绑大小) :

import { Button, Dialog, Input, ChatSearch } from '@brainfish-ai/components';

可用个人进口

UI 组件

  • @brainfish-ai/components/ui/button
  • @brainfish-ai/components/ui/card
  • @brainfish-ai/components/ui/collapsible
  • @brainfish-ai/components/ui/command
  • @brainfish-ai/components/ui/dialog
  • @brainfish-ai/components/ui/dropdown-menu
  • @brainfish-ai/components/ui/input
  • @brainfish-ai/components/ui/label
  • @brainfish-ai/components/ui/popover
  • @brainfish-ai/components/ui/scroll-area
  • @brainfish-ai/components/ui/switch
  • @brainfish-ai/components/ui/textarea
  • @brainfish-ai/components/ui/tooltip

复杂组件

  • @brainfish-ai/components/chat-search
  • @brainfish-ai/components/combobox
  • @brainfish-ai/components/date-picker
  • @brainfish-ai/components/feedback
  • @brainfish-ai/components/filter
  • @brainfish-ai/components/generating-star
  • @brainfish-ai/components/markdown
  • @brainfish-ai/components/select

样式

别忘了输入CSS:

import '@brainfish-ai/components/styles.css';

发展

开始

yarn install

发展中国家

要开始运行 :

yarn start

这将构建一个版本的您的库,运行监视器,并运行故事书. 要手动打开"故事本"打开浏览器并导航到 http://localhost:6006 (英语)。 。 。 . 开始在 src/components 文件夹并更新 src/index.js 相应的文件. 总是提供 YourComponent.story.tsx 文件,所以您的组件将出现在故事本中.

大楼

以单个组件导出构建库 :

yarn build:components

发展指南

本节解释此组件库用于帮助新开发者快速启动的架构和模式.

颜色系统

我们的颜色系统建立在定义于 src/global.css所有变量都使用 --bfc- 前缀(Brainfish 组件).

颜色调试缩放

颜色跟随100-1000比例尺,较低数字更轻而较高数字更暗:

--bfc-v2-color-blue-100: #e9f2fe;  /* lightest */
--bfc-v2-color-blue-500: #4688ec;  /* mid-tone */
--bfc-v2-color-blue-1000: #1c2b42; /* darkest */

可用的颜色调色板

调色板CSS 变量模式
单曲--bfc-v2-color-mono-{100-1000}
红色--bfc-v2-color-red-{100-1000}
橙红色--bfc-v2-color-orange-{100-1000}
黄色--bfc-v2-color-yellow-{100-1000}
莱姆--bfc-v2-color-lime-{100-1000}
绿色--bfc-v2-color-green-{100-1000}
蓝色--bfc-v2-color-blue-{100-1000}
提尔--bfc-v2-color-teal-{100-1000}
紫色--bfc-v2-color-purple-{100-1000}
紫红色--bfc-v2-color-magenta-{100-1000}

语义色彩托肯斯

与其使用生色值,不如使用适应主题的语义符号:

脚本目的
--bfc-primary主要品牌颜色
--bfc-background页面背景
--bfc-foreground主文本颜色
--bfc-muted下层背景
--bfc-muted-foreground已修改文本
--bfc-border边框颜色
--bfc-destructive-bg错误/危险背景
--bfc-success-bg成功状态背景

黑暗模式

黑暗模式通过添加 .dark 分类到元素。 颜色尺度会自动倒置(100会变成最黑暗的,1000会变成最轻的),确保两个主题的一致对比.

<!-- Light mode (default) -->
<html>...</html>

<!-- Dark mode -->
<html class="dark">...</html>

尾风 CSS 整合

我们使用Tailwind CSS, 带有一个自定义的预设, 将我们的颜色系统映射到Tailwind公用事业.

使用尾风预设

这个库的消费者可以导入我们的 Tailwind 预设, 用同样的设计符号:

// tailwind.config.js
module.exports = {
  presets: [require('@brainfish-ai/components/tailwind')],
  // ... your config
};

语义色彩类

使用语义性 Tailwind 类而不是生色 :

// Good - uses semantic colors that adapt to themes
<div className="bg-primary text-foreground border-border" />
<div className="bg-destructive text-destructive" />
<div className="bg-muted text-muted-foreground" />

// Bad - hardcoded colors won't adapt to dark mode
<div className="bg-[#a3e635] text-[#171717]" />

字型设备

自定义的打字类用于一致的文本样式:

类字体大小使用大小写
.heading-xxl2点页面标题
.heading-xl1.75雷姆科头
.heading-lg1.5雷姆(1.5雷姆)纸牌头
.heading-m1.25雷门分节
.heading-sm1雷姆( 1雷姆)小标题
.paragraph-lg1雷姆( 1雷姆)文本正文
.paragraph-md0.875亿雷姆默认文本
.paragraph-sm0.75亿雷姆说明、标签

这个 cn() 工具

使用 cn() 从 @/lib/utils 安全合并 Tailwind 类:

import { cn } from '@/lib/utils';

// Merges classes and handles conflicts properly
<div className={cn('bg-primary p-4', isActive && 'bg-accent', className)} />

组件模式(阴影/井)

我们的UI组件如下 阴影/ ui 模式和公约.

构成部分

  • 基础UI组件 : src/components/ui/
  • 复杂/复合组件: src/components/

构成部分结构

组件使用 class-variance-authority (CVA)用于变种管理:

import * as React from 'react';
import { cva, type VariantProps } from 'class-variance-authority';
import { cn } from '@/lib/utils';

// Define variants with CVA
const buttonVariants = cva(
  'inline-flex items-center justify-center rounded-md text-sm font-medium',
  {
    variants: {
      variant: {
        default: 'bg-primary text-primary-foreground',
        destructive: 'bg-destructive text-destructive-foreground',
        outline: 'border border-input bg-background',
      },
      size: {
        default: 'h-9 px-4 py-2',
        sm: 'h-8 px-3 text-sm',
        lg: 'h-10 px-8',
      },
    },
    defaultVariants: {
      variant: 'default',
      size: 'default',
    },
  }
);

// Component with forwarded ref
export interface ButtonProps
  extends React.ButtonHTMLAttributes<HTMLButtonElement>,
    VariantProps<typeof buttonVariants> {}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
  ({ className, variant, size, ...props }, ref) => (
    <button
      className={cn(buttonVariants({ variant, size, className }))}
      ref={ref}
      {...props}
    />
  )
);
Button.displayName = 'Button';

export { Button, buttonVariants };

主要公约

  1. 总是使用语义颜色 - 在组件中不要使用原始六分法值
  2. 预览 - 所有组成部分均应提交灵活性参考文件
  3. 使用 cn() 用于类Name - 总是与来类合并Name
  4. 导出变体 - 出口CVA变体再利用
  5. 设定显示Name - 总是设置 displayName 用于更好的调试

故事书要求

每个组件MUST都有相伴随的"故事本"故事文件.

为什么故事重要

  • 启用独立的组件测试和开发
  • 作为组成部分API的活文件
  • 允许视觉回归测试
  • 帮助设计者和开发者合作

故事文件公约

对于一个构成部分 Button.tsx创建 Button.stories.tsx 在同一目录中:

src/components/ui/
├── button.tsx
├── button.stories.tsx  <-- Required!
└── button.test.tsx     <-- Optional unit tests

故事结构

import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './button';

const meta: Meta<typeof Button> = {
  title: 'UI/Button',
  component: Button,
  tags: ['autodocs'],
};

export default meta;
type Story = StoryObj<typeof Button>;

// Show all variants
export const Default: Story = {
  args: { children: 'Click me' },
};

export const Destructive: Story = {
  args: { variant: 'destructive', children: 'Delete' },
};

export const AllSizes: Story = {
  render: () => (
    <div className="flex gap-4">
      <Button size="sm">Small</Button>
      <Button size="default">Default</Button>
      <Button size="lg">Large</Button>
    </div>
  ),
};

运行故事本

yarn storybook

然后打开 http://localhost:6006 (英语) 在您的浏览器中.


Typescript 的 Linting 和代码格式化

通过 Linting 和代码格式化 ESLint 语录 财务报告和审定财务报表 高级 使用 eslint- 插件反应 财务报告和审定财务报表 埃斯林特- 配置- prettier。 。 。 . 你可以修改林地规则,在 .eslintrc.cjs 文档.

yarn lint

或(如果可以自动固定)

yarn lint:fix

测试

测试用完了 维特 财务报告和审定财务报表 @ testing-library/反应 你可以参考 Button.test.js 作为例子.

yarn test

将您的图书馆发布给国家预防机制

向国家防范机制或私人登记处开放图书馆,确保您在 国家预防机制、 .npmrc 文件被正确设置, 注册 URL 发布 Config 在 package.json 文件设置为您的仓库 url, 然后 :

yarn release

故事书

关于自定义布局,造型和更多关于"故事书"的信息,请参见: 故事书 文档.

向 GitHub 页部署故事本

确定主页 URL 在 package.json 文件设置为您的 githup 页面 url, 然后 :

yarn deploy

脚本

  • yarn start :只服务于故事书.
  • yarn build :构建您的库(可在 dist 文件夹).
  • yarn storybook:build :构建静态故事书,以备你想部署.
  • yarn test :进行测试.
  • yarn test:coverage:运行测试并显示覆盖.
  • yarn lint :运行linter, Typescript 类型检查和样式lint.
  • yarn lint:fix :运行linter, Typescript 类型检查和样式lint并修正自动可修复的问题.
  • yarn eslint: 只运行 JavaScript linter.
  • yarn eslint:fix: 只运行 JavaScript 插件并修正自动可修复的问题.
  • yarn stylelint: 只运行样式 linter .
  • yarn stylelint:fix:只运行样式的linter并修正自动可修复的问题.
  • yarn check-types: 运行打字机类型检查器.
  • yarn ci:运行Linting,测试和打字机一起运行.
  • yarn release : 在国家预防机制或私人登记处公布图书馆(取决于您在国家预防机制或私人登记处的配置) .npmrc 存档).
  • yarn storybook: 和纱线的开头一样,为故事书服务.
  • yarn storybook:build: 生成故事书的构建 storybook-static 文件夹,可以在您需要的地方部署.
  • yarn storybook:deploy:构建并部署"故事本"到"GitHub Pages".

资源

邦德勒语Name

代码格式

故事书

测试

线性

编译器

版本与发布记录

@brainfish-ai/components 共发布 377 个版本,首次发布于 2024/12/23;过去 12 个月发布了 149 个版本。

版本发布日期距今
0.37.1latest2026/11/053 天前
0.37.02026/11/044 天前
0.36.12026/11/035 天前
0.36.02026/10/309 天前
0.35.202026/10/2712 天前
0.35.192026/10/1920 天前

其他发布通道:beta → 0.15.0-beta.3,rc → 0.16.6-rc.3,alpha → 0.18.4-alpha.7。

关于 @brainfish-ai/components 的常见问题

@brainfish-ai/components 是什么?

脑鱼成分

如何安装 @brainfish-ai/components?

在项目目录运行 npm install @brainfish-ai/components,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:clsx(^2.x)、react(18.x || 19.x)、react-dom(18.x || 19.x)、usehooks-ts(^3.x)、tailwind-merge(^2.x)、tailwindcss-animate(^1.x)、@phosphor-icons/react(^2.x)、class-variance-authority(^0.7.x)、@tailwindcss/container-queries(0.1.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@brainfish-ai/components 支持 TypeScript 吗?

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

@brainfish-ai/components 支持 ESM 还是 CommonJS?

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

@brainfish-ai/components 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 22.x || 24.x。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@brainfish-ai/components 可以商用吗?

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

@brainfish-ai/components 的下载量有多少?

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

@brainfish-ai/components 还在维护吗?

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