sard 1.0.0-canary.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/dist/accordion/Item.d.ts +17 -0
- package/dist/accordion/Item.js +25 -0
- package/dist/accordion/index.d.ts +26 -0
- package/dist/accordion/index.js +27 -0
- package/dist/accordion/index.scss +49 -0
- package/dist/action-sheet/ActionSheet.d.ts +24 -0
- package/dist/action-sheet/ActionSheet.js +79 -0
- package/dist/action-sheet/Agent.d.ts +6 -0
- package/dist/action-sheet/Agent.js +7 -0
- package/dist/action-sheet/Item.d.ts +16 -0
- package/dist/action-sheet/Item.js +22 -0
- package/dist/action-sheet/imperative.d.ts +10 -0
- package/dist/action-sheet/imperative.js +22 -0
- package/dist/action-sheet/index.d.ts +12 -0
- package/dist/action-sheet/index.js +10 -0
- package/dist/action-sheet/index.scss +148 -0
- package/dist/animated/index.d.ts +62 -0
- package/dist/animated/index.js +101 -0
- package/dist/animated/index.rn.d.ts +4 -0
- package/dist/animated/index.rn.js +35 -0
- package/dist/avatar/Group.d.ts +9 -0
- package/dist/avatar/Group.js +27 -0
- package/dist/avatar/index.d.ts +17 -0
- package/dist/avatar/index.js +22 -0
- package/dist/avatar/index.scss +82 -0
- package/dist/badge/index.d.ts +13 -0
- package/dist/badge/index.js +16 -0
- package/dist/badge/index.scss +81 -0
- package/dist/base.d.ts +11 -0
- package/dist/base.js +1 -0
- package/dist/button/CustomButton.d.ts +9 -0
- package/dist/button/CustomButton.js +23 -0
- package/dist/button/index.d.ts +21 -0
- package/dist/button/index.js +34 -0
- package/dist/button/index.scss +346 -0
- package/dist/calendar/Day.d.ts +23 -0
- package/dist/calendar/Day.js +70 -0
- package/dist/calendar/MonthPicker.d.ts +13 -0
- package/dist/calendar/MonthPicker.js +22 -0
- package/dist/calendar/Toolbar.d.ts +11 -0
- package/dist/calendar/Toolbar.js +18 -0
- package/dist/calendar/Weeks.d.ts +6 -0
- package/dist/calendar/Weeks.js +18 -0
- package/dist/calendar/index.d.ts +48 -0
- package/dist/calendar/index.js +193 -0
- package/dist/calendar/index.scss +210 -0
- package/dist/card/index.d.ts +15 -0
- package/dist/card/index.js +14 -0
- package/dist/card/index.scss +64 -0
- package/dist/cascader/index.d.ts +43 -0
- package/dist/cascader/index.js +216 -0
- package/dist/cascader/index.scss +130 -0
- package/dist/checkbox/Group.d.ts +5 -0
- package/dist/checkbox/Group.js +5 -0
- package/dist/checkbox/index.d.ts +10 -0
- package/dist/checkbox/index.js +8 -0
- package/dist/checkbox/index.scss +78 -0
- package/dist/collapse/index.d.ts +14 -0
- package/dist/collapse/index.js +61 -0
- package/dist/collapse/index.rn.d.ts +14 -0
- package/dist/collapse/index.rn.js +76 -0
- package/dist/collapse/index.scss +31 -0
- package/dist/components.d.ts +66 -0
- package/dist/components.js +66 -0
- package/dist/components.scss +65 -0
- package/dist/config-provider/index.d.ts +21 -0
- package/dist/config-provider/index.js +20 -0
- package/dist/count-down/index.d.ts +26 -0
- package/dist/count-down/index.js +95 -0
- package/dist/datetime-picker/index.d.ts +36 -0
- package/dist/datetime-picker/index.js +230 -0
- package/dist/dialog/Agent.d.ts +6 -0
- package/dist/dialog/Agent.js +7 -0
- package/dist/dialog/Dialog.d.ts +31 -0
- package/dist/dialog/Dialog.js +103 -0
- package/dist/dialog/imperative.d.ts +17 -0
- package/dist/dialog/imperative.js +35 -0
- package/dist/dialog/index.d.ts +14 -0
- package/dist/dialog/index.js +12 -0
- package/dist/dialog/index.scss +156 -0
- package/dist/dropdown/Item.d.ts +33 -0
- package/dist/dropdown/Item.js +164 -0
- package/dist/dropdown/Option.d.ts +10 -0
- package/dist/dropdown/Option.js +12 -0
- package/dist/dropdown/index.d.ts +20 -0
- package/dist/dropdown/index.js +59 -0
- package/dist/dropdown/index.scss +236 -0
- package/dist/ellipsis/index.d.ts +8 -0
- package/dist/ellipsis/index.js +18 -0
- package/dist/ellipsis/index.scss +23 -0
- package/dist/empty/index.d.ts +10 -0
- package/dist/empty/index.js +14 -0
- package/dist/empty/index.scss +59 -0
- package/dist/footer-bar/index.d.ts +8 -0
- package/dist/footer-bar/index.js +15 -0
- package/dist/footer-bar/index.scss +29 -0
- package/dist/form/CustomForm.d.ts +13 -0
- package/dist/form/CustomForm.js +26 -0
- package/dist/form/ErrorList.d.ts +6 -0
- package/dist/form/ErrorList.js +15 -0
- package/dist/form/Field.d.ts +41 -0
- package/dist/form/Field.js +124 -0
- package/dist/form/FieldContext.d.ts +18 -0
- package/dist/form/FieldContext.js +8 -0
- package/dist/form/List.d.ts +31 -0
- package/dist/form/List.js +87 -0
- package/dist/form/Map.d.ts +17 -0
- package/dist/form/Map.js +24 -0
- package/dist/form/NodeContext.d.ts +12 -0
- package/dist/form/NodeContext.js +14 -0
- package/dist/form/Validator.d.ts +88 -0
- package/dist/form/Validator.js +268 -0
- package/dist/form/createFormStore.d.ts +36 -0
- package/dist/form/createFormStore.js +249 -0
- package/dist/form/index.d.ts +43 -0
- package/dist/form/index.js +109 -0
- package/dist/form/index.scss +200 -0
- package/dist/form/store/Context.d.ts +4 -0
- package/dist/form/store/Context.js +3 -0
- package/dist/form/store/createStore.d.ts +6 -0
- package/dist/form/store/createStore.js +28 -0
- package/dist/form/store/useDispatch.d.ts +2 -0
- package/dist/form/store/useDispatch.js +10 -0
- package/dist/form/store/useSelector.d.ts +7 -0
- package/dist/form/store/useSelector.js +35 -0
- package/dist/form/type.d.ts +20 -0
- package/dist/form/type.js +1 -0
- package/dist/form/useForm.d.ts +27 -0
- package/dist/form/useForm.js +14 -0
- package/dist/form/useInternalWatch.d.ts +3 -0
- package/dist/form/useInternalWatch.js +27 -0
- package/dist/form/useNode.d.ts +49 -0
- package/dist/form/useNode.js +284 -0
- package/dist/form/useValidator.d.ts +23 -0
- package/dist/form/useValidator.js +74 -0
- package/dist/form/useWatch.d.ts +4 -0
- package/dist/form/useWatch.js +24 -0
- package/dist/grid/Col.d.ts +9 -0
- package/dist/grid/Col.js +20 -0
- package/dist/grid/Row.d.ts +11 -0
- package/dist/grid/Row.js +34 -0
- package/dist/grid/index.d.ts +2 -0
- package/dist/grid/index.js +2 -0
- package/dist/grid/index.scss +56 -0
- package/dist/halfline/index.d.ts +10 -0
- package/dist/halfline/index.js +27 -0
- package/dist/halfline/index.scss +80 -0
- package/dist/icon/common.d.ts +15 -0
- package/dist/icon/common.js +1 -0
- package/dist/icon/font/iconfont.json +275 -0
- package/dist/icon/font/iconfont.rn.scss +0 -0
- package/dist/icon/font/iconfont.scss +164 -0
- package/dist/icon/font/iconfont.ttf +0 -0
- package/dist/icon/fontLoader.d.ts +7 -0
- package/dist/icon/fontLoader.js +14 -0
- package/dist/icon/fontLoader.rn.d.ts +6 -0
- package/dist/icon/fontLoader.rn.js +52 -0
- package/dist/icon/index.d.ts +21 -0
- package/dist/icon/index.js +41 -0
- package/dist/icon/index.scss +23 -0
- package/dist/index-bar/Item.d.ts +9 -0
- package/dist/index-bar/Item.js +11 -0
- package/dist/index-bar/Nav.d.ts +13 -0
- package/dist/index-bar/Nav.js +75 -0
- package/dist/index-bar/index.d.ts +19 -0
- package/dist/index-bar/index.js +142 -0
- package/dist/index-bar/index.scss +153 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.scss +1 -0
- package/dist/input/index.d.ts +37 -0
- package/dist/input/index.js +116 -0
- package/dist/input/index.scss +249 -0
- package/dist/linear-gradient/index.d.ts +14 -0
- package/dist/linear-gradient/index.js +30 -0
- package/dist/linear-gradient/index.rn.d.ts +3 -0
- package/dist/linear-gradient/index.rn.js +3 -0
- package/dist/list/Item.d.ts +22 -0
- package/dist/list/Item.js +26 -0
- package/dist/list/ListContext.d.ts +9 -0
- package/dist/list/ListContext.js +2 -0
- package/dist/list/OrderContext.d.ts +8 -0
- package/dist/list/OrderContext.js +6 -0
- package/dist/list/index.d.ts +19 -0
- package/dist/list/index.js +29 -0
- package/dist/list/index.scss +257 -0
- package/dist/loading/index.d.ts +10 -0
- package/dist/loading/index.js +47 -0
- package/dist/loading/index.scss +25 -0
- package/dist/locale/index.d.ts +199 -0
- package/dist/locale/index.js +36 -0
- package/dist/locale/lang/en-US.d.ts +92 -0
- package/dist/locale/lang/en-US.js +92 -0
- package/dist/locale/lang/zh-CN.d.ts +92 -0
- package/dist/locale/lang/zh-CN.js +92 -0
- package/dist/locale/useTranslate.d.ts +7 -0
- package/dist/locale/useTranslate.js +41 -0
- package/dist/mask/index.d.ts +13 -0
- package/dist/mask/index.js +26 -0
- package/dist/mask/index.scss +24 -0
- package/dist/menu/Item.d.ts +15 -0
- package/dist/menu/Item.js +17 -0
- package/dist/menu/index.d.ts +17 -0
- package/dist/menu/index.js +15 -0
- package/dist/menu/index.scss +128 -0
- package/dist/mesh/Item.d.ts +16 -0
- package/dist/mesh/Item.js +16 -0
- package/dist/mesh/index.d.ts +14 -0
- package/dist/mesh/index.js +69 -0
- package/dist/mesh/index.scss +131 -0
- package/dist/mesh/type.d.ts +9 -0
- package/dist/mesh/type.js +1 -0
- package/dist/modal/index.d.ts +8 -0
- package/dist/modal/index.js +9 -0
- package/dist/modal/index.rn.d.ts +8 -0
- package/dist/modal/index.rn.js +8 -0
- package/dist/navbar/Item.d.ts +8 -0
- package/dist/navbar/Item.js +11 -0
- package/dist/navbar/index.d.ts +15 -0
- package/dist/navbar/index.js +16 -0
- package/dist/navbar/index.scss +128 -0
- package/dist/notice-bar/index.d.ts +28 -0
- package/dist/notice-bar/index.js +135 -0
- package/dist/notice-bar/index.scss +109 -0
- package/dist/notify/Agent.d.ts +6 -0
- package/dist/notify/Agent.js +7 -0
- package/dist/notify/Notify.d.ts +22 -0
- package/dist/notify/Notify.js +48 -0
- package/dist/notify/imperative.d.ts +18 -0
- package/dist/notify/imperative.js +35 -0
- package/dist/notify/index.d.ts +15 -0
- package/dist/notify/index.js +13 -0
- package/dist/notify/index.scss +65 -0
- package/dist/number-keyboard/index.d.ts +10 -0
- package/dist/number-keyboard/index.js +51 -0
- package/dist/number-keyboard/index.scss +93 -0
- package/dist/pagination/index.d.ts +20 -0
- package/dist/pagination/index.js +65 -0
- package/dist/pagination/index.scss +131 -0
- package/dist/pan-gesture-detector/index.d.ts +8 -0
- package/dist/pan-gesture-detector/index.js +11 -0
- package/dist/pan-gesture-detector/index.rn.d.ts +8 -0
- package/dist/pan-gesture-detector/index.rn.js +23 -0
- package/dist/pan-gesture-detector/usePan.d.ts +47 -0
- package/dist/pan-gesture-detector/usePan.js +146 -0
- package/dist/password-input/index.d.ts +22 -0
- package/dist/password-input/index.js +91 -0
- package/dist/password-input/index.scss +189 -0
- package/dist/picker/InertialMotion.d.ts +20 -0
- package/dist/picker/InertialMotion.js +141 -0
- package/dist/picker/PickerView.d.ts +1 -0
- package/dist/picker/PickerView.h5.d.ts +17 -0
- package/dist/picker/PickerView.h5.js +36 -0
- package/dist/picker/PickerView.js +1 -0
- package/dist/picker/PickerViewColumn copy.d.ts +9 -0
- package/dist/picker/PickerViewColumn copy.js +143 -0
- package/dist/picker/PickerViewColumn.d.ts +12 -0
- package/dist/picker/PickerViewColumn.js +238 -0
- package/dist/picker/index.d.ts +38 -0
- package/dist/picker/index.js +224 -0
- package/dist/picker/index.rn.scss +0 -0
- package/dist/picker/index.scss +138 -0
- package/dist/popout/index.d.ts +25 -0
- package/dist/popout/index.js +87 -0
- package/dist/popout/index.scss +136 -0
- package/dist/popout-input/index.d.ts +29 -0
- package/dist/popout-input/index.js +91 -0
- package/dist/popout-input/index.scss +53 -0
- package/dist/popover/index.d.ts +35 -0
- package/dist/popover/index.js +193 -0
- package/dist/popover/index.scss +94 -0
- package/dist/popover/utils.d.ts +23 -0
- package/dist/popover/utils.js +124 -0
- package/dist/popup/index.d.ts +29 -0
- package/dist/popup/index.js +60 -0
- package/dist/popup/index.scss +60 -0
- package/dist/pressable/index.d.ts +13 -0
- package/dist/pressable/index.js +58 -0
- package/dist/pressable/index.rn.d.ts +13 -0
- package/dist/pressable/index.rn.js +50 -0
- package/dist/progress-bar/index.d.ts +10 -0
- package/dist/progress-bar/index.js +22 -0
- package/dist/progress-bar/index.scss +45 -0
- package/dist/progress-circle/index.d.ts +11 -0
- package/dist/progress-circle/index.js +54 -0
- package/dist/progress-circle/index.scss +141 -0
- package/dist/radio/Group.d.ts +5 -0
- package/dist/radio/Group.js +5 -0
- package/dist/radio/index.d.ts +10 -0
- package/dist/radio/index.js +8 -0
- package/dist/radio/index.scss +77 -0
- package/dist/rate/index.d.ts +23 -0
- package/dist/rate/index.js +116 -0
- package/dist/rate/index.scss +99 -0
- package/dist/result/index.d.ts +12 -0
- package/dist/result/index.js +19 -0
- package/dist/result/index.scss +88 -0
- package/dist/safe-area/index.d.ts +7 -0
- package/dist/safe-area/index.js +35 -0
- package/dist/safe-area/index.scss +24 -0
- package/dist/scroll-view/index.d.ts +24 -0
- package/dist/scroll-view/index.js +72 -0
- package/dist/scroll-view/index.rn.d.ts +21 -0
- package/dist/scroll-view/index.rn.js +51 -0
- package/dist/search/index.d.ts +26 -0
- package/dist/search/index.js +35 -0
- package/dist/search/index.scss +75 -0
- package/dist/share-sheet/Item.d.ts +15 -0
- package/dist/share-sheet/Item.js +26 -0
- package/dist/share-sheet/Row.d.ts +10 -0
- package/dist/share-sheet/Row.js +26 -0
- package/dist/share-sheet/index.d.ts +26 -0
- package/dist/share-sheet/index.js +76 -0
- package/dist/share-sheet/index.scss +230 -0
- package/dist/skeleton/Avatar.d.ts +7 -0
- package/dist/skeleton/Avatar.js +17 -0
- package/dist/skeleton/Block.d.ts +8 -0
- package/dist/skeleton/Block.js +44 -0
- package/dist/skeleton/Paragraph.d.ts +7 -0
- package/dist/skeleton/Paragraph.js +13 -0
- package/dist/skeleton/Title.d.ts +7 -0
- package/dist/skeleton/Title.js +16 -0
- package/dist/skeleton/index.d.ts +28 -0
- package/dist/skeleton/index.js +22 -0
- package/dist/skeleton/index.scss +108 -0
- package/dist/slider/index.d.ts +36 -0
- package/dist/slider/index.js +187 -0
- package/dist/slider/index.scss +138 -0
- package/dist/space/index.d.ts +13 -0
- package/dist/space/index.js +33 -0
- package/dist/space/index.scss +36 -0
- package/dist/stepper/index.d.ts +26 -0
- package/dist/stepper/index.js +138 -0
- package/dist/stepper/index.scss +106 -0
- package/dist/steps/Step.d.ts +23 -0
- package/dist/steps/Step.js +41 -0
- package/dist/steps/index.d.ts +23 -0
- package/dist/steps/index.js +38 -0
- package/dist/steps/index.scss +300 -0
- package/dist/style/base.scss +3 -0
- package/dist/style/functions.scss +54 -0
- package/dist/style/index.d.ts +2 -0
- package/dist/style/index.js +2 -0
- package/dist/style/index.scss +0 -0
- package/dist/style/mixins/bem.scss +63 -0
- package/dist/style/mixins/border.scss +80 -0
- package/dist/style/mixins/disabled.scss +9 -0
- package/dist/style/mixins/env.rn.scss +11 -0
- package/dist/style/mixins/env.scss +11 -0
- package/dist/style/mixins/fixed.rn.scss +3 -0
- package/dist/style/mixins/fixed.scss +3 -0
- package/dist/style/mixins/sticky.rn.scss +3 -0
- package/dist/style/mixins/sticky.scss +3 -0
- package/dist/style/mixins/theme.scss +11 -0
- package/dist/style/mixins/universal.rn.scss +2 -0
- package/dist/style/mixins/universal.scss +6 -0
- package/dist/style/mixins.scss +8 -0
- package/dist/style/utils.scss +130 -0
- package/dist/style/variables.scss +422 -0
- package/dist/swiper/Item.d.ts +8 -0
- package/dist/swiper/Item.js +10 -0
- package/dist/swiper/index.d.ts +12 -0
- package/dist/swiper/index.js +13 -0
- package/dist/swiper/index.scss +10 -0
- package/dist/switch/index.d.ts +19 -0
- package/dist/switch/index.js +78 -0
- package/dist/switch/index.scss +106 -0
- package/dist/tabbar/Item.d.ts +17 -0
- package/dist/tabbar/Item.js +24 -0
- package/dist/tabbar/index.d.ts +17 -0
- package/dist/tabbar/index.js +33 -0
- package/dist/tabbar/index.scss +89 -0
- package/dist/tabs/Tab.d.ts +12 -0
- package/dist/tabs/Tab.js +17 -0
- package/dist/tabs/index.d.ts +23 -0
- package/dist/tabs/index.js +258 -0
- package/dist/tabs/index.scss +113 -0
- package/dist/tag/index.d.ts +17 -0
- package/dist/tag/index.js +21 -0
- package/dist/tag/index.scss +93 -0
- package/dist/template/index.d.ts +6 -0
- package/dist/template/index.js +10 -0
- package/dist/template/index.scss +16 -0
- package/dist/toast/Agent.d.ts +6 -0
- package/dist/toast/Agent.js +7 -0
- package/dist/toast/Toast.d.ts +24 -0
- package/dist/toast/Toast.js +43 -0
- package/dist/toast/imperative.d.ts +18 -0
- package/dist/toast/imperative.js +35 -0
- package/dist/toast/index.d.ts +15 -0
- package/dist/toast/index.js +13 -0
- package/dist/toast/index.scss +96 -0
- package/dist/transition/CSSTransition.d.ts +7 -0
- package/dist/transition/CSSTransition.js +49 -0
- package/dist/transition/CSSTransition.rn.d.ts +7 -0
- package/dist/transition/CSSTransition.rn.js +312 -0
- package/dist/transition/index.d.ts +43 -0
- package/dist/transition/index.js +156 -0
- package/dist/transition/index.rn.scss +0 -0
- package/dist/transition/index.scss +158 -0
- package/dist/upload/Preview.d.ts +35 -0
- package/dist/upload/Preview.js +41 -0
- package/dist/upload/PreviewVideo.d.ts +7 -0
- package/dist/upload/PreviewVideo.js +38 -0
- package/dist/upload/PreviewVideo.rn.d.ts +6 -0
- package/dist/upload/PreviewVideo.rn.js +24 -0
- package/dist/upload/chooseMedia.d.ts +26 -0
- package/dist/upload/chooseMedia.h5.d.ts +25 -0
- package/dist/upload/chooseMedia.h5.js +117 -0
- package/dist/upload/chooseMedia.js +55 -0
- package/dist/upload/index.d.ts +37 -0
- package/dist/upload/index.js +167 -0
- package/dist/upload/index.scss +247 -0
- package/dist/use/index.d.ts +20 -0
- package/dist/use/index.js +20 -0
- package/dist/use/useAutoplay.d.ts +1 -0
- package/dist/use/useAutoplay.js +34 -0
- package/dist/use/useBem.d.ts +9 -0
- package/dist/use/useBem.js +52 -0
- package/dist/use/useBrush.d.ts +23 -0
- package/dist/use/useBrush.js +61 -0
- package/dist/use/useControllableValue.d.ts +12 -0
- package/dist/use/useControllableValue.js +59 -0
- package/dist/use/useEvent.d.ts +4 -0
- package/dist/use/useEvent.js +12 -0
- package/dist/use/useForceRender.d.ts +5 -0
- package/dist/use/useForceRender.js +8 -0
- package/dist/use/useIndexableMap.d.ts +21 -0
- package/dist/use/useIndexableMap.js +65 -0
- package/dist/use/useInertRef.d.ts +7 -0
- package/dist/use/useInertRef.js +15 -0
- package/dist/use/useInternalSelect.d.ts +42 -0
- package/dist/use/useInternalSelect.js +64 -0
- package/dist/use/useLayoutUpdateEffect.d.ts +5 -0
- package/dist/use/useLayoutUpdateEffect.js +18 -0
- package/dist/use/usePropRef.d.ts +5 -0
- package/dist/use/usePropRef.js +9 -0
- package/dist/use/useResize.d.ts +2 -0
- package/dist/use/useResize.js +14 -0
- package/dist/use/useResizeObserver.d.ts +5 -0
- package/dist/use/useResizeObserver.js +38 -0
- package/dist/use/useSelect.d.ts +15 -0
- package/dist/use/useSelect.js +56 -0
- package/dist/use/useSelectorId.d.ts +1 -0
- package/dist/use/useSelectorId.js +5 -0
- package/dist/use/useSetTimeout.d.ts +10 -0
- package/dist/use/useSetTimeout.js +34 -0
- package/dist/use/useStopMovePropagate.d.ts +5 -0
- package/dist/use/useStopMovePropagate.js +28 -0
- package/dist/use/useThrottle.d.ts +8 -0
- package/dist/use/useThrottle.js +11 -0
- package/dist/use/useUpdateEffect.d.ts +5 -0
- package/dist/use/useUpdateEffect.js +18 -0
- package/dist/use/useUpdateWatchSync.d.ts +5 -0
- package/dist/use/useUpdateWatchSync.js +18 -0
- package/dist/use/useWatchStateSync.d.ts +4 -0
- package/dist/use/useWatchStateSync.js +18 -0
- package/dist/utils/animate.d.ts +28 -0
- package/dist/utils/animate.js +81 -0
- package/dist/utils/createPubSub.d.ts +8 -0
- package/dist/utils/createPubSub.js +53 -0
- package/dist/utils/date.d.ts +13 -0
- package/dist/utils/date.js +87 -0
- package/dist/utils/dom.d.ts +149 -0
- package/dist/utils/dom.js +297 -0
- package/dist/utils/file.d.ts +18 -0
- package/dist/utils/file.js +57 -0
- package/dist/utils/imperative.d.ts +20 -0
- package/dist/utils/imperative.js +37 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/is.d.ts +16 -0
- package/dist/utils/is.js +57 -0
- package/dist/utils/measure.d.ts +8 -0
- package/dist/utils/measure.js +13 -0
- package/dist/utils/measure.rn.d.ts +8 -0
- package/dist/utils/measure.rn.js +15 -0
- package/dist/utils/platform.android.d.ts +2 -0
- package/dist/utils/platform.android.js +2 -0
- package/dist/utils/platform.d.ts +2 -0
- package/dist/utils/platform.ios.d.ts +2 -0
- package/dist/utils/platform.ios.js +2 -0
- package/dist/utils/platform.js +2 -0
- package/dist/utils/style.d.ts +10 -0
- package/dist/utils/style.js +34 -0
- package/dist/utils/utils.d.ts +199 -0
- package/dist/utils/utils.js +639 -0
- package/package.json +30 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// 启动惯性滑动的时间阈值
|
|
2
|
+
const momentumTimeThreshold = 300;
|
|
3
|
+
// 启动惯性滑动的距离阈值
|
|
4
|
+
const momentumYThreshold = 15;
|
|
5
|
+
// 惯性滑动加速度
|
|
6
|
+
const deceleration = 0.003;
|
|
7
|
+
// 回弹阻力
|
|
8
|
+
const bounceRate = 10;
|
|
9
|
+
// 强弱回弹的分割值
|
|
10
|
+
const bounceThreshold = 300;
|
|
11
|
+
// 回弹的最大限度
|
|
12
|
+
const durationMap = {
|
|
13
|
+
noBounce: 1000,
|
|
14
|
+
weekBounce: 800,
|
|
15
|
+
strongBounce: 400,
|
|
16
|
+
};
|
|
17
|
+
// 回弹时间
|
|
18
|
+
const resetDuration = 500;
|
|
19
|
+
// 阻尼系数
|
|
20
|
+
const damping = 3;
|
|
21
|
+
const bezierMap = {
|
|
22
|
+
noBounce: 'cubic-bezier(.23,1,.68,1)',
|
|
23
|
+
weekBounce: 'cubic-bezier(.25,.46,.45,.94)',
|
|
24
|
+
strongBounce: 'cubic-bezier(.25,.46,.45,.94)',
|
|
25
|
+
reset: 'cubic-bezier(.165, .84, .44, 1)',
|
|
26
|
+
};
|
|
27
|
+
export function createInertialMotion(options) {
|
|
28
|
+
const { scrollHeight: _scrollHeight, contentHeight: _contentHeight, onReset, onStop, onMove: _onMove, onOutsideEnd, onInsideEnd, beforeMonmentum, onMomentum, maxOverflowY = 0, } = options;
|
|
29
|
+
let scrollHeight = _scrollHeight;
|
|
30
|
+
let contentHeight = _contentHeight;
|
|
31
|
+
let startClientY = 0;
|
|
32
|
+
let currentOffsetY = 0;
|
|
33
|
+
let startOffsetY = 0;
|
|
34
|
+
let momentumStartY = 0;
|
|
35
|
+
let startTime = 0;
|
|
36
|
+
let minY = scrollHeight - contentHeight;
|
|
37
|
+
const maxY = 0;
|
|
38
|
+
function setSize(scrollH, contentH) {
|
|
39
|
+
scrollHeight = scrollH;
|
|
40
|
+
contentHeight = contentH;
|
|
41
|
+
minY = scrollHeight - contentHeight;
|
|
42
|
+
}
|
|
43
|
+
let timer;
|
|
44
|
+
function momentumEnd(duration) {
|
|
45
|
+
timer = setTimeout(() => {
|
|
46
|
+
timer = null;
|
|
47
|
+
isNeedReset();
|
|
48
|
+
}, duration);
|
|
49
|
+
}
|
|
50
|
+
function stop() {
|
|
51
|
+
if (timer) {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
}
|
|
54
|
+
onStop();
|
|
55
|
+
}
|
|
56
|
+
function destroy() {
|
|
57
|
+
if (timer) {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function onStart(clientY) {
|
|
62
|
+
stop();
|
|
63
|
+
startClientY = clientY;
|
|
64
|
+
momentumStartY = startOffsetY = currentOffsetY;
|
|
65
|
+
startTime = Date.now();
|
|
66
|
+
}
|
|
67
|
+
function onMove(clientY) {
|
|
68
|
+
const deltaY = clientY - startClientY;
|
|
69
|
+
let offsetY = Math.round(startOffsetY + deltaY);
|
|
70
|
+
if (offsetY < minY) {
|
|
71
|
+
offsetY = Math.round(minY + (offsetY - minY) / damping);
|
|
72
|
+
}
|
|
73
|
+
else if (offsetY > maxY) {
|
|
74
|
+
offsetY = Math.round(offsetY / damping);
|
|
75
|
+
}
|
|
76
|
+
currentOffsetY = offsetY;
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
if (now - startTime > momentumTimeThreshold) {
|
|
79
|
+
momentumStartY = currentOffsetY;
|
|
80
|
+
startTime = now;
|
|
81
|
+
}
|
|
82
|
+
_onMove(currentOffsetY);
|
|
83
|
+
}
|
|
84
|
+
function onEnd() {
|
|
85
|
+
const resetValue = isNeedReset();
|
|
86
|
+
if (resetValue) {
|
|
87
|
+
onOutsideEnd(currentOffsetY);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const absDeltaY = Math.abs(currentOffsetY - momentumStartY);
|
|
91
|
+
const duration = Date.now() - startTime;
|
|
92
|
+
if (duration < momentumTimeThreshold && absDeltaY > momentumYThreshold) {
|
|
93
|
+
momentum(currentOffsetY, momentumStartY, duration);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
onInsideEnd(currentOffsetY);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function isNeedReset() {
|
|
100
|
+
const offsetY = Math.min(Math.max(minY, currentOffsetY), maxY);
|
|
101
|
+
if (offsetY !== currentOffsetY) {
|
|
102
|
+
currentOffsetY = offsetY;
|
|
103
|
+
onReset(offsetY, resetDuration, bezierMap.reset);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function momentum(current, start, duration) {
|
|
108
|
+
const offset = current - start;
|
|
109
|
+
const speed = (2 * Math.abs(offset)) / duration;
|
|
110
|
+
const direction = offset < 0 ? -1 : 1;
|
|
111
|
+
const distance = (speed / deceleration) * direction;
|
|
112
|
+
let destination = current + distance;
|
|
113
|
+
let type = 'noBounce';
|
|
114
|
+
let overflowY;
|
|
115
|
+
if (destination < minY) {
|
|
116
|
+
overflowY = minY - destination;
|
|
117
|
+
type = overflowY > bounceThreshold ? 'strongBounce' : 'weekBounce';
|
|
118
|
+
destination = Math.max(minY - maxOverflowY, minY - overflowY / bounceRate);
|
|
119
|
+
}
|
|
120
|
+
else if (destination > maxY) {
|
|
121
|
+
overflowY = destination - maxY;
|
|
122
|
+
type = overflowY > bounceThreshold ? 'strongBounce' : 'weekBounce';
|
|
123
|
+
destination = Math.min(maxY + maxOverflowY, maxY + overflowY / bounceRate);
|
|
124
|
+
}
|
|
125
|
+
destination = beforeMonmentum(destination);
|
|
126
|
+
currentOffsetY = destination;
|
|
127
|
+
onMomentum(destination, durationMap[type], bezierMap[type]);
|
|
128
|
+
momentumEnd(durationMap[type]);
|
|
129
|
+
}
|
|
130
|
+
function setCurrentOffsetY(offsetY) {
|
|
131
|
+
currentOffsetY = offsetY;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
onStart,
|
|
135
|
+
onMove,
|
|
136
|
+
onEnd,
|
|
137
|
+
setCurrentOffsetY,
|
|
138
|
+
setSize,
|
|
139
|
+
destroy,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PickerView, type PickerViewProps, PickerViewColumn, } from '@tarojs/components';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AnyFunction, BaseProps } from '../base';
|
|
2
|
+
import { PickerViewColumn } from './PickerViewColumn';
|
|
3
|
+
export { PickerViewColumn };
|
|
4
|
+
export interface PickerViewProps extends BaseProps {
|
|
5
|
+
value?: number[];
|
|
6
|
+
onChange?: (event: {
|
|
7
|
+
detail: {
|
|
8
|
+
value: number[];
|
|
9
|
+
};
|
|
10
|
+
}) => void;
|
|
11
|
+
immediateChange?: boolean;
|
|
12
|
+
onPickEnd?: AnyFunction;
|
|
13
|
+
maskClass?: string;
|
|
14
|
+
indicatorStyle?: string;
|
|
15
|
+
indicatorClass?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const PickerView: (props: PickerViewProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, cloneElement, useEffect, useRef } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { View } from '@tarojs/components';
|
|
5
|
+
import { useBem } from '../use';
|
|
6
|
+
import { PickerViewColumn } from './PickerViewColumn';
|
|
7
|
+
export { PickerViewColumn };
|
|
8
|
+
export const PickerView = (props) => {
|
|
9
|
+
const { children, className, value, onChange, immediateChange, maskClass, indicatorStyle, indicatorClass, ...restProps } = props;
|
|
10
|
+
const [bem] = useBem('picker');
|
|
11
|
+
const currentValue = useRef(value || []);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (value) {
|
|
14
|
+
currentValue.current = value;
|
|
15
|
+
}
|
|
16
|
+
}, [value]);
|
|
17
|
+
return (_jsx(View, { ...restProps, className: classNames(bem.e('wrapper'), className), children: Children.map(children, (element, i) => {
|
|
18
|
+
return cloneElement(element, {
|
|
19
|
+
value: value?.[i] || 0,
|
|
20
|
+
immediateChange,
|
|
21
|
+
maskClass,
|
|
22
|
+
indicatorStyle,
|
|
23
|
+
indicatorClass,
|
|
24
|
+
onChange(index) {
|
|
25
|
+
currentValue.current[i] = index;
|
|
26
|
+
const nextValue = currentValue.current.map((item) => item || 0);
|
|
27
|
+
currentValue.current = nextValue.slice();
|
|
28
|
+
onChange?.({
|
|
29
|
+
detail: {
|
|
30
|
+
value: nextValue,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}) }));
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PickerView, PickerViewColumn, } from '@tarojs/components';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export interface PickerViewColumnProps {
|
|
3
|
+
children?: ReactElement | ReactElement[];
|
|
4
|
+
indicatorHeight?: number;
|
|
5
|
+
value?: number;
|
|
6
|
+
onChange?: (value: number) => void;
|
|
7
|
+
immediateChange?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const PickerViewColumn: (props: PickerViewColumnProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, cloneElement, useEffect, useMemo, useRef, } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { View } from '@tarojs/components';
|
|
5
|
+
import { useBem, useEvent } from '../use';
|
|
6
|
+
import { isNullish, minmax } from '../utils';
|
|
7
|
+
import Halfline from '../halfline';
|
|
8
|
+
import { usePan } from '../pan-gesture-detector/usePan';
|
|
9
|
+
import PanGestureDetector from '../pan-gesture-detector';
|
|
10
|
+
import { createInertialMotion } from './InertialMotion';
|
|
11
|
+
export const PickerViewColumn = (props) => {
|
|
12
|
+
const { children, indicatorHeight = 48, value, onChange } = props;
|
|
13
|
+
const [bem] = useBem('picker');
|
|
14
|
+
const columns = Children.toArray(children);
|
|
15
|
+
const itemCount = columns.length;
|
|
16
|
+
const groupRef = useRef(null);
|
|
17
|
+
const currentIndex = useRef();
|
|
18
|
+
const setTranslate = useEvent((value) => {
|
|
19
|
+
if (groupRef.current) {
|
|
20
|
+
groupRef.current.style.transform = `translateY(${value}px) translateZ(0px)`;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const setDuration = (duration) => {
|
|
24
|
+
if (groupRef.current) {
|
|
25
|
+
groupRef.current.style.transitionDuration = `${duration}ms`;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const setBezier = (bezier) => {
|
|
29
|
+
if (groupRef.current) {
|
|
30
|
+
groupRef.current.style.transitionTimingFunction = bezier;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const setIndex = useEvent((index, emitChange = false, animated = false) => {
|
|
34
|
+
index = minmax(index, 0, itemCount - 1);
|
|
35
|
+
if (index === currentIndex.current) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const to = -index * indicatorHeight;
|
|
39
|
+
currentIndex.current = index;
|
|
40
|
+
motion.setCurrentOffsetY(to);
|
|
41
|
+
setDuration(animated ? 300 : 0);
|
|
42
|
+
setTranslate(to);
|
|
43
|
+
if (emitChange) {
|
|
44
|
+
onChange?.(index);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const handleStop = useEvent(() => {
|
|
48
|
+
setDuration(0);
|
|
49
|
+
if (groupRef.current) {
|
|
50
|
+
const offsetY = +window
|
|
51
|
+
.getComputedStyle(groupRef.current)
|
|
52
|
+
.getPropertyValue('transform')
|
|
53
|
+
.split(')')[0]
|
|
54
|
+
.split(', ')[5];
|
|
55
|
+
setTranslate(offsetY);
|
|
56
|
+
motion.setCurrentOffsetY(offsetY);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const handleReset = useEvent((offsetY, duration, bezier) => {
|
|
60
|
+
setTranslate(offsetY);
|
|
61
|
+
setDuration(duration);
|
|
62
|
+
setBezier(bezier);
|
|
63
|
+
});
|
|
64
|
+
const handleMotionEnd = useEvent((offsetY) => {
|
|
65
|
+
const index = Math.round(Math.abs(offsetY) / indicatorHeight);
|
|
66
|
+
const correctOffsetY = -index * indicatorHeight;
|
|
67
|
+
if (correctOffsetY !== offsetY) {
|
|
68
|
+
setDuration(300);
|
|
69
|
+
setTranslate(correctOffsetY);
|
|
70
|
+
motion.setCurrentOffsetY(correctOffsetY);
|
|
71
|
+
}
|
|
72
|
+
if (currentIndex.current !== index) {
|
|
73
|
+
currentIndex.current = index;
|
|
74
|
+
onChange?.(index);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const beforeMonmentum = useEvent((offsetY) => {
|
|
78
|
+
// inside
|
|
79
|
+
if (offsetY < 0 && offsetY > -(itemCount - 1) * indicatorHeight) {
|
|
80
|
+
const index = Math.round(Math.abs(offsetY) / indicatorHeight);
|
|
81
|
+
const correctOffsetY = -index * indicatorHeight;
|
|
82
|
+
if (currentIndex.current !== index) {
|
|
83
|
+
currentIndex.current = index;
|
|
84
|
+
onChange?.(index);
|
|
85
|
+
}
|
|
86
|
+
return correctOffsetY;
|
|
87
|
+
}
|
|
88
|
+
// outside
|
|
89
|
+
const index = offsetY > 0 ? 0 : itemCount - 1;
|
|
90
|
+
if (currentIndex.current !== index) {
|
|
91
|
+
currentIndex.current = index;
|
|
92
|
+
onChange?.(index);
|
|
93
|
+
}
|
|
94
|
+
return offsetY;
|
|
95
|
+
});
|
|
96
|
+
const handleMomentum = useEvent((offsetY, duration, bezier) => {
|
|
97
|
+
setTranslate(offsetY);
|
|
98
|
+
setDuration(duration);
|
|
99
|
+
setBezier(bezier);
|
|
100
|
+
});
|
|
101
|
+
const motion = useMemo(() => {
|
|
102
|
+
return createInertialMotion({
|
|
103
|
+
scrollHeight: indicatorHeight,
|
|
104
|
+
contentHeight: indicatorHeight * itemCount,
|
|
105
|
+
maxOverflowY: 0,
|
|
106
|
+
onStop: handleStop,
|
|
107
|
+
onMove: (offsetY) => {
|
|
108
|
+
setTranslate(offsetY);
|
|
109
|
+
},
|
|
110
|
+
onOutsideEnd: handleMotionEnd,
|
|
111
|
+
onInsideEnd: handleMotionEnd,
|
|
112
|
+
beforeMonmentum: beforeMonmentum,
|
|
113
|
+
onMomentum: handleMomentum,
|
|
114
|
+
onReset: handleReset,
|
|
115
|
+
});
|
|
116
|
+
}, []);
|
|
117
|
+
useMemo(() => {
|
|
118
|
+
motion.setSize(indicatorHeight, indicatorHeight * itemCount);
|
|
119
|
+
}, [indicatorHeight, itemCount]);
|
|
120
|
+
const handlers = usePan({
|
|
121
|
+
start(event) {
|
|
122
|
+
motion.onStart(event.y0);
|
|
123
|
+
},
|
|
124
|
+
move(event) {
|
|
125
|
+
motion.onMove(event.moveY);
|
|
126
|
+
},
|
|
127
|
+
end: motion.onEnd,
|
|
128
|
+
});
|
|
129
|
+
const handleItemClick = (index) => {
|
|
130
|
+
setIndex(index, true, true);
|
|
131
|
+
};
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (!isNullish(value)) {
|
|
134
|
+
setIndex(value, false, false);
|
|
135
|
+
}
|
|
136
|
+
}, [value]);
|
|
137
|
+
useEffect(() => motion.destroy, []);
|
|
138
|
+
return (_jsx(PanGestureDetector, { handlers: handlers, children: _jsxs(View, { className: bem.e('column'), children: [_jsx(View, { className: classNames(bem.e('mask'), bem.em('mask', 'top')) }), _jsxs(View, { className: bem.e('indicator'), style: { height: indicatorHeight + 'px' }, children: [_jsx(View, { className: bem.e('item-group'), ref: groupRef, children: Children.map(children, (element, i) => {
|
|
139
|
+
return cloneElement(element, {
|
|
140
|
+
onClick: () => handleItemClick(i),
|
|
141
|
+
});
|
|
142
|
+
}) }), _jsx(Halfline, { direction: "top" }), _jsx(Halfline, { direction: "bottom" })] }), _jsx(View, { className: classNames(bem.e('mask'), bem.em('mask', 'bottom')) })] }) }));
|
|
143
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export interface PickerViewColumnProps {
|
|
3
|
+
children?: ReactElement | ReactElement[];
|
|
4
|
+
indicatorHeight?: number;
|
|
5
|
+
value?: number;
|
|
6
|
+
onChange?: (value: number) => void;
|
|
7
|
+
immediateChange?: boolean;
|
|
8
|
+
maskClass?: string;
|
|
9
|
+
indicatorStyle?: string;
|
|
10
|
+
indicatorClass?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const PickerViewColumn: (props: PickerViewColumnProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, cloneElement, useEffect, useRef } from 'react';
|
|
3
|
+
import { View } from '@tarojs/components';
|
|
4
|
+
import { useBem, useEvent } from '../use';
|
|
5
|
+
import { animate, easeOutCubic, easeOutQuad, getDirectionByTwoPoints, getDistanceByTowPoints, getRectDampingValue, isNullish, minmax, } from '../utils';
|
|
6
|
+
import Halfline from '../halfline';
|
|
7
|
+
import { usePan } from '../pan-gesture-detector/usePan';
|
|
8
|
+
import PanGestureDetector from '../pan-gesture-detector';
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
// 回弹运动强度判断阈值,不超出边界无回弹,超出此值为强回弹,否则为弱回弹
|
|
11
|
+
const bounceThreshold = 300;
|
|
12
|
+
// 阻尼系数
|
|
13
|
+
const damping = 2;
|
|
14
|
+
// 回正运动时间
|
|
15
|
+
const correctDuration = 300;
|
|
16
|
+
// 惯性运动时间,会与速度相乘得到运动距离
|
|
17
|
+
const inertiaTime = 250;
|
|
18
|
+
// 允许超出边界的item数量
|
|
19
|
+
const maxOverflowCount = 2;
|
|
20
|
+
// 触发平移的最小距离
|
|
21
|
+
const panMinDistance = 5;
|
|
22
|
+
// 触发平移滑动的速度 px/ms
|
|
23
|
+
const panSwipeMinSpeed = 0.3;
|
|
24
|
+
const maxLastMoveCoordCount = 3;
|
|
25
|
+
// 不同回弹强度对应的运动时间
|
|
26
|
+
const mapBounceDuration = {
|
|
27
|
+
noBounce: 1000,
|
|
28
|
+
weekBounce: 650,
|
|
29
|
+
strongBounce: 500,
|
|
30
|
+
};
|
|
31
|
+
// 不同回弹强度对应的缓动公式
|
|
32
|
+
const mapBounceEase = {
|
|
33
|
+
noBounce: easeOutCubic,
|
|
34
|
+
weekBounce: easeOutQuad,
|
|
35
|
+
strongBounce: easeOutQuad,
|
|
36
|
+
};
|
|
37
|
+
// 不同回弹强度允许越出边界的距离(相对于item高度)
|
|
38
|
+
const mapBounceInertiaOverflowExtra = {
|
|
39
|
+
noBounce: 0,
|
|
40
|
+
weekBounce: 0.5,
|
|
41
|
+
strongBounce: 1,
|
|
42
|
+
};
|
|
43
|
+
export const PickerViewColumn = (props) => {
|
|
44
|
+
const { children, indicatorHeight = 48, value, onChange, immediateChange, maskClass, indicatorStyle, indicatorClass, } = props;
|
|
45
|
+
void maskClass;
|
|
46
|
+
void indicatorStyle;
|
|
47
|
+
void indicatorClass;
|
|
48
|
+
const [bem] = useBem('picker');
|
|
49
|
+
const columns = Children.toArray(children);
|
|
50
|
+
const itemCount = columns.length;
|
|
51
|
+
const isMoving = useRef(false);
|
|
52
|
+
const translate = useRef(0);
|
|
53
|
+
const downTranslate = useRef(0);
|
|
54
|
+
const stopInertia = useRef();
|
|
55
|
+
const stopCorrect = useRef();
|
|
56
|
+
const groupRef = useRef(null);
|
|
57
|
+
const currentIndex = useRef();
|
|
58
|
+
const setTranslate = (value) => {
|
|
59
|
+
translate.current = value;
|
|
60
|
+
if (groupRef.current) {
|
|
61
|
+
groupRef.current.style.transform = `translate3d(0, ${value}px, 0)`;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const changedAtLeastOnce = useRef(false);
|
|
65
|
+
const complete = (index, emitChange) => {
|
|
66
|
+
if (currentIndex.current !== index) {
|
|
67
|
+
currentIndex.current = index;
|
|
68
|
+
if (emitChange) {
|
|
69
|
+
changedAtLeastOnce.current = true;
|
|
70
|
+
onChange?.(index);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const toCorrectPosition = (to, animated = true, emitChange = true) => {
|
|
75
|
+
if (immediateChange) {
|
|
76
|
+
complete(Math.abs(to / indicatorHeight), emitChange);
|
|
77
|
+
}
|
|
78
|
+
stopCorrect.current = animate({
|
|
79
|
+
from: translate.current,
|
|
80
|
+
to,
|
|
81
|
+
duration: animated ? correctDuration : 0,
|
|
82
|
+
step(value) {
|
|
83
|
+
setTranslate(value);
|
|
84
|
+
},
|
|
85
|
+
finish(value) {
|
|
86
|
+
if (immediateChange) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
complete(Math.abs(value / indicatorHeight), emitChange);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
const getCurrentDampedVaule = (value, division = false) => {
|
|
94
|
+
return getRectDampingValue(value, indicatorHeight, indicatorHeight * itemCount, division ? 1 / damping || 0 : damping);
|
|
95
|
+
};
|
|
96
|
+
const setIndex = useEvent((index, emitChange = false, animated = false) => {
|
|
97
|
+
index = minmax(index, 0, columns.length - 1);
|
|
98
|
+
if (index === currentIndex.current) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
stopInertia.current?.();
|
|
102
|
+
stopCorrect.current?.();
|
|
103
|
+
const to = -index * indicatorHeight;
|
|
104
|
+
toCorrectPosition(to, animated, emitChange);
|
|
105
|
+
return true;
|
|
106
|
+
});
|
|
107
|
+
const handleTouchStart = useEvent(() => {
|
|
108
|
+
stopInertia.current?.();
|
|
109
|
+
stopCorrect.current?.();
|
|
110
|
+
downTranslate.current = getCurrentDampedVaule(translate.current);
|
|
111
|
+
});
|
|
112
|
+
const moveCoordQueue = useRef([]);
|
|
113
|
+
const handleTouchMove = useEvent((event) => {
|
|
114
|
+
moveCoordQueue.current.push({
|
|
115
|
+
x: event.moveX,
|
|
116
|
+
y: event.moveY,
|
|
117
|
+
time: Date.now(),
|
|
118
|
+
});
|
|
119
|
+
if (moveCoordQueue.current.length > maxLastMoveCoordCount) {
|
|
120
|
+
moveCoordQueue.current = moveCoordQueue.current.slice(-maxLastMoveCoordCount);
|
|
121
|
+
}
|
|
122
|
+
isMoving.current = true;
|
|
123
|
+
setTranslate(getCurrentDampedVaule(downTranslate.current + event.dy, true));
|
|
124
|
+
});
|
|
125
|
+
const swipeInfo = useRef({
|
|
126
|
+
direction: undefined,
|
|
127
|
+
speed: 0,
|
|
128
|
+
});
|
|
129
|
+
const isPanSwipe = () => {
|
|
130
|
+
const points = moveCoordQueue.current;
|
|
131
|
+
moveCoordQueue.current = [];
|
|
132
|
+
if (points.length >= 2) {
|
|
133
|
+
const point1 = points[0];
|
|
134
|
+
const point2 = points[points.length - 1];
|
|
135
|
+
const distance = getDistanceByTowPoints(point1, point2);
|
|
136
|
+
if (distance > panMinDistance) {
|
|
137
|
+
const speed = distance / (point2.time - point1.time);
|
|
138
|
+
if (speed >= panSwipeMinSpeed) {
|
|
139
|
+
const direction = getDirectionByTwoPoints(point1, point2);
|
|
140
|
+
swipeInfo.current = {
|
|
141
|
+
speed,
|
|
142
|
+
direction,
|
|
143
|
+
};
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const handlePanSwipe = () => {
|
|
150
|
+
const endEdge = (1 - itemCount) * indicatorHeight;
|
|
151
|
+
const isOverflow = translate.current > 0 || translate.current < endEdge;
|
|
152
|
+
if (isOverflow) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const direction = swipeInfo.current.direction === 'up' ? -1 : 1;
|
|
156
|
+
let to = translate.current + direction * (swipeInfo.current.speed * inertiaTime);
|
|
157
|
+
to = Math.round(to / indicatorHeight) * indicatorHeight;
|
|
158
|
+
let type = 'noBounce';
|
|
159
|
+
if (to > bounceThreshold || to < endEdge - bounceThreshold) {
|
|
160
|
+
type = 'strongBounce';
|
|
161
|
+
}
|
|
162
|
+
else if (to > 0 || to < endEdge) {
|
|
163
|
+
type = 'weekBounce';
|
|
164
|
+
}
|
|
165
|
+
const maxOverflow = maxOverflowCount * indicatorHeight;
|
|
166
|
+
to = minmax(to, endEdge - maxOverflow, maxOverflow);
|
|
167
|
+
if (immediateChange) {
|
|
168
|
+
complete(Math.abs(minmax(to, endEdge, 0) / indicatorHeight), true);
|
|
169
|
+
}
|
|
170
|
+
stopInertia.current = animate({
|
|
171
|
+
from: translate.current,
|
|
172
|
+
to,
|
|
173
|
+
duration: mapBounceDuration[type],
|
|
174
|
+
easing: mapBounceEase[type],
|
|
175
|
+
step(value) {
|
|
176
|
+
const extra = mapBounceInertiaOverflowExtra[type];
|
|
177
|
+
const withinTranslate = minmax(value, (1 - itemCount - extra) * indicatorHeight, extra * indicatorHeight);
|
|
178
|
+
if (value !== withinTranslate) {
|
|
179
|
+
stopInertia.current?.();
|
|
180
|
+
toCorrectPosition(withinTranslate >= 0 ? 0 : endEdge, true, !immediateChange);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
setTranslate(value);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
finish(value) {
|
|
187
|
+
if (value > 0 || value < endEdge) {
|
|
188
|
+
toCorrectPosition(value > 0 ? 0 : endEdge, true, !immediateChange);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
complete(Math.abs(value / indicatorHeight), !immediateChange);
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
const handleTouchEnd = useEvent(() => {
|
|
197
|
+
if (isMoving.current) {
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
isMoving.current = false;
|
|
200
|
+
}, 0);
|
|
201
|
+
}
|
|
202
|
+
const endEdge = (1 - itemCount) * indicatorHeight;
|
|
203
|
+
const isOverflow = translate.current > 0 || translate.current < endEdge;
|
|
204
|
+
if (isPanSwipe() && !isOverflow) {
|
|
205
|
+
handlePanSwipe();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
toCorrectPosition(Math.round(minmax(translate.current, endEdge, 0) / indicatorHeight) *
|
|
209
|
+
indicatorHeight);
|
|
210
|
+
});
|
|
211
|
+
const handlers = usePan({
|
|
212
|
+
start: handleTouchStart,
|
|
213
|
+
move: handleTouchMove,
|
|
214
|
+
end: handleTouchEnd,
|
|
215
|
+
});
|
|
216
|
+
const handleItemClick = (index) => {
|
|
217
|
+
if (isMoving.current) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
setIndex(index, true, true);
|
|
221
|
+
};
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
if (!isNullish(value)) {
|
|
224
|
+
setIndex(value, false, false);
|
|
225
|
+
}
|
|
226
|
+
}, [value]);
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
return () => {
|
|
229
|
+
stopInertia.current?.();
|
|
230
|
+
stopCorrect.current?.();
|
|
231
|
+
};
|
|
232
|
+
}, []);
|
|
233
|
+
return (_jsx(PanGestureDetector, { handlers: handlers, children: _jsxs(View, { className: bem.e('column'), children: [_jsx(View, { className: classNames(bem.e('mask')) }), _jsxs(View, { className: bem.e('indicator'), style: { height: indicatorHeight + 'px' }, children: [_jsx(View, { className: bem.e('item-group'), ref: groupRef, children: Children.map(children, (element, i) => {
|
|
234
|
+
return cloneElement(element, {
|
|
235
|
+
onClick: () => handleItemClick(i),
|
|
236
|
+
});
|
|
237
|
+
}) }), _jsx(Halfline, { direction: "top" }), _jsx(Halfline, { direction: "bottom" })] })] }) }));
|
|
238
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ForwardRefExoticComponent, RefAttributes, PropsWithoutRef } from 'react';
|
|
2
|
+
import { PickerViewProps } from './PickerView';
|
|
3
|
+
import { PopoutProps } from '../popout';
|
|
4
|
+
export * from './PickerView';
|
|
5
|
+
export interface PickerOptionKeys {
|
|
6
|
+
label?: string;
|
|
7
|
+
value?: string;
|
|
8
|
+
children?: string;
|
|
9
|
+
}
|
|
10
|
+
type PickerOptionObject = {
|
|
11
|
+
label?: string | number;
|
|
12
|
+
value?: string | number;
|
|
13
|
+
children?: PickerOption[];
|
|
14
|
+
[key: PropertyKey]: any;
|
|
15
|
+
};
|
|
16
|
+
export type PickerOption = PickerOptionObject | string | number;
|
|
17
|
+
export interface PickerProps extends Omit<PickerViewProps, 'value' | 'onChange'> {
|
|
18
|
+
columns?: PickerOption[] | PickerOption[][];
|
|
19
|
+
optionKeys?: PickerOptionKeys;
|
|
20
|
+
value?: any;
|
|
21
|
+
defaultValue?: any;
|
|
22
|
+
onChange?: (value: any, selectedOptions: PickerOption[], selectedIndex: number[]) => void;
|
|
23
|
+
withPopout?: boolean;
|
|
24
|
+
popoutProps?: PopoutProps;
|
|
25
|
+
outletFormatter?: (labels: (string | number)[]) => string;
|
|
26
|
+
}
|
|
27
|
+
export interface PickerRef {
|
|
28
|
+
getValueForcibly: () => any;
|
|
29
|
+
}
|
|
30
|
+
export interface PickerFC extends ForwardRefExoticComponent<PropsWithoutRef<PickerProps> & RefAttributes<PickerRef>> {
|
|
31
|
+
alwaysHasValue: boolean;
|
|
32
|
+
outletFormatter: typeof outletFormatter;
|
|
33
|
+
defaultOutletFormatter: typeof defaultOutletFormatter;
|
|
34
|
+
}
|
|
35
|
+
declare function defaultOutletFormatter(labels: (string | number)[]): string;
|
|
36
|
+
declare function outletFormatter(props: PickerProps, value: any): string;
|
|
37
|
+
export declare const Picker: PickerFC;
|
|
38
|
+
export default Picker;
|