@nutui/nutui-react 1.5.2-beta.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/ActionSheet/style/index.js +2 -0
- package/dist/esm/ActionSheet.js +92 -0
- package/dist/esm/Address/style/index.js +4 -0
- package/dist/esm/Address.js +622 -0
- package/dist/esm/Animate/style/index.js +2 -0
- package/dist/esm/Animate.js +55 -0
- package/dist/esm/AnimatingNumbers/style/index.js +3 -0
- package/dist/esm/AnimatingNumbers.js +127 -0
- package/dist/esm/Audio/style/index.js +4 -0
- package/dist/esm/Audio.js +266 -0
- package/dist/esm/Avatar/style/index.js +2 -0
- package/dist/esm/Avatar.js +132 -0
- package/dist/esm/AvatarContext-15733596.js +3 -0
- package/dist/esm/AvatarGroup/style/index.js +2 -0
- package/dist/esm/AvatarGroup.js +43 -0
- package/dist/esm/BackTop/style/index.js +2 -0
- package/dist/esm/BackTop.js +139 -0
- package/dist/esm/Badge/style/index.js +2 -0
- package/dist/esm/Badge.js +73 -0
- package/dist/esm/Barrage/style/index.js +2 -0
- package/dist/esm/Barrage.js +99 -0
- package/dist/esm/Button/style/index.js +2 -0
- package/dist/esm/Button.js +109 -0
- package/dist/esm/Calendar/style/index.js +2 -0
- package/dist/esm/Calendar.js +129 -0
- package/dist/esm/CalendarItem/style/index.js +2 -0
- package/dist/esm/CalendarItem.js +676 -0
- package/dist/esm/Card/style/index.js +4 -0
- package/dist/esm/Card.js +63 -0
- package/dist/esm/Cascader/style/index.js +3 -0
- package/dist/esm/Cascader.js +673 -0
- package/dist/esm/Cell/style/index.js +2 -0
- package/dist/esm/Cell.js +103 -0
- package/dist/esm/CellGroup/style/index.js +2 -0
- package/dist/esm/CellGroup.js +5 -0
- package/dist/esm/Checkbox/style/index.js +3 -0
- package/dist/esm/Checkbox.js +8 -0
- package/dist/esm/CheckboxGroup/style/index.js +2 -0
- package/dist/esm/CheckboxGroup.js +113 -0
- package/dist/esm/CircleProgress/style/index.js +2 -0
- package/dist/esm/CircleProgress.js +116 -0
- package/dist/esm/Col/style/index.js +2 -0
- package/dist/esm/Col.js +58 -0
- package/dist/esm/Collapse/style/index.js +2 -0
- package/dist/esm/Collapse.js +99 -0
- package/dist/esm/CollapseItem/style/index.js +2 -0
- package/dist/esm/CollapseItem.js +148 -0
- package/dist/esm/ConfigProvider/style/index.js +2 -0
- package/dist/esm/ConfigProvider.js +187 -0
- package/dist/esm/CountDown/style/index.js +2 -0
- package/dist/esm/CountDown.js +249 -0
- package/dist/esm/DatePicker/style/index.js +2 -0
- package/dist/esm/DatePicker.js +310 -0
- package/dist/esm/Dialog/style/index.js +3 -0
- package/dist/esm/Dialog.js +296 -0
- package/dist/esm/Divider/style/index.js +2 -0
- package/dist/esm/Divider.js +36 -0
- package/dist/esm/Drag/style/index.js +2 -0
- package/dist/esm/Drag.js +120 -0
- package/dist/esm/Elevator/style/index.js +2 -0
- package/dist/esm/Elevator.js +236 -0
- package/dist/esm/Ellipsis/style/index.js +2 -0
- package/dist/esm/Ellipsis.js +177 -0
- package/dist/esm/Empty/style/index.js +2 -0
- package/dist/esm/Empty.js +82 -0
- package/dist/esm/FixedNav/style/index.js +3 -0
- package/dist/esm/FixedNav.js +105 -0
- package/dist/esm/Form/style/index.js +2 -0
- package/dist/esm/Form.js +219 -0
- package/dist/esm/FormItem/style/index.js +2 -0
- package/dist/esm/FormItem.js +5 -0
- package/dist/esm/Grid/style/index.js +2 -0
- package/dist/esm/Grid.js +83 -0
- package/dist/esm/GridItem/style/index.js +2 -0
- package/dist/esm/GridItem.js +125 -0
- package/dist/esm/Icon/style/index.js +4 -0
- package/dist/esm/Icon.js +5 -0
- package/dist/esm/Image/style/index.js +2 -0
- package/dist/esm/Image.js +170 -0
- package/dist/esm/ImagePreview/style/index.js +4 -0
- package/dist/esm/ImagePreview.js +226 -0
- package/dist/esm/Indicator/style/index.js +2 -0
- package/dist/esm/Indicator.js +52 -0
- package/dist/esm/Infiniteloading/style/index.js +2 -0
- package/dist/esm/Infiniteloading.js +217 -0
- package/dist/esm/Input/style/index.js +2 -0
- package/dist/esm/Input.js +363 -0
- package/dist/esm/InputNumber/style/index.js +2 -0
- package/dist/esm/InputNumber.js +277 -0
- package/dist/esm/Layout/style/index.js +2 -0
- package/dist/esm/Layout.js +14 -0
- package/dist/esm/Menu/style/index.js +3 -0
- package/dist/esm/Menu.js +154 -0
- package/dist/esm/MenuItem/style/index.js +3 -0
- package/dist/esm/MenuItem.js +177 -0
- package/dist/esm/NavBar/style/index.js +2 -0
- package/dist/esm/NavBar.js +116 -0
- package/dist/esm/NoticeBar/style/index.js +2 -0
- package/dist/esm/NoticeBar.js +570 -0
- package/dist/esm/Notify/style/index.js +2 -0
- package/dist/esm/Notify.js +236 -0
- package/dist/esm/NumberKeyboard/style/index.js +2 -0
- package/dist/esm/NumberKeyboard.js +249 -0
- package/dist/esm/Overlay/style/index.js +2 -0
- package/dist/esm/Overlay.js +6 -0
- package/dist/esm/Pagination/style/index.js +2 -0
- package/dist/esm/Pagination.js +170 -0
- package/dist/esm/Picker/style/index.js +2 -0
- package/dist/esm/Picker.js +496 -0
- package/dist/esm/Popover/style/index.js +3 -0
- package/dist/esm/Popover.js +225 -0
- package/dist/esm/Popup/style/index.js +3 -0
- package/dist/esm/Popup.js +195 -0
- package/dist/esm/Price/style/index.js +2 -0
- package/dist/esm/Price.js +86 -0
- package/dist/esm/Progress/style/index.js +2 -0
- package/dist/esm/Progress.js +124 -0
- package/dist/esm/PullToRefresh/style/index.js +2 -0
- package/dist/esm/PullToRefresh.js +277 -0
- package/dist/esm/Radio/style/index.js +3 -0
- package/dist/esm/Radio.js +6 -0
- package/dist/esm/RadioGroup/style/index.js +2 -0
- package/dist/esm/RadioGroup.js +123 -0
- package/dist/esm/Range/style/index.js +2 -0
- package/dist/esm/Range.js +407 -0
- package/dist/esm/Rate/style/index.js +2 -0
- package/dist/esm/Rate.js +123 -0
- package/dist/esm/Row/style/index.js +2 -0
- package/dist/esm/Row.js +50 -0
- package/dist/esm/SearchBar/style/index.js +2 -0
- package/dist/esm/SearchBar.js +237 -0
- package/dist/esm/ShortPassword/style/index.js +3 -0
- package/dist/esm/ShortPassword.js +193 -0
- package/dist/esm/SideNavBar/style/index.js +2 -0
- package/dist/esm/SideNavBar.js +58 -0
- package/dist/esm/SideNavBarItem/style/index.js +2 -0
- package/dist/esm/SideNavBarItem.js +25 -0
- package/dist/esm/Signature/style/index.js +2 -0
- package/dist/esm/Signature.js +155 -0
- package/dist/esm/Skeleton/style/index.js +2 -0
- package/dist/esm/Skeleton.js +100 -0
- package/dist/esm/Step/style/index.js +2 -0
- package/dist/esm/Step.js +89 -0
- package/dist/esm/Steps/style/index.js +2 -0
- package/dist/esm/Steps.js +40 -0
- package/dist/esm/Sticky/style/index.js +2 -0
- package/dist/esm/Sticky.js +192 -0
- package/dist/esm/SubSideNavBar/style/index.js +2 -0
- package/dist/esm/SubSideNavBar.js +79 -0
- package/dist/esm/Swipe/style/index.js +2 -0
- package/dist/esm/Swipe.js +232 -0
- package/dist/esm/Swiper/style/index.js +2 -0
- package/dist/esm/Swiper.js +492 -0
- package/dist/esm/SwiperItem/style/index.js +2 -0
- package/dist/esm/SwiperItem.js +38 -0
- package/dist/esm/Switch/style/index.js +2 -0
- package/dist/esm/Switch.js +73 -0
- package/dist/esm/TabPane/style/index.js +2 -0
- package/dist/esm/TabPane.js +6 -0
- package/dist/esm/Tabbar/style/index.js +2 -0
- package/dist/esm/Tabbar.js +70 -0
- package/dist/esm/TabbarItem/style/index.js +2 -0
- package/dist/esm/TabbarItem.js +80 -0
- package/dist/esm/Table/style/index.js +2 -0
- package/dist/esm/Table.js +142 -0
- package/dist/esm/Tabs/style/index.js +4 -0
- package/dist/esm/Tabs.js +9 -0
- package/dist/esm/Tag/style/index.js +2 -0
- package/dist/esm/Tag.js +111 -0
- package/dist/esm/TextArea/style/index.js +2 -0
- package/dist/esm/TextArea.js +150 -0
- package/dist/esm/TimeDetail/style/index.js +2 -0
- package/dist/esm/TimeDetail.js +69 -0
- package/dist/esm/TimePannel/style/index.js +2 -0
- package/dist/esm/TimePannel.js +31 -0
- package/dist/esm/TimeSelect/style/index.js +4 -0
- package/dist/esm/TimeSelect.js +173 -0
- package/dist/esm/Toast/style/index.js +2 -0
- package/dist/esm/Toast.js +271 -0
- package/dist/esm/TrendArrow/style/index.js +2 -0
- package/dist/esm/TrendArrow.js +101 -0
- package/dist/esm/Uploader/style/index.js +4 -0
- package/dist/esm/Uploader.js +568 -0
- package/dist/esm/UserContext-101ad4a4.js +3 -0
- package/dist/esm/UserContext-2629d479.js +3 -0
- package/dist/esm/UserContext-b33bcf21.js +3 -0
- package/dist/esm/Video/style/index.js +2 -0
- package/dist/esm/Video.js +92 -0
- package/dist/esm/VirtualList/style/index.js +2 -0
- package/dist/esm/VirtualList.js +315 -0
- package/dist/esm/WaterMark/style/index.js +2 -0
- package/dist/esm/WaterMark.js +113 -0
- package/dist/esm/bem-3b438e61.js +8 -0
- package/dist/esm/cellgroup-fcc72767.js +34 -0
- package/dist/esm/checkbox-44e13cd0.js +137 -0
- package/dist/esm/date-c7aad4c0.js +97 -0
- package/dist/esm/formitem-8a73a5fb.js +157 -0
- package/dist/esm/get-scroll-parent-5f85dee8.js +24 -0
- package/dist/esm/grid.context-2ee27d95.js +6 -0
- package/dist/esm/icon-4ef1581c.js +70 -0
- package/dist/esm/index-030b7245.js +11 -0
- package/dist/esm/nutui-react.es.js +94 -0
- package/dist/esm/offsetContext-3ab00d40.js +16 -0
- package/dist/esm/overlay-de6c79d5.js +83 -0
- package/dist/esm/radio-9f141e6b.js +118 -0
- package/dist/esm/render-bbebb760.js +79 -0
- package/dist/esm/tabpane-01075e6c.js +29 -0
- package/dist/esm/tabs-e1b4e4b1.js +181 -0
- package/dist/esm/typings-f27b58f4.js +8 -0
- package/dist/esm/useClientRect-56bb675b.js +39 -0
- package/dist/esm/useTouch-cf73a407.js +99 -0
- package/dist/locales/base.d.ts +129 -0
- package/dist/locales/base.js +5 -0
- package/dist/locales/en-US.d.ts +3 -0
- package/dist/locales/en-US.js +135 -0
- package/dist/locales/id-ID.d.ts +3 -0
- package/dist/locales/id-ID.js +135 -0
- package/dist/locales/zh-CN.d.ts +3 -0
- package/dist/locales/zh-CN.js +137 -0
- package/dist/locales/zh-TW.d.ts +3 -0
- package/dist/locales/zh-TW.js +135 -0
- package/dist/locales/zh-UG.d.ts +3 -0
- package/dist/locales/zh-UG.js +135 -0
- package/dist/nutui.react.mjs +1 -1
- package/dist/nutui.react.umd.js +1 -1
- package/dist/packages/actionsheet/actionsheet.scss +103 -0
- package/dist/packages/address/address.scss +243 -0
- package/dist/packages/animate/animate.scss +284 -0
- package/dist/packages/animatingnumbers/animatingnumbers.scss +0 -0
- package/dist/packages/animatingnumbers/countup.scss +45 -0
- package/dist/packages/audio/audio.scss +93 -0
- package/dist/packages/avatar/avatar.scss +58 -0
- package/dist/packages/avatargroup/avatargroup.scss +14 -0
- package/dist/packages/backtop/backtop.scss +29 -0
- package/dist/packages/badge/badge.scss +53 -0
- package/dist/packages/barrage/barrage.scss +60 -0
- package/dist/packages/button/button.scss +245 -0
- package/dist/packages/calendar/calendar.scss +265 -0
- package/dist/packages/calendaritem/calendaritem.scss +0 -0
- package/dist/packages/card/card.scss +83 -0
- package/dist/packages/cascader/cascader.scss +108 -0
- package/dist/packages/cell/cell.scss +107 -0
- package/dist/packages/cellgroup/cellgroup.scss +46 -0
- package/dist/packages/checkbox/checkbox.scss +49 -0
- package/dist/packages/checkboxgroup/checkboxgroup.scss +33 -0
- package/dist/packages/circleprogress/circleprogress.scss +33 -0
- package/dist/packages/col/col.scss +24 -0
- package/dist/packages/collapse/collapse.scss +0 -0
- package/dist/packages/collapseitem/collapseitem.scss +161 -0
- package/dist/packages/configprovider/configprovider.scss +0 -0
- package/dist/packages/countdown/countdown.scss +3 -0
- package/dist/packages/datepicker/datepicker.scss +0 -0
- package/dist/packages/dialog/dialog.scss +135 -0
- package/dist/packages/divider/divider.scss +73 -0
- package/dist/packages/drag/drag.scss +10 -0
- package/dist/packages/elevator/elevator.scss +124 -0
- package/dist/packages/ellipsis/ellipsis.scss +17 -0
- package/dist/packages/empty/empty.scss +42 -0
- package/dist/packages/fixednav/fixednav.scss +141 -0
- package/dist/packages/form/form.scss +31 -0
- package/dist/packages/formitem/formitem.scss +100 -0
- package/dist/packages/grid/grid.scss +10 -0
- package/dist/packages/griditem/griditem.scss +108 -0
- package/dist/packages/icon/icon.scss +132 -0
- package/dist/packages/image/image.scss +53 -0
- package/dist/packages/imagepreview/imagepreview.scss +51 -0
- package/dist/packages/indicator/indicator.scss +70 -0
- package/dist/packages/infiniteloading/infiniteloading.scss +69 -0
- package/dist/packages/input/input.scss +203 -0
- package/dist/packages/inputnumber/inputnumber.scss +79 -0
- package/dist/packages/layout/layout.scss +2 -0
- package/dist/packages/menu/menu.scss +75 -0
- package/dist/packages/menuitem/menuitem.scss +120 -0
- package/dist/packages/navbar/navbar.scss +185 -0
- package/dist/packages/noticebar/noticebar.scss +156 -0
- package/dist/packages/notify/notify.scss +93 -0
- package/dist/packages/numberkeyboard/numberkeyboard.scss +147 -0
- package/dist/packages/overlay/overlay.scss +75 -0
- package/dist/packages/pagination/pagination.scss +81 -0
- package/dist/packages/picker/picker.scss +225 -0
- package/dist/packages/popover/popover.scss +288 -0
- package/dist/packages/popup/popup.scss +201 -0
- package/dist/packages/price/price.scss +37 -0
- package/dist/packages/progress/progress.scss +114 -0
- package/dist/packages/pulltorefresh/pulltorefresh.scss +26 -0
- package/dist/packages/radio/radio.scss +84 -0
- package/dist/packages/radiogroup/radiogroup.scss +86 -0
- package/dist/packages/range/range.scss +224 -0
- package/dist/packages/rate/rate.scss +36 -0
- package/dist/packages/row/row.scss +83 -0
- package/dist/packages/searchbar/searchbar.scss +146 -0
- package/dist/packages/shortpassword/shortpassword.scss +203 -0
- package/dist/packages/sidenavbar/sidenavbar.scss +100 -0
- package/dist/packages/sidenavbaritem/sidenavbaritem.scss +25 -0
- package/dist/packages/signature/signature.scss +39 -0
- package/dist/packages/skeleton/skeleton.scss +70 -0
- package/dist/packages/step/step.scss +274 -0
- package/dist/packages/steps/steps.scss +7 -0
- package/dist/packages/sticky/sticky.scss +3 -0
- package/dist/packages/subsidenavbar/subsidenavbar.scss +35 -0
- package/dist/packages/swipe/swipe.scss +33 -0
- package/dist/packages/swiper/swiper.scss +45 -0
- package/dist/packages/swiperitem/swiperitem.scss +3 -0
- package/dist/packages/switch/switch.scss +87 -0
- package/dist/packages/tabbar/tabbar.scss +46 -0
- package/dist/packages/tabbaritem/tabbaritem.scss +97 -0
- package/dist/packages/table/table.scss +152 -0
- package/dist/packages/tabpane/tabpane.scss +23 -0
- package/dist/packages/tabs/tabs.scss +284 -0
- package/dist/packages/tag/tag.scss +67 -0
- package/dist/packages/textarea/textarea.scss +60 -0
- package/dist/packages/timedetail/timedetail.scss +45 -0
- package/dist/packages/timepannel/timepannel.scss +17 -0
- package/dist/packages/timeselect/timeselect.scss +73 -0
- package/dist/packages/toast/toast.scss +98 -0
- package/dist/packages/trendarrow/trendarrow.scss +17 -0
- package/dist/packages/uploader/uploader.scss +237 -0
- package/dist/packages/video/video.scss +18 -0
- package/dist/packages/virtuallist/virtuallist.scss +87 -0
- package/dist/packages/watermark/watermark.scss +13 -0
- package/dist/style.css +1 -0
- package/dist/style.mjs +9 -0
- package/dist/styles/animation/drop.scss +24 -0
- package/dist/styles/animation/ease.scss +23 -0
- package/dist/styles/animation/fade.scss +20 -0
- package/dist/styles/animation/icon.scss +245 -0
- package/dist/styles/animation/index.scss +7 -0
- package/dist/styles/animation/rotate.scss +10 -0
- package/dist/styles/animation/zoom.scss +26 -0
- package/dist/styles/font/config.json +175 -0
- package/dist/styles/font/demo.css +539 -0
- package/dist/styles/font/demo_index.html +3063 -0
- package/dist/styles/font/iconfont.css +515 -0
- package/dist/styles/font/iconfont.eot +0 -0
- package/dist/styles/font/iconfont.js +68 -0
- package/dist/styles/font/iconfont.json +884 -0
- package/dist/styles/font/iconfont.svg +356 -0
- package/dist/styles/font/iconfont.ttf +0 -0
- package/dist/styles/font/iconfont.woff +0 -0
- package/dist/styles/font/iconfont.woff2 +0 -0
- package/dist/styles/mixins/index.scss +2 -0
- package/dist/styles/mixins/make-animation.scss +24 -0
- package/dist/styles/mixins/text-ellipsis.scss +20 -0
- package/dist/styles/theme-dark.scss +26 -0
- package/dist/styles/theme-default.scss +40 -0
- package/dist/styles/themes/default.scss +97 -0
- package/dist/styles/variables.scss +2610 -0
- package/dist/types/index.d.ts +2201 -0
- package/package.json +1 -1
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
5
|
+
var _excluded = ["children", "direction", "className", "pageContent", "onChange", "initPage", "paginationColor", "paginationVisible", "touchable", "isPreventDefault", "isStopPropagation", "autoPlay", "isCenter", "paginationBgColor"];
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
+
import React__default, { useRef, useState, useMemo, useEffect } from 'react';
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import { D as DataContext } from './UserContext-2629d479.js';
|
|
11
|
+
import { c as cn } from './bem-3b438e61.js';
|
|
12
|
+
import { g as getRect } from './useClientRect-56bb675b.js';
|
|
13
|
+
import '@bem-react/classname';
|
|
14
|
+
var defaultProps = {
|
|
15
|
+
width: (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' ? window.innerWidth : 375,
|
|
16
|
+
height: 0,
|
|
17
|
+
duration: 500,
|
|
18
|
+
initPage: 0,
|
|
19
|
+
autoPlay: 0,
|
|
20
|
+
direction: 'horizontal',
|
|
21
|
+
paginationColor: '#fff',
|
|
22
|
+
paginationBgColor: '#ddd',
|
|
23
|
+
paginationVisible: false,
|
|
24
|
+
loop: true,
|
|
25
|
+
touchable: true,
|
|
26
|
+
isPreventDefault: true,
|
|
27
|
+
isStopPropagation: true,
|
|
28
|
+
isCenter: false,
|
|
29
|
+
className: ''
|
|
30
|
+
};
|
|
31
|
+
var DISTANCE = 5;
|
|
32
|
+
var Swiper = React__default.forwardRef(function (props, ref) {
|
|
33
|
+
var _classNames, _classNames2;
|
|
34
|
+
var propSwiper = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
35
|
+
var children = propSwiper.children,
|
|
36
|
+
direction = propSwiper.direction,
|
|
37
|
+
className = propSwiper.className,
|
|
38
|
+
pageContent = propSwiper.pageContent,
|
|
39
|
+
onChange = propSwiper.onChange,
|
|
40
|
+
initPage = propSwiper.initPage,
|
|
41
|
+
paginationColor = propSwiper.paginationColor,
|
|
42
|
+
paginationVisible = propSwiper.paginationVisible,
|
|
43
|
+
touchable = propSwiper.touchable,
|
|
44
|
+
isPreventDefault = propSwiper.isPreventDefault,
|
|
45
|
+
isStopPropagation = propSwiper.isStopPropagation,
|
|
46
|
+
autoPlay = propSwiper.autoPlay,
|
|
47
|
+
isCenter = propSwiper.isCenter,
|
|
48
|
+
paginationBgColor = propSwiper.paginationBgColor,
|
|
49
|
+
rest = _objectWithoutProperties(propSwiper, _excluded);
|
|
50
|
+
var container = useRef(null);
|
|
51
|
+
var innerRef = useRef(null);
|
|
52
|
+
var _swiper = useRef({
|
|
53
|
+
moving: false,
|
|
54
|
+
autoplayTimer: null,
|
|
55
|
+
width: 0,
|
|
56
|
+
height: 0,
|
|
57
|
+
offset: 0,
|
|
58
|
+
size: 0
|
|
59
|
+
});
|
|
60
|
+
var isVertical = direction === 'vertical';
|
|
61
|
+
var _useState = useState(null),
|
|
62
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
63
|
+
rect = _useState2[0],
|
|
64
|
+
setRect = _useState2[1];
|
|
65
|
+
// eslint-disable-next-line prefer-const
|
|
66
|
+
var _useState3 = useState(0),
|
|
67
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
68
|
+
active = _useState4[0],
|
|
69
|
+
setActive = _useState4[1];
|
|
70
|
+
var _useState5 = useState(0),
|
|
71
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
72
|
+
width = _useState6[0],
|
|
73
|
+
setWidth = _useState6[1];
|
|
74
|
+
var _useState7 = useState(0),
|
|
75
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
76
|
+
height = _useState8[0],
|
|
77
|
+
setHeight = _useState8[1];
|
|
78
|
+
var _useState9 = useState(0),
|
|
79
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
80
|
+
offset = _useState10[0],
|
|
81
|
+
setOffset = _useState10[1];
|
|
82
|
+
var _useState11 = useState([]),
|
|
83
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
84
|
+
childOffset = _useState12[0],
|
|
85
|
+
setChildOffset = _useState12[1];
|
|
86
|
+
var _useState13 = useState(false),
|
|
87
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
88
|
+
ready = _useState14[0],
|
|
89
|
+
setReady = _useState14[1];
|
|
90
|
+
var size = isVertical ? height : width;
|
|
91
|
+
var _useState15 = useState({
|
|
92
|
+
startX: 0,
|
|
93
|
+
startY: 0,
|
|
94
|
+
deltaX: 0,
|
|
95
|
+
deltaY: 0,
|
|
96
|
+
offsetX: 0,
|
|
97
|
+
offsetY: 0,
|
|
98
|
+
stateDirection: '',
|
|
99
|
+
delta: 0,
|
|
100
|
+
touchTime: 0
|
|
101
|
+
}),
|
|
102
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
103
|
+
touch = _useState16[0],
|
|
104
|
+
setTouch = _useState16[1];
|
|
105
|
+
var _useMemo = useMemo(function () {
|
|
106
|
+
var childCount = 0;
|
|
107
|
+
var childs = React__default.Children.map(props.children, function (child) {
|
|
108
|
+
if (!React__default.isValidElement(child)) return null;
|
|
109
|
+
childCount++;
|
|
110
|
+
return child;
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
childs: childs,
|
|
114
|
+
childCount: childCount
|
|
115
|
+
};
|
|
116
|
+
}, [props.children]),
|
|
117
|
+
childs = _useMemo.childs,
|
|
118
|
+
childCount = _useMemo.childCount;
|
|
119
|
+
var trackSize = childCount * Number(size);
|
|
120
|
+
// 父组件参数传入子组件item
|
|
121
|
+
var parent = {
|
|
122
|
+
propSwiper: propSwiper,
|
|
123
|
+
size: size
|
|
124
|
+
};
|
|
125
|
+
var minOffset = function () {
|
|
126
|
+
if (rect) {
|
|
127
|
+
var base = isVertical ? rect.height : rect.width;
|
|
128
|
+
return base - Number(size) * childCount;
|
|
129
|
+
}
|
|
130
|
+
return 0;
|
|
131
|
+
}();
|
|
132
|
+
// 清除定时器
|
|
133
|
+
var stopAutoPlay = function stopAutoPlay() {
|
|
134
|
+
clearTimeout(_swiper.current.autoplayTimer);
|
|
135
|
+
_swiper.current.autoplayTimer = null;
|
|
136
|
+
};
|
|
137
|
+
// 定时轮播
|
|
138
|
+
var autoplay = function autoplay() {
|
|
139
|
+
if (propSwiper.autoPlay <= 0 || childCount <= 1) return;
|
|
140
|
+
stopAutoPlay();
|
|
141
|
+
_swiper.current.autoplayTimer = setTimeout(function () {
|
|
142
|
+
next();
|
|
143
|
+
autoplay();
|
|
144
|
+
}, Number(propSwiper.autoPlay));
|
|
145
|
+
};
|
|
146
|
+
// 重置首尾位置信息
|
|
147
|
+
var resettPosition = function resettPosition() {
|
|
148
|
+
_swiper.current.moving = true;
|
|
149
|
+
if (active <= -1) {
|
|
150
|
+
move({
|
|
151
|
+
pace: childCount
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (active >= childCount) {
|
|
155
|
+
move({
|
|
156
|
+
pace: -childCount
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
// 上一页
|
|
161
|
+
var prev = function prev() {
|
|
162
|
+
resettPosition();
|
|
163
|
+
touchReset();
|
|
164
|
+
requestFrame(function () {
|
|
165
|
+
requestFrame(function () {
|
|
166
|
+
_swiper.current.moving = false;
|
|
167
|
+
move({
|
|
168
|
+
pace: -1,
|
|
169
|
+
isEmit: true
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
// 下一页
|
|
175
|
+
var next = function next() {
|
|
176
|
+
resettPosition();
|
|
177
|
+
touchReset();
|
|
178
|
+
requestFrame(function () {
|
|
179
|
+
requestFrame(function () {
|
|
180
|
+
_swiper.current.moving = false;
|
|
181
|
+
move({
|
|
182
|
+
pace: 1,
|
|
183
|
+
isEmit: true
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
// 前往指定页
|
|
189
|
+
var to = function to(index) {
|
|
190
|
+
resettPosition();
|
|
191
|
+
touchReset();
|
|
192
|
+
requestFrame(function () {
|
|
193
|
+
requestFrame(function () {
|
|
194
|
+
_swiper.current.moving = false;
|
|
195
|
+
var targetIndex;
|
|
196
|
+
if (props.loop && childCount === index) {
|
|
197
|
+
targetIndex = active === 0 ? 0 : index;
|
|
198
|
+
} else {
|
|
199
|
+
targetIndex = index % childCount;
|
|
200
|
+
}
|
|
201
|
+
move({
|
|
202
|
+
pace: targetIndex - active,
|
|
203
|
+
isEmit: true
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
var resize = function resize() {
|
|
209
|
+
init(active);
|
|
210
|
+
};
|
|
211
|
+
// 切换方法
|
|
212
|
+
var move = function move(_ref) {
|
|
213
|
+
var _ref$pace = _ref.pace,
|
|
214
|
+
pace = _ref$pace === void 0 ? 0 : _ref$pace,
|
|
215
|
+
_ref$offset = _ref.offset,
|
|
216
|
+
offset = _ref$offset === void 0 ? 0 : _ref$offset,
|
|
217
|
+
_ref$isEmit = _ref.isEmit,
|
|
218
|
+
isEmit = _ref$isEmit === void 0 ? false : _ref$isEmit,
|
|
219
|
+
_ref$movingStatus = _ref.movingStatus,
|
|
220
|
+
movingStatus = _ref$movingStatus === void 0 ? false : _ref$movingStatus;
|
|
221
|
+
if (childCount <= 1) return;
|
|
222
|
+
var targetActive = getActive(pace);
|
|
223
|
+
// 父级容器偏移量
|
|
224
|
+
var targetOffset = getOffset(targetActive, offset);
|
|
225
|
+
// 如果循环,调整开头结尾图片位置
|
|
226
|
+
if (props.loop) {
|
|
227
|
+
if (Array.isArray(children) && children[0] && targetOffset !== minOffset) {
|
|
228
|
+
var rightBound = targetOffset < minOffset;
|
|
229
|
+
childOffset[0] = rightBound ? trackSize : 0;
|
|
230
|
+
}
|
|
231
|
+
if (Array.isArray(children) && children[childCount - 1] && targetOffset !== 0) {
|
|
232
|
+
var leftBound = targetOffset > 0;
|
|
233
|
+
childOffset[childCount - 1] = leftBound ? -trackSize : 0;
|
|
234
|
+
}
|
|
235
|
+
setChildOffset(childOffset);
|
|
236
|
+
}
|
|
237
|
+
if (isEmit && active !== targetActive) {
|
|
238
|
+
props.onChange && props.onChange((targetActive + childCount) % childCount);
|
|
239
|
+
}
|
|
240
|
+
active = targetActive;
|
|
241
|
+
setActive(targetActive);
|
|
242
|
+
setOffset(targetOffset);
|
|
243
|
+
getStyle(targetOffset);
|
|
244
|
+
};
|
|
245
|
+
// 确定当前active 元素
|
|
246
|
+
var getActive = function getActive(pace) {
|
|
247
|
+
if (pace) {
|
|
248
|
+
var _active = active + pace;
|
|
249
|
+
if (props.loop) {
|
|
250
|
+
return range(_active, -1, childCount);
|
|
251
|
+
}
|
|
252
|
+
return range(_active, 0, childCount - 1);
|
|
253
|
+
}
|
|
254
|
+
return active;
|
|
255
|
+
};
|
|
256
|
+
// 计算位移
|
|
257
|
+
var getOffset = function getOffset(active) {
|
|
258
|
+
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
259
|
+
var currentPosition = active * Number(size);
|
|
260
|
+
if (!props.loop) {
|
|
261
|
+
currentPosition = Math.min(currentPosition, -minOffset);
|
|
262
|
+
}
|
|
263
|
+
var targetOffset = offset - currentPosition;
|
|
264
|
+
if (!props.loop) {
|
|
265
|
+
targetOffset = range(targetOffset, minOffset, 0);
|
|
266
|
+
}
|
|
267
|
+
return targetOffset;
|
|
268
|
+
};
|
|
269
|
+
// 浏览器 帧 事件
|
|
270
|
+
var requestFrame = function requestFrame(fn) {
|
|
271
|
+
window.requestAnimationFrame.call(window, fn);
|
|
272
|
+
};
|
|
273
|
+
// 取值 方法
|
|
274
|
+
var range = function range(num, min, max) {
|
|
275
|
+
return Math.min(Math.max(num, min), max);
|
|
276
|
+
};
|
|
277
|
+
var getDirection = function getDirection(x, y) {
|
|
278
|
+
if (x > y && x > DISTANCE) return 'horizontal';
|
|
279
|
+
if (y > x && y > DISTANCE) return 'vertical';
|
|
280
|
+
return '';
|
|
281
|
+
};
|
|
282
|
+
// 重置 全部位移信息
|
|
283
|
+
var touchReset = function touchReset() {
|
|
284
|
+
touch.startX = 0;
|
|
285
|
+
touch.startY = 0;
|
|
286
|
+
touch.deltaX = 0;
|
|
287
|
+
touch.deltaY = 0;
|
|
288
|
+
touch.offsetX = 0;
|
|
289
|
+
touch.offsetY = 0;
|
|
290
|
+
touch.delta = 0;
|
|
291
|
+
touch.stateDirection = '';
|
|
292
|
+
touch.touchTime = 0;
|
|
293
|
+
};
|
|
294
|
+
// 触摸事件开始
|
|
295
|
+
var touchStart = function touchStart(e) {
|
|
296
|
+
touchReset();
|
|
297
|
+
touch.startX = e.touches[0].clientX;
|
|
298
|
+
touch.startY = e.touches[0].clientY;
|
|
299
|
+
};
|
|
300
|
+
// 触摸事件移动
|
|
301
|
+
var touchMove = function touchMove(e) {
|
|
302
|
+
touch.deltaX = e.touches[0].clientX - touch.startX;
|
|
303
|
+
touch.deltaY = e.touches[0].clientY - touch.startY;
|
|
304
|
+
touch.offsetX = Math.abs(touch.deltaX);
|
|
305
|
+
touch.offsetY = Math.abs(touch.deltaY);
|
|
306
|
+
touch.delta = isVertical ? touch.deltaY : touch.deltaX;
|
|
307
|
+
if (!touch.stateDirection) {
|
|
308
|
+
touch.stateDirection = getDirection(touch.offsetX, touch.offsetY);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
var b = cn('swiper');
|
|
312
|
+
var classes = classNames(b(''));
|
|
313
|
+
var contentClass = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(b('inner')), true), _defineProperty(_classNames, "".concat(b('vertical')), isVertical), _classNames));
|
|
314
|
+
var getStyle = function getStyle() {
|
|
315
|
+
var moveOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : offset;
|
|
316
|
+
var target = innerRef.current;
|
|
317
|
+
var _offset = 0;
|
|
318
|
+
if (!isCenter) {
|
|
319
|
+
_offset = moveOffset;
|
|
320
|
+
} else {
|
|
321
|
+
var _size = isVertical ? height : width;
|
|
322
|
+
var val = isVertical ? rect.height - _size : rect.width - _size;
|
|
323
|
+
_offset = moveOffset + (active === childCount - 1 && !props.loop ? -val / 2 : val / 2);
|
|
324
|
+
}
|
|
325
|
+
target.style.transitionDuration = "".concat(_swiper.current.moving ? 0 : props.duration, "ms");
|
|
326
|
+
target.style[isVertical ? 'height' : 'width'] = "".concat(Number(size) * childCount, "px");
|
|
327
|
+
target.style[isVertical ? 'width' : 'height'] = "".concat(isVertical ? width : height, "px");
|
|
328
|
+
target.style.transform = "translate3D".concat(!isVertical ? "(".concat(_offset, "px,0,0)") : "(0,".concat(_offset, "px,0)"));
|
|
329
|
+
};
|
|
330
|
+
var onTouchStart = function onTouchStart(e) {
|
|
331
|
+
if (props.isPreventDefault) e.preventDefault();
|
|
332
|
+
if (props.isStopPropagation) e.stopPropagation();
|
|
333
|
+
if (!props.touchable) return;
|
|
334
|
+
touchStart(e);
|
|
335
|
+
touch.touchTime = Date.now();
|
|
336
|
+
stopAutoPlay();
|
|
337
|
+
resettPosition();
|
|
338
|
+
};
|
|
339
|
+
var onTouchMove = function onTouchMove(e) {
|
|
340
|
+
if (props.touchable && _swiper.current.moving) {
|
|
341
|
+
touchMove(e);
|
|
342
|
+
if (touch.stateDirection === props.direction) {
|
|
343
|
+
move({
|
|
344
|
+
offset: touch.delta
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
var onTouchEnd = function onTouchEnd(e) {
|
|
350
|
+
if (!props.touchable || !_swiper.current.moving) return;
|
|
351
|
+
var speed = touch.delta / (Date.now() - touch.touchTime);
|
|
352
|
+
var isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta) > +(size / 2).toFixed(2);
|
|
353
|
+
var pace = 0;
|
|
354
|
+
_swiper.current.moving = false;
|
|
355
|
+
if (isShouldMove && touch.stateDirection === props.direction) {
|
|
356
|
+
var _offset2 = isVertical ? touch.offsetY : touch.offsetX;
|
|
357
|
+
if (props.loop) {
|
|
358
|
+
if (_offset2 > 0) {
|
|
359
|
+
pace = touch.delta > 0 ? -1 : 1;
|
|
360
|
+
} else {
|
|
361
|
+
pace = 0;
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
pace = -Math[touch.delta > 0 ? 'ceil' : 'floor'](touch.delta / size);
|
|
365
|
+
}
|
|
366
|
+
move({
|
|
367
|
+
pace: pace,
|
|
368
|
+
isEmit: true
|
|
369
|
+
});
|
|
370
|
+
} else if (touch.delta) {
|
|
371
|
+
move({
|
|
372
|
+
pace: 0
|
|
373
|
+
});
|
|
374
|
+
} else {
|
|
375
|
+
getStyle();
|
|
376
|
+
}
|
|
377
|
+
autoplay();
|
|
378
|
+
};
|
|
379
|
+
useEffect(function () {
|
|
380
|
+
_swiper.current.activePagination = (active + childCount) % childCount;
|
|
381
|
+
}, [active]);
|
|
382
|
+
var init = function init() {
|
|
383
|
+
var active = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : +propSwiper.initPage;
|
|
384
|
+
var rect = getRect(container === null || container === void 0 ? void 0 : container.current);
|
|
385
|
+
var _active = Math.max(Math.min(childCount - 1, active), 0);
|
|
386
|
+
var _width = propSwiper.width ? +propSwiper.width : rect.width;
|
|
387
|
+
var _height = propSwiper.height ? +propSwiper.height : rect.height;
|
|
388
|
+
size = isVertical ? _height : _width;
|
|
389
|
+
trackSize = childCount * Number(size);
|
|
390
|
+
var targetOffset = getOffset(_active);
|
|
391
|
+
_swiper.current.moving = true;
|
|
392
|
+
if (ready) {
|
|
393
|
+
_swiper.current.moving = false;
|
|
394
|
+
}
|
|
395
|
+
setRect(rect);
|
|
396
|
+
setActive(_active);
|
|
397
|
+
setWidth(_width);
|
|
398
|
+
setHeight(_height);
|
|
399
|
+
setOffset(targetOffset);
|
|
400
|
+
setReady(true);
|
|
401
|
+
};
|
|
402
|
+
useEffect(function () {
|
|
403
|
+
if (ready) {
|
|
404
|
+
getStyle();
|
|
405
|
+
}
|
|
406
|
+
}, [isVertical, width, height, offset, ready]);
|
|
407
|
+
useEffect(function () {
|
|
408
|
+
if (ready) {
|
|
409
|
+
stopAutoPlay();
|
|
410
|
+
autoplay();
|
|
411
|
+
}
|
|
412
|
+
return function () {
|
|
413
|
+
setReady(false);
|
|
414
|
+
};
|
|
415
|
+
}, [ready]);
|
|
416
|
+
useEffect(function () {
|
|
417
|
+
stopAutoPlay();
|
|
418
|
+
autoplay();
|
|
419
|
+
}, [children]);
|
|
420
|
+
useEffect(function () {
|
|
421
|
+
init();
|
|
422
|
+
}, [propSwiper.initPage]);
|
|
423
|
+
useEffect(function () {
|
|
424
|
+
var target = container.current;
|
|
425
|
+
target.addEventListener('touchstart', onTouchStart, false);
|
|
426
|
+
target.addEventListener('touchmove', onTouchMove, false);
|
|
427
|
+
target.addEventListener('touchend', onTouchEnd, false);
|
|
428
|
+
return function () {
|
|
429
|
+
target.removeEventListener('touchstart', onTouchStart, false);
|
|
430
|
+
target.removeEventListener('touchmove', onTouchMove, false);
|
|
431
|
+
target.removeEventListener('touchend', onTouchEnd, false);
|
|
432
|
+
};
|
|
433
|
+
});
|
|
434
|
+
useEffect(function () {
|
|
435
|
+
return function () {
|
|
436
|
+
stopAutoPlay();
|
|
437
|
+
};
|
|
438
|
+
}, []);
|
|
439
|
+
var itemStyle = function itemStyle(index) {
|
|
440
|
+
var style = {};
|
|
441
|
+
var _direction = propSwiper.direction || direction;
|
|
442
|
+
var _size = size;
|
|
443
|
+
if (_size) {
|
|
444
|
+
style[_direction === 'horizontal' ? 'width' : 'height'] = "".concat(_size, "px");
|
|
445
|
+
}
|
|
446
|
+
var offset = childOffset[index];
|
|
447
|
+
if (offset) {
|
|
448
|
+
style.transform = "translate3D".concat(_direction === 'horizontal' ? "(".concat(offset, "px,0,0)") : "(0,".concat(offset, "px,0)"));
|
|
449
|
+
}
|
|
450
|
+
return style;
|
|
451
|
+
};
|
|
452
|
+
React__default.useImperativeHandle(ref, function () {
|
|
453
|
+
return {
|
|
454
|
+
to: to,
|
|
455
|
+
next: next,
|
|
456
|
+
prev: prev,
|
|
457
|
+
resize: resize
|
|
458
|
+
};
|
|
459
|
+
});
|
|
460
|
+
return React__default.createElement(DataContext.Provider, {
|
|
461
|
+
value: parent
|
|
462
|
+
}, React__default.createElement("div", _objectSpread({
|
|
463
|
+
className: "".concat(classes, " ").concat(className),
|
|
464
|
+
ref: container
|
|
465
|
+
}, rest), React__default.createElement("div", {
|
|
466
|
+
className: contentClass,
|
|
467
|
+
ref: innerRef
|
|
468
|
+
}, React__default.Children.map(childs, function (child, index) {
|
|
469
|
+
return React__default.createElement("div", {
|
|
470
|
+
className: b('item-wrapper'),
|
|
471
|
+
style: itemStyle(index),
|
|
472
|
+
key: index
|
|
473
|
+
}, child);
|
|
474
|
+
})), propSwiper.paginationVisible && !('pageContent' in propSwiper) ? React__default.createElement("div", {
|
|
475
|
+
className: classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(b('pagination')), true), _defineProperty(_classNames2, "".concat(b('pagination-vertical')), isVertical), _classNames2))
|
|
476
|
+
}, React__default.Children.map(childs, function (item, index) {
|
|
477
|
+
return React__default.createElement("i", {
|
|
478
|
+
style: (active + childCount) % childCount === index ? {
|
|
479
|
+
backgroundColor: propSwiper.paginationColor
|
|
480
|
+
} : {
|
|
481
|
+
backgroundColor: propSwiper.paginationBgColor
|
|
482
|
+
},
|
|
483
|
+
className: classNames({
|
|
484
|
+
active: (active + childCount) % childCount === index
|
|
485
|
+
}),
|
|
486
|
+
key: index
|
|
487
|
+
});
|
|
488
|
+
})) : React__default.createElement("div", null, pageContent)));
|
|
489
|
+
});
|
|
490
|
+
Swiper.defaultProps = defaultProps;
|
|
491
|
+
Swiper.displayName = 'NutSwiper';
|
|
492
|
+
export { Swiper as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
import React__default, { useContext } from 'react';
|
|
5
|
+
import classNames from 'classnames';
|
|
6
|
+
import { D as DataContext } from './UserContext-2629d479.js';
|
|
7
|
+
import { c as cn } from './bem-3b438e61.js';
|
|
8
|
+
import '@bem-react/classname';
|
|
9
|
+
var defaultProps = {
|
|
10
|
+
direction: 'horizontal'
|
|
11
|
+
};
|
|
12
|
+
var SwiperItem = React__default.forwardRef(function (props, ref) {
|
|
13
|
+
var _props = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
14
|
+
var className = _props.className,
|
|
15
|
+
style = _props.style,
|
|
16
|
+
children = _props.children,
|
|
17
|
+
direction = _props.direction,
|
|
18
|
+
size = _props.size;
|
|
19
|
+
var parent = useContext(DataContext);
|
|
20
|
+
var b = cn('swiper-item');
|
|
21
|
+
var classes = classNames(b(''), className);
|
|
22
|
+
var getStyle = function getStyle() {
|
|
23
|
+
var style = {};
|
|
24
|
+
var _direction = (parent === null || parent === void 0 ? void 0 : parent.propSwiper.direction) || direction;
|
|
25
|
+
var _size = (parent === null || parent === void 0 ? void 0 : parent.size) || size;
|
|
26
|
+
if (_size) {
|
|
27
|
+
style[_direction === 'horizontal' ? 'width' : 'height'] = "".concat(_size, "px");
|
|
28
|
+
}
|
|
29
|
+
return style;
|
|
30
|
+
};
|
|
31
|
+
return React__default.createElement("div", {
|
|
32
|
+
className: classes,
|
|
33
|
+
style: _objectSpread(_objectSpread({}, style), getStyle())
|
|
34
|
+
}, children);
|
|
35
|
+
});
|
|
36
|
+
SwiperItem.defaultProps = defaultProps;
|
|
37
|
+
SwiperItem.displayName = 'NutSwiperItem';
|
|
38
|
+
export { SwiperItem as default };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
+
import React__default, { useState, useEffect } from 'react';
|
|
6
|
+
import { c as cn } from './bem-3b438e61.js';
|
|
7
|
+
import { C as ComponentDefaults } from './typings-f27b58f4.js';
|
|
8
|
+
import '@bem-react/classname';
|
|
9
|
+
var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
|
|
10
|
+
isAsync: false,
|
|
11
|
+
checked: false,
|
|
12
|
+
disable: false,
|
|
13
|
+
activeColor: '',
|
|
14
|
+
inactiveColor: '',
|
|
15
|
+
activeText: '',
|
|
16
|
+
inactiveText: '',
|
|
17
|
+
className: ''
|
|
18
|
+
});
|
|
19
|
+
var Switch = function Switch(props) {
|
|
20
|
+
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
|
|
21
|
+
isAsync = _defaultProps$props.isAsync,
|
|
22
|
+
checked = _defaultProps$props.checked,
|
|
23
|
+
disable = _defaultProps$props.disable,
|
|
24
|
+
activeColor = _defaultProps$props.activeColor,
|
|
25
|
+
inactiveColor = _defaultProps$props.inactiveColor,
|
|
26
|
+
activeText = _defaultProps$props.activeText,
|
|
27
|
+
inactiveText = _defaultProps$props.inactiveText,
|
|
28
|
+
onChange = _defaultProps$props.onChange,
|
|
29
|
+
className = _defaultProps$props.className,
|
|
30
|
+
style = _defaultProps$props.style;
|
|
31
|
+
var _useState = useState(false),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
value = _useState2[0],
|
|
34
|
+
setValue = _useState2[1];
|
|
35
|
+
var b = cn('switch');
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
setValue(checked);
|
|
38
|
+
}, [checked]);
|
|
39
|
+
var classes = function classes() {
|
|
40
|
+
return "".concat(b(), " ").concat(value ? 'switch-open' : 'switch-close', " ").concat(disable ? "".concat(b(), "-disable") : '', " ", "".concat(b(), "-base"), " ").concat(className);
|
|
41
|
+
};
|
|
42
|
+
var styles = function styles() {
|
|
43
|
+
var myStyle = _objectSpread({
|
|
44
|
+
backgroundColor: value ? activeColor : inactiveColor
|
|
45
|
+
}, style || {});
|
|
46
|
+
return myStyle;
|
|
47
|
+
};
|
|
48
|
+
var _onClick = function onClick(event) {
|
|
49
|
+
if (disable) return;
|
|
50
|
+
if (!isAsync) {
|
|
51
|
+
setValue(!value);
|
|
52
|
+
}
|
|
53
|
+
onChange && onChange(!value, event);
|
|
54
|
+
};
|
|
55
|
+
return React__default.createElement("div", {
|
|
56
|
+
className: classes(),
|
|
57
|
+
onClick: function onClick(e) {
|
|
58
|
+
return _onClick(e);
|
|
59
|
+
},
|
|
60
|
+
style: styles()
|
|
61
|
+
}, React__default.createElement("div", {
|
|
62
|
+
className: "switch-button"
|
|
63
|
+
}, !value && React__default.createElement("div", {
|
|
64
|
+
className: "close-line"
|
|
65
|
+
}), activeText && React__default.createElement(React__default.Fragment, null, value ? React__default.createElement("div", {
|
|
66
|
+
className: "".concat(b('label'), " open")
|
|
67
|
+
}, activeText) : React__default.createElement("div", {
|
|
68
|
+
className: "".concat(b('label'), " close")
|
|
69
|
+
}, inactiveText))));
|
|
70
|
+
};
|
|
71
|
+
Switch.defaultProps = defaultProps;
|
|
72
|
+
Switch.displayName = 'NutSwitch';
|
|
73
|
+
export { Switch as default };
|