mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
* fix drawer-slider carousel function && convert to pointer logic * refactor conditional logic * get rid of absolute value
This commit is contained in:
@@ -186,6 +186,7 @@
|
|||||||
slot="drawer-slider",
|
slot="drawer-slider",
|
||||||
:itemWidth=94,
|
:itemWidth=94,
|
||||||
:itemMargin=24,
|
:itemMargin=24,
|
||||||
|
:itemType="selectedDrawerTab"
|
||||||
)
|
)
|
||||||
template(slot="item", slot-scope="context")
|
template(slot="item", slot-scope="context")
|
||||||
foodItem(
|
foodItem(
|
||||||
|
|||||||
@@ -194,6 +194,7 @@
|
|||||||
slot="drawer-slider",
|
slot="drawer-slider",
|
||||||
:itemWidth=94,
|
:itemWidth=94,
|
||||||
:itemMargin=24,
|
:itemMargin=24,
|
||||||
|
:itemType="selectedDrawerTab"
|
||||||
)
|
)
|
||||||
template(slot="item", slot-scope="ctx")
|
template(slot="item", slot-scope="ctx")
|
||||||
item(
|
item(
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
)
|
)
|
||||||
div.slider-button-area.left-button(
|
div.slider-button-area.left-button(
|
||||||
v-if="scrollButtonsVisible",
|
v-if="scrollButtonsVisible",
|
||||||
@mousedown.left="lastPage"
|
@mousedown.left="shiftLeft"
|
||||||
)
|
)
|
||||||
a.slider-button
|
a.slider-button
|
||||||
.svg-icon(v-html="icons.previous")
|
.svg-icon(v-html="icons.previous")
|
||||||
div.slider-button-area.right-button(
|
div.slider-button-area.right-button(
|
||||||
v-if="scrollButtonsVisible",
|
v-if="scrollButtonsVisible",
|
||||||
@mousedown.left="nextPage"
|
@mousedown.left="shiftRight"
|
||||||
)
|
)
|
||||||
a.slider-button
|
a.slider-button
|
||||||
.svg-icon(v-html="icons.next")
|
.svg-icon(v-html="icons.next")
|
||||||
@@ -18,8 +18,11 @@
|
|||||||
// 120 = width of the left/right buttons
|
// 120 = width of the left/right buttons
|
||||||
div.sliding-content(v-resize="500", @resized="currentWidth = $event.width - 120")
|
div.sliding-content(v-resize="500", @resized="currentWidth = $event.width - 120")
|
||||||
.items.items-one-line
|
.items.items-one-line
|
||||||
template(v-for="item in pages[currentPage]")
|
template(v-for="item in showItems")
|
||||||
div.vertical-divider(v-if="item.ofNextPage")
|
div.vertical-divider(
|
||||||
|
v-if="shouldAddVerticalLine(item)"
|
||||||
|
v-bind:style="dividerMargins"
|
||||||
|
)
|
||||||
|
|
||||||
slot(
|
slot(
|
||||||
name="item",
|
name="item",
|
||||||
@@ -80,12 +83,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.sliding-content .items {
|
.sliding-content .items {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
margin-left: $buttonAreaWidth+ px;
|
margin-left: $buttonAreaWidth+ px;
|
||||||
|
margin-right: $buttonAreaWidth+ px;
|
||||||
& > div:last-of-type {
|
|
||||||
margin-right: $buttonAreaWidth + 20px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.vertical-divider {
|
.vertical-divider {
|
||||||
@@ -102,8 +106,6 @@
|
|||||||
import next from 'assets/svg/next.svg';
|
import next from 'assets/svg/next.svg';
|
||||||
import ResizeDirective from 'client/directives/resize.directive';
|
import ResizeDirective from 'client/directives/resize.directive';
|
||||||
|
|
||||||
import _chunk from 'lodash/chunk';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
directives: {
|
directives: {
|
||||||
resize: ResizeDirective,
|
resize: ResizeDirective,
|
||||||
@@ -115,45 +117,58 @@
|
|||||||
next,
|
next,
|
||||||
}),
|
}),
|
||||||
currentWidth: 0,
|
currentWidth: 0,
|
||||||
currentPage: 0,
|
pointer: 0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
pages () {
|
showItems () {
|
||||||
return _chunk(this.items, this.itemsPerPage() - 1).map((content, index, array) => {
|
let items = this.items;
|
||||||
let resultData = [...content];
|
let pointer = this.pointer;
|
||||||
|
let itemsPerPage = this.itemsPerPage();
|
||||||
|
let firstSlice = items.slice(pointer, pointer + itemsPerPage);
|
||||||
|
|
||||||
if (array[index + 1]) {
|
if (firstSlice.length === itemsPerPage) {
|
||||||
resultData.push({
|
return firstSlice;
|
||||||
...array[index + 1][0],
|
} else {
|
||||||
ofNextPage: true,
|
let getRemainderItems = itemsPerPage - firstSlice.length;
|
||||||
});
|
let secondSlice = items.slice(0, getRemainderItems);
|
||||||
}
|
|
||||||
|
|
||||||
return resultData;
|
return firstSlice.concat(secondSlice);
|
||||||
});
|
}
|
||||||
|
},
|
||||||
|
dividerMargins () {
|
||||||
|
return {
|
||||||
|
marginLeft: `${-this.itemMargin / 2}px`,
|
||||||
|
marginRight: `${this.itemMargin / 2}px`,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
itemType () {
|
||||||
|
this.pointer = 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
lastPage () {
|
shiftLeft () {
|
||||||
if (this.currentPage > 0) {
|
if (this.pointer < this.items.length - 1) {
|
||||||
this.currentPage--;
|
this.pointer++;
|
||||||
} else {
|
} else {
|
||||||
this.currentPage = this.pages.length - 1;
|
this.pointer = 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
shiftRight () {
|
||||||
nextPage () {
|
if (this.pointer > 0) {
|
||||||
if (this.currentPage < this.pages.length - 1) {
|
this.pointer--;
|
||||||
this.currentPage++;
|
|
||||||
} else {
|
} else {
|
||||||
this.currentPage = 0;
|
this.pointer = this.items.length - 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
itemsPerPage () {
|
itemsPerPage () {
|
||||||
return Math.floor(this.currentWidth / (this.itemWidth + this.itemMargin));
|
return Math.floor(this.currentWidth / (this.itemWidth + this.itemMargin));
|
||||||
},
|
},
|
||||||
|
shouldAddVerticalLine (item) {
|
||||||
|
return this.items[this.itemsPerPage() - 1] === item && this.pointer !== 5;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
scrollButtonsVisible: {
|
scrollButtonsVisible: {
|
||||||
@@ -163,6 +178,9 @@
|
|||||||
items: {
|
items: {
|
||||||
type: Array,
|
type: Array,
|
||||||
},
|
},
|
||||||
|
itemType: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
itemWidth: {
|
itemWidth: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user