Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Do not show duotone panel is subcomponents are empty or disabled
  • Loading branch information
oandregal committed Jul 12, 2021
commit 1fa16578f8378a83ddd4630048d5cac4ff36b734
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ function DuotoneControl( {
} ) {
const [ isOpen, setIsOpen ] = useState( false );

if ( ! duotonePalette ) {
return null;
}

const onToggle = () => {
setIsOpen( ( prev ) => ! prev );
};
Expand Down
18 changes: 11 additions & 7 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,23 @@ ${ selector } {
);
}

function DuotonePanel( { attributes, setAttributes } ) {
function DuotonePanel( { name, attributes, setAttributes } ) {
const style = attributes?.style;
const duotone = style?.color?.duotone;

const duotonePalette = useSetting( 'color.duotone' );
const colorPalette = useSetting( 'color.palette' );
const disableCustomColors = ! useSetting( 'color.custom' );

if (
! hasBlockSupport( name, 'color.__experimentalDuotone' ) ||
( duotonePalette?.length === 0 &&
colorPalette?.length === 0 &&
disableCustomColors )
) {
return null;
}

return (
<BlockControls group="block">
<DuotoneControl
Expand Down Expand Up @@ -186,15 +195,10 @@ function addDuotoneAttributes( settings ) {
*/
const withDuotoneControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const hasDuotoneSupport = hasBlockSupport(
props.name,
'color.__experimentalDuotone'
);

return (
<>
<BlockEdit { ...props } />
{ hasDuotoneSupport && <DuotonePanel { ...props } /> }
<DuotonePanel { ...props } />
</>
);
},
Expand Down
37 changes: 18 additions & 19 deletions packages/components/src/duotone-picker/duotone-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,24 @@ function DuotonePicker( {
{ ! disableCustomColors && (
<CustomDuotoneBar value={ value } onChange={ onChange } />
) }
{ colorPalette && (
<ColorListPicker
labels={ [ __( 'Shadows' ), __( 'Highlights' ) ] }
colors={ colorPalette }
value={ value }
disableCustomColors={ disableCustomColors }
onChange={ ( newColors ) => {
if ( ! newColors[ 0 ] ) {
newColors[ 0 ] = defaultDark;
}
if ( ! newColors[ 1 ] ) {
newColors[ 1 ] = defaultLight;
}
const newValue =
newColors.length >= 2 ? newColors : undefined;
onChange( newValue );
} }
/>
) }

<ColorListPicker
labels={ [ __( 'Shadows' ), __( 'Highlights' ) ] }
colors={ colorPalette }
value={ value }
disableCustomColors={ disableCustomColors }
onChange={ ( newColors ) => {
if ( ! newColors[ 0 ] ) {
newColors[ 0 ] = defaultDark;
}
if ( ! newColors[ 1 ] ) {
newColors[ 1 ] = defaultLight;
}
const newValue =
newColors.length >= 2 ? newColors : undefined;
onChange( newValue );
} }
/>
</CircularOptionPicker>
);
}
Expand Down