Here‘s a function for showing a color picker:
colorPicker = () => html`<input type="color">`
I can easily use it in a notebook as a kind of component:
viewof myColor = colorPicker()
And then reference the color in another cell like this:
html`<p style="color: ${myColor}; font-family: Avenir; font-size: 30px;">Sample Text</p>`
Pretty cool! (live version is here: https://beta.observablehq.com/@halffullheart/test
I know it seems small, but having to put viewof
in there (or use Generators.input()
in the referencing cells) is frustrating. A custom component like this is meant to always be used this way where it displays one thing but exposes another value.
What I’m looking for is a way to package up what viewof
is doing into the component so that wherever it is used, I only have to give it a name: aColor = colorPicker()
.