carousel2.mjs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import { defineComponent, computed, unref, openBlock, createElementBlock, normalizeClass, withModifiers, createBlock, Transition, withCtx, withDirectives, createElementVNode, createVNode, vShow, createCommentVNode, normalizeStyle, renderSlot, Fragment, renderList, toDisplayString } from 'vue';
  2. import { ElIcon } from '../../icon/index.mjs';
  3. import { ArrowLeft, ArrowRight } from '@element-plus/icons-vue';
  4. import { carouselProps, carouselEmits } from './carousel.mjs';
  5. import { useCarousel } from './use-carousel.mjs';
  6. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  7. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  8. import { useLocale } from '../../../hooks/use-locale/index.mjs';
  9. const COMPONENT_NAME = "ElCarousel";
  10. const __default__ = defineComponent({
  11. name: COMPONENT_NAME
  12. });
  13. const _sfc_main = /* @__PURE__ */ defineComponent({
  14. ...__default__,
  15. props: carouselProps,
  16. emits: carouselEmits,
  17. setup(__props, { expose, emit }) {
  18. const props = __props;
  19. const {
  20. root,
  21. activeIndex,
  22. arrowDisplay,
  23. hasLabel,
  24. hover,
  25. isCardType,
  26. items,
  27. isVertical,
  28. containerStyle,
  29. handleButtonEnter,
  30. handleButtonLeave,
  31. isTransitioning,
  32. handleIndicatorClick,
  33. handleMouseEnter,
  34. handleMouseLeave,
  35. handleTransitionEnd,
  36. setActiveItem,
  37. prev,
  38. next,
  39. PlaceholderItem,
  40. isTwoLengthShow,
  41. throttledArrowClick,
  42. throttledIndicatorHover
  43. } = useCarousel(props, emit, COMPONENT_NAME);
  44. const ns = useNamespace("carousel");
  45. const { t } = useLocale();
  46. const carouselClasses = computed(() => {
  47. const classes = [ns.b(), ns.m(props.direction)];
  48. if (unref(isCardType)) {
  49. classes.push(ns.m("card"));
  50. }
  51. return classes;
  52. });
  53. const carouselContainer = computed(() => {
  54. const classes = [ns.e("container")];
  55. if (props.motionBlur && unref(isTransitioning) && items.value.length > 1) {
  56. classes.push(unref(isVertical) ? `${ns.namespace.value}-transitioning-vertical` : `${ns.namespace.value}-transitioning`);
  57. }
  58. return classes;
  59. });
  60. const indicatorsClasses = computed(() => {
  61. const classes = [ns.e("indicators"), ns.em("indicators", props.direction)];
  62. if (unref(hasLabel)) {
  63. classes.push(ns.em("indicators", "labels"));
  64. }
  65. if (props.indicatorPosition === "outside") {
  66. classes.push(ns.em("indicators", "outside"));
  67. }
  68. if (unref(isVertical)) {
  69. classes.push(ns.em("indicators", "right"));
  70. }
  71. return classes;
  72. });
  73. expose({
  74. activeIndex,
  75. setActiveItem,
  76. prev,
  77. next
  78. });
  79. return (_ctx, _cache) => {
  80. return openBlock(), createElementBlock("div", {
  81. ref_key: "root",
  82. ref: root,
  83. class: normalizeClass(unref(carouselClasses)),
  84. onMouseenter: withModifiers(unref(handleMouseEnter), ["stop"]),
  85. onMouseleave: withModifiers(unref(handleMouseLeave), ["stop"])
  86. }, [
  87. unref(arrowDisplay) ? (openBlock(), createBlock(Transition, {
  88. key: 0,
  89. name: "carousel-arrow-left",
  90. persisted: ""
  91. }, {
  92. default: withCtx(() => [
  93. withDirectives(createElementVNode("button", {
  94. type: "button",
  95. class: normalizeClass([unref(ns).e("arrow"), unref(ns).em("arrow", "left")]),
  96. "aria-label": unref(t)("el.carousel.leftArrow"),
  97. onMouseenter: ($event) => unref(handleButtonEnter)("left"),
  98. onMouseleave: unref(handleButtonLeave),
  99. onClick: withModifiers(($event) => unref(throttledArrowClick)(unref(activeIndex) - 1), ["stop"])
  100. }, [
  101. createVNode(unref(ElIcon), null, {
  102. default: withCtx(() => [
  103. createVNode(unref(ArrowLeft))
  104. ]),
  105. _: 1
  106. })
  107. ], 42, ["aria-label", "onMouseenter", "onMouseleave", "onClick"]), [
  108. [
  109. vShow,
  110. (_ctx.arrow === "always" || unref(hover)) && (props.loop || unref(activeIndex) > 0)
  111. ]
  112. ])
  113. ]),
  114. _: 1
  115. })) : createCommentVNode("v-if", true),
  116. unref(arrowDisplay) ? (openBlock(), createBlock(Transition, {
  117. key: 1,
  118. name: "carousel-arrow-right",
  119. persisted: ""
  120. }, {
  121. default: withCtx(() => [
  122. withDirectives(createElementVNode("button", {
  123. type: "button",
  124. class: normalizeClass([unref(ns).e("arrow"), unref(ns).em("arrow", "right")]),
  125. "aria-label": unref(t)("el.carousel.rightArrow"),
  126. onMouseenter: ($event) => unref(handleButtonEnter)("right"),
  127. onMouseleave: unref(handleButtonLeave),
  128. onClick: withModifiers(($event) => unref(throttledArrowClick)(unref(activeIndex) + 1), ["stop"])
  129. }, [
  130. createVNode(unref(ElIcon), null, {
  131. default: withCtx(() => [
  132. createVNode(unref(ArrowRight))
  133. ]),
  134. _: 1
  135. })
  136. ], 42, ["aria-label", "onMouseenter", "onMouseleave", "onClick"]), [
  137. [
  138. vShow,
  139. (_ctx.arrow === "always" || unref(hover)) && (props.loop || unref(activeIndex) < unref(items).length - 1)
  140. ]
  141. ])
  142. ]),
  143. _: 1
  144. })) : createCommentVNode("v-if", true),
  145. createElementVNode("div", {
  146. class: normalizeClass(unref(carouselContainer)),
  147. style: normalizeStyle(unref(containerStyle)),
  148. onTransitionend: unref(handleTransitionEnd)
  149. }, [
  150. createVNode(unref(PlaceholderItem)),
  151. renderSlot(_ctx.$slots, "default")
  152. ], 46, ["onTransitionend"]),
  153. _ctx.indicatorPosition !== "none" ? (openBlock(), createElementBlock("ul", {
  154. key: 2,
  155. class: normalizeClass(unref(indicatorsClasses))
  156. }, [
  157. (openBlock(true), createElementBlock(Fragment, null, renderList(unref(items), (item, index) => {
  158. return withDirectives((openBlock(), createElementBlock("li", {
  159. key: index,
  160. class: normalizeClass([
  161. unref(ns).e("indicator"),
  162. unref(ns).em("indicator", _ctx.direction),
  163. unref(ns).is("active", index === unref(activeIndex))
  164. ]),
  165. onMouseenter: ($event) => unref(throttledIndicatorHover)(index),
  166. onClick: withModifiers(($event) => unref(handleIndicatorClick)(index), ["stop"])
  167. }, [
  168. createElementVNode("button", {
  169. class: normalizeClass(unref(ns).e("button")),
  170. "aria-label": unref(t)("el.carousel.indicator", { index: index + 1 })
  171. }, [
  172. unref(hasLabel) ? (openBlock(), createElementBlock("span", { key: 0 }, toDisplayString(item.props.label), 1)) : createCommentVNode("v-if", true)
  173. ], 10, ["aria-label"])
  174. ], 42, ["onMouseenter", "onClick"])), [
  175. [vShow, unref(isTwoLengthShow)(index)]
  176. ]);
  177. }), 128))
  178. ], 2)) : createCommentVNode("v-if", true),
  179. props.motionBlur ? (openBlock(), createElementBlock("svg", {
  180. key: 3,
  181. xmlns: "http://www.w3.org/2000/svg",
  182. version: "1.1",
  183. style: { "display": "none" }
  184. }, [
  185. createElementVNode("defs", null, [
  186. createElementVNode("filter", { id: "elCarouselHorizontal" }, [
  187. createElementVNode("feGaussianBlur", {
  188. in: "SourceGraphic",
  189. stdDeviation: "12,0"
  190. })
  191. ]),
  192. createElementVNode("filter", { id: "elCarouselVertical" }, [
  193. createElementVNode("feGaussianBlur", {
  194. in: "SourceGraphic",
  195. stdDeviation: "0,10"
  196. })
  197. ])
  198. ])
  199. ])) : createCommentVNode("v-if", true)
  200. ], 42, ["onMouseenter", "onMouseleave"]);
  201. };
  202. }
  203. });
  204. var Carousel = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "carousel.vue"]]);
  205. export { Carousel as default };
  206. //# sourceMappingURL=carousel2.mjs.map