Sha256: 29e0f23336226bbda22982013ba73f4977488ad38d33a290f6c0a6f0c5bccf2b

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

import { CocoComponent } from "@js/coco";
import { getComponent } from "@helpers/alpine";

export default CocoComponent("appImagePicker", ({ image }) => {
  return {
    use: [],
    image: null,

    get name() {
      return this.image && this.image.name;
    },

    get src() {
      return this.image && this.image.data;
    },

    get hasImage() {
      return !!this.src;
    },

    get uploader() {
      return getComponent(this.$refs.uploader.firstElementChild);
    },

    setImage(file, silent = false) {
      this.image = file;
      this.uploader.setFile(file);
      if (silent === false) {
        this.$dispatch("image-picker:select", { image: this.image });
      }
    },

    clearImage(silent = false) {
      this.uploader.clear();
      this.image = null;
      if (silent === false) {
        this.$dispatch("image-picker:clear");
      }
    },

    browseFiles() {
      this.uploader.openPicker();
    },

    replaceImage() {
      this.uploader.openPicker();
    },
  };
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coveragebook_components-0.5.0 app/components/coco/app/elements/image_picker/image_picker.js