Skip to main content

TextOnImageTeaser: React

An article teaser refers to a summary of a longer written news article. Its purpose is to entice readers and generate interest in the full article by offering a glimpse of the content's main points, intriguing information, or engaging elements. This pattern is called the Text On Image Teaser which shows a preview of the content’s main points on top of an image.

Installation

Before you can start using the @mediahuis/chameleon-react component, you’ll need to install it, for more information check: Getting started for developers.

With that done, you’re now ready to implement the component in your application.

import { TextOnImageTeaser } from '@mediahuis/chameleon-react';

export default function Example() {
return (
<TextOnImageTeaser
title="Title"
image={
<img
src="https://via.placeholder.com/150"
alt="placeholder"
width="150"
height="150"
/>
}
/>
);
}

Properties

PropertyTypeDefaultRequiredDescription
asElementType'article'NoAllows rendering the TextOnImageTeaser with a different HTML tag or a different custom component.
articleType'article' | 'video''article'NoThe type of article the teaser links to. This could add a visual indicator to the teaser, such as a play button.
dateTimeString-NoDateTime of the article, indicate when the teaser has been published. Should be in (ISO8601) notation.
dateTimeOptionsDateTimeOptionProps{}NoThe date and time formatting setting.
durationString-NoA property to indicate the duration of the media in the article, should there be any.
editorialLabelString-NoOptional label to display on the teaser to highlight current status or urgency, such as 'Breaking' or 'Live'.
editorialAnimationBoolean-NoActivates a pulsating animation typically used to indicate live content.
externalBoolean-NoIndicates that the teaser links to an external resource. This adds a visual indicator after the title.
fullHeightBoolean-NoDetermines the height of the teaser. If set to true, the Teaser's link will fill it's parent. This could be useful when vertically justifying.
imageElementType | ReactElement-NoThe image to be shown in the teaser.
imageOptionsUnknown{}NoOptions to add to the image, such as aspect-ratio. Aspect-ratio can also be a list of responsive values, so a teaser can have a different aspect-ratio on the screen size of your choice.
introductionString-NoIntroduction text to be shown in the teaser.
introductionOptionsIntroductionOptionProps{ hidden: false }NoOther options to add to introduction, such as clamping and show/hide on mq's.
labelString-NoLabel text to be shown in the teaser, above the title.
linkReactNode-YesYou can pass a simple URL as string, or you could supply your own component if you would like to add custom props to it (e.g. if you want to add target="_blank")
loadingBoolean-NoThe loading state of the teaser. Will show skeleton loader over the teaser.
prefixString-NoPrepend a prefix to the title.
premiumBoolean-NoAdds a visual indication that the teaser links to premium content.
size'sm' | 'md' | 'lg' | ResponsiveSize'sm'YesThe size of elements in the teaser (title, paddings, image size, ...). This can also be a list of responsive values, so a teaser can be small or large on the screen size of your choice.
subLabelString-NoSublabel text to be shown in the teaser, next to the label.
testIDsOmit{}NoTest IDs for automated testing.
titleString-YesThe title of the teaser.
titleTagName'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span''h2'NoThe HTML tag to be used for the title, this has no effect on styling, but is important for accessibility and SEO.

Responsive Properties

The following properties are responsive and can be customized for different screen sizes: size and imageOptions.aspectRatio. These can be used by passing an object for the property value, where the key is the screen size and the value is the property value for that screen size. Possible screensizes are xs, sm, md, lg and xl.

<TextOnImageTeaser
imageOptions={{
aspectRatio={{
xs: '1:1',
sm: '1:2',
md: '2:1',
lg: '16:9',
xl: '21:9',
}}
}}
size={{
xs: 'sm',
sm: 'md',
md: 'lg',
lg: 'sm',
xl: 'md',
}}
{...props}
/>

DateTimeOptions

The dateTimeOptions property is an object with configuration for the dateTime, like format, locale, timezone and position. This uses the DateTime component internally.

dateTimeOptions.position

This option takes two possible values: meta (the default) or taxonomy. This defines the location where the DateTime component is visually layed out on the teaser component.

IntroductionOptions

The introductionOptions property is an object with configuration for the introduction, like clamp (number of lines visible) and hidden (on which breakpoints to hide/show the introduction). The remaining options get spread over the introduction element.

In this example the introduction is clamped to 2 lines and only shows on xs and sm screens.

<TextOnImageTeaser
introductionOptions={{
clamp: 2,
hidden: {
xs: true,
sm: true,
md: false,
lg: false,
xl: false,
},
}},
{...props}
/>

ImageOptions

The imageOptions property is an object with configuration for the image, like aspectRatio and hidden (on which breakpoints to hide/show the image).

In this example the image has different aspect-ratio's on varying breakpoints and only shows on xs and sm screens.

<TextOnImageTeaser
imageOptions={{
aspectRatio={{
xs: '1:1',
sm: '1:2',
md: '2:1',
lg: '16:9',
xl: '21:9',
}},
hidden: {
xs: true,
sm: true,
md: false,
lg: false,
xl: false,
},
}},
{...props}
/>