@financial-times/x-teaser

中文文档
21.1.1发布于 2026/09/16ISCTypeScriptESM + CJS近 30 天下载 4532

This module provides templates for use with o-teaser. Teasers are used to present content.

原始使用文档
文档目录10 节
  1. Installation
  2. Concepts
  3. Features
  4. Indicators
  5. Rules
  6. Usage
  7. Child components
  8. TypeScript
  9. Properties
  10. Presets

x-teaser

This module provides templates for use with o-teaser. Teasers are used to present content.

Installation

npm install --save @financial-times/x-teaser @financial-times/o-teaser

The x-engine module is used to inject your chosen runtime into the component. Please read the x-engine documentation first if you are consuming x- components for the first time in your application.

Concepts

Features

Because teasers are very complex with thousands of possible permutations the component has been split into logical groups of features. These are:-

  • Meta, the element above the title categorising the content
  • Title, the title of the content
  • Standfirst, a subtitle or description of the content
  • Status, the date of, or time since the content was published
  • Related links, An additional list of links to related content
  • Image, the poster image for the content
  • Headshot, an image of the content author when content is published in their column
  • Video, for video content able to play videos in-situ
  • Custom slot, a free slot to insert custom components or markup
  • Promotional content, a slot to insert promotional content of different types such as but not limited to: clips, interactive graphics, etc.

screenshot of a teaser with features highlighted

Indicators

Teasers display content but our content items are also decorated with hints and traits which further describe them. Content items may only be available to premium subscribers, excluded from syndication licenses, or selected as an editor's choice. This extra data may not always produce visible output, or be visible to all users. However, they can be used in addition to the content itself to make decisions with.

Rules

Because there are so many teaser properties some options can conflict. In these cases one option must take precedence over the others. These sitations are resolved by using a ruleset. A ruleset is a function which implements a series of conditions in order of precedence. When a condition evaluates to true it must return.

For example to decide which media type to display (a video, headshot, or image) we define the following ruleset:

const media = (props) => {
  if (props.showVideo && props.video && props.video.url) {
    return 'video'
  }

  if (props.showHeadshot && props.headshot && props.headshot.url && props.indicators.isColumn) {
    return 'headshot'
  }

  if (props.showImage && props.image && props.image.url) {
    return 'image'
  }
}

Usage

The components provided by this module are all functions that expect a map of teaser properties. They can be used with vanilla JavaScript or JSX (If you are not familiar check out WTF is JSX first). For example if you were writing your application using React you could use the component like this:

import React from 'react'
import { Teaser } from '@financial-times/x-teaser'

// A == B == C
const a = Teaser(props)
const b = <Teaser {...props} />
const c = React.createElement(Teaser, props)

All x- components are designed to be compatible with a variety of runtimes, not just React. Check out the x-engine documentation for a list of recommended libraries and frameworks.

Child components

All the sub-components used to build a complete teaser may be imported and used individually. Every component can be given the full set of teaser properties.

import { Title, Standfirst } from '@financial-times/x-teaser'

const TeaserIsh = (title, standfirst) => (
  <div className="teaser-ish">
    <Title title={title} />
    <Standfirst standfirst={standfirst} />
  </div>
)

TypeScript

A TypeScript definitions file is included which covers all of the properties expected by this component. You can use it like this:

import { TeaserProps } from './Props'

const props: TeaserProps = {}

Properties

As covered in the features documentation the teaser properties, or props, have also been split into logical groups. No props are mandatory and no defaults are set, but presets are available for common combinations. In cases where props conflict rules should decide which should take precedence. There is a TypeScript definition available for props.

Feature Props

FeatureTypeNotes
showMetaBoolean
showTitleBoolean
showTitlePrefixBoolean
showStandfirstBoolean
showPremiumLabelBoolean
showExclusiveLabelBoolean
showStatusBoolean
showImageBoolean
showBylineBooleanTakes precedence over headshot
showBylineHeadshotBoolean
showHeadshotBooleanTakes precedence over image
showVideoBooleanTakes precedence over image or headshot
showGuidanceBooleanShow video captions guidance
showRelatedLinksBoolean
showCustomSlotBoolean
showPromotionalContentBoolean

General Props

PropertyTypeNotes
idStringContent UUID
urlStringCanonical URL
relativeUrlStringURL path, will take precendence over url
typeStringContent type (article, video, etc.)
indicatorsindicators
dataTrackableStringTracking data for the teaser

Meta Props

