-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
babd035
to
fdd3f52
Compare
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. |
c24228f
to
f044457
Compare
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 Sketch 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. |
835598f
to
31588dc
Compare
Hi @mtias, |
There was a problem hiding this 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 !== '%' ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
a44e038
to
6455760
Compare
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. |
@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. |
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray comment? :)
packages/components/src/custom-gradient-picker/control-points.js
Outdated
Show resolved
Hide resolved
packages/components/src/custom-gradient-picker/control-points.js
Outdated
Show resolved
Hide resolved
const onMouseUp = () => { | ||
if ( window && window.removeEventListener ) { | ||
window.removeEventListener( 'mousemove', onMouseMove ); | ||
window.removeEventListener( 'mouseup', onMouseUp ); |
There was a problem hiding this comment.
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.
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 <[email protected]>
Co-Authored-By: Miguel Fonseca <[email protected]>
a6bb970
to
dbb5f8b
Compare
Thank you for the reviews @mcsf. |
A README and some stories for the component would be appreciated :) |
Should this component be named just GradientPicker (equivalent to the existing ColorPicker) |
Hi @youknowriad, |
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:
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:
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