fix(Layout): gutter calculation (#6197)
* Revert "fix(Layout): outside of the screen after setting gutter (#6143)"
This reverts commit a460425b26.
* fix(Layout): gutter calculation
* test: fix snapshot
This commit is contained in:
@@ -20,6 +20,47 @@ export default createComponent({
|
||||
},
|
||||
},
|
||||
|
||||
computed: {
|
||||
spaces() {
|
||||
const gutter = Number(this.gutter);
|
||||
|
||||
if (!gutter) {
|
||||
return;
|
||||
}
|
||||
|
||||
const spaces = [];
|
||||
const groups = [[]];
|
||||
|
||||
let totalSpan = 0;
|
||||
this.children.forEach((item, index) => {
|
||||
totalSpan += Number(item.span);
|
||||
|
||||
if (totalSpan > 24) {
|
||||
groups.push([index]);
|
||||
totalSpan -= 24;
|
||||
} else {
|
||||
groups[groups.length - 1].push(index);
|
||||
}
|
||||
});
|
||||
|
||||
groups.forEach((group) => {
|
||||
const averagePadding = (gutter * (group.length - 1)) / group.length;
|
||||
|
||||
group.forEach((item, index) => {
|
||||
if (index === 0) {
|
||||
spaces.push({ right: group.length > 1 ? averagePadding : 0 });
|
||||
} else {
|
||||
const left = gutter - spaces[item - 1].right;
|
||||
const right = averagePadding - left;
|
||||
spaces.push({ left, right });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return spaces;
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
onClick(event) {
|
||||
this.$emit('click', event);
|
||||
|
||||
Reference in New Issue
Block a user