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

Add a description key to theme.json style variations #45242

Merged
merged 20 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
735698b
Try adding description as a top level key in theme.json
carolinan Oct 24, 2022
dcdf77a
add the key to WP_Theme_JSON_6_0 instead
carolinan Oct 24, 2022
cbb6523
Update theme-i18n.json
carolinan Oct 25, 2022
fd4fdcf
Update screen-style-variations.js
carolinan Oct 25, 2022
ca3f8f7
Merge branch 'trunk' into try/add-description-top-level-key
carolinan Oct 27, 2022
ed736e0
Update screen-style-variations.js
carolinan Nov 4, 2022
997bdb3
Update screen-style-variations.js
carolinan Nov 4, 2022
25a4a06
trying to solve merge conflicts since 6.0 compat files were removed.
carolinan Dec 13, 2022
75f8bef
Merge branch 'trunk' into try/add-description-top-level-key
carolinan Dec 13, 2022
6e5bde2
try to re-add description as a valid top level key
carolinan Dec 13, 2022
c25183b
Revert changes to resolve merge conflicts
carolinan Dec 30, 2022
ed5f1cd
Merge branch 'trunk' into try/add-description-top-level-key
carolinan Dec 30, 2022
dd0be62
re-add description to VALID_TOP_LEVEL_KEYS
carolinan Dec 30, 2022
d4a2a40
Merge branch 'trunk' into try/add-description-top-level-key
carolinan Apr 12, 2023
290f948
try to resolve issues after the merge conflict
carolinan Apr 12, 2023
bafae06
Merge branch 'trunk' into try/add-description-top-level-key
carolinan Apr 19, 2023
0f9582a
Try to solve merge conflicts
carolinan May 20, 2023
b4a7255
Merge branch 'trunk' into try/add-description-top-level-key
carolinan May 20, 2023
71353d6
Update style-variations-container.js
carolinan May 20, 2023
0d23174
Merge branch 'trunk' into try/add-description-top-level-key
carolinan Jun 14, 2023
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
2 changes: 2 additions & 0 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,12 @@ class WP_Theme_JSON_Gutenberg {
* @since 5.8.0 As `ALLOWED_TOP_LEVEL_KEYS`.
* @since 5.9.0 Renamed from `ALLOWED_TOP_LEVEL_KEYS` to `VALID_TOP_LEVEL_KEYS`,
* added the `customTemplates` and `templateParts` values.
* @since 6.3.0 Added the `description` value.
* @var string[]
*/
const VALID_TOP_LEVEL_KEYS = array(
'customTemplates',
'description',
'patterns',
'settings',
'styles',
Expand Down
1 change: 1 addition & 0 deletions lib/theme-i18n.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Style variation name",
"description": "Style variation description",
"settings": {
"typography": {
"fontSizes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useSelect } from '@wordpress/data';
import { useMemo, useContext, useState } from '@wordpress/element';
import { ENTER } from '@wordpress/keycodes';
import { __experimentalGrid as Grid } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';

/**
Expand Down Expand Up @@ -60,6 +60,16 @@ function Variation( { variation } ) {
return areGlobalStyleConfigsEqual( user, variation );
}, [ user, variation ] );

let label = variation?.title;
if ( variation?.description ) {
label = sprintf(
/* translators: %1$s: variation title. %2$s variation description. */
__( '%1$s (%2$s)' ),
variation?.title,
variation?.description
);
}

return (
<GlobalStylesContext.Provider value={ context }>
<div
Expand All @@ -73,7 +83,7 @@ function Variation( { variation } ) {
onClick={ selectVariation }
onKeyDown={ selectOnEnter }
tabIndex="0"
aria-label={ variation?.title }
aria-label={ label }
aria-current={ isActive }
onFocus={ () => setIsFocused( true ) }
onBlur={ () => setIsFocused( false ) }
Expand Down
4 changes: 4 additions & 0 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,10 @@
"type": "string",
"description": "Title of the global styles variation. If not defined, the file name will be used."
},
"description": {
"type": "string",
"description": "Description of the global styles variation."
},
"settings": {
"description": "Settings for the block editor and individual blocks. These include things like:\n- Which customization options should be available to the user. \n- The default colors, font sizes... available to the user. \n- CSS custom properties and class names used in styles.\n- And the default layout of the editor (widths and available alignments).",
"type": "object",
Expand Down