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

Add custom gradient component #17603

Merged
merged 7 commits into from
Dec 5, 2019
Merged

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Sep 26, 2019

Description

Issued discussing the design: #16662

This PR is a WIP with the objective of implementing a custom gradient component.

The objective is to get something similar to:
image

But for now, we are not yet trying to get that design pixel perfect it is more important to test the interactions.

The small gradient component should be able to:

  • Add new control points in a given position with a given color.
  • Change the color of the control point in a gradient.
  • Remove a gradient control point.
  • Move a control point position e.g: from 0% to 20%.

This version misses the ability to move a control point. The implementation is getting complex and I would like some intermediary feedback about this path before implementing it. The idea I have is simply being able to drag the control points.

Besides this small visual component we also need inputs to select between radial and linear gradients and the angle. My idea is to use our existing input components for that. We will also probably need to allow to edit the control points in a normal input for a11y reasons, using drag & drop is not accessible to everyone.

For now, I would like some feedback on what we have and thoughts if we need to change direction.

The code is not polished yet.

How has this been tested?

I added a button.
I tried to create some gradients using the custom gradients bar.

Screenshots

Sep-26-2019 10-43-56

@melchoyce
Copy link
Contributor

Only thing that feels weird is that you can select both a background color, and a gradient. Maybe we could consider adding a toggle that has you choose to either use a solid color, or a gradient:

image

(Please excuse the giant toggles, I threw this together in a couple minutes)

@joyously
Copy link

joyously commented Oct 1, 2019

I think that since the gradient colors can be semi-transparent, it makes sense to be able to choose a background color and a gradient.

@enriquesanchez
Copy link
Contributor

enriquesanchez commented Oct 1, 2019

I agree with @melchoyce. I think that there should be a toggle to choose between solid or gradient.

Some screen from popular design apps for inspiration:

Figma

Screen Shot 2019-10-01 at 4 22 26 PM

Sketch

Screen Shot 2019-10-01 at 4 23 09 PM

I don't think we need to go as far as having a dropdown or long list of options here because we wouldn't have this many options. A toggle should suffice.

@jorgefilipecosta jorgefilipecosta force-pushed the add/custom-gradient-component branch 2 times, most recently from 835598f to 31588dc Compare November 25, 2019 12:11
@jorgefilipecosta
Copy link
Member Author

Hi @mtias,
Do you consider the tabs between solid color and gradient a blocker or we can try to land this custom gradient UI and then try to have a tabbed design?

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

I still need to review in more detail, but here's some rough initial feedback.

  • Product-wise, it feels nice, and I think we can iterate from here.
  • It's not fully keyboard accessible, but I also think we can iterate afterwards, as this PR is already large.

return [];
}
return map( parsedGradient.colorStops, ( colorStop ) => {
if ( ! colorStop || ! colorStop.length || colorStop.length.type !== '%' ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

colorStop.length.type !== '%'

Is this right?

Edit: Ah, I just saw getGradientWithColorStopAdded, gotcha. I do feel, though, that there is a lot of new domain to assimilate across these files. Maybe it's a necessary evil — in which case we could create some new JSDoc types and document a bit — maybe it's something we can reduce.

Copy link
Member Author

Choose a reason for hiding this comment

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

This structure comes from the gradient-parser package which provides an AST for gradients. I agree it is not easy to understand the structure. I added a link to the package where the structure is documented. I made sure all the functions that need knowledge about this structure are defined on the same fil. I added JSDOCS to getMarkerPoints function which returns an array derived from this structure. I hope these changes make things simpler to understand.

@jorgefilipecosta jorgefilipecosta force-pushed the add/custom-gradient-component branch 2 times, most recently from a44e038 to 6455760 Compare December 4, 2019 12:47
@jorgefilipecosta
Copy link
Member Author

Hi @mcsf, I tried to address your review. I also did a refactor to the components to simplify its logic using a reduce/state machine-based approach. I hope these changes make the code easier to review.

@mtias
Copy link
Member

mtias commented Dec 4, 2019

@jorgefilipecosta I would like to avoid this to hang in a few plugin releases (lack of tabbed interface) if we don't address it soon as it adds significant weight to the inspector settings.

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

This is a pretty big PR and I can't review it thoroughly! But I've done a few passes and it looks good overall. The items I raised need to be addressed, but after that go ahead and merge so that we can iterate more quickly. The API itself for CustomGradientPicker is small and nice. :)

}

/**
* Get the connection state.
Copy link
Contributor

Choose a reason for hiding this comment

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

Stray comment? :)

const onMouseUp = () => {
if ( window && window.removeEventListener ) {
window.removeEventListener( 'mousemove', onMouseMove );
window.removeEventListener( 'mouseup', onMouseUp );
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also remove the listeners on unmount? Relying only on a pending mouseup event to take care of the cleanup feels fragile.

@mcsf
Copy link
Contributor

mcsf commented Dec 5, 2019

To address separately:

Captura de ecrã 2019-12-05, às 17 46 00

Mispositioned popover (Firefox Beta, macOS stable).

jorgefilipecosta and others added 7 commits December 5, 2019 22:18
Squashed commits:
[4ee9051258] Avoid moving over other control points
[479d199cfe] Add mechanism that allows themes disabling custom gradients.
[37bc638743] Polish gradients further, and the gradient stops.

Polish some of the gradient stop dimensions.

Tweak the gradient presets to have fewer in the same hue.
[9778bef873] Polish, better gradients, better spacing.

This commit improves a few things:

- It better spaces the items, so that there can be 6 swatches on a line. And works both with and without scrollbar.
- It polishes the gradient customizer so that the handles are perfectly placed in the curves of the slider.
- It removes a few of the more muddy gradient presets.
[0c23c3d962] Improved a11y
[c0fd4d6b97] Code refactor (+2 squashed commits)
Squashed commits:
[cc33664] Refactor and improvements
[f044457] Add: Custom gradient component
Co-Authored-By: Miguel Fonseca <miguelcsf@gmail.com>
Co-Authored-By: Miguel Fonseca <miguelcsf@gmail.com>
@jorgefilipecosta jorgefilipecosta merged commit 5e68cdc into master Dec 5, 2019
@jorgefilipecosta jorgefilipecosta deleted the add/custom-gradient-component branch December 5, 2019 22:56
@jorgefilipecosta
Copy link
Member Author

Thank you for the reviews @mcsf.
I merged the component so we can iterate, add more functionality to it fix problems, etc in different PR's, but before merging I removed its usage by default. So even though the PR is merged and the component is available it is not visible/used yet. On can easily make the component visible by reverting dbb5f8b.
I plan to make the component visible when we land the tabbed UI suggested by Matias.

@youknowriad
Copy link
Contributor

A README and some stories for the component would be appreciated :)

@youknowriad
Copy link
Contributor

Should this component be named just GradientPicker (equivalent to the existing ColorPicker)

@youknowriad youknowriad added this to the Gutenberg 7.1 milestone Dec 9, 2019
@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Dec 9, 2019

A README and some stories for the component would be appreciated :)

Hi @youknowriad,
We have a GradientPicker component that will contain a picker for named gradients and custom ones. I named this component CustomGradientPicker because it will focus only on the UI to create/edit a custom gradient.

@jorgefilipecosta jorgefilipecosta added the Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Feb 4, 2020
@jorgefilipecosta jorgefilipecosta removed the Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Accessibility Feedback Need input from accessibility Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet