Skip to content

Commit f4b0aac

Browse files
Block Supports: Add presets to dimension block supports
1 parent eda8d9d commit f4b0aac

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

src/wp-includes/class-wp-theme-json.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ class WP_Theme_JSON {
215215
'classes' => array(),
216216
'properties' => array( 'border-radius' ),
217217
),
218+
array(
219+
'path' => array( 'dimensions', 'dimensionSizes' ),
220+
'prevent_override' => false,
221+
'use_default_names' => false,
222+
'value_key' => 'size',
223+
'css_vars' => '--wp--preset--dimension--$slug',
224+
'classes' => array(),
225+
'properties' => array( 'width', 'min-height' ),
226+
),
218227
);
219228

220229
/**
@@ -433,6 +442,7 @@ class WP_Theme_JSON {
433442
'aspectRatio' => null,
434443
'aspectRatios' => null,
435444
'defaultAspectRatios' => null,
445+
'dimensionSizes' => null,
436446
'minHeight' => null,
437447
),
438448
'layout' => array(

src/wp-includes/style-engine/class-wp-style-engine.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,16 @@ final class WP_Style_Engine {
216216
),
217217
'path' => array( 'dimensions', 'minHeight' ),
218218
'css_vars' => array(
219-
'spacing' => '--wp--preset--spacing--$slug',
219+
'dimension' => '--wp--preset--dimension--$slug',
220+
),
221+
),
222+
'width' => array(
223+
'property_keys' => array(
224+
'default' => 'width',
225+
),
226+
'path' => array( 'dimensions', 'width' ),
227+
'css_vars' => array(
228+
'dimension' => '--wp--preset--dimension--$slug',
220229
),
221230
),
222231
),

src/wp-includes/theme-i18n.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
{
4444
"name": "Aspect ratio name"
4545
}
46+
],
47+
"dimensionSizes": [
48+
{
49+
"name": "Dimension size name"
50+
}
4651
]
4752
},
4853
"shadow": {
@@ -95,6 +100,11 @@
95100
{
96101
"name": "Aspect ratio name"
97102
}
103+
],
104+
"dimensionSizes": [
105+
{
106+
"name": "Dimension size name"
107+
}
98108
]
99109
},
100110
"spacing": {

tests/phpunit/tests/style-engine/styleEngine.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ public function data_wp_style_engine_get_styles() {
119119
),
120120
),
121121

122+
'inline_valid_dimension_preset_style' => array(
123+
'block_styles' => array(
124+
'dimensions' => array(
125+
'width' => 'var:preset|dimension|large',
126+
),
127+
),
128+
'options' => null,
129+
'expected_output' => array(
130+
'css' => 'width:var(--wp--preset--dimension--large);',
131+
'declarations' => array(
132+
'width' => 'var(--wp--preset--dimension--large)',
133+
),
134+
),
135+
),
136+
122137
'inline_valid_box_model_style' => array(
123138
'block_styles' => array(
124139
'spacing' => array(

tests/phpunit/tests/theme/wpThemeJson.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,20 @@ public function test_get_stylesheet() {
418418
),
419419
),
420420
),
421+
'dimensions' => array(
422+
'dimensionSizes' => array(
423+
array(
424+
'name' => 'Small',
425+
'slug' => 'small',
426+
'size' => '100px',
427+
),
428+
array(
429+
'name' => 'Large',
430+
'slug' => 'large',
431+
'size' => '200px',
432+
),
433+
),
434+
),
421435
'color' => array(
422436
'text' => 'value',
423437
'palette' => array(
@@ -508,6 +522,7 @@ public function test_get_stylesheet() {
508522
),
509523
'dimensions' => array(
510524
'minHeight' => '50vh',
525+
'width' => 'var:preset|dimension|large',
511526
),
512527
'elements' => array(
513528
'link' => array(
@@ -584,8 +599,8 @@ public function test_get_stylesheet() {
584599
)
585600
);
586601

587-
$variables = ':root{--wp--preset--color--grey: grey;--wp--preset--gradient--custom-gradient: linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%);--wp--preset--font-size--small: 14px;--wp--preset--font-size--big: 41px;--wp--preset--font-family--arial: Arial, serif;--wp--preset--border-radius--small: 2px;--wp--preset--border-radius--medium: 4px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}';
588-
$styles = ':where(body) { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}.is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}.is-layout-flex{flex-wrap: wrap;align-items: center;}.is-layout-flex > :is(*, div){margin: 0;}body .is-layout-grid{display: grid;}.is-layout-grid > :is(*, div){margin: 0;}body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}:root :where(.wp-element-button, .wp-block-button__link){box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}:root :where(.wp-block-cover){min-height: unset;aspect-ratio: 16/9;border-radius: var(--wp--preset--border-radius--small);}:root :where(.wp-block-group){background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;min-height: 50vh;padding: 24px;}:root :where(.wp-block-group a:where(:not(.wp-element-button))){color: #111;}:root :where(.wp-block-heading){color: #123456;}:root :where(.wp-block-heading a:where(:not(.wp-element-button))){background-color: #333;color: #111;font-size: 60px;}:root :where(.wp-block-media-text){text-align: center;}:root :where(.wp-block-post-date){color: #123456;}:root :where(.wp-block-post-date a:where(:not(.wp-element-button))){background-color: #777;color: #555;}:root :where(.wp-block-post-excerpt){column-count: 2;}:root :where(.wp-block-image){margin-bottom: 30px;}:root :where(.wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder){border-top-left-radius: 10px;border-bottom-right-radius: 1em;}:root :where(.wp-block-image img, .wp-block-image .components-placeholder){filter: var(--wp--preset--duotone--custom-duotone);}';
602+
$variables = ':root{--wp--preset--color--grey: grey;--wp--preset--gradient--custom-gradient: linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%);--wp--preset--font-size--small: 14px;--wp--preset--font-size--big: 41px;--wp--preset--font-family--arial: Arial, serif;--wp--preset--border-radius--small: 2px;--wp--preset--border-radius--medium: 4px;--wp--preset--dimension--small: 100px;--wp--preset--dimension--large: 200px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}';
603+
$styles = ':where(body) { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}.is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}.is-layout-flex{flex-wrap: wrap;align-items: center;}.is-layout-flex > :is(*, div){margin: 0;}body .is-layout-grid{display: grid;}.is-layout-grid > :is(*, div){margin: 0;}body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}:root :where(.wp-element-button, .wp-block-button__link){box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}:root :where(.wp-block-cover){min-height: unset;aspect-ratio: 16/9;border-radius: var(--wp--preset--border-radius--small);}:root :where(.wp-block-group){background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;min-height: 50vh;padding: 24px;width: var(--wp--preset--dimension--large);}:root :where(.wp-block-group a:where(:not(.wp-element-button))){color: #111;}:root :where(.wp-block-heading){color: #123456;}:root :where(.wp-block-heading a:where(:not(.wp-element-button))){background-color: #333;color: #111;font-size: 60px;}:root :where(.wp-block-media-text){text-align: center;}:root :where(.wp-block-post-date){color: #123456;}:root :where(.wp-block-post-date a:where(:not(.wp-element-button))){background-color: #777;color: #555;}:root :where(.wp-block-post-excerpt){column-count: 2;}:root :where(.wp-block-image){margin-bottom: 30px;}:root :where(.wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder){border-top-left-radius: 10px;border-bottom-right-radius: 1em;}:root :where(.wp-block-image img, .wp-block-image .components-placeholder){filter: var(--wp--preset--duotone--custom-duotone);}';
589604
$presets = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-custom-gradient-gradient-background{background: var(--wp--preset--gradient--custom-gradient) !important;}.has-small-font-size{font-size: var(--wp--preset--font-size--small) !important;}.has-big-font-size{font-size: var(--wp--preset--font-size--big) !important;}.has-arial-font-family{font-family: var(--wp--preset--font-family--arial) !important;}';
590605
$all = $variables . $styles . $presets;
591606

0 commit comments

Comments
 (0)