UNPKG

winbox-ui-next

Version:

We Design Vue 2.0: A Vue.js 3 UI Library

66 lines (65 loc) 2.53 kB
import { defineComponent, getCurrentInstance, inject, onMounted, onUnmounted, computed, openBlock, createElementBlock, normalizeClass, normalizeStyle, renderSlot } from "vue"; import { getPrefixCls } from "../_utils/global-config.js"; import { carouselInjectionKey } from "./context.js"; import _export_sfc from "../_virtual/plugin-vue_export-helper"; const _sfc_main = defineComponent({ name: "CarouselItem", setup() { const prefixCls = getPrefixCls("carousel-item"); const instance = getCurrentInstance(); const instanceId = instance.uid; const context = inject(carouselInjectionKey); onMounted(() => { if (context == null ? void 0 : context.addItem) { context.addItem({ uid: instanceId }); } }); onUnmounted(() => { if (context == null ? void 0 : context.removeItem) { context.removeItem(instanceId); } }); const myIndexRef = computed(() => { const items = (context == null ? void 0 : context.items) || []; const index = items.findIndex((it) => it.uid === instanceId); return index; }); const cls = computed(() => { const { previousIndex, animationName, slideDirection, mergedIndexes } = context; const index = myIndexRef.value; const { mergedPrevIndex, mergedNextIndex, mergedIndex } = mergedIndexes; return { [`${prefixCls}-prev`]: index === mergedPrevIndex, [`${prefixCls}-next`]: index === mergedNextIndex, [`${prefixCls}-current`]: index === mergedIndex, [`${prefixCls}-slide-in`]: animationName === "slide" && slideDirection && index === mergedIndex, [`${prefixCls}-slide-out`]: animationName === "slide" && slideDirection && index === previousIndex }; }); const animationStyle = computed(() => { const { transitionTimingFunction, moveSpeed } = context; return { transitionTimingFunction, transitionDuration: `${moveSpeed}ms`, animationTimingFunction: transitionTimingFunction, animationDuration: `${moveSpeed}ms` }; }); return { cls, animationStyle }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return openBlock(), createElementBlock("div", { class: normalizeClass(_ctx.cls), style: normalizeStyle(_ctx.animationStyle) }, [ renderSlot(_ctx.$slots, "default") ], 6); } var CarouselItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { CarouselItem as default };