@nutui/nutui-react-taro 1.5.2 → 1.5.3-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.
Files changed (232) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/esm/ActionSheet.js +14 -90
  3. package/dist/esm/Address.js +21 -620
  4. package/dist/esm/Animate.js +7 -53
  5. package/dist/esm/AnimatingNumbers.js +7 -125
  6. package/dist/esm/Audio.js +19 -264
  7. package/dist/esm/Avatar.js +11 -130
  8. package/dist/esm/{AvatarContext-15733596.js → AvatarContext-c96afdcc.js} +3 -1
  9. package/dist/esm/AvatarGroup.js +11 -41
  10. package/dist/esm/BackTop.js +10 -138
  11. package/dist/esm/Badge.js +9 -71
  12. package/dist/esm/Barrage.js +8 -97
  13. package/dist/esm/Button.js +9 -108
  14. package/dist/esm/Calendar.js +20 -128
  15. package/dist/esm/CalendarItem.js +12 -674
  16. package/dist/esm/Card.js +11 -61
  17. package/dist/esm/Cascader.js +16 -671
  18. package/dist/esm/Cell.js +9 -101
  19. package/dist/esm/CellGroup.js +5 -2
  20. package/dist/esm/Checkbox.js +7 -5
  21. package/dist/esm/CheckboxGroup.js +8 -111
  22. package/dist/esm/CircleProgress.js +8 -114
  23. package/dist/esm/Col.js +7 -57
  24. package/dist/esm/Collapse.js +7 -97
  25. package/dist/esm/CollapseItem.js +8 -146
  26. package/dist/esm/ConfigProvider.js +8 -187
  27. package/dist/esm/CountDown.js +9 -247
  28. package/dist/esm/DatePicker.js +25 -309
  29. package/dist/esm/Dialog.js +17 -296
  30. package/dist/esm/Divider.js +7 -34
  31. package/dist/esm/Drag.js +7 -118
  32. package/dist/esm/Elevator.js +8 -234
  33. package/dist/esm/Ellipsis.js +10 -176
  34. package/dist/esm/Empty.js +8 -79
  35. package/dist/esm/FixedNav.js +14 -103
  36. package/dist/esm/Form.js +10 -215
  37. package/dist/esm/FormItem.js +10 -3
  38. package/dist/esm/Grid.js +11 -81
  39. package/dist/esm/GridItem.js +13 -123
  40. package/dist/esm/Icon.js +5 -2
  41. package/dist/esm/Image.js +11 -169
  42. package/dist/esm/ImagePreview.js +19 -225
  43. package/dist/esm/Indicator.js +7 -50
  44. package/dist/esm/Infiniteloading.js +14 -215
  45. package/dist/esm/Input.js +12 -362
  46. package/dist/esm/InputNumber.js +9 -275
  47. package/dist/esm/Layout.js +5 -13
  48. package/dist/esm/Menu.js +10 -153
  49. package/dist/esm/MenuItem.js +15 -175
  50. package/dist/esm/NavBar.js +9 -114
  51. package/dist/esm/NoticeBar.js +10 -568
  52. package/dist/esm/Notify.js +8 -234
  53. package/dist/esm/NumberKeyboard.js +17 -247
  54. package/dist/esm/Overlay.js +6 -2
  55. package/dist/esm/Pagination.js +9 -168
  56. package/dist/esm/Picker.js +22 -494
  57. package/dist/esm/Popover.js +12 -223
  58. package/dist/esm/Popup.js +13 -193
  59. package/dist/esm/Price.js +6 -84
  60. package/dist/esm/Progress.js +9 -122
  61. package/dist/esm/PullToRefresh.js +13 -276
  62. package/dist/esm/Radio.js +8 -4
  63. package/dist/esm/RadioGroup.js +7 -120
  64. package/dist/esm/Range.js +15 -406
  65. package/dist/esm/Rate.js +9 -121
  66. package/dist/esm/Row.js +7 -49
  67. package/dist/esm/SearchBar.js +12 -235
  68. package/dist/esm/ShortPassword.js +17 -191
  69. package/dist/esm/SideNavBar.js +19 -57
  70. package/dist/esm/SideNavBarItem.js +5 -24
  71. package/dist/esm/Signature.js +13 -153
  72. package/dist/esm/Skeleton.js +12 -98
  73. package/dist/esm/Step.js +10 -87
  74. package/dist/esm/Steps.js +8 -38
  75. package/dist/esm/Sticky.js +11 -190
  76. package/dist/esm/SubSideNavBar.js +6 -78
  77. package/dist/esm/Swipe.js +10 -230
  78. package/dist/esm/Swiper.js +9 -490
  79. package/dist/esm/SwiperItem.js +8 -36
  80. package/dist/esm/Switch.js +6 -71
  81. package/dist/esm/TabPane.js +5 -2
  82. package/dist/esm/Tabbar.js +6 -68
  83. package/dist/esm/TabbarItem.js +9 -78
  84. package/dist/esm/Table.js +12 -140
  85. package/dist/esm/Tabs.js +8 -5
  86. package/dist/esm/Tag.js +10 -110
  87. package/dist/esm/TextArea.js +9 -148
  88. package/dist/esm/TimeDetail.js +9 -67
  89. package/dist/esm/TimePannel.js +9 -29
  90. package/dist/esm/TimeSelect.js +19 -171
  91. package/dist/esm/Toast.js +7 -268
  92. package/dist/esm/TrendArrow.js +7 -99
  93. package/dist/esm/Uploader.js +17 -566
  94. package/dist/esm/{UserContext-101ad4a4.js → UserContext-0aac9a82.js} +3 -1
  95. package/dist/esm/{UserContext-2629d479.js → UserContext-e402e1a6.js} +3 -1
  96. package/dist/esm/{UserContext-b33bcf21.js → UserContext-e8176108.js} +3 -1
  97. package/dist/esm/Video.js +7 -90
  98. package/dist/esm/VirtualList.js +9 -313
  99. package/dist/esm/WaterMark.js +11 -111
  100. package/dist/esm/actionsheet.taro-e6a51446.js +53 -0
  101. package/dist/esm/address.taro-3a9b6396.js +461 -0
  102. package/dist/esm/animate.taro-fb7986d6.js +40 -0
  103. package/dist/esm/animatingnumbers.taro-03e5d61d.js +104 -0
  104. package/dist/esm/audio.taro-87ec8bf2.js +161 -0
  105. package/dist/esm/avatar.taro-3676f38f.js +103 -0
  106. package/dist/esm/avatargroup-f3574510.js +34 -0
  107. package/dist/esm/backtop.taro-66394a36.js +48 -0
  108. package/dist/esm/badge.taro-a4e59c11.js +52 -0
  109. package/dist/esm/barrage.taro-0495a1b2.js +94 -0
  110. package/dist/esm/{bem-3b438e61.js → bem-350c1702.js} +3 -6
  111. package/dist/esm/button.taro-9244d065.js +100 -0
  112. package/dist/esm/calendar.taro-670842ea.js +65 -0
  113. package/dist/esm/calendaritem.taro-2a603571.js +787 -0
  114. package/dist/esm/can-use-dom-3eeb5af4.js +6 -0
  115. package/dist/esm/card.taro-e4c76dad.js +33 -0
  116. package/dist/esm/cascader.taro-eb1fb011.js +438 -0
  117. package/dist/esm/cell.taro-a10a74d3.js +64 -0
  118. package/dist/esm/cellgroup.taro-abe501bc.js +25 -0
  119. package/dist/esm/checkbox.taro-6120e3e3.js +171 -0
  120. package/dist/esm/circleprogress.taro-79854448.js +109 -0
  121. package/dist/esm/col.taro-53eed3cc.js +41 -0
  122. package/dist/esm/collapse.taro-1a9e4ba2.js +83 -0
  123. package/dist/esm/collapseitem-4d0bc55d.js +83 -0
  124. package/dist/esm/configprovider-67d19d3a.js +19 -0
  125. package/dist/esm/configprovider.taro-8d71eb49.js +42 -0
  126. package/dist/esm/countdown.taro-5b17c607.js +226 -0
  127. package/dist/esm/datepicker.taro-6e9b4b8f.js +275 -0
  128. package/dist/esm/dialog.taro-a3267d29.js +118 -0
  129. package/dist/esm/divider.taro-26d1d8b4.js +35 -0
  130. package/dist/esm/drag.taro-79bb8744.js +110 -0
  131. package/dist/esm/elevator.taro-6019669e.js +178 -0
  132. package/dist/esm/ellipsis.taro-f15f26da.js +241 -0
  133. package/dist/esm/empty.taro-04ae4389.js +62 -0
  134. package/dist/esm/fixednav.taro-1f05acaf.js +53 -0
  135. package/dist/esm/form.taro-0c8e7a39.js +179 -0
  136. package/dist/esm/formitem.taro-190a3326.js +89 -0
  137. package/dist/esm/get-scroll-parent-b4a07e65.js +25 -0
  138. package/dist/esm/grid.taro-3503b82c.js +61 -0
  139. package/dist/esm/{grid.context-2ee27d95.js → grid.taro.context-c2bbfb4f.js} +4 -2
  140. package/dist/esm/griditem.taro-cdb3f119.js +98 -0
  141. package/dist/esm/icon-296a1bec.js +63 -0
  142. package/dist/esm/icon.taro-296a1bec.js +63 -0
  143. package/dist/esm/image.taro-142cf512.js +64 -0
  144. package/dist/esm/imagepreview.taro-c50bb0a3.js +167 -0
  145. package/dist/esm/index-5bcb0ff8.js +7 -0
  146. package/dist/esm/indicator.taro-cba8b010.js +37 -0
  147. package/dist/esm/infiniteloading.taro-183bccbf.js +144 -0
  148. package/dist/esm/input.taro-97af6c96.js +240 -0
  149. package/dist/esm/inputnumber.taro-91f65d17.js +130 -0
  150. package/dist/esm/layout.taro-9046d093.js +11 -0
  151. package/dist/esm/menu.taro-7e4038a1.js +99 -0
  152. package/dist/esm/menuitem.taro-96cc4f15.js +130 -0
  153. package/dist/esm/navbar.taro-777c4705.js +79 -0
  154. package/dist/esm/noticebar.taro-4a23cdee.js +448 -0
  155. package/dist/esm/notify.taro-e17c6f82.js +75 -0
  156. package/dist/esm/numberkeyboard.taro-1bc24744.js +159 -0
  157. package/dist/esm/nutui-react.es.js +119 -94
  158. package/dist/esm/offsetContext-c2a746fa.js +5 -0
  159. package/dist/esm/overlay.taro-21e87fb1.js +69 -0
  160. package/dist/esm/pagination.taro-715a173b.js +124 -0
  161. package/dist/esm/picker.taro-9ad1b7c5.js +473 -0
  162. package/dist/esm/popover.taro-ad5e76ea.js +156 -0
  163. package/dist/esm/popup.taro-01676bff.js +137 -0
  164. package/dist/esm/price.taro-776ed16e.js +83 -0
  165. package/dist/esm/progress.taro-f0ce38e9.js +90 -0
  166. package/dist/esm/pulltorefresh.taro-a294f656.js +181 -0
  167. package/dist/esm/radio.taro-a6eff96c.js +168 -0
  168. package/dist/esm/range.taro-d8fc7656.js +332 -0
  169. package/dist/esm/rate.taro-6cdf03bd.js +75 -0
  170. package/dist/esm/row.taro-f64d4a13.js +46 -0
  171. package/dist/esm/searchbar.taro-0c25927b.js +152 -0
  172. package/dist/esm/shortpassword.taro-9ee034f7.js +111 -0
  173. package/dist/esm/sidenavbar.taro-c307b35e.js +35 -0
  174. package/dist/esm/sidenavbaritem.taro-5a7965d0.js +12 -0
  175. package/dist/esm/signature.taro-ec4e713b.js +143 -0
  176. package/dist/esm/skeleton.taro-76faf63f.js +62 -0
  177. package/dist/esm/step.taro-b7903e8c.js +59 -0
  178. package/dist/esm/steps.taro-c82d2252.js +30 -0
  179. package/dist/esm/sticky.taro-218bda37.js +138 -0
  180. package/dist/esm/subsidenavbar.taro-69cb9752.js +63 -0
  181. package/dist/esm/supports-passive-c85ef996.js +18 -0
  182. package/dist/esm/swipe.taro-ea35f07f.js +177 -0
  183. package/dist/esm/swiper.taro-7a94e211.js +451 -0
  184. package/dist/esm/swiperitem-c9e3d0d5.js +29 -0
  185. package/dist/esm/switch.taro-34ca8228.js +50 -0
  186. package/dist/esm/tabbar.taro-9acfc2fa.js +59 -0
  187. package/dist/esm/tabbaritem.taro-bf517487.js +58 -0
  188. package/dist/esm/table.taro-91fc0c01.js +93 -0
  189. package/dist/esm/tabpane.taro-4ca340ef.js +23 -0
  190. package/dist/esm/tabs.taro-6a7524a4.js +140 -0
  191. package/dist/esm/tag.taro-23ba0834.js +92 -0
  192. package/dist/esm/textarea.taro-442e7350.js +94 -0
  193. package/dist/esm/timedetail.taro-5b2f2269.js +44 -0
  194. package/dist/esm/timepannel.taro-d6e40180.js +22 -0
  195. package/dist/esm/timeselect.taro-a07036f4.js +133 -0
  196. package/dist/esm/toast.taro-d6c14811.js +109 -0
  197. package/dist/esm/trendarrow.taro-b8c5ccd9.js +73 -0
  198. package/dist/esm/typings-b9828dba.js +9 -0
  199. package/dist/esm/uploader.taro-587e6bf3.js +492 -0
  200. package/dist/esm/useClientRect-1f8ed1fe.js +18 -0
  201. package/dist/esm/useTouch-db24bb5c.js +69 -0
  202. package/dist/esm/video-f1be8a91.js +67 -0
  203. package/dist/esm/virtuallist.taro-f0b0270d.js +214 -0
  204. package/dist/esm/watermark.taro-9ce2ae37.js +114 -0
  205. package/dist/esm/zh-CN-c779e6c1.js +131 -0
  206. package/dist/locales/base.js +1 -1
  207. package/dist/locales/en-US.js +1 -1
  208. package/dist/locales/id-ID.js +1 -1
  209. package/dist/locales/zh-CN.js +1 -1
  210. package/dist/locales/zh-TW.js +1 -1
  211. package/dist/locales/zh-UG.js +1 -1
  212. package/dist/nutui.react.mjs +13030 -14863
  213. package/dist/nutui.react.umd.js +13029 -14864
  214. package/dist/style.mjs +1 -1
  215. package/dist/types/index.d.ts +176 -183
  216. package/package.json +1 -1
  217. package/dist/esm/cellgroup-fcc72767.js +0 -34
  218. package/dist/esm/checkbox-44e13cd0.js +0 -137
  219. package/dist/esm/date-c7aad4c0.js +0 -97
  220. package/dist/esm/formitem-8a73a5fb.js +0 -157
  221. package/dist/esm/get-scroll-parent-5f85dee8.js +0 -24
  222. package/dist/esm/icon-4ef1581c.js +0 -70
  223. package/dist/esm/index-030b7245.js +0 -11
  224. package/dist/esm/offsetContext-3ab00d40.js +0 -16
  225. package/dist/esm/overlay-de6c79d5.js +0 -83
  226. package/dist/esm/radio-9f141e6b.js +0 -118
  227. package/dist/esm/render-bbebb760.js +0 -79
  228. package/dist/esm/tabpane-01075e6c.js +0 -29
  229. package/dist/esm/tabs-e1b4e4b1.js +0 -181
  230. package/dist/esm/typings-f27b58f4.js +0 -8
  231. package/dist/esm/useClientRect-56bb675b.js +0 -39
  232. package/dist/esm/useTouch-cf73a407.js +0 -99
