Skip to content

ColorArea and ColorWheel step and pagestep size fit evenly in range #2888

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

Merged
merged 12 commits into from
Mar 3, 2022

Conversation

snowystinger
Copy link
Member

@snowystinger snowystinger commented Feb 25, 2022

Closes
Based on changes in #2570
ColorArea behavior is, step and pagestep size fits evenly into the range for RGB with meaningful values.
step is the smallest increment possible, 1
page step steps through web safe colors, 0x11

ColorWheel behavior is, step and pagestep size fits evenly into the hue range for HSL/HSB
step is the smallest increment possible, 1
page step increments by 15, which is large enough to cover the circle quickly but small enough to easily make hitting in between values also short

neither of these are exposed as part of the color area API, instead, when we allow bring your own colorspace, you can set the step and page size through that color space

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@snowystinger snowystinger changed the title change default step size to evenly fit ColorArea step and pagestep size fit evenly in range Feb 25, 2022
@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

Confirmed that the thumb snaps to max/min value regardless of the amount of remaining distance to traverse

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

/** The page step size for the xChannel. */
xChannelPageStep?: number,
/** The page step size for the yChannel. */
yChannelPageStep?: number
Copy link
Member

Choose a reason for hiding this comment

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

What's the use case to configure these?

Copy link
Member Author

Choose a reason for hiding this comment

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

If someone sets a step size bigger than the page step size, then they may want to increase the page step size to compensate.
It might make more sense with HSL/HSB where you can have decimals and you actually want to decrease the page step size.

Copy link
Member

Choose a reason for hiding this comment

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

what if we just multiply the step by some amount to find the page step?

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

},
decrementY(stepSize) {
setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepSize));
setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, yChannelStep));
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still think increment/decrement should snap to stepSize rather than xChannelStep or yChannelStep. So that snapping is based on the interval by which one increments or decrements.

Copy link
Member Author

Choose a reason for hiding this comment

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

For example step=5 pageStep=8

step start at 0 => 5

would it be
pageStep start at 0 => 8 & start at 5 (from the regular step) => 13
or is it
pageStep start at 0 => 8 & start at 5 (from the regular step) => 16

Native sliders, when supplied a step, cannot have a value that does not fall on a multiple of step. You can see this clearly in the Chrome Date picker. I think this is more predictable.
pageStep start at 0 => 8 & start at 5 (from the regular step) => 15

Or are you suggesting that color sliders are different from regular sliders?

Copy link
Member Author

Choose a reason for hiding this comment

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

Caught up in the other discussion on the same topic. Devon had an idea, we keep the page step size out of the API and just treat it as a multiple of the step. We currently don't support page step size in our Sliders, so this makes a fair amount of sense

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see where you're coming from if the uses a step size that is not a factor of the page size. With ColorSliders, the step is usually 1, or 0.01 for alpha, and default for pageSize will always snap to step. Can do something like this, using modulus?

    incrementX(stepSize) {
      setXValue(xValue + stepSize > maxValueX ? maxValueX : snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepSize > xChannelStep && stepSize % xChannelStep === 0 ? stepSize : xChannelStep));
    },
    incrementY(stepSize) {
      setYValue(yValue + stepSize > maxValueY ? maxValueY : snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepSize > yChannelStep && stepSize % yChannelStep === 0 ? stepSize : yChannelStep));
    },
    decrementX(stepSize) {
      setXValue(snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepSize > xChannelStep && stepSize % xChannelStep === 0 ? stepSize : xChannelStep));
    },
    decrementY(stepSize) {
      setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepSize > yChannelStep && stepSize % yChannelStep === 0 ? stepSize : yChannelStep));
    },

Copy link
Member Author

Choose a reason for hiding this comment

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

it's getting too complicated I think, see previous comment about doing away with it in our API
That way we can make sure it's a multiple of the step and eliminate that worry.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess my question would be, what multiple of a step would make the most sense for color channels? The reason for returning pageSize as part of the color channel range object returned by Color.getChannelRange was so that we could have more useful page stepping than simply dividing the range by 10. For example for the hue channel, a pageSize of 15 seems to make sense for snapping to primary, secondary and tertiary colors around the color wheel (BTW, we should use getChannelRange('hue').pageSize instead of the PAGE_MIN_STEP_SIZE constant in useColorWheel). I suggested 0x11 as a pageSize for RGB channels because it divides 0xFF evenly, and increments channel values in a way that makes sense for web developers 0x11, 0x22, 0x33, 0x44, ..., 0xDD, 0xEE, 0xFF.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another option would be to eliminate step and pageStep from the public API for color controls, and use values that make sense for each color channel internally. Then we wouldn't have to worry about a pageSize that is not a multiple of a step because we would control it.

Copy link
Member Author

@snowystinger snowystinger Mar 2, 2022

Choose a reason for hiding this comment

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

Maybe this brings up if step should be configurable too?

What is the actual use case for setting step sizes in a color area or color slider? Maybe we should consider that color sliders are different than sliders

RGB 255 is not many values. Having the step size always be 1 and the page size always be 11 makes a lot of sense, you can get quickly to any value and you are always evenly and predictably within the range.

For HSL 0-360 and 0-1 are known ranges that will not change, a step of 1 and 0.01 respectively make sense and page sizes are easy to figure out from there as well.

I think what I'm saying is every color space is well defined and knowable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that color spaces seem well defined and knowable. I suppose there may be some use cases for floating point steps with hue, saturation and lightness/brightness channels, but it should be noted that Photoshop throws up a dialog if you try to use a floating point value in one of its inputs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I still think that snapping to stepSize, the pageStep, is preferable to snapping to step, the channel step, and now that we can be sure that the channel step is a factor of the stepSize, I don't se why we shouldn't do it this way.

@majornista majornista mentioned this pull request Mar 2, 2022
5 tasks
@snowystinger snowystinger changed the title ColorArea step and pagestep size fit evenly in range ColorArea and ColorWheel step and pagestep size fit evenly in range Mar 3, 2022
@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

Reminder that the aria/spectrum docs for ColorWheel/useColorWheel should also have references/examples to step removed (probably do that in a separate PR, I can help w/ that). The functionality seem good to me

@snowystinger
Copy link
Member Author

Yeah, it's in #2666

@LFDanLu
Copy link
Member

LFDanLu commented Mar 3, 2022

Ok, sweet. I'll go ahead and pull those docs changes out of the PR since those should go in after release

Copy link
Member

@ktabors ktabors left a comment

Choose a reason for hiding this comment

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

Can you add testing instructions? It didn't seem like you mentioned colorslider, but it looks like it changed too.

I tested and keyboard navigation seems good for colorslider. Home and end don't seem to matter for colorwheel since they both goto the same spot.

For color area RTL, home and end key events are still ltr.

@snowystinger
Copy link
Member Author

snowystinger commented Mar 3, 2022

I'm not sure what slider changes you are referring to? This is only ColorArea and ColorWheel.

Home/End are reversed in RTL/LTR ColorArea. That wasn't changed. We can followup if that's weird and it should remain the same.

Correct for ColorWheel, Home/End both go to the same spot. We can follow up if that's weird.

@adobe-bot
Copy link

Build successful! 🎉

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.

7 participants