Sha256: c538edbbf5638171a7927b132b25cc9758580c06b6ff3b7dd811c135abb0ee85
Contents?: true
Size: 1.18 KB
Versions: 33
Compression:
Stored size: 1.18 KB
Contents
import { CocoComponent } from "@js/coco"; import { getData } from "@helpers/alpine"; import { basename } from "@helpers/path"; export default CocoComponent("appImagePickerButton", ({ src }) => { return { selectedImage: { name: basename(src), file: null, data: src, }, getPicker() { return getData( this.$root.querySelector("[data-role='image-picker'").firstElementChild ); }, handleExternalDrop(event) { this.readFile(event.dataTransfer.files[0]); }, readFile(file) { const reader = new FileReader(); reader.addEventListener("load", () => { this.selectedImage = { name: file.name, file, data: reader.result, }; this.dropdown.hide(); }); reader.readAsDataURL(file); }, clearSelectedImage() { this.dropdown.hide(); this.selectedImage = { name: null, data: null, file: null }; }, setSelectedImage(image) { this.dropdown.hide(); this.selectedImage = image; }, onDropdownMount({ detail }) { this.dropdown = detail.dropdown; this.getPicker().setImage(this.selectedImage, true); }, }; });
Version data entries
33 entries across 33 versions & 1 rubygems