forked from SSENSE/vue-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Navigation.vue
127 lines (120 loc) · 3.06 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<template>
<div class="VueCarousel-navigation">
<button
type="button"
aria-label="Previous page"
:tabindex="canAdvanceBackward ? 0 : -1"
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"
:tabindex="canAdvanceForward ? 0 : -1"
class="VueCarousel-navigation-button VueCarousel-navigation-next"
v-on:click.prevent="triggerPageAdvance('forward')"
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-button:focus {
outline: 1px solid lightblue;
}
.VueCarousel-navigation-next {
right: 0;
transform: translateY(-50%) translateX(100%);
font-family: "system";
}
.VueCarousel-navigation-prev {
left: 0;
transform: translateY(-50%) translateX(-100%);
font-family: "system";
}
.VueCarousel-navigation--disabled {
opacity: 0.5;
cursor: default;
}
/* Define the "system" font family */
@font-face {
font-family: system;
font-style: normal;
font-weight: 300;
src: local(".SFNSText-Light"), local(".HelveticaNeueDeskInterface-Light"),
local(".LucidaGrandeUI"), local("Ubuntu Light"), local("Segoe UI Symbol"),
local("Roboto-Light"), local("DroidSans"), local("Tahoma");
}
</style>