Skip to content

Commit e537ef2

Browse files
author
Guillaume Chau
committed
feat(widget): resize improvements
1 parent 455c5c5 commit e537ef2

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

packages/@vue/cli-ui/src/components/Widget.vue

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
@click.stop="remove()"
6868
/>
6969

70-
<template v-if="isSelected">
70+
<template v-if="showResizeHandle">
7171
<div
7272
v-for="handle of resizeHandles"
7373
:key="handle"
@@ -141,7 +141,7 @@ const GRID_SIZE = 200
141141
142142
const state = new Vue({
143143
data: {
144-
selectedWidget: null
144+
selectedWidgetId: null
145145
}
146146
})
147147
@@ -237,7 +237,7 @@ export default {
237237
},
238238
239239
isSelected () {
240-
return this.widget === state.selectedWidget
240+
return this.widget.id === state.selectedWidgetId
241241
}
242242
},
243243
@@ -250,7 +250,7 @@ export default {
250250
251251
customizeMode (value) {
252252
if (!value && this.isSelected) {
253-
state.selectedWidget = null
253+
state.selectedWidgetId = null
254254
}
255255
}
256256
},
@@ -314,7 +314,7 @@ export default {
314314
},
315315
316316
select () {
317-
state.selectedWidget = this.widget
317+
state.selectedWidgetId = this.widget.id
318318
},
319319
320320
async onMoved () {
@@ -426,6 +426,9 @@ export default {
426426
v-box()
427427
box-center()
428428
cursor move
429+
user-select none
430+
box-sizing border-box
431+
border transparent 1px solid
429432
430433
/deep/ > *
431434
transition transform .15s
@@ -448,8 +451,7 @@ export default {
448451
fill @color
449452
450453
.customize-overlay:hover,
451-
.moving .customize-overlay,
452-
.resizing .customize-overlay
454+
.selected .customize-overlay
453455
background rgba($vue-ui-color-primary, .2)
454456
455457
.remove-button
@@ -510,31 +512,33 @@ export default {
510512
511513
.move-ghost,
512514
.resize-ghost
515+
z-index 10000
513516
.backdrop
514517
background rgba($vue-ui-color-accent, .2)
515518
border-radius ($br / .7)
516519
.vue-ui-dark-mode &
517520
background rgba(lighten($vue-ui-color-accent, 60%), .2)
518521
519-
.moving
522+
.moving,
523+
.resizing
520524
.shell
521525
z-index 10001
526+
527+
.moving
528+
.shell
522529
.wrapper
523530
box-shadow 0 5px 30px rgba($md-black, .2)
524-
.move-ghost
525-
z-index 10000
526531
527532
.resizing
528533
.shell
529-
z-index 10001
530534
opacity .5
531-
.resize-ghost
532-
z-index 10000
533535
534536
.widget
537+
.shell
538+
transition opacity .15s
535539
&:not(.moving):not(.resizing)
536540
.shell
537-
transition left .15s, top .15s, width .15s, height .15s
541+
transition opacity .15s, left .15s, top .15s, width .15s, height .15s
538542
539543
&.selected
540544
.customize-overlay

packages/@vue/cli-ui/src/mixins/Resizable.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ export default function ({
1010
}
1111
},
1212

13+
computed: {
14+
showResizeHandle () {
15+
return this.isSelected && !this.moveState &&
16+
this.canBeResized
17+
},
18+
19+
canBeResized () {
20+
const { definition } = this[field]
21+
return definition.minWidth !== definition.maxWidth ||
22+
definition.minHeight !== definition.maxHeight
23+
}
24+
},
25+
1326
created () {
1427
this.resizeHandles = [
1528
'top-left',

0 commit comments

Comments
 (0)