11import { If } from "@mendix/widget-plugin-component-kit/If" ;
22import classNames from "classnames" ;
3- import { ChangeEvent , createElement , ReactElement , useEffect , useRef , useState } from "react" ;
3+ import { ChangeEvent , createElement , ReactElement , SyntheticEvent , useEffect , useRef , useState } from "react" ;
44import { RichTextContainerProps } from "../../../typings/RichTextProps" ;
55import { type imageConfigType } from "../../utils/formats" ;
66import { IMG_MIME_TYPES } from "../CustomToolbars/constants" ;
@@ -109,6 +109,10 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
109109 setSelectedImageEntity ( undefined ) ;
110110 } ;
111111
112+ const onImageLoaded = ( e : SyntheticEvent < HTMLImageElement > ) : void => {
113+ setFormState ( { ...formState , width : e . currentTarget . naturalWidth , height : e . currentTarget . naturalHeight } ) ;
114+ } ;
115+
112116 useEffect ( ( ) => {
113117 // event listener for image selection triggered from custom widgets JS Action
114118 const imgRef = imageUploadElementRef . current ;
@@ -123,7 +127,7 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
123127 } , [ imageUploadElementRef . current ] ) ;
124128
125129 return (
126- < DialogContent className = "video -dialog" >
130+ < DialogContent className = "image -dialog" >
127131 < DialogHeader onClose = { onClose } > { activeTab === "general" ? "Insert/Edit" : "Embed" } Images</ DialogHeader >
128132 < DialogBody >
129133 < div ref = { imageUploadElementRef } >
@@ -170,6 +174,7 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
170174 src = { selectedImageEntity . thumbnailUrl || selectedImageEntity . url }
171175 alt = { selectedImageEntity . id }
172176 className = "mx-image-dialog-thumbnail-small"
177+ onLoad = { onImageLoaded }
173178 />
174179 < span className = "icon-container" >
175180 < span className = "icons icon-Delete" onClick = { onEmbedDeleted } > </ span >
@@ -195,28 +200,35 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
195200 ref = { inputReference }
196201 />
197202 </ FormControl >
198- < FormControl label = "Width" >
199- < input
200- className = "form-control"
201- type = "number"
202- name = "width"
203- onChange = { onInputChange }
204- value = { formState . width }
205- />
206- px
207- </ FormControl >
208- < FormControl label = "Height" >
209- < input
210- className = "form-control"
211- type = "number"
212- name = "height"
213- onChange = { onInputChange }
214- value = { formState . height }
215- disabled = { formState . keepAspectRatio }
216- />
217- px
203+ < FormControl label = "Width" className = "image-dialog-size" >
204+ < div className = "flexcontainer image-dialog-size-container" >
205+ < div className = "flexcontainer image-dialog-size-input" >
206+ < input
207+ className = "form-control"
208+ type = "number"
209+ name = "width"
210+ onChange = { onInputChange }
211+ value = { formState . width }
212+ />
213+ < span > px</ span >
214+ </ div >
215+ < div className = "flexcontainer image-dialog-size-label" >
216+ < label className = "control-label" > Height</ label >
217+ </ div >
218+ < div className = "flexcontainer image-dialog-size-input" >
219+ < input
220+ className = "form-control"
221+ type = "number"
222+ name = "height"
223+ onChange = { onInputChange }
224+ value = { formState . height }
225+ disabled = { formState . keepAspectRatio }
226+ />
227+ < span > px</ span >
228+ </ div >
229+ </ div >
218230 </ FormControl >
219- < FormControl label = "Keep aspect ratio" >
231+ < FormControl label = "Keep ratio" >
220232 < input
221233 type = "checkbox"
222234 name = "keepAspectRatio"
@@ -227,7 +239,7 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
227239 < DialogFooter onSubmit = { ( ) => onSubmit ( formState ) } onClose = { onClose } > </ DialogFooter >
228240 </ If >
229241 < If condition = { activeTab === "embed" } >
230- < div > { imageSourceContent } </ div >
242+ < div className = "image-dialog-upload" > { imageSourceContent } </ div >
231243 </ If >
232244 </ div >
233245 </ div >
0 commit comments