@nutui/nutui-react 1.2.3-beta.4 → 1.3.1-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 (334) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/esm/Audio/style/index.js +4 -0
  3. package/dist/esm/Audio.js +293 -0
  4. package/dist/esm/Avatar.js +7 -5
  5. package/dist/esm/Calendar/style/index.js +1 -2
  6. package/dist/esm/Calendar.js +80 -33
  7. package/dist/esm/CalendarItem.js +440 -238
  8. package/dist/esm/Cascader/style/index.js +2 -0
  9. package/dist/esm/Cascader.js +788 -0
  10. package/dist/esm/CheckboxGroup.js +0 -1
  11. package/dist/esm/ConfigProvider.js +16 -0
  12. package/dist/esm/DatePicker.js +37 -6
  13. package/dist/esm/Dialog.js +9 -16
  14. package/dist/esm/Drag.js +1 -1
  15. package/dist/esm/Elevator.js +16 -5
  16. package/dist/esm/Grid/style/index.js +2 -0
  17. package/dist/esm/Grid.js +91 -0
  18. package/dist/esm/GridItem/style/index.js +2 -0
  19. package/dist/esm/GridItem.js +99 -0
  20. package/dist/esm/Icon/style/index.js +1 -0
  21. package/dist/esm/Icon.js +2 -2
  22. package/dist/esm/ImagePreview/style/index.js +2 -0
  23. package/dist/esm/ImagePreview.js +257 -0
  24. package/dist/esm/Input.js +8 -2
  25. package/dist/esm/InputNumber.js +11 -11
  26. package/dist/esm/Menu/style/index.js +3 -0
  27. package/dist/esm/Menu.js +153 -0
  28. package/dist/esm/MenuItem/style/index.js +3 -0
  29. package/dist/esm/MenuItem.js +197 -0
  30. package/dist/esm/NoticeBar.js +70 -30
  31. package/dist/esm/Notify.js +19 -4
  32. package/dist/esm/Picker.js +9 -4
  33. package/dist/esm/Popover.js +57 -80
  34. package/dist/esm/Price.js +14 -3
  35. package/dist/esm/Progress.js +1 -1
  36. package/dist/esm/Range.js +11 -48
  37. package/dist/esm/Swipe/style/index.js +2 -0
  38. package/dist/esm/Swipe.js +265 -0
  39. package/dist/esm/Swiper.js +2 -1
  40. package/dist/esm/TabPane.js +5 -33
  41. package/dist/esm/TabbarItem.js +1 -1
  42. package/dist/esm/Tabs.js +6 -196
  43. package/dist/esm/Tag.js +1 -1
  44. package/dist/esm/TextArea.js +48 -4
  45. package/dist/esm/Toast.js +24 -13
  46. package/dist/esm/Uploader.js +16 -6
  47. package/dist/esm/{icon-62bd7379.js → icon-8dc4de10.js} +9 -9
  48. package/dist/esm/nutui-react.es.js +8 -0
  49. package/dist/esm/render-4a3856cb.js +32 -0
  50. package/dist/esm/tabpane-c957ab14.js +33 -0
  51. package/dist/esm/tabs-a48583e9.js +196 -0
  52. package/dist/esm/useClientRect-839d18c5.js +44 -0
  53. package/dist/locales/base.d.ts +16 -0
  54. package/dist/locales/base.js +1 -1
  55. package/dist/locales/en-US.js +17 -1
  56. package/dist/locales/id-ID.js +17 -1
  57. package/dist/locales/zh-CN.js +17 -1
  58. package/dist/locales/zh-TW.js +17 -1
  59. package/dist/nutui.react.es.js +2639 -768
  60. package/dist/nutui.react.umd.js +2646 -767
  61. package/dist/packages/audio/audio.scss +80 -0
  62. package/dist/packages/calendar/calendar.scss +57 -36
  63. package/dist/packages/calendaritem/calendaritem.scss +0 -191
  64. package/dist/packages/cascader/cascader.scss +69 -0
  65. package/dist/packages/col/col.scss +2 -2
  66. package/dist/packages/collapseitem/collapseitem.scss +1 -2
  67. package/dist/packages/grid/grid.scss +10 -0
  68. package/dist/packages/griditem/griditem.scss +103 -0
  69. package/dist/packages/icon/icon.scss +104 -12
  70. package/dist/packages/imagepreview/imagepreview.scss +51 -0
  71. package/dist/packages/menu/menu.scss +72 -0
  72. package/dist/packages/menuitem/menuitem.scss +90 -0
  73. package/dist/packages/noticebar/noticebar.scss +31 -15
  74. package/dist/packages/notify/notify.scss +9 -0
  75. package/dist/packages/popover/popover.scss +205 -83
  76. package/dist/packages/popup/popup.scss +1 -1
  77. package/dist/packages/rate/rate.scss +14 -13
  78. package/dist/packages/searchbar/searchbar.scss +1 -0
  79. package/dist/packages/shortpassword/shortpassword.scss +6 -1
  80. package/dist/packages/swipe/swipe.scss +33 -0
  81. package/dist/packages/textarea/textarea.scss +16 -1
  82. package/dist/packages/toast/toast.scss +16 -13
  83. package/dist/style.css +1 -1
  84. package/dist/style.es.js +1 -1
  85. package/dist/styles/animation/icon.scss +245 -0
  86. package/dist/styles/animation/index.scss +1 -0
  87. package/dist/styles/font/config.json +169 -0
  88. package/dist/styles/font/demo_index.html +210 -3
  89. package/dist/styles/font/iconfont.css +39 -3
  90. package/dist/styles/font/iconfont.js +42 -40
  91. package/dist/styles/font/iconfont.json +63 -0
  92. package/dist/styles/font/iconfont.ttf +0 -0
  93. package/dist/styles/font/iconfont.woff +0 -0
  94. package/dist/styles/font/iconfont.woff2 +0 -0
  95. package/dist/styles/themes/default.scss +8 -0
  96. package/dist/styles/variables.scss +82 -15
  97. package/dist/types/actionsheet/actionsheet.taro.d.ts +20 -0
  98. package/dist/types/actionsheet/index.taro.d.ts +2 -0
  99. package/dist/types/address/address.taro.d.ts +34 -0
  100. package/dist/types/address/index.taro.d.ts +2 -0
  101. package/dist/types/animatingnumbers/animatingnumbers.taro.d.ts +12 -0
  102. package/dist/types/animatingnumbers/countup.taro.d.ts +11 -0
  103. package/dist/types/animatingnumbers/index.taro.d.ts +2 -0
  104. package/dist/types/audio/__test__/audio.spec.d.ts +1 -0
  105. package/dist/types/audio/audio.d.ts +18 -0
  106. package/dist/types/audio/audio.taro.d.ts +18 -0
  107. package/dist/types/audio/demo.d.ts +4 -0
  108. package/dist/types/audio/index.d.ts +2 -0
  109. package/dist/types/audio/index.taro.d.ts +2 -0
  110. package/dist/types/avatar/avatar.taro.d.ts +17 -0
  111. package/dist/types/avatar/index.taro.d.ts +2 -0
  112. package/dist/types/avatargroup/index.taro.d.ts +2 -0
  113. package/dist/types/backtop/__test__/backtop.spec.d.ts +1 -0
  114. package/dist/types/backtop/backtop.taro.d.ts +15 -0
  115. package/dist/types/backtop/index.taro.d.ts +2 -0
  116. package/dist/types/badge/badge.taro.d.ts +14 -0
  117. package/dist/types/badge/index.taro.d.ts +2 -0
  118. package/dist/types/barrage/barrage.taro.d.ts +12 -0
  119. package/dist/types/barrage/index.taro.d.ts +2 -0
  120. package/dist/types/button/button.taro.d.ts +20 -0
  121. package/dist/types/button/index.taro.d.ts +2 -0
  122. package/dist/types/calendar/__tests__/calendar.spec.d.ts +1 -0
  123. package/dist/types/calendar/calendar.d.ts +22 -2
  124. package/dist/types/calendar/calendar.taro.d.ts +14 -0
  125. package/dist/types/calendar/demo.d.ts +1 -0
  126. package/dist/types/calendar/index.taro.d.ts +2 -0
  127. package/dist/types/calendaritem/calendaritem.d.ts +21 -3
  128. package/dist/types/calendaritem/calendaritem.taro.d.ts +17 -0
  129. package/dist/types/calendaritem/index.taro.d.ts +2 -0
  130. package/dist/types/card/card.taro.d.ts +17 -0
  131. package/dist/types/card/index.taro.d.ts +2 -0
  132. package/dist/types/cascader/__tests__/cascader.spec.d.ts +1 -0
  133. package/dist/types/cascader/cascader.d.ts +25 -0
  134. package/dist/types/cascader/cascader.taro.d.ts +25 -0
  135. package/dist/types/cascader/cascaderItem.d.ts +25 -0
  136. package/dist/types/cascader/cascaderItem.taro.d.ts +25 -0
  137. package/dist/types/cascader/demo.d.ts +3 -0
  138. package/dist/types/cascader/helper.d.ts +4 -0
  139. package/dist/types/cascader/index.d.ts +2 -0
  140. package/dist/types/cascader/index.taro.d.ts +2 -0
  141. package/dist/types/cascader/tree.d.ts +12 -0
  142. package/dist/types/cascader/types.d.ts +28 -0
  143. package/dist/types/cell/cell.taro.d.ts +20 -0
  144. package/dist/types/cell/index.taro.d.ts +2 -0
  145. package/dist/types/cellgroup/cellgroup.taro.d.ts +10 -0
  146. package/dist/types/cellgroup/index.taro.d.ts +2 -0
  147. package/dist/types/checkbox/checkbox.d.ts +2 -2
  148. package/dist/types/checkbox/checkbox.taro.d.ts +19 -0
  149. package/dist/types/checkbox/index.taro.d.ts +2 -0
  150. package/dist/types/checkboxgroup/checkboxgroup.d.ts +2 -2
  151. package/dist/types/checkboxgroup/checkboxgroup.taro.d.ts +8 -0
  152. package/dist/types/checkboxgroup/index.taro.d.ts +2 -0
  153. package/dist/types/circleprogress/circleprogress.taro.d.ts +15 -0
  154. package/dist/types/circleprogress/index.taro.d.ts +2 -0
  155. package/dist/types/col/col.taro.d.ts +10 -0
  156. package/dist/types/col/index.taro.d.ts +2 -0
  157. package/dist/types/collapse/collapse.taro.d.ts +12 -0
  158. package/dist/types/collapse/index.taro.d.ts +2 -0
  159. package/dist/types/collapseitem/index.taro.d.ts +2 -0
  160. package/dist/types/configprovider/configprovider.taro.d.ts +12 -0
  161. package/dist/types/configprovider/index.taro.d.ts +2 -0
  162. package/dist/types/countdown/countdown.taro.d.ts +15 -0
  163. package/dist/types/countdown/index.taro.d.ts +2 -0
  164. package/dist/types/datepicker/datepicker.taro.d.ts +27 -0
  165. package/dist/types/datepicker/index.taro.d.ts +2 -0
  166. package/dist/types/dialog/__test__/dialog.spec.d.ts +1 -0
  167. package/dist/types/dialog/config.d.ts +3 -3
  168. package/dist/types/dialog/dialog.d.ts +2 -1
  169. package/dist/types/dialog/dialog.taro.d.ts +3 -0
  170. package/dist/types/dialog/index.taro.d.ts +2 -0
  171. package/dist/types/divider/divider.taro.d.ts +12 -0
  172. package/dist/types/divider/index.taro.d.ts +2 -0
  173. package/dist/types/drag/drag.taro.d.ts +14 -0
  174. package/dist/types/drag/index.taro.d.ts +2 -0
  175. package/dist/types/elevator/elevator.taro.d.ts +22 -0
  176. package/dist/types/elevator/index.taro.d.ts +2 -0
  177. package/dist/types/empty/empty.taro.d.ts +8 -0
  178. package/dist/types/empty/index.taro.d.ts +2 -0
  179. package/dist/types/fixednav/fixednav.d.ts +2 -2
  180. package/dist/types/fixednav/fixednav.taro.d.ts +22 -0
  181. package/dist/types/fixednav/index.taro.d.ts +2 -0
  182. package/dist/types/grid/__test__/grid.spec.d.ts +1 -0
  183. package/dist/types/grid/demo.d.ts +3 -0
  184. package/dist/types/grid/grid.d.ts +16 -0
  185. package/dist/types/grid/grid.taro.d.ts +16 -0
  186. package/dist/types/grid/index.d.ts +2 -0
  187. package/dist/types/grid/index.taro.d.ts +2 -0
  188. package/dist/types/griditem/griditem.d.ts +20 -0
  189. package/dist/types/griditem/griditem.taro.d.ts +20 -0
  190. package/dist/types/griditem/index.d.ts +2 -0
  191. package/dist/types/griditem/index.taro.d.ts +2 -0
  192. package/dist/types/icon/icon.d.ts +10 -5
  193. package/dist/types/icon/icon.taro.d.ts +18 -0
  194. package/dist/types/icon/index.taro.d.ts +2 -0
  195. package/dist/types/imagepreview/__test__/imagepreview.spec.d.ts +1 -0
  196. package/dist/types/imagepreview/demo.d.ts +3 -0
  197. package/dist/types/imagepreview/imagepreview.d.ts +26 -0
  198. package/dist/types/imagepreview/imagepreview.taro.d.ts +26 -0
  199. package/dist/types/imagepreview/index.d.ts +2 -0
  200. package/dist/types/imagepreview/index.taro.d.ts +2 -0
  201. package/dist/types/indicator/index.taro.d.ts +2 -0
  202. package/dist/types/indicator/indicator.taro.d.ts +10 -0
  203. package/dist/types/infiniteloading/index.taro.d.ts +2 -0
  204. package/dist/types/infiniteloading/infiniteloading.taro.d.ts +20 -0
  205. package/dist/types/input/__test__/input.spec.d.ts +1 -0
  206. package/dist/types/input/index.taro.d.ts +2 -0
  207. package/dist/types/input/input.taro.d.ts +57 -0
  208. package/dist/types/inputnumber/index.taro.d.ts +2 -0
  209. package/dist/types/inputnumber/inputnumber.taro.d.ts +22 -0
  210. package/dist/types/layout/index.taro.d.ts +2 -0
  211. package/dist/types/layout/layout.taro.d.ts +4 -0
  212. package/dist/types/menu/__test__/menu.spec.d.ts +1 -0
  213. package/dist/types/menu/demo.d.ts +4 -0
  214. package/dist/types/menu/index.d.ts +2 -0
  215. package/dist/types/menu/index.taro.d.ts +2 -0
  216. package/dist/types/menu/menu.d.ts +12 -0
  217. package/dist/types/menu/menu.taro.d.ts +12 -0
  218. package/dist/types/menuitem/index.d.ts +2 -0
  219. package/dist/types/menuitem/index.taro.d.ts +2 -0
  220. package/dist/types/menuitem/menuitem.d.ts +23 -0
  221. package/dist/types/menuitem/menuitem.taro.d.ts +23 -0
  222. package/dist/types/navbar/index.taro.d.ts +2 -0
  223. package/dist/types/navbar/navbar.taro.d.ts +21 -0
  224. package/dist/types/noticebar/demo.d.ts +1 -0
  225. package/dist/types/noticebar/index.taro.d.ts +2 -0
  226. package/dist/types/noticebar/noticebar.d.ts +1 -1
  227. package/dist/types/noticebar/noticebar.taro.d.ts +23 -0
  228. package/dist/types/notify/Notification.d.ts +8 -7
  229. package/dist/types/notify/__test__/notify.spec.d.ts +1 -0
  230. package/dist/types/notify/index.taro.d.ts +2 -0
  231. package/dist/types/notify/notify.d.ts +13 -0
  232. package/dist/types/notify/notify.taro.d.ts +23 -0
  233. package/dist/types/numberkeyboard/index.taro.d.ts +2 -0
  234. package/dist/types/numberkeyboard/numberkeyboard.taro.d.ts +20 -0
  235. package/dist/types/nutui.react.d.ts +95 -1
  236. package/dist/types/overlay/index.taro.d.ts +2 -0
  237. package/dist/types/overlay/overlay.taro.d.ts +12 -0
  238. package/dist/types/pagination/index.taro.d.ts +2 -0
  239. package/dist/types/pagination/pagination.taro.d.ts +19 -0
  240. package/dist/types/picker/doc.en.d.ts +142 -0
  241. package/dist/types/picker/index.taro.d.ts +2 -0
  242. package/dist/types/picker/picker.d.ts +3 -2
  243. package/dist/types/picker/picker.taro.d.ts +24 -0
  244. package/dist/types/picker/pickerSlot.d.ts +1 -0
  245. package/dist/types/popover/__tests__/popover.spec.d.ts +1 -0
  246. package/dist/types/popover/index.taro.d.ts +2 -0
  247. package/dist/types/popover/popover.d.ts +14 -7
  248. package/dist/types/popover/popover.taro.d.ts +21 -0
  249. package/dist/types/popup/index.taro.d.ts +2 -0
  250. package/dist/types/popup/popup.d.ts +1 -1
  251. package/dist/types/popup/popup.taro.d.ts +25 -0
  252. package/dist/types/price/index.taro.d.ts +2 -0
  253. package/dist/types/price/price.taro.d.ts +11 -0
  254. package/dist/types/progress/index.taro.d.ts +2 -0
  255. package/dist/types/progress/progress.taro.d.ts +26 -0
  256. package/dist/types/radio/index.taro.d.ts +2 -0
  257. package/dist/types/radio/radio.taro.d.ts +21 -0
  258. package/dist/types/radiogroup/index.taro.d.ts +2 -0
  259. package/dist/types/range/index.taro.d.ts +2 -0
  260. package/dist/types/range/range.taro.d.ts +25 -0
  261. package/dist/types/rate/index.taro.d.ts +2 -0
  262. package/dist/types/rate/rate.taro.d.ts +17 -0
  263. package/dist/types/row/index.taro.d.ts +2 -0
  264. package/dist/types/row/row.taro.d.ts +12 -0
  265. package/dist/types/searchbar/index.taro.d.ts +2 -0
  266. package/dist/types/searchbar/searchbar.taro.d.ts +60 -0
  267. package/dist/types/shortpassword/index.taro.d.ts +2 -0
  268. package/dist/types/shortpassword/shortpassword.taro.d.ts +21 -0
  269. package/dist/types/sidenavbar/index.taro.d.ts +2 -0
  270. package/dist/types/sidenavbar/sidenavbar.d.ts +14 -2
  271. package/dist/types/sidenavbar/sidenavbar.taro.d.ts +15 -0
  272. package/dist/types/sidenavbaritem/index.taro.d.ts +2 -0
  273. package/dist/types/sidenavbaritem/sidenavbaritem.d.ts +10 -2
  274. package/dist/types/sidenavbaritem/sidenavbaritem.taro.d.ts +11 -0
  275. package/dist/types/signature/index.taro.d.ts +2 -0
  276. package/dist/types/signature/signature.taro.d.ts +11 -0
  277. package/dist/types/skeleton/index.taro.d.ts +2 -0
  278. package/dist/types/skeleton/skeleton.taro.d.ts +19 -0
  279. package/dist/types/step/index.taro.d.ts +2 -0
  280. package/dist/types/steps/index.taro.d.ts +2 -0
  281. package/dist/types/steps/steps.taro.d.ts +10 -0
  282. package/dist/types/subsidenavbar/index.taro.d.ts +2 -0
  283. package/dist/types/subsidenavbar/subsidenavbar.d.ts +13 -3
  284. package/dist/types/subsidenavbar/subsidenavbar.taro.d.ts +13 -0
  285. package/dist/types/swipe/__tests__/swipe.spec.d.ts +1 -0
  286. package/dist/types/swipe/demo.d.ts +3 -0
  287. package/dist/types/swipe/index.d.ts +2 -0
  288. package/dist/types/swipe/index.taro.d.ts +2 -0
  289. package/dist/types/swipe/swipe.d.ts +41 -0
  290. package/dist/types/swipe/swipe.taro.d.ts +41 -0
  291. package/dist/types/swiper/index.taro.d.ts +2 -0
  292. package/dist/types/swiper/swiper.d.ts +1 -2
  293. package/dist/types/swiper/swiper.taro.d.ts +27 -0
  294. package/dist/types/swiperitem/index.taro.d.ts +2 -0
  295. package/dist/types/swiperitem/swiperitem.d.ts +1 -2
  296. package/dist/types/switch/index.taro.d.ts +2 -0
  297. package/dist/types/switch/switch.taro.d.ts +14 -0
  298. package/dist/types/tabbar/index.taro.d.ts +2 -0
  299. package/dist/types/tabbar/tabbar.taro.d.ts +14 -0
  300. package/dist/types/tabbaritem/index.taro.d.ts +2 -0
  301. package/dist/types/tabbaritem/tabbaritem.taro.d.ts +17 -0
  302. package/dist/types/table/index.taro.d.ts +2 -0
  303. package/dist/types/table/table.d.ts +2 -1
  304. package/dist/types/table/table.taro.d.ts +4 -0
  305. package/dist/types/table/types.d.ts +1 -1
  306. package/dist/types/tabpane/index.taro.d.ts +2 -0
  307. package/dist/types/tabpane/tabpane.taro.d.ts +10 -0
  308. package/dist/types/tabs/index.taro.d.ts +2 -0
  309. package/dist/types/tabs/tabs.taro.d.ts +30 -0
  310. package/dist/types/tag/index.taro.d.ts +2 -0
  311. package/dist/types/tag/tag.taro.d.ts +16 -0
  312. package/dist/types/textarea/__test__/textarea.spec.d.ts +1 -0
  313. package/dist/types/textarea/index.taro.d.ts +2 -0
  314. package/dist/types/textarea/textarea.taro.d.ts +18 -0
  315. package/dist/types/timedetail/index.taro.d.ts +2 -0
  316. package/dist/types/timedetail/timedetail.taro.d.ts +13 -0
  317. package/dist/types/timepannel/index.taro.d.ts +2 -0
  318. package/dist/types/timepannel/timepannel.taro.d.ts +8 -0
  319. package/dist/types/timeselect/index.taro.d.ts +2 -0
  320. package/dist/types/timeselect/timeselect.taro.d.ts +21 -0
  321. package/dist/types/toast/Notification.d.ts +6 -4
  322. package/dist/types/toast/__test__/toast.spec.d.ts +1 -0
  323. package/dist/types/toast/index.taro.d.ts +2 -0
  324. package/dist/types/toast/toast.d.ts +21 -0
  325. package/dist/types/toast/toast.taro.d.ts +29 -0
  326. package/dist/types/uploader/index.taro.d.ts +2 -0
  327. package/dist/types/uploader/uploader.d.ts +2 -2
  328. package/dist/types/uploader/uploader.taro.d.ts +68 -0
  329. package/dist/types/video/index.taro.d.ts +2 -0
  330. package/dist/types/virtuallist/index.taro.d.ts +2 -0
  331. package/dist/types/virtuallist/type.d.ts +1 -1
  332. package/dist/types/virtuallist/virtuallist.d.ts +2 -1
  333. package/dist/types/virtuallist/virtuallist.taro.d.ts +4 -0
  334. package/package.json +18 -7
