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 a new Coral Color Picker component. #179

Merged
merged 23 commits into from
Sep 16, 2021

Conversation

indra2gurjar
Copy link
Contributor

@indra2gurjar indra2gurjar commented Jul 3, 2021

Description

We are adding a new ColorPicker component which can support multiple formats like - HSL, HSV, RGB, HEX, HEX3, HEX4, HEX8, Name etc.
The component is similar to ColarArea component in Spectrum - https://spectrum.adobe.com/page/color-area/

For color format conversions library '@ctrl/tinycolor' is used.
At some places we are converting hsv/hsl color string since tinycolor doesn't preserve hue at S/L boundaries.
Color conversion in different formats loose details so it's done minimal and at many places color strings are generated for hsl/hsl format.

Related Issue

https://jira.corp.adobe.com/browse/CUI-7445
https://xd.adobe.com/view/4565a1db-3df7-4483-8246-3a0e4882c842-1036/screen/e4cae491-ff98-49ce-9161-264e6abc03ef
https://stock.adobe.com/

Motivation and Context

Existing ColorInput component does support only few formats like - RGBA and color swatches only.
This new Color Picker provides user a way to select colors in the natural way where user can select a fully saturated hue(color) from ColorSlider, then user can change saturation and luminosity.
Color input-output supports most of the formats.
Alpha channel selector isn't added currently and can be added later. This isn't required for CUI-7445.
User can still change alpha manually.

How Has This Been Tested?

Only manually.
Component can be seen in action at - http://indra-imac.corp.adobe.com:9001/examples/
We are planning to add unit test in the PR.

Screenshots (if appropriate):

Screenshot 2021-07-04 at 5 45 01 AM

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

@indra2gurjar
Copy link
Contributor Author

@Pareesh @icaraps A gentle reminder! Please help in reviewing.

_stepY() {
return 0.01;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

since all these are const values. you can add a getter like

get _minX() { return 0; }

and then you can use it as property rather than function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The major difference I see b/w property and _minX function is:
Property can be changed by the consumer of the class while _minX function always returns the const value.
We want to keep min, max, step values constant.

I don't know any benefit of accessing a property over a function call. Accessing a property is same as calling getter function.

Copy link
Collaborator

@Pareesh Pareesh Jul 22, 2021

Choose a reason for hiding this comment

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

This corresponds more to a property rather than function. Generally the the property starting with underscore is private and should not be changed, in case consumer is changing its consumer faults.

you can still avoid the change by adding an empty setter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid getter/setter functions , we can simply define these constants in constructor.
e.g.
constructor(){
this._minX= 0;
this._maxX = 100;
}

Properties are meant to be set/get by consumers to change the component's behaviour.

}
if(this.y !== y) {
this.y = y;
this.trigger('change');
Copy link
Collaborator

@Pareesh Pareesh Jul 22, 2021

Choose a reason for hiding this comment

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

We will be calling a change event twice in case both value change. If possible can we trigger only one change event, when both or one of the values get changed

The color string
*/
extractHsv(colorString) {
const exp = /^hsva?\((\d{1,3}),\s*(\d{1,3}%),\s*(\d{1,3}%)/;
Copy link
Collaborator

@Pareesh Pareesh Jul 22, 2021

Choose a reason for hiding this comment

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

Please add a single line comment explaining the regex, would be useful for future. Please do it for all regex as well.
Thank you

Copy link
Collaborator

@Pareesh Pareesh left a comment

Choose a reason for hiding this comment

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

I didn't tried this visually apart from that LGTM.

@indra2gurjar
Copy link
Contributor Author

@Pareesh You can try this here - http://indra-imac.corp.adobe.com:9001/examples/

@indra2gurjar
Copy link
Contributor Author

@majornista Could you please review this for accessibility?
This can be tried at - http://indra-imac.corp.adobe.com:9001/examples/

1. ColorArea is currently just for Saturation and Brightness/Value. With luminosity, 50% is fully saturated, 100% is white and 0% is black, so its important to be clear about which values the slider controls.
2. We should use `aria-valuetext` to report the value of each slider.
3. The ColorPicker overlay should have aria-live="off", otherwise the value change to the text input announces assertively instead of the value of the slider that changed.
4. I added a degree symbol to the aria-valuetext of the Hue slider.
Copy link
Collaborator

@majornista majornista left a comment

Choose a reason for hiding this comment

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

I opened a PR with some suggested changes for accessibility: indra2gurjar#2

indra2gurjar and others added 2 commits August 13, 2021 10:24
fix(adobe#179): Suggested changes to ColorArea to improve accessibility
@majornista
Copy link
Collaborator

FWIW, I have a PR open for React-Spectrum that implements a ColorArea with support for HSL and RGB in addition to HSV: adobe/react-spectrum#1732. See: https://reactspectrum.blob.core.windows.net/reactspectrum/d02b605cb71505dbf074eb9f3b54c9174538bc8c/storybook/index.html?path=/story/colorarea--default-hsb-xchannel-saturation-ychannel-brightness for an example.

@majornista majornista merged commit 7b271c3 into adobe:master Sep 16, 2021
majornista added a commit that referenced this pull request Sep 16, 2021
* Add a new Coral Color Picker component.

* dependency at tiny

* Fix axe

* lint

* add package-lock

* update examples

* @trivial

* Fixed

* Add formats support.

* Tests ColorArea

* fix(#179): Suggested changes to ColorArea to improve accessibility

1. ColorArea is currently just for Saturation and Brightness/Value. With luminosity, 50% is fully saturated, 100% is white and 0% is black, so its important to be clear about which values the slider controls.
2. We should use `aria-valuetext` to report the value of each slider.
3. The ColorPicker overlay should have aria-live="off", otherwise the value change to the text input announces assertively instead of the value of the slider that changed.
4. I added a degree symbol to the aria-valuetext of the Hue slider.

* Tests ColorSliderHue

* Test ColorProperties.

* test

* Test ColorPicker

* coverage

* large style

* support large

* Add 1 second debounce for change event.

* cleanup

* add translation provided by translation team.

Co-authored-by: igurjar <igurjar@adobe.com>
Co-authored-by: Michael Jordan <mijordan@adobe.com>
Co-authored-by: Mohit Arora <mohiaror@adobe.com>
github-actions bot pushed a commit that referenced this pull request Sep 16, 2021
# [4.12.0](v4.11.1...v4.12.0) (2021-09-16)

### Features

* **ColorPicker:** Add a new Coral Color Picker component. ([#179](#179)) ([eb1b4d6](eb1b4d6))
@github-actions
Copy link

🎉 This issue has been resolved in version 4.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

None yet

4 participants