Skip to content

Commit

Permalink
refactor: improve banner component structure
Browse files Browse the repository at this point in the history
  • Loading branch information
robherba committed Nov 11, 2024
1 parent 68ff0c9 commit d7c68d0
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 216 deletions.
72 changes: 16 additions & 56 deletions src/components/banner/banner.component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,38 @@ status: stable
props:
type: object
required:
- banner__title
- banner__content
- banner__button__content
- banner__button__url
- banner__heading
- banner__text
properties:
banner__title:
banner__heading:
type: string
title: Title
description: 'Specifies the title of the banner'
data: 'This is the banner title'
banner__content:
data: 'THIS IS A BANNER HEADING'
banner__text:
type: string
title: Content
description: 'Specifies the main content of the banner'
data: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
banner__button__content:
data: '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>'
banner__link:
type: string
title: Button Content
description: 'Specifies the text displayed on the button'
data: 'Learn More'
banner__button__url:
type: string
title: Button URL
description: 'Specifies the URL the button will link to'
data: '#'
banner__image__src:
title: Link Content
description: 'Specifies the text displayed on the link'
data: 'this is a link'
banner__image:
type: string
title: Image's source
description: The image's source of the banner.
data: 'https://placehold.co/400'
banner__image__alt:
type: string
title: Image's alternative text
description: The image's alternative text of the banner.
data: 'This is the card image alt text'
data: 'https://picsum.photos/1480/360'
banner__video:
type: string
title: Video URL
description: 'Specifies the URL of the video to be displayed. Either this or banner__image should be provided.'
data: ''
data:
- 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4'
- 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-webm-file.webm'
banner__alignment:
type: string
title: Alignment
description: 'Specifies the alignment of the content within the banner. Options include: left, center, right.'
enum:
- left
- center
data: 'center'
example:
- banner__title: 'THIS IS A BANNER HEADING'
banner__content: '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>'
banner__button__content: 'this is a link'
banner__button__url: '#'
banner__image__src: 'https://picsum.photos/890/215'
banner__image__alt: "This is the banner image's alt text"
- banner__title: 'THIS IS A BANNER HEADING'
banner__content: '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>'
banner__button__content: 'this is a link'
banner__button__url: '#'
banner__videos:
- 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4'
- 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-webm-file.webm'
- banner__title: 'THIS IS A BANNER HEADING'
banner__content: '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>'
banner__button__content: 'this is a link'
banner__button__url: '#'
banner__image__src: 'https://picsum.photos/890/215'
banner__image__alt: "This is the banner image's alt text"
banner__alignment: 'center'
- banner__title: 'THIS IS A BANNER HEADING'
banner__content: '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>'
banner__button__content: 'this is a link'
banner__button__url: '#'
banner__videos: ''
banner__alignment: 'center'
data: 'left'
124 changes: 53 additions & 71 deletions src/components/banner/banner.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,124 +18,106 @@
}

.banner {
z-index: 1;
min-height: 16rem;
position: relative;
}

.banner__image {
width: 100%;
height: 100%;
position: absolute;
.banner__media {
@include overlay-darken;

&:is(div) {
@include overlay-darken;
& {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-size: cover;
z-index: 0;
}

&:is(img) {
z-index: 1;
img {
width: 100%;
height: 100%;
object-fit: cover;
}
}

.banner__video-container {
width: 100%;
height: 100%;
max-width: 100%;
position: absolute;
}
.banner__video {
@include overlay-darken;

.banner__video-container {
&::before {
content: '';
& {
position: absolute;
top: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100%;
opacity: 0.75;
display: block;
position: absolute;
pointer-events: none;
mix-blend-mode: multiply;
background-color: var(--color-primary-dark);
object-fit: cover;
z-index: 0;
}
}

.banner__video {
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
position: absolute;
video {
width: 100%;
height: 100%;
object-fit: cover;
}
}

.banner__video-controls {
z-index: 3;
.banner__playback {
z-index: 5;
position: absolute;
bottom: var(--spacing-xl);
right: var(--spacing-xl);
}

.banner__toggle {
cursor: pointer;
border-radius: 50%;
width: var(--spacing-xl);
height: var(--spacing-xl);
border: 3px solid var(--color-white);
background-color: var(--color-primary-lighter);

svg {
width: 100%;
height: 100%;
}
}

.banner__content {
z-index: 2;
width: 100%;
display: flex;
position: relative;
flex-direction: column;
color: var(--color-white);
padding: var(--spacing-2xl) var(--spacing-xl);
row-gap: var(--spacing-xl);
padding: var(--spacing-2xl) 0;

.heading {
@include h2;
[data-banner-alignment='center'] & {
align-items: center;
}
}

margin: 0 0 calc(var(--spacing-lg) * 1.5);
.banner__heading {
@include h2;

& {
margin: 0;
}
}

.banner__text {
@include h5;

& {
font-weight: initial;
margin: 0;
}

p {
margin: 0 0 var(--spacing-lg);
font-size: var(--font-size-h5);

&:is(p:last-child) {
&:last-child {
margin-bottom: 0;
}
}
}

.banner__action {
margin: var(--spacing-xl) 0 0;

.button,
.button:hover,
.button:focus {
color: var(--color-black);
font-size: var(--font-size-small);
border-color: var(--color-primary-lighter);
background-color: var(--color-primary-lighter);
}
.banner__links {
display: flex;
flex-direction: row;
row-gap: var(--spacing);
}

.banner-list {
display: flex;
flex-direction: column;
row-gap: var(--spacing-xl);
}

/* Variants -- Content centered */
.banner__content--center {
align-items: center;
margin: var(--spacing-lg) 0;
}
67 changes: 58 additions & 9 deletions src/components/banner/banner.stories.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
import bannerTwig from './banner.twig';
import { props } from './banner.component.yml';

import './banner';
import '../video/playback';

const bannerData = props.properties;

export default {
title: 'Components/Banner',
decorators: [
(story) =>
`<div style="max-width: 890px; margin: 0 auto;">${story()}</div>`,
],
argTypes: {
type: {
name: 'Media Type',
control: { type: 'select' },
options: {
Image: 'image',
Video: 'video',
},
},
alignment: {
name: 'Banner Alignment',
type: 'select',
options: {
'Left': 'left',
'Center': 'center',
},
},
heading: {
name: 'Banner Heading',
type: 'string',
},
text: {
name: 'Banner Text',
type: 'string',
},
link: {
name: 'Banner Link',
type: 'string',
},
},
args: {
type: 'image',
alignment: bannerData.banner__alignment.data,
heading: bannerData.banner__heading.data,
text: bannerData.banner__text.data,
link: bannerData.banner__link.data,
},
};

export const Banner = () =>
`<div class="banner-list">${props.example
.map((data) => bannerTwig(data))
.join('')}</div>`;
export const Banner = ({
type,
alignment,
heading,
text,
link,
}) => bannerTwig({
banner__image: bannerData.banner__image.data,
banner__video: bannerData.banner__video.data,
banner__media: type,
banner__alignment: alignment,
banner__heading: heading,
banner__text: text,
banner__link_items: [{
url: '#',
content: link,
}]
});
Loading

0 comments on commit d7c68d0

Please sign in to comment.