Skip to content

Commit b8686e8

Browse files
oandregalnoisysocks
authored andcommitted
Color UI component: reorder palettes and update names (core by defaults, user by custom) (#36622)
1 parent d0e6ff8 commit b8686e8

File tree

7 files changed

+125
-85
lines changed

7 files changed

+125
-85
lines changed

docs/how-to-guides/themes/theme-json.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,11 @@ The settings section has the following structure:
226226
},
227227
"color": {
228228
"background": true,
229-
"corePalette": true,
230-
"coreGradients": true,
231229
"custom": true,
232230
"customDuotone": true,
233231
"customGradient": true,
234-
"corePalette": true,
235-
"coreGradients": true,
232+
"defaultGradients": true,
233+
"defaultPalette": true,
236234
"duotone": [],
237235
"gradients": [],
238236
"link": false,

lib/class-wp-theme-json-gutenberg.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,17 @@ class WP_Theme_JSON_Gutenberg {
8888
'width' => null,
8989
),
9090
'color' => array(
91-
'background' => null,
92-
'corePalette' => null,
93-
'coreGradients' => null,
94-
'custom' => null,
95-
'customDuotone' => null,
96-
'customGradient' => null,
97-
'duotone' => null,
98-
'gradients' => null,
99-
'link' => null,
100-
'palette' => null,
101-
'text' => null,
91+
'background' => null,
92+
'custom' => null,
93+
'customDuotone' => null,
94+
'customGradient' => null,
95+
'defaultGradients' => null,
96+
'defaultPalette' => null,
97+
'duotone' => null,
98+
'gradients' => null,
99+
'link' => null,
100+
'palette' => null,
101+
'text' => null,
102102
),
103103
'custom' => null,
104104
'layout' => array(

lib/class-wp-theme-json-resolver-gutenberg.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static function get_theme_data() {
171171
// If the theme does not have any palette, we still want to show the core one.
172172
$default_palette = true;
173173
}
174-
$theme_support_data['settings']['color']['corePalette'] = $default_palette;
174+
$theme_support_data['settings']['color']['defaultPalette'] = $default_palette;
175175

176176
$default_gradients = false;
177177
if ( current_theme_supports( 'default-gradient-presets' ) ) {
@@ -181,7 +181,7 @@ public static function get_theme_data() {
181181
// If the theme does not have any gradients, we still want to show the core ones.
182182
$default_gradients = true;
183183
}
184-
$theme_support_data['settings']['color']['coreGradients'] = $default_gradients;
184+
$theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;
185185
}
186186
$with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data );
187187
$with_theme_supports->merge( self::$theme );

lib/theme.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@
170170
}
171171
],
172172
"custom": true,
173-
"corePalette": true,
174-
"coreGradients": true,
175173
"customDuotone": true,
176174
"customGradient": true,
175+
"defaultGradients": true,
176+
"defaultPalette": true,
177177
"link": false,
178178
"text": true
179179
},

packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js

+55-31
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { every, isEmpty } from 'lodash';
88
* WordPress dependencies
99
*/
1010
import { PanelBody, ColorIndicator } from '@wordpress/components';
11-
import { sprintf, __ } from '@wordpress/i18n';
11+
import { sprintf, __, _x } from '@wordpress/i18n';
1212
import { useMemo } from '@wordpress/element';
1313