PropertyTypeNotes
metaPrefixTextStringDeprecated. When metaLinks property is present, this text is not displayed in the tag. It is being phased out in favour of titlePrefix, which will be used more sparingly
metaSuffixTextString
metaLinkmeta linkDeprecated - use metaLinks property instead
metaAltLinkmeta linkDeprecated - use metaLinks property instead
metaLinksArray of [ string, string ]Array of [linkText, relativeUrl]
promotedPrefixTextStringWill take precedence over links
promotedSuffixTextString

Title Props

PropertyTypeNotes
titleString
titlePrefixString
altTitle.StringUsed for testing content variations

Standfirst Props

PropertyTypeNotes
standfirstString
altStandfirstStringUsed for testing content variations

Status Props

PropertyTypeNotes
publishedDateString, Number, DateLast published date
firstPublishedDateString, Number, Date
useRelativeTimeBooleanDisplay time since publish
statusStringLive blog status

Image Props

PropertyTypeNotes
imagemedia
imageSizeStringXS, Small, Medium, Large, XL or XXL
imageLazyLoadBoolean, StringOutput image with data-src attribute. If this is a string it will be appended to the image as a class name.
imageHighestQualityBooleanCalls image service with "quality=highest" option, works only with XXL images
imageOptionsObjectCalls Image Service with specified props, takes precedence over other image options such as imageSize and imageHighestQuality

Byline Props

PropertyTypeNotes
bylineArray of [string, string(optional), string(optional)][text, relativeUrl, headshotUrl][]

Headshot Props

PropertyTypeNotes
headshotStringOnly displayed if showHeadshot and columnist indicator is true
headshotTintStringSee the image service API for usage

Video Props

PropertyTypeNotes
videomediaRequires o-video to create a video player
systemCodeStringRequired by o-video to pass with requests.
Should be the Biz-Ops code for the implementing system
PropertyTypeNotes
relatedLinksArray of link

Context Props

PropertyTypeNotes
headlineTestingBooleanEnables alternative content for headline testing
parentLabelStringShows the alternative meta link when the label matches
parentIdStringShows the alternative meta link when the ID matches

Variant Props

PropertyTypeNotes
layoutString"small", "large", "hero", or "top-story"
themeStringPackage theme, setting this will override any other indicators
parentThemeStringTheme inherited from any parent package
modifiersString[]Extra modifier class names to append
PropertyTypeNotes
prefLabelString
urlStringCanonical URL
relativeUrlStringURL path, will take precedence over url
PropertyTypeNotes
idStringContent UUID
urlStringCanonical URL
relativeUrlStringURL path, will take precedence over url
typeStringContent type (article, video, etc.)
titleString

Media Props

PropertyTypeNotes
urlStringContent UUID or, in the case of images, data: or blob: URL
widthNumber
heightNumber

Indicator Props

PropertyTypeNotes
accessLevelString"premium", "subscribed", "registered", or "free"
isOpinionBoolean
isColumnBoolean
isPodcastBoolean
isEditorsChoiceBoolean
isExclusiveBooleanControls whether the Exclusive badge is displayed
isScoopBoolean

Special Styling Props

PropertyTypeNotes
allowLiveTeaserStylingBooleanApply o-teaser--live class to Container. :memo: Consumers need to include the o-teaser styling in their applications too.

Presets

Because there are so many options presets are available for the most commonly used configurations, these are:-

  • Small
  • SmallHeavy
  • Large
  • Hero
  • HeroNarrow
  • HeroVideo
  • HeroOverlay
  • TopStory
  • TopStoryLandscape

To use a preset import the presets property along with the teaser component and mix your chosen preset in with your other properties.

import { Teaser, presets } from '@financial-times/x-teaser'

const html = Teaser({ ...props, ...presets.Hero, showStatus: false })

版本与发布记录

@financial-times/x-teaser 共发布 205 个版本,首次发布于 2018/04/12;过去 12 个月发布了 13 个版本。

版本发布日期距今
21.1.1latest2026/09/161 个月前
21.1.02026/04/246 个月前
21.0.02026/03/317 个月前
21.0.0-beta.12026/03/317 个月前
20.0.12026/03/138 个月前
20.0.02026/03/048 个月前

其他发布通道:next → 1.0.0-1,pre-release → 0.2.1-alpha.2,pre-origami → 1.0.0-beta.24。

关于 @financial-times/x-teaser 的常见问题

@financial-times/x-teaser 是什么?

This module provides templates for use with o-teaser. Teasers are used to present content.

如何安装 @financial-times/x-teaser?

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

@financial-times/x-teaser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@financial-times/x-teaser 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@financial-times/x-teaser 需要什么版本的 Node.js?

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

@financial-times/x-teaser 可以商用吗?

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

@financial-times/x-teaser 的下载量有多少?

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

@financial-times/x-teaser 还在维护吗?

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