Skip to content

Commit 4f78b56

Browse files
author
kirillmurashov
committed
Added: initial "auto" for width and height props
1 parent 3241a19 commit 4f78b56

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

src/component/vue-drag-resize.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.vdr {
22
position: absolute;
33
box-sizing: border-box;
4+
overflow: visible;
45
}
56
.vdr.active:before{
67
content: '';
@@ -39,4 +40,9 @@
3940
}
4041
.vdr-stick.not-resizable{
4142
display: none;
43+
}
44+
45+
.content-container{
46+
display: block;
47+
position: relative;
4248
}

src/component/vue-drag-resize.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
<div class="vdr" :style="style"
1+
<div class="vdr"
2+
:style="positionStyle"
23
:class="`${(active || isActive) ? 'active' : 'inactive'} ${contentClass ? contentClass: ''}`"
34
@mousedown="bodyDown($event)"
45
@touchstart="bodyDown($event)"
5-
@touchend="up($event)">
6-
<slot></slot>
6+
@touchend="up($event)"
7+
ref="container"
8+
tabindex="0">
9+
<div :style="sizeStyle" class="content-container" ref="container2">
10+
<slot></slot>
11+
</div>
712
<div
813
v-for="stick in sticks"
914
class="vdr-stick"

src/component/vue-drag-resize.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export default {
5050
isResizable: {
5151
type: Boolean, default: true,
5252
},
53+
focusable: {
54+
type: Boolean, default: false,
55+
},
5356
aspectRatio: {
5457
type: Boolean, default: false,
5558
},
@@ -63,14 +66,14 @@ export default {
6366
type: Number,
6467
default: 50,
6568
validator(val) {
66-
return val > 0;
69+
return val >= 0;
6770
},
6871
},
6972
gridY: {
7073
type: Number,
7174
default: 50,
7275
validator(val) {
73-
return val > 0;
76+
return val >= 0;
7477
},
7578
},
7679
parentW: {
@@ -88,31 +91,31 @@ export default {
8891
},
8992
},
9093
w: {
91-
type: Number,
94+
type: [String, Number],
9295
default: 200,
9396
validator(val) {
94-
return val > 0;
97+
return (typeof val === 'string') ? val === 'auto' : val >= 0;
9598
},
9699
},
97100
h: {
98-
type: Number,
101+
type: [String, Number],
99102
default: 200,
100103
validator(val) {
101-
return val > 0;
104+
return (typeof val === 'string') ? val === 'auto' : val >= 0;
102105
},
103106
},
104107
minw: {
105108
type: Number,
106109
default: 50,
107110
validator(val) {
108-
return val > 0;
111+
return val >= 0;
109112
},
110113
},
111114
minh: {
112115
type: Number,
113116
default: 50,
114117
validator(val) {
115-
return val > 0;
118+
return val >= 0;
116119
},
117120
},
118121
x: {
@@ -166,6 +169,7 @@ export default {
166169

167170
data() {
168171
return {
172+
fixAspectRatio: null,
169173
active: null,
170174
zIndex: null,
171175
parentWidth: null,
@@ -199,8 +203,8 @@ export default {
199203

200204
this.left = this.x;
201205
this.top = this.y;
202-
this.right = this.parentWidth - this.w - this.left;
203-
this.bottom = this.parentHeight - this.h - this.top;
206+
this.right = this.parentWidth - (this.w === 'auto' ? this.$refs.container.scrollWidth : this.w) - this.left;
207+
this.bottom = this.parentHeight - (this.h === 'auto' ? this.$refs.container.scrollHeight : this.h) - this.top;
204208

205209
this.domEvents = new Map([
206210
['mousemove', this.move],
@@ -679,16 +683,21 @@ export default {
679683
},
680684

681685
computed: {
682-
style() {
686+
positionStyle() {
683687
return {
684688
top: this.top + 'px',
685689
left: this.left + 'px',
686-
width: this.width + 'px',
687-
height: this.height + 'px',
688690
zIndex: this.zIndex,
689691
};
690692
},
691693

694+
sizeStyle(){
695+
return {
696+
width: this.width + 'px',
697+
height: this.height + 'px'
698+
};
699+
},
700+
692701
vdrStick() {
693702
return (stick) => {
694703
const stickStyle = {

0 commit comments

Comments
 (0)