1
1
import { isPhone , isDesktop } from "@ui5/webcomponents-base/dist/Device.js" ;
2
2
import Popup from "./Popup.js" ;
3
+ import "@ui5/webcomponents-icons/dist/icons/resize-corner.js" ;
4
+ import Icon from "./Icon.js" ;
3
5
4
6
// Template
5
7
import DialogTemplate from "./generated/templates/DialogTemplate.lit.js" ;
@@ -77,6 +79,23 @@ const metadata = {
77
79
type : Boolean ,
78
80
} ,
79
81
82
+ /**
83
+ * Configures the <code>ui5-dialog</code> to be resizable.
84
+ * If this property is set to true, the Dialog will have a resize handle in its bottom right corner in LTR languages.
85
+ * In RTL languages, the resize handle will be placed in the bottom left corner.
86
+ * <br><br>
87
+ * <b>Note:</b> The <code>ui5-dialog</code> can be resizable only in desktop mode.
88
+ * <br>
89
+ * <b>Note:</b> Upon resizing, externally defined height and width styling will be ignored.
90
+ * @type {boolean }
91
+ * @defaultvalue false
92
+ * @since 1.0.0-rc.10
93
+ * @public
94
+ */
95
+ resizable : {
96
+ type : Boolean ,
97
+ } ,
98
+
80
99
/**
81
100
* @private
82
101
*/
@@ -137,6 +156,12 @@ class Dialog extends Popup {
137
156
return metadata ;
138
157
}
139
158
159
+ static get dependencies ( ) {
160
+ return [
161
+ Icon ,
162
+ ] ;
163
+ }
164
+
140
165
static get template ( ) {
141
166
return DialogTemplate ;
142
167
}
@@ -168,14 +193,22 @@ class Dialog extends Popup {
168
193
} ;
169
194
}
170
195
196
+ _clamp ( val , min , max ) {
197
+ return Math . min ( Math . max ( val , min ) , max ) ;
198
+ }
199
+
171
200
onBeforeRendering ( ) {
201
+ this . _isRTL = this . effectiveDir === "rtl" ;
172
202
this . onPhone = isPhone ( ) ;
173
203
this . onDesktop = isDesktop ( ) ;
174
204
}
175
205
176
206
onEnterDOM ( ) {
177
207
this . _dragMouseMoveHandler = this . _onDragMouseMove . bind ( this ) ;
178
208
this . _dragMouseUpHandler = this . _onDragMouseUp . bind ( this ) ;
209
+
210
+ this . _resizeMouseMoveHandler = this . _onResizeMouseMove . bind ( this ) ;
211
+ this . _resizeMouseUpHandler = this . _onResizeMouseUp . bind ( this ) ;
179
212
}
180
213
181
214
onExitDOM ( ) {
@@ -212,8 +245,8 @@ class Dialog extends Popup {
212
245
transform : "none" ,
213
246
top : `${ top } px` ,
214
247
left : `${ left } px` ,
215
- width : `${ Math . round ( Number ( width ) * 100 ) / 100 } px` ,
216
- height : `${ Math . round ( Number ( height ) * 100 ) / 100 } px` ,
248
+ width : `${ Math . round ( Number . parseFloat ( width ) * 100 ) / 100 } px` ,
249
+ height : `${ Math . round ( Number . parseFloat ( height ) * 100 ) / 100 } px` ,
217
250
} ) ;
218
251
219
252
this . _x = event . clientX ;
@@ -232,7 +265,6 @@ class Dialog extends Popup {
232
265
top,
233
266
} = this . getBoundingClientRect ( ) ;
234
267
235
-
236
268
Object . assign ( this . style , {
237
269
left : `${ Math . floor ( left - calcX ) } px` ,
238
270
top : `${ Math . floor ( top - calcY ) } px` ,
@@ -268,6 +300,116 @@ class Dialog extends Popup {
268
300
} ) ;
269
301
this . removeEventListener ( "ui5-before-close" , this . _recenter ) ;
270
302
}
303
+
304
+ _onResizeMouseDown ( event ) {
305
+ if ( ! ( this . resizable && this . onDesktop ) ) {
306
+ return ;
307
+ }
308
+
309
+ event . preventDefault ( ) ;
310
+
311
+ const {
312
+ top,
313
+ left,
314
+ } = this . getBoundingClientRect ( ) ;
315
+ const {
316
+ width,
317
+ height,
318
+ minWidth,
319
+ minHeight,
320
+ } = window . getComputedStyle ( this ) ;
321
+
322
+ this . _initialX = event . clientX ;
323
+ this . _initialY = event . clientY ;
324
+ this . _initialWidth = Number . parseFloat ( width ) ;
325
+ this . _initialHeight = Number . parseFloat ( height ) ;
326
+ this . _initialTop = top ;
327
+ this . _initialLeft = left ;
328
+ this . _minWidth = Number . parseFloat ( minWidth ) ;
329
+ this . _minHeight = Number . parseFloat ( minHeight ) ;
330
+
331
+ Object . assign ( this . style , {
332
+ transform : "none" ,
333
+ top : `${ top } px` ,
334
+ left : `${ left } px` ,
335
+ } ) ;
336
+
337
+ this . _attachResizeHandlers ( ) ;
338
+ }
339
+
340
+ _onResizeMouseMove ( event ) {
341
+ const { clientX, clientY } = event ;
342
+
343
+ let newWidth ;
344
+ let newLeft ;
345
+
346
+ if ( this . _isRTL ) {
347
+ newWidth = this . _clamp (
348
+ this . _initialWidth - ( clientX - this . _initialX ) ,
349
+ this . _minWidth ,
350
+ this . _initialLeft + this . _initialWidth
351
+ ) ;
352
+
353
+ newLeft = this . _clamp (
354
+ this . _initialLeft + ( clientX - this . _initialX ) ,
355
+ 0 ,
356
+ this . _initialX + this . _initialWidth - this . _minWidth
357
+ ) ;
358
+ } else {
359
+ newWidth = this . _clamp (
360
+ this . _initialWidth + ( clientX - this . _initialX ) ,
361
+ this . _minWidth ,
362
+ window . innerWidth - this . _initialLeft
363
+ ) ;
364
+ }
365
+
366
+ const newHeight = this . _clamp (
367
+ this . _initialHeight + ( clientY - this . _initialY ) ,
368
+ this . _minHeight ,
369
+ window . innerHeight - this . _initialTop
370
+ ) ;
371
+
372
+ Object . assign ( this . style , {
373
+ height : `${ newHeight } px` ,
374
+ width : `${ newWidth } px` ,
375
+ left : newLeft ? `${ newLeft } px` : undefined ,
376
+ } ) ;
377
+ }
378
+
379
+ _onResizeMouseUp ( ) {
380
+ this . _initialX = null ;
381
+ this . _initialY = null ;
382
+ this . _initialWidth = null ;
383
+ this . _initialHeight = null ;
384
+ this . _initialTop = null ;
385
+ this . _initialLeft = null ;
386
+ this . _minWidth = null ;
387
+ this . _minHeight = null ;
388
+
389
+ this . _detachResizeHandlers ( ) ;
390
+ }
391
+
392
+ _attachResizeHandlers ( ) {
393
+ window . addEventListener ( "mousemove" , this . _resizeMouseMoveHandler ) ;
394
+ window . addEventListener ( "mouseup" , this . _resizeMouseUpHandler ) ;
395
+ this . addEventListener ( "ui5-before-close" , this . _revertSize ) ;
396
+ }
397
+
398
+ _detachResizeHandlers ( ) {
399
+ window . removeEventListener ( "mousemove" , this . _resizeMouseMoveHandler ) ;
400
+ window . removeEventListener ( "mouseup" , this . _resizeMouseUpHandler ) ;
401
+ }
402
+
403
+ _revertSize ( ) {
404
+ Object . assign ( this . style , {
405
+ top : "" ,
406
+ left : "" ,
407
+ width : "" ,
408
+ height : "" ,
409
+ transform : "" ,
410
+ } ) ;
411
+ this . removeEventListener ( "ui5-before-close" , this . _revertSize ) ;
412
+ }
271
413
}
272
414
273
415
Dialog . define ( ) ;
0 commit comments