Sha256: b68c39dc9621cf42153b8dd4dee1ea635ea28c96046f2d7f4064ddfa97b96a41

Contents?: true

Size: 1.16 KB

Versions: 25

Compression:

Stored size: 1.16 KB

Contents

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

export default CocoComponent("appImagePicker", ({ 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

25 entries across 25 versions & 1 rubygems

Version Path
coveragebook_components-0.10.0 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.9.1 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.9.0 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.9 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.8 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.7 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.6 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.5 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.4 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.3 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.2 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.1 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.0 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.0.beta.3 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.0.beta.2 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.8.0.beta.1 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.7.10 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.7.9 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.7.8 app/components/coco/app/elements/image_picker/image_picker.js
coveragebook_components-0.7.7 app/components/coco/app/elements/image_picker/image_picker.js