Skip to content

Commit a3a1a48

Browse files
committed
standard grid working with slots
1 parent 8025fa9 commit a3a1a48

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ <h1>Vue Grid Layout</h1>
2121
</div>
2222
</div>
2323
<div id="content">
24-
<!--<responsive-grid-layout :layout.sync="layout" :layouts="layouts" :row-height="30" :is-draggable="true" :vertical-compact="true">
25-
<text-item v-for="item in layout" :text="item.i"></text-item>
26-
</responsive-grid-layout>-->
2724
<!--<responsive-grid-layout :layout.sync="layout" :layouts="layouts" :row-height="30" :is-draggable="true" :vertical-compact="true">
2825
<grid-item v-for="item in layout"
2926
:x.sync="item.x"

src/GridItem.vue

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div v-el:item
33
class="vue-grid-item"
44
:class="{ 'vue-resizable' : isResizable, 'vue-draggable-dragging' : isDragging, 'cssTransforms' : useCssTransforms }"
5-
style="{{{createStyle}}}"
5+
:style="style"
66
>
77
<slot></slot>
88
<!--span class="text">{{id}}</span-->
@@ -205,7 +205,7 @@
205205
this.isDraggable = this.$parent.isDraggable;
206206
this.isResizable = this.$parent.isResizable;
207207
this.useCssTransforms = this.$parent.useCssTransforms;
208-
// this.createStyle();
208+
this.createStyle();
209209
// var self = this;
210210
if (this.isDraggable) {
211211
var element = this.$els.item;
@@ -223,13 +223,28 @@
223223
}
224224
//this.pos = this.calcPosition();
225225
},
226-
/*watch: {
226+
watch: {
227227
cols: function() {
228228
this.createStyle();
229+
},
230+
containerWidth: function() {
231+
this.createStyle();
232+
},
233+
x: function() {
234+
this.createStyle();
235+
},
236+
y: function() {
237+
this.createStyle();
238+
},
239+
h: function() {
240+
this.createStyle();
241+
},
242+
w: function() {
243+
this.createStyle();
229244
}
230-
},*/
245+
},
231246
computed: {
232-
createStyle: function() {
247+
/*createStyle: function() {
233248
var pos = this.calcPosition(this.x, this.y, this.w, this.h);
234249
//const {usePercentages, containerWidth, useCssTransforms} = this.props;
235250
@@ -244,7 +259,7 @@
244259
}
245260
246261
return createMarkup(style);
247-
},
262+
},*/
248263
},
249264
methods: {
250265
createStyle: function() {
@@ -308,12 +323,16 @@
308323
*/
309324
// Get new WH
310325
var pos = this.calcWH(newSize.height, newSize.width);
311-
this.w = pos.w;
312326
if (pos.h >= 1) {
313327
this.h = pos.h;
314328
} else {
315329
this.h = 1;
316330
}
331+
if (pos.w >= 1) {
332+
this.w = pos.w;
333+
} else {
334+
this.w = 1;
335+
}
317336
318337
var shouldUpdate = false;
319338
if (this.lastW !== x && this.lastH !== y) {
@@ -370,7 +389,7 @@
370389
clientRect = event.target.getBoundingClientRect();
371390
newPosition.left = clientRect.left - parentRect.left;
372391
newPosition.top = clientRect.top - parentRect.top;
373-
console.log("### drag end => " + JSON.stringify(newPosition));
392+
// console.log("### drag end => " + JSON.stringify(newPosition));
374393
// console.log("### DROP: " + JSON.stringify(newPosition));
375394
this.dragging = null;
376395
this.isDragging = false;

src/GridLayout.vue

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
<template>
22
<div class="vue-grid-layout container" :style="mergedStyle">
33
<slot></slot>
4-
<!--grid-item v-for="item in layout"
5-
:cols="cols"
6-
:container-width="width"
7-
:margin="margin"
8-
:max-rows="maxRows"
9-
:row-height="rowHeight"
10-
:is-draggable="isDraggable"
11-
:is-resizable="isResizable"
12-
:use-css-transforms="useCssTransforms"
13-
:x.sync="item.x"
14-
:y.sync="item.y"
15-
:w.sync="item.w"
16-
:h.sync="item.h"
17-
:id="item.i"
18-
:component="item.component"
19-
>
20-
</grid-item-->
214
</div>
225
</template>
236
<style>
@@ -90,8 +73,11 @@
9073
},
9174
ready() {
9275
if (this.width === null) {
93-
this.width = this.$parent.$el.offsetWidth - (this.margin[0] * 2);
94-
window.addEventListener('resize', this.onWindowResize);
76+
this.$nextTick(function() {
77+
// this.width = this.$parent.$el.offsetWidth - (this.margin[0] * 2);
78+
this.width = this.$parent.$el.offsetWidth;
79+
window.addEventListener('resize', this.onWindowResize);
80+
});
9581
}
9682
this.layout = compact(this.layout, this.verticalCompact);
9783
@@ -112,8 +98,8 @@
11298
};
11399
},
114100
onWindowResize: function() {
115-
if (this.$parent.$el.offsetWidth !== undefined) {
116-
this.width = this.$parent.$el.offsetWidth - (this.margin[0] * 2);
101+
if (this.$parent !== null && this.$parent.$el.offsetWidth !== undefined) {
102+
this.width = this.$parent.$el.offsetWidth;
117103
}
118104
},
119105
containerHeight: function() {

0 commit comments

Comments
 (0)