-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Global Styles: Try style system at site edit #20530
Changes from all commits
6bd655c
0aa67a0
b5e2d6f
207236f
6c92579
c30ce34
88dcd4e
b9a50e5
b317ba8
650947e
1a3f50b
a2dfea9
b49cd0d
9888d92
1b97ad7
96d9e9f
f1d75bb
76b6e04
e1413a8
8eb2bd9
413eadc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,11 +90,11 @@ function gutenberg_experimental_global_styles_get_user() { | |
* | ||
* @param array $post_status_filter Filter CPT by post status. | ||
* By default, only fetches published posts. | ||
* @param bool $should_create_draft Whether a new draft should be created | ||
* if no CPT was found. False by default. | ||
* @param bool $should_create_cpt Whether a new draft should be created | ||
* if no CPT was found. False by default. | ||
* @return array Custom Post Type for the user's Global Styles. | ||
*/ | ||
function gutenberg_experimental_global_styles_get_user_cpt( $post_status_filter = array( 'publish' ), $should_create_draft = false ) { | ||
function gutenberg_experimental_global_styles_get_user_cpt( $post_status_filter = array( 'publish' ), $should_create_cpt = false ) { | ||
$user_cpt = array(); | ||
$post_type_filter = 'wp_global_styles'; | ||
$post_name_filter = 'wp-global-styles-' . strtolower( wp_get_theme()->get( 'TextDomain' ) ); | ||
|
@@ -111,11 +111,11 @@ function gutenberg_experimental_global_styles_get_user_cpt( $post_status_filter | |
|
||
if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) { | ||
$user_cpt = $recent_posts[0]; | ||
} elseif ( $should_create_draft ) { | ||
} elseif ( $should_create_cpt ) { | ||
$cpt_post_id = wp_insert_post( | ||
array( | ||
'post_content' => '{}', | ||
'post_status' => 'draft', | ||
'post_status' => 'publish', | ||
'post_type' => $post_type_filter, | ||
'post_name' => $post_name_filter, | ||
), | ||
|
@@ -148,7 +148,7 @@ function gutenberg_experimental_global_styles_get_user_cpt_id() { | |
*/ | ||
function gutenberg_experimental_global_styles_get_core() { | ||
return gutenberg_experimental_global_styles_get_from_file( | ||
dirname( dirname( __FILE__ ) ) . '/experimental-default-global-styles.json' | ||
dirname( __FILE__ ) . '/global-styles/experimental-default-global-styles.json' | ||
); | ||
} | ||
|
||
|
@@ -164,15 +164,21 @@ function gutenberg_experimental_global_styles_get_theme() { | |
} | ||
|
||
/** | ||
* Takes a Global Styles tree and returns a CSS rule | ||
* Takes core, theme, and user preferences, | ||
* builds a single global styles tree and returns a CSS rule | ||
* that contains the corresponding CSS custom properties. | ||
* | ||
* @param array $global_styles Global Styles tree. | ||
* @return string CSS rule. | ||
*/ | ||
function gutenberg_experimental_global_styles_resolver( $global_styles ) { | ||
function gutenberg_experimental_global_styles_resolver() { | ||
$css_rule = ''; | ||
|
||
$global_styles = array_replace_recursive( | ||
gutenberg_experimental_global_styles_get_core(), | ||
gutenberg_experimental_global_styles_get_theme(), | ||
gutenberg_experimental_global_styles_get_user() | ||
); | ||
|
||
$token = '--'; | ||
$prefix = '--wp' . $token; | ||
$css_vars = gutenberg_experimental_global_styles_get_css_vars( $global_styles, $prefix, $token ); | ||
|
@@ -189,16 +195,6 @@ function gutenberg_experimental_global_styles_resolver( $global_styles ) { | |
return $css_rule; | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this check means that, if the FSE experiment is enabled, we'll load the CSS variables in all wp-admin, not only in edit-site pages. I did this because the CSS vars are now inlined into the block's CSS, so if I load the edit-post I'd expect it to work the same as the edit-site (variables are loaded, so blocks look the same). Another option would be to only load this in the edit-post & edit-site? I don't think that's necessary but happy to hear other thoughts. cc @jorgefilipecosta There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worth noting that if #21102 is merged, the editor content will be iframed, so CSS variables outside of that iframe would have no effect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Something to be mindful of in the iframe PR. We have ways to communicate into and out of the iframe, so it should be possible to set things properly in both. |
||
* Fetches the Global Styles for each level (core, theme, user) | ||
* and enqueues the resulting CSS custom properties for the editor. | ||
*/ | ||
function gutenberg_experimental_global_styles_enqueue_assets_editor() { | ||
if ( gutenberg_experimental_global_styles_is_site_editor() ) { | ||
gutenberg_experimental_global_styles_enqueue_assets(); | ||
} | ||
} | ||
|
||
/** | ||
* Fetches the Global Styles for each level (core, theme, user) | ||
* and enqueues the resulting CSS custom properties. | ||
|
@@ -208,13 +204,7 @@ function gutenberg_experimental_global_styles_enqueue_assets() { | |
return; | ||
} | ||
|
||
$global_styles = array_merge( | ||
gutenberg_experimental_global_styles_get_core(), | ||
gutenberg_experimental_global_styles_get_theme(), | ||
gutenberg_experimental_global_styles_get_user() | ||
); | ||
|
||
$inline_style = gutenberg_experimental_global_styles_resolver( $global_styles ); | ||
$inline_style = gutenberg_experimental_global_styles_resolver(); | ||
if ( empty( $inline_style ) ) { | ||
return; | ||
} | ||
|
@@ -224,51 +214,6 @@ function gutenberg_experimental_global_styles_enqueue_assets() { | |
wp_enqueue_style( 'global-styles' ); | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're no longer relying on the |
||
* Adds class wp-gs to the frontend body class. | ||
* | ||
* @param array $classes Existing body classes. | ||
* @return array The filtered array of body classes. | ||
*/ | ||
function gutenberg_experimental_global_styles_wp_gs_class_front_end( $classes ) { | ||
if ( ! gutenberg_experimental_global_styles_has_theme_support() ) { | ||
return $classes; | ||
} | ||
|
||
return array_merge( $classes, array( 'wp-gs' ) ); | ||
} | ||
|
||
/** | ||
* Adds class wp-gs to the block-editor body class. | ||
* | ||
* @param string $classes Existing body classes separated by space. | ||
* @return string The filtered string of body classes. | ||
*/ | ||
function gutenberg_experimental_global_styles_wp_gs_class_editor( $classes ) { | ||
if ( | ||
! gutenberg_experimental_global_styles_has_theme_support() || | ||
! gutenberg_experimental_global_styles_is_site_editor() | ||
) { | ||
return $classes; | ||
} | ||
|
||
return $classes . ' wp-gs'; | ||
} | ||
|
||
/** | ||
* Whether the loaded page is the site editor. | ||
* | ||
* @return boolean Whether the loaded page is the site editor. | ||
*/ | ||
function gutenberg_experimental_global_styles_is_site_editor() { | ||
if ( ! function_exists( 'get_current_screen' ) ) { | ||
return false; | ||
} | ||
|
||
$screen = get_current_screen(); | ||
return ! empty( $screen ) && gutenberg_is_edit_site_page( $screen->id ); | ||
} | ||
|
||
/** | ||
* Makes the base Global Styles (core, theme) | ||
* and the ID of the CPT that stores the user's Global Styles | ||
|
@@ -279,8 +224,7 @@ function gutenberg_experimental_global_styles_is_site_editor() { | |
*/ | ||
function gutenberg_experimental_global_styles_settings( $settings ) { | ||
if ( | ||
! gutenberg_experimental_global_styles_has_theme_support() || | ||
! gutenberg_experimental_global_styles_is_site_editor() | ||
! gutenberg_experimental_global_styles_has_theme_support() | ||
) { | ||
return $settings; | ||
} | ||
|
@@ -332,10 +276,8 @@ function gutenberg_experimental_global_styles_register_cpt() { | |
|
||
if ( gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' ) ) { | ||
add_action( 'init', 'gutenberg_experimental_global_styles_register_cpt' ); | ||
add_filter( 'body_class', 'gutenberg_experimental_global_styles_wp_gs_class_front_end' ); | ||
add_filter( 'admin_body_class', 'gutenberg_experimental_global_styles_wp_gs_class_editor' ); | ||
add_filter( 'block_editor_settings', 'gutenberg_experimental_global_styles_settings' ); | ||
// enqueue_block_assets is not fired in edit-site, so we use separate back/front hooks instead. | ||
add_action( 'wp_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets' ); | ||
add_action( 'admin_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets_editor' ); | ||
add_action( 'admin_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets' ); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved from the top-level. So posting here the old contents for comparison:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that I've removed the |
||
"color": { | ||
"background": "white", | ||
"text": "black" | ||
}, | ||
"typography": { | ||
"font-base": 16, | ||
"font-scale": 1.2, | ||
"font-weight-base": 400, | ||
"font-weight-heading": 400, | ||
"line-height-base": 1.5, | ||
"line-height-heading": 1.5 | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,6 @@ $blocks-button__height: 56px; | |
} | ||
} | ||
|
||
.wp-gs .wp-block-button__link:not(.has-background) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment. |
||
background-color: var(--wp--color--primary); | ||
} | ||
|
||
.is-style-squared .wp-block-button__link { | ||
border-radius: 0; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
h6 { | ||
background-color: var(--wp--color--background); | ||
color: var(--wp--color--text); | ||
line-height: var(--wp--typography--line-height); | ||
line-height: var(--wp--typography--line-height, var(--wp--typography--line-height-heading)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that, the line-height hook that is shown in the block inspector is using |
||
font-weight: var(--wp--typography--font-weight-heading); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just remove the "-heading" suffix given that we will probably not have block specific variables? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've commented on this at #20530 (comment) TLDR is that so far we don't have a way to do otherwise. I proposed a potential direction but it needs some adjustments before is ready. This is a discussion that also needs to address what do we do with font-size (used at the custom styles/block level) VS font base/scale (used at the global styles level) I mentioned at #20530 (comment) Those seem conversations we need to have before settling on anything, so I lean towards merging this and then iterate. How does it sound? |
||
} | ||
} | ||
|
||
|
@@ -21,3 +22,27 @@ h6 { | |
padding: $block-bg-padding--v $block-bg-padding--h; | ||
} | ||
} | ||
|
||
:root h1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the global styles UI, we aim to expose base and scale, and not font size directly. At the block UI level, we're instead inlining font-size values directly (see related PR to make font size an implicit attribute of the block). This may need some consolidation in further PRs. We also may do with some pre-generation of variables or/and with some improvements to the theme.json, as @jorgefilipecosta (suggested). I think we may want to explore that separately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you share a little clarification on this? Currently the styles here auto-generate heading sizes, and do so with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm so incredibly excited about these features to land, and some of my favorite people are working on this! However, and especially seeing the GIF above, the "base font" and "base scale" is the only aspect that feels unintuitive to me. I understand that the idea is to provide a harmonious typescale, and to provide a single control to affect all headings in one go. But my first question is "how do I adjust only the H2?" Tying this to a type-scale only, feels like it might end up frustrating users. What if I want my H2 to be almost exactly as big as my H1, and my H3 and H4 to be much smaller? If I'm reading this interface correctly, that's not possible in a global sense. More often than not the designs I've worked with use heading sizes that don't fit a typescale at all, but are still appropriate for the design in question. Many times they even use different font-weights or even fonts at different levels. Don't get me wrong, the type scale is impressive, and there are many reasons to use one. But to me the type scale feels like an option to offer, rather than being the default or only interface. CC: @karmatosed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few things at play here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of great conversation here. I wanted to pop in and first say nothing here is set. I think what was mocked up was a good first bet, let's maybe see where this needs iterating. There are a few options:
I can totally see maybe this is theme optional, maybe it all is for base font and type scale. I however, do see that a user could find this really magical being able to go up and down. Regarding individual headings, this is where I agree there needs to be some considered refinement. We are considering elements in groups, over individually. One option which is debatable if v1 or beyond (I could go either way), could be to have an option for more granular control 'reveal'. A simple then list of each heading could do that for headings. I'm totally into exploring around this. |
||
font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale)); | ||
} | ||
|
||
:root h2 { | ||
font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale)); | ||
} | ||
|
||
:root h3 { | ||
font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale)); | ||
} | ||
|
||
:root h4 { | ||
font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale)); | ||
} | ||
|
||
:root h5 { | ||
font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale)); | ||
} | ||
|
||
:root h6 { | ||
font-size: calc(0.5px * var(--wp--typography--font-base) * var(--wp--typography--font-scale)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is some probability that they will break many teams. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR adds font-size and font-weight to existing blocks that have already added CSS to target line-height and/or colors as CSS variables. Is there any reason we should treat font-size or font-weight differently? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For line height, and colors we use the variables but these variables can be defined by the user. E.g: the user can use the UI to change line-height, and colors. Here we use the variables and don't allow any control over the variables in most themes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see what you mean, thanks for the clarification 👍 Here's my thinking:
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was moved from the top-level to
lib/global-styles
as per this comment.