@nutui/nutui-react-taro 1.4.4 → 1.4.5-beta.0
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 +15 -0
- package/dist/esm/Address.js +5 -5
- package/dist/esm/Audio.js +5 -5
- package/dist/esm/AvatarContext-7153ad2b.js +3 -1
- package/dist/esm/AvatarGroup.js +4 -4
- package/dist/esm/Calendar.js +5 -5
- package/dist/esm/CalendarItem.js +4 -4
- package/dist/esm/Card.js +4 -3
- package/dist/esm/Cell.js +2 -2
- package/dist/esm/ConfigProvider.js +3 -3
- package/dist/esm/CountDown.js +4 -4
- package/dist/esm/DatePicker.js +5 -5
- package/dist/esm/Dialog.js +4 -4
- package/dist/esm/Ellipsis.js +4 -4
- package/dist/esm/Empty.js +4 -4
- package/dist/esm/FixedNav.js +4 -4
- package/dist/esm/Form.js +4 -4
- package/dist/esm/FormItem.js +3 -3
- package/dist/esm/Grid.js +4 -4
- package/dist/esm/GridItem.js +4 -4
- package/dist/esm/Image.js +4 -4
- package/dist/esm/Infiniteloading.js +4 -4
- package/dist/esm/Input.js +4 -4
- package/dist/esm/MenuItem.js +4 -4
- package/dist/esm/NoticeBar.js +2 -2
- package/dist/esm/NumberKeyboard.js +4 -4
- package/dist/esm/Pagination.js +4 -4
- package/dist/esm/Picker.js +4 -4
- package/dist/esm/PullToRefresh.js +4 -4
- package/dist/esm/Range.js +4 -4
- package/dist/esm/SearchBar.js +4 -4
- package/dist/esm/ShortPassword.js +4 -4
- package/dist/esm/SideNavBar.js +4 -4
- package/dist/esm/Signature.js +4 -4
- package/dist/esm/Sticky.js +4 -4
- package/dist/esm/Table.js +4 -4
- package/dist/esm/Tag.js +3 -2
- package/dist/esm/TextArea.js +4 -4
- package/dist/esm/TimeDetail.js +4 -4
- package/dist/esm/TimePannel.js +4 -4
- package/dist/esm/TimeSelect.js +6 -6
- package/dist/esm/Uploader.js +4 -4
- package/dist/esm/UserContext-68f62e66.js +3 -1
- package/dist/esm/UserContext-b4181162.js +3 -1
- package/dist/esm/UserContext-be8097d2.js +3 -1
- package/dist/esm/VirtualList.js +6 -4
- package/dist/esm/WaterMark.js +4 -4
- package/dist/esm/actionsheet.taro-a58d3d12.js +45 -83
- package/dist/esm/address.taro-79cc7c96.js +461 -0
- package/dist/esm/animate.taro-b0e83dd5.js +32 -46
- package/dist/esm/animatingnumbers.taro-6f40a2e9.js +93 -134
- package/dist/esm/audio.taro-4fadc583.js +161 -0
- package/dist/esm/avatar.taro-85ced995.js +93 -119
- package/dist/esm/avatargroup-1d900174.js +34 -0
- package/dist/esm/backtop.taro-99107c30.js +39 -62
- package/dist/esm/badge.taro-fe9171ec.js +40 -58
- package/dist/esm/barrage.taro-0e157b5e.js +61 -91
- package/dist/esm/bem-893ad28d.js +3 -6
- package/dist/esm/button.taro-4ce133b9.js +87 -98
- package/dist/esm/calendar.taro-4ed72058.js +38 -0
- package/dist/esm/calendaritem.taro-1ebe428d.js +571 -0
- package/dist/esm/card.taro-39055e82.js +32 -0
- package/dist/esm/cascader.taro-d8cb1c3e.js +397 -636
- package/dist/esm/cell.taro-9a04a92e.js +64 -0
- package/dist/esm/cellgroup.taro-e094471c.js +18 -27
- package/dist/esm/checkbox.taro-0bda9796.js +160 -232
- package/dist/esm/circleprogress.taro-47db537c.js +99 -120
- package/dist/esm/col.taro-b61c7cba.js +33 -50
- package/dist/esm/collapse.taro-af58206c.js +73 -86
- package/dist/esm/collapseitem-ce1849d2.js +75 -139
- package/dist/esm/configprovider-5eea4f5d.js +19 -0
- package/dist/esm/configprovider.taro-26882dd2.js +42 -0
- package/dist/esm/countdown.taro-9e40de9c.js +225 -0
- package/dist/esm/datepicker.taro-7220e495.js +270 -0
- package/dist/esm/dialog.taro-1c03960e.js +123 -0
- package/dist/esm/divider.taro-5236fe6a.js +27 -27
- package/dist/esm/drag.taro-82b6b27a.js +99 -138
- package/dist/esm/elevator.taro-d7d65470.js +185 -259
- package/dist/esm/ellipsis.taro-49b6db0c.js +232 -0
- package/dist/esm/empty.taro-7bd813f9.js +62 -0
- package/dist/esm/fixednav.taro-5ad15202.js +53 -0
- package/dist/esm/form.taro-71d32671.js +179 -0
- package/dist/esm/formitem.taro-3089489b.js +89 -0
- package/dist/esm/grid.taro-e6decfce.js +58 -0
- package/dist/esm/grid.taro.context-39636af9.js +4 -2
- package/dist/esm/griditem.taro-4cade72e.js +90 -0
- package/dist/esm/icon-8dc4de10.js +43 -51
- package/dist/esm/icon.taro-1d0d4fb7.js +43 -51
- package/dist/esm/image.taro-e6dc5867.js +64 -0
- package/dist/esm/imagepreview.taro-3400ea03.js +158 -205
- package/dist/esm/index.taro-a36f96fb.js +149 -210
- package/dist/esm/indicator.taro-183ea169.js +29 -43
- package/dist/esm/infiniteloading.taro-6c2a2e95.js +142 -0
- package/dist/esm/input.taro-fd566407.js +243 -0
- package/dist/esm/inputnumber.taro-dc39b853.js +129 -177
- package/dist/esm/layout.taro-358f014f.js +6 -9
- package/dist/esm/menu.taro-4abed328.js +89 -132
- package/dist/esm/menuitem.taro-6e8b27c3.js +130 -0
- package/dist/esm/navbar.taro-c931c078.js +69 -105
- package/dist/esm/noticebar.taro-69ea7673.js +450 -0
- package/dist/esm/notify.taro-308e5892.js +66 -97
- package/dist/esm/numberkeyboard.taro-194519e4.js +158 -0
- package/dist/esm/nutui-react.es.js +44 -44
- package/dist/esm/offsetContext-bfb02c25.js +3 -1
- package/dist/esm/overlay.taro-98367bc1.js +59 -74
- package/dist/esm/pagination.taro-bb490de9.js +124 -0
- package/dist/esm/picker.taro-2a8ded7c.js +420 -0
- package/dist/esm/popover.taro-46d813e8.js +132 -222
- package/dist/esm/popup.taro-cb777e09.js +125 -178
- package/dist/esm/price.taro-8801462e.js +75 -86
- package/dist/esm/progress.taro-623bc807.js +84 -118
- package/dist/esm/pulltorefresh.taro-cab7b51c.js +221 -0
- package/dist/esm/range.taro-5d6ff217.js +332 -0
- package/dist/esm/rate.taro-10197384.js +64 -111
- package/dist/esm/row.taro-37a895de.js +38 -42
- package/dist/esm/searchbar.taro-839dd622.js +148 -0
- package/dist/esm/shortpassword.taro-182d46f7.js +111 -0
- package/dist/esm/sidenavbar.taro-006cf38b.js +35 -0
- package/dist/esm/sidenavbaritem.taro-fee11d26.js +9 -22
- package/dist/esm/signature.taro-33632585.js +143 -0
- package/dist/esm/skeleton.taro-853ce460.js +51 -88
- package/dist/esm/step.taro-1c94e067.js +49 -78
- package/dist/esm/steps.taro-acf205a0.js +21 -30
- package/dist/esm/sticky.taro-d0553f48.js +13 -0
- package/dist/esm/subsidenavbar.taro-f46b4c73.js +58 -75
- package/dist/esm/swipe.taro-83bc248f.js +164 -254
- package/dist/esm/swiper.taro-852f6615.js +424 -505
- package/dist/esm/swiperitem-86a3578a.js +20 -28
- package/dist/esm/switch.taro-bae2dca0.js +43 -64
- package/dist/esm/tabbar.taro-86cece39.js +47 -57
- package/dist/esm/tabbaritem.taro-8dfb8055.js +51 -79
- package/dist/esm/table.taro-cb4dd2c3.js +92 -0
- package/dist/esm/tabpane.taro-91cd6cf4.js +17 -22
- package/dist/esm/tabs.taro-e71875fa.js +121 -165
- package/dist/esm/tag.taro-00fe554d.js +89 -0
- package/dist/esm/textarea.taro-42600f8c.js +74 -0
- package/dist/esm/timedetail.taro-c5f564fd.js +44 -0
- package/dist/esm/timepannel.taro-29f9dd86.js +22 -0
- package/dist/esm/timeselect.taro-3ecce65d.js +133 -0
- package/dist/esm/toast.taro-0804b6b4.js +99 -137
- package/dist/esm/trendarrow.taro-5a7153e4.js +63 -90
- package/dist/esm/types/src/packages/cell/cell.taro.d.ts +0 -1
- package/dist/esm/types/src/packages/noticebar/noticebar.d.ts +5 -4
- package/dist/esm/types/src/packages/noticebar/noticebar.taro.d.ts +5 -4
- package/dist/esm/types/src/packages/uploader/uploader.d.ts +1 -1
- package/dist/esm/types/src/packages/virtuallist/virtuallist.taro.d.ts +13 -2
- package/dist/esm/typings-1c5f2628.js +7 -6
- package/dist/esm/uploader.taro-f80d76d9.js +392 -0
- package/dist/esm/useClientRect-bf69d7b3.js +5 -25
- package/dist/esm/useTouch-a2ea68c6.js +63 -93
- package/dist/esm/video-8a3518c5.js +59 -83
- package/dist/esm/virtuallist.taro-e3345ced.js +215 -0
- package/dist/esm/watermark.taro-cd9db98a.js +114 -0
- package/dist/esm/zh-CN-dfc384d0.js +128 -133
- 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.es.js +634 -5664
- package/dist/nutui.react.umd.js +634 -5664
- package/dist/packages/noticebar/noticebar.scss +17 -0
- package/dist/packages/radio/radio.scss +3 -1
- package/dist/packages/row/row.scss +2 -0
- package/dist/packages/searchbar/searchbar.scss +1 -1
- package/dist/packages/tag/tag.scss +13 -5
- package/dist/packages/virtuallist/virtuallist.scss +24 -0
- package/dist/style.css +1 -1
- package/dist/style.es.js +1 -1
- package/dist/styles/temp.scss +2340 -0
- package/dist/styles/theme-dark.scss +7 -0
- package/dist/styles/theme-default.scss +11 -0
- package/dist/styles/variables.scss +1945 -710
- package/dist/types/index.d.ts +16 -23
- package/package.json +9 -4
- package/dist/esm/address.taro-1e2aea24.js +0 -615
- package/dist/esm/audio.taro-fddcdfc0.js +0 -228
- package/dist/esm/avatargroup-f7f600ff.js +0 -42
- package/dist/esm/calendar.taro-72974415.js +0 -83
- package/dist/esm/calendaritem.taro-84e889eb.js +0 -580
- package/dist/esm/card.taro-a530dfb3.js +0 -61
- package/dist/esm/cell.taro-cf50c4f2.js +0 -109
- package/dist/esm/configprovider-c7d60e20.js +0 -18
- package/dist/esm/configprovider.taro-8bdb3a28.js +0 -50
- package/dist/esm/countdown.taro-d7dc8681.js +0 -246
- package/dist/esm/datepicker.taro-7199f521.js +0 -304
- package/dist/esm/dialog.taro-f54cfbf0.js +0 -187
- package/dist/esm/ellipsis.taro-c0de6ff4.js +0 -309
- package/dist/esm/empty.taro-dbc66496.js +0 -81
- package/dist/esm/fixednav.taro-9e759320.js +0 -97
- package/dist/esm/form.taro-880014b1.js +0 -181
- package/dist/esm/formitem.taro-3695f4a7.js +0 -136
- package/dist/esm/grid.taro-c2cc12d6.js +0 -81
- package/dist/esm/griditem.taro-892153cd.js +0 -122
- package/dist/esm/image.taro-c30973d5.js +0 -105
- package/dist/esm/infiniteloading.taro-b5ddf3cc.js +0 -188
- package/dist/esm/input.taro-104130c1.js +0 -361
- package/dist/esm/menuitem.taro-216e9f7d.js +0 -193
- package/dist/esm/noticebar.taro-94002898.js +0 -368
- package/dist/esm/numberkeyboard.taro-5e8f0ddf.js +0 -245
- package/dist/esm/pagination.taro-9925ffab.js +0 -169
- package/dist/esm/picker.taro-3b5cc054.js +0 -540
- package/dist/esm/pulltorefresh.taro-f26a20dd.js +0 -302
- package/dist/esm/range.taro-c41e9b90.js +0 -469
- package/dist/esm/searchbar.taro-01ed4ea4.js +0 -236
- package/dist/esm/shortpassword.taro-3a3bf412.js +0 -190
- package/dist/esm/sidenavbar.taro-06026f31.js +0 -66
- package/dist/esm/signature.taro-17648cac.js +0 -192
- package/dist/esm/sticky.taro-36013e97.js +0 -16
- package/dist/esm/table.taro-adda6622.js +0 -139
- package/dist/esm/tag.taro-bd900990.js +0 -104
- package/dist/esm/textarea.taro-83d5fe73.js +0 -102
- package/dist/esm/timedetail.taro-105f5380.js +0 -68
- package/dist/esm/timepannel.taro-c66c63dd.js +0 -30
- package/dist/esm/timeselect.taro-fc7ec6ee.js +0 -172
- package/dist/esm/uploader.taro-a1edf38f.js +0 -529
- package/dist/esm/virtuallist.taro-4add61c3.js +0 -315
- package/dist/esm/watermark.taro-323d1cf3.js +0 -132
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import React__default, { useRef, useState, useMemo, useEffect } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { I as Icon } from './icon.taro-1d0d4fb7.js';
|
|
4
|
+
import { c as cn } from './bem-893ad28d.js';
|
|
5
|
+
import { g as getRectByTaro } from './useClientRect-bf69d7b3.js';
|
|
6
|
+
import { C as ComponentDefaults } from './typings-1c5f2628.js';
|
|
7
|
+
|
|
8
|
+
const defaultProps = {
|
|
9
|
+
...ComponentDefaults,
|
|
10
|
+
// 滚动方向 across 横向 vertical 纵向
|
|
11
|
+
direction: 'across',
|
|
12
|
+
list: [],
|
|
13
|
+
standTime: 1000,
|
|
14
|
+
complexAm: false,
|
|
15
|
+
height: 40,
|
|
16
|
+
text: '',
|
|
17
|
+
closeMode: false,
|
|
18
|
+
wrapable: false,
|
|
19
|
+
leftIcon: '',
|
|
20
|
+
color: '',
|
|
21
|
+
background: '',
|
|
22
|
+
delay: 1,
|
|
23
|
+
scrollable: null,
|
|
24
|
+
speed: 50,
|
|
25
|
+
};
|
|
26
|
+
const NoticeBar = (props) => {
|
|
27
|
+
const { children, className, style, direction, list, standTime, complexAm, height, text, closeMode, wrapable, leftIcon, color, background, delay, scrollable, speed, rightIcon, close, click, onClose, onClick, onClickItem, iconClassPrefix, iconFontClassName, } = {
|
|
28
|
+
...defaultProps,
|
|
29
|
+
...props,
|
|
30
|
+
};
|
|
31
|
+
const wrap = useRef(null);
|
|
32
|
+
const content = useRef(null);
|
|
33
|
+
const [showNoticeBar, SetShowNoticeBar] = useState(true);
|
|
34
|
+
const scrollList = useRef([]);
|
|
35
|
+
const [wrapWidth, SetWrapWidth] = useState(0);
|
|
36
|
+
const [firstRound, SetFirstRound] = useState(true);
|
|
37
|
+
const [duration, SetDuration] = useState(0);
|
|
38
|
+
const [offsetWidth, SetOffsetW] = useState(0);
|
|
39
|
+
const [animationClass, SetAnimationClass] = useState('');
|
|
40
|
+
const [animate, SetAnimate] = useState(false);
|
|
41
|
+
const [distance, SetDistance] = useState(0);
|
|
42
|
+
const [timer, SetTimer] = useState(0);
|
|
43
|
+
const [isCanScroll, SetIsCanScroll] = useState(null);
|
|
44
|
+
const isVertical = direction === 'vertical';
|
|
45
|
+
const [rect, setRect] = useState(null);
|
|
46
|
+
let active = 0;
|
|
47
|
+
const [vLeftIcon, setLeftIcon] = useState('');
|
|
48
|
+
const [ready, setReady] = useState(false);
|
|
49
|
+
const container = useRef(null);
|
|
50
|
+
const innerRef = useRef(null);
|
|
51
|
+
const _swiper = useRef({
|
|
52
|
+
moving: false,
|
|
53
|
+
autoplayTimer: null,
|
|
54
|
+
width: 0,
|
|
55
|
+
height: 0,
|
|
56
|
+
offset: 0,
|
|
57
|
+
size: 0,
|
|
58
|
+
});
|
|
59
|
+
const [childOffset, setChildOffset] = useState([]);
|
|
60
|
+
const [offset, setOffset] = useState(0);
|
|
61
|
+
const { childs, childCount } = useMemo(() => {
|
|
62
|
+
let childCount = 0;
|
|
63
|
+
const childs = React__default.Children.map(children, (child) => {
|
|
64
|
+
if (!React__default.isValidElement(child))
|
|
65
|
+
return null;
|
|
66
|
+
childCount++;
|
|
67
|
+
return child;
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
childs,
|
|
71
|
+
childCount,
|
|
72
|
+
};
|
|
73
|
+
}, [children]);
|
|
74
|
+
let trackSize = childCount * Number(height);
|
|
75
|
+
const minOffset = (() => {
|
|
76
|
+
if (rect) {
|
|
77
|
+
const base = isVertical ? rect.height : rect.width;
|
|
78
|
+
return base - Number(height) * childCount;
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
81
|
+
})();
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (isVertical) {
|
|
84
|
+
// 兼容老版本无左侧Icon问题
|
|
85
|
+
if (leftIcon !== '') {
|
|
86
|
+
setLeftIcon(leftIcon);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
setLeftIcon('close');
|
|
90
|
+
}
|
|
91
|
+
if (children) {
|
|
92
|
+
scrollList.current = [].concat(childs);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
scrollList.current = [].concat(list);
|
|
96
|
+
// startRollEasy()
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
startRollEasy();
|
|
99
|
+
}, Number(standTime));
|
|
100
|
+
}
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
complexAm && startRoll();
|
|
103
|
+
}, Number(standTime));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
initScrollWrap();
|
|
107
|
+
}
|
|
108
|
+
return () => {
|
|
109
|
+
// 销毁事件
|
|
110
|
+
clearInterval(timer);
|
|
111
|
+
startRoll();
|
|
112
|
+
startRollEasy();
|
|
113
|
+
};
|
|
114
|
+
}, []);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
initScrollWrap();
|
|
117
|
+
}, [text]);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (list && list.length) {
|
|
120
|
+
scrollList.current = [].concat(list);
|
|
121
|
+
}
|
|
122
|
+
}, [list]);
|
|
123
|
+
const initScrollWrap = (value) => {
|
|
124
|
+
if (showNoticeBar === false) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
setTimeout(async () => {
|
|
128
|
+
if (!wrap.current || !content.current) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const warpRes = await getRectByTaro(wrap.current);
|
|
132
|
+
const contentRes = await getRectByTaro(content.current);
|
|
133
|
+
const wrapW = warpRes.width;
|
|
134
|
+
const offsetW = contentRes.width;
|
|
135
|
+
const canScroll = scrollable == null ? offsetW > wrapW : scrollable;
|
|
136
|
+
SetIsCanScroll(canScroll);
|
|
137
|
+
if (canScroll) {
|
|
138
|
+
SetWrapWidth(wrapW);
|
|
139
|
+
SetOffsetW(offsetW);
|
|
140
|
+
SetDuration(offsetW / speed);
|
|
141
|
+
SetAnimationClass('play');
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
SetAnimationClass('');
|
|
145
|
+
}
|
|
146
|
+
}, 0);
|
|
147
|
+
};
|
|
148
|
+
const handleClick = (event) => {
|
|
149
|
+
click && click(event);
|
|
150
|
+
onClick && onClick(event);
|
|
151
|
+
};
|
|
152
|
+
const onClickIcon = (event) => {
|
|
153
|
+
event.stopPropagation();
|
|
154
|
+
SetShowNoticeBar(!closeMode);
|
|
155
|
+
close && close(event);
|
|
156
|
+
onClose && onClose(event);
|
|
157
|
+
};
|
|
158
|
+
const onAnimationEnd = () => {
|
|
159
|
+
SetFirstRound(false);
|
|
160
|
+
setTimeout(() => {
|
|
161
|
+
SetDuration((offsetWidth + wrapWidth) / speed);
|
|
162
|
+
SetAnimationClass('play-infinite');
|
|
163
|
+
}, 0);
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* 滚动方式一
|
|
167
|
+
*/
|
|
168
|
+
const startRollEasy = () => {
|
|
169
|
+
showhorseLamp();
|
|
170
|
+
const time = height / speed / 4 < 1
|
|
171
|
+
? Number((height / speed / 4).toFixed(1)) * 1000
|
|
172
|
+
: ~~(height / speed / 4) * 1000;
|
|
173
|
+
const timerCurr = window.setInterval(showhorseLamp, time + Number(standTime));
|
|
174
|
+
SetTimer(timerCurr);
|
|
175
|
+
};
|
|
176
|
+
const showhorseLamp = () => {
|
|
177
|
+
SetAnimate(true);
|
|
178
|
+
const time = height / speed / 4 < 1
|
|
179
|
+
? Number((height / speed / 4).toFixed(1)) * 1000
|
|
180
|
+
: ~~(height / speed / 4) * 1000;
|
|
181
|
+
setTimeout(() => {
|
|
182
|
+
scrollList.current.push(scrollList.current[0]);
|
|
183
|
+
scrollList.current.shift();
|
|
184
|
+
SetAnimate(false);
|
|
185
|
+
}, time);
|
|
186
|
+
};
|
|
187
|
+
const startRoll = () => {
|
|
188
|
+
const timerCurr = window.setInterval(() => {
|
|
189
|
+
const chunk = 100;
|
|
190
|
+
for (let i = 0; i < chunk; i++) {
|
|
191
|
+
scroll(i, !(i < chunk - 1));
|
|
192
|
+
}
|
|
193
|
+
}, Number(standTime) + 100 * speed);
|
|
194
|
+
SetTimer(timerCurr);
|
|
195
|
+
};
|
|
196
|
+
const scroll = (n, last) => {
|
|
197
|
+
SetAnimate(true);
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
let long = distance;
|
|
200
|
+
long -= height / 100;
|
|
201
|
+
SetDistance(long);
|
|
202
|
+
if (last) {
|
|
203
|
+
scrollList.current.push(scrollList.current[0]);
|
|
204
|
+
scrollList.current.shift();
|
|
205
|
+
SetDistance(0);
|
|
206
|
+
SetAnimate(false);
|
|
207
|
+
}
|
|
208
|
+
}, n * speed);
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* 点击滚动单元
|
|
212
|
+
*/
|
|
213
|
+
const handleClickIcon = (event) => {
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
SetShowNoticeBar(!closeMode);
|
|
216
|
+
close && close(event);
|
|
217
|
+
onClose && onClose(event);
|
|
218
|
+
};
|
|
219
|
+
const iconShow = () => {
|
|
220
|
+
if (leftIcon === 'close' || vLeftIcon === 'close') {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return true;
|
|
224
|
+
};
|
|
225
|
+
const iconBg = () => {
|
|
226
|
+
let iconBg = '';
|
|
227
|
+
if (leftIcon) {
|
|
228
|
+
iconBg = leftIcon;
|
|
229
|
+
}
|
|
230
|
+
return iconBg;
|
|
231
|
+
};
|
|
232
|
+
const isEllipsis = () => {
|
|
233
|
+
if (isCanScroll == null) {
|
|
234
|
+
return wrapable;
|
|
235
|
+
}
|
|
236
|
+
return !isCanScroll && !wrapable;
|
|
237
|
+
};
|
|
238
|
+
const contentStyle = {
|
|
239
|
+
animationDelay: `${firstRound ? delay : 0}s`,
|
|
240
|
+
animationDuration: `${duration}s`,
|
|
241
|
+
transform: `translateX(${firstRound ? 0 : `${wrapWidth}px`})`,
|
|
242
|
+
};
|
|
243
|
+
const barStyle = {
|
|
244
|
+
color,
|
|
245
|
+
background,
|
|
246
|
+
height: isVertical ? `${height}px` : '',
|
|
247
|
+
};
|
|
248
|
+
const duringTime = height / speed / 4 < 1
|
|
249
|
+
? Number((height / speed / 4).toFixed(1))
|
|
250
|
+
: ~~(height / speed / 4);
|
|
251
|
+
const noDuring = height / speed < 1 ? (height / speed).toFixed(1) : ~~(height / speed);
|
|
252
|
+
const horseLampStyle = {
|
|
253
|
+
transform: complexAm ? `translateY(${distance}px)` : '',
|
|
254
|
+
transition: animate
|
|
255
|
+
? `all ${duringTime === 0 ? noDuring : duringTime}s`
|
|
256
|
+
: '',
|
|
257
|
+
marginTop: animate ? `-${height}px` : '',
|
|
258
|
+
};
|
|
259
|
+
const b = cn('noticebar');
|
|
260
|
+
const noticebarClass = classNames({
|
|
261
|
+
'nut-noticebar-page': true,
|
|
262
|
+
withicon: closeMode,
|
|
263
|
+
close: closeMode,
|
|
264
|
+
wrapable,
|
|
265
|
+
});
|
|
266
|
+
/**
|
|
267
|
+
* 垂直自定义滚动方式
|
|
268
|
+
*/
|
|
269
|
+
const init = (active = +0) => {
|
|
270
|
+
if (!container?.current)
|
|
271
|
+
return;
|
|
272
|
+
setTimeout(async () => {
|
|
273
|
+
const rects = await getRectByTaro(container?.current);
|
|
274
|
+
const _active = Math.max(Math.min(childCount - 1, active), 0);
|
|
275
|
+
const _height = rects.height;
|
|
276
|
+
trackSize = childCount * Number(_height);
|
|
277
|
+
const targetOffset = getOffset(_active);
|
|
278
|
+
_swiper.current.moving = true;
|
|
279
|
+
if (ready) {
|
|
280
|
+
_swiper.current.moving = false;
|
|
281
|
+
}
|
|
282
|
+
active = _active;
|
|
283
|
+
setRect(rects);
|
|
284
|
+
setOffset(targetOffset);
|
|
285
|
+
setReady(true);
|
|
286
|
+
}, 0);
|
|
287
|
+
};
|
|
288
|
+
useEffect(() => {
|
|
289
|
+
if (ready) {
|
|
290
|
+
stopAutoPlay();
|
|
291
|
+
autoplay();
|
|
292
|
+
}
|
|
293
|
+
return () => {
|
|
294
|
+
setReady(false);
|
|
295
|
+
};
|
|
296
|
+
}, [ready]);
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
if (isVertical && children) {
|
|
299
|
+
setTimeout(() => {
|
|
300
|
+
init();
|
|
301
|
+
stopAutoPlay();
|
|
302
|
+
autoplay();
|
|
303
|
+
}, 300);
|
|
304
|
+
}
|
|
305
|
+
}, [children, container?.current]);
|
|
306
|
+
// 清除定时器
|
|
307
|
+
const stopAutoPlay = () => {
|
|
308
|
+
clearTimeout(_swiper.current.autoplayTimer);
|
|
309
|
+
_swiper.current.autoplayTimer = null;
|
|
310
|
+
};
|
|
311
|
+
// 定时轮播
|
|
312
|
+
const autoplay = () => {
|
|
313
|
+
if (childCount <= 1)
|
|
314
|
+
return;
|
|
315
|
+
stopAutoPlay();
|
|
316
|
+
_swiper.current.autoplayTimer = setTimeout(() => {
|
|
317
|
+
next();
|
|
318
|
+
autoplay();
|
|
319
|
+
}, Number(standTime) + 100 * speed);
|
|
320
|
+
};
|
|
321
|
+
// 切换方法
|
|
322
|
+
const move = ({ pace = 0, offset = 0 }) => {
|
|
323
|
+
if (childCount <= 1)
|
|
324
|
+
return;
|
|
325
|
+
const targetActive = getActive(pace);
|
|
326
|
+
// 父级容器偏移量
|
|
327
|
+
const targetOffset = getOffset(targetActive, offset);
|
|
328
|
+
// 如果循环,调整开头结尾图片位置
|
|
329
|
+
if (Array.isArray(children) && children[0] && targetOffset !== minOffset) {
|
|
330
|
+
const rightBound = targetOffset < minOffset;
|
|
331
|
+
childOffset[0] = rightBound ? trackSize : 0;
|
|
332
|
+
}
|
|
333
|
+
if (Array.isArray(children) &&
|
|
334
|
+
children[childCount - 1] &&
|
|
335
|
+
targetOffset !== 0) {
|
|
336
|
+
const leftBound = targetOffset > 0;
|
|
337
|
+
childOffset[childCount - 1] = leftBound ? -trackSize : 0;
|
|
338
|
+
}
|
|
339
|
+
setChildOffset(childOffset);
|
|
340
|
+
active = targetActive;
|
|
341
|
+
setOffset(targetOffset);
|
|
342
|
+
getStyle(targetOffset);
|
|
343
|
+
};
|
|
344
|
+
// 下一页
|
|
345
|
+
const next = () => {
|
|
346
|
+
resettPosition();
|
|
347
|
+
requestFrame(() => {
|
|
348
|
+
requestFrame(() => {
|
|
349
|
+
_swiper.current.moving = false;
|
|
350
|
+
move({
|
|
351
|
+
pace: 1,
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
const handleItemClick = (event, value) => {
|
|
357
|
+
onClickItem && onClickItem(event, value);
|
|
358
|
+
};
|
|
359
|
+
const getStyle = (moveOffset = offset) => {
|
|
360
|
+
const target = innerRef.current;
|
|
361
|
+
let _offset = 0;
|
|
362
|
+
// 容器高度-元素高度
|
|
363
|
+
const val = rect.height - height;
|
|
364
|
+
_offset = moveOffset + Number(active === childCount - 1 && val / 2);
|
|
365
|
+
target.style.transitionDuration = `${_swiper.current.moving ? 0 : standTime}ms`;
|
|
366
|
+
target.style.height = `${Number(height) * childCount}px`;
|
|
367
|
+
target.style.transform = `translate3D(0,${_offset}px,0)`;
|
|
368
|
+
};
|
|
369
|
+
// 无缝滚动第一个元素位移控制
|
|
370
|
+
const itemStyle = (index) => {
|
|
371
|
+
const style = {};
|
|
372
|
+
if (height) {
|
|
373
|
+
style.height = `${height}px`;
|
|
374
|
+
style.lineHeight = `${height}px`;
|
|
375
|
+
}
|
|
376
|
+
const offset = childOffset[index];
|
|
377
|
+
if (offset) {
|
|
378
|
+
style.transform = `translate3D(0,${offset}px,0)`;
|
|
379
|
+
}
|
|
380
|
+
return style;
|
|
381
|
+
};
|
|
382
|
+
// 确定当前active 元素
|
|
383
|
+
const getActive = (pace) => {
|
|
384
|
+
if (pace) {
|
|
385
|
+
const _active = active + pace;
|
|
386
|
+
return range(_active, -1, childCount);
|
|
387
|
+
}
|
|
388
|
+
return active;
|
|
389
|
+
};
|
|
390
|
+
// 计算位移
|
|
391
|
+
const getOffset = (active, offset = 0) => {
|
|
392
|
+
const currentPosition = active * Number(height);
|
|
393
|
+
const targetOffset = offset - currentPosition;
|
|
394
|
+
return targetOffset;
|
|
395
|
+
};
|
|
396
|
+
// 浏览器 帧 事件
|
|
397
|
+
const requestFrame = (fn) => {
|
|
398
|
+
window.requestAnimationFrame.call(window, fn);
|
|
399
|
+
};
|
|
400
|
+
// 取值 方法
|
|
401
|
+
const range = (num, min, max) => {
|
|
402
|
+
return Math.min(Math.max(num, min), max);
|
|
403
|
+
};
|
|
404
|
+
// 重置首尾位置信息
|
|
405
|
+
const resettPosition = () => {
|
|
406
|
+
_swiper.current.moving = true;
|
|
407
|
+
if (active <= -1) {
|
|
408
|
+
move({ pace: childCount });
|
|
409
|
+
}
|
|
410
|
+
if (active >= childCount) {
|
|
411
|
+
move({ pace: -childCount });
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
useEffect(() => {
|
|
415
|
+
return () => {
|
|
416
|
+
stopAutoPlay();
|
|
417
|
+
};
|
|
418
|
+
}, []);
|
|
419
|
+
return (React__default.createElement("div", { className: `${b()} ${className || ''}`, style: style },
|
|
420
|
+
showNoticeBar && direction === 'across' ? (React__default.createElement("div", { className: noticebarClass, style: barStyle, onClick: handleClick },
|
|
421
|
+
iconShow() ? (React__default.createElement("div", { className: "left-icon", style: { backgroundImage: `url(${iconBg() || ''})` } }, !iconBg() ? (React__default.createElement(Icon, { classPrefix: iconClassPrefix, fontClassName: iconFontClassName, name: "notice", size: "16", color: color })) : null)) : null,
|
|
422
|
+
React__default.createElement("div", { ref: wrap, className: "wrap" },
|
|
423
|
+
React__default.createElement("div", { ref: content, className: `content ${animationClass} ${isEllipsis() ? 'nut-ellipsis' : ''}`, style: contentStyle, onAnimationEnd: onAnimationEnd },
|
|
424
|
+
children,
|
|
425
|
+
text)),
|
|
426
|
+
closeMode || rightIcon ? (React__default.createElement("div", { className: "right-icon", onClick: onClickIcon },
|
|
427
|
+
React__default.createElement(Icon, { classPrefix: iconClassPrefix, fontClassName: iconFontClassName, name: rightIcon || 'close', color: color }))) : null)) : null,
|
|
428
|
+
showNoticeBar && scrollList.current.length > 0 && isVertical ? (React__default.createElement("div", { className: "nut-noticebar-vertical", style: barStyle, ref: container, onClick: handleClick },
|
|
429
|
+
iconShow() ? (React__default.createElement("div", { className: "left-icon", style: { backgroundImage: `url(${iconBg() || ''})` } }, !iconBg() ? (React__default.createElement(Icon, { classPrefix: iconClassPrefix, fontClassName: iconFontClassName, name: "notice", size: "16", color: color })) : null)) : null,
|
|
430
|
+
children ? (React__default.createElement(React__default.Fragment, null,
|
|
431
|
+
React__default.createElement("div", { className: "nut-noticebar__inner", ref: innerRef }, scrollList.current.map((item, index) => {
|
|
432
|
+
return (React__default.createElement("div", { className: "scroll-inner ", style: itemStyle(index), key: index, onClick: (e) => {
|
|
433
|
+
handleItemClick(e, item);
|
|
434
|
+
} }, item));
|
|
435
|
+
})))) : (React__default.createElement("div", { className: "horseLamp_list", style: horseLampStyle }, scrollList.current.map((item, index) => {
|
|
436
|
+
return (
|
|
437
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
438
|
+
React__default.createElement("div", { className: "horseLamp_list_item", style: { height }, key: index, onClick: (e) => {
|
|
439
|
+
handleItemClick(e, item);
|
|
440
|
+
} }, item));
|
|
441
|
+
}))),
|
|
442
|
+
React__default.createElement("div", { className: "go", onClick: (e) => {
|
|
443
|
+
handleClickIcon(e);
|
|
444
|
+
} }, rightIcon ||
|
|
445
|
+
(closeMode ? (React__default.createElement(Icon, { classPrefix: iconClassPrefix, fontClassName: iconFontClassName, name: rightIcon || 'close', color: color, size: "11px" })) : null)))) : null));
|
|
446
|
+
};
|
|
447
|
+
NoticeBar.defaultProps = defaultProps;
|
|
448
|
+
NoticeBar.displayName = 'NutNoticeBar';
|
|
449
|
+
|
|
450
|
+
export { NoticeBar as N };
|
|
@@ -1,106 +1,75 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["id", "children", "style", "msg", "color", "background", "type", "className", "position", "isWrapTeleport", "visible", "duration", "onClosed", "onClick"];
|
|
5
|
-
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; }
|
|
6
|
-
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; }
|
|
7
1
|
import React__default, { useState, useEffect } from 'react';
|
|
8
2
|
import classNames from 'classnames';
|
|
9
3
|
import { CSSTransition } from 'react-transition-group';
|
|
10
4
|
import { c as cn } from './bem-893ad28d.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
|
|
6
|
+
const defaultProps = {
|
|
7
|
+
id: '',
|
|
8
|
+
msg: '',
|
|
9
|
+
color: '',
|
|
10
|
+
duration: 3000,
|
|
11
|
+
type: 'danger',
|
|
12
|
+
className: '',
|
|
13
|
+
background: '',
|
|
14
|
+
position: 'top',
|
|
15
|
+
isWrapTeleport: true,
|
|
16
|
+
visible: false,
|
|
17
|
+
onClosed: () => { },
|
|
18
|
+
onClick: () => { },
|
|
24
19
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
element && element.parentNode && element.parentNode.removeChild(element);
|
|
77
|
-
}
|
|
78
|
-
onClosed();
|
|
79
|
-
};
|
|
80
|
-
cn('notify');
|
|
81
|
-
var classes = classNames(_defineProperty({
|
|
82
|
-
'popup-top': position === 'top',
|
|
83
|
-
'popup-bottom': position === 'bottom',
|
|
84
|
-
'nut-notify': true
|
|
85
|
-
}, "nut-notify--".concat(type), true));
|
|
86
|
-
return React__default.createElement(React__default.Fragment, null, React__default.createElement(CSSTransition, {
|
|
87
|
-
"in": showNotify,
|
|
88
|
-
timeout: 300,
|
|
89
|
-
classNames: "fade",
|
|
90
|
-
unmountOnExit: true,
|
|
91
|
-
appear: true,
|
|
92
|
-
position: position,
|
|
93
|
-
isWrapTeleport: isWrapTeleport,
|
|
94
|
-
id: id
|
|
95
|
-
}, React__default.createElement("div", {
|
|
96
|
-
className: "".concat(classes, " ").concat(className),
|
|
97
|
-
style: {
|
|
98
|
-
color: "".concat(color || ''),
|
|
99
|
-
background: "".concat(background || '')
|
|
100
|
-
},
|
|
101
|
-
onClick: clickHandle
|
|
102
|
-
}, children || msg)));
|
|
20
|
+
const Notify = (props) => {
|
|
21
|
+
const { id, children, style, msg, color, background, type, className, position, isWrapTeleport, visible, duration, onClosed, onClick, ...rest } = { ...defaultProps, ...props };
|
|
22
|
+
let timer;
|
|
23
|
+
const [showNotify, SetShow] = useState(false);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (visible) {
|
|
26
|
+
SetShow(true);
|
|
27
|
+
show();
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
hide();
|
|
31
|
+
}
|
|
32
|
+
}, [visible]);
|
|
33
|
+
const clickHandle = () => {
|
|
34
|
+
onClick();
|
|
35
|
+
};
|
|
36
|
+
const show = () => {
|
|
37
|
+
clearTimer();
|
|
38
|
+
if (duration) {
|
|
39
|
+
timer = window.setTimeout(() => {
|
|
40
|
+
hide();
|
|
41
|
+
}, duration);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const clearTimer = () => {
|
|
45
|
+
if (timer) {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
timer = null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const hide = () => {
|
|
51
|
+
SetShow(false);
|
|
52
|
+
if (id) {
|
|
53
|
+
const element = document.getElementById(id);
|
|
54
|
+
element && element.parentNode && element.parentNode.removeChild(element);
|
|
55
|
+
}
|
|
56
|
+
onClosed();
|
|
57
|
+
};
|
|
58
|
+
cn('notify');
|
|
59
|
+
const classes = classNames({
|
|
60
|
+
'popup-top': position === 'top',
|
|
61
|
+
'popup-bottom': position === 'bottom',
|
|
62
|
+
'nut-notify': true,
|
|
63
|
+
[`nut-notify--${type}`]: true,
|
|
64
|
+
});
|
|
65
|
+
return (React__default.createElement(React__default.Fragment, null,
|
|
66
|
+
React__default.createElement(CSSTransition, { in: showNotify, timeout: 300, classNames: "fade", unmountOnExit: true, appear: true, position: position, isWrapTeleport: isWrapTeleport, id: id },
|
|
67
|
+
React__default.createElement("div", { className: `${classes} ${className}`, style: {
|
|
68
|
+
color: `${color || ''}`,
|
|
69
|
+
background: `${background || ''}`,
|
|
70
|
+
}, onClick: clickHandle }, children || msg))));
|
|
103
71
|
};
|
|
104
72
|
Notify.defaultProps = defaultProps;
|
|
105
73
|
Notify.displayName = 'NutNotify';
|
|
74
|
+
|
|
106
75
|
export { Notify as N };
|