-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
[space-picker] First iteration #143
Conversation
✅ Deploy Preview for color-elements ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
src/space-picker/space-picker.js
Outdated
default: () => Self.Color.spaces, | ||
convert (value) { | ||
// Drop non-existing spaces | ||
let spaces = Object.fromEntries(Object.entries(value).filter(([id, space]) => space)); |
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 don't think we should drop them, I think we should just not list them with a name. Just the id.
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.e. the name should default to the id.
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.
Makes sense. Will fix it. Thanks!
|
||
static formAssociated = { | ||
like: el => el._el.picker, | ||
role: "combobox", |
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.
Doesn't this default to the element we specified in like
? If not, it probably should.
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.
In our code, we try to default to computedRole
. Unfortunately, it still isn't supported. It's probably under the flag in some browsers (not sure).
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.
We should just use getComputedAccessibleNode()
instead. It's not like we don't have access to this information at all.
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.
(in Nude Element, in case that wasn't clear)
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.
Got it. Thanks. I'll send a PR with the change.
src/space-picker/space-picker.js
Outdated
like: el => el._el.picker, | ||
role: "combobox", | ||
valueProp: "value", | ||
changeEvent: "spacechange", |
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.
Shouldn't this use change
?
src/space-picker/space-picker.js
Outdated
|
||
value += ""; | ||
|
||
return Self.Color.Space.get(value); |
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 again the same issue with the string/object props. We need a prop that contains your actual input as a string (value
) and one that contains the color space object (likely space
or selectedSpace
).
src/space-picker/space-picker.js
Outdated
this.value = this._el.picker.value; | ||
} | ||
|
||
this.dispatchEvent(new event.constructor(event.type, {...event})); |
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.
Doesn't defining the change event below take care of this?
Thank you so much for your review! Every comment is on point, and I'll try to address it ASAP. |
- Use `value` for actual input (as a string) and `selectedSpace` for the corresponding space object - Support custom grouping of color spaces via the `groups()` prop - Don't drop non-existent spaces; replace them with the `{ id, name: id }` objects - Expose the `valuechange` and `spacechange` events - Retarget the `input` event - In `formAssociated`, use `change` as the `changeEvent`
fad2aed
to
f416bd5
Compare
@LeaVerou, I addressed all your feedback (thank you for it). Here are the changes I made:
Here is an example of using a custom grouping (from your color palettes research): <space-picker id="space_picker" spaces="oklch, p3, srgb" value = "p3"></space-picker>
<script type="module">
space_picker.groups = (spaces) => {
let ret = {polar: {}, rectangular: {}};
for (let id in spaces) {
let space = spaces[id];
if (space.id !== id) {
continue;
}
let isPolar = space.coords.h?.type === "angle";
ret[isPolar ? "polar" : "rectangular"][id] = space;
}
return ret;
};
</script> Could you please take a look at this PR one more time? |
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.
- Authors should not have to loop over spaces themselves in the grouping function, it doesn't seem like they get any benefit for the extra work, are there cases where the grouping depends on what other spaces are available? (and even if so, one can just check
spaces
?). I was thinking of something like agroupBy()
function that just takes a single space as a param, and gets back a group name.groups
could still exist as a computed prop. - Why do we need
defaultGroups
? That seems to exist purely for implementation convenience. No grouping is not just a single group, that implies a different UI. - We definitely need to pick up the design discussion around rawProps, the pattern keeps coming up.
919edb7
to
fe0d219
Compare
* Add the `groupBy()` prop that expects a space and returns the name of a group the space belongs to * Related to the previous one: `groups` is now a computed prop returning an object with all the groups * Use different UI for cases with grouping and without Oops
fe0d219
to
5ea258d
Compare
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.
Looks good! Please add a README, and add it to the list of upcoming components.
Thank you! Will do. |
Done! It's alive and can be played with: https://elements.colorjs.io/src/space-picker/ 🎉 |
Partially addresses #123.
Usage examples