@appdirect/sfb-theme-components

中文文档
2.1.52发布于 2026/11/03UNLICENSEDCommonJS近 30 天下载 2143

存储前置构建器用于构建主题的组件.

中文使用文档
文档目录11 节
  1. 安装
  2. 利用市场进行地方发展
  3. 使用工具包进行地方发展
  4. 故事书
  5. 为您的主题创建自定义组件
  6. CSS - 命名公约
  7. 构成部分的结构
  8. 进行响应
  9. 推进型和功能组件不强制
  10. CSS - 命名工具
  11. Jest - 测试和调试

sfb -- -- 主题组成部分

存储前置构建器用于构建主题的组件.

安装

  • 安装依赖关系 npm install
    • 升级到16号节点后,您必须完成 npm install --legacy-peer-deps 换成

利用市场进行地方发展

  • 启动服务器 npm start。 。 。 .
  • 你用得着 资源覆盖 用于js和cs:
    • 发讯人: https://engage19billing.test.devappdirect.me/sfb-theme-components@0/* 改为 http://localhost:3444/*
    • 替换您选择的 MP URL

使用工具包进行地方发展

  • 安装 sfb-toolkit (英语)。 。 。 .
  • 设置以 Plaza 为主题的主题项目: sfb-toolkit setup。 。 。 .
  • 开始 sfb-toolkit 本地服务器 : sfb-toolkit start。 。 。 .
  • 开始 sfb-theme-components 服务捆绑的本地服务器 : npm run start
  • 你可以做到这一点 资源覆盖 用于js和cs:
    • 发讯人: https://engage19billing.test.devappdirect.me/sfb-theme-components@0/* 改为 http://localhost:3444/*

故事书

要查看组件,我们可以启动"故事本"服务器:

  • 运行 npm run storybook。 。 。 .
  • 导航到 http://localhost:8087/。 。 。 .
  • 在左手导航栏上,选择一个组件/Atom将使组件成为主部分.
  • 我们正在使用 童话小说 以更新故事本中组件设置道具.

为您的主题创建自定义组件

CSS - 命名公约

我们将遵循修改后的版本: https://css-tricks.com/abem-useful-adaptation-bem/ (中文(中国大陆) )

  • 无 a/o/m 前缀
  • 名称应多用一个词 骆驼 Case 公约代替 -
  • 修改器正在使用 -- (双破折号)并与名称相接

实例:

// just an element, nothing to see
<div class="blockName_elementName"></div>
// with a modifier
<div class="blockName_elementName blockName_elementName--modifier"></div>

关于更详细的例子,请参见一节 CSS - Naming Tool

构成部分的结构

组件有两个文件夹:

  • atoms/ 其中应包括非常基本、易于重复使用的不同主题和样式组件,例如: 图像, (中文(简体) ), 按钮, (中文(简体) ), 页眉等 (中文(简体) ).
  • components/ 包含一个主题更具体的组件,大多数时间包括一个或多个 原子 组件

进行响应

推进型和功能组件不强制

CSS - 命名工具

已实施命名工具,以帮助跟踪CSS命名结构:

每一组成部分应包含:

import { createNamespace } from './tools/namingTools';

const n = createNamespace('MyComponentName');

简单用途 :

<div {...n(element[, [modifiers]]).props}></div>
  • modifier 是可选的,也可以是其中之一 string 或者说 array of strings

实例

带有修改符的元素 :
<div {...n('elementName', 'myModifier').props}></div> 
// translates to
<div 
    class="myComponentName_elementName 
           myComponentName_elementName--myModifier">
</div> 
带有修改词列表的元素 :
<div {...n('elementName', ['myModifier1', 'myModifier2']).props}></div> 
// translates to
<div 
    class="myComponentName_elementName 
           myComponentName_elementName--myModifier1 
           myComponentName_elementName--myModifier2">
