@financial-times/o-brand

中文文档
4.2.4发布于 2026/02/26MITES Module零依赖近 30 天下载 1.4万

用于"品牌"其他"Origami"组件的工具.

中文使用文档
文档目录14 节
  1. 术语
  2. 品牌
  3. 备选案文
  4. 使用量
  5. 萨斯
  6. 红宝石
  7. brand获得当前
  8. 红外线防御
  9. 红外线
  10. brand 支持软件
  11. 澳洲海关
  12. 移徙
  13. 联系人
  14. 许可证

○-品牌

用于调整Origami组件以用于不同用途的工具.

术语

品牌

品牌代表一种要求组件提供独特外观或独特功能的环境. 品牌可能被视为一个主题,但品牌组件可以提供独特的特征以及独特的外观.

品牌包括:

  • 核心:面向公共ft.com网站和子公司的FT品牌.
  • 内部:适合内部产品、工具和文档的样式.
  • 白色标签:基,结构样式仅.

说明: "主人"的品牌已经贬值了,取而代之的是"核心"品牌.

备选案文

一个变体是给定品牌内某个组件的添加或修改. 备选案文 必须 具有可选性,并基于充分功能的组成部分。 例如:按钮组件可能具有"反"变体,"大"变体等. 一个头部组件可能有一个"子导航"变体,一个"粘"变体等.

使用量

非奥利加米项目不得依赖 o-brand 直接说.

非奥里加米项目不得依赖 o-brand 直接说 检查出来 如何将 Origami 组件纳入您的项目 开始使用 Origami 组件。 如果你愿意学习如何开发一个有品牌的 Origami 组件 创建 Origami 组件教程 显示如何使用 o-brand 用于构建可定制组件.

萨斯

内部混合 o-brand 帮助配置支持品牌的组件。 没有配置在 o-brand它为部件应用自己的品牌支持提供了机制。 消费Origami品牌组件的项目可通过设置品牌来选择一个品牌 $o-brand 变量.

以下组合和功能有助于品牌组件.

红宝石

此功能会检查当前使用的品牌是否是给定的品牌.

$o-brand: internal; // Defined in the product using branded Origami components.

$chosen-brand: oBrandIs('internal'); // true
$chosen-brand: oBrandIs('core'); // false

brand获得当前

此函数返回当前品牌, 如果没有设置则返回默认品牌 .

$o-brand: internal; // Defined in the product using branded Origami components.

$chosen-brand: oBrandGetCurrent('internal'); // internal

红外线防御

组件各自负责为其支持的每个品牌确定配置. 为了添加新品牌的配置, 请使用混音 oBrandDefine。 。 。 .

何处 $component 是组件的名称; $brand 属于“核心”、“内部”或“白色标签”;以及 $config 由变量和辅助变量组成的地图:

@if oBrandIs('core') {
    @include oBrandDefine($component, $brand, $config);
}

说明: oBrandDefine 应结合 oBrandIs,只定义请求的品牌.

品牌变量

品牌变量为品牌配置组件. 例如,一个构成部分 o-example 可能定义变量 example-background 来配置其背景颜色.

$variables: (
    example-background: 'paper'
);

嵌入式映射会配置一个变体,这个变体可能为已存在的变量提供新的变量或不同的值. 例如 inverse 对变量有不同值的变量 example-background数字 :

$variables: (
    example-background: 'paper',
    'inverse': (
        example-background: 'slate'
    )
);
  • 变量名称 必须 是一个字符串,应该为字母数字,包括破折号等. example-background。 。 。 .
  • 变量名称 不应该 完全匹配 css 属性,例如. example-background 结束 background。 。 。 .
  • 一个变体 必须 成为数字字符串例如. inverse, (中文(简体) ), b2b-inverse。 。 。 .

支持的备选案文

要表示品牌应支持一个变体,请将变体名称添加到 supports-variants 列表中选择一个选项.

例如,要配置对"反"和"b2b"变体的支持:

$supports-variants: (
    'inverse',
    'b2b'
);

然后可以使用 brand 支持软件。 。 。 .

内容 oBrandDefine 示例

以下示例定义了 core 用于组件的品牌 o-example我们定义了四个变量,包括: example-background但我们提供不同的 example-background 数值 inverse 财务报告和审定财务报表 b2b 变相. 使用 supports-variants 我们明确列出 core 品牌支持这两个变体.

@if oBrandIs('core') {
    @include oBrandDefine('o-example', 'core', (
        'variables': (
            example-background: 'paper',
            example-border-width: 1px,
            example-border-type: solid,
            example-border-type: grey,
            'inverse': (
                example-background: 'slate'
            )
            'b2b': (
                example-background: 'lightblue'
            )
        ),
        'supports-variants': (
            'inverse',
            'b2b'
        )
    ));
}

红外线

使用 oBrandGet 获取一个品牌变量。 首先创建一个私有的, 组件- spectifc 函数来调用 oBrandGet,例如,一个组件 o-example创建 _oExampleGet数字 :

