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

Shadow: revert shadow default presets opt-in to opt-out #60204

Merged
merged 2 commits into from
Apr 2, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Setting that enables the following UI tools:
- position: sticky
- spacing: blockGap, margin, padding
- typography: lineHeight
- shadow: defaultPresets


---
Expand Down Expand Up @@ -73,7 +72,7 @@ Settings related to shadows.

| Property | Type | Default | Props |
| --- | --- | --- |--- |
| defaultPresets | boolean | false | |
| defaultPresets | boolean | true | |
| presets | array | | name, shadow, slug |

---
Expand Down
1 change: 0 additions & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ public static function get_element_class_name( $element ) {
array( 'spacing', 'margin' ),
array( 'spacing', 'padding' ),
array( 'typography', 'lineHeight' ),
array( 'shadow', 'defaultPresets' ),
);

/**
Expand Down
11 changes: 11 additions & 0 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ public static function get_theme_data( $deprecated = array(), $options = array()
}
$theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;

if ( ! isset( $theme_support_data['settings']['shadow'] ) ) {
$theme_support_data['settings']['shadow'] = array();
}
/*
* Shadow presets are explicitly disabled for classic themes until a
* decision is made for whether the default presets should match the
* other presets or if they should be disabled by default in classic
* themes. See https://github.com/WordPress/gutenberg/issues/59989.
*/
$theme_support_data['settings']['shadow']['defaultPresets'] = false;

// Allow themes to enable all border settings via theme_support.
if ( current_theme_supports( 'border' ) ) {
$theme_support_data['settings']['border']['color'] = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"text": true
},
"shadow": {
"defaultPresets": false,
"defaultPresets": true,
"presets": [
{
"name": "Natural",
Expand Down
100 changes: 100 additions & 0 deletions phpunit/class-wp-theme-json-resolver-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ public function test_translations_are_applied() {
'padding' => true,
'blockGap' => true,
),
'shadow' => array(
'presets' => array(
'theme' => array(
array(
'name' => 'Natural',
'slug' => 'natural',
'shadow' => '2px 2px 3px #000',
),
array(
'name' => 'Test',
'slug' => 'test',
'shadow' => '2px 2px 3px #000',
),
),
),
),
'blocks' => array(
'core/paragraph' => array(
'color' => array(
Expand Down Expand Up @@ -540,6 +556,22 @@ public function test_merges_child_theme_json_into_parent_theme_json() {
),
),
),
'shadow' => array(
'presets' => array(
'theme' => array(
array(
'name' => 'Natural',
'slug' => 'natural',
'shadow' => '2px 2px 3px #000',
),
array(
'name' => 'Test',
'slug' => 'test',
'shadow' => '2px 2px 3px #000',
),
),
),
),
'spacing' => array(
'blockGap' => true,
'units' => array( 'rem' ),
Expand Down Expand Up @@ -1039,4 +1071,72 @@ public function test_get_style_variations_returns_all_variations() {
$actual_settings
);
}

public function test_theme_shadow_presets_do_not_override_default_shadow_presets() {
switch_theme( 'block-theme' );

$theme_json_resolver = new WP_Theme_JSON_Resolver_Gutenberg();
$theme_json = $theme_json_resolver->get_merged_data();
$actual_settings = $theme_json->get_settings()['shadow']['presets'];

$expected_settings = array(
'default' => array(
array(
'name' => 'Natural',
'shadow' => '6px 6px 9px rgba(0, 0, 0, 0.2)',
'slug' => 'natural',
),
array(
'name' => 'Deep',
'shadow' => '12px 12px 50px rgba(0, 0, 0, 0.4)',
'slug' => 'deep',
),
array(
'name' => 'Sharp',
'shadow' => '6px 6px 0px rgba(0, 0, 0, 0.2)',
'slug' => 'sharp',
),
array(
'name' => 'Outlined',
'shadow' => '6px 6px 0px -3px rgba(255, 255, 255, 1), 6px 6px rgba(0, 0, 0, 1)',
'slug' => 'outlined',
),
array(
'name' => 'Crisp',
'shadow' => '6px 6px 0px rgba(0, 0, 0, 1)',
'slug' => 'crisp',
),
),
'theme' => array(
array(
'name' => 'Test',
'shadow' => '2px 2px 3px #000',
'slug' => 'test',
),
),
);

wp_recursive_ksort( $actual_settings );
wp_recursive_ksort( $expected_settings );

$this->assertSame(
$expected_settings,
$actual_settings
);
}

public function test_shadow_default_presets_value_for_block_and_classic_themes() {
$theme_json_resolver = new WP_Theme_JSON_Resolver_Gutenberg();
$theme_json = $theme_json_resolver->get_merged_data();

$default_presets_for_classic = $theme_json->get_settings()['shadow']['defaultPresets'];
$this->assertFalse( $default_presets_for_classic );

switch_theme( 'block-theme' );
$theme_json_resolver = new WP_Theme_JSON_Resolver_Gutenberg();
$theme_json = $theme_json_resolver->get_merged_data();

$default_presets_for_block = $theme_json->get_settings()['shadow']['defaultPresets'];
$this->assertTrue( $default_presets_for_block );
}
}
6 changes: 0 additions & 6 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,6 @@ public function test_get_settings_appearance_true_opts_in() {
'typography' => array(
'lineHeight' => true,
),
'shadow' => array(
'defaultPresets' => true,
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
Expand Down Expand Up @@ -331,9 +328,6 @@ public function test_get_settings_appearance_true_opts_in() {
'typography' => array(
'lineHeight' => false,
),
'shadow' => array(
'defaultPresets' => true,
),
),
),
);
Expand Down
14 changes: 14 additions & 0 deletions phpunit/data/themedir1/block-theme/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
"padding": true,
"blockGap": true
},
"shadow": {
"presets": [
{
"name": "Natural",
"slug": "natural",
"shadow": "2px 2px 3px #000"
},
{
"name": "Test",
"slug": "test",
"shadow": "2px 2px 3px #000"
}
]
},
"blocks": {
"core/paragraph": {
"color": {
Expand Down
4 changes: 2 additions & 2 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"type": "object",
"properties": {
"appearanceTools": {
"description": "Setting that enables the following UI tools:\n\n- background: backgroundImage, backgroundSize\n- border: color, radius, style, width\n- color: link, heading, button, caption\n- dimensions: aspectRatio, minHeight\n- position: sticky\n- spacing: blockGap, margin, padding\n- typography: lineHeight\n- shadow: defaultPresets",
"description": "Setting that enables the following UI tools:\n\n- background: backgroundImage, backgroundSize\n- border: color, radius, style, width\n- color: link, heading, button, caption\n- dimensions: aspectRatio, minHeight\n- position: sticky\n- spacing: blockGap, margin, padding\n- typography: lineHeight",
"type": "boolean",
"default": false
}
Expand Down Expand Up @@ -77,7 +77,7 @@
"defaultPresets": {
"description": "Allow users to choose shadows from the default shadow presets.",
"type": "boolean",
"default": false
"default": true
},
"presets": {
"description": "Shadow presets for the shadow picker.\nGenerates a single custom property (`--wp--preset--shadow--{slug}`) per preset value.",
Expand Down
Loading