1
1
import { If } from "@mendix/widget-plugin-component-kit/If" ;
2
2
import classNames from "classnames" ;
3
- import { ChangeEvent , createElement , ReactElement , useEffect , useRef , useState } from "react" ;
3
+ import { ChangeEvent , createElement , ReactElement , SyntheticEvent , useEffect , useRef , useState } from "react" ;
4
4
import { RichTextContainerProps } from "../../../typings/RichTextProps" ;
5
5
import { type imageConfigType } from "../../utils/formats" ;
6
6
import { IMG_MIME_TYPES } from "../CustomToolbars/constants" ;
@@ -109,6 +109,10 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
109
109
setSelectedImageEntity ( undefined ) ;
110
110
} ;
111
111
112
+ const onImageLoaded = ( e : SyntheticEvent < HTMLImageElement > ) : void => {
113
+ setFormState ( { ...formState , width : e . currentTarget . naturalWidth , height : e . currentTarget . naturalHeight } ) ;
114
+ } ;
115
+
112
116
useEffect ( ( ) => {
113
117
// event listener for image selection triggered from custom widgets JS Action
114
118
const imgRef = imageUploadElementRef . current ;
@@ -123,7 +127,7 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
123
127
} , [ imageUploadElementRef . current ] ) ;
124
128
125
129
return (
126
- < DialogContent className = "video -dialog" >
130
+ < DialogContent className = "image -dialog" >
127
131
< DialogHeader onClose = { onClose } > { activeTab === "general" ? "Insert/Edit" : "Embed" } Images</ DialogHeader >
128
132
< DialogBody >
129
133
< div ref = { imageUploadElementRef } >
@@ -170,6 +174,7 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
170
174
src = { selectedImageEntity . thumbnailUrl || selectedImageEntity . url }
171
175
alt = { selectedImageEntity . id }
172
176
className = "mx-image-dialog-thumbnail-small"
177
+ onLoad = { onImageLoaded }
173
178
/>
174
179
< span className = "icon-container" >
175
180
< span className = "icons icon-Delete" onClick = { onEmbedDeleted } > </ span >
@@ -195,28 +200,35 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
195
200
ref = { inputReference }
196
201
/>
197
202
</ 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 >
218
230
</ FormControl >
219
- < FormControl label = "Keep aspect ratio" >
231
+ < FormControl label = "Keep ratio" >
220
232
< input
221
233
type = "checkbox"
222
234
name = "keepAspectRatio"
@@ -227,7 +239,7 @@ export default function ImageDialog(props: ImageDialogProps): ReactElement {
227
239
< DialogFooter onSubmit = { ( ) => onSubmit ( formState ) } onClose = { onClose } > </ DialogFooter >
228
240
</ If >
229
241
< If condition = { activeTab === "embed" } >
230
- < div > { imageSourceContent } </ div >
242
+ < div className = "image-dialog-upload" > { imageSourceContent } </ div >
231
243
</ If >
232
244
</ div >
233
245
</ div >
0 commit comments