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

Support gradients with omitted stop positions in CustomGradientPicker #27413

Merged

Conversation

stokesman
Copy link
Contributor

@stokesman stokesman commented Dec 1, 2020

Description

Adds logic to test the color stops of the parsed gradient for any positions that are undefined or set with a unit other than percent. If some are found then each color stop in the gradient is reassigned a new equidistant position as percent.

Will fix #27382 and fix #23501 (duplicates).

Commentary

These changes were aimed at doing the simplest thing to prevent errors and support common use cases. The 'fixup' applied when stop positions are omitted is simpler than the spec (which wouldn't make sense to implement with the current UI). Additionally, a use case not handled by this is when stops are defined outside of 0-100:
linear-gradient( 135deg, crimson -10%, gold 50%, lime 110% )
Such cases produce no errors but the outside stops can be out of reach in the UI.

The reassignment of non-percentage units is coverage for an edge case not mentioned in either of the issues but is something that causes similar issues. It may be worthwhile to add some note about this in the documentation for the gradient presets, e.g. gradient presets support omitting positions or defining them in percentage only.

How has this been tested?

In WP 5.5.3

  1. Added these gradient presets to the theme:
"gradients": [
          {
            "slug": "azure-tan",
            "gradient": "linear-gradient( 135deg, #f0ffff, #d2b48c )"
          },
          {
            "slug": "turquoise-orange",
            "gradient": "linear-gradient( 135deg, #40e0d0 50px, #ffa500 100px )"
          },
          {
            "slug": "rastafarish",
            "gradient": "linear-gradient( 135deg, crimson 49.5%, gold, lime 50.5% )"
          },
          {
            "slug": "roygbiv",
            "gradient": "linear-gradient( 135deg, red 0%, orange 10%, yellow 20%, green 30%, blue 40%, indigo 50%, violet 60% )"
          },
          {
            "slug": "roygbiv-radial",
            "gradient": "radial-gradient( red, orange 10%, yellow 20%, green 30%, blue 40%, indigo 50%, violet 60% )"
          }
        ],
  1. Assigned each gradient to a Cover block.
  2. Verified that modifying the type of gradient (Linear/Radial) worked.
  3. Verified that modifying the angle of the graident worked.
  4. Verified that adding new stops to the gradient worked.

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@stokesman stokesman marked this pull request as ready for review December 1, 2020 22:58
@ItsJonQ ItsJonQ added the [Type] Bug An existing feature does not function as intended label Dec 3, 2020
@ItsJonQ ItsJonQ self-requested a review December 3, 2020 15:15
Copy link

@ItsJonQ ItsJonQ left a comment

Choose a reason for hiding this comment

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

🚀 from me! Thank you @stokesman !!

Tested this locally, and it is working as expected.

Screen Shot 2020-12-03 at 10 14 47 AM

It took be a bit to understand the assignColorStopLength, but it eventually clicked (MATH is hard, haha)

@ItsJonQ ItsJonQ merged commit 2f48b90 into WordPress:master Dec 3, 2020
@github-actions github-actions bot added this to the Gutenberg 9.6 milestone Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
2 participants