-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GIVCAMP-307 | Stacked story hero variant (#251)
* Stacked story hero variant * hero headline sizes * Hero variant styles * Stretch image to full width * Optimize images; clean up * Add fallback hero bg color before a proper value is entered
- Loading branch information
1 parent
a831dc9
commit cec029a
Showing
8 changed files
with
249 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,3 @@ | ||
import { cnb } from 'cnbuilder'; | ||
|
||
export const root = 'relative'; | ||
|
||
export const imageCrops = { | ||
'1x1': '1200x1200', | ||
'2x1': '2000x1000', | ||
'3x2': '2100x1400', | ||
'5x8': '1000x1600', | ||
'16x9': '2000x1125', | ||
'free': '2000x0', | ||
}; | ||
export type ImageCropType = keyof typeof imageCrops; | ||
|
||
export const mobileImageCrops = { | ||
'1x1': '1000x1000', | ||
'2x1': '1000x500', | ||
'3x2': '1200x800', | ||
'5x8': '1000x1600', | ||
'16x9': '1600x900', | ||
'free': '1000x0', | ||
}; | ||
|
||
export const image = (renderTwoImages: boolean) => cnb( | ||
'size-full', | ||
renderTwoImages ? 'hidden lg:block' : '', | ||
); | ||
export const mobileImage = 'size-full lg:hidden'; | ||
export const captionWrapper = 'mt-06em'; | ||
export const caption = 'caption *:leading-display mt-08em max-w-prose-wide'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { cnb } from 'cnbuilder'; | ||
|
||
export const root = 'relative'; | ||
|
||
export const contentWrapper = 'mt-40 md:-mt-60 xl:mt-0'; | ||
export const superhead = (isLightHero: boolean) => cnb('cc mb-04em w-full', !isLightHero && 'text-shadow-sm'); | ||
export const heading = ( | ||
isSmallHeading?: boolean, | ||
headingFont?: 'druk' | 'serif', | ||
) => cnb('mb-0 text-balance mx-auto whitespace-pre-line', { | ||
'fluid-type-7 max-w-1400': headingFont === 'druk', | ||
'md:fluid-type-8': isSmallHeading && headingFont === 'druk', | ||
'md:fluid-type-9': !isSmallHeading && headingFont === 'druk', | ||
'fluid-type-5 md:fluid-type-7 max-w-1200': headingFont === 'serif', | ||
'xl:fluid-type-8 ': headingFont === 'serif' && !isSmallHeading, | ||
}); | ||
export const dek = 'max-w-900 text-balance mx-auto rs-mt-3'; | ||
export const image = 'rs-mt-4 w-full'; | ||
export const mobileImage = 'size-full lg:hidden'; | ||
export const captionWrapper = 'mt-06em'; | ||
export const caption = 'caption *:leading-display mt-08em max-w-prose-wide'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { AnimateInView } from '@/components/Animate'; | ||
import { Container } from '@/components/Container'; | ||
import { | ||
Heading, Paragraph, Text, SrOnlyText, | ||
} from '@/components/Typography'; | ||
import { getProcessedImage } from '@/utilities/getProcessedImage'; | ||
import { getSbImageSize } from '@/utilities/getSbImageSize'; | ||
import * as styles from './StoryHeroStacked.styles'; | ||
|
||
export type StoryHeroStackedProps = { | ||
title: string; | ||
superhead?: string; | ||
headingFont?: 'serif' | 'druk'; | ||
isSmallHeading?: boolean; | ||
dek?: string; | ||
heroBgColor?: string; // Hex color value from Storyblok native color picker | ||
imageSrc?: string; | ||
imageFocus?: string; | ||
alt?: string; | ||
hasCaption?: boolean; | ||
isLightHero?: boolean; | ||
}; | ||
|
||
export const StoryHeroStacked = ({ | ||
title, | ||
superhead, | ||
headingFont, | ||
isSmallHeading, | ||
dek, | ||
heroBgColor, | ||
imageSrc, | ||
imageFocus, | ||
alt, | ||
hasCaption, | ||
isLightHero = false, | ||
}: StoryHeroStackedProps) => { | ||
// We keep the original image aspect ratio | ||
const imageSize = getSbImageSize(imageSrc) || { width: 0, height: 0 }; | ||
const { width: imageWidth, height: imageHeight } = imageSize; | ||
|
||
return ( | ||
<Container | ||
width="full" | ||
className={styles.root} | ||
pt={10} | ||
style={{ backgroundColor: heroBgColor || '#888' }} | ||
> | ||
<Container className={styles.contentWrapper}> | ||
{superhead && ( | ||
<AnimateInView animation="slideUp"> | ||
<Text | ||
size={1} | ||
align="center" | ||
color={isLightHero ? 'black' : 'white'} | ||
// If there is a heading, superhead will be rendered as screen reader text as part of the heading | ||
aria-hidden | ||
className={styles.superhead(isLightHero)} | ||
> | ||
{superhead} | ||
</Text> | ||
</AnimateInView> | ||
)} | ||
{title && ( | ||
<AnimateInView animation="slideUp" delay={0.1}> | ||
<Heading | ||
as="h1" | ||
align="center" | ||
color={isLightHero ? 'black' : 'white'} | ||
font={headingFont} | ||
leading={headingFont === 'druk' ? 'druk' : 'tight'} | ||
className={styles.heading(isSmallHeading, headingFont)} | ||
> | ||
{superhead && <SrOnlyText>{`${superhead}:`}</SrOnlyText>}{title} | ||
</Heading> | ||
</AnimateInView> | ||
)} | ||
{dek && ( | ||
<AnimateInView animation="slideUp" delay={0.2}> | ||
<Paragraph | ||
variant="overview" | ||
weight="normal" | ||
leading="display" | ||
align="center" | ||
className={styles.dek} | ||
color={isLightHero ? 'black' : 'white'} | ||
noMargin | ||
> | ||
{dek} | ||
</Paragraph> | ||
</AnimateInView> | ||
)} | ||
</Container> | ||
{imageSrc && ( | ||
<AnimateInView animation="zoomSharpen" duration={1}> | ||
<picture> | ||
<source | ||
srcSet={getProcessedImage(imageSrc, '2000x0', imageFocus)} | ||
media="(min-width: 1500px)" | ||
/> | ||
<source | ||
srcSet={getProcessedImage(imageSrc, '1500x0', imageFocus)} | ||
media="(min-width: 1200px)" | ||
/> | ||
<source | ||
srcSet={getProcessedImage(imageSrc, '1200x0', imageFocus)} | ||
media="(min-width: 768px)" | ||
/> | ||
<source | ||
srcSet={getProcessedImage(imageSrc, '800x0', imageFocus)} | ||
media="(min-width: 576px)" | ||
/> | ||
<source | ||
srcSet={getProcessedImage(imageSrc, '600x0', imageFocus)} | ||
media="(max-width: 575px)" | ||
/> | ||
<img | ||
src={getProcessedImage(imageSrc, '2000x0', imageFocus)} | ||
alt={alt || ''} | ||
aria-describedby={hasCaption ? 'story-hero-caption' : undefined} | ||
fetchPriority="high" | ||
width={imageWidth} | ||
height={imageHeight} | ||
className={styles.image} | ||
/> | ||
</picture> | ||
</AnimateInView> | ||
)} | ||
</Container> | ||
); | ||
}; |
Oops, something went wrong.