Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Editor: Optimize 'duotone' controls #55753

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function DuotonePanel( { attributes, setAttributes, name } ) {
const style = attributes?.style;
const duotoneStyle = style?.color?.duotone;
const settings = useBlockSettings( name );
const blockEditingMode = useBlockEditingMode();

const duotonePalette = useMultiOriginPresets( {
presetSetting: 'color.duotone',
Expand All @@ -124,6 +125,10 @@ function DuotonePanel( { attributes, setAttributes, name } ) {
return null;
}

if ( blockEditingMode !== 'default' ) {
return null;
}

const duotonePresetOrColors = ! Array.isArray( duotoneStyle )
? getColorsFromDuotonePreset( duotoneStyle, duotonePalette )
: duotoneStyle;
Expand Down Expand Up @@ -219,17 +224,13 @@ const withDuotoneControls = createHigherOrderComponent(
'filter.duotone'
);

const blockEditingMode = useBlockEditingMode();

// CAUTION: code added before this line will be executed
// for all blocks, not just those that support duotone. Code added
// above this line should be carefully evaluated for its impact on
// performance.
return (
<>
{ hasDuotoneSupport && blockEditingMode === 'default' && (
<DuotonePanel { ...props } />
) }
{ hasDuotoneSupport && <DuotonePanel { ...props } /> }
<BlockEdit { ...props } />
</>
);
Expand Down