buefy 0.9.12 → 0.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buefy.css +1 -1
- package/dist/buefy.esm.js +106 -104
- package/dist/buefy.esm.min.js +2 -2
- package/dist/buefy.js +106 -104
- package/dist/buefy.min.css +1 -1
- package/dist/buefy.min.js +2 -2
- package/dist/cjs/autocomplete.js +4 -4
- package/dist/cjs/button.js +2 -2
- package/dist/cjs/carousel.js +5 -5
- package/dist/cjs/{chunk-47e1b22b.js → chunk-114191ae.js} +2 -2
- package/dist/cjs/{chunk-db3fa73a.js → chunk-2062216d.js} +1 -1
- package/dist/cjs/{chunk-d9a33552.js → chunk-2911aa4b.js} +45 -45
- package/dist/cjs/{chunk-de7a7f98.js → chunk-2ae50815.js} +3 -3
- package/dist/cjs/{chunk-01268607.js → chunk-2c7de785.js} +0 -0
- package/dist/cjs/{chunk-30d55827.js → chunk-30670fac.js} +2 -2
- package/dist/cjs/{chunk-c3495010.js → chunk-34949503.js} +0 -0
- package/dist/cjs/{chunk-2dc027c9.js → chunk-3cc5d9a6.js} +0 -0
- package/dist/cjs/{chunk-a14ca5bf.js → chunk-61023b09.js} +1 -1
- package/dist/cjs/{chunk-c5a552d4.js → chunk-6cb902f8.js} +0 -0
- package/dist/cjs/{chunk-7b13241d.js → chunk-7da0c017.js} +4 -2
- package/dist/cjs/{chunk-bd1feb6c.js → chunk-9e4cf4c5.js} +0 -0
- package/dist/cjs/{chunk-ea7e1e7e.js → chunk-a11294f9.js} +1 -1
- package/dist/cjs/{chunk-3aaecc36.js → chunk-c6fbc7b4.js} +1 -1
- package/dist/cjs/{chunk-dcf024d2.js → chunk-c7b2aa4b.js} +0 -0
- package/dist/cjs/{chunk-40697b2f.js → chunk-d0f8ea39.js} +6 -6
- package/dist/cjs/{chunk-c00639be.js → chunk-d120e215.js} +0 -0
- package/dist/cjs/{chunk-cb3ee6f4.js → chunk-d54e40f6.js} +0 -0
- package/dist/cjs/{chunk-adaa5792.js → chunk-f5106717.js} +2 -2
- package/dist/cjs/{chunk-66710d19.js → chunk-fe2f57ee.js} +1 -1
- package/dist/cjs/{chunk-344f6275.js → chunk-fefd7b77.js} +0 -0
- package/dist/cjs/clockpicker.js +7 -7
- package/dist/cjs/datepicker.js +8 -8
- package/dist/cjs/datetimepicker.js +10 -10
- package/dist/cjs/dialog.js +10 -10
- package/dist/cjs/dropdown.js +2 -2
- package/dist/cjs/field.js +1 -1
- package/dist/cjs/helpers.js +50 -50
- package/dist/cjs/icon.js +1 -1
- package/dist/cjs/image.js +1 -1
- package/dist/cjs/index.js +21 -21
- package/dist/cjs/input.js +3 -3
- package/dist/cjs/loading.js +1 -1
- package/dist/cjs/menu.js +1 -1
- package/dist/cjs/message.js +2 -2
- package/dist/cjs/modal.js +1 -1
- package/dist/cjs/notification.js +3 -3
- package/dist/cjs/numberinput.js +6 -6
- package/dist/cjs/pagination.js +2 -2
- package/dist/cjs/progress.js +1 -1
- package/dist/cjs/rate.js +1 -1
- package/dist/cjs/select.js +3 -3
- package/dist/cjs/slider.js +1 -1
- package/dist/cjs/snackbar.js +1 -1
- package/dist/cjs/steps.js +4 -4
- package/dist/cjs/table.js +7 -7
- package/dist/cjs/tabs.js +4 -4
- package/dist/cjs/taginput.js +4 -4
- package/dist/cjs/timepicker.js +9 -9
- package/dist/cjs/toast.js +1 -1
- package/dist/cjs/tooltip.js +1 -1
- package/dist/cjs/upload.js +1 -1
- package/dist/components/autocomplete/index.js +5 -5
- package/dist/components/autocomplete/index.min.js +1 -1
- package/dist/components/breadcrumb/index.js +1 -1
- package/dist/components/breadcrumb/index.min.js +1 -1
- package/dist/components/button/index.js +3 -3
- package/dist/components/button/index.min.js +1 -1
- package/dist/components/carousel/index.js +26 -26
- package/dist/components/carousel/index.min.js +1 -1
- package/dist/components/checkbox/index.js +1 -1
- package/dist/components/checkbox/index.min.js +1 -1
- package/dist/components/clockpicker/index.js +22 -20
- package/dist/components/clockpicker/index.min.js +2 -2
- package/dist/components/collapse/index.js +1 -1
- package/dist/components/collapse/index.min.js +1 -1
- package/dist/components/datepicker/index.js +71 -69
- package/dist/components/datepicker/index.min.js +2 -2
- package/dist/components/datetimepicker/index.js +71 -69
- package/dist/components/datetimepicker/index.min.js +2 -2
- package/dist/components/dialog/index.js +10 -10
- package/dist/components/dialog/index.min.js +1 -1
- package/dist/components/dropdown/index.js +6 -6
- package/dist/components/dropdown/index.min.js +1 -1
- package/dist/components/field/index.js +5 -3
- package/dist/components/field/index.min.js +2 -2
- package/dist/components/icon/index.js +3 -3
- package/dist/components/icon/index.min.js +1 -1
- package/dist/components/image/index.js +4 -4
- package/dist/components/image/index.min.js +1 -1
- package/dist/components/input/index.js +3 -3
- package/dist/components/input/index.min.js +1 -1
- package/dist/components/loading/index.js +3 -3
- package/dist/components/loading/index.min.js +1 -1
- package/dist/components/menu/index.js +3 -3
- package/dist/components/menu/index.min.js +1 -1
- package/dist/components/message/index.js +3 -3
- package/dist/components/message/index.min.js +1 -1
- package/dist/components/modal/index.js +3 -3
- package/dist/components/modal/index.min.js +1 -1
- package/dist/components/navbar/index.js +1 -1
- package/dist/components/navbar/index.min.js +1 -1
- package/dist/components/notification/index.js +3 -3
- package/dist/components/notification/index.min.js +1 -1
- package/dist/components/numberinput/index.js +6 -6
- package/dist/components/numberinput/index.min.js +1 -1
- package/dist/components/pagination/index.js +3 -3
- package/dist/components/pagination/index.min.js +1 -1
- package/dist/components/progress/index.js +6 -6
- package/dist/components/progress/index.min.js +1 -1
- package/dist/components/radio/index.js +1 -1
- package/dist/components/radio/index.min.js +1 -1
- package/dist/components/rate/index.js +3 -3
- package/dist/components/rate/index.min.js +1 -1
- package/dist/components/select/index.js +3 -3
- package/dist/components/select/index.min.js +1 -1
- package/dist/components/sidebar/index.js +1 -1
- package/dist/components/sidebar/index.min.js +1 -1
- package/dist/components/skeleton/index.js +1 -1
- package/dist/components/skeleton/index.min.js +1 -1
- package/dist/components/slider/index.js +7 -7
- package/dist/components/slider/index.min.js +1 -1
- package/dist/components/snackbar/index.js +3 -3
- package/dist/components/snackbar/index.min.js +1 -1
- package/dist/components/steps/index.js +14 -14
- package/dist/components/steps/index.min.js +1 -1
- package/dist/components/switch/index.js +1 -1
- package/dist/components/switch/index.min.js +1 -1
- package/dist/components/table/index.js +10 -10
- package/dist/components/table/index.min.js +1 -1
- package/dist/components/tabs/index.js +14 -14
- package/dist/components/tabs/index.min.js +1 -1
- package/dist/components/tag/index.js +1 -1
- package/dist/components/tag/index.min.js +1 -1
- package/dist/components/taginput/index.js +5 -5
- package/dist/components/taginput/index.min.js +1 -1
- package/dist/components/timepicker/index.js +22 -20
- package/dist/components/timepicker/index.min.js +2 -2
- package/dist/components/toast/index.js +3 -3
- package/dist/components/toast/index.min.js +1 -1
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/tooltip/index.min.js +1 -1
- package/dist/components/upload/index.js +1 -1
- package/dist/components/upload/index.min.js +1 -1
- package/dist/esm/autocomplete.js +5 -5
- package/dist/esm/button.js +3 -3
- package/dist/esm/carousel.js +5 -5
- package/dist/esm/{chunk-3dbb54cd.js → chunk-18e8b067.js} +1 -1
- package/dist/esm/{chunk-7d9db167.js → chunk-21fc0948.js} +6 -6
- package/dist/esm/{chunk-a146937d.js → chunk-22e9f916.js} +45 -45
- package/dist/esm/{chunk-18fcd4ac.js → chunk-29ca0df8.js} +0 -0
- package/dist/esm/{chunk-affd6df1.js → chunk-3773c62d.js} +0 -0
- package/dist/esm/{chunk-7ee6c15c.js → chunk-4b67a181.js} +1 -1
- package/dist/esm/{chunk-f97f6a90.js → chunk-6019fd7a.js} +2 -2
- package/dist/esm/{chunk-d9794c38.js → chunk-71a547bc.js} +0 -0
- package/dist/esm/{chunk-161dac72.js → chunk-75a5af93.js} +0 -0
- package/dist/esm/{chunk-4f046bae.js → chunk-799e084d.js} +0 -0
- package/dist/esm/{chunk-6b53dd42.js → chunk-83eb0d37.js} +2 -2
- package/dist/esm/{chunk-80ec133b.js → chunk-8d0f95b8.js} +3 -3
- package/dist/esm/{chunk-50188ced.js → chunk-9f7f7441.js} +0 -0
- package/dist/esm/{chunk-3098b0e9.js → chunk-ae8ab23a.js} +2 -2
- package/dist/esm/{chunk-0f30042f.js → chunk-b07e3182.js} +4 -2
- package/dist/esm/{chunk-a64bdef6.js → chunk-b0c0c6b0.js} +0 -0
- package/dist/esm/{chunk-cdfb7fda.js → chunk-c9c58d0c.js} +0 -0
- package/dist/esm/{chunk-f6b30428.js → chunk-d7f92d97.js} +1 -1
- package/dist/esm/{chunk-9957ac1a.js → chunk-d92f0cd9.js} +0 -0
- package/dist/esm/{chunk-72ad8d50.js → chunk-e7c9b2cb.js} +1 -1
- package/dist/esm/{chunk-8b279c1f.js → chunk-ece062a7.js} +1 -1
- package/dist/esm/clockpicker.js +7 -7
- package/dist/esm/datepicker.js +9 -9
- package/dist/esm/datetimepicker.js +10 -10
- package/dist/esm/dialog.js +10 -10
- package/dist/esm/dropdown.js +3 -3
- package/dist/esm/field.js +2 -2
- package/dist/esm/helpers.js +50 -50
- package/dist/esm/icon.js +2 -2
- package/dist/esm/image.js +2 -2
- package/dist/esm/index.js +21 -21
- package/dist/esm/input.js +4 -4
- package/dist/esm/loading.js +2 -2
- package/dist/esm/menu.js +1 -1
- package/dist/esm/message.js +2 -2
- package/dist/esm/modal.js +2 -2
- package/dist/esm/notification.js +3 -3
- package/dist/esm/numberinput.js +6 -6
- package/dist/esm/pagination.js +3 -3
- package/dist/esm/progress.js +1 -1
- package/dist/esm/rate.js +1 -1
- package/dist/esm/select.js +4 -4
- package/dist/esm/slider.js +1 -1
- package/dist/esm/snackbar.js +1 -1
- package/dist/esm/steps.js +4 -4
- package/dist/esm/table.js +7 -7
- package/dist/esm/tabs.js +4 -4
- package/dist/esm/taginput.js +4 -4
- package/dist/esm/timepicker.js +10 -10
- package/dist/esm/toast.js +1 -1
- package/dist/esm/tooltip.js +2 -2
- package/dist/esm/upload.js +1 -1
- package/package.json +171 -171
- package/src/components/breadcrumb/BreadcrumbItem.spec.js +25 -25
- package/src/components/carousel/CarouselList.vue +313 -313
- package/src/components/carousel/__snapshots__/CarouselList.spec.js.snap +156 -156
- package/src/components/datepicker/Datepicker.vue +843 -843
- package/src/components/dialog/Dialog.vue +256 -256
- package/src/components/field/Field.vue +3 -3
- package/src/components/image/Image.vue +309 -309
- package/src/components/numberinput/Numberinput.vue +309 -309
- package/src/utils/helpers.js +291 -291
|
@@ -1,313 +1,313 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
class="carousel-list"
|
|
4
|
-
:class="{'has-shadow': scrollIndex > 0}"
|
|
5
|
-
@mousedown.prevent="dragStart"
|
|
6
|
-
@touchstart="dragStart">
|
|
7
|
-
<div
|
|
8
|
-
class="carousel-slides"
|
|
9
|
-
:class="listClass"
|
|
10
|
-
:style="'transform:translateX('+translation+'px)'">
|
|
11
|
-
<div
|
|
12
|
-
v-for="(list, index) in data"
|
|
13
|
-
class="carousel-slide"
|
|
14
|
-
:class="{'is-active': asIndicator ? activeItem === index : scrollIndex === index}"
|
|
15
|
-
@mouseup="checkAsIndicator(index, $event)"
|
|
16
|
-
@touchend="checkAsIndicator(index, $event)"
|
|
17
|
-
:key="index"
|
|
18
|
-
:style="itemStyle">
|
|
19
|
-
<slot
|
|
20
|
-
:index="index"
|
|
21
|
-
:active="activeItem"
|
|
22
|
-
:scroll="scrollIndex"
|
|
23
|
-
v-bind="list"
|
|
24
|
-
:list="list"
|
|
25
|
-
name="item">
|
|
26
|
-
<b-image
|
|
27
|
-
:src="list.image"
|
|
28
|
-
v-bind="list"
|
|
29
|
-
/>
|
|
30
|
-
</slot>
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
<div
|
|
34
|
-
v-if="arrow"
|
|
35
|
-
class="carousel-arrow"
|
|
36
|
-
:class="{'is-hovered': settings.arrowHover}">
|
|
37
|
-
<b-icon
|
|
38
|
-
v-show="hasPrev"
|
|
39
|
-
class="has-icons-left"
|
|
40
|
-
@click.native.prevent="prev"
|
|
41
|
-
:pack="settings.iconPack"
|
|
42
|
-
:icon="settings.iconPrev"
|
|
43
|
-
:size="settings.iconSize"
|
|
44
|
-
both />
|
|
45
|
-
<b-icon
|
|
46
|
-
v-show="hasNext"
|
|
47
|
-
class="has-icons-right"
|
|
48
|
-
@click.native.prevent="next"
|
|
49
|
-
:pack="settings.iconPack"
|
|
50
|
-
:icon="settings.iconNext"
|
|
51
|
-
:size="settings.iconSize"
|
|
52
|
-
both />
|
|
53
|
-
</div>
|
|
54
|
-
</div>
|
|
55
|
-
</template>
|
|
56
|
-
|
|
57
|
-
<script>
|
|
58
|
-
import {sign, mod, bound} from '../../utils/helpers'
|
|
59
|
-
import config from '../../utils/config'
|
|
60
|
-
|
|
61
|
-
import Icon from '../icon/Icon'
|
|
62
|
-
import Image from '../image/Image'
|
|
63
|
-
|
|
64
|
-
export default {
|
|
65
|
-
name: 'BCarouselList',
|
|
66
|
-
components: {
|
|
67
|
-
[Icon.name]: Icon,
|
|
68
|
-
[Image.name]: Image
|
|
69
|
-
},
|
|
70
|
-
props: {
|
|
71
|
-
data: {
|
|
72
|
-
type: Array,
|
|
73
|
-
default: () => []
|
|
74
|
-
},
|
|
75
|
-
value: {
|
|
76
|
-
type: Number,
|
|
77
|
-
default: 0
|
|
78
|
-
},
|
|
79
|
-
scrollValue: {
|
|
80
|
-
type: Number,
|
|
81
|
-
default: 0
|
|
82
|
-
},
|
|
83
|
-
hasDrag: {
|
|
84
|
-
type: Boolean,
|
|
85
|
-
default: true
|
|
86
|
-
},
|
|
87
|
-
hasGrayscale: Boolean,
|
|
88
|
-
hasOpacity: Boolean,
|
|
89
|
-
repeat: Boolean,
|
|
90
|
-
itemsToShow: {
|
|
91
|
-
type: Number,
|
|
92
|
-
default: 4
|
|
93
|
-
},
|
|
94
|
-
itemsToList: {
|
|
95
|
-
type: Number,
|
|
96
|
-
default: 1
|
|
97
|
-
},
|
|
98
|
-
asIndicator: Boolean,
|
|
99
|
-
arrow: {
|
|
100
|
-
type: Boolean,
|
|
101
|
-
default: true
|
|
102
|
-
},
|
|
103
|
-
arrowHover: {
|
|
104
|
-
type: Boolean,
|
|
105
|
-
default: true
|
|
106
|
-
},
|
|
107
|
-
iconPack: String,
|
|
108
|
-
iconSize: String,
|
|
109
|
-
iconPrev: {
|
|
110
|
-
type: String,
|
|
111
|
-
default: () => {
|
|
112
|
-
return config.defaultIconPrev
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
iconNext: {
|
|
116
|
-
type: String,
|
|
117
|
-
default: () => {
|
|
118
|
-
return config.defaultIconNext
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
breakpoints: {
|
|
122
|
-
type: Object,
|
|
123
|
-
default: () => ({})
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
data() {
|
|
127
|
-
return {
|
|
128
|
-
activeItem: this.value,
|
|
129
|
-
scrollIndex: this.asIndicator ? this.scrollValue : this.value,
|
|
130
|
-
delta: 0,
|
|
131
|
-
dragX: false,
|
|
132
|
-
hold: 0,
|
|
133
|
-
windowWidth: 0,
|
|
134
|
-
touch: false,
|
|
135
|
-
observer: null,
|
|
136
|
-
refresh_: 0
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
computed: {
|
|
140
|
-
dragging() {
|
|
141
|
-
return this.dragX !== false
|
|
142
|
-
},
|
|
143
|
-
listClass() {
|
|
144
|
-
return [
|
|
145
|
-
{
|
|
146
|
-
'has-grayscale': this.settings.hasGrayscale,
|
|
147
|
-
'has-opacity': this.settings.hasOpacity,
|
|
148
|
-
'is-dragging': this.dragging
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
},
|
|
152
|
-
itemStyle() {
|
|
153
|
-
return `width: ${this.itemWidth}px;`
|
|
154
|
-
},
|
|
155
|
-
translation() {
|
|
156
|
-
return -bound(
|
|
157
|
-
this.delta + (this.scrollIndex * this.itemWidth), 0,
|
|
158
|
-
(this.data.length - this.settings.itemsToShow) * this.itemWidth
|
|
159
|
-
)
|
|
160
|
-
},
|
|
161
|
-
total() {
|
|
162
|
-
return this.data.length - this.settings.itemsToShow
|
|
163
|
-
},
|
|
164
|
-
hasPrev() {
|
|
165
|
-
return (this.settings.repeat || this.scrollIndex > 0)
|
|
166
|
-
},
|
|
167
|
-
hasNext() {
|
|
168
|
-
return (this.settings.repeat || this.scrollIndex < this.total)
|
|
169
|
-
},
|
|
170
|
-
breakpointKeys() {
|
|
171
|
-
return Object.keys(this.breakpoints).sort((a, b) => b - a)
|
|
172
|
-
},
|
|
173
|
-
settings() {
|
|
174
|
-
let breakpoint = this.breakpointKeys.filter((breakpoint) => {
|
|
175
|
-
if (this.windowWidth >= breakpoint) {
|
|
176
|
-
return true
|
|
177
|
-
}
|
|
178
|
-
})[0]
|
|
179
|
-
if (breakpoint) {
|
|
180
|
-
return {...this.$props, ...this.breakpoints[breakpoint]}
|
|
181
|
-
}
|
|
182
|
-
return this.$props
|
|
183
|
-
},
|
|
184
|
-
itemWidth() {
|
|
185
|
-
if (this.windowWidth) { // Ensure component is mounted
|
|
186
|
-
/* eslint-disable-next-line */
|
|
187
|
-
this.refresh_; // We force the computed property to refresh if this prop is changed
|
|
188
|
-
|
|
189
|
-
const rect = this.$el.getBoundingClientRect()
|
|
190
|
-
return rect.width / this.settings.itemsToShow
|
|
191
|
-
}
|
|
192
|
-
return 0
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
watch: {
|
|
196
|
-
/**
|
|
197
|
-
* When v-model is changed set the new active item.
|
|
198
|
-
*/
|
|
199
|
-
value(value) {
|
|
200
|
-
this.switchTo(this.asIndicator ? value - (this.itemsToShow - 3) / 2 : value)
|
|
201
|
-
if (this.activeItem !== value) {
|
|
202
|
-
this.activeItem = bound(value, 0, this.data.length - 1)
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
scrollValue(value) {
|
|
206
|
-
this.switchTo(value)
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
methods: {
|
|
210
|
-
resized() {
|
|
211
|
-
this.windowWidth = window.innerWidth
|
|
212
|
-
},
|
|
213
|
-
switchTo(newIndex) {
|
|
214
|
-
if (newIndex === this.scrollIndex || isNaN(newIndex)) { return }
|
|
215
|
-
|
|
216
|
-
if (this.settings.repeat) {
|
|
217
|
-
newIndex = mod(newIndex, this.total + 1)
|
|
218
|
-
}
|
|
219
|
-
newIndex = bound(newIndex, 0, this.total)
|
|
220
|
-
this.scrollIndex = newIndex
|
|
221
|
-
if (!this.asIndicator && this.value !== newIndex) {
|
|
222
|
-
this.$emit('input', newIndex)
|
|
223
|
-
} else if (this.scrollIndex !== newIndex) {
|
|
224
|
-
this.$emit('updated:scroll', newIndex)
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
next() {
|
|
228
|
-
this.switchTo(this.scrollIndex + this.settings.itemsToList)
|
|
229
|
-
},
|
|
230
|
-
prev() {
|
|
231
|
-
this.switchTo(this.scrollIndex - this.settings.itemsToList)
|
|
232
|
-
},
|
|
233
|
-
checkAsIndicator(value, event) {
|
|
234
|
-
if (!this.asIndicator) return
|
|
235
|
-
|
|
236
|
-
const dragEndX = event.changedTouches ? event.changedTouches[0].clientX : event.clientX
|
|
237
|
-
if (this.hold - Date.now() > 2000 || Math.abs(this.dragX - dragEndX) > 10) return
|
|
238
|
-
|
|
239
|
-
this.dragX = false
|
|
240
|
-
this.hold = 0
|
|
241
|
-
event.preventDefault()
|
|
242
|
-
|
|
243
|
-
// Make the item appear in the middle
|
|
244
|
-
this.activeItem = value
|
|
245
|
-
|
|
246
|
-
this.$emit('switch', value)
|
|
247
|
-
},
|
|
248
|
-
// handle drag event
|
|
249
|
-
dragStart(event) {
|
|
250
|
-
if (this.dragging || !this.settings.hasDrag || (event.button !== 0 && event.type !== 'touchstart')) return
|
|
251
|
-
this.hold = Date.now()
|
|
252
|
-
this.touch = !!event.touches
|
|
253
|
-
this.dragX = this.touch ? event.touches[0].clientX : event.clientX
|
|
254
|
-
window.addEventListener(this.touch ? 'touchmove' : 'mousemove', this.dragMove)
|
|
255
|
-
window.addEventListener(this.touch ? 'touchend' : 'mouseup', this.dragEnd)
|
|
256
|
-
},
|
|
257
|
-
dragMove(event) {
|
|
258
|
-
if (!this.dragging) return
|
|
259
|
-
const dragEndX = event.touches
|
|
260
|
-
? (event.changedTouches[0] || event.touches[0]).clientX : event.clientX
|
|
261
|
-
this.delta = this.dragX - dragEndX
|
|
262
|
-
if (!event.touches) {
|
|
263
|
-
event.preventDefault()
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
dragEnd() {
|
|
267
|
-
if (!this.dragging && !this.hold) return
|
|
268
|
-
if (this.hold) {
|
|
269
|
-
const signCheck = sign(this.delta)
|
|
270
|
-
const results = Math.round(Math.abs(this.delta / this.itemWidth) + 0.15)// Hack
|
|
271
|
-
this.switchTo(this.scrollIndex + signCheck * results)
|
|
272
|
-
}
|
|
273
|
-
this.delta = 0
|
|
274
|
-
this.dragX = false
|
|
275
|
-
window.removeEventListener(this.touch ? 'touchmove' : 'mousemove', this.dragMove)
|
|
276
|
-
window.removeEventListener(this.touch ? 'touchend' : 'mouseup', this.dragEnd)
|
|
277
|
-
},
|
|
278
|
-
refresh() {
|
|
279
|
-
this.$nextTick(() => {
|
|
280
|
-
this.refresh_++
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
mounted() {
|
|
285
|
-
if (typeof window !== 'undefined') {
|
|
286
|
-
if (window.ResizeObserver) {
|
|
287
|
-
this.observer = new ResizeObserver(this.refresh)
|
|
288
|
-
this.observer.observe(this.$el)
|
|
289
|
-
}
|
|
290
|
-
window.addEventListener('resize', this.resized)
|
|
291
|
-
document.addEventListener('animationend', this.refresh)
|
|
292
|
-
document.addEventListener('transitionend', this.refresh)
|
|
293
|
-
document.addEventListener('transitionstart', this.refresh)
|
|
294
|
-
this.resized()
|
|
295
|
-
}
|
|
296
|
-
if (this.$attrs.config) {
|
|
297
|
-
throw new Error('The config prop was removed, you need to use v-bind instead')
|
|
298
|
-
}
|
|
299
|
-
},
|
|
300
|
-
beforeDestroy() {
|
|
301
|
-
if (typeof window !== 'undefined') {
|
|
302
|
-
if (window.ResizeObserver) {
|
|
303
|
-
this.observer.disconnect()
|
|
304
|
-
}
|
|
305
|
-
window.removeEventListener('resize', this.resized)
|
|
306
|
-
document.removeEventListener('animationend', this.refresh)
|
|
307
|
-
document.removeEventListener('transitionend', this.refresh)
|
|
308
|
-
document.removeEventListener('transitionstart', this.refresh)
|
|
309
|
-
this.dragEnd()
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="carousel-list"
|
|
4
|
+
:class="{'has-shadow': scrollIndex > 0}"
|
|
5
|
+
@mousedown.prevent="dragStart"
|
|
6
|
+
@touchstart="dragStart">
|
|
7
|
+
<div
|
|
8
|
+
class="carousel-slides"
|
|
9
|
+
:class="listClass"
|
|
10
|
+
:style="'transform:translateX('+translation+'px)'">
|
|
11
|
+
<div
|
|
12
|
+
v-for="(list, index) in data"
|
|
13
|
+
class="carousel-slide"
|
|
14
|
+
:class="{'is-active': asIndicator ? activeItem === index : scrollIndex === index}"
|
|
15
|
+
@mouseup="checkAsIndicator(index, $event)"
|
|
16
|
+
@touchend="checkAsIndicator(index, $event)"
|
|
17
|
+
:key="index"
|
|
18
|
+
:style="itemStyle">
|
|
19
|
+
<slot
|
|
20
|
+
:index="index"
|
|
21
|
+
:active="activeItem"
|
|
22
|
+
:scroll="scrollIndex"
|
|
23
|
+
v-bind="list"
|
|
24
|
+
:list="list"
|
|
25
|
+
name="item">
|
|
26
|
+
<b-image
|
|
27
|
+
:src="list.image"
|
|
28
|
+
v-bind="list"
|
|
29
|
+
/>
|
|
30
|
+
</slot>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
<div
|
|
34
|
+
v-if="arrow"
|
|
35
|
+
class="carousel-arrow"
|
|
36
|
+
:class="{'is-hovered': settings.arrowHover}">
|
|
37
|
+
<b-icon
|
|
38
|
+
v-show="hasPrev"
|
|
39
|
+
class="has-icons-left"
|
|
40
|
+
@click.native.prevent="prev"
|
|
41
|
+
:pack="settings.iconPack"
|
|
42
|
+
:icon="settings.iconPrev"
|
|
43
|
+
:size="settings.iconSize"
|
|
44
|
+
both />
|
|
45
|
+
<b-icon
|
|
46
|
+
v-show="hasNext"
|
|
47
|
+
class="has-icons-right"
|
|
48
|
+
@click.native.prevent="next"
|
|
49
|
+
:pack="settings.iconPack"
|
|
50
|
+
:icon="settings.iconNext"
|
|
51
|
+
:size="settings.iconSize"
|
|
52
|
+
both />
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
</template>
|
|
56
|
+
|
|
57
|
+
<script>
|
|
58
|
+
import {sign, mod, bound} from '../../utils/helpers'
|
|
59
|
+
import config from '../../utils/config'
|
|
60
|
+
|
|
61
|
+
import Icon from '../icon/Icon'
|
|
62
|
+
import Image from '../image/Image'
|
|
63
|
+
|
|
64
|
+
export default {
|
|
65
|
+
name: 'BCarouselList',
|
|
66
|
+
components: {
|
|
67
|
+
[Icon.name]: Icon,
|
|
68
|
+
[Image.name]: Image
|
|
69
|
+
},
|
|
70
|
+
props: {
|
|
71
|
+
data: {
|
|
72
|
+
type: Array,
|
|
73
|
+
default: () => []
|
|
74
|
+
},
|
|
75
|
+
value: {
|
|
76
|
+
type: Number,
|
|
77
|
+
default: 0
|
|
78
|
+
},
|
|
79
|
+
scrollValue: {
|
|
80
|
+
type: Number,
|
|
81
|
+
default: 0
|
|
82
|
+
},
|
|
83
|
+
hasDrag: {
|
|
84
|
+
type: Boolean,
|
|
85
|
+
default: true
|
|
86
|
+
},
|
|
87
|
+
hasGrayscale: Boolean,
|
|
88
|
+
hasOpacity: Boolean,
|
|
89
|
+
repeat: Boolean,
|
|
90
|
+
itemsToShow: {
|
|
91
|
+
type: Number,
|
|
92
|
+
default: 4
|
|
93
|
+
},
|
|
94
|
+
itemsToList: {
|
|
95
|
+
type: Number,
|
|
96
|
+
default: 1
|
|
97
|
+
},
|
|
98
|
+
asIndicator: Boolean,
|
|
99
|
+
arrow: {
|
|
100
|
+
type: Boolean,
|
|
101
|
+
default: true
|
|
102
|
+
},
|
|
103
|
+
arrowHover: {
|
|
104
|
+
type: Boolean,
|
|
105
|
+
default: true
|
|
106
|
+
},
|
|
107
|
+
iconPack: String,
|
|
108
|
+
iconSize: String,
|
|
109
|
+
iconPrev: {
|
|
110
|
+
type: String,
|
|
111
|
+
default: () => {
|
|
112
|
+
return config.defaultIconPrev
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
iconNext: {
|
|
116
|
+
type: String,
|
|
117
|
+
default: () => {
|
|
118
|
+
return config.defaultIconNext
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
breakpoints: {
|
|
122
|
+
type: Object,
|
|
123
|
+
default: () => ({})
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
data() {
|
|
127
|
+
return {
|
|
128
|
+
activeItem: this.value,
|
|
129
|
+
scrollIndex: this.asIndicator ? this.scrollValue : this.value,
|
|
130
|
+
delta: 0,
|
|
131
|
+
dragX: false,
|
|
132
|
+
hold: 0,
|
|
133
|
+
windowWidth: 0,
|
|
134
|
+
touch: false,
|
|
135
|
+
observer: null,
|
|
136
|
+
refresh_: 0
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
computed: {
|
|
140
|
+
dragging() {
|
|
141
|
+
return this.dragX !== false
|
|
142
|
+
},
|
|
143
|
+
listClass() {
|
|
144
|
+
return [
|
|
145
|
+
{
|
|
146
|
+
'has-grayscale': this.settings.hasGrayscale,
|
|
147
|
+
'has-opacity': this.settings.hasOpacity,
|
|
148
|
+
'is-dragging': this.dragging
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
itemStyle() {
|
|
153
|
+
return `width: ${this.itemWidth}px;`
|
|
154
|
+
},
|
|
155
|
+
translation() {
|
|
156
|
+
return -bound(
|
|
157
|
+
this.delta + (this.scrollIndex * this.itemWidth), 0,
|
|
158
|
+
(this.data.length - this.settings.itemsToShow) * this.itemWidth
|
|
159
|
+
)
|
|
160
|
+
},
|
|
161
|
+
total() {
|
|
162
|
+
return this.data.length - this.settings.itemsToShow
|
|
163
|
+
},
|
|
164
|
+
hasPrev() {
|
|
165
|
+
return (this.settings.repeat || this.scrollIndex > 0)
|
|
166
|
+
},
|
|
167
|
+
hasNext() {
|
|
168
|
+
return (this.settings.repeat || this.scrollIndex < this.total)
|
|
169
|
+
},
|
|
170
|
+
breakpointKeys() {
|
|
171
|
+
return Object.keys(this.breakpoints).sort((a, b) => b - a)
|
|
172
|
+
},
|
|
173
|
+
settings() {
|
|
174
|
+
let breakpoint = this.breakpointKeys.filter((breakpoint) => {
|
|
175
|
+
if (this.windowWidth >= breakpoint) {
|
|
176
|
+
return true
|
|
177
|
+
}
|
|
178
|
+
})[0]
|
|
179
|
+
if (breakpoint) {
|
|
180
|
+
return {...this.$props, ...this.breakpoints[breakpoint]}
|
|
181
|
+
}
|
|
182
|
+
return this.$props
|
|
183
|
+
},
|
|
184
|
+
itemWidth() {
|
|
185
|
+
if (this.windowWidth) { // Ensure component is mounted
|
|
186
|
+
/* eslint-disable-next-line */
|
|
187
|
+
this.refresh_; // We force the computed property to refresh if this prop is changed
|
|
188
|
+
|
|
189
|
+
const rect = this.$el.getBoundingClientRect()
|
|
190
|
+
return rect.width / this.settings.itemsToShow
|
|
191
|
+
}
|
|
192
|
+
return 0
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
watch: {
|
|
196
|
+
/**
|
|
197
|
+
* When v-model is changed set the new active item.
|
|
198
|
+
*/
|
|
199
|
+
value(value) {
|
|
200
|
+
this.switchTo(this.asIndicator ? value - (this.itemsToShow - 3) / 2 : value)
|
|
201
|
+
if (this.activeItem !== value) {
|
|
202
|
+
this.activeItem = bound(value, 0, this.data.length - 1)
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
scrollValue(value) {
|
|
206
|
+
this.switchTo(value)
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
methods: {
|
|
210
|
+
resized() {
|
|
211
|
+
this.windowWidth = window.innerWidth
|
|
212
|
+
},
|
|
213
|
+
switchTo(newIndex) {
|
|
214
|
+
if (newIndex === this.scrollIndex || isNaN(newIndex)) { return }
|
|
215
|
+
|
|
216
|
+
if (this.settings.repeat) {
|
|
217
|
+
newIndex = mod(newIndex, this.total + 1)
|
|
218
|
+
}
|
|
219
|
+
newIndex = bound(newIndex, 0, this.total)
|
|
220
|
+
this.scrollIndex = newIndex
|
|
221
|
+
if (!this.asIndicator && this.value !== newIndex) {
|
|
222
|
+
this.$emit('input', newIndex)
|
|
223
|
+
} else if (this.scrollIndex !== newIndex) {
|
|
224
|
+
this.$emit('updated:scroll', newIndex)
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
next() {
|
|
228
|
+
this.switchTo(this.scrollIndex + this.settings.itemsToList)
|
|
229
|
+
},
|
|
230
|
+
prev() {
|
|
231
|
+
this.switchTo(this.scrollIndex - this.settings.itemsToList)
|
|
232
|
+
},
|
|
233
|
+
checkAsIndicator(value, event) {
|
|
234
|
+
if (!this.asIndicator) return
|
|
235
|
+
|
|
236
|
+
const dragEndX = event.changedTouches ? event.changedTouches[0].clientX : event.clientX
|
|
237
|
+
if (this.hold - Date.now() > 2000 || Math.abs(this.dragX - dragEndX) > 10) return
|
|
238
|
+
|
|
239
|
+
this.dragX = false
|
|
240
|
+
this.hold = 0
|
|
241
|
+
event.preventDefault()
|
|
242
|
+
|
|
243
|
+
// Make the item appear in the middle
|
|
244
|
+
this.activeItem = value
|
|
245
|
+
|
|
246
|
+
this.$emit('switch', value)
|
|
247
|
+
},
|
|
248
|
+
// handle drag event
|
|
249
|
+
dragStart(event) {
|
|
250
|
+
if (this.dragging || !this.settings.hasDrag || (event.button !== 0 && event.type !== 'touchstart')) return
|
|
251
|
+
this.hold = Date.now()
|
|
252
|
+
this.touch = !!event.touches
|
|
253
|
+
this.dragX = this.touch ? event.touches[0].clientX : event.clientX
|
|
254
|
+
window.addEventListener(this.touch ? 'touchmove' : 'mousemove', this.dragMove)
|
|
255
|
+
window.addEventListener(this.touch ? 'touchend' : 'mouseup', this.dragEnd)
|
|
256
|
+
},
|
|
257
|
+
dragMove(event) {
|
|
258
|
+
if (!this.dragging) return
|
|
259
|
+
const dragEndX = event.touches
|
|
260
|
+
? (event.changedTouches[0] || event.touches[0]).clientX : event.clientX
|
|
261
|
+
this.delta = this.dragX - dragEndX
|
|
262
|
+
if (!event.touches) {
|
|
263
|
+
event.preventDefault()
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
dragEnd() {
|
|
267
|
+
if (!this.dragging && !this.hold) return
|
|
268
|
+
if (this.hold) {
|
|
269
|
+
const signCheck = sign(this.delta)
|
|
270
|
+
const results = Math.round(Math.abs(this.delta / this.itemWidth) + 0.15)// Hack
|
|
271
|
+
this.switchTo(this.scrollIndex + signCheck * results)
|
|
272
|
+
}
|
|
273
|
+
this.delta = 0
|
|
274
|
+
this.dragX = false
|
|
275
|
+
window.removeEventListener(this.touch ? 'touchmove' : 'mousemove', this.dragMove)
|
|
276
|
+
window.removeEventListener(this.touch ? 'touchend' : 'mouseup', this.dragEnd)
|
|
277
|
+
},
|
|
278
|
+
refresh() {
|
|
279
|
+
this.$nextTick(() => {
|
|
280
|
+
this.refresh_++
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
mounted() {
|
|
285
|
+
if (typeof window !== 'undefined') {
|
|
286
|
+
if (window.ResizeObserver) {
|
|
287
|
+
this.observer = new ResizeObserver(this.refresh)
|
|
288
|
+
this.observer.observe(this.$el)
|
|
289
|
+
}
|
|
290
|
+
window.addEventListener('resize', this.resized)
|
|
291
|
+
document.addEventListener('animationend', this.refresh)
|
|
292
|
+
document.addEventListener('transitionend', this.refresh)
|
|
293
|
+
document.addEventListener('transitionstart', this.refresh)
|
|
294
|
+
this.resized()
|
|
295
|
+
}
|
|
296
|
+
if (this.$attrs.config) {
|
|
297
|
+
throw new Error('The config prop was removed, you need to use v-bind instead')
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
beforeDestroy() {
|
|
301
|
+
if (typeof window !== 'undefined') {
|
|
302
|
+
if (window.ResizeObserver) {
|
|
303
|
+
this.observer.disconnect()
|
|
304
|
+
}
|
|
305
|
+
window.removeEventListener('resize', this.resized)
|
|
306
|
+
document.removeEventListener('animationend', this.refresh)
|
|
307
|
+
document.removeEventListener('transitionend', this.refresh)
|
|
308
|
+
document.removeEventListener('transitionstart', this.refresh)
|
|
309
|
+
this.dragEnd()
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
</script>
|