Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Try styling Search and File buttons #202

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function twentytwentytwo_styles() {
// Add styles inline.
wp_add_inline_style( 'twentytwentytwo-style', twentytwentytwo_get_font_face_styles() );

// Add global styles linked variables.
wp_add_inline_style( 'twentytwentytwo-style', twentytwentytwo_theme_variables() );

// Add metadata to the CSS stylesheet.
wp_style_add_data( 'twentytwentytwo-style', 'path', get_template_directory() . '/style.css' );

Expand All @@ -56,6 +59,22 @@ function twentytwentytwo_styles() {

endif;

/**
* Create variables linked to global styles.
*
* @return string
*/
function twentytwentytwo_theme_variables() {
if ( ! function_exists( 'gutenberg_get_global_styles' ) ) {
return;
}

// Get the properties of the button that we want to use in other blocks like search and file.
$button_styles = gutenberg_get_global_styles( array(), 'core/button' );

// Create variables that point to the value of those customizable properties.
return ':root, body { --wp--theme--button--color--text: ' . $button_styles['color']['text'] . '; --wp--theme--button--color--background: ' . $button_styles['color']['background'] . '; --wp--theme--button--border--radius: ' . $button_styles['border']['radius'] . '; }';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FWIW I'm hesitant to add a workaround like this to the theme. Open to other opinions and feedback.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, this feels just a bit too complicated for my liking. Since this is the sort of thing that should most definitely be handled natively by Gutenberg at some point, I lean towards not patching it in the theme. 😕

I'm not too concerned about the file block, but the Search block seems like a higher priority since we're actually using that in a template.

}

if ( ! function_exists( 'twentytwentytwo_editor_styles' ) ) :

Expand All @@ -69,6 +88,12 @@ function twentytwentytwo_editor_styles() {
// Add styles inline.
wp_add_inline_style( 'wp-block-library', twentytwentytwo_get_font_face_styles() );

// Add global styles linked variables.
wp_add_inline_style( 'wp-block-library', twentytwentytwo_theme_variables() );

// Add stylesheet.
add_editor_style( array( get_stylesheet_uri() ) );

}
add_action( 'admin_init', 'twentytwentytwo_editor_styles' );

Expand Down
9 changes: 9 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ Tags: one-column, custom-colors, custom-menu, custom-logo, editor-style, feature
Twenty Twenty-Two WordPress Theme, (C) 2021 WordPress.org
Twenty Twenty-Two is distributed under the terms of the GNU GPL.
*/

.wp-block-search__button,
.wp-block-file .wp-block-file__button {
background-color: var(--wp--theme--button--color--background);
border: none;
border-radius: var(--wp--theme--button--border--radius);
color: var(--wp--theme--button--color--text);
cursor: pointer;
}