@fesjs/fes-design
Version:
fes-design for PC
43 lines (39 loc) • 1.8 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
import { ref, computed, provide } from 'vue';
import getPrefixCls from '../_util/getPrefixCls';
import { provideKey } from './const';
import useCarouselItem from './useCarouselItem';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
const prefixCls = getPrefixCls('carousel');
function useCarousel(props) {
const wrapperRef = ref(null); // 最外层容器句柄
const activeIndex = ref(-1); // 当前激活的索引
// 方向
const direction = computed(() => {
const {
indicatorPlacement: propIndicatorPlacement
} = props;
if (propIndicatorPlacement === 'top' || propIndicatorPlacement === 'bottom') {
return 'horizontal';
}
if (propIndicatorPlacement === 'left' || propIndicatorPlacement === 'right') {
return 'vertical';
}
return '';
});
const itemState = useCarouselItem({
props,
activeIndex
});
const state = _objectSpread({
prefixCls,
wrapperRef,
direction,
rootProps: props,
activeIndex
}, itemState);
provide(provideKey, state);
return state;
}
export { useCarousel as default };