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

experimental: add gradient controller to update color stops using ui #4159

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

JayaKrishnaNamburu
Copy link
Contributor

@JayaKrishnaNamburu JayaKrishnaNamburu commented Sep 25, 2024

Description

The GradientControl helps in displaying the colour stops that are available in the linear-gradient that users added.

There are two knows issues at the moment.

  • The only limitation is. We can't swap the colours when a colour stop crosses an existing colour stop. In some
    tools, the colours are swapped resulting in the swiping of the gradient too.
    This is because of a limitation/bug on the radix side, they pre-sort the slider stops. So, we can never know which crosses an existing stop and changed it's value. Slider ability to disable swap of multiple thumbs radix-ui/primitives#2247

Steps for reproduction

  • Passing a linear-gradient should show all the color-stops in the gradient.
  • The color-hints are displayed at the bottom of the gradient bar. These can't be moved along, more info about it is in the code component. Because, this basically changes the whole gradient just by moving.
  • The color-hints are showed at the bottom of the gradient. Just to notify users about the existence of the hints.
  • Users should be able to move the color-stops along the slider track.
  • The color-stops can be moved using the arrow keys from the keyboard.
Screenshot 2024-09-25 at 10 32 47 AM Screenshot 2024-09-25 at 10 32 43 AM Screenshot 2024-09-25 at 10 32 38 AM

color-change-gradients

Code Review

  • hi @kof, I need you to do
    • conceptual review (architecture, feature-correctness)
    • detailed review (read every line)
    • test it on preview

Before requesting a review

  • made a self-review
  • added inline comments where things may be not obvious (the "why", not "what")

Before merging

  • tested locally and on preview environment (preview dev login: 5de6)
  • updated test cases document
  • added tests
  • if any new env variables are added, added them to .env file

@@ -0,0 +1,171 @@
import { toValue, UnitValue } from "@webstudio-is/css-engine";
Copy link
Member

Choose a reason for hiding this comment

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

If we are building a lower level component, without any application logic, then it should go into design system pacakge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently in the design-system package we are not using css-engine pacakge. Is it ok if i add it there ? I am using types from there and it's the only reason i added it into builder.

Copy link
Member

Choose a reason for hiding this comment

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

I would say you can decouple the things you are using from css engine, seems very minimal, but curious what @TrySound would say

@JayaKrishnaNamburu JayaKrishnaNamburu marked this pull request as ready for review September 27, 2024 08:53
@JayaKrishnaNamburu JayaKrishnaNamburu marked this pull request as draft September 27, 2024 09:16
@JayaKrishnaNamburu JayaKrishnaNamburu self-assigned this Sep 27, 2024
@JayaKrishnaNamburu JayaKrishnaNamburu marked this pull request as ready for review September 28, 2024 10:25
@TrySound
Copy link
Member

TrySound commented Oct 2, 2024

I like how gradient style tries to balance new dots instead of manually centering, maybe not needed for our case
https://github.com/user-attachments/assets/a339afc6-6d18-4597-9eb0-518dcc03b52e

@TrySound
Copy link
Member

TrySound commented Oct 2, 2024

I would add outline for focus-visible only
image

@TrySound
Copy link
Member

TrySound commented Oct 2, 2024

I instinctively do alt+click to delete thumbs

@TrySound
Copy link
Member

TrySound commented Oct 2, 2024

I would do color picker as popover, tooltip feels super unpredictable

@kof
Copy link
Member

kof commented Oct 3, 2024

I instinctively do alt+click to delete thumbs

I think its not a bad idea for us to support this, since our users know this combo

@JayaKrishnaNamburu
Copy link
Contributor Author

I like how gradient style tries to balance new dots instead of manually centering, maybe not needed for our case https://github.com/user-attachments/assets/a339afc6-6d18-4597-9eb0-518dcc03b52e

It is indeed looking good. But the catch is, if a user sets the slider to a custom location. It changes it at the time of rebalancing when a new stop is added. Or is the behaviour is different there ?

@JayaKrishnaNamburu
Copy link
Contributor Author

I would do color picker as popover, tooltip feels super unpredictable

I am using it as PropOver itself.
https://github.com/webstudio-is/webstudio/blob/add-gradient-control/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-control.tsx#L320

Seems the events from Slider are little bit unpredictable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants