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

Color UI component: reorder palettes and update names (core by defaults, user by custom) #36622

Merged
merged 8 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 2 additions & 4 deletions docs/how-to-guides/themes/theme-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,11 @@ The settings section has the following structure:
},
"color": {
"background": true,
"corePalette": true,
"coreGradients": true,
"custom": true,
"customDuotone": true,
"customGradient": true,
"corePalette": true,
"coreGradients": true,
"defaultGradients": true,
"defaultPalette": true,
"duotone": [],
"gradients": [],
"link": false,
Expand Down
22 changes: 11 additions & 11 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ class WP_Theme_JSON_Gutenberg {
'width' => null,
),
'color' => array(
'background' => null,
'corePalette' => null,
'coreGradients' => null,
Comment on lines -92 to -93
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these settings were only recently introduced, which is why we don't need migrations.

'custom' => null,
'customDuotone' => null,
'customGradient' => null,
'duotone' => null,
'gradients' => null,
'link' => null,
'palette' => null,
'text' => null,
'background' => null,
'custom' => null,
'customDuotone' => null,
'customGradient' => null,
'defaultGradients' => null,
'defaultPalette' => null,
'duotone' => null,
'gradients' => null,
'link' => null,
'palette' => null,
'text' => null,
),
'custom' => null,
'layout' => array(
Expand Down
4 changes: 2 additions & 2 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static function get_theme_data() {
// If the theme does not have any palette, we still want to show the core one.
$default_palette = true;
}
$theme_support_data['settings']['color']['corePalette'] = $default_palette;
$theme_support_data['settings']['color']['defaultPalette'] = $default_palette;

$default_gradients = false;
if ( current_theme_supports( 'default-gradient-presets' ) ) {
Expand All @@ -181,7 +181,7 @@ public static function get_theme_data() {
// If the theme does not have any gradients, we still want to show the core ones.
$default_gradients = true;
}
$theme_support_data['settings']['color']['coreGradients'] = $default_gradients;
$theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;
}
$with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data );
$with_theme_supports->merge( self::$theme );
Expand Down
4 changes: 2 additions & 2 deletions lib/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@
}
],
"custom": true,
"corePalette": true,
"coreGradients": true,
"customDuotone": true,
"customGradient": true,
"defaultGradients": true,
"defaultPalette": true,
"link": false,
"text": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,64 +172,70 @@ const PanelColorGradientSettingsSingleSelect = ( props ) => {

const PanelColorGradientSettingsMultipleSelect = ( props ) => {
const colorGradientSettings = useCommonSingleMultipleSelects();
const userColors = useSetting( 'color.palette.user' );
const customColors = useSetting( 'color.palette.user' );
const themeColors = useSetting( 'color.palette.theme' );
const coreColors = useSetting( 'color.palette.core' );
const shouldDisplayCoreColors = useSetting( 'color.corePalette' );
const defaultColors = useSetting( 'color.palette.core' );
const shouldDisplayDefaultColors = useSetting( 'color.defaultPalette' );

colorGradientSettings.colors = useMemo( () => {
const result = [];
if ( shouldDisplayCoreColors && coreColors && coreColors.length ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the mockups, the order in which the palettes should be shown is: defaults, theme, user.

result.push( {
name: __( 'Core' ),
colors: coreColors,
} );
}
if ( themeColors && themeColors.length ) {
result.push( {
name: __( 'Theme' ),
colors: themeColors,
} );
}
if ( userColors && userColors.length ) {
if (
shouldDisplayDefaultColors &&
defaultColors &&
defaultColors.length
) {
result.push( {
name: __( 'Default' ),
colors: defaultColors,
} );
}
if ( customColors && customColors.length ) {
result.push( {
name: __( 'User' ),
colors: userColors,
name: __( 'Custom' ),
colors: customColors,
} );
}
return result;
}, [ coreColors, themeColors, userColors ] );
}, [ defaultColors, themeColors, customColors ] );

const userGradients = useSetting( 'color.gradients.user' );
const customGradients = useSetting( 'color.gradients.user' );
const themeGradients = useSetting( 'color.gradients.theme' );
const coreGradients = useSetting( 'color.gradients.core' );
const shouldDisplayCoreGradients = useSetting( 'color.coreGradients' );
const defaultGradients = useSetting( 'color.gradients.core' );
const shouldDisplayDefaultGradients = useSetting(
'color.defaultGradients'
);
colorGradientSettings.gradients = useMemo( () => {
const result = [];
if (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the mockups, the order in which the palettes should be shown is: defaults, theme, user.

shouldDisplayCoreGradients &&
coreGradients &&
coreGradients.length
) {
result.push( {
name: __( 'Core' ),
gradients: coreGradients,
} );
}
if ( themeGradients && themeGradients.length ) {
result.push( {
name: __( 'Theme' ),
gradients: themeGradients,
} );
}
if ( userGradients && userGradients.length ) {
if (
shouldDisplayDefaultGradients &&
defaultGradients &&
defaultGradients.length
) {
result.push( {
name: __( 'Default' ),
gradients: defaultGradients,
} );
}
if ( customGradients && customGradients.length ) {
result.push( {
name: __( 'User' ),
gradients: userGradients,
name: __( 'Custom' ),
gradients: customGradients,
} );
}
return result;
}, [ userGradients, themeGradients, coreGradients ] );
}, [ customGradients, themeGradients, defaultGradients ] );
return (
<PanelColorGradientSettingsInner
{ ...{ ...colorGradientSettings, ...props } }
Expand Down
48 changes: 24 additions & 24 deletions packages/edit-site/src/components/global-styles/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,57 +218,57 @@ export function getSupportedGlobalStylesPanels( name ) {
}

export function useColorsPerOrigin( name ) {
const [ userColors ] = useSetting( 'color.palette.user', name );
const [ customColors ] = useSetting( 'color.palette.user', name );
const [ themeColors ] = useSetting( 'color.palette.theme', name );
const [ coreColors ] = useSetting( 'color.palette.core', name );
const [ defaultColors ] = useSetting( 'color.palette.core', name );
return useMemo( () => {
const result = [];
if ( coreColors && coreColors.length ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the mockups, the order of teh palettes is: theme, defaults, custom.

result.push( {
name: __( 'Core' ),
colors: coreColors,
} );
}
if ( themeColors && themeColors.length ) {
result.push( {
name: __( 'Theme' ),
colors: themeColors,
} );
}
if ( userColors && userColors.length ) {
if ( defaultColors && defaultColors.length ) {
result.push( {
name: __( 'Default' ),
colors: defaultColors,
} );
}
if ( customColors && customColors.length ) {
result.push( {
name: __( 'User' ),
colors: userColors,
name: __( 'Custom' ),
colors: customColors,
} );
}
return result;
}, [ userColors, themeColors, coreColors ] );
}, [ customColors, themeColors, defaultColors ] );
}

