color-js / elements

WIP
12 stars 1 forks source link

`color` vs `value` attribute #73

Open LeaVerou opened 3 months ago

LeaVerou commented 3 months ago

When rewriting <color-swatch>, I opted for a color attribute. However, I’m not so sure it was a good idea. value is far more common across HTML elements, and there are libraries and frameworks that work out of the box with elements that follow the convention of .value property + input event for user-initiated changes (e.g. Vue’s v-model). Also, color is a Color, so conceptually since the attribute is specifying a string, value seems more fitting.

So what about:

This would be across all components whose value is a color (<color-inline>, <color-swatch>, <color-picker>).

DmitrySharabin commented 3 months ago

Do I get it correctly that the color property will become a getter in that case? Can authors set Color as a value of the value attribute?

In general, I think it's good to be consistent with the platform and let authors use the elements the way they used to. I think it's a win-win.

LeaVerou commented 3 months ago

No, I think it's okay for authors to set either of them, and they should be kept in sync.

I was also thinking that space has a similar issue: Authors actually set a space id via the attribute, but it gets converted to a color space object. We should instead have a spaceId property (that reflects from the space attribute) and a separate space property that is a ColorSpace object (and authors can set either).

LeaVerou commented 3 months ago

For inspiration, I was using <input>’s valueAsDate/valueAsNumber properties, and that's exactly how they work: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement

DmitrySharabin commented 3 months ago

I was also thinking that space has a similar issue: Authors actually set a space id via the attribute, but it gets converted to a color space object.

I believe we have a bit more, e.g., stops.

LeaVerou commented 3 months ago

Related: https://github.com/nudeui/element/issues/24