import type { VNode } from 'vue'; import type { DropdownButtonItemArgs } from '../dropdown-button/dropdown-button-item'; import type { FormItemWrapperArgs, MarginType } from '../form/form-item-wrapper'; import { Prop, toNative } from 'vue-facing-decorator'; import PowerduckState from '../../app/powerduck-state'; import TsxComponent, { Component } from '../../app/vuetsx'; import { isNullOrEmpty } from '../../common/utils/is-null-or-empty'; import FormItemWrapper from '../form/form-item-wrapper'; import { FileManagerDialog, FileManagerModalFileType } from '../modal/ts/file-manager-dialog'; import './css/image-upload.css'; interface ImageUploadBoxArgs extends FormItemWrapperArgs { value: string; changed: (newValue: string) => void; maxImgWidth?: number; } @Component class ImageUploadBoxComponent extends TsxComponent implements ImageUploadBoxArgs { @Prop() clicked: (e: any) => void; @Prop() label!: string | VNode; @Prop() labelButtons!: DropdownButtonItemArgs[]; @Prop() subtitle!: string; @Prop() value!: string; @Prop() mandatory!: boolean; @Prop() marginType?: MarginType; @Prop() maxWidth?: number; @Prop() maxImgWidth?: number; @Prop() wrap!: boolean; @Prop() showClearValueButton!: boolean; @Prop() hint: string; @Prop() changed: (newValue: string) => void; getCssClass(): string { let ret = 'image-box-wrap'; if (isNullOrEmpty(this.value)) { ret += ' image-box-wrap-empty'; } return ret; } uploadImg() { FileManagerDialog.show({ fileType: FileManagerModalFileType.Image, callback: (data) => { this.changed(data.url); }, maxWidth: this.maxImgWidth, }); } render(h) { return ( {isNullOrEmpty(this.value) && (
{ this.uploadImg(); }} >
{PowerduckState.getResourceValue('add')}   {PowerduckState.getResourceValue('image')}
)} {!isNullOrEmpty(this.value) && (
{ this.uploadImg(); }} > { this.uploadImg(); }} > { this.changed(null); }} >
)}
); } } const ImageUploadBox = toNative(ImageUploadBoxComponent); export default ImageUploadBox;