/// Helper for `o-brand` function.
/// @access private
@function _oExampleGet($variables, $from: null) {
    @return oBrandGet($component: 'o-example', $variables: $variables, $from: $from);
}

您的新组件 spectifc 函数 _oExampleGet 然后可用于获取变量。 例如,在《公约》的基础上 oBrandDefine 示例:

.o-example {
    background: _oExampleGet($variables: 'example-background'); // background: paper;
}

可以要求多个变量:

.o-example {
    border: _oExampleGet($variables: ('example-border-width', 'example-border-type', 'example-border-color')); // border: 1px solid grey;
}

要获取变量用于变量,请使用 $from 参数 :

.o-example--inverse {
    background: _oExampleGet($variables: 'example-background', $from: 'inverse'); // background: slate;
}

这个 $from 参数还接受自定义变体 :

$custom-variant: (
    'example-background': 'hotpink',
    'example-border-width', '2px'
);

.o-example--custom {
    background: _oExampleGet($variables: 'example-background', $from: $custom-variant); // background: hotpink;
    border-width: _oExampleGet($variables: 'example-border-width', $from: $custom-variant); // border-width: 2px;
}
  • oBrandGet 返回时 null 如果变量未定义。 Sass去除设置为的 Css 属性 null。这是对不同变体有条件输出 css 属性的有用特性.

brand 支持软件

检查一个品牌是否支持变种调用 oBrandSupportsVariant。首先创建用于包接 oBrandSupportsVariant,例如,一个组件 o-example创建 _oExampleSupports数字 :

/// Helper for `o-brand` function.
/// @access private
@function _oExampleSupports($variant) {
    @return oBrandSupportsVariant($component: 'o-example', $variant: $variant);
}

那就调用您的新功能 _oExampleSupports 以确定是否为变体输出 CSS。 例如,只输出 inverse 如果品牌支持它,则变体:

@if _oExampleSupports($variant: 'inverse') {
    .o-example--inverse {
        background: _oExampleGet($variables: 'example-background', $from: 'inverse'); // background: slate;
    }
}

澳洲海关

oBrandCustomize 允许修改现有的品牌变量,只要这些变量已经用 oBrandDefine。这种自定义是特定组件的,所以品牌组件必须包起来 oBrandCustomize 在自己的混合体中 o-brand 不得在Origami组件外直接使用.

示例组件(实例):

/// Create a component-specific mixin to wrap `oBrandCustomize`.
@mixin oExampleCustomize($variables) {
    @include oBrandCustomize('o-example', $variables);
}

// Define the whitelabel brand for the component.
@if oBrandIs('whitelabel') {
    @include oBrandDefine('o-example', 'whitelabel', (
        'variables': (
            example-background: white,
            example-color: black,
        ),
        'supports-variants': ()
    ));
}

示例项目:

$o-brand: 'whitelabel';
@import '@financial-times/o-table';

// Customise the example component.
// Here we change the variable "example-background" from "white" to "lightblue".
// The "example-color" variable has not been customised so remains "black".
@include oExampleCustomize((
    example-background: lightblue
));

// Output the example component CSS.
@include oExample();

移徙

状态主要版本最后一个小版本移徙指南
活动页:1不详迁移到 v4
维护3个3.2 国家迁移到 v3
维护2个2.4 国家迁移到 v2
已贬值1个1.1 国家不详

联系人

如果您对本部分有任何问题或评论,或需要帮助使用本部分,请 提出问题访问 {\fn黑体\fs20\shad2\2ah82\3ah20\4ah33\fscx95\3ch592001\be1}#毛发折射 或电子邮件 折纸支持。 。 。 .

许可证

本软件由金融时报根据以下规定出版: 麻省理工学院许可证。 。 。 .

版本与发布记录

@financial-times/o-brand 共发布 23 个版本,首次发布于 2019/02/12;过去 12 个月发布了 1 个版本。

版本发布日期距今
4.2.4latest2026/02/268 个月前
4.2.32025/02/251.7 年前
4.2.22023/10/273 年前
4.2.12022/01/134 年前
4.2.02021/11/254 年前
4.1.02021/11/095 年前

其他发布通道:tag--v3.3.0 → 3.3.0,prerelease → 4.0.0-beta.1。

关于 @financial-times/o-brand 的常见问题

@financial-times/o-brand 是什么?

用于"品牌"其他"Origami"组件的工具.

如何安装 @financial-times/o-brand?

在项目目录运行 npm install @financial-times/o-brand,或使用 pnpm add / yarn add / bun add。

@financial-times/o-brand 支持 TypeScript 吗?

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

@financial-times/o-brand 支持 ESM 还是 CommonJS?

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

@financial-times/o-brand 可以商用吗?

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

@financial-times/o-brand 的下载量有多少?

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

@financial-times/o-brand 还在维护吗?

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