UNPKG

@nutui/nutui-react

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

30 lines (29 loc) 1.41 kB
import { _ as _define_property } from "@swc/helpers/_/_define_property"; import React from "react"; import { animated } from "@react-spring/web"; import { useRtl } from "../../configprovider"; var getPerSlidePosition = function(index, position, loop, count) { var currentPosition = index * 100 + position; if (loop) { var cycle = count * 100; var shift = cycle / 2; var nextPosition = (currentPosition + shift) % cycle; var shiftedPosition = (nextPosition < 0 ? nextPosition + cycle : nextPosition) - shift; return "".concat(shiftedPosition, "%"); } return "".concat(currentPosition, "%"); }; export var defaultEffect = function(args) { return React.Children.map(args.children, function(child, index) { var isVertical = args.isVertical, getSpringsAxis = args.getSpringsAxis, loop = args.loop, count = args.count; var rtl = useRtl(); var position = rtl ? 'right' : 'left'; var _obj; return /*#__PURE__*/ React.createElement(animated.div, { className: "nut-swiper-slide", style: (_obj = {}, _define_property(_obj, isVertical ? 'y' : 'x', getSpringsAxis().to(function(position) { return getPerSlidePosition(index, position, loop, count); })), _define_property(_obj, isVertical ? 'top' : position, "-".concat(index * 100, "%")), _obj) }, child); }); };