Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Feature/410 cover block #516

Merged
merged 40 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
73e5c32
Add all block attrs
ravewebdev Jun 10, 2021
48dfa02
Merge branch 'main' into feature/410-cover-block
ravewebdev Jun 11, 2021
70084bb
Add basic overlay color styling
ravewebdev Jun 11, 2021
fe24279
Add gradient overlay handling
ravewebdev Jun 11, 2021
dc9030d
Don't distort image on fill
ravewebdev Jun 11, 2021
09b5d48
Fix border-radius
ravewebdev Jun 11, 2021
b17e556
Ensure child elements display over background image
ravewebdev Jun 11, 2021
e200799
Add function to convert Hex to RGB
ravewebdev Jun 11, 2021
99b53ea
Add function to extract numeric RGB values from string
ravewebdev Jun 11, 2021
c17b45a
Simplify overlay handling
ravewebdev Jun 11, 2021
ca4e0e0
Add SO link
ravewebdev Jun 11, 2021
442a9d1
Add relative class to innerblocks
ravewebdev Jun 14, 2021
f860fc1
Always pass image url
ravewebdev Jun 14, 2021
bd8a2d9
Pass duotone array
ravewebdev Jun 14, 2021
c9b5863
Fix overlay display
ravewebdev Jun 14, 2021
b38770a
Create, display duotone filter component
ravewebdev Jun 14, 2021
2995822
Add image for filter, remove custom children handling
ravewebdev Jun 14, 2021
f9c19a1
Add filter styles
ravewebdev Jun 14, 2021
4bb048c
Remove additional tint
ravewebdev Jun 14, 2021
eb34e13
Hide filter
ravewebdev Jun 14, 2021
2441f07
Display plain image to allow for filter
ravewebdev Jun 14, 2021
46d5bcf
Reset z-index if only overlay, no image
ravewebdev Jun 14, 2021
2df9bc3
Set default text color to white
ravewebdev Jun 14, 2021
eace20b
Add align handling
ravewebdev Jun 14, 2021
1791fa1
Change to flex to allow text alignment
ravewebdev Jun 14, 2021
18a82a9
Don't output empty heading tag
ravewebdev Jun 14, 2021
d406414
Use min-height instead of padding
ravewebdev Jun 14, 2021
c51471a
Add content align top/bottom handling
ravewebdev Jun 14, 2021
6710037
Reset x-axis padding
ravewebdev Jun 14, 2021
af91cd9
Add horizontal content alignment
ravewebdev Jun 14, 2021
ee3edd1
Add full height support
ravewebdev Jun 14, 2021
b66b069
Add custom min-height
ravewebdev Jun 14, 2021
05324bb
Abstract focal point handling to fn
ravewebdev Jun 14, 2021
80a1f08
Abstract filter style to const
ravewebdev Jun 14, 2021
a579468
Add focal point handling
ravewebdev Jun 14, 2021
b31a77c
Add parallax handling
ravewebdev Jun 14, 2021
0727f39
Fix content z-index
ravewebdev Jun 14, 2021
109a7ea
Add repeat handling
ravewebdev Jun 14, 2021
a64aaac
Remove eslint-disable
ravewebdev Jun 14, 2021
7f69d9b
Merge branch 'main' into feature/410-cover-block
ravewebdev Jun 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions components/atoms/Image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ export default function DisplayImage(props) {
imageProps.width = imageSize?.width
}

return <Image {...imageProps} />
return (
<Image
{...imageProps}
className={cn(props?.nextImageFill ? styles.imageFill : null)}
/>
)
}

