14.7.4 • Published 2 days ago

@financial-times/x-teaser v14.7.4

Weekly downloads
524
License
ISC
Repository
github
Last release
2 days ago

x-teaser

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

Installation

This module is supported on Node 12 and is distributed on npm.

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
showStandfirstBoolean
showStatusBoolean
showImageBoolean
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
metaPrefixTextString
metaSuffixTextString
metaLinkmeta link
metaAltLinkmeta link
promotedPrefixTextStringWill take precedence over links
promotedSuffixTextString

Title Props

PropertyTypeNotes
titleString
altTitleStringUsed 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

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

Related Links Props

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

Meta Link Props

PropertyTypeNotes
prefLabelString
urlStringCanonical URL
relativeUrlStringURL path, will take precedence over url

Link Props

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
isExclusiveBoolean
isScoopBoolean

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 })
14.7.4

2 days ago

14.7.3

8 days ago

14.7.2

23 days ago

14.7.1

1 month ago

14.6.5

1 month ago

14.7.0

1 month ago

14.6.3

2 months ago

14.6.4

2 months ago

14.6.2

2 months ago

14.6.0

2 months ago

14.6.1

2 months ago

14.5.2

3 months ago

14.5.0

3 months ago

14.5.1

3 months ago

14.4.2

3 months ago

14.4.1

4 months ago

14.4.0

4 months ago

14.3.1

4 months ago

14.3.0

4 months ago

14.2.0

5 months ago

14.1.0

6 months ago

14.1.1

6 months ago

14.1.2

6 months ago

12.0.0

10 months ago

12.0.1

10 months ago

12.0.2

9 months ago

11.2.0

11 months ago

13.0.0

9 months ago

13.0.1

9 months ago

12.0.0-beta.2

11 months ago

12.0.0-beta.3

11 months ago

12.0.0-beta.1

11 months ago

12.0.1-beta.1

11 months ago

14.0.0

9 months ago

14.0.1

8 months ago

14.0.2

8 months ago

14.0.3

8 months ago

14.0.4

7 months ago

11.1.1

12 months ago

11.1.2

11 months ago

11.1.0

12 months ago

10.4.0

1 year ago

11.0.0

1 year ago

10.5.0

1 year ago

10.3.0

1 year ago

10.0.0

1 year ago

10.2.0

1 year ago

10.1.0

1 year ago

10.1.1

1 year ago

10.1.2

1 year ago

8.2.3

1 year ago

8.2.2

2 years ago

8.2.5

1 year ago

8.2.4

1 year ago

8.1.1

2 years ago

8.2.1

2 years ago

8.2.0

2 years ago

8.1.0

2 years ago

8.0.5

2 years ago

8.0.4

2 years ago

8.0.6

2 years ago

8.0.3

2 years ago

8.0.2

2 years ago

6.8.2-beta.1

2 years ago

8.0.1

2 years ago

8.0.1-beta.1

2 years ago

7.0.0

2 years ago

6.8.1

2 years ago

8.0.0

2 years ago

6.6.0

2 years ago

6.7.1

2 years ago

6.3.1

2 years ago

6.8.0

2 years ago

6.4.1

2 years ago

6.2.12

2 years ago

6.3.0

2 years ago

6.2.10

2 years ago

6.2.11

2 years ago

6.2.7

3 years ago

6.2.9

3 years ago

6.2.8

3 years ago

6.2.5

3 years ago

6.2.6

3 years ago

6.2.4

3 years ago

6.2.3

3 years ago

6.2.2

3 years ago

4.1.5

3 years ago

6.2.1

3 years ago

6.2.0

3 years ago

6.1.0

3 years ago

6.0.0

3 years ago

5.2.0

3 years ago

5.1.0

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.1.4

3 years ago

4.1.3

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.1.0

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

2.0.6

3 years ago

2.0.5

4 years ago

2.0.2

4 years ago

1.7.0

4 years ago

1.6.9

4 years ago

1.6.8

4 years ago

1.6.7

4 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.4

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.0-beta.24

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta.23

4 years ago

1.0.0-beta.22

4 years ago

1.0.0-beta.21

5 years ago

1.0.0-beta.20

5 years ago

1.0.0-beta.19

5 years ago

1.0.0-beta.18

5 years ago

1.0.0-beta.17

5 years ago

1.0.0-beta.16

5 years ago

1.0.0-beta.15

5 years ago

1.0.0-beta.14

5 years ago

1.0.0-beta.13

5 years ago

0.2.1-alpha.2

5 years ago

0.2.0-alpha.1

5 years ago

1.0.0-beta.12

5 years ago

1.0.0-beta.11

5 years ago

1.0.0-beta.10

5 years ago

1.0.0-beta.9

5 years ago

1.0.0-beta.8

5 years ago

1.0.0-beta.7

5 years ago

1.0.0-beta.6

6 years ago

1.0.0-beta.5

6 years ago

1.0.0-beta.4

6 years ago

1.0.0-beta.3

6 years ago

1.0.0-beta.2

6 years ago

1.0.0-beta.1

6 years ago

1.0.0-6

6 years ago

1.0.0-5

6 years ago

1.0.0-4

6 years ago

1.0.0-3

6 years ago

1.0.0-1

6 years ago