UNPKG

@ray-js/components

Version:

Ray basic components

68 lines 2.65 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; const _excluded = ["id", "style", "className", "current", "dataSource", "onAfterChange", "onChange", "renderItem", "children"]; import "core-js/modules/esnext.iterator.constructor.js"; import "core-js/modules/esnext.iterator.map.js"; import clsx from 'clsx'; import * as React from 'react'; import { inlineStyle } from '@ray-js/framework-shared'; import { Swiper as RemaxSwiper, SwiperItem as RemaxSwiperItem } from '@ray-core/wechat'; import { propsAlias } from '../core'; import { SwiperPropsAlias, defaultSwiperProps } from './props'; function Swiper(props) { const { id, style, className, current, dataSource, onAfterChange, onChange, renderItem, children } = props, restProps = _objectWithoutProperties(props, _excluded); const [internalCurrent, setInternalCurrent] = React.useState(current); const bufferCurrent = React.useRef(current); React.useEffect(() => { if (bufferCurrent.current !== current) { setInternalCurrent(current); bufferCurrent.current = current; } }, [current]); return /*#__PURE__*/React.createElement(RemaxSwiper, _extends({ id: id, style: inlineStyle(style), className: clsx('ray-swiper', className), onChange: function (event) { onChange === null || onChange === void 0 || onChange(_objectSpread(_objectSpread({}, event), {}, { // FIXME: 为什么保留原始数据?这里是为了兼容原有业务已经使用该数据的情况 type: 'change', current: event.detail.current, source: event.detail.source, origin: event })); }, onAnimationFinish: function (event) { onAfterChange === null || onAfterChange === void 0 || onAfterChange(_objectSpread(_objectSpread({}, event), {}, { // FIXME: 为什么保留原始数据?这里是为了兼容原有业务已经使用该数据的情况 type: 'afterChange', current: event.detail.current, source: event.detail.source, origin: event })); }, current: internalCurrent }, propsAlias(restProps, SwiperPropsAlias)), function () { return children; }() || function () { return dataSource.map((item, index) => { return /*#__PURE__*/React.createElement(RemaxSwiperItem, { key: index }, renderItem(item, index)); }); }()); } Swiper.defaultProps = defaultSwiperProps; export default Swiper;