@appdirect/sfb-theme-components

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

Components used by the storefront builder to build themes.

原始使用文档
文档目录11 节
  1. Installation
  2. Local development using a Marketplace
  3. Local development using toolkit
  4. Storybook
  5. Creating custom components for your theme
  6. CSS - Naming convention
  7. Component's structure
  8. Doing Responsive
  9. Proptypes and functional components are inforced
  10. CSS - Naming Tool
  11. Jest - Testing & Debugging

sfb-theme-components

Components used by the storefront builder to build themes.

Installation

  • Install dependencies with npm install
    • After upgrading to Node 16, you have to do npm install --legacy-peer-deps instead

Local development using a Marketplace

  • Start server with npm start.
  • You can use resource override for the js and css:
    • From: https://engage19billing.test.devappdirect.me/sfb-theme-components@0/* to http://localhost:3444/*
    • Replace MP url of your choice

Local development using toolkit

  • Install sfb-toolkit.
  • Setup a theme project with a Plaza theme: sfb-toolkit setup.
  • Start the sfb-toolkit local server: sfb-toolkit start.
  • Start the sfb-theme-components local server to serve the bundles: npm run start
  • You can do the resource override for the js and css:
    • From: https://engage19billing.test.devappdirect.me/sfb-theme-components@0/* to http://localhost:3444/*

Storybook

To view the components, we can start the Storybook server:

  • Run npm run storybook.
  • Navigate to http://localhost:8087/.
  • On the left hand navigation bar, selecting a Component/Atom will render the component in the main section.
  • We are using Storybook Knobs to update the component's settings prop in Storybook.

Creating custom components for your theme

CSS - Naming convention

We're gonna follow modified version of: https://css-tricks.com/abem-useful-adaptation-bem/

  • NO a/o/m prefixes
  • Names with more then one term should use camelCase convention instead of -
  • Modifiers are using -- (double dash) and are connected with the name

Examples:

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

For more detailed examples please take a look in section CSS - Naming Tool

Component's structure

There are two folders for components:

  • atoms/ which should include very basic, easily re-usable across different themes and styling components like Image, Button, Header, etc.
  • components/ should contain components that are more specific for a theme, most of the time are including one or more atom components

Doing Responsive

Proptypes and functional components are inforced

CSS - Naming Tool

There has been implemented namingTool to help out follow above CSS naming structure:

Every component should contain:

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

const n = createNamespace('MyComponentName');

Simple usage:

<div {...n(element[, [modifiers]]).props}></div>
  • modifier is optional and can be either string or array of strings

Examples

Element with modifier:
<div {...n('elementName', 'myModifier').props}></div> 
// translates to
<div 
    class="myComponentName_elementName 
           myComponentName_elementName--myModifier">
</div> 
Element with list of modifiers:
<div {...n('elementName', ['myModifier1', 'myModifier2']).props}></div> 
// translates to
<div 
    class="myComponentName_elementName 
           myComponentName_elementName--myModifier1 
           myComponentName_elementName--myModifier2">
</div> 
Element with testId: .withTestId()
<div {...n('elementName').withTestId().props}></div> 
// translates to
<div class="myComponentName_elementName" data-testid="myComponentName:elementName"></div> 
Element with custom testId: .withTestId(*)
<div {...n('elementName').withTestId('myTestId').props}></div> 
// translates to
<div class="myComponentName_elementName" data-testid="myComponentName:myTestId"></div> 
Element with testId only: .withTestId()
<div {...n().withTestId('myTestId').props}></div> 
// translates to
<div data-testid="myComponentName:myTestId"></div> 
Element with extra class .withClass(*)
<div {...n('elementName').withClass('myExtraClass').props}></div> 
// translates to
<div class="myComponentName_elementName myExtraClass"></div> 
Element with extra classes .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 and it's functions .withClass(), .withTestId() are chainable which means you can work on the results of each function until the .props will be called.

Complex example
<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 - Testing & Debugging

There are five launch configurations defined that can be used to test and debug:

  • Jest run all test suites - this configuration will go through all test suites and all test cases defined in the project.
  • Jest run selected test suite - this configuration will run all test cases found in the file (test suite) that is currently selected in your workspace.
  • Jest run all tests matching selected text - this configuration will run all test cases that will match the text selected/highlighted in your workspace (multiple tests can match depending on the selected text)
  • Jest run all test suites matching prompted input - this configuration will run all test suites that contain/match the text provided in the input box that will show up once the configuration is run (multiple test suites can match)
  • Jest run all tests matching prompted input - this configuration will run all test cases that contain/match the text provided in the input box that will show up once the configuration is run (multiple test cases can match)

NOTE: Breakpoints should work correctly in VS Code when using the above configurations.

版本与发布记录

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

版本发布日期距今
2.1.52latest2026/11/035 天前
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 是什么?

Components used by the storefront builder to build themes.

如何安装 @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(5 天前);至今共发布 98 个版本,其中过去 12 个月发布了 7 个;首次发布于 2019/05/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。