This is where I built the initial color picker for my Fonts and Colors site
I decided to limit the component to just the sliders. They fire an event when they change that can be used for functionality on the parent page. For example, the color box above the sliders is generated on the parent page and not in the component
The example below is build diretly from the code snippets to ensure evrything works.
The inital color is set by passing in values. Right now, this is not optional
I'm using default form controls, but still need to review the accessability of the component. Probably adding lables would make sense.
I switched the order of the sliders to something that makes more sense to me. I see the hue more as the foundation hence I put it at the bottom of the stack
The slider color gets a little off from the background at the ends. This is because the slider is based off the center point of the moving piece (aka thumb) but the background colors extend to the full edge. I played around with a design with the gradient ends extending in. I didn't like it. Next up will be to setup so the slider thumb goes out a little.
The CSS is not needed for the component itself, it's there to render the output display block from teh parent page.
Same goes for the 'preview-block' div. That's an implementation detail from the parent page
The JavaScript block includes both the web compnent and the code that to use it from the parent page (which is at the bottom).
I check the background colors for the sliders work on Chrome, Firefox, and Safari on macOS 12.x. Other setups TBD
TODO
[ ] - Add default values so it's not required to send in initail values
[ ] - Refactor the first addition of the values for the range sliders so the don't get set twice on init
[ ] - Write up details on the functionality
[ ] - Refactor to remove the duplication of creating each slider
[ ] - Adjust so the slider thumb can extend so the center point ends up at the edge of the background boundries
[ ] - Make it responsive
[ ] - Setup to use arrow keys to bump the value for the last slider that was interacted with
[ ] - Add alpha
[ ] - Send RBG values and all the various other color formats in raw text and something that can be copied direcly into a stylesheet
[ ] - Add second selection for color to put under alpha
[ ] - Add debouce option to slow down sending event signal
[ ] - See about using cookies to store values so they are the same on refresh, etc... Guessing sending an ID will be require
[ ] - Make the size of the background configurable