forked from SSENSE/vue-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Navigation.vue
111 lines (106 loc) · 2.55 KB
/
Navigation.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
<div class="VueCarousel-navigation">
<button
type="button"
aria-label="Previous page"
role="button"
class="VueCarousel-navigation-button VueCarousel-navigation-prev"
v-on:click.prevent="triggerPageAdvance('backward')"
v-bind:class="{ 'VueCarousel-navigation--disabled': !canAdvanceBackward }"
v-bind:style="`padding: ${clickTargetSize}px; margin-right: -${clickTargetSize}px;`"
v-html="prevLabel"></button>
<button
type="button"
aria-label="Next page"
role="button"
class="VueCarousel-navigation-button VueCarousel-navigation-next"
v-on:click.prevent="triggerPageAdvance()"
v-bind:class="{ 'VueCarousel-navigation--disabled': !canAdvanceForward }"
v-bind:style="`padding: ${clickTargetSize}px; margin-left: -${clickTargetSize}px;`"
v-html="nextLabel"></button>
</div>
</template>
<script>
export default {
name: "navigation",
inject: ["carousel"],
props: {
/**
* Amount of padding to apply around the label in pixels
*/
clickTargetSize: {
type: Number,
default: 8
},
/**
* Text content of the navigation next button
*/
nextLabel: {
type: String,
default: "▶"
},
/**
* Text content of the navigation prev button
*/
prevLabel: {
type: String,
default: "◀"
}
},
computed: {
/**
* @return {Boolean} Can the slider move forward?
*/
canAdvanceForward() {
return this.carousel.canAdvanceForward || false;
},
/**
* @return {Boolean} Can the slider move backward?
*/
canAdvanceBackward() {
return this.carousel.canAdvanceBackward || false;
}
},
methods: {
/**
* Trigger page change on +/- 1 depending on the direction
* @param {"backward"} [direction]
* @return {void}
*/
triggerPageAdvance(direction) {
/**
* @event paginationclick
* @type {string}
*/
this.$emit("navigationclick", direction);
}
}
};
</script>
<style scoped>
.VueCarousel-navigation-button {
position: absolute;
top: 50%;
box-sizing: border-box;
color: #000;
text-decoration: none;
appearance: none;
border: none;
background-color: transparent;
padding: 0;
cursor: pointer;
outline: none;
}
.VueCarousel-navigation-next {
right: 0;
transform: translateY(-50%) translateX(100%);
}
.VueCarousel-navigation-prev {
left: 0;
transform: translateY(-50%) translateX(-100%);
}
.VueCarousel-navigation--disabled {
opacity: 0.5;
cursor: default;
}
</style>