50/50 Component
The 50/50 is a more complex component because it contains more fields, logic and it also makes use of previously built components. With the 50/50 Teaser we will reuse other components by using Twig's include statements. More on this later.
Whether you are building simple or complex components, the process for getting started is the same; create files for data, markup and styles. Let's do this with the 50/50 component.
First let's take a look at how this component looks so we can identify the different data fields we need.

Based on the design above, we need the following fields:
Image
Eyebrow
Title or heading
Summary
Call to action (CTA)
Exercise: Build the 50/50 teaser component
Component's stock content
Delete the existing "teaser" folder inside of components (we are going to recreate it from scratch!)
Inside components create a new folder called teaser
Inside the teaser folder create a new file called teaser.stories.js
Inside teaser.json add the following code:
export const Left = TeaserTemplate.bind({});
Left.args = {
"title": 'News Title',
'eyebrow': 'Eyebrow',
"image": "<img src='https://via.placeholder.com/800x600.png' class='img-fluid rounded' alt='Placeholder' />",
"summary": 'Contra legem facit qui id facit quod lex prohibet. Nec dubitamus multa iter quae et nos invenerat. Praeterea iter est quasdam res quas ex communi. Lorem ipsum dolor sit amet, consectetur adipisici elit.',
"link": {
"url": "#",
"text":"Read More",
"modifier": "btn-primary"
},
"layout": "left",
"modifier": "container-fluid rounded",
};
export const Right = TeaserTemplate.bind({});
Right.args = {
"title": 'News Title',
'eyebrow': 'Eyebrow',
"image": "<img src='https://via.placeholder.com/800x600.png' class='img-fluid rounded' alt='Placeholder' />",
"summary": 'Contra legem facit qui id facit quod lex prohibet. Nec dubitamus multa iter quae et nos invenerat. Praeterea iter est quasdam res quas ex communi. Lorem ipsum dolor sit amet, consectetur adipisici elit.',
"link": {
"url": "#",
"text":"Read More",
"modifier": "btn-primary"
},
"layout": "right",
"modifier": "container-fluid rounded",
};
Similar to the previous example involving the basic component, we are employing JavaScript to import files, specify the arguments of the component, and incorporate stock or dummy content into it. Our objective in this case is to enhance code efficiency and facilitate maintenance by nesting pre-existing components within the 50/50 teaser. By doing so, we can avoid code duplication and establish a single source of code for improved component management.
Component's Markup
Now let's write some HTML for the component.
Inside the teaser folder create a new file called teaser.twig
Inside
teaser.twigadd the following code:
Some things to notice:
We are using the Bootstrap row and col classes to arrange our content into columns. Bootstrap also lets us specify specific breakpoint classes (e.g. col-lg-6) for our column sizes.
We have added a conditional for the direction of the image and copy:
{{ layout == 'right' ? 'flex-lg-row-reverse' : 'flex-lg-row' }}. Bootstrap has a class that easily allows us to reverse the direction of our columns.Lastly, and most important, we make use of Twig's
includestatement to include or nest the Badge, Heading and Button components into the 50/50 teaser. This is extremely powerful and we will be talking more about it later. Biggest benefit of include statements is that we can reuse other components to avoid duplicating code.
Component's styles
Inside the teaser folder create a new file called teaser.scss
Inside
teaser.scssadd this code:
Notice how little CSS we have added, thanks to Bootstrap's built-in classes. We are importing the card stylesheet which is used by our 50/50 component. The only change we have made here is to make the teaser image stretch as a 'cover.'
Compiling the code
If Storybook is running you should see the Teaser component in Storybook under the Editorial category on the left side. Otherwise run the command below:
npm run storybookIn your browser of choice open the following URL: http://localhost:6006/. This will open Storybook where you can find the 50/50 component under "Editorial."
Last updated