Sha256: d7530be143a2085daf58aefa42a1dccd2c1088960d583c49f524344ff7729959

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

import { CocoComponent } from "@assets/js/base/coco";
import { getComponent } from "@helpers/alpine";
import { basename } from "@helpers/path";

export default CocoComponent("imagePicker", ({ src }) => {
  return {
    image: {
      name: basename(src),
      file: null,
      data: src,
    },

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

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

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

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

    setImage(file, silent = false) {
      this.image = {
        file: file.file,
        name: file.name,
        data: file.data,
      };

      this.uploader.setFile(file);

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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coveragebook_components-0.14.0 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.13.1 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.13.0 app/components/coco/pickers/image_picker/image_picker.js