@@ -35,12 +35,22 @@ var defaultProps = {
35
35
  defaultValue: '',
36
36
  startDate: Utils.getDay(0),
37
37
  endDate: Utils.getDay(365),
38
+ showToday: true,
39
+ startText: '开始',
40
+ endText: '结束',
41
+ confirmText: '确认',
42
+ showTitle: true,
43
+ showSubTitle: true,
44
+ toDateAnimation: true,
45
+ onBtn: undefined,
46
+ onDay: undefined,
47
+ onTopInfo: undefined,
48
+ onBottomInfo: undefined,
38
49
  onChoose: function onChoose(data) {},
39
50
  onUpdate: function onUpdate() {},
40
- onClose: function onClose() {}
51
+ onSelected: function onSelected(data) {}
41
52
  };
42
-
43
- var CalendarItem = function CalendarItem(props) {
53
+ var CalendarItem = React__default.forwardRef(function (props, ref) {
44
54
  var _classNames, _classNames2;
45
55
 
46
56
  var _useConfig = useConfig(),
@@ -52,11 +62,20 @@ var CalendarItem = function CalendarItem(props) {
52
62
  poppable = _defaultProps$props.poppable,
53
63
  title = _defaultProps$props.title,
54
64
  defaultValue = _defaultProps$props.defaultValue,
55
- startDate = _defaultProps$props.startDate,
56
- endDate = _defaultProps$props.endDate,
65
+ showToday = _defaultProps$props.showToday,
66
+ startText = _defaultProps$props.startText,
67
+ endText = _defaultProps$props.endText,
68
+ confirmText = _defaultProps$props.confirmText,
69
+ showTitle = _defaultProps$props.showTitle,
70
+ showSubTitle = _defaultProps$props.showSubTitle,
71
+ toDateAnimation = _defaultProps$props.toDateAnimation,
72
+ onBtn = _defaultProps$props.onBtn,
73
+ onDay = _defaultProps$props.onDay,
74
+ onTopInfo = _defaultProps$props.onTopInfo,
75
+ onBottomInfo = _defaultProps$props.onBottomInfo,
57
76
  onChoose = _defaultProps$props.onChoose,
58
77
  onUpdate = _defaultProps$props.onUpdate,
59
- onClose = _defaultProps$props.onClose;
78
+ onSelected = _defaultProps$props.onSelected;
60
79
 
61
80
  var weeks = locale.calendaritem.weekdays;
62
81
 
@@ -65,18 +84,26 @@ var CalendarItem = function CalendarItem(props) {
65
84
  yearMonthTitle = _useState2[0],
66
85
  setYearMonthTitle = _useState2[1];
67
86
 
68
- var _useState3 = useState(false),
87
+ var _useState3 = useState([]),
69
88
  _useState4 = _slicedToArray(_useState3, 2),
70
- unLoadPrev = _useState4[0],
71
- setUnLoadPrev = _useState4[1];
89
+ monthsData = _useState4[0],
90
+ setMonthsData = _useState4[1];
72
91
 
73
- var _useState5 = useState([]),
92
+ var _useState5 = useState(0),
74
93
  _useState6 = _slicedToArray(_useState5, 2),
75
- monthsData = _useState6[0],
76
- setMonthsData = _useState6[1];
94
+ translateY = _useState6[0],
95
+ setTranslateY = _useState6[1];
96
+
97
+ var _useState7 = useState([]),
98
+ _useState8 = _slicedToArray(_useState7, 2),
99
+ monthDefaultRange = _useState8[0],
100
+ setMonthDefaultRange = _useState8[1];
77
101
 
78
- var _useState7 = useState({
102
+ var _useState9 = useState({
79
103
  currDate: '',
104
+ propStartDate: '',
105
+ propEndDate: '',
106
+ unLoadPrev: false,
80
107
  touchParams: {
81
108
  startY: 0,
82
109
  endY: 0,
@@ -86,7 +113,6 @@ var CalendarItem = function CalendarItem(props) {
86
113
  lastTime: 0
87
114
  },
88
115
  transformY: 0,
89
- translateY: 0,
90
116
  scrollDistance: 0,
91
117
  defaultData: [],
92
118
  chooseData: [],
@@ -94,15 +120,20 @@ var CalendarItem = function CalendarItem(props) {
94
120
  dayPrefix: 'calendar-month-day',
95
121
  startData: '',
96
122
  endData: '',
97
- isRange: type === 'range',
98
- timer: 0
123
+ isRange: props.type === 'range',
124
+ timer: 0,
125
+ currentIndex: 0,
126
+ avgHeight: 0,
127
+ monthsNum: 0
99
128
  }),
100
- _useState8 = _slicedToArray(_useState7, 1),
101
- state = _useState8[0];
129
+ _useState10 = _slicedToArray(_useState9, 1),
130
+ state = _useState10[0];
102
131
 
103
132
  var weeksPanel = useRef(null);
104
133
  var months = useRef(null);
105
134
  var monthsPanel = useRef(null);
135
+ var viewArea = useRef(null);
136
+ var viewHeight = 0;
106
137
  var b = cn('calendar');
107
138
  var classes = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(b(''), "-tile"), !poppable), _defineProperty(_classNames, "".concat(b(''), "-nofooter"), !!isAutoBackFill), _classNames), b(''));
108
139
  var headerClasses = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(b(''), "-header"), true), _defineProperty(_classNames2, "".concat(b(''), "-header-tile"), !poppable), _classNames2));
@@ -122,23 +153,33 @@ var CalendarItem = function CalendarItem(props) {
122
153
  return Utils.isEqual(state.currDate[1], currDate);
123
154
  };
124
155
 
125
- var getCurrDate = function getCurrDate(day, month, isRange) {
126
- return isRange ? "".concat(month.curData[3], "-").concat(month.curData[4], "-").concat(Utils.getNumTwoBit(+day.day)) : "".concat(month.curData[0], "-").concat(month.curData[1], "-").concat(Utils.getNumTwoBit(+day.day));
156
+ var isMultiple = function isMultiple(currDate) {
157
+ if (state.currDate.length > 0) {
158
+ return state.currDate.some(function (item) {
159
+ return Utils.isEqual(item, currDate);
160
+ });
161
+ }
162
+
163
+ return false;
127
164
  };
128
165
 
129
- var getClass = function getClass(day, month, isRange) {
130
- var currDate = getCurrDate(day, month, isRange);
166
+ var getCurrDate = function getCurrDate(day, month) {
167
+ return "".concat(month.curData[0], "-").concat(month.curData[1], "-").concat(Utils.getNumTwoBit(+day.day));
168
+ };
169
+
170
+ var getClass = function getClass(day, month) {
171
+ var currDate = getCurrDate(day, month);
131
172
 
132
173
  if (day.type === 'curr') {
133
- if (!state.isRange && Utils.isEqual(state.currDate, currDate) || state.isRange && (isStart(currDate) || isEnd(currDate))) {
174
+ if (Utils.isEqual(state.currDate, currDate) || type === 'range' && (isStart(currDate) || isEnd(currDate)) || type === 'multiple' && isMultiple(currDate)) {
134
175
  return "".concat(state.dayPrefix, "-active");
135
176
  }
136
177
 
137
- if (startDate && Utils.compareDate(currDate, startDate) || endDate && Utils.compareDate(endDate, currDate)) {
178
+ if (state.propStartDate && Utils.compareDate(currDate, state.propStartDate) || state.propEndDate && Utils.compareDate(state.propEndDate, currDate)) {
138
179
  return "".concat(state.dayPrefix, "-disabled");
139
180
  }
140
181
 
141
- if (state.isRange && Array.isArray(state.currDate) && Object.values(state.currDate).length == 2 && Utils.compareDate(state.currDate[0], currDate) && Utils.compareDate(currDate, state.currDate[1])) {
182
+ if (type === 'range' && Array.isArray(state.currDate) && Object.values(state.currDate).length === 2 && Utils.compareDate(state.currDate[0], currDate) && Utils.compareDate(currDate, state.currDate[1])) {
142
183
  return "".concat(state.dayPrefix, "-choose");
143
184
  }
144
185
 
@@ -149,7 +190,7 @@ var CalendarItem = function CalendarItem(props) {
149
190
  };
150
191
 
151
192
  var isActive = function isActive(day, month) {
152
- return state.isRange && day.type == 'curr' && getClass(day, month) == 'calendar-month-day-active';
193
+ return state.isRange && day.type === 'curr' && getClass(day, month) === 'calendar-month-day-active';
153
194
  };
154
195
 
155
196
  var isCurrDay = function isCurrDay(month, day) {
@@ -158,8 +199,11 @@ var CalendarItem = function CalendarItem(props) {
158
199
  };
159
200
 
160
201
  var confirm = function confirm() {
161
- if (state.isRange && state.chooseData.length == 2 || !state.isRange) {
162
- onChoose && onChoose(state.chooseData);
202
+ var type = props.type;
203
+
204
+ if (type === 'range' && state.chooseData.length === 2 || type !== 'range') {
205
+ var chooseData = state.chooseData.slice(0);
206
+ onChoose && onChoose(chooseData);
163
207
 
164
208
  if (poppable) {
165
209
  onUpdate && onUpdate();
@@ -167,20 +211,42 @@ var CalendarItem = function CalendarItem(props) {
167
211
  }
168
212
  };
169
213
 
170
- var chooseDay = function chooseDay(day, month, isFirst, isRange) {
171
- if (getClass(day, month, isRange) != "".concat(state.dayPrefix, "-disabled")) {
214
+ var chooseDay = function chooseDay(day, month, isFirst) {
215
+ if (getClass(day, month) !== "".concat(state.dayPrefix, "-disabled")) {
216
+ var _type = props.type;
217
+
172
218
  var days = _toConsumableArray(month.curData);
173
219
 
174
- days = isRange ? days.splice(3) : days.splice(0, 3);
175
220
  days[2] = typeof day.day === 'number' ? Utils.getNumTwoBit(day.day) : day.day;
176
221
  days[3] = "".concat(days[0], "-").concat(days[1], "-").concat(days[2]);
177
222
  days[4] = Utils.getWhatDay(+days[0], +days[1], +days[2]);
178
223
 
179
- if (!state.isRange) {
180
- state.currDate = days[3];
181
- state.chooseData = _toConsumableArray(days);
182
- } else {
183
- if (Object.values(state.currDate).length === 2) {
224
+ if (_type === 'multiple') {
225
+ if (state.currDate.length > 0) {
226
+ var hasIndex = '';
227
+ state.currDate.forEach(function (item, index) {
228
+ if (item === days[3]) {
229
+ hasIndex = index;
230
+ }
231
+ });
232
+
233
+ if (isFirst) {
234
+ state.chooseData.push(_toConsumableArray(days));
235
+ } else if (hasIndex !== '') {
236
+ state.currDate.splice(hasIndex, 1);
237
+ state.chooseData.splice(hasIndex, 1);
238
+ } else {
239
+ state.currDate.push(days[3]);
240
+ state.chooseData.push(_toConsumableArray(days));
241
+ }
242
+ } else {
243
+ state.currDate = [days[3]];
244
+ state.chooseData = [_toConsumableArray(days)];
245
+ }
246
+ } else if (_type === 'range') {
247
+ var curDataLength = Object.values(state.currDate).length;
248
+
249
+ if (curDataLength === 2 || curDataLength === 0) {
184
250
  state.currDate = [days[3]];
185
251
  } else if (Utils.compareDate(state.currDate[0], days[3])) {
186
252
  Array.isArray(state.currDate) && state.currDate.push(days[3]);
@@ -188,17 +254,25 @@ var CalendarItem = function CalendarItem(props) {
188
254
  Array.isArray(state.currDate) && state.currDate.unshift(days[3]);
189
255
  }
190
256
 
191
- if (state.chooseData.length == 2 || !state.chooseData.length) {
192
- state.chooseData = _toConsumableArray(days);
193
- } else if (Utils.compareDate(state.chooseData[3], days[3])) {
194
- state.chooseData = [_toConsumableArray(state.chooseData), _toConsumableArray(days)];
257
+ if (state.chooseData.length === 2 || !state.chooseData.length) {
258
+ state.chooseData = [_toConsumableArray(days)];
259
+ } else if (Utils.compareDate(state.chooseData[0][3], days[3])) {
260
+ state.chooseData = [].concat(_toConsumableArray(state.chooseData), [_toConsumableArray(days)]);
195
261
  } else {
196
- state.chooseData = [_toConsumableArray(days), _toConsumableArray(state.chooseData)];
262
+ state.chooseData = [_toConsumableArray(days)].concat(_toConsumableArray(state.chooseData));
197
263
  }
264
+ } else {
265
+ state.currDate = days[3];
266
+ state.chooseData = _toConsumableArray(days);
198
267
  }
199
268
 
200
- if (isAutoBackFill && !isFirst) {
201
- confirm();
269
+ if (!isFirst) {
270
+ // 点击日期 触发
271
+ onSelected && onSelected(state.chooseData);
272
+
273
+ if (isAutoBackFill || !poppable) {
274
+ confirm();
275
+ }
202
276
  }
203
277
 
204
278
  setMonthsData(state.monthsData.slice());
@@ -206,33 +280,42 @@ var CalendarItem = function CalendarItem(props) {
206
280
  };
207
281
 
208
282
  var isStartTip = function isStartTip(day, month) {
209
- if (isActive(day, month)) {
210
- return isStart(getCurrDate(day, month));
283
+ return isActive(day, month) && isStart(getCurrDate(day, month));
284
+ }; // 是否有结束提示
285
+
286
+
287
+ var isEndTip = function isEndTip(day, month) {
288
+ if (state.currDate.length >= 2 && isEnd(getCurrDate(day, month))) {
289
+ return isActive(day, month);
211
290
  }
212
291
 
213
292
  return false;
214
- }; // 是否有结束提示
293
+ }; // 开始结束时间是否相等
215
294
 
216
295
 
217
- var isEndTip = function isEndTip(day, month) {
218
- return isActive(day, month);
296
+ var rangeTip = function rangeTip() {
297
+ if (state.currDate.length >= 2) {
298
+ return Utils.isEqual(state.currDate[0], state.currDate[1]);
299
+ }
300
+
301
+ return false;
219
302
  }; // 获取当前月数据
220
303
 
221
304
 
222
305
  var getCurrData = function getCurrData(type) {
223
- var monthData = type == 'prev' ? state.monthsData[0] : state.monthsData[state.monthsData.length - 1];
306
+ var monthData = type === 'prev' ? state.monthsData[0] : state.monthsData[state.monthsData.length - 1];
224
307
  var year = parseInt(monthData.curData[0]);
225
308
  var month = parseInt(monthData.curData[1].toString().replace(/^0/, ''));
226
309
 
227
310
  switch (type) {
228
311
  case 'prev':
229
- month == 1 && (year -= 1);
230
- month = month == 1 ? 12 : --month;
312
+ month === 1 && (year -= 1);
313
+ month = month === 1 ? 12 : --month;
231
314
  break;
232
315
 
233
316
  case 'next':
234
- month == 12 && (year += 1);
235
- month = month == 12 ? 1 : ++month;
317
+ month === 12 && (year += 1);
318
+ month = month === 12 ? 1 : ++month;
236
319
  break;
237
320
  }
238
321
 
@@ -240,24 +323,59 @@ var CalendarItem = function CalendarItem(props) {
240
323
  }; // 获取日期状态
241
324
 
242
325
 
243
- var getDaysStatus = function getDaysStatus(days, type) {
326
+ var getDaysStatus = function getDaysStatus(days, type, dateInfo) {
244
327
  // 修复:当某个月的1号是周日时,月份下方会空出来一行
245
- if (type == 'prev' && days >= 7) {
328
+ var year = dateInfo.year,
329
+ month = dateInfo.month;
330
+
331
+ if (type === 'prev' && days >= 7) {
246
332
  days -= 7;
247
333
  }
248
334
 
249
335
  return Array.from(Array(days), function (v, k) {
250
336
  return {
251
337
  day: k + 1,
252
- type: type
338
+ type: type,
339
+ year: year,
340
+ month: month
253
341
  };
254
342
  });
343
+ }; // 获取上一个月的最后一周天数,填充当月空白
344
+
345
+
346
+ var getPreDaysStatus = function getPreDaysStatus(days, type, dateInfo, preCurrMonthDays) {
347
+ // 修复:当某个月的1号是周日时,月份下方会空出来一行
348
+ var year = dateInfo.year,
349
+ month = dateInfo.month;
350
+
351
+ if (type === 'prev' && days >= 7) {
352
+ days -= 7;
353
+ }
354
+
355
+ var months = Array.from(Array(preCurrMonthDays), function (v, k) {
356
+ return {
357
+ day: k + 1,
358
+ type: type,
359
+ year: year,
360
+ month: month
361
+ };
362
+ });
363
+ return months.slice(preCurrMonthDays - days);
255
364
  }; // 获取月数据
256
365
 
257
366
 
258
367
  var getMonth = function getMonth(curData, type) {
259
368
  var preMonthDays = Utils.getMonthPreDay(+curData[0], +curData[1]);
369
+ var preMonth = +curData[1] - 1;
370
+ var preYear = curData[0];
371
+
372
+ if (preMonth <= 0) {
373
+ preMonth = 12;
374
+ preYear += 1;
375
+ }
376
+
260
377
  var currMonthDays = Utils.getMonthDays(curData[0], curData[1]);
378
+ var preCurrMonthDays = Utils.getMonthDays("".concat(preYear), "".concat(preMonth));
261
379
  var title = {
262
380
  year: curData[0],
263
381
  month: curData[1]
@@ -265,236 +383,315 @@ var CalendarItem = function CalendarItem(props) {
265
383
  var monthInfo = {
266
384
  curData: curData,
267
385
  title: locale.calendaritem.monthTitle(title.year, title.month),
268
- monthData: [].concat(_toConsumableArray(getDaysStatus(preMonthDays, 'prev')), _toConsumableArray(getDaysStatus(currMonthDays, 'curr')))
386
+ monthData: [].concat(_toConsumableArray(getPreDaysStatus(preMonthDays, 'prev', {
387
+ month: preMonth,
388
+ year: preYear
389
+ }, preCurrMonthDays)), _toConsumableArray(getDaysStatus(currMonthDays, 'curr', title)))
269
390
  };
391
+ monthInfo.cssHeight = 39 + (monthInfo.monthData.length > 35 ? 384 : 320);
392
+ var cssScrollHeight = 0;
393
+
394
+ if (state.monthsData.length > 0) {
395
+ cssScrollHeight = state.monthsData[state.monthsData.length - 1].cssScrollHeight + state.monthsData[state.monthsData.length - 1].cssHeight;
396
+ }
397
+
398
+ monthInfo.cssScrollHeight = cssScrollHeight;
270
399
 
271
- if (type == 'next') {
400
+ if (type === 'next') {
272
401
  if (!state.endData || !Utils.compareDate("".concat(state.endData[0], "-").concat(state.endData[1], "-").concat(Utils.getMonthDays(state.endData[0], state.endData[1])), "".concat(curData[0], "-").concat(curData[1], "-").concat(curData[2]))) {
273
402
  state.monthsData.push(monthInfo);
274
403
  }
275
404
  } else if (!state.startData || !Utils.compareDate("".concat(curData[0], "-").concat(curData[1], "-").concat(curData[2]), "".concat(state.startData[0], "-").concat(state.startData[1], "-01"))) {
276
405
  state.monthsData.unshift(monthInfo);
277
- } else {
278
- setUnLoadPrev(true);
279
406
  }
280
407
 
281
408
  setMonthsData(state.monthsData);
282
- }; // 监听月份滚动,改变月份标题
283
-
284
-
285
- var loadScroll = function loadScroll() {
286
- if (!props.poppable) {
287
- return false;
288
- }
289
-
290
- requestAniFrame$1(function () {
291
- if (weeksPanel !== null && weeksPanel !== void 0 && weeksPanel.current && monthsPanel !== null && monthsPanel !== void 0 && monthsPanel.current) {
292
- var top = weeksPanel === null || weeksPanel === void 0 ? void 0 : weeksPanel.current.getBoundingClientRect().bottom;
293
- var monthsDoms = monthsPanel.current.getElementsByClassName('calendar-month');
294
-
295
- for (var i = 0; i < monthsDoms.length; i++) {
296
- if (monthsDoms[i].getBoundingClientRect().top <= top && monthsDoms[i].getBoundingClientRect().bottom >= top) {
297
- setYearMonthTitle(state.monthsData[i].title);
298
- } else if (state.scrollDistance === 0) {
299
- setYearMonthTitle(state.monthsData[0].title);
300
- }
301
- }
302
- }
303
- });
304
- }; // 设置月份滚动距离和速度
305
-
306
-
307
- var setTransform = function setTransform() {
308
- var translateY = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
309
- var type = arguments.length > 1 ? arguments[1] : undefined;
310
- var time = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
409
+ };
311
410
 
312
- if (monthsPanel !== null && monthsPanel !== void 0 && monthsPanel.current) {
313
- if (type === 'end') {
314
- monthsPanel.current.style.webkitTransition = "transform ".concat(time, "ms cubic-bezier(0.19, 1, 0.22, 1)");
315
- clearTimeout(state.timer);
316
- state.timer = setTimeout(function () {
317
- loadScroll();
318
- }, time);
319
- } else {
320
- monthsPanel.current.style.webkitTransition = '';
321
- loadScroll();
411
+ var setDefaultRange = function setDefaultRange(monthsNum, current) {
412
+ var start = 0;
413
+ var end = 0;
414
+
415
+ if (monthsNum >= 3) {
416
+ if (current > 0 && current < monthsNum) {
417
+ start = current - 1;
418
+ end = current + 3;
419
+ } else if (current === 0) {
420
+ start = current;
421
+ end = current + 4;
422
+ } else if (current === monthsNum) {
423
+ start = current - 2;
424
+ end = current + 2;
322
425
  }
323
-
324
- monthsPanel.current.style.webkitTransform = "translateY(".concat(translateY, "px)");
325
- state.scrollDistance = translateY;
426
+ } else {
427
+ start = 0;
428
+ end = monthsNum + 2;
326
429
  }
327
- }; // 计算滚动方向和距离
328
430
 
431
+ setMonthDefaultRange([start, end]);
432
+ setTranslateY(state.monthsData[start].cssScrollHeight);
433
+ };
329
434
 
330
- var setMove = function setMove(move, type, time) {
331
- var _months$current, _monthsPanel$current;
435
+ var mothsViewScroll = function mothsViewScroll(e) {
436
+ if (state.monthsData.length <= 1) {
437
+ return;
438
+ }
332
439
 
333
- var updateMove = move + state.transformY;
334
- var h = ((_months$current = months.current) === null || _months$current === void 0 ? void 0 : _months$current.offsetHeight) || 0;
335
- var offsetHeight = ((_monthsPanel$current = monthsPanel.current) === null || _monthsPanel$current === void 0 ? void 0 : _monthsPanel$current.offsetHeight) || 0;
440
+ var target = e.target;
441
+ var currentScrollTop = target.scrollTop;
442
+ var current = Math.floor(currentScrollTop / state.avgHeight);
336
443
 
337
- if (type === 'end') {
338
- // 限定滚动距离
339
- if (updateMove > 0) {
340
- updateMove = 0;
444
+ if (current === 0) {
445
+ if (currentScrollTop >= state.monthsData[current + 1].cssScrollHeight) {
446
+ current += 1;
341
447
  }
342
-
343
- if (updateMove < 0 && updateMove < -offsetHeight + h) {
344
- updateMove = -offsetHeight + h;
448
+ } else if (current > 0 && current < state.monthsNum - 1) {
449
+ if (currentScrollTop >= state.monthsData[current + 1].cssScrollHeight) {
450
+ current += 1;
345
451
  }
346
452
 
347
- if (offsetHeight <= h && state.monthsData.length == 1) {
348
- updateMove = 0;
453
+ if (currentScrollTop < state.monthsData[current].cssScrollHeight) {
454
+ current -= 1;
349
455
  }
350
-
351
- setTransform(updateMove, type, time);
352
456
  } else {
353
- if (updateMove > 0 && updateMove > 100) {
354
- updateMove = 100;
457
+ var viewPosition = Math.round(currentScrollTop + viewHeight);
458
+
459
+ if (viewPosition < state.monthsData[current].cssScrollHeight + state.monthsData[current].cssHeight && currentScrollTop > state.monthsData[current - 1].cssScrollHeight) {
460
+ current -= 1;
355
461
  }
356
462
 
357
- if (updateMove < -offsetHeight + h - 100 && state.monthsData.length > 1) {
358
- updateMove = -offsetHeight + h - 100;
463
+ if (current + 1 <= state.monthsNum && viewPosition >= state.monthsData[current + 1].cssScrollHeight + state.monthsData[current + 1].cssHeight) {
464
+ current += 1;
359
465
  }
360
466
 
361
- if (updateMove < 0 && updateMove < -100 && state.monthsData.length == 1) {
362
- updateMove = -100;
467
+ if (current >= 1 && currentScrollTop < state.monthsData[current - 1].cssScrollHeight) {
468
+ current -= 1;
363
469
  }
470
+ }
364
471
 
365
- setTransform(updateMove);
472
+ if (state.currentIndex !== current) {
473
+ state.currentIndex = current;
474
+ setDefaultRange(state.monthsNum, current);
366
475
  }
367
- };
368
476
 
369
- var onTouchStart = function onTouchStart(event) {
370
- event.stopPropagation();
371
- var changedTouches = event.changedTouches[0];
372
- state.touchParams.startY = changedTouches.pageY;
373
- state.touchParams.startTime = event.timeStamp || Date.now();
374
- state.transformY = state.scrollDistance;
477
+ setYearMonthTitle(state.monthsData[current].title);
375
478
  };
376
479
 
377
- var onTouchMove = function onTouchMove(event) {
378
- event.stopPropagation();
379
- var changedTouches = event.changedTouches[0];
380
- state.touchParams.lastY = changedTouches.pageY;
381
- state.touchParams.lastTime = event.timeStamp || Date.now();
382
- var move = state.touchParams.lastY - state.touchParams.startY;
383
-
384
- if (Math.abs(move) < 5) {
385
- return false;
386
- }
480
+ var initData = function initData() {
481
+ // 初始化开始结束数据
482
+ var propStartDate = props.startDate ? props.startDate : Utils.getDay(0);
483
+ var propEndDate = props.endDate ? props.endDate : Utils.getDay(365);
484
+ state.propStartDate = propStartDate;
485
+ state.propEndDate = propEndDate;
486
+ state.startData = splitDate(propStartDate);
487
+ state.endData = splitDate(propEndDate); // 根据是否存在默认时间,初始化当前日期
387
488
 
388
- setMove(move);
389
- };
489
+ if (defaultValue || Array.isArray(defaultValue) && defaultValue.length > 0) {
490
+ state.currDate = props.type !== 'one' ? _toConsumableArray(props.defaultValue) : props.defaultValue;
491
+ } // 判断时间范围内存在多少个月
390
492
 
391
- var onTouchEnd = function onTouchEnd(event) {
392
- var _months$current2, _monthsPanel$current2;
393
493
 
394
- event.stopPropagation();
395
- var changedTouches = event.changedTouches[0];
396
- state.touchParams.lastY = changedTouches.pageY;
397
- state.touchParams.lastTime = event.timeStamp || Date.now();
398
- var move = state.touchParams.lastY - state.touchParams.startY;
494
+ var startDate = {
495
+ year: Number(state.startData[0]),
496
+ month: Number(state.startData[1])
497
+ };
498
+ var endDate = {
499
+ year: Number(state.endData[0]),
500
+ month: Number(state.endData[1])
501
+ };
502
+ var monthsNum = endDate.month - startDate.month;
399
503
 
400
- if (Math.abs(move) < 5) {
401
- return false;
504
+ if (endDate.year - startDate.year > 0) {
505
+ monthsNum += 12 * (endDate.year - startDate.year);
402
506
  }
403
507
 
404
- var updateMove = move + state.transformY;
405
- var h = ((_months$current2 = months.current) === null || _months$current2 === void 0 ? void 0 : _months$current2.offsetHeight) || 0;
406
- var offsetHeight = ((_monthsPanel$current2 = monthsPanel.current) === null || _monthsPanel$current2 === void 0 ? void 0 : _monthsPanel$current2.offsetHeight) || 0;
508
+ if (monthsNum <= 0) {
509
+ monthsNum = 1;
510
+ } // 设置月份数据
511
+
512
+
513
+ getMonth(state.startData, 'next');
514
+ var i = 1;
407
515
 
408
- if (updateMove > 0) {
409
- getMonth(getCurrData('prev'), 'prev');
410
- } else if (updateMove < 0 && updateMove < -offsetHeight + (Math.abs(move) > h ? Math.abs(move) : h) * 5) {
516
+ do {
411
517
  getMonth(getCurrData('next'), 'next');
518
+ } while (i++ < monthsNum);
412
519
 
413
- if (Math.abs(move) >= 300) {
414
- getMonth(getCurrData('next'), 'next');
415
- }
416
- }
520
+ state.monthsNum = monthsNum; // 日期转化为数组,限制初始日期。判断时间范围
417
521
 
418
- var moveTime = state.touchParams.lastTime - state.touchParams.startTime;
522
+ if (type === 'range' && Array.isArray(state.currDate)) {
523
+ if (state.currDate.length > 0) {
524
+ if (propStartDate && Utils.compareDate(state.currDate[0], propStartDate)) {
525
+ state.currDate.splice(0, 1, propStartDate);
526
+ }
419
527
 
420
- if (moveTime <= 300) {
421
- move *= 2;
422
- moveTime += 1000;
423
- setMove(move, 'end', moveTime);
424
- } else {
425
- setMove(move, 'end');
426
- }
427
- };
528
+ if (propEndDate && Utils.compareDate(propEndDate, state.currDate[1])) {
529
+ state.currDate.splice(1, 1, propEndDate);
530
+ }
428
531
 
429
- var initData = function initData() {
430
- // 初始化开始结束数据
431
- state.startData = startDate ? splitDate(startDate) : '';
432
- state.endData = endDate ? splitDate(endDate) : ''; // 初始化当前日期
532
+ state.defaultData = [].concat(_toConsumableArray(splitDate(state.currDate[0])), _toConsumableArray(splitDate(state.currDate[1])));
533
+ }
534
+ } else if (props.type === 'multiple' && Array.isArray(state.currDate)) {
535
+ if (state.currDate.length > 0) {
536
+ var defaultArr = [];
537
+ var obj = {};
538
+ state.currDate.forEach(function (item) {
539
+ if (propStartDate && !Utils.compareDate(item, propStartDate) && propEndDate && !Utils.compareDate(propEndDate, item)) {
540
+ if (!Object.hasOwnProperty.call(obj, item)) {
541
+ defaultArr.push(item);
542
+ obj[item] = item;
543
+ }
544
+ }
545
+ });
546
+ state.currDate = [].concat(defaultArr);
547
+ state.defaultData = _toConsumableArray(splitDate(defaultArr[0]));
548
+ }
549
+ } else if (state.currDate) {
550
+ if (propStartDate && Utils.compareDate(state.currDate, propStartDate)) {
551
+ state.currDate = propStartDate;
552
+ } else if (propEndDate && !Utils.compareDate(state.currDate, propEndDate)) {
553
+ state.currDate = propEndDate;
554
+ }
433
555
 
434
- if (!defaultValue) {
435
- state.currDate = state.isRange ? [Utils.date2Str(new Date()), Utils.getDay(1)] : Utils.date2Str(new Date());
436
- } else {
437
- state.currDate = state.isRange ? _toConsumableArray(defaultValue) : defaultValue;
438
- } // 日期转化为数组
556
+ state.defaultData = _toConsumableArray(splitDate(state.currDate));
557
+ } // 设置默认可见区域
439
558
 
440
559
 
441
- if (state.isRange && Array.isArray(state.currDate)) {
442
- if (startDate && Utils.compareDate(state.currDate[0], startDate)) {
443
- state.currDate.splice(0, 1, startDate);
444
- }
560
+ var current = 0;
561
+ var lastCurrent = 0;
562
+
563
+ if (state.defaultData.length > 0) {
564
+ state.monthsData.forEach(function (item, index) {
565
+ if (item.title === locale.calendaritem.monthTitle(state.defaultData[0], state.defaultData[1])) {
566
+ current = index;
567
+ }
568
+
569
+ if (props.type === 'range') {
570
+ if (item.title === locale.calendaritem.monthTitle(state.defaultData[3], state.defaultData[4])) {
571
+ lastCurrent = index;
572
+ }
573
+ }
574
+ });
575
+ }
445
576
 
446
- if (endDate && Utils.compareDate(endDate, state.currDate[1])) {
447
- state.currDate.splice(1, 1, endDate);
577
+ setDefaultRange(monthsNum, current);
578
+ state.currentIndex = current;
579
+ setYearMonthTitle(state.monthsData[state.currentIndex].title);
580
+
581
+ if (state.defaultData.length > 0) {
582
+ // 设置当前选中日期
583
+ if (type === 'range') {
584
+ chooseDay({
585
+ day: state.defaultData[2],
586
+ type: 'curr'
587
+ }, state.monthsData[state.currentIndex], true);
588
+ chooseDay({
589
+ day: state.defaultData[5],
590
+ type: 'curr'
591
+ }, state.monthsData[lastCurrent], true);
592
+ } else if (type === 'multiple') {
593
+ _toConsumableArray(state.currDate).forEach(function (item) {
594
+ var dateArr = splitDate(item);
595
+ var current = state.currentIndex;
596
+ state.monthsData.forEach(function (item, index) {
597
+ if (item.title === locale.calendaritem.monthTitle(dateArr[0], dateArr[1])) {
598
+ current = index;
599
+ }
600
+ });
601
+ chooseDay({
602
+ day: dateArr[2],
603
+ type: 'curr'
604
+ }, state.monthsData[current], true);
605
+ });
606
+ } else {
607
+ chooseDay({
608
+ day: state.defaultData[2],
609
+ type: 'curr'
610
+ }, state.monthsData[state.currentIndex], true);
448
611
  }
612
+ }
449
613
 
450
- state.defaultData = [].concat(_toConsumableArray(splitDate(state.currDate[0])), _toConsumableArray(splitDate(state.currDate[1])));
451
- } else {
452
- if (startDate && Utils.compareDate(state.currDate, startDate)) {
453
- state.currDate = startDate;
454
- } else if (endDate && !Utils.compareDate(state.currDate, endDate)) {
455
- state.currDate = endDate;
614
+ var lastItem = state.monthsData[state.monthsData.length - 1];
615
+ var containerHeight = lastItem.cssHeight + lastItem.cssScrollHeight;
616
+ requestAniFrame$1(function () {
617
+ // 初始化 日历位置
618
+ if (months && monthsPanel && viewArea) {
619
+ viewHeight = months.current.clientHeight;
620
+ monthsPanel.current.style.height = "".concat(containerHeight, "px");
621
+ months.current.scrollTop = state.monthsData[state.currentIndex].cssScrollHeight;
456
622
  }
623
+ });
624
+ state.avgHeight = Math.floor(containerHeight / (monthsNum + 1));
625
+ };
457
626
 
458
- state.defaultData = _toConsumableArray(splitDate(state.currDate));
459
- }
627
+ var resetRender = function resetRender() {
628
+ state.chooseData.splice(0);
629
+ state.monthsData.splice(0);
630
+ initData();
631
+ }; // 暴露出的API
460
632
 
461
- getMonth(state.defaultData, 'next');
462
- setYearMonthTitle(state.monthsData[0].title);
463
- var i = 1;
464
633
 
465
- do {
466
- getMonth(getCurrData('next'), 'next');
467
- } while (i++ < 4);
468
-
469
- if (state.isRange) {
470
- chooseDay({
471
- day: state.defaultData[2],
472
- type: 'curr'
473
- }, state.monthsData[0], true);
474
- chooseDay({
475
- day: state.defaultData[5],
476
- type: 'curr'
477
- }, state.monthsData[0], true, true);
478
- } else {
479
- chooseDay({
480
- day: state.defaultData[2],
481
- type: 'curr'
482
- }, state.monthsData[0], true);
634
+ var scrollToDate = function scrollToDate(date) {
635
+ if (Utils.compareDate(date, state.propStartDate)) {
636
+ date = state.propStartDate;
637
+ } else if (!Utils.compareDate(date, state.propEndDate)) {
638
+ date = state.propEndDate;
483
639
  }
640
+
641
+ var dateArr = splitDate(date);
642
+ state.monthsData.forEach(function (item, index) {
643
+ if (item.title === locale.calendaritem.monthTitle(dateArr[0], dateArr[1])) {
644
+ if (months.current) {
645
+ var distance = state.monthsData[index].cssScrollHeight - months.current.scrollTop;
646
+
647
+ if (toDateAnimation) {
648
+ var flag = 0;
649
+ var interval = setInterval(function () {
650
+ flag++;
651
+
652
+ if (months.current) {
653
+ var offset = distance / 10;
654
+ months.current.scrollTop += offset;
655
+ }
656
+
657
+ if (flag >= 10) {
658
+ clearInterval(interval);
659
+
660
+ if (months.current) {
661
+ months.current.scrollTop = state.monthsData[index].cssScrollHeight;
662
+ }
663
+ }
664
+ }, 40);
665
+ } else {
666
+ months.current.scrollTop = state.monthsData[index].cssScrollHeight;
667
+ }
668
+ }
669
+ }
670
+ });
484
671
  };
485
672
 
486
673
  useEffect(function () {
487
674
  initData();
488
675
  }, []);
676
+ useEffect(function () {
677
+ poppable && resetRender();
678
+ }, [defaultValue]);
679
+ React__default.useImperativeHandle(ref, function () {
680
+ return {
681
+ scrollToDate: scrollToDate
682
+ };
683
+ });
489
684
  return React__default.createElement(React__default.Fragment, null, React__default.createElement("div", {
490
685
  className: classes
491
686
  }, React__default.createElement("div", {
492
687
  className: headerClasses
493
- }, poppable ? React__default.createElement(React__default.Fragment, null, React__default.createElement("div", {
688
+ }, showTitle && React__default.createElement("div", {
494
689
  className: "calendar-title"
495
- }, locale.calendaritem.title), React__default.createElement("div", {
690
+ }, title || locale.calendaritem.title), onBtn && React__default.createElement("div", {
691
+ className: "calendar-top-slot"
692
+ }, onBtn()), showSubTitle && React__default.createElement("div", {
496
693
  className: "calendar-curr-month"
497
- }, yearMonthTitle)) : '', React__default.createElement("div", {
694
+ }, yearMonthTitle), React__default.createElement("div", {
498
695
  className: "calendar-weeks",
499
696
  ref: weeksPanel
500
697
  }, weeks.map(function (item) {
@@ -504,16 +701,18 @@ var CalendarItem = function CalendarItem(props) {
504
701
  }, item);
505
702
  }))), React__default.createElement("div", {
506
703
  className: "nut-calendar-content",
507
- onTouchStart: onTouchStart,
508
- onTouchMove: onTouchMove,
509
- onTouchEnd: onTouchEnd,
704
+ onScroll: mothsViewScroll,
510
705
  ref: months
511
706
  }, React__default.createElement("div", {
512
707
  className: "calendar-months-panel",
513
708
  ref: monthsPanel
514
709
  }, React__default.createElement("div", {
515
- className: "calendar-loading-tip"
516
- }, !unLoadPrev ? locale.calendaritem.loadPreviousMonth : locale.calendaritem.noEarlierMonth), monthsData.map(function (month, key) {
710
+ className: "viewArea",
711
+ ref: viewArea,
712
+ style: {
713
+ transform: "translateY(".concat(translateY, "px)")
714
+ }
715
+ }, state.monthsData.slice(monthDefaultRange[0], monthDefaultRange[1]).map(function (month, key) {
517
716
  return React__default.createElement("div", {
518
717
  className: "calendar-month",
519
718
  key: key
@@ -523,31 +722,34 @@ var CalendarItem = function CalendarItem(props) {
523
722
  className: "calendar-month-con"
524
723
  }, React__default.createElement("div", {
525
724
  className: monthitemclasses
526
- }, month.monthData && month.monthData.map(function (day, index) {
725
+ }, month.monthData.map(function (day, i) {
527
726
  return React__default.createElement("div", {
528
727
  className: ['calendar-month-day', getClass(day, month)].join(' '),
529
- key: index,
530
728
  onClick: function onClick() {
531
729
  chooseDay(day, month);
532
- }
730
+ },
731
+ key: i
533
732
  }, React__default.createElement("div", {
534
733
  className: "calendar-day"
535
- }, day.type === 'curr' ? day.day : ''), isCurrDay(month, day.day) ? React__default.createElement("div", {
536
- className: "calendar-curr-tips"
537
- }, locale.calendaritem.today) : '', isStartTip(day, month) ? React__default.createElement("div", {
538
- className: "calendar-day-tip"
539
- }, locale.calendaritem.start) : isEndTip(day, month) ? React__default.createElement("div", {
734
+ }, onDay ? onDay(day) : day.day), onTopInfo && React__default.createElement("div", {
735
+ className: "calendar-curr-tips calendar-curr-tips-top"
736
+ }, onTopInfo(day)), onBottomInfo && React__default.createElement("div", {
737
+ className: "calendar-curr-tips calendar-curr-tips-bottom"
738
+ }, onBottomInfo(day)), !onBottomInfo && showToday && isCurrDay(month, day.day) && React__default.createElement("div", {
739
+ className: "calendar-curr-tip-curr"
740
+ }, locale.calendaritem.today), isStartTip(day, month) && React__default.createElement("div", {
741
+ className: "calendar-day-tip ".concat(rangeTip() ? 'calendar-curr-tips-top' : '')
742
+ }, startText || locale.calendaritem.start), isEndTip(day, month) && React__default.createElement("div", {
540
743
  className: "calendar-day-tip"
541
- }, locale.calendaritem.end) : '');
744
+ }, endText || locale.calendaritem.end));
542
745
  }))));
543
- }))), poppable && !isAutoBackFill ? React__default.createElement("div", {
746
+ })))), poppable && !isAutoBackFill ? React__default.createElement("div", {
544
747
  className: "nut-calendar-footer"
545
748
  }, React__default.createElement("div", {
546
749
  className: "calendar-confirm-btn",
547
750
  onClick: confirm
548
- }, locale.confirm)) : ''));
549
- };
550
-
751
+ }, confirmText || locale.confirm)) : ''));
752
+ });
551
753
  CalendarItem.defaultProps = defaultProps;
552
754
  CalendarItem.displayName = 'NutCalendarItem';
553
755
  export { CalendarItem as default };