-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Featured Image: Fix overlay rendering in the editor (#60187)
- Loading branch information
1 parent
80a0b12
commit 1d7407b
Showing
3 changed files
with
117 additions
and
85 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
88 changes: 88 additions & 0 deletions
88
packages/block-library/src/post-featured-image/overlay-controls.js
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,88 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
RangeControl, | ||
__experimentalToolsPanelItem as ToolsPanelItem, | ||
} from '@wordpress/components'; | ||
import { | ||
InspectorControls, | ||
withColors, | ||
__experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown, | ||
__experimentalUseGradient, | ||
__experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients, | ||
} from '@wordpress/block-editor'; | ||
import { compose } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const Overlay = ( { | ||
clientId, | ||
attributes, | ||
setAttributes, | ||
overlayColor, | ||
setOverlayColor, | ||
} ) => { | ||
const { dimRatio } = attributes; | ||
const { gradientValue, setGradient } = __experimentalUseGradient(); | ||
const colorGradientSettings = useMultipleOriginColorsAndGradients(); | ||
|
||
if ( ! colorGradientSettings.hasColorsOrGradients ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<InspectorControls group="color"> | ||
<ColorGradientSettingsDropdown | ||
__experimentalIsRenderedInSidebar | ||
settings={ [ | ||
{ | ||
colorValue: overlayColor.color, | ||
gradientValue, | ||
label: __( 'Overlay' ), | ||
onColorChange: setOverlayColor, | ||
onGradientChange: setGradient, | ||
isShownByDefault: true, | ||
resetAllFilter: () => ( { | ||
overlayColor: undefined, | ||
customOverlayColor: undefined, | ||
gradient: undefined, | ||
customGradient: undefined, | ||
} ), | ||
}, | ||
] } | ||
panelId={ clientId } | ||
{ ...colorGradientSettings } | ||
/> | ||
<ToolsPanelItem | ||
hasValue={ () => dimRatio !== undefined } | ||
label={ __( 'Overlay opacity' ) } | ||
onDeselect={ () => setAttributes( { dimRatio: 0 } ) } | ||
resetAllFilter={ () => ( { | ||
dimRatio: 0, | ||
} ) } | ||
isShownByDefault | ||
panelId={ clientId } | ||
> | ||
<RangeControl | ||
__nextHasNoMarginBottom | ||
label={ __( 'Overlay opacity' ) } | ||
value={ dimRatio } | ||
onChange={ ( newDimRatio ) => | ||
setAttributes( { | ||
dimRatio: newDimRatio, | ||
} ) | ||
} | ||
min={ 0 } | ||
max={ 100 } | ||
step={ 10 } | ||
required | ||
__next40pxDefaultSize | ||
/> | ||
</ToolsPanelItem> | ||
</InspectorControls> | ||
); | ||
}; | ||
|
||
export default compose( [ | ||
withColors( { overlayColor: 'background-color' } ), | ||
] )( Overlay ); |
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