UNPKG

@ray-js/components

Version:

Ray basic components

67 lines 2.29 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 handleProps from '../utils/handleProps'; import { defaultSwiperProps } from './props'; import { useEventListener } from 'ahooks'; 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); const currentNode = React.useRef(null); React.useEffect(() => { if (bufferCurrent.current !== current) { setInternalCurrent(current); } }, [current]); function handleChange(event) { onChange === null || onChange === void 0 || onChange(_objectSpread(_objectSpread({}, event === null || event === void 0 ? void 0 : event.detail), event)); } function handleAfterChange(event) { onAfterChange === null || onAfterChange === void 0 || onAfterChange(_objectSpread(_objectSpread({}, event === null || event === void 0 ? void 0 : event.detail), event)); } useEventListener('change', e => { handleChange(e); }, { target: currentNode }); useEventListener('onanimationend', e => { handleAfterChange(e); }, { target: currentNode }); return ( /*#__PURE__*/ // @ts-ignore React.createElement("v-swiper", _extends({ ref: currentNode }, handleProps(restProps)), (() => { return children; })() || (() => { return dataSource.map((item, index) => { // @ts-ignore return /*#__PURE__*/React.createElement("v-swiper-item", { key: index }, renderItem(item, index)); }); })()) ); } Swiper.defaultProps = defaultSwiperProps; export default Swiper;