Skip to content

Commit

Permalink
Update conditions to hide duotone panel (#33295)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored and youknowriad committed Jul 13, 2021
1 parent 8bdf9e9 commit b2a5a81
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/how-to-guides/themes/theme-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ The settings section has the following structure:
},
"color": {
"custom": true,
"customDuotone": true,
"customGradient": true,
"duotone": [],
"gradients": [],
Expand Down
1 change: 1 addition & 0 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class WP_Theme_JSON_Gutenberg {
),
'color' => array(
'custom' => null,
'customDuotone' => null,
'customGradient' => null,
'duotone' => null,
'gradients' => null,
Expand Down
5 changes: 3 additions & 2 deletions lib/experimental-default-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@
}
],
"custom": true,
"link": false,
"customGradient": true
"customDuotone": true,
"customGradient": true,
"link": false
},
"typography": {
"dropCap": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function DuotonePickerPopover( {
duotonePalette,
colorPalette,
disableCustomColors,
disableCustomDuotone,
} ) {
return (
<Popover
Expand All @@ -23,6 +24,7 @@ function DuotonePickerPopover( {
colorPalette={ colorPalette }
duotonePalette={ duotonePalette }
disableCustomColors={ disableCustomColors }
disableCustomDuotone={ disableCustomDuotone }
value={ value }
onChange={ onChange }
/>
Expand Down
6 changes: 2 additions & 4 deletions packages/block-editor/src/components/duotone-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ function DuotoneControl( {
colorPalette,
duotonePalette,
disableCustomColors,
disableCustomDuotone,
value,
onChange,
} ) {
const [ isOpen, setIsOpen ] = useState( false );

if ( ! duotonePalette ) {
return null;
}

const onToggle = () => {
setIsOpen( ( prev ) => ! prev );
};
Expand Down Expand Up @@ -55,6 +52,7 @@ function DuotoneControl( {
duotonePalette={ duotonePalette }
colorPalette={ colorPalette }
disableCustomColors={ disableCustomColors }
disableCustomDuotone={ disableCustomDuotone }
/>
) }
</>
Expand Down
14 changes: 12 additions & 2 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
useSetting,
} from '../components';

const EMPTY_ARRAY = [];

/**
* Convert a list of colors to an object of R, G, and B values.
*
Expand Down Expand Up @@ -123,15 +125,23 @@ function DuotonePanel( { attributes, setAttributes } ) {
const style = attributes?.style;
const duotone = style?.color?.duotone;

const duotonePalette = useSetting( 'color.duotone' );
const colorPalette = useSetting( 'color.palette' );
const duotonePalette = useSetting( 'color.duotone' ) || EMPTY_ARRAY;
const colorPalette = useSetting( 'color.palette' ) || EMPTY_ARRAY;
const disableCustomColors = ! useSetting( 'color.custom' );
const disableCustomDuotone =
! useSetting( 'color.customDuotone' ) ||
( colorPalette?.length === 0 && disableCustomColors );

if ( duotonePalette?.length === 0 && disableCustomDuotone ) {
return null;
}

return (
<BlockControls group="block">
<DuotoneControl
duotonePalette={ duotonePalette }
colorPalette={ colorPalette }
disableCustomDuotone={ disableCustomDuotone }
disableCustomColors={ disableCustomColors }
value={ duotone }
onChange={ ( newDuotone ) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/duotone-picker/duotone-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ function DuotonePicker( {
colorPalette,
duotonePalette,
disableCustomColors,
disableCustomDuotone,
value,
onChange,
} ) {
const [ defaultDark, defaultLight ] = useMemo(
() => getDefaultColors( colorPalette ),
[ colorPalette ]
);

return (
<CircularOptionPicker
options={ duotonePalette.map( ( { colors, slug, name } ) => {
Expand Down Expand Up @@ -74,10 +76,10 @@ function DuotonePicker( {
</CircularOptionPicker.ButtonAction>
}
>
{ ! disableCustomColors && (
{ ! disableCustomColors && ! disableCustomDuotone && (
<CustomDuotoneBar value={ value } onChange={ onChange } />
) }
{ colorPalette && (
{ ! disableCustomDuotone && (
<ColorListPicker
labels={ [ __( 'Shadows' ), __( 'Highlights' ) ] }
colors={ colorPalette }
Expand Down

0 comments on commit b2a5a81

Please sign in to comment.