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 labels to the global styles variations #39322

Merged
merged 9 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ public function get_theme_items( $request ) {
foreach ( $nested_html_files as $path => $file ) {
$decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) );
if ( is_array( $decoded_file ) ) {
$variations[] = ( new WP_Theme_JSON_Gutenberg( $decoded_file ) )->get_raw_data();
$variation = ( new WP_Theme_JSON_Gutenberg( $decoded_file ) )->get_raw_data();
if ( ! isset( $variation['name'] ) ) {
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
$variation['name'] = basename( $path, '.json' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure the name of the file is quite right for using in this case. Maybe mark it as "No name provided"? That would make more sense to me than hearing the name of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The filename in empty theme example is not very representative IMO and I feel like most file names will be in this case personally.

}
$variations[] = $variation;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WP_Theme_JSON_Gutenberg extends WP_Theme_JSON_5_9 {
'styles',
'templateParts',
'version',
'name',
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { useMemo, useContext } from '@wordpress/element';
import { ENTER } from '@wordpress/keycodes';
import {
__experimentalGrid as Grid,
__experimentalVStack as VStack,
__experimentalHStack as HStack,
Card,
CardBody,
} from '@wordpress/components';
Expand Down Expand Up @@ -78,7 +80,12 @@ function Variation( { variation } ) {
onKeyDown={ selectOnEnter }
tabIndex="0"
>
<StylesPreview height={ 100 } />
<VStack spacing="2">
<div className="edit-site-global-styles-variations_item-preview">
<StylesPreview height={ 100 } />
</div>
<HStack alignment="center">{ variation?.name }</HStack>
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
</VStack>
</div>
</GlobalStylesContext.Provider>
);
Expand Down
15 changes: 9 additions & 6 deletions packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,22 @@

.edit-site-global-styles-variations_item {
box-sizing: border-box;
padding: $border-width * 2;
border-radius: $radius-block-ui;
border: $gray-200 $border-width solid;

&.is-active {
.edit-site-global-styles-variations_item-preview {
padding: $border-width * 2;
border-radius: $radius-block-ui;
border: $gray-200 $border-width solid;
}

&.is-active .edit-site-global-styles-variations_item-preview {
border: $gray-900 $border-width solid;
}

&:hover {
&:hover .edit-site-global-styles-variations_item-preview {
border: var(--wp-admin-theme-color) $border-width solid;
}

&:focus {
&:focus .edit-site-global-styles-variations_item-preview {
border: var(--wp-admin-theme-color) $border-width solid;
}
}