color-js / elements

WIP
13 stars 1 forks source link

[color-picker] No sliders if no `space` is provided #39

Closed LeaVerou closed 5 months ago

LeaVerou commented 5 months ago

It would be nice to just default to the color space of the color provided. Or even a predefined one, like oklch.

Testcase: https://codepen.io/leaverou/pen/ExzVaPO

Edit: there is actually a static default one, oklch. Need to debug why it's not working!

DmitrySharabin commented 5 months ago

The default space is a string, but we need this to be an instance of the corresponding color space (we generate the sliders based on this.space.cords):

https://github.com/color-js/elements/blob/2135f503352281d6fbedfb151b65fb619618b27b/src/color-picker/color-picker.js#L72

So, the default value is not parsed but should (already filed the related issue on Nude Element).

DmitrySharabin commented 5 months ago

I have a fix (I wouldn't say I like it much, though) in case we need something quick (and dirty 😅)

propChangedCallback ({name, prop, detail: change}) {
    if (name === "space") {
        if (typeof this.space === "string") {
            this.space = prop.parse(this.space);
        }

        ...
}
DmitrySharabin commented 5 months ago

It seems to me I could find (or become a bit closer to) a better (more general) solution: https://github.com/nudeui/element/pull/9.

DmitrySharabin commented 5 months ago

This will be fixed automatically as soon as we have a new release of NudeUI Element, so I'm going to close it.