/**
Expand Down Expand Up @@ -134,7 +139,8 @@ export default function DisplayImage(props) {
className={cn(
styles.image,
props?.className,
props?.id ? `image-${props?.id}` : ''
props?.id ? `image-${props?.id}` : '',
props?.nextImageFill ? styles.hasImageFill : null
)}
>
{props?.href ? (
Expand Down
8 changes: 8 additions & 0 deletions components/atoms/Image/Image.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
& .caption {
@apply text-center text-xs pt-4;
}

&.hasImageFill {
@apply mb-0;
}

& .imageFill {
@apply object-cover rounded;
}
}
113 changes: 102 additions & 11 deletions components/blocks/Gutenberg/BlockCover/BlockCover.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Blocks from '@/components/molecules/Blocks'
import Hero from '@/components/organisms/Hero'
import formatFocalPoint from '@/functions/formatFocalPoint'
import PropTypes from 'prop-types'
import {useEffect, useState} from 'react'

/**
* Cover Block
Expand All @@ -14,25 +16,114 @@ import PropTypes from 'prop-types'
* @return {Element} The Cover component.
*/
export default function BlockCover({media, innerBlocks}) {
const {
align,
anchor,
className,
contentPosition,
customGradient,
dimRatio,
focalPoint,
gradientHex,
hasParallax,
isRepeated,
minHeight,
minHeightUnit,
overlayColorHex,
style,
url
} = media

const overlayColor = overlayColorHex || '#000000'
const overlayGradient = customGradient || gradientHex
const overlayOpacity = url ? dimRatio / 100 : 1

// Add custom styles for Hero.
const coverStyle = {}

if (overlayColor && !overlayGradient) {
coverStyle.backgroundColor = overlayColor
}

if (overlayGradient) {
coverStyle.background = overlayGradient
}

if (minHeight && minHeightUnit !== 'vh') {
coverStyle.minHeight = `${minHeight}px`
}

const newFocalPoint = formatFocalPoint(focalPoint)

const [newInnerBlocks, setInnerBlocks] = useState()

// Add extra class(es) to inner blocks on initial load.
useEffect(() => {
setInnerBlocks(
!innerBlocks?.length
? []
: innerBlocks.map((block) => {
const classes = (block?.attributes?.className ?? '').split(' ')

// Extra check to only add class once.
if (classes.includes('relative')) {
return block
}

block.attributes = {
...block?.attributes,
className: `${block?.attributes?.className || ''} relative z-10`
}

return block
})
)
}, [innerBlocks])

// Only proceed if we're provided a media URL or a user-selected overlay color/gradient.
if (!url && !overlayColorHex && !overlayGradient) {
return null
}

return (
<>
{!!media?.url && (
<Hero
backgroundImage={media}
id={media?.anchor}
className={media?.className}
>
{!!innerBlocks?.length && <Blocks blocks={innerBlocks} />}
</Hero>
)}
</>
<Hero
align={align}
contentAlign={contentPosition}
backgroundImage={{url}}
className={className}
duotone={style?.color?.duotone}
fixed={hasParallax}
focalPoint={newFocalPoint}
fullHeight={minHeight === 100 && minHeightUnit === 'vh'}
id={anchor}
overlayOpacity={overlayOpacity}
repeat={isRepeated}
style={coverStyle}
>
{!!newInnerBlocks?.length && <Blocks blocks={newInnerBlocks} />}
</Hero>
)
}

BlockCover.propTypes = {
media: PropTypes.shape({
align: PropTypes.string,
anchor: PropTypes.string,
className: PropTypes.string,
contentPosition: PropTypes.string,
customGradient: PropTypes.string,
dimRatio: PropTypes.number,
focalPoint: PropTypes.shape({
x: PropTypes.string,
y: PropTypes.string
}),
gradientHex: PropTypes.string,
hasParallax: PropTypes.bool,
isRepeated: PropTypes.bool,
minHeight: PropTypes.number,
minHeightUnit: PropTypes.string,
overlayColorHex: PropTypes.string,
style: PropTypes.object,
url: PropTypes.string
}),
innerBlocks: PropTypes.arrayOf(
Expand Down
12 changes: 2 additions & 10 deletions components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Blocks from '@/components/molecules/Blocks'
import MediaText from '@/components/organisms/MediaText'
import formatFocalPoint from '@/functions/formatFocalPoint'
import getBlockStyles from '@/functions/wordpress/blocks/getBlockStyles'
import PropTypes from 'prop-types'

Expand Down Expand Up @@ -53,16 +54,7 @@ export default function BlockMediaText({innerBlocks, media}) {
mediaPosition === 'left' ? `${mediaWidth}% 1fr` : `1fr ${mediaWidth}%`
mediaTextStyle.gridTemplateColumns = gridtemplatecolumns

const newFocalPoint = {}

// Convert focal point values to percent.
if (imageFill) {
const x = parseFloat(focalPoint?.x || '.5') ?? 0.5
const y = parseFloat(focalPoint?.y || '.5') ?? 0.5

newFocalPoint.x = `${x * 100}%`
newFocalPoint.y = `${y * 100}%`
}
const newFocalPoint = imageFill ? formatFocalPoint(focalPoint) : {}

return (
<>
Expand Down
Loading