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

Update conditions to hide duotone panel #33295

Merged
merged 13 commits into from
Jul 12, 2021
2 changes: 2 additions & 0 deletions docs/how-to-guides/themes/theme-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ The settings section has the following structure:
"settings": {
"color": {
"custom": true,
"customDuotone": true,
"customGradient": true,
"duotone": [],
"gradients": [],
Expand Down Expand Up @@ -220,6 +221,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 @@ -85,6 +85,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
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 @@ -124,15 +126,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 );
ajlende marked this conversation as resolved.
Show resolved Hide resolved

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