1414
/**
@@ -172,64 +172,88 @@ const PanelColorGradientSettingsSingleSelect = ( props ) => {
172172

173173
const PanelColorGradientSettingsMultipleSelect = ( props ) => {
174174
const colorGradientSettings = useCommonSingleMultipleSelects();
175-
const userColors = useSetting( 'color.palette.user' );
175+
const customColors = useSetting( 'color.palette.user' );
176176
const themeColors = useSetting( 'color.palette.theme' );
177-
const coreColors = useSetting( 'color.palette.core' );
178-
const shouldDisplayCoreColors = useSetting( 'color.corePalette' );
177+
const defaultColors = useSetting( 'color.palette.core' );
178+
const shouldDisplayDefaultColors = useSetting( 'color.defaultPalette' );
179179

180180
colorGradientSettings.colors = useMemo( () => {
181181
const result = [];
182-
if ( shouldDisplayCoreColors && coreColors && coreColors.length ) {
182+
if ( themeColors && themeColors.length ) {
183183
result.push( {
184-
name: __( 'Core' ),
185-
colors: coreColors,
184+
name: _x(
185+
'Theme',
186+
'Indicates this palette comes from the theme.'
187+
),
188+
colors: themeColors,
186189
} );
187190
}
188-
if ( themeColors && themeColors.length ) {
191+
if (
192+
shouldDisplayDefaultColors &&
193+
defaultColors &&
194+
defaultColors.length
195+
) {
189196
result.push( {
190-
name: __( 'Theme' ),
191-
colors: themeColors,
197+
name: _x(
198+
'Default',
199+
'Indicates this palette comes from WordPress.'
200+
),
201+
colors: defaultColors,
192202
} );
193203
}
194-
if ( userColors && userColors.length ) {
204+
if ( customColors && customColors.length ) {
195205
result.push( {
196-
name: __( 'User' ),
197-
colors: userColors,
206+
name: _x(
207+
'Custom',
208+
'Indicates this palette comes from the theme.'
209+
),
210+
colors: customColors,
198211
} );
199212
}
200213
return result;
201-
}, [ coreColors, themeColors, userColors ] );
214+
}, [ defaultColors, themeColors, customColors ] );
202215

203-
const userGradients = useSetting( 'color.gradients.user' );
216+
const customGradients = useSetting( 'color.gradients.user' );
204217
const themeGradients = useSetting( 'color.gradients.theme' );
205-
const coreGradients = useSetting( 'color.gradients.core' );
206-
const shouldDisplayCoreGradients = useSetting( 'color.coreGradients' );
218+
const defaultGradients = useSetting( 'color.gradients.core' );
219+
const shouldDisplayDefaultGradients = useSetting(
220+
'color.defaultGradients'
221+
);
207222
colorGradientSettings.gradients = useMemo( () => {
208223
const result = [];
209-
if (
210-
shouldDisplayCoreGradients &&
211-
coreGradients &&
212-
coreGradients.length
213-
) {
224+
if ( themeGradients && themeGradients.length ) {
214225
result.push( {
215-
name: __( 'Core' ),
216-
gradients: coreGradients,
226+
name: _x(
227+
'Theme',
228+
'Indicates this palette comes from the theme.'
229+
),
230+
gradients: themeGradients,
217231
} );
218232
}
219-
if ( themeGradients && themeGradients.length ) {
233+
if (
234+
shouldDisplayDefaultGradients &&
235+
defaultGradients &&
236+
defaultGradients.length
237+
) {
220238
result.push( {
221-
name: __( 'Theme' ),
222-
gradients: themeGradients,
239+
name: _x(
240+
'Default',
241+
'Indicates this palette comes from WordPress.'
242+
),
243+
gradients: defaultGradients,
223244
} );
224245
}
225-
if ( userGradients && userGradients.length ) {
246+
if ( customGradients && customGradients.length ) {
226247
result.push( {
227-
name: __( 'User' ),
228-
gradients: userGradients,
248+
name: _x(
249+
'Custom',
250+
'Indicates this palette is created by the user.'
251+
),
252+
gradients: customGradients,
229253
} );
230254
}
231255
return result;
232-
}, [ userGradients, themeGradients, coreGradients ] );
256+
}, [ customGradients, themeGradients, defaultGradients ] );
233257
return (
234258
<PanelColorGradientSettingsInner
235259
{ ...{ ...colorGradientSettings, ...props } }

packages/edit-site/src/components/global-styles/hooks.js

+43-25
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { get, cloneDeep, set, isEqual, has } from 'lodash';
66
/**
77
* WordPress dependencies
88
*/
9-
import { __ } from '@wordpress/i18n';
9+
import { _x } from '@wordpress/i18n';
1010
import { useContext, useCallback, useMemo } from '@wordpress/element';
1111
import {
1212
getBlockType,
@@ -218,57 +218,75 @@ export function getSupportedGlobalStylesPanels( name ) {
218218
}
219219

220220
export function useColorsPerOrigin( name ) {
221-
const [ userColors ] = useSetting( 'color.palette.user', name );
221+
const [ customColors ] = useSetting( 'color.palette.user', name );
222222
const [ themeColors ] = useSetting( 'color.palette.theme', name );
223-
const [ coreColors ] = useSetting( 'color.palette.core', name );
223+
const [ defaultColors ] = useSetting( 'color.palette.core', name );
224224
return useMemo( () => {
225225
const result = [];
226-
if ( coreColors && coreColors.length ) {
226+
if ( themeColors && themeColors.length ) {
227227
result.push( {
228-
name: __( 'Core' ),
229-
colors: coreColors,
228+
name: _x(
229+
'Theme',
230+
'Indicates this palette comes from the theme.'
231+
),
232+
colors: themeColors,
230233
} );
231234
}
232-
if ( themeColors && themeColors.length ) {
235+
if ( defaultColors && defaultColors.length ) {
233236
result.push( {
234-
name: __( 'Theme' ),
235-
colors: themeColors,
237+
name: _x(
238+
'Default',
239+
'Indicates this palette comes from WordPress.'
240+
),
241+
colors: defaultColors,
236242
} );
237243
}
238-
if ( userColors && userColors.length ) {
244+
if ( customColors && customColors.length ) {
239245
result.push( {
240-
name: __( 'User' ),
241-
colors: userColors,
246+
name: _x(
247+
'Custom',
248+
'Indicates this palette is created by the user.'
249+
),
250+
colors: customColors,
242251
} );
243252
}
244253
return result;
245-
}, [ userColors, themeColors, coreColors ] );
254+
}, [ customColors, themeColors, defaultColors ] );
246255
}
247256

248257
export function useGradientsPerOrigin( name ) {
249-
const [ userGradients ] = useSetting( 'color.gradients.user', name );
258+
const [ customGradients ] = useSetting( 'color.gradients.user', name );
250259
const [ themeGradients ] = useSetting( 'color.gradients.theme', name );
251-
const [ coreGradients ] = useSetting( 'color.gradients.core', name );
260+
const [ defaultGradients ] = useSetting( 'color.gradients.core', name );
252261
return useMemo( () => {
253262
const result = [];
254-
if ( coreGradients && coreGradients.length ) {
263+
if ( themeGradients && themeGradients.length ) {
255264
result.push( {
256-
name: __( 'Core' ),
257-
gradients: coreGradients,
265+
name: _x(
266+
'Theme',
267+
'Indicates this palette comes from the theme.'
268+
),
269+
gradients: themeGradients,
258270
} );
259271
}
260-
if ( themeGradients && themeGradients.length ) {
272+
if ( defaultGradients && defaultGradients.length ) {
261273
result.push( {
262-
name: __( 'Theme' ),
263-
gradients: themeGradients,
274+
name: _x(
275+
'Default',
276+
'Indicates this palette comes from WordPress.'
277+
),
278+
gradients: defaultGradients,
264279
} );
265280
}
266-
if ( userGradients && userGradients.length ) {
281+
if ( customGradients && customGradients.length ) {
267282
result.push( {
268-
name: __( 'User' ),
269-
gradients: userGradients,
283+
name: _x(
284+
'Custom',
285+
'Indicates this palette is created by the user.'
286+
),
287+
gradients: customGradients,
270288
} );
271289
}
272290
return result;
273-
}, [ userGradients, themeGradients, coreGradients ] );
291+
}, [ customGradients, themeGradients, defaultGradients ] );
274292
}

schemas/json/theme.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@
4545
"type": "boolean",
4646
"default": true
4747
},
48-
"corePalette": {
49-
"description": "Allow users to choose colors from the Core palette. \nGutenberg plugin required.",
50-
"type": "boolean",
51-
"default": true
52-
},
53-
"coreGradients": {
54-
"description": "Allow users to choose colors from the Core gradients. \nGutenberg plugin required.",
55-
"type": "boolean",
56-
"default": true
57-
},
5848
"custom": {
5949
"description": "Allow users to select custom colors.\nSince 5.8.",
6050
"type": "boolean",
@@ -70,6 +60,16 @@
7060
"type": "boolean",
7161
"default": true
7262
},
63+
"defaultGradients": {
64+
"description": "Allow users to choose colors from the default gradients. \nGutenberg plugin required.",
65+
"type": "boolean",
66+
"default": true
67+
},
68+
"defaultPalette": {
69+
"description": "Allow users to choose colors from the default palette. \nGutenberg plugin required.",
70+
"type": "boolean",
71+
"default": true
72+
},
7373
"duotone": {
7474
"description": "Duotone presets for the duotone picker.\nDoesn't generate classes or properties.\nSince 5.8.",
7575
"type": "array",

0 commit comments

Comments
 (0)