export function useGradientsPerOrigin( name ) {
const [ userGradients ] = useSetting( 'color.gradients.user', name );
const [ customGradients ] = useSetting( 'color.gradients.user', name );
const [ themeGradients ] = useSetting( 'color.gradients.theme', name );
const [ coreGradients ] = useSetting( 'color.gradients.core', name );
const [ defaultGradients ] = useSetting( 'color.gradients.core', name );
return useMemo( () => {
const result = [];
if ( coreGradients && coreGradients.length ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the mockups, the order of teh palettes is: theme, defaults, custom.

result.push( {
name: __( 'Core' ),
gradients: coreGradients,
} );
}
if ( themeGradients && themeGradients.length ) {
result.push( {
name: __( 'Theme' ),
gradients: themeGradients,
} );
}
if ( userGradients && userGradients.length ) {
if ( defaultGradients && defaultGradients.length ) {
result.push( {
name: __( 'Default' ),
gradients: defaultGradients,
} );
}
if ( customGradients && customGradients.length ) {
result.push( {
name: __( 'User' ),
gradients: userGradients,
name: __( 'Custom' ),
gradients: customGradients,
} );
}
return result;
}, [ userGradients, themeGradients, coreGradients ] );
}, [ customGradients, themeGradients, defaultGradients ] );
}
20 changes: 10 additions & 10 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@
"type": "boolean",
"default": true
},
"corePalette": {
"description": "Allow users to choose colors from the Core palette. \nGutenberg plugin required.",
"type": "boolean",
"default": true
},
"coreGradients": {
"description": "Allow users to choose colors from the Core gradients. \nGutenberg plugin required.",
"type": "boolean",
"default": true
},
"custom": {
"description": "Allow users to select custom colors.\nSince 5.8.",
"type": "boolean",
Expand All @@ -70,6 +60,16 @@
"type": "boolean",
"default": true
},
"defaultGradients": {
"description": "Allow users to choose colors from the default gradients. \nGutenberg plugin required.",
"type": "boolean",
"default": true
},
"defaultPalette": {
"description": "Allow users to choose colors from the default palette. \nGutenberg plugin required.",
"type": "boolean",
"default": true
},
"duotone": {
"description": "Duotone presets for the duotone picker.\nDoesn't generate classes or properties.\nSince 5.8.",
"type": "array",
Expand Down