Sha256: 076e6f668fd5d947e9dd4ea71d8dc955e1d8b5adb40dd4b80a53f07b9b4e9938

Contents?: true

Size: 1.17 KB

Versions: 22

Compression:

Stored size: 1.17 KB

Contents

import { CocoComponent } from "@assets/js/coco/component";
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

22 entries across 22 versions & 1 rubygems

Version Path
coveragebook_components-0.19.8 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.19.7 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.19.6 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.19.5 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.19.4 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.19.3 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.19.2 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.19.1 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.19.0 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.18.8 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.18.7 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.18.0 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.17.7 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.17.6 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.17.5 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.17.4 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.17.3 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.17.2 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.17.1 app/components/coco/pickers/image_picker/image_picker.js
coveragebook_components-0.17.0 app/components/coco/pickers/image_picker/image_picker.js