|
@@ -1,16 +1,16 @@
|
|
<template>
|
|
<template>
|
|
<div
|
|
<div
|
|
- class="el-carousel"
|
|
|
|
- :class="{ 'el-carousel--card': type === 'card' }"
|
|
|
|
|
|
+ :class="carouselClasses"
|
|
@mouseenter.stop="handleMouseEnter"
|
|
@mouseenter.stop="handleMouseEnter"
|
|
@mouseleave.stop="handleMouseLeave">
|
|
@mouseleave.stop="handleMouseLeave">
|
|
<div
|
|
<div
|
|
class="el-carousel__container"
|
|
class="el-carousel__container"
|
|
:style="{ height: height }">
|
|
:style="{ height: height }">
|
|
- <transition name="carousel-arrow-left">
|
|
|
|
|
|
+ <transition
|
|
|
|
+ v-if="arrowDisplay"
|
|
|
|
+ name="carousel-arrow-left">
|
|
<button
|
|
<button
|
|
type="button"
|
|
type="button"
|
|
- v-if="arrow !== 'never'"
|
|
|
|
v-show="(arrow === 'always' || hover) && (loop || activeIndex > 0)"
|
|
v-show="(arrow === 'always' || hover) && (loop || activeIndex > 0)"
|
|
@mouseenter="handleButtonEnter('left')"
|
|
@mouseenter="handleButtonEnter('left')"
|
|
@mouseleave="handleButtonLeave"
|
|
@mouseleave="handleButtonLeave"
|
|
@@ -19,10 +19,11 @@
|
|
<i class="el-icon-arrow-left"></i>
|
|
<i class="el-icon-arrow-left"></i>
|
|
</button>
|
|
</button>
|
|
</transition>
|
|
</transition>
|
|
- <transition name="carousel-arrow-right">
|
|
|
|
|
|
+ <transition
|
|
|
|
+ v-if="arrowDisplay"
|
|
|
|
+ name="carousel-arrow-right">
|
|
<button
|
|
<button
|
|
type="button"
|
|
type="button"
|
|
- v-if="arrow !== 'never'"
|
|
|
|
v-show="(arrow === 'always' || hover) && (loop || activeIndex < items.length - 1)"
|
|
v-show="(arrow === 'always' || hover) && (loop || activeIndex < items.length - 1)"
|
|
@mouseenter="handleButtonEnter('right')"
|
|
@mouseenter="handleButtonEnter('right')"
|
|
@mouseleave="handleButtonLeave"
|
|
@mouseleave="handleButtonLeave"
|
|
@@ -34,16 +35,20 @@
|
|
<slot></slot>
|
|
<slot></slot>
|
|
</div>
|
|
</div>
|
|
<ul
|
|
<ul
|
|
- class="el-carousel__indicators"
|
|
|
|
v-if="indicatorPosition !== 'none'"
|
|
v-if="indicatorPosition !== 'none'"
|
|
- :class="{ 'el-carousel__indicators--labels': hasLabel, 'el-carousel__indicators--outside': indicatorPosition === 'outside' || type === 'card' }">
|
|
|
|
|
|
+ :class="indicatorsClasses">
|
|
<li
|
|
<li
|
|
v-for="(item, index) in items"
|
|
v-for="(item, index) in items"
|
|
- class="el-carousel__indicator"
|
|
|
|
- :class="{ 'is-active': index === activeIndex }"
|
|
|
|
|
|
+ :key="index"
|
|
|
|
+ :class="[
|
|
|
|
+ 'el-carousel__indicator',
|
|
|
|
+ 'el-carousel__indicator--' + direction,
|
|
|
|
+ { 'is-active': index === activeIndex }]"
|
|
@mouseenter="throttledIndicatorHover(index)"
|
|
@mouseenter="throttledIndicatorHover(index)"
|
|
@click.stop="handleIndicatorClick(index)">
|
|
@click.stop="handleIndicatorClick(index)">
|
|
- <button class="el-carousel__button"><span v-if="hasLabel">{{ item.label }}</span></button>
|
|
|
|
|
|
+ <button class="el-carousel__button">
|
|
|
|
+ <span v-if="hasLabel">{{ item.label }}</span>
|
|
|
|
+ </button>
|
|
</li>
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
@@ -87,6 +92,13 @@ export default {
|
|
loop: {
|
|
loop: {
|
|
type: Boolean,
|
|
type: Boolean,
|
|
default: true
|
|
default: true
|
|
|
|
+ },
|
|
|
|
+ direction: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: 'horizontal',
|
|
|
|
+ validator(val) {
|
|
|
|
+ return ['horizontal', 'vertical'].indexOf(val) !== -1;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -101,8 +113,31 @@ export default {
|
|
},
|
|
},
|
|
|
|
|
|
computed: {
|
|
computed: {
|
|
|
|
+ arrowDisplay() {
|
|
|
|
+ return this.arrow !== 'never' && this.direction !== 'vertical';
|
|
|
|
+ },
|
|
|
|
+
|
|
hasLabel() {
|
|
hasLabel() {
|
|
return this.items.some(item => item.label.toString().length > 0);
|
|
return this.items.some(item => item.label.toString().length > 0);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ carouselClasses() {
|
|
|
|
+ const classes = ['el-carousel', 'el-carousel--' + this.direction];
|
|
|
|
+ if (this.type === 'card') {
|
|
|
|
+ classes.push('el-carousel--card');
|
|
|
|
+ }
|
|
|
|
+ return classes;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ indicatorsClasses() {
|
|
|
|
+ const classes = ['el-carousel__indicators', 'el-carousel__indicators--' + this.direction];
|
|
|
|
+ if (this.hasLabel) {
|
|
|
|
+ classes.push('el-carousel__indicators--labels');
|
|
|
|
+ }
|
|
|
|
+ if (this.indicatorPosition === 'outside' || this.type === 'card') {
|
|
|
|
+ classes.push('el-carousel__indicators--outside');
|
|
|
|
+ }
|
|
|
|
+ return classes;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -149,6 +184,7 @@ export default {
|
|
},
|
|
},
|
|
|
|
|
|
handleButtonEnter(arrow) {
|
|
handleButtonEnter(arrow) {
|
|
|
|
+ if (this.direction === 'vertical') return;
|
|
this.items.forEach((item, index) => {
|
|
this.items.forEach((item, index) => {
|
|
if (arrow === this.itemInStage(item, index)) {
|
|
if (arrow === this.itemInStage(item, index)) {
|
|
item.hover = true;
|
|
item.hover = true;
|
|
@@ -157,6 +193,7 @@ export default {
|
|
},
|
|
},
|
|
|
|
|
|
handleButtonLeave() {
|
|
handleButtonLeave() {
|
|
|
|
+ if (this.direction === 'vertical') return;
|
|
this.items.forEach(item => {
|
|
this.items.forEach(item => {
|
|
item.hover = false;
|
|
item.hover = false;
|
|
});
|
|
});
|
|
@@ -201,7 +238,6 @@ export default {
|
|
}
|
|
}
|
|
index = Number(index);
|
|
index = Number(index);
|
|
if (isNaN(index) || index !== Math.floor(index)) {
|
|
if (isNaN(index) || index !== Math.floor(index)) {
|
|
- process.env.NODE_ENV !== 'production' &&
|
|
|
|
console.warn('[Element Warn][Carousel]index must be an integer.');
|
|
console.warn('[Element Warn][Carousel]index must be an integer.');
|
|
return;
|
|
return;
|
|
}
|
|
}
|