@@ -0,0 +1,226 @@
1
+ import React__default, { useState, useRef, useImperativeHandle, useEffect } from 'react';
2
+ import { c as cn } from './bem-350c1702.js';
3
+ import { u as useConfig } from './configprovider.taro-8d71eb49.js';
4
+
5
+ const defaultProps = {
6
+ paused: false,
7
+ startTime: Date.now(),
8
+ endTime: Date.now(),
9
+ millisecond: false,
10
+ format: 'HH:mm:ss',
11
+ autoStart: true,
12
+ time: 0,
13
+ destroy: false,
14
+ };
15
+ const InternalCountDown = (props, ref) => {
16
+ useConfig();
17
+ const { paused, startTime, endTime, millisecond, format, autoStart, time, destroy, className, style, onEnd, onPaused, onRestart, onUpdate, children, ...rest } = { ...defaultProps, ...props };
18
+ const b = cn('countdown');
19
+ const [restTimeStamp, setRestTime] = useState(0);
20
+ const stateRef = useRef({
21
+ pauseTime: 0,
22
+ curr: 0,
23
+ isPaused: paused,
24
+ isIninted: false,
25
+ timer: 0,
26
+ restTime: 0,
27
+ counting: !paused && autoStart,
28
+ handleEndTime: Date.now(),
29
+ diffTime: 0, // 设置了 startTime 时,与 date.now() 的差异
30
+ });
31
+ // 时间戳转换 或 获取当前时间的时间戳
32
+ const getTimeStamp = (timeStr) => {
33
+ if (!timeStr)
34
+ return Date.now();
35
+ let t = timeStr;
36
+ t = t > 0 ? +t : t.toString().replace(/-/g, '/');
37
+ return new Date(t).getTime();
38
+ };
39
+ // 倒计时 interval
40
+ const initTime = () => {
41
+ stateRef.current.handleEndTime = endTime;
42
+ stateRef.current.diffTime = Date.now() - getTimeStamp(startTime); // 时间差
43
+ if (!stateRef.current.counting)
44
+ stateRef.current.counting = true;
45
+ tick();
46
+ };
47
+ const tick = () => {
48
+ stateRef.current.timer = requestAnimationFrame(() => {
49
+ if (stateRef.current.counting) {
50
+ const currentTime = Date.now() - stateRef.current.diffTime;
51
+ const remainTime = Math.max(stateRef.current.handleEndTime - currentTime, 0);
52
+ stateRef.current.restTime = remainTime;
53
+ setRestTime(remainTime);
54
+ if (!remainTime) {
55
+ stateRef.current.counting = false;
56
+ pause();
57
+ onEnd && onEnd();
58
+ }
59
+ if (remainTime > 0) {
60
+ tick();
61
+ }
62
+ }
63
+ });
64
+ };
65
+ // 将倒计时剩余时间格式化 参数: t 时间戳 type custom 自定义类型
66
+ const formatRemainTime = (t, type) => {
67
+ const ts = t;
68
+ const rest = {
69
+ d: 0,
70
+ h: 0,
71
+ m: 0,
72
+ s: 0,
73
+ ms: 0,
74
+ };
75
+ const SECOND = 1000;
76
+ const MINUTE = 60 * SECOND;
77
+ const HOUR = 60 * MINUTE;
78
+ const DAY = 24 * HOUR;
79
+ if (ts > 0) {
80
+ rest.d = ts >= SECOND ? Math.floor(ts / DAY) : 0;
81
+ rest.h = Math.floor((ts % DAY) / HOUR);
82
+ rest.m = Math.floor((ts % HOUR) / MINUTE);
83
+ rest.s = Math.floor((ts % MINUTE) / SECOND);
84
+ rest.ms = Math.floor(ts % SECOND);
85
+ }
86
+ return type === 'custom' ? rest : parseFormat({ ...rest });
87
+ };
88
+ const parseFormat = (time) => {
89
+ const { d } = time;
90
+ let { h, m, s, ms } = time;
91
+ let formatCache = format;
92
+ if (formatCache.includes('DD')) {
93
+ formatCache = formatCache.replace('DD', padZero(d));
94
+ }
95
+ else {
96
+ h += Number(d) * 24;
97
+ }
98
+ if (formatCache.includes('HH')) {
99
+ formatCache = formatCache.replace('HH', padZero(h));
100
+ }
101
+ else {
102
+ m += Number(h) * 60;
103
+ }
104
+ if (formatCache.includes('mm')) {
105
+ formatCache = formatCache.replace('mm', padZero(m));
106
+ }
107
+ else {
108
+ s += Number(m) * 60;
109
+ }
110
+ if (formatCache.includes('ss')) {
111
+ formatCache = formatCache.replace('ss', padZero(s));
112
+ }
113
+ else {
114
+ ms += Number(s) * 1000;
115
+ }
116
+ if (formatCache.includes('S')) {
117
+ const msC = padZero(ms, 3).toString();
118
+ if (formatCache.includes('SSS')) {
119
+ formatCache = formatCache.replace('SSS', msC);
120
+ }
121
+ else if (formatCache.includes('SS')) {
122
+ formatCache = formatCache.replace('SS', msC.slice(0, 2));
123
+ }
124
+ else if (formatCache.includes('S')) {
125
+ formatCache = formatCache.replace('SS', msC.slice(0, 1));
126
+ }
127
+ }
128
+ return formatCache;
129
+ };
130
+ const padZero = (num, length = 2) => {
131
+ num += '';
132
+ while (num.length < length) {
133
+ num = `0${num}`;
134
+ }
135
+ return num.toString();
136
+ };
137
+ // 暂定
138
+ const pause = () => {
139
+ cancelAnimationFrame(stateRef.current.timer);
140
+ stateRef.current.counting = false;
141
+ onPaused && onPaused(stateRef.current.restTime);
142
+ };
143
+ useImperativeHandle(ref, () => ({
144
+ start: () => {
145
+ if (!stateRef.current.counting && !autoStart) {
146
+ stateRef.current.counting = true;
147
+ stateRef.current.handleEndTime =
148
+ Date.now() + Number(stateRef.current.restTime);
149
+ tick();
150
+ onRestart && onRestart(stateRef.current.restTime);
151
+ }
152
+ },
153
+ pause: () => {
154
+ cancelAnimationFrame(stateRef.current.timer);
155
+ stateRef.current.counting = false;
156
+ onPaused && onPaused(stateRef.current.restTime);
157
+ },
158
+ reset: () => {
159
+ if (!autoStart) {
160
+ pause();
161
+ stateRef.current.restTime = time;
162
+ setRestTime(time);
163
+ }
164
+ },
165
+ }));
166
+ // 监听值变更
167
+ useEffect(() => {
168
+ const tranTime = formatRemainTime(stateRef.current.restTime, 'custom');
169
+ onUpdate && onUpdate(tranTime);
170
+ }, [restTimeStamp]);
171
+ // 监听暂停
172
+ useEffect(() => {
173
+ if (stateRef.current.isIninted) {
174
+ if (paused) {
175
+ if (stateRef.current.counting) {
176
+ pause();
177
+ }
178
+ }
179
+ else {
180
+ if (!stateRef.current.counting) {
181
+ stateRef.current.counting = true;
182
+ stateRef.current.handleEndTime =
183
+ Date.now() + Number(stateRef.current.restTime);
184
+ tick();
185
+ }
186
+ onRestart && onRestart(stateRef.current.restTime);
187
+ }
188
+ }
189
+ }, [paused]);
190
+ // 监听开始结束时间变更
191
+ useEffect(() => {
192
+ if (stateRef.current.isIninted) {
193
+ initTime();
194
+ }
195
+ }, [endTime, startTime]);
196
+ // 初始化
197
+ useEffect(() => {
198
+ if (autoStart) {
199
+ initTime();
200
+ }
201
+ else {
202
+ stateRef.current.restTime = time;
203
+ setRestTime(time);
204
+ }
205
+ if (!stateRef.current.isIninted) {
206
+ stateRef.current.isIninted = true;
207
+ }
208
+ return componentWillUnmount;
209
+ }, []);
210
+ const componentWillUnmount = () => {
211
+ destroy && cancelAnimationFrame(stateRef.current.timer);
212
+ };
213
+ const renderTime = (() => {
214
+ return formatRemainTime(stateRef.current.restTime);
215
+ })();
216
+ return (React__default.createElement("div", { className: `${b()} ${className || ''}`, style: { ...style }, ...rest }, children || (React__default.createElement("div", { className: b('block'),
217
+ // eslint-disable-next-line react/no-danger
218
+ dangerouslySetInnerHTML: {
219
+ __html: `${renderTime}`,
220
+ } }))));
221
+ };
222
+ const CountDown = React__default.forwardRef(InternalCountDown);
223
+ CountDown.defaultProps = defaultProps;
224
+ CountDown.displayName = 'NutCountDown';
225
+
226
+ export { CountDown as C };
@@ -0,0 +1,275 @@
1
+ import React__default, { useState, useRef, useEffect } from 'react';
2
+ import { P as Picker } from './picker.taro-9ad1b7c5.js';
3
+ import { u as useConfig } from './configprovider-67d19d3a.js';
4
+ import { View } from '@tarojs/components';
5
+
6
+ const currentYear = new Date().getFullYear();
7
+ const defaultProps = {
8
+ modelValue: null,
9
+ visible: false,
10
+ title: '',
11
+ type: 'date',
12
+ isShowChinese: false,
13
+ threeDimensional: true,
14
+ minuteStep: 1,
15
+ minDate: new Date(currentYear - 10, 0, 1),
16
+ maxDate: new Date(currentYear + 10, 11, 31),
17
+ };
18
+ const DatePicker = (props) => {
19
+ const { minDate, maxDate, type, isShowChinese, minuteStep, modelValue, visible, title, formatter, onCloseDatePicker, onConfirmDatePicker, filter, onChange, threeDimensional, className, style, ...rest } = {
20
+ ...defaultProps,
21
+ ...props,
22
+ };
23
+ const { locale } = useConfig();
24
+ const [show, setShow] = useState(false);
25
+ const [currentDate, setCurrentDate] = useState(modelValue);
26
+ const [defaultValue, setDefaultValue] = useState([]);
27
+ const [listData, setListData] = useState([]);
28
+ const pickerRef = useRef(null);
29
+ const isDate = (val) => {
30
+ return (Object.prototype.toString.call(val) === '[object Date]' &&
31
+ !Number.isNaN(val.getTime()));
32
+ };
33
+ const datepickerLang = locale.datepicker;
34
+ const zhCNType = {
35
+ day: datepickerLang.day,
36
+ year: datepickerLang.year,
37
+ month: datepickerLang.month,
38
+ hour: datepickerLang.hour,
39
+ minute: datepickerLang.min,
40
+ seconds: datepickerLang.seconds,
41
+ };
42
+ const formatValue = (value) => {
43
+ let cvalue = value;
44
+ if (!cvalue || (cvalue && !isDate(cvalue))) {
45
+ cvalue = minDate;
46
+ }
47
+ let timestmp = Math.max(cvalue.getTime(), minDate.getTime());
48
+ timestmp = Math.min(timestmp, maxDate.getTime());
49
+ return new Date(timestmp);
50
+ };
51
+ function getMonthEndDay(year, month) {
52
+ return new Date(year, month, 0).getDate();
53
+ }
54
+ const getBoundary = (type, value) => {
55
+ const boundary = type === 'min' ? minDate : maxDate;
56
+ const year = boundary.getFullYear();
57
+ let month = 1;
58
+ let date = 1;
59
+ let hour = 0;
60
+ let minute = 0;
61
+ if (type === 'max') {
62
+ month = 12;
63
+ date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1);
64
+ hour = 23;
65
+ minute = 59;
66
+ }
67
+ const seconds = minute;
68
+ if (value.getFullYear() === year) {
69
+ month = boundary.getMonth() + 1;
70
+ if (value.getMonth() + 1 === month) {
71
+ date = boundary.getDate();
72
+ if (value.getDate() === date) {
73
+ hour = boundary.getHours();
74
+ if (value.getHours() === hour) {
75
+ minute = boundary.getMinutes();
76
+ }
77
+ }
78
+ }
79
+ }
80
+ return {
81
+ [`${type}Year`]: year,
82
+ [`${type}Month`]: month,
83
+ [`${type}Date`]: date,
84
+ [`${type}Hour`]: hour,
85
+ [`${type}Minute`]: minute,
86
+ [`${type}Seconds`]: seconds,
87
+ };
88
+ };
89
+ const ranges = (date) => {
90
+ const curDate = date || currentDate;
91
+ if (!curDate)
92
+ return [];
93
+ const { maxYear, maxDate, maxMonth, maxHour, maxMinute, maxSeconds } = getBoundary('max', curDate);
94
+ const { minYear, minDate, minMonth, minHour, minMinute, minSeconds } = getBoundary('min', curDate);
95
+ let result = [
96
+ {
97
+ type: 'year',
98
+ range: [minYear, maxYear],
99
+ },
100
+ {
101
+ type: 'month',
102
+ range: [minMonth, maxMonth],
103
+ },
104
+ {
105
+ type: 'day',
106
+ range: [minDate, maxDate],
107
+ },
108
+ {
109
+ type: 'hour',
110
+ range: [minHour, maxHour],
111
+ },
112
+ {
113
+ type: 'minute',
114
+ range: [minMinute, maxMinute],
115
+ },
116
+ {
117
+ type: 'seconds',
118
+ range: [minSeconds, maxSeconds],
119
+ },
120
+ ];
121
+ switch (type.toLocaleLowerCase()) {
122
+ case 'date':
123
+ result = result.slice(0, 3);
124
+ break;
125
+ case 'datetime':
126
+ result = result.slice(0, 5);
127
+ break;
128
+ case 'time':
129
+ result = result.slice(3, 6);
130
+ break;
131
+ case 'year-month':
132
+ result = result.slice(0, 2);
133
+ break;
134
+ case 'hour-minutes':
135
+ result = result.slice(3, 5);
136
+ break;
137
+ case 'month-day':
138
+ result = result.slice(1, 3);
139
+ break;
140
+ case 'datehour':
141
+ result = result.slice(0, 4);
142
+ break;
143
+ }
144
+ return result;
145
+ };
146
+ const updateChooseValueCustmer = (index, selectedValue, cacheValueData) => {
147
+ if (['date', 'datetime', 'datehour', 'month-day', 'year-month'].includes(type.toLocaleLowerCase())) {
148
+ const formatDate = [];
149
+ selectedValue.forEach((item) => {
150
+ formatDate.push(item);
151
+ });
152
+ if (type.toLocaleLowerCase() === 'month-day' && formatDate.length < 3) {
153
+ formatDate.unshift(new Date(modelValue || minDate || maxDate).getFullYear());
154
+ }
155
+ if (type.toLocaleLowerCase() === 'year-month' && formatDate.length < 3) {
156
+ formatDate.push(new Date(modelValue || minDate || maxDate).getDate());
157
+ }
158
+ const year = Number(formatDate[0]);
159
+ const month = Number(formatDate[1]) - 1;
160
+ const day = Math.min(Number(formatDate[2]), getMonthEndDay(Number(formatDate[0]), Number(formatDate[1])));
161
+ let date = null;
162
+ if (type.toLocaleLowerCase() === 'date' ||
163
+ type.toLocaleLowerCase() === 'month-day' ||
164
+ type.toLocaleLowerCase() === 'year-month') {
165
+ date = new Date(year, month, day);
166
+ }
167
+ else if (type.toLocaleLowerCase() === 'datetime') {
168
+ date = new Date(year, month, day, Number(formatDate[3]), Number(formatDate[4]));
169
+ }
170
+ else if (type.toLocaleLowerCase() === 'datehour') {
171
+ date = new Date(year, month, day, Number(formatDate[3]));
172
+ }
173
+ const isEqual = currentDate?.getTime() === date?.getTime();
174
+ date &&
175
+ isDate(date) &&
176
+ !isEqual &&
177
+ setCurrentDate(formatValue(date));
178
+ }
179
+ props.onChange && props.onChange(index, selectedValue, cacheValueData);
180
+ };
181
+ const padZero = (num, targetLength = 2) => {
182
+ let str = `${num}`;
183
+ while (str.length < targetLength) {
184
+ str = `0${str}`;
185
+ }
186
+ return str;
187
+ };
188
+ const formatterOption = (type, value) => {
189
+ let fOption = null;
190
+ if (formatter) {
191
+ fOption = formatter(type, {
192
+ text: padZero(value, 2),
193
+ value: padZero(value, 2),
194
+ });
195
+ }
196
+ else {
197
+ const padMin = padZero(value, 2);
198
+ const fatter = isShowChinese ? zhCNType[type] : '';
199
+ fOption = { text: padMin + fatter, value: padMin };
200
+ }
201
+ return fOption;
202
+ };
203
+ const generateValue = (min, max, val, type, columnIndex) => {
204
+ let cmin = min;
205
+ const arr = [];
206
+ let index = 0;
207
+ while (cmin <= max) {
208
+ arr.push(formatterOption(type, cmin));
209
+ if (type === 'minute') {
210
+ cmin += minuteStep;
211
+ }
212
+ else {
213
+ cmin++;
214
+ }
215
+ if (cmin <= val) {
216
+ index++;
217
+ }
218
+ }
219
+ defaultValue[columnIndex] = arr[index].value;
220
+ setDefaultValue([...defaultValue]);
221
+ if (props.filter && props.filter(type, arr)) {
222
+ return props.filter(type, arr);
223
+ }
224
+ return arr;
225
+ };
226
+ const getDateIndex = (type) => {
227
+ if (!currentDate)
228
+ return 0;
229
+ let d = 0;
230
+ if (type === 'year') {
231
+ d = currentDate.getFullYear();
232
+ }
233
+ else if (type === 'month') {
234
+ d = currentDate.getMonth() + 1;
235
+ }
236
+ else if (type === 'day') {
237
+ d = currentDate.getDate();
238
+ }
239
+ else if (type === 'hour') {
240
+ d = currentDate.getHours();
241
+ }
242
+ else if (type === 'minute') {
243
+ d = currentDate.getMinutes();
244
+ }
245
+ else if (type === 'seconds') {
246
+ d = currentDate.getSeconds();
247
+ }
248
+ return d;
249
+ };
250
+ const columns = (date) => {
251
+ const val = ranges(date).map((res, columnIndex) => {
252
+ return generateValue(res.range[0], res.range[1], getDateIndex(res.type), res.type, columnIndex);
253
+ });
254
+ return val || [];
255
+ };
256
+ useEffect(() => {
257
+ setCurrentDate(formatValue(modelValue));
258
+ }, []);
259
+ useEffect(() => {
260
+ setCurrentDate(formatValue(modelValue));
261
+ }, [modelValue]);
262
+ useEffect(() => {
263
+ setShow(visible);
264
+ }, [visible]);
265
+ useEffect(() => {
266
+ if (currentDate) {
267
+ setListData(columns());
268
+ }
269
+ }, [currentDate]);
270
+ return (React__default.createElement(View, { className: `nut-datepicker ${className || ''}`, style: style, ...rest, catchMove: true }, listData.length > 0 && (React__default.createElement(Picker, { title: title, isVisible: show, listData: listData, onClose: onCloseDatePicker, defaultValueData: defaultValue, onConfirm: (values, options) => onConfirmDatePicker && onConfirmDatePicker(values, options), onChange: (index, value, list) => updateChooseValueCustmer(index, value, list), threeDimensional: threeDimensional, ref: pickerRef }))));
271
+ };
272
+ DatePicker.defaultProps = defaultProps;
273
+ DatePicker.displayName = 'NutDatePicker';
274
+
275
+ export { DatePicker as D };
@@ -0,0 +1,118 @@
1
+ import * as React from 'react';
2
+ import React__default, { forwardRef } from 'react';
3
+ import classNames from 'classnames';
4
+ import { B as Button } from './button.taro-9244d065.js';
5
+ import { View } from '@tarojs/components';
6
+ import { CSSTransition } from 'react-transition-group';
7
+ import { u as useConfig } from './configprovider.taro-8d71eb49.js';
8
+
9
+ const Content = (props) => {
10
+ const { visible, title, footer, textAlign, footerDirection, onClickSelf, children, } = props;
11
+ let headerNode;
12
+ if (title) {
13
+ headerNode = React__default.createElement("div", { className: "nut-dialog__header" }, title);
14
+ }
15
+ let footerNode;
16
+ if (footer) {
17
+ footerNode = (React__default.createElement("div", { className: classNames('nut-dialog__footer', {
18
+ [footerDirection]: footerDirection,
19
+ }) }, footer));
20
+ }
21
+ const handleClick = () => {
22
+ onClickSelf && onClickSelf();
23
+ };
24
+ return (React__default.createElement("div", { className: "nut-dialog__outer", onClick: handleClick },
25
+ React__default.createElement("div", { className: "nut-dialog", style: { display: visible ? 'flex' : 'none' } },
26
+ headerNode,
27
+ React__default.createElement("div", { className: "nut-dialog__content", style: { textAlign } },
28
+ React__default.createElement("div", null, children)),
29
+ footerNode)));
30
+ };
31
+ Content.displayName = 'NutContent';
32
+
33
+ function Mask(props) {
34
+ return React.createElement("div", { className: "nut-dialog__mask" });
35
+ }
36
+
37
+ const DialogWrap = (props) => {
38
+ const { className, style, visible, mask, closeOnClickOverlay, lockScroll, onClosed, onCancel, } = props;
39
+ const handleClick = (e) => {
40
+ if (closeOnClickOverlay && visible && e.target === e.currentTarget) {
41
+ onClosed?.();
42
+ onCancel?.();
43
+ lockScroll && document.body.classList.remove('nut-overflow-hidden');
44
+ }
45
+ };
46
+ const wrapStyle = {
47
+ ...style,
48
+ display: visible ? 'block' : 'none',
49
+ };
50
+ if (lockScroll && visible) {
51
+ document.body.classList.add('nut-overflow-hidden');
52
+ }
53
+ return (React__default.createElement(React__default.Fragment, null,
54
+ mask ? (React__default.createElement(CSSTransition, { in: visible, timeout: 300, classNames: "fadeDialog", unmountOnExit: true, appear: true },
55
+ React__default.createElement(Mask, null))) : null,
56
+ React__default.createElement("div", { className: classNames('nut-dialog__wrap', className), onClick: handleClick, style: wrapStyle },
57
+ React__default.createElement(Content, { ...props, visible: visible }))));
58
+ };
59
+ DialogWrap.displayName = 'NutDialogWrap';
60
+
61
+ const DialogWrapper = (props) => {
62
+ const { visible, lockScroll } = props;
63
+ return (React__default.createElement(View, { style: { display: visible ? 'block' : 'none' }, catchMove: lockScroll },
64
+ React__default.createElement(DialogWrap, { ...props })));
65
+ };
66
+ DialogWrapper.displayName = 'NutDialogWrapper';
67
+
68
+ const defaultProps = {
69
+ okText: '',
70
+ cancelText: '',
71
+ mask: true,
72
+ closeOnClickOverlay: true,
73
+ noFooter: false,
74
+ noOkBtn: false,
75
+ noCancelBtn: false,
76
+ okBtnDisabled: false,
77
+ cancelAutoClose: true,
78
+ textAlign: 'center',
79
+ footerDirection: 'horizontal',
80
+ lockScroll: false,
81
+ };
82
+ const BaseDialog = forwardRef((props, ref) => {
83
+ const { locale } = useConfig();
84
+ const { visible, footer, noOkBtn, noCancelBtn, lockScroll, okBtnDisabled, cancelAutoClose, okText, cancelText, onClosed, onCancel, onOk, ...restProps } = props;
85
+ const renderFooter = function () {
86
+ if (footer === null)
87
+ return '';
88
+ const handleCancel = function (e) {
89
+ e.stopPropagation();
90
+ if (!cancelAutoClose)
91
+ return;
92
+ onClosed?.();
93
+ onCancel?.();
94
+ if (lockScroll && visible) {
95
+ document.body.classList.remove('nut-overflow-hidden');
96
+ }
97
+ };
98
+ const handleOk = function (e) {
99
+ e.stopPropagation();
100
+ onClosed?.();
101
+ onOk?.(e);
102
+ if (lockScroll && visible) {
103
+ document.body.classList.remove('nut-overflow-hidden');
104
+ }
105
+ };
106
+ const footerContent = footer || (React__default.createElement(React__default.Fragment, null,
107
+ !noCancelBtn && (React__default.createElement(Button, { size: "small", plain: true, type: "primary", className: "nut-dialog__footer-cancel", onClick: (e) => handleCancel(e) }, cancelText || locale.cancel)),
108
+ !noOkBtn && (React__default.createElement(Button, { size: "small", type: "primary", className: classNames('nut-dialog__footer-ok', {
109
+ disabled: okBtnDisabled,
110
+ }), disabled: okBtnDisabled, onClick: (e) => handleOk(e) }, okText || locale.confirm))));
111
+ return footerContent;
112
+ };
113
+ return (React__default.createElement(DialogWrapper, { ...restProps, visible: visible, lockScroll: lockScroll, footer: renderFooter(), onClosed: onClosed, onCancel: onCancel }));
114
+ });
115
+ BaseDialog.defaultProps = defaultProps;
116
+ BaseDialog.displayName = 'NutDialog';
117
+
118
+ export { BaseDialog as B };
@@ -0,0 +1,35 @@
1
+ import React__default from 'react';
2
+ import classNames from 'classnames';
3
+ import { c as cn } from './bem-350c1702.js';
4
+
5
+ const defaultProps = {
6
+ contentPosition: 'center',
7
+ dashed: false,
8
+ hairline: true,
9
+ direction: 'horizontal',
10
+ };
11
+ const Divider = (props) => {
12
+ const { children, contentPosition, dashed, hairline, styles, className, direction, ...rest } = {
13
+ ...defaultProps,
14
+ ...props,
15
+ };
16
+ const dividerBem = cn('divider');
17
+ const classes = direction === 'horizontal'
18
+ ? classNames({
19
+ [dividerBem()]: true,
20
+ [dividerBem('center')]: children,
21
+ [dividerBem('left')]: contentPosition === 'left',
22
+ [dividerBem('right')]: contentPosition === 'right',
23
+ [dividerBem('dashed')]: dashed,
24
+ [dividerBem('hairline')]: hairline,
25
+ })
26
+ : classNames({
27
+ [dividerBem()]: true,
28
+ [dividerBem('vertical')]: direction === 'vertical',
29
+ });
30
+ return (React__default.createElement("div", { className: `${classes} ${className || ''}`, style: styles, ...rest }, children));
31
+ };
32
+ Divider.defaultProps = defaultProps;
33
+ Divider.displayName = 'NutDivider';
34
+
35
+ export { Divider as D };