@financial-times/o-spacing

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

Maintain consistent spaces across components and projects in accordance to our baseline grid and design guidelines.

原始使用文档
文档目录16 节
  1. Usage
  2. Spaces
  3. Baseline
  4. Named Spaces
  5. Markup
  6. CSS Custom Properties
  7. Named Space Custom Properties
  8. Baseline Custom Property
  9. Sass
  10. Relative Units
  11. Named Space
  12. Baseline Space
  13. Custom Properties & Utility Classes
  14. Migration
  15. Contact
  16. Licence

⚠️ NOTE: o-spacing has been replaced with o3-foundation. Please see Migration Guide for steps to upgrade.

o-spacing

A styling utility component to aid projects and component with consistent spacing, according to the baseline grid within the design guidelines.

Usage

Check out how to include Origami components in your project to get started with o-spacing.

For Build Service users, o-spacing provides CSS classes for vertical space and CSS Custom Properties (CSS Variables) for other usecases. For Sass users o-spacing also provides a number of Sass functions and mixins for applying space to a project.

Spaces

Visual representation of spaces defined below.

The above illustration is taken from the UXD Sketch Toolkit.

Baseline

Our baseline grid defaults to 4px. Any multiple of this default may be applied to a project. We recommend using our named spaces for consistency.

Named Spaces

Named spaces are the sizes we use to layout a component or page consistently. Each space is based on the 4px baseline. Small sizes such as s1 or s2 are ideal for space within a component; use medium sizes m12 and m16 for related content on a page; and large sizes l18, l24 for separating distinct areas within a project.

namevalue
s14px
s28px
s312px
s416px
s624px
s832px
m1248px
m1664px
l1872px
l2496px

To apply named spaces see o-spacing markup and Sass documentation.

Markup

o-spacing provides utility classes to help space Origami components vertically within your project.

<!-- Add a 48px vertical margin between elements. -->
<div class='o-spacing-m12'></div>
<div class='o-spacing-m12'></div>

To apply spaces to other properties o-spacing provides CSS Custom Properties (CSS Variables).

CSS Custom Properties

Named Space Custom Properties

o-spacing outputs a CSS Custom Property (CSS Variable) for each named space. E.g. --o-spacing-s1. These may be used to apply spaces in custom CSS if your project supports CSS Custom Properties. This is particularly useful for Build Service users who do not have access to o-spacing's Sass functions.

.example {
    margin: var(--o-spacing-s1);
}

Baseline Custom Property

We recommend using a named space, but for more granular control a project may output any space which is a multiple of our baseline value. For users who do not have access to Sass, o-spacing outputs a --o-spacing-baseline CSS variable.

.example {
    padding: calc(var(--o-spacing-baseline) * 1); // A small padding (4px).
    margin-bottom: calc(var(--o-spacing-baseline) * 4); // A large space (16px).
}

Sass

Relative Units

For compatibility with existing Origami projects, o-spacing outputs px values by default. To use relative rem values, set $o-spacing-relative-units: true before importing @financial-times/o-spacing/main.

    $o-spacing-relative-units: true;

    .example {
        padding: oSpacingByName('s1');  // Small padding (0.24rem).
        margin-bottom: oSpacingByName('m12'); // Medium margin (3rem).
    }

If using o-typography set $o-typography-relative-units also.

Named Space

We recommend Sass users apply space to their project using the oSpacingByName function. It accepts a space name and returns a px value (or rem value, if relative units are enabled).

    .example {
        padding: oSpacingByName('s1');  // Small padding (4px).
        margin-bottom: oSpacingByName('m12'); // Medium margin (48px).
    }

Baseline Space

We recommend the use of named spaces, but any space that multiplies our baseline is allowed. To apply a multiple of the baseline value use oSpacingByIncrement. It accepts a value to multiply the baseline by and returns a px value (or rem value, if relative units are enabled).

    .example {
        margin-bottom: oSpacingByIncrement(4);
    }

Custom Properties & Utility Classes

We recommend users apply named spaces using the Sass function oSpacingByName, but Sass users may output all o-spacing CSS including utility classes and CSS custom properties using the oSpacing mixin.

@include oSpacing($opts: (
    'margin-bottom-utilities': true, // Output CSS classes such as `o-spacing-s1`
    'custom-properties': true // Output CSS variables
));

Migration

StateMajor VersionLast Minor ReleaseMigration guide
✨ activeo3N/Amigrate to Origami 3
⚠ maintained3N/Amigrate to v3
╳ deprecated22.1migrate to v2
╳ deprecated11.0N/A

Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #origami-support or email Origami Support.

Licence

This software is published by the Financial Times under the MIT licence.

版本与发布记录

@financial-times/o-spacing 共发布 22 个版本,首次发布于 2019/05/24;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.2.6latest2026/02/268 个月前
3.2.52023/10/273 年前
3.2.42023/08/253 年前
3.2.32023/04/283 年前
3.2.22022/12/213 年前
3.2.12022/01/134 年前

其他发布通道:prerelease → 3.0.0-beta.0。

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

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

Maintain consistent spaces across components and projects in accordance to our baseline grid and design guidelines.

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

在项目目录运行 npm install @financial-times/o-spacing,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@financial-times/math(^1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

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

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

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

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

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

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

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

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

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

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