@financial-times/o-visual-effects

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

Provides visual effects through SCSS mixins, such as shadows and animations

原始使用文档
文档目录8 节
  1. Usage
  2. Markup
  3. CSS Custom Properties
  4. Sass
  5. Shadows mixin
  6. Migration guide
  7. Contact
  8. Licence

o-visual-effects

This Origami component provides CSS visual effects via a set of Sass variables and mixins.

Usage

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

Markup

o-visual-effects provides helper classes to style with different levels of box shadow:

  • .o-visual-effects-shadow-ultralow
  • .o-visual-effects-shadow-low
  • .o-visual-effects-shadow-mid
  • .o-visual-effects-shadow-high
<div class="o-visual-effects-shadow-high">Box content</div>

o-visual-effects also provides timing functions for slide, expand, or fade animations and transitions as CSS custom properties (CSS Variables). Sass users may use Sass variables to apply these timing functions instead.

CSS Custom Properties

Build Service users may use CSS Custom Properties (CSS Variables) to apply consistent timing functions within custom CSS. The variables avalible are:

  • --o-visual-effects-timing-slide
  • --o-visual-effects-timing-expand
  • --o-visual-effects-timing-fade

E.g.

.transition--slide {
    transition: all 0.5s var(--o-visual-effects-timing-slide);
}

.transition--expand {
    transition: all 0.5s var(--o-visual-effects-timing-expand);
}

.transition--fade {
    transition: all 0.5s var(--o-visual-effects-timing-fade);
}

CSS Custom Properties (CSS Variables) are also available for shadows.

E.g.

.my-shadow {
    box-shadow: var(--o-visual-effects-shadow-high);
}

Sass

To include all o-visual-effects css call the oVisualEffects mixin. This will include box shadow styles and CSS custom properties for transition timing functions.

@include oVisualEffects();

o-visual-effects may also be output granularly. For example ommit the CSS custom properties if you are using Sass variables such as $o-visual-effects-timing-slide instead:

@include oVisualEffects(
    $opts: (
        'shadows': (
            'ultralow',
            'low',
            'mid',
            'high',
        ),
    )
);

If you are not using o-visual-effects CSS, and instead are using other Sass mixins or variables directly there is no need to call oVisualEffects.

Shadows mixin

The oVisualEffectsShadowContent mixin is used to add a consistent shadow to your element. There are 4 levels of shadow available: ultralow, low (default), mid, and high.

Example:

.my-element {
    @include oVisualEffectsShadowContent('mid');
}

Output:

.my-element {
    box-shadow: 0 1px 3px rgba(77, 72, 69, 0.2), 0 6px 10px rgba(77, 72, 69, 0.15);
}

Transition variables

When adding transitions to elements in CSS, you should use o-visual-effects variables for consistent timings for slide, expand, and fade effects.

Example:

.transition--slide {
    transition: all 0.5s $o-visual-effects-timing-slide;
}

.transition--expand {
    transition: all 0.5s $o-visual-effects-timing-expand;
}

.transition--fade {
    transition: all 0.5s $o-visual-effects-timing-fade;
}

Output:

.transition--slide {
    transition: all 0.5s cubic-bezier(1, 0, 0.5, 1.275);
}

.transition--expand {
    transition: all 0.5s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.transition--fade {
    transition: all 0.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}

Migration guide

StateMajor VersionLast Minor ReleaseMigration guide
⚠ maintained5N/Amigrate to v5
╳ deprecated44.2migrate to v4
╳ deprecated33.0migrate 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-visual-effects 共发布 24 个版本,首次发布于 2019/02/13;过去 12 个月发布了 1 个版本。

版本发布日期距今
5.0.2latest2026/02/268 个月前
5.0.12025/02/271.7 年前
5.0.02025/02/211.7 年前
4.2.22023/10/273 年前
4.2.12023/04/283 年前
4.2.02022/02/154 年前

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

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

@financial-times/o-visual-effects 是什么?

Provides visual effects through SCSS mixins, such as shadows and animations

如何安装 @financial-times/o-visual-effects?

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

@financial-times/o-visual-effects 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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