@nutui/nutui-react-taro 2.0.0-alpha.5 → 2.0.0-alpha.6
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/CHANGELOG.md +14 -0
- package/dist/esm/ActionSheet.js +15 -16
- package/dist/esm/Address.js +19 -20
- package/dist/esm/Animate.js +7 -8
- package/dist/esm/AnimatingNumbers.js +8 -9
- package/dist/esm/Audio.js +17 -19
- package/dist/esm/Avatar.js +11 -13
- package/dist/esm/AvatarGroup.js +8 -9
- package/dist/esm/BackTop.js +9 -10
- package/dist/esm/Badge.js +7 -8
- package/dist/esm/Barrage.js +9 -10
- package/dist/esm/Button.js +8 -9
- package/dist/esm/Calendar.js +18 -20
- package/dist/esm/CalendarItem.js +11 -13
- package/dist/esm/Card.js +12 -13
- package/dist/esm/Cascader.js +16 -19
- package/dist/esm/Cell.js +7 -8
- package/dist/esm/CellGroup.js +7 -8
- package/dist/esm/Checkbox.js +9 -10
- package/dist/esm/CheckboxGroup.js +9 -10
- package/dist/esm/CircleProgress.js +8 -9
- package/dist/esm/Col.js +8 -9
- package/dist/esm/Collapse.js +8 -9
- package/dist/esm/CollapseItem.js +7 -8
- package/dist/esm/ConfigProvider.js +9 -8
- package/dist/esm/CountDown.js +8 -10
- package/dist/esm/DatePicker.js +21 -23
- package/dist/esm/Dialog.js +13 -15
- package/dist/esm/Divider.js +7 -8
- package/dist/esm/Drag.js +7 -8
- package/dist/esm/Elevator.js +9 -10
- package/dist/esm/Ellipsis.js +9 -10
- package/dist/esm/Empty.js +7 -9
- package/dist/esm/FixedNav.js +11 -13
- package/dist/esm/Form.js +10 -11
- package/dist/esm/FormItem.js +8 -9
- package/dist/esm/Grid.js +8 -10
- package/dist/esm/GridItem.js +7 -9
- package/dist/esm/Image.js +7 -9
- package/dist/esm/ImagePreview.js +19 -20
- package/dist/esm/Indicator.js +6 -7
- package/dist/esm/Infiniteloading.js +12 -14
- package/dist/esm/Input.js +11 -13
- package/dist/esm/InputNumber.js +9 -10
- package/dist/esm/Layout.js +5 -6
- package/dist/esm/Menu.js +8 -9
- package/dist/esm/MenuItem.js +13 -14
- package/dist/esm/NavBar.js +7 -8
- package/dist/esm/NoticeBar.js +11 -12
- package/dist/esm/Notify.js +9 -10
- package/dist/esm/NumberKeyboard.js +16 -18
- package/dist/esm/Overlay.js +8 -9
- package/dist/esm/Pagination.js +9 -11
- package/dist/esm/Picker.js +20 -22
- package/dist/esm/Popover.js +10 -11
- package/dist/esm/Popup.js +12 -13
- package/dist/esm/Price.js +7 -8
- package/dist/esm/Progress.js +7 -8
- package/dist/esm/PullToRefresh.js +11 -13
- package/dist/esm/Radio.js +9 -10
- package/dist/esm/RadioGroup.js +9 -10
- package/dist/esm/Range.js +13 -15
- package/dist/esm/Rate.js +9 -10
- package/dist/esm/Row.js +8 -9
- package/dist/esm/SearchBar.js +11 -13
- package/dist/esm/ShortPassword.js +16 -18
- package/dist/esm/SideNavBar.js +14 -15
- package/dist/esm/SideNavBarItem.js +5 -6
- package/dist/esm/Signature.js +13 -15
- package/dist/esm/Skeleton.js +14 -16
- package/dist/esm/Step.js +10 -11
- package/dist/esm/Steps.js +9 -10
- package/dist/esm/Sticky.js +11 -12
- package/dist/esm/SubSideNavBar.js +6 -7
- package/dist/esm/Swipe.js +11 -12
- package/dist/esm/Swiper.js +10 -11
- package/dist/esm/SwiperItem.js +9 -10
- package/dist/esm/Switch.js +7 -8
- package/dist/esm/TabPane.js +6 -7
- package/dist/esm/Tabbar.js +10 -11
- package/dist/esm/TabbarItem.js +8 -9
- package/dist/esm/Table.js +9 -13
- package/dist/esm/Tabs.js +11 -12
- package/dist/esm/Tag.js +8 -9
- package/dist/esm/TextArea.js +11 -10
- package/dist/esm/TimeDetail.js +8 -10
- package/dist/esm/TimePannel.js +8 -10
- package/dist/esm/TimeSelect.js +18 -20
- package/dist/esm/Toast.js +9 -10
- package/dist/esm/TrendArrow.js +8 -9
- package/dist/esm/Uploader.js +14 -16
- package/dist/esm/UserContext-735db09f.js +5 -0
- package/dist/esm/UserContext-ab42ba7f.js +5 -0
- package/dist/esm/UserContext-fde5badc.js +5 -0
- package/dist/esm/Video.js +8 -9
- package/dist/esm/VirtualList.js +8 -10
- package/dist/esm/WaterMark.js +10 -12
- package/dist/esm/actionsheet.taro-d2217152.js +61 -0
- package/dist/esm/address.taro-1c534feb.js +470 -0
- package/dist/esm/animate.taro-c8b29242.js +44 -0
- package/dist/esm/animatingnumbers.taro-c2a52dbd.js +103 -0
- package/dist/esm/audio.taro-ec96ef80.js +185 -0
- package/dist/esm/avatar.taro-01536aff.js +100 -0
- package/dist/esm/avatargroup-ad5ffb46.js +34 -0
- package/dist/esm/backtop.taro-7de36464.js +48 -0
- package/dist/esm/badge.taro-872605bf.js +48 -0
- package/dist/esm/barrage.taro-c8cb9864.js +91 -0
- package/dist/esm/bem-cdccae08.js +5 -0
- package/dist/esm/button.taro-01eae688.js +72 -0
- package/dist/esm/calendar.taro-10a6cb11.js +70 -0
- package/dist/esm/calendaritem.taro-3e5f114e.js +732 -0
- package/dist/esm/can-use-dom-0e539bd3.js +4 -0
- package/dist/esm/card.taro-a46fdf25.js +51 -0
- package/dist/esm/cascader.taro-a8d2148e.js +463 -0
- package/dist/esm/cell.taro-4e31d1fa.js +48 -0
- package/dist/esm/cellgroup.taro-a790d91b.js +28 -0
- package/dist/esm/checkbox.taro-016074da.js +177 -0
- package/dist/esm/circleprogress.taro-7149e09d.js +104 -0
- package/dist/esm/col.taro-d6a46a7d.js +41 -0
- package/dist/esm/collapse.taro-3d997680.js +70 -0
- package/dist/esm/collapseitem-f4571575.js +76 -0
- package/dist/esm/configprovider.taro-25758d9f.js +462 -0
- package/dist/esm/context-d0fccf11.js +5 -0
- package/dist/esm/countdown.taro-22200811.js +210 -0
- package/dist/esm/datepicker.taro-3f718964.js +260 -0
- package/dist/esm/dialog.taro-290eb9a6.js +128 -0
- package/dist/esm/divider.taro-0cb5f894.js +31 -0
- package/dist/esm/drag.taro-48e1ff38.js +111 -0
- package/dist/esm/elevator.taro-bc162e4f.js +201 -0
- package/dist/esm/ellipsis.taro-f9688dd7.js +242 -0
- package/dist/esm/empty.taro-ca792f57.js +59 -0
- package/dist/esm/fixednav.taro-28e5f776.js +61 -0
- package/dist/esm/form.taro-b06754e8.js +182 -0
- package/dist/esm/formitem.taro-b326809d.js +108 -0
- package/dist/esm/get-scroll-parent-8da04f2e.js +24 -0
- package/dist/esm/grid.taro-fbbd8618.js +52 -0
- package/dist/esm/griditem.taro-b0c37077.js +85 -0
- package/dist/esm/image.taro-767aa000.js +65 -0
- package/dist/esm/imagepreview.taro-8832dc01.js +163 -0
- package/dist/esm/index-e3184f19.js +9 -0
- package/dist/esm/indicator.taro-f2bd212f.js +30 -0
- package/dist/esm/infiniteloading.taro-f8f23ac6.js +143 -0
- package/dist/esm/input.taro-27d686c9.js +164 -0
- package/dist/esm/inputnumber.taro-877dc947.js +197 -0
- package/dist/esm/layout.taro-9659a928.js +11 -0
- package/dist/esm/menu.taro-cd0fef41.js +122 -0
- package/dist/esm/menuitem.taro-6076bffa.js +142 -0
- package/dist/esm/navbar.taro-5e1a0835.js +61 -0
- package/dist/esm/noticebar.taro-b3bfd4fe.js +408 -0
- package/dist/esm/notify.taro-6b6eb6bf.js +82 -0
- package/dist/esm/numberkeyboard.taro-0a0e866a.js +183 -0
- package/dist/esm/nutui-react.es.js +211 -116
- package/dist/esm/offsetContext-f32a9246.js +5 -0
- package/dist/esm/overlay.taro-75012bd3.js +77 -0
- package/dist/esm/pagination.taro-63607c3b.js +94 -0
- package/dist/esm/picker.taro-a5603921.js +468 -0
- package/dist/esm/popover.taro-ad483372.js +162 -0
- package/dist/esm/popup.taro-e756f3fc.js +150 -0
- package/dist/esm/price.taro-c4f45310.js +80 -0
- package/dist/esm/progress.taro-ff63be75.js +49 -0
- package/dist/esm/pulltorefresh.taro-c611fd92.js +179 -0
- package/dist/esm/radio.taro-3a54f4c8.js +152 -0
- package/dist/esm/range.taro-52cda918.js +325 -0
- package/dist/esm/rate.taro-78c66969.js +77 -0
- package/dist/esm/row.taro-8b7febd4.js +48 -0
- package/dist/esm/searchbar.taro-37ade36e.js +159 -0
- package/dist/esm/shortpassword.taro-f7292032.js +146 -0
- package/dist/esm/sidenavbar.taro-9f210df4.js +51 -0
- package/dist/esm/sidenavbaritem.taro-32a45ce6.js +12 -0
- package/dist/esm/signature.taro-c57469aa.js +146 -0
- package/dist/esm/skeleton.taro-9ff9baf4.js +71 -0
- package/dist/esm/step.taro-3bc01c0c.js +66 -0
- package/dist/esm/steps.taro-77e301ab.js +30 -0
- package/dist/esm/sticky.taro-3c03eb0a.js +134 -0
- package/dist/esm/subsidenavbar.taro-abe07673.js +64 -0
- package/dist/esm/supports-passive-aaaf0eff.js +17 -0
- package/dist/esm/swipe.taro-de80fcd8.js +180 -0
- package/dist/esm/swiper.taro-74cf9306.js +430 -0
- package/dist/esm/swiperitem-80df464a.js +29 -0
- package/dist/esm/switch.taro-f0da73a3.js +44 -0
- package/dist/esm/tabbar.taro-18eee41f.js +55 -0
- package/dist/esm/tabbaritem.taro-89646ca1.js +47 -0
- package/dist/esm/table.taro-15a55c5d.js +100 -0
- package/dist/esm/tabpane.taro-f8d92ece.js +21 -0
- package/dist/esm/tabs.taro-56e46dd3.js +137 -0
- package/dist/esm/tag.taro-1b4134a5.js +92 -0
- package/dist/esm/textarea.taro-c110565e.js +102 -0
- package/dist/esm/timedetail.taro-8d2acbbf.js +41 -0
- package/dist/esm/timepannel.taro-ee4c5dfa.js +22 -0
- package/dist/esm/timeselect.taro-069deedd.js +133 -0
- package/dist/esm/toast.taro-92c10e1d.js +114 -0
- package/dist/esm/trendarrow.taro-0cf43935.js +72 -0
- package/dist/esm/typings-11d83a22.js +7 -0
- package/dist/esm/uploader.taro-92977813.js +519 -0
- package/dist/esm/use-client-rect-f317804e.js +10 -0
- package/dist/esm/use-props-value-7ac1b1b5.js +16 -0
- package/dist/esm/use-touch-ff43512c.js +69 -0
- package/dist/esm/video-5d106e33.js +73 -0
- package/dist/esm/virtuallist.taro-99f03769.js +195 -0
- package/dist/esm/watermark.taro-cef29c03.js +109 -0
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.mjs +505 -447
- package/dist/nutui.react.umd.js +504 -446
- package/dist/packages/cascader/cascader.scss +0 -26
- package/dist/packages/picker/picker.scss +66 -137
- package/dist/packages/table/table.scss +0 -56
- package/dist/packages/textarea/textarea.scss +5 -12
- package/dist/style.css +1 -1
- package/dist/style.mjs +1 -1
- package/dist/styles/variables-jmapp.scss +1 -4
- package/dist/styles/variables.scss +2 -6
- package/dist/types/index.d.ts +42 -46
- package/package.json +1 -1
- package/dist/esm/UserContext-0aac9a82.js +0 -5
- package/dist/esm/UserContext-e402e1a6.js +0 -5
- package/dist/esm/UserContext-e8176108.js +0 -5
- package/dist/esm/actionsheet.taro-12cf5a3e.js +0 -53
- package/dist/esm/address.taro-cab0ea22.js +0 -475
- package/dist/esm/animate.taro-485331bb.js +0 -41
- package/dist/esm/animatingnumbers.taro-f6eaffef.js +0 -104
- package/dist/esm/audio.taro-ff280f5e.js +0 -162
- package/dist/esm/avatar.taro-6e8f1f5c.js +0 -107
- package/dist/esm/avatargroup-f4375806.js +0 -31
- package/dist/esm/backtop.taro-8ec80d02.js +0 -52
- package/dist/esm/badge.taro-e2169fbe.js +0 -45
- package/dist/esm/barrage.taro-aa08da6c.js +0 -94
- package/dist/esm/bem-350c1702.js +0 -5
- package/dist/esm/button.taro-b50bc217.js +0 -65
- package/dist/esm/calendar.taro-2fc9b899.js +0 -65
- package/dist/esm/calendaritem.taro-2d4a8c34.js +0 -791
- package/dist/esm/can-use-dom-3eeb5af4.js +0 -6
- package/dist/esm/card.taro-0e849e94.js +0 -33
- package/dist/esm/cascader.taro-467910b2.js +0 -447
- package/dist/esm/cell.taro-ea725a95.js +0 -43
- package/dist/esm/cellgroup.taro-e05ea802.js +0 -25
- package/dist/esm/checkbox.taro-9d02f86c.js +0 -175
- package/dist/esm/circleprogress.taro-d4943109.js +0 -103
- package/dist/esm/col.taro-4477c9f7.js +0 -43
- package/dist/esm/collapse.taro-89bcadf2.js +0 -79
- package/dist/esm/collapseitem-0e228cec.js +0 -68
- package/dist/esm/configprovider.taro-ce34d482.js +0 -174
- package/dist/esm/context-c96afdcc.js +0 -5
- package/dist/esm/countdown.taro-3118ba23.js +0 -225
- package/dist/esm/datepicker.taro-2e3e955b.js +0 -275
- package/dist/esm/dialog.taro-eab19eab.js +0 -107
- package/dist/esm/divider.taro-3993d7d5.js +0 -33
- package/dist/esm/drag.taro-347dfb84.js +0 -111
- package/dist/esm/elevator.taro-1a4e3356.js +0 -193
- package/dist/esm/ellipsis.taro-e1ac99a1.js +0 -244
- package/dist/esm/empty.taro-26363c66.js +0 -56
- package/dist/esm/fixednav.taro-ddb21e87.js +0 -54
- package/dist/esm/form.taro-423b0f0a.js +0 -179
- package/dist/esm/formitem.taro-b550d29c.js +0 -89
- package/dist/esm/get-scroll-parent-b4a07e65.js +0 -25
- package/dist/esm/grid.taro-883a9c35.js +0 -49
- package/dist/esm/griditem.taro-16c7055b.js +0 -80
- package/dist/esm/image.taro-3025e659.js +0 -64
- package/dist/esm/imagepreview.taro-d511342c.js +0 -167
- package/dist/esm/index-5bcb0ff8.js +0 -7
- package/dist/esm/indicator.taro-bfb21d45.js +0 -30
- package/dist/esm/infiniteloading.taro-721bca1f.js +0 -141
- package/dist/esm/input.taro-06c1e4d5.js +0 -167
- package/dist/esm/inputnumber.taro-1f893d42.js +0 -199
- package/dist/esm/layout.taro-e4bf83cb.js +0 -11
- package/dist/esm/menu.taro-e5c68cb8.js +0 -111
- package/dist/esm/menuitem.taro-37c18382.js +0 -129
- package/dist/esm/navbar.taro-92bab9c4.js +0 -57
- package/dist/esm/noticebar.taro-cbe93c9e.js +0 -427
- package/dist/esm/notify.taro-f1079218.js +0 -75
- package/dist/esm/numberkeyboard.taro-d9b1721b.js +0 -159
- package/dist/esm/offsetContext-c2a746fa.js +0 -5
- package/dist/esm/overlay.taro-067b7202.js +0 -73
- package/dist/esm/pagination.taro-94f9be5e.js +0 -91
- package/dist/esm/picker.taro-e16b4312.js +0 -423
- package/dist/esm/popover.taro-84a55ff9.js +0 -153
- package/dist/esm/popup.taro-89cc342a.js +0 -139
- package/dist/esm/price.taro-959d82f2.js +0 -83
- package/dist/esm/progress.taro-1a7ac8a4.js +0 -40
- package/dist/esm/pulltorefresh.taro-016d0079.js +0 -181
- package/dist/esm/radio.taro-36438449.js +0 -177
- package/dist/esm/range.taro-8953e8c3.js +0 -332
- package/dist/esm/rate.taro-895bb41c.js +0 -77
- package/dist/esm/row.taro-e929ec5c.js +0 -48
- package/dist/esm/searchbar.taro-4467040f.js +0 -152
- package/dist/esm/shortpassword.taro-433b86a4.js +0 -119
- package/dist/esm/sidenavbar.taro-f8ffb7dc.js +0 -33
- package/dist/esm/sidenavbaritem.taro-6cb0821e.js +0 -12
- package/dist/esm/signature.taro-a4d9b5c9.js +0 -143
- package/dist/esm/skeleton.taro-8ec11af9.js +0 -62
- package/dist/esm/step.taro-7ea33a76.js +0 -58
- package/dist/esm/steps.taro-86753d36.js +0 -30
- package/dist/esm/sticky.taro-a142a5f2.js +0 -136
- package/dist/esm/subsidenavbar.taro-85c03291.js +0 -63
- package/dist/esm/supports-passive-c85ef996.js +0 -18
- package/dist/esm/swipe.taro-0b8cc872.js +0 -175
- package/dist/esm/swiper.taro-c0e9a56b.js +0 -451
- package/dist/esm/swiperitem-abab7606.js +0 -29
- package/dist/esm/switch.taro-e82809f6.js +0 -38
- package/dist/esm/tabbar.taro-48413fb8.js +0 -51
- package/dist/esm/tabbaritem.taro-5afa3562.js +0 -37
- package/dist/esm/table.taro-327b4248.js +0 -95
- package/dist/esm/tabpane.taro-406cc0d3.js +0 -21
- package/dist/esm/tabs.taro-d47ccfc5.js +0 -120
- package/dist/esm/tag.taro-846ee805.js +0 -92
- package/dist/esm/textarea.taro-add72cf3.js +0 -94
- package/dist/esm/timedetail.taro-82a2900b.js +0 -44
- package/dist/esm/timepannel.taro-0573bb65.js +0 -22
- package/dist/esm/timeselect.taro-29124a34.js +0 -133
- package/dist/esm/toast.taro-c509a870.js +0 -108
- package/dist/esm/trendarrow.taro-dd83ec94.js +0 -70
- package/dist/esm/typings-d8491423.js +0 -6
- package/dist/esm/uploader.taro-c70d00de.js +0 -494
- package/dist/esm/use-client-rect-1f8ed1fe.js +0 -18
- package/dist/esm/use-props-value-ae7ee726.js +0 -15
- package/dist/esm/use-touch-db24bb5c.js +0 -69
- package/dist/esm/video-1c6405b4.js +0 -67
- package/dist/esm/virtuallist.taro-ba8e1f21.js +0 -214
- package/dist/esm/watermark.taro-168cdac5.js +0 -114
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, useRef, useState, useImperativeHandle, useEffect } from 'react';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import { useReady, nextTick } from '@tarojs/taro';
|
|
4
|
-
import { c as cn } from './bem-350c1702.js';
|
|
5
|
-
import { u as useTouch } from './use-touch-db24bb5c.js';
|
|
6
|
-
import { g as getRectByTaro } from './use-client-rect-1f8ed1fe.js';
|
|
7
|
-
|
|
8
|
-
function preventDefault(event, isStopPropagation) {
|
|
9
|
-
if (typeof event.cancelable !== 'boolean' || event.cancelable) {
|
|
10
|
-
event.preventDefault();
|
|
11
|
-
}
|
|
12
|
-
if (isStopPropagation) {
|
|
13
|
-
event.stopPropagation();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const defaultProps = {
|
|
17
|
-
name: '',
|
|
18
|
-
};
|
|
19
|
-
const Swipe = forwardRef((props, instanceRef) => {
|
|
20
|
-
const swipeBem = cn('swipe');
|
|
21
|
-
const touch = useTouch();
|
|
22
|
-
// 获取元素的时候要在页面 onReady 后,需要参考小程序的事件周期
|
|
23
|
-
useReady(() => {
|
|
24
|
-
const getWidth = async () => {
|
|
25
|
-
if (leftWrapper.current) {
|
|
26
|
-
const leftRect = await getRectByTaro(leftWrapper.current);
|
|
27
|
-
setActionWidth((v) => ({ ...v, left: leftRect.width }));
|
|
28
|
-
}
|
|
29
|
-
if (rightWrapper.current) {
|
|
30
|
-
const rightRect = await getRectByTaro(rightWrapper.current);
|
|
31
|
-
setActionWidth((v) => ({ ...v, right: rightRect.width }));
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
nextTick(() => getWidth());
|
|
35
|
-
});
|
|
36
|
-
const { children, className, style } = { ...defaultProps, ...props };
|
|
37
|
-
const root = useRef();
|
|
38
|
-
const opened = useRef(false);
|
|
39
|
-
const lockClick = useRef(false);
|
|
40
|
-
const startOffset = useRef(0);
|
|
41
|
-
const [state, setState] = useState({
|
|
42
|
-
offset: 0,
|
|
43
|
-
dragging: false,
|
|
44
|
-
});
|
|
45
|
-
const [actionWidth, setActionWidth] = useState({
|
|
46
|
-
left: 0,
|
|
47
|
-
right: 0,
|
|
48
|
-
});
|
|
49
|
-
const wrapperStyle = {
|
|
50
|
-
transform: `translate3d(${state.offset}px, 0, 0)`,
|
|
51
|
-
transitionDuration: state.dragging ? '0s' : '.6s',
|
|
52
|
-
};
|
|
53
|
-
const leftWidth = actionWidth.left;
|
|
54
|
-
const rightWidth = actionWidth.right;
|
|
55
|
-
const onTouchStart = async (event) => {
|
|
56
|
-
if (leftWrapper.current) {
|
|
57
|
-
const leftRect = await getRectByTaro(leftWrapper.current);
|
|
58
|
-
setActionWidth((v) => ({ ...v, left: leftRect.width }));
|
|
59
|
-
}
|
|
60
|
-
if (rightWrapper.current) {
|
|
61
|
-
const rightRect = await getRectByTaro(rightWrapper.current);
|
|
62
|
-
setActionWidth((v) => ({ ...v, right: rightRect.width }));
|
|
63
|
-
}
|
|
64
|
-
if (!props.disabled) {
|
|
65
|
-
startOffset.current = state.offset;
|
|
66
|
-
touch.start(event);
|
|
67
|
-
props.onTouchStart && props.onTouchStart(event);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const onTouchMove = (event) => {
|
|
71
|
-
if (props.disabled) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
touch.move(event);
|
|
75
|
-
props.onTouchMove && props.onTouchMove(event);
|
|
76
|
-
if (touch.isHorizontal()) {
|
|
77
|
-
lockClick.current = true;
|
|
78
|
-
const newState = { ...state, dragging: true };
|
|
79
|
-
const isEdge = !opened || touch.deltaX * startOffset.current < 0;
|
|
80
|
-
if (isEdge) {
|
|
81
|
-
preventDefault(event, true);
|
|
82
|
-
}
|
|
83
|
-
newState.offset = rangeCalculation(touch.deltaX + startOffset.current, -rightWidth || 0, leftWidth || 0);
|
|
84
|
-
setState(newState);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const onTouchEnd = (event) => {
|
|
88
|
-
if (state.dragging) {
|
|
89
|
-
setState((v) => ({ ...v, dragging: false }));
|
|
90
|
-
toggle(state.offset > 0 ? 'left' : 'right');
|
|
91
|
-
setTimeout(() => {
|
|
92
|
-
lockClick.current = false;
|
|
93
|
-
}, 0);
|
|
94
|
-
props.onTouchEnd && props.onTouchEnd(event);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const toggle = (side) => {
|
|
98
|
-
const offset = Math.abs(state.offset);
|
|
99
|
-
const base = 0.3;
|
|
100
|
-
const baseNum = opened ? 1 - base : base;
|
|
101
|
-
const width = side === 'left' ? leftWidth : rightWidth;
|
|
102
|
-
if (width && offset > Number(width) * baseNum) {
|
|
103
|
-
open(side);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
close(side);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const open = (side) => {
|
|
110
|
-
opened.current = true;
|
|
111
|
-
const offset = side === 'left' ? leftWidth : -rightWidth;
|
|
112
|
-
const name = props.name;
|
|
113
|
-
props.onOpen?.({ name, position: side });
|
|
114
|
-
setState((v) => ({ ...v, offset: Number(offset) || 0 }));
|
|
115
|
-
};
|
|
116
|
-
const close = (position) => {
|
|
117
|
-
if (opened.current) {
|
|
118
|
-
opened.current = false;
|
|
119
|
-
props.onClose?.({
|
|
120
|
-
name: props.name,
|
|
121
|
-
position: position || 'left',
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
setState((v) => ({ ...v, offset: 0 }));
|
|
125
|
-
};
|
|
126
|
-
const rangeCalculation = (num, min, max) => {
|
|
127
|
-
return Math.min(Math.max(Number(num), Number(min)), Number(max));
|
|
128
|
-
};
|
|
129
|
-
const leftWrapper = useRef(null);
|
|
130
|
-
const rightWrapper = useRef(null);
|
|
131
|
-
const renderActionContent = (side) => {
|
|
132
|
-
if (props[`${side}Action`]) {
|
|
133
|
-
return (React.createElement("div", { id: "left", ref: side === 'left' ? leftWrapper : rightWrapper, className: `${swipeBem(side)}`, onClick: (e) => handleOperate(e, side) }, props[`${side}Action`]));
|
|
134
|
-
}
|
|
135
|
-
return null;
|
|
136
|
-
};
|
|
137
|
-
const handleOperate = (event, position) => {
|
|
138
|
-
event.stopPropagation();
|
|
139
|
-
if (props.beforeClose) {
|
|
140
|
-
props.beforeClose(position);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
props.onActionClick && props.onActionClick(event, position);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
useImperativeHandle(instanceRef, () => ({
|
|
147
|
-
open,
|
|
148
|
-
close: () => close(),
|
|
149
|
-
}));
|
|
150
|
-
useEffect(() => {
|
|
151
|
-
const handler = (event) => {
|
|
152
|
-
const targets = [root];
|
|
153
|
-
if (targets.some((targetItem) => {
|
|
154
|
-
const targetElement = targetItem.current || targetItem;
|
|
155
|
-
return !targetElement || targetElement?.contains(event.target);
|
|
156
|
-
})) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
close();
|
|
160
|
-
};
|
|
161
|
-
document.addEventListener('touchstart', handler);
|
|
162
|
-
return () => {
|
|
163
|
-
document.removeEventListener('touchstart', handler);
|
|
164
|
-
};
|
|
165
|
-
}, []);
|
|
166
|
-
return (React.createElement("div", { ref: root, className: classNames(swipeBem(), className), onTouchStart: (e) => onTouchStart(e), onTouchMove: (e) => onTouchMove(e), onTouchEnd: (e) => onTouchEnd(e), style: style },
|
|
167
|
-
React.createElement("div", { className: `${swipeBem('wrapper')}`, style: wrapperStyle },
|
|
168
|
-
renderActionContent('left'),
|
|
169
|
-
children,
|
|
170
|
-
renderActionContent('right'))));
|
|
171
|
-
});
|
|
172
|
-
Swipe.defaultProps = defaultProps;
|
|
173
|
-
Swipe.displayName = 'NutSwipe';
|
|
174
|
-
|
|
175
|
-
export { Swipe as S };
|
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState, useMemo, useEffect } from 'react';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import { nextTick, useReady, createSelectorQuery } from '@tarojs/taro';
|
|
4
|
-
import { D as DataContext } from './UserContext-e8176108.js';
|
|
5
|
-
import { c as cn } from './bem-350c1702.js';
|
|
6
|
-
|
|
7
|
-
const defaultProps = {
|
|
8
|
-
width: typeof window === 'object' ? window.innerWidth : 375,
|
|
9
|
-
height: 0,
|
|
10
|
-
duration: 500,
|
|
11
|
-
initPage: 0,
|
|
12
|
-
autoPlay: 0,
|
|
13
|
-
direction: 'horizontal',
|
|
14
|
-
paginationColor: '#fff',
|
|
15
|
-
paginationBgColor: '#ddd',
|
|
16
|
-
paginationVisible: false,
|
|
17
|
-
loop: true,
|
|
18
|
-
touchable: true,
|
|
19
|
-
isPreventDefault: true,
|
|
20
|
-
isStopPropagation: true,
|
|
21
|
-
isCenter: false,
|
|
22
|
-
className: '',
|
|
23
|
-
};
|
|
24
|
-
const DISTANCE = 5;
|
|
25
|
-
const Swiper = React.forwardRef((props, ref) => {
|
|
26
|
-
const propSwiper = { ...defaultProps, ...props };
|
|
27
|
-
const { children, direction, className, pageContent, onChange, initPage, paginationColor, paginationVisible, touchable, isPreventDefault, isStopPropagation, autoPlay, isCenter, ...rest } = propSwiper;
|
|
28
|
-
const container = useRef(null);
|
|
29
|
-
const innerRef = useRef(null);
|
|
30
|
-
const _swiper = useRef({
|
|
31
|
-
moving: false,
|
|
32
|
-
autoplayTimer: null,
|
|
33
|
-
width: 0,
|
|
34
|
-
height: 0,
|
|
35
|
-
offset: 0,
|
|
36
|
-
size: 0,
|
|
37
|
-
});
|
|
38
|
-
const [refRandomId] = useState(Math.random().toString(36).slice(-8));
|
|
39
|
-
const isVertical = direction === 'vertical';
|
|
40
|
-
const [rect, setRect] = useState(null);
|
|
41
|
-
// eslint-disable-next-line prefer-const
|
|
42
|
-
let [active, setActive] = useState(0);
|
|
43
|
-
const [width, setWidth] = useState(0);
|
|
44
|
-
const [height, setHeight] = useState(0);
|
|
45
|
-
const [offset, setOffset] = useState(0);
|
|
46
|
-
const [childOffset, setChildOffset] = useState([]);
|
|
47
|
-
const [ready, setReady] = useState(false);
|
|
48
|
-
let size = isVertical ? height : width;
|
|
49
|
-
const [touch, setTouch] = useState({
|
|
50
|
-
startX: 0,
|
|
51
|
-
startY: 0,
|
|
52
|
-
deltaX: 0,
|
|
53
|
-
deltaY: 0,
|
|
54
|
-
offsetX: 0,
|
|
55
|
-
offsetY: 0,
|
|
56
|
-
stateDirection: '',
|
|
57
|
-
delta: 0,
|
|
58
|
-
touchTime: 0,
|
|
59
|
-
});
|
|
60
|
-
const { childs, childCount } = useMemo(() => {
|
|
61
|
-
let childCount = 0;
|
|
62
|
-
const childs = React.Children.map(props.children, (child) => {
|
|
63
|
-
if (!React.isValidElement(child))
|
|
64
|
-
return null;
|
|
65
|
-
childCount++;
|
|
66
|
-
return child;
|
|
67
|
-
});
|
|
68
|
-
return {
|
|
69
|
-
childs,
|
|
70
|
-
childCount,
|
|
71
|
-
};
|
|
72
|
-
}, [props.children]);
|
|
73
|
-
let trackSize = childCount * Number(size);
|
|
74
|
-
// 父组件参数传入子组件item
|
|
75
|
-
const parent = {
|
|
76
|
-
propSwiper,
|
|
77
|
-
size,
|
|
78
|
-
};
|
|
79
|
-
const minOffset = (() => {
|
|
80
|
-
if (rect) {
|
|
81
|
-
const base = isVertical ? rect?.height : rect?.width;
|
|
82
|
-
return base - Number(size) * childCount;
|
|
83
|
-
}
|
|
84
|
-
return 0;
|
|
85
|
-
})();
|
|
86
|
-
// 清除定时器
|
|
87
|
-
const stopAutoPlay = () => {
|
|
88
|
-
clearTimeout(_swiper.current.autoplayTimer);
|
|
89
|
-
_swiper.current.autoplayTimer = null;
|
|
90
|
-
};
|
|
91
|
-
// 定时轮播
|
|
92
|
-
const autoplay = () => {
|
|
93
|
-
if (propSwiper.autoPlay <= 0 || childCount <= 1)
|
|
94
|
-
return;
|
|
95
|
-
stopAutoPlay();
|
|
96
|
-
_swiper.current.autoplayTimer = setTimeout(() => {
|
|
97
|
-
next();
|
|
98
|
-
autoplay();
|
|
99
|
-
}, Number(propSwiper.autoPlay));
|
|
100
|
-
};
|
|
101
|
-
// 重置首尾位置信息
|
|
102
|
-
const resettPosition = () => {
|
|
103
|
-
_swiper.current.moving = true;
|
|
104
|
-
if (active <= -1) {
|
|
105
|
-
move({ pace: childCount });
|
|
106
|
-
}
|
|
107
|
-
if (active >= childCount) {
|
|
108
|
-
move({ pace: -childCount });
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
// 上一页
|
|
112
|
-
const prev = () => {
|
|
113
|
-
resettPosition();
|
|
114
|
-
touchReset();
|
|
115
|
-
requestFrame(() => {
|
|
116
|
-
requestFrame(() => {
|
|
117
|
-
_swiper.current.moving = false;
|
|
118
|
-
move({
|
|
119
|
-
pace: -1,
|
|
120
|
-
isEmit: true,
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
// 下一页
|
|
126
|
-
const next = () => {
|
|
127
|
-
resettPosition();
|
|
128
|
-
touchReset();
|
|
129
|
-
requestFrame(() => {
|
|
130
|
-
requestFrame(() => {
|
|
131
|
-
_swiper.current.moving = false;
|
|
132
|
-
move({
|
|
133
|
-
pace: 1,
|
|
134
|
-
isEmit: true,
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
// 前往指定页
|
|
140
|
-
const to = (index) => {
|
|
141
|
-
resettPosition();
|
|
142
|
-
touchReset();
|
|
143
|
-
requestFrame(() => {
|
|
144
|
-
requestFrame(() => {
|
|
145
|
-
_swiper.current.moving = false;
|
|
146
|
-
let targetIndex;
|
|
147
|
-
if (props.loop && childCount === index) {
|
|
148
|
-
targetIndex = active === 0 ? 0 : index;
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
targetIndex = index % childCount;
|
|
152
|
-
}
|
|
153
|
-
move({
|
|
154
|
-
pace: targetIndex - active,
|
|
155
|
-
isEmit: true,
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
const resize = () => {
|
|
161
|
-
init(active);
|
|
162
|
-
};
|
|
163
|
-
// 切换方法
|
|
164
|
-
const move = ({ pace = 0, offset = 0, isEmit = false, movingStatus = false, }) => {
|
|
165
|
-
if (childCount <= 1)
|
|
166
|
-
return;
|
|
167
|
-
const targetActive = getActive(pace);
|
|
168
|
-
// 父级容器偏移量
|
|
169
|
-
const targetOffset = getOffset(targetActive, offset);
|
|
170
|
-
// 如果循环,调整开头结尾图片位置
|
|
171
|
-
if (props.loop) {
|
|
172
|
-
if (Array.isArray(children) &&
|
|
173
|
-
children[0] &&
|
|
174
|
-
targetOffset !== minOffset) {
|
|
175
|
-
const rightBound = targetOffset < minOffset;
|
|
176
|
-
childOffset[0] = rightBound ? trackSize : 0;
|
|
177
|
-
}
|
|
178
|
-
if (Array.isArray(children) &&
|
|
179
|
-
children[childCount - 1] &&
|
|
180
|
-
targetOffset !== 0) {
|
|
181
|
-
const leftBound = targetOffset > 0;
|
|
182
|
-
childOffset[childCount - 1] = leftBound ? -trackSize : 0;
|
|
183
|
-
}
|
|
184
|
-
setChildOffset(childOffset);
|
|
185
|
-
}
|
|
186
|
-
if (isEmit && active !== targetActive) {
|
|
187
|
-
props.onChange && props.onChange((targetActive + childCount) % childCount);
|
|
188
|
-
}
|
|
189
|
-
active = targetActive;
|
|
190
|
-
setActive(targetActive);
|
|
191
|
-
setOffset(targetOffset);
|
|
192
|
-
getStyle(targetOffset);
|
|
193
|
-
};
|
|
194
|
-
// 确定当前active 元素
|
|
195
|
-
const getActive = (pace) => {
|
|
196
|
-
if (pace) {
|
|
197
|
-
const _active = active + pace;
|
|
198
|
-
if (props.loop) {
|
|
199
|
-
return range(_active, -1, childCount);
|
|
200
|
-
}
|
|
201
|
-
return range(_active, 0, childCount - 1);
|
|
202
|
-
}
|
|
203
|
-
return active;
|
|
204
|
-
};
|
|
205
|
-
// 计算位移
|
|
206
|
-
const getOffset = (active, offset = 0) => {
|
|
207
|
-
let currentPosition = active * Number(size);
|
|
208
|
-
if (!props.loop) {
|
|
209
|
-
currentPosition = Math.min(currentPosition, -minOffset);
|
|
210
|
-
}
|
|
211
|
-
let targetOffset = offset - currentPosition;
|
|
212
|
-
if (!props.loop) {
|
|
213
|
-
targetOffset = range(targetOffset, minOffset, 0);
|
|
214
|
-
}
|
|
215
|
-
return targetOffset;
|
|
216
|
-
};
|
|
217
|
-
// 浏览器 帧 事件
|
|
218
|
-
const requestFrame = (fn) => {
|
|
219
|
-
window.requestAnimationFrame.call(window, fn);
|
|
220
|
-
};
|
|
221
|
-
// 取值 方法
|
|
222
|
-
const range = (num, min, max) => {
|
|
223
|
-
return Math.min(Math.max(num, min), max);
|
|
224
|
-
};
|
|
225
|
-
const getDirection = (x, y) => {
|
|
226
|
-
if (x > y && x > DISTANCE)
|
|
227
|
-
return 'horizontal';
|
|
228
|
-
if (y > x && y > DISTANCE)
|
|
229
|
-
return 'vertical';
|
|
230
|
-
return '';
|
|
231
|
-
};
|
|
232
|
-
// 重置 全部位移信息
|
|
233
|
-
const touchReset = () => {
|
|
234
|
-
touch.startX = 0;
|
|
235
|
-
touch.startY = 0;
|
|
236
|
-
touch.deltaX = 0;
|
|
237
|
-
touch.deltaY = 0;
|
|
238
|
-
touch.offsetX = 0;
|
|
239
|
-
touch.offsetY = 0;
|
|
240
|
-
touch.delta = 0;
|
|
241
|
-
touch.stateDirection = '';
|
|
242
|
-
touch.touchTime = 0;
|
|
243
|
-
};
|
|
244
|
-
// 触摸事件开始
|
|
245
|
-
const touchStart = (e) => {
|
|
246
|
-
touchReset();
|
|
247
|
-
touch.startX = e.touches[0].clientX;
|
|
248
|
-
touch.startY = e.touches[0].clientY;
|
|
249
|
-
};
|
|
250
|
-
// 触摸事件移动
|
|
251
|
-
const touchMove = (e) => {
|
|
252
|
-
touch.deltaX = e.touches[0].clientX - touch.startX;
|
|
253
|
-
touch.deltaY = e.touches[0].clientY - touch.startY;
|
|
254
|
-
touch.offsetX = Math.abs(touch.deltaX);
|
|
255
|
-
touch.offsetY = Math.abs(touch.deltaY);
|
|
256
|
-
touch.delta = isVertical ? touch.deltaY : touch.deltaX;
|
|
257
|
-
if (!touch.stateDirection) {
|
|
258
|
-
touch.stateDirection = getDirection(touch.offsetX, touch.offsetY);
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
const b = cn('swiper');
|
|
262
|
-
const classes = classNames(b(''));
|
|
263
|
-
const contentClass = classNames({
|
|
264
|
-
[`${b('inner')}`]: true,
|
|
265
|
-
[`${b('vertical')}`]: isVertical,
|
|
266
|
-
});
|
|
267
|
-
const getStyle = (moveOffset = offset) => {
|
|
268
|
-
const target = innerRef.current;
|
|
269
|
-
let _offset = 0;
|
|
270
|
-
if (!isCenter) {
|
|
271
|
-
_offset = moveOffset;
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
const _size = isVertical ? height : width;
|
|
275
|
-
const val = isVertical
|
|
276
|
-
? rect?.height - _size
|
|
277
|
-
: rect?.width - _size;
|
|
278
|
-
_offset =
|
|
279
|
-
moveOffset +
|
|
280
|
-
(active === childCount - 1 && !props.loop ? -val / 2 : val / 2);
|
|
281
|
-
}
|
|
282
|
-
target.style.transitionDuration = `${_swiper.current.moving ? 0 : props.duration}ms`;
|
|
283
|
-
target.style[isVertical ? 'height' : 'width'] = `${Number(size) * childCount}px`;
|
|
284
|
-
target.style[isVertical ? 'width' : 'height'] = `${isVertical ? width : height}px`;
|
|
285
|
-
target.style.transform = `translate3D${!isVertical ? `(${_offset}px,0,0)` : `(0,${_offset}px,0)`}`;
|
|
286
|
-
};
|
|
287
|
-
const onTouchStart = (e) => {
|
|
288
|
-
if (props.isPreventDefault)
|
|
289
|
-
e.preventDefault();
|
|
290
|
-
if (props.isStopPropagation)
|
|
291
|
-
e.stopPropagation();
|
|
292
|
-
if (!props.touchable)
|
|
293
|
-
return;
|
|
294
|
-
touchStart(e);
|
|
295
|
-
touch.touchTime = Date.now();
|
|
296
|
-
stopAutoPlay();
|
|
297
|
-
resettPosition();
|
|
298
|
-
};
|
|
299
|
-
const onTouchMove = (e) => {
|
|
300
|
-
if (props.touchable && _swiper.current.moving) {
|
|
301
|
-
touchMove(e);
|
|
302
|
-
if (touch.stateDirection === props.direction) {
|
|
303
|
-
move({
|
|
304
|
-
offset: touch.delta,
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
const onTouchEnd = (e) => {
|
|
310
|
-
if (!props.touchable || !_swiper.current.moving)
|
|
311
|
-
return;
|
|
312
|
-
const speed = touch.delta / (Date.now() - touch.touchTime);
|
|
313
|
-
const isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta) > +(size / 2).toFixed(2);
|
|
314
|
-
let pace = 0;
|
|
315
|
-
_swiper.current.moving = false;
|
|
316
|
-
if (isShouldMove && touch.stateDirection === props.direction) {
|
|
317
|
-
const offset = isVertical ? touch.offsetY : touch.offsetX;
|
|
318
|
-
if (props.loop) {
|
|
319
|
-
if (offset > 0) {
|
|
320
|
-
pace = touch.delta > 0 ? -1 : 1;
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
pace = 0;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
pace = -Math[touch.delta > 0 ? 'ceil' : 'floor'](touch.delta / size);
|
|
328
|
-
}
|
|
329
|
-
move({
|
|
330
|
-
pace,
|
|
331
|
-
isEmit: true,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
else if (touch.delta) {
|
|
335
|
-
move({ pace: 0 });
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
getStyle();
|
|
339
|
-
}
|
|
340
|
-
autoplay();
|
|
341
|
-
};
|
|
342
|
-
useEffect(() => {
|
|
343
|
-
_swiper.current.activePagination = (active + childCount) % childCount;
|
|
344
|
-
}, [active]);
|
|
345
|
-
const queryRect = (element) => {
|
|
346
|
-
return new Promise((resolve) => {
|
|
347
|
-
const query = createSelectorQuery();
|
|
348
|
-
query.select(`#${element.id}`) &&
|
|
349
|
-
query.select(`#${element.id}`).boundingClientRect();
|
|
350
|
-
query.exec((res) => {
|
|
351
|
-
resolve(res[0]);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
};
|
|
355
|
-
const init = async (active = +propSwiper.initPage) => {
|
|
356
|
-
const rect = await queryRect(container.current);
|
|
357
|
-
const _active = Math.max(Math.min(childCount - 1, active), 0);
|
|
358
|
-
const _width = propSwiper.width ? +propSwiper.width : rect?.width;
|
|
359
|
-
const _height = propSwiper.height ? +propSwiper.height : rect?.height;
|
|
360
|
-
size = isVertical ? _height : _width;
|
|
361
|
-
trackSize = childCount * Number(size);
|
|
362
|
-
const targetOffset = getOffset(_active);
|
|
363
|
-
_swiper.current.moving = true;
|
|
364
|
-
if (ready) {
|
|
365
|
-
_swiper.current.moving = false;
|
|
366
|
-
}
|
|
367
|
-
setRect(rect);
|
|
368
|
-
setActive(_active);
|
|
369
|
-
setWidth(_width);
|
|
370
|
-
setHeight(_height);
|
|
371
|
-
setOffset(targetOffset);
|
|
372
|
-
setReady(true);
|
|
373
|
-
};
|
|
374
|
-
useEffect(() => {
|
|
375
|
-
if (ready) {
|
|
376
|
-
getStyle();
|
|
377
|
-
}
|
|
378
|
-
}, [isVertical, width, height, offset, ready]);
|
|
379
|
-
useEffect(() => {
|
|
380
|
-
if (ready) {
|
|
381
|
-
stopAutoPlay();
|
|
382
|
-
autoplay();
|
|
383
|
-
}
|
|
384
|
-
return () => {
|
|
385
|
-
setReady(false);
|
|
386
|
-
};
|
|
387
|
-
}, [ready]);
|
|
388
|
-
useEffect(() => {
|
|
389
|
-
stopAutoPlay();
|
|
390
|
-
autoplay();
|
|
391
|
-
}, [children]);
|
|
392
|
-
useEffect(() => {
|
|
393
|
-
nextTick(() => {
|
|
394
|
-
init();
|
|
395
|
-
});
|
|
396
|
-
}, [propSwiper.initPage]);
|
|
397
|
-
useEffect(() => {
|
|
398
|
-
return () => {
|
|
399
|
-
stopAutoPlay();
|
|
400
|
-
};
|
|
401
|
-
}, []);
|
|
402
|
-
useReady(() => {
|
|
403
|
-
nextTick(() => {
|
|
404
|
-
init();
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
const itemStyle = (index) => {
|
|
408
|
-
const style = {};
|
|
409
|
-
const _direction = propSwiper.direction || direction;
|
|
410
|
-
const _size = size;
|
|
411
|
-
if (_size) {
|
|
412
|
-
style[_direction === 'horizontal' ? 'width' : 'height'] = `${_size}px`;
|
|
413
|
-
}
|
|
414
|
-
const offset = childOffset[index];
|
|
415
|
-
if (offset) {
|
|
416
|
-
style.transform = `translate3D${_direction === 'horizontal' ? `(${offset}px,0,0)` : `(0,${offset}px,0)`}`;
|
|
417
|
-
}
|
|
418
|
-
return style;
|
|
419
|
-
};
|
|
420
|
-
React.useImperativeHandle(ref, () => ({
|
|
421
|
-
to,
|
|
422
|
-
next,
|
|
423
|
-
prev,
|
|
424
|
-
resize,
|
|
425
|
-
}));
|
|
426
|
-
return (React.createElement(DataContext.Provider, { value: parent },
|
|
427
|
-
React.createElement("div", { className: `${classes} ${className}`, ref: container, ...rest, id: `container-${refRandomId}`, onTouchStart: onTouchStart, onTouchMove: onTouchMove, onTouchEnd: onTouchEnd,
|
|
428
|
-
// @ts-ignore
|
|
429
|
-
catchMove: isVertical },
|
|
430
|
-
React.createElement("div", { className: contentClass, ref: innerRef }, React.Children.map(childs, (child, index) => {
|
|
431
|
-
return (React.createElement("div", { className: b('item-wrapper'), style: itemStyle(index), key: index }, child));
|
|
432
|
-
})),
|
|
433
|
-
propSwiper.paginationVisible && !('pageContent' in propSwiper) ? (React.createElement("div", { className: classNames({
|
|
434
|
-
[`${b('pagination')}`]: true,
|
|
435
|
-
[`${b('pagination-vertical')}`]: isVertical,
|
|
436
|
-
}) }, React.Children.map(childs, (item, index) => {
|
|
437
|
-
return (React.createElement("i", { style: (active + childCount) % childCount === index
|
|
438
|
-
? {
|
|
439
|
-
backgroundColor: propSwiper.paginationColor,
|
|
440
|
-
}
|
|
441
|
-
: {
|
|
442
|
-
backgroundColor: propSwiper.paginationBgColor,
|
|
443
|
-
}, className: classNames({
|
|
444
|
-
active: (active + childCount) % childCount === index,
|
|
445
|
-
}), key: index }));
|
|
446
|
-
}))) : (React.createElement("div", null, pageContent)))));
|
|
447
|
-
});
|
|
448
|
-
Swiper.defaultProps = defaultProps;
|
|
449
|
-
Swiper.displayName = 'NutSwiper';
|
|
450
|
-
|
|
451
|
-
export { Swiper as S };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import { D as DataContext } from './UserContext-e8176108.js';
|
|
4
|
-
import { c as cn } from './bem-350c1702.js';
|
|
5
|
-
|
|
6
|
-
const defaultProps = {
|
|
7
|
-
direction: 'horizontal',
|
|
8
|
-
};
|
|
9
|
-
const SwiperItem = React.forwardRef((props, ref) => {
|
|
10
|
-
const _props = { ...defaultProps, ...props };
|
|
11
|
-
const { className, style, children, direction, size } = _props;
|
|
12
|
-
const parent = useContext(DataContext);
|
|
13
|
-
const b = cn('swiper-item');
|
|
14
|
-
const classes = classNames(b(''), className);
|
|
15
|
-
const getStyle = () => {
|
|
16
|
-
const style = {};
|
|
17
|
-
const _direction = parent?.propSwiper.direction || direction;
|
|
18
|
-
const _size = parent?.size || size;
|
|
19
|
-
if (_size) {
|
|
20
|
-
style[_direction === 'horizontal' ? 'width' : 'height'] = `${_size}px`;
|
|
21
|
-
}
|
|
22
|
-
return style;
|
|
23
|
-
};
|
|
24
|
-
return (React.createElement("div", { className: classes, style: { ...style, ...getStyle() } }, children));
|
|
25
|
-
});
|
|
26
|
-
SwiperItem.defaultProps = defaultProps;
|
|
27
|
-
SwiperItem.displayName = 'NutSwiperItem';
|
|
28
|
-
|
|
29
|
-
export { SwiperItem as S };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { C as ComponentDefaults } from './typings-d8491423.js';
|
|
3
|
-
import { u as usePropsValue } from './use-props-value-ae7ee726.js';
|
|
4
|
-
|
|
5
|
-
const defaultProps = {
|
|
6
|
-
...ComponentDefaults,
|
|
7
|
-
disabled: false,
|
|
8
|
-
activeText: '',
|
|
9
|
-
inactiveText: '',
|
|
10
|
-
};
|
|
11
|
-
const Switch = (props) => {
|
|
12
|
-
const { checked, defaultChecked, disabled, activeText, inactiveText, className, style, onChange, } = {
|
|
13
|
-
...defaultProps,
|
|
14
|
-
...props,
|
|
15
|
-
};
|
|
16
|
-
const classPrefix = 'nut-switch';
|
|
17
|
-
const [value, setValue] = usePropsValue({
|
|
18
|
-
value: checked,
|
|
19
|
-
defaultValue: defaultChecked,
|
|
20
|
-
});
|
|
21
|
-
const classes = () => {
|
|
22
|
-
return `${classPrefix} ${value ? 'switch-open' : 'switch-close'} ${disabled ? `${classPrefix}-disabled` : ''} ${`${classPrefix}-base`} ${className}`;
|
|
23
|
-
};
|
|
24
|
-
const onClick = (event) => {
|
|
25
|
-
if (disabled)
|
|
26
|
-
return;
|
|
27
|
-
onChange && onChange(!value, event);
|
|
28
|
-
setValue(!value);
|
|
29
|
-
};
|
|
30
|
-
return (React.createElement("div", { className: classes(), onClick: (e) => onClick(e), style: style },
|
|
31
|
-
React.createElement("div", { className: "switch-button" },
|
|
32
|
-
!value && React.createElement("div", { className: "close-line" }),
|
|
33
|
-
activeText && (React.createElement(React.Fragment, null, value ? (React.createElement("div", { className: `${classPrefix}__label open` }, activeText)) : (React.createElement("div", { className: `${classPrefix}__label close` }, inactiveText)))))));
|
|
34
|
-
};
|
|
35
|
-
Switch.defaultProps = defaultProps;
|
|
36
|
-
Switch.displayName = 'NutSwitch';
|
|
37
|
-
|
|
38
|
-
export { Switch as S };
|