-
Notifications
You must be signed in to change notification settings - Fork 219
Attribute Filter block: Enable global style #5557
Changes from 13 commits
e9d7c30
517f80a
48709c7
6d79824
4bcdc58
a17ca36
8e2f0dc
1d9cf47
c2cab62
6d6b1e7
0efbf23
d7805ea
f5d0ade
77df342
30b64ec
94f5e5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ import { | |
InnerBlocks, | ||
InspectorControls, | ||
MediaReplaceFlow, | ||
PanelColorSettings, | ||
withColors, | ||
RichText, | ||
} from '@wordpress/block-editor'; | ||
import { | ||
|
@@ -56,8 +54,6 @@ import { withCategory } from '../../hocs'; | |
* @param {function(any):any} props.getCategory Function for getting category details. | ||
* @param {boolean} props.isLoading Whether loading or not. | ||
* @param {Object} props.category The product category object. | ||
* @param {Object} props.overlayColor Overlay color object for content. | ||
* @param {function(any):any} props.setOverlayColor Setter for overlay color. | ||
* @param {function(any):any} props.debouncedSpeak Function for delayed speak. | ||
* @param {function():void} props.triggerUrlUpdate Function to update Shop now button Url. | ||
*/ | ||
|
@@ -69,8 +65,6 @@ const FeaturedCategory = ( { | |
getCategory, | ||
isLoading, | ||
category, | ||
overlayColor, | ||
setOverlayColor, | ||
debouncedSpeak, | ||
triggerUrlUpdate = () => void null, | ||
} ) => { | ||
|
@@ -148,21 +142,14 @@ const FeaturedCategory = ( { | |
} | ||
/> | ||
</PanelBody> | ||
<PanelColorSettings | ||
title={ __( 'Overlay', 'woo-gutenberg-products-block' ) } | ||
colorSettings={ [ | ||
{ | ||
value: overlayColor.color, | ||
onChange: setOverlayColor, | ||
label: __( | ||
'Overlay Color', | ||
{ !! url && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand you want to cast this as a boolean, but I have to say I've always found the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just moved this code, I didn't edit it. I agree with you that it is not very clear this cast! I will change it! |
||
<> | ||
<PanelBody | ||
title={ __( | ||
'Overlay', | ||
'woo-gutenberg-products-block' | ||
), | ||
}, | ||
] } | ||
> | ||
{ !! url && ( | ||
<> | ||
) } | ||
> | ||
<RangeControl | ||
label={ __( | ||
'Background Opacity', | ||
|
@@ -189,9 +176,9 @@ const FeaturedCategory = ( { | |
} | ||
/> | ||
) } | ||
</> | ||
) } | ||
</PanelColorSettings> | ||
</PanelBody> | ||
</> | ||
) } | ||
</InspectorControls> | ||
); | ||
}; | ||
|
@@ -287,14 +274,8 @@ const FeaturedCategory = ( { | |
}; | ||
|
||
const renderCategory = () => { | ||
const { | ||
className, | ||
contentAlign, | ||
dimRatio, | ||
focalPoint, | ||
height, | ||
showDesc, | ||
} = attributes; | ||
const { contentAlign, dimRatio, focalPoint, showDesc } = attributes; | ||
|
||
const classes = classnames( | ||
'wc-block-featured-category', | ||
{ | ||
|
@@ -304,14 +285,10 @@ const FeaturedCategory = ( { | |
'has-background-dim': dimRatio !== 0, | ||
}, | ||
dimRatioToClass( dimRatio ), | ||
contentAlign !== 'center' && `has-${ contentAlign }-content`, | ||
className | ||
contentAlign !== 'center' && `has-${ contentAlign }-content` | ||
); | ||
const mediaSrc = attributes.mediaSrc || getCategoryImageSrc( category ); | ||
const style = !! category ? getBackgroundImageStyles( mediaSrc ) : {}; | ||
if ( overlayColor.color ) { | ||
style.backgroundColor = overlayColor.color; | ||
} | ||
if ( focalPoint ) { | ||
const bgPosX = focalPoint.x * 100; | ||
const bgPosY = focalPoint.y * 100; | ||
|
@@ -325,7 +302,10 @@ const FeaturedCategory = ( { | |
return ( | ||
<ResizableBox | ||
className={ classes } | ||
size={ { height } } | ||
size={ { | ||
height: '', | ||
width: '', | ||
} } | ||
minHeight={ getSetting( 'min_height', 500 ) } | ||
enable={ { bottom: true } } | ||
onResizeStop={ onResizeStop } | ||
|
@@ -416,17 +396,13 @@ FeaturedCategory.propTypes = { | |
description: PropTypes.node, | ||
permalink: PropTypes.string, | ||
} ), | ||
// from withColors | ||
overlayColor: PropTypes.object, | ||
setOverlayColor: PropTypes.func.isRequired, | ||
// from withSpokenMessages | ||
debouncedSpeak: PropTypes.func.isRequired, | ||
triggerUrlUpdate: PropTypes.func, | ||
}; | ||
|
||
export default compose( [ | ||
withCategory, | ||
withColors( { overlayColor: 'background-color' } ), | ||
withSpokenMessages, | ||
withSelect( ( select, { clientId }, { dispatch } ) => { | ||
const Block = select( 'core/block-editor' ).getBlock( clientId ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Block from './block'; | ||
|
||
export const Edit = ( props: unknown ): JSX.Element => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't worked with blocks much, so forgive me for asking: isn't there a way to know this type at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, we can try to type it, but without the right typeguards, there is the risk that the code will be less safe than now. |
||
const blockProps = useBlockProps(); | ||
|
||
// The useBlockProps function returns the style with the `color`. | ||
// We need to remove it to avoid the block to be styled with the color. | ||
const { color, ...styles } = blockProps.style; | ||
|
||
return ( | ||
<div { ...blockProps } style={ styles }> | ||
<Block { ...props } /> | ||
</div> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using
CSSProperties
?