</div> 
有 testId 的元素 : .withTestId()
<div {...n('elementName').withTestId().props}></div> 
// translates to
<div class="myComponentName_elementName" data-testid="myComponentName:elementName"></div> 
有自定义 testId 的元素 : .withTestId(*)
<div {...n('elementName').withTestId('myTestId').props}></div> 
// translates to
<div class="myComponentName_elementName" data-testid="myComponentName:myTestId"></div> 
有 testId 的元素 仅限数字 : .withTestId()
<div {...n().withTestId('myTestId').props}></div> 
// translates to
<div data-testid="myComponentName:myTestId"></div> 
有额外类的元素 .withClass(*)
<div {...n('elementName').withClass('myExtraClass').props}></div> 
// translates to
<div class="myComponentName_elementName myExtraClass"></div> 
有额外类的元素 .withClass(*)
<div {...n('elementName').withClass(['myExtraClass1', 'myExtraClass2']).props}></div> 
// or
<div {...n('elementName').withClass('myExtraClass1').withClass('myExtraClass2').props}></div> 
// translates to
<div class="myComponentName_elementName myExtraClass1 myExtraClass2"></div> 

namingTool 和它的职能 .withClass(), (中文(简体) ), .withTestId() 为: 可连锁 这意味着您可以研究每个函数的结果,直到 .props 将召入.

复杂实例
<div 
     {...n('elementName', ['modifier1', modifier2'])
         .withClass(['myExtraClass1', 'myExtraClass2'])
         .withClass('testClass')
         .withTestId()
         .props
     }></div> 
// translates to
<div 
    class="myComponentName_elementName 
           myComponentName_elementName--modifier1
           myComponentName_elementName--modifier2
           myExtraClass1 
           myExtraClass2
           testClass"
    data-testid="myComponentName:elementName "
></div> 

Jest - 测试和调试

已有5个定义的发射配置可用于测试和调试:

  • Jest run all test suites - 这个配置将贯穿所有测试套件和项目中定义的所有测试案例.
  • Jest run selected test suite - 此配置将运行目前在您工作空间中选择的文件( 测试套件) 中找到的所有测试大小写 .
  • Jest run all tests matching selected text - 此配置将运行所有匹配您工作空间中选中/ 突出显示的文本的测试大小写( 多个测试可根据所选文本匹配)
  • Jest run all test suites matching prompted input - 此配置将运行所有包含/匹配输入框中提供的文本的测试套件, 当配置运行时将会显示( 多个测试套件可以匹配)
  • Jest run all tests matching prompted input - 此配置将运行所有包含/匹配输入框中提供的文本的测试大小写, 当配置运行时会显示( 多个测试大小写可以匹配)

NOTE: 在使用上述配置时,断点应在VS代码中正确工作.

版本与发布记录

@appdirect/sfb-theme-components 共发布 98 个版本,首次发布于 2019/05/16;过去 12 个月发布了 7 个版本。

版本发布日期距今
2.1.52latest2026/11/034 天前
2.1.502026/10/0929 天前
2.1.492026/08/252 个月前
2.1.462026/06/304 个月前
2.1.332026/05/056 个月前
2.1.322026/04/186 个月前

关于 @appdirect/sfb-theme-components 的常见问题

@appdirect/sfb-theme-components 是什么?

存储前置构建器用于构建主题的组件.

如何安装 @appdirect/sfb-theme-components?

在项目目录运行 npm install @appdirect/sfb-theme-components,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>= 16.x.x || >= 18.x.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@appdirect/sfb-theme-components 支持 TypeScript 吗?

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

@appdirect/sfb-theme-components 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@appdirect/sfb-theme-components 需要什么版本的 Node.js?

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

@appdirect/sfb-theme-components 可以商用吗?

@appdirect/sfb-theme-components 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@appdirect/sfb-theme-components 的下载量有多少?

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

@appdirect/sfb-theme-components 还在维护吗?

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