Public
Edited
Apr 10
1 fork
Importers
Insert cell
Insert cell
viewof files = ImageLoader()
Insert cell
files
Insert cell
function ImageLoader({ width = 50, files = [] } = {}) {
const filesIn = Inputs.file({
multiple: true,
accept: ".jpg, .png,.tiff,.png"
});
const thumbsHolder = htl.html`<output></output>`;
const target = htl.html`<div>
${filesIn}
<div>
<style>
img {
max-width: 50px;
max-height: 50px;
}
</style>
${thumbsHolder}
</div>
</div>`;

async function showValue() {
const thumbs = htl.html`${await Promise.all(widget.value.map((i) => i.image()))}`;
thumbsHolder.innerHTML = "";
thumbsHolder.appendChild(thumbs);
}

const widget = ReactiveWidget(target, {
value: files,
showValue
});

filesIn.oninput = (evt) => {
evt.stopPropagation();
evt.preventDefault();
widget.setValue(filesIn.value);
};

return widget;
}
Insert cell
// ReactiveWidget = require("reactive-widget-helper")
import {ReactiveWidget} from "@john-guerra/reactive-widgets"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more