Skip to content

Commit

Permalink
Handle mutually exclusivity of attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Feb 24, 2023
1 parent 1de4a63 commit 360af4d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,15 @@ function DuotonePanel( { attributes, setAttributes } ) {
return null;
}

const duotonePresetOrColors = duotonePreset
? getColorsFromDuotonePreset( duotonePreset, duotonePalette )
: duotoneColors;
let duotonePresetOrColors;

if ( duotoneColors === 'unset' ) {
duotonePresetOrColors = 'unset';
} else {
duotonePresetOrColors = duotonePreset
? getColorsFromDuotonePreset( duotonePreset, duotonePalette )
: duotoneColors;
}

return (
<BlockControls group="block" __experimentalShareWithChildBlocks>
Expand All @@ -146,6 +152,13 @@ function DuotonePanel( { attributes, setAttributes } ) {
if ( maybePreset ) {
// Duotone presets are stored in a separate attribute.
newDuotoneAttributes.duotone = maybePreset;
newDuotoneAttributes.style = {
...style,
color: {
...style?.color,
duotone: '', // remove any custom colors
},
};

// Todo: should we store the custom colors **as well**
// in the style attribute as a fallback?
Expand All @@ -158,6 +171,8 @@ function DuotonePanel( { attributes, setAttributes } ) {
duotone: newDuotone, // custom colors
},
};
// Remove any presets.
newDuotoneAttributes.duotone = '';
}

setAttributes( newDuotoneAttributes );
Expand Down

0 comments on commit 360af4d

Please sign in to comment.