Make WordPress Core

Changeset 55176


Ignore:
Timestamp:
02/01/2023 06:05:44 PM (4 years ago)
Author:
hellofromTonya
Message:

Themes: Add shadow presets support for theme.json.

Adds shadow presets support for theme.json within the WP_Theme_JSON by

  • Adding it to presets metadata and valid settings.
  • Defining the default shadow presets in Core's theme.json.

Includes PHPUnit tests.

References:

Follow-up to [54162], [52049], [50973].

Props madhudollu, mamaduka, oandregal, scruffian, hellofromTonya.
Fixes #57559.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r55175 r55176  
    116116         * @since 6.0.0 Replaced `override` with `prevent_override` and updated the
    117117         *              `prevent_override` value for `color.duotone` to use `color.defaultDuotone`.
     118         * @since 6.2.0 Added 'shadow' presets.
    118119         * @var array
    119120         */
    … …  
    177178                        'properties'        => array( 'padding', 'margin' ),
    178179                ),
     180                array(
     181                        'path'              => array( 'shadow', 'presets' ),
     182                        'prevent_override'  => array( 'shadow', 'defaultPresets' ),
     183                        'use_default_names' => false,
     184                        'value_key'         => 'shadow',
     185                        'css_vars'          => '--wp--preset--shadow--$slug',
     186                        'classes'           => array(),
     187                        'properties'        => array( 'box-shadow' ),
     188                ),
    179189        );
    180190
    … …  
    295305         * @since 6.0.0 Added `color.defaultDuotone`.
    296306         * @since 6.1.0 Added `layout.definitions` and `useRootPaddingAwareAlignments`.
    297          * @since 6.2.0 Added `dimensions.minHeight`.
     307         * @since 6.2.0 Added `dimensions.minHeight`, 'shadow.presets', and 'shadow.defaultPresets'.
    298308         * @var array
    299309         */
    … …  
    338348                        'padding'           => null,
    339349                        'units'             => null,
     350                ),
     351                'shadow'                        => array(
     352                        'presets'        => null,
     353                        'defaultPresets' => null,
    340354                ),
    341355                'typography'                    => array(
  • trunk/src/wp-includes/theme.json

    r54162 r55176  
    325325                                }
    326326                        }
     327                },
     328                "shadow": {
     329                        "presets": [
     330                                {
     331                                        "name": "Natural",
     332                                        "slug": "natural",
     333                                        "shadow": "0 .2rem .3rem 0 rgba(0,0,0, 0.3), 0 .5rem .6rem 0 rgba(0,0,0, 0.4)"
     334                                },
     335                                {
     336                                        "name": "Sharp",
     337                                        "slug": "sharp",
     338                                        "shadow": ".5rem .5rem 0 0 rgba(0,0,0, 0.4)"
     339                                }
     340                        ]
    327341                },
    328342                "spacing": {
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r55175 r55176  
    44354435                $this->assertSame( $expected, $theme_json->get_stylesheet() );
    44364436        }
     4437
     4438        /**
     4439         * @ticket 57559
     4440         */
     4441        public function test_shadow_preset_styles() {
     4442                $theme_json = new WP_Theme_JSON(
     4443                        array(
     4444                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     4445                                'settings' => array(
     4446                                        'shadow' => array(
     4447                                                'presets' => array(
     4448                                                        array(
     4449                                                                'slug'   => 'natural',
     4450                                                                'shadow' => '5px 5px 5px 0 black',
     4451                                                        ),
     4452                                                        array(
     4453                                                                'slug'   => 'sharp',
     4454                                                                'shadow' => '5px 5px black',
     4455                                                        ),
     4456                                                ),
     4457                                        ),
     4458                                ),
     4459                        )
     4460                );
     4461
     4462                $expected_styles = 'body{--wp--preset--shadow--natural: 5px 5px 5px 0 black;--wp--preset--shadow--sharp: 5px 5px black;}';
     4463                $this->assertSame( $expected_styles, $theme_json->get_stylesheet(), 'Styles returned from "::get_stylesheet()" does not match expectations' );
     4464                $this->assertSame( $expected_styles, $theme_json->get_stylesheet( array( 'variables' ) ), 'Styles returned from "::get_stylesheet()" when requiring "variables" type does not match expectations' );
     4465        }
     4466
     4467        /**
     4468         * @ticket 57559
     4469         */
     4470        public function test_get_shadow_styles_for_blocks() {
     4471                $theme_json = new WP_Theme_JSON(
     4472                        array(
     4473                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     4474                                'settings' => array(
     4475                                        'shadow' => array(
     4476                                                'presets' => array(
     4477                                                        array(
     4478                                                                'slug'   => 'natural',
     4479                                                                'shadow' => '5px 5px 0 0 black',
     4480                                                        ),
     4481                                                ),
     4482                                        ),
     4483                                ),
     4484                                'styles'   => array(
     4485                                        'blocks'   => array(
     4486                                                'core/paragraph' => array(
     4487                                                        'shadow' => 'var(--wp--preset--shadow--natural)',
     4488                                                ),
     4489                                        ),
     4490                                        'elements' => array(
     4491                                                'button' => array(
     4492                                                        'shadow' => 'var:preset|shadow|natural',
     4493                                                ),
     4494                                                'link'   => array(
     4495                                                        'shadow' => array( 'ref' => 'styles.elements.button.shadow' ),
     4496                                                ),
     4497                                        ),
     4498                                ),
     4499                        )
     4500                );
     4501
     4502                $global_styles   = 'body{--wp--preset--shadow--natural: 5px 5px 0 0 black;}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; }';
     4503                $element_styles  = 'a:where(:not(.wp-element-button)){box-shadow: var(--wp--preset--shadow--natural);}.wp-element-button, .wp-block-button__link{box-shadow: var(--wp--preset--shadow--natural);}p{box-shadow: var(--wp--preset--shadow--natural);}';
     4504                $expected_styles = $global_styles . $element_styles;
     4505
     4506                $this->assertSame( $expected_styles, $theme_json->get_stylesheet() );
     4507        }
    44374508}
Note: See TracChangeset for help on using the changeset viewer.