react-native-system-ui 0.0.6 → 1.0.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/README.md +53 -30
- package/dist/cjs/components/action-sheet/ActionSheet.js +97 -105
- package/dist/cjs/components/action-sheet/tokens.js +16 -27
- package/dist/cjs/components/area/Area.js +54 -67
- package/dist/cjs/components/area/tokens.js +6 -3
- package/dist/cjs/components/avatar/Avatar.js +25 -23
- package/dist/cjs/components/badge/Badge.js +31 -31
- package/dist/cjs/components/badge/tokens.js +6 -8
- package/dist/cjs/components/button/Button.js +115 -151
- package/dist/cjs/components/button/ButtonGroup.js +8 -42
- package/dist/cjs/components/button/tokens.js +1 -8
- package/dist/cjs/components/calendar/Calendar.js +212 -223
- package/dist/cjs/components/calendar/tokens.js +3 -3
- package/dist/cjs/components/cascader/Cascader.js +177 -180
- package/dist/cjs/components/cascader/tokens.js +2 -2
- package/dist/cjs/components/cascader/useCascaderExtend.js +25 -29
- package/dist/cjs/components/cell/Cell.js +70 -83
- package/dist/cjs/components/cell/CellGroup.js +16 -29
- package/dist/cjs/components/checkbox/Checkbox.js +139 -132
- package/dist/cjs/components/checkbox/CheckboxGroup.js +4 -35
- package/dist/cjs/components/checkbox/tokens.js +7 -10
- package/dist/cjs/components/circle/Circle.js +25 -24
- package/dist/cjs/components/collapse/Collapse.js +75 -91
- package/dist/cjs/components/config-provider/ConfigProvider.js +16 -3
- package/dist/cjs/components/config-provider/DirectionContext.js +15 -0
- package/dist/cjs/components/config-provider/index.js +7 -0
- package/dist/cjs/components/config-provider/locale/en-US.js +32 -0
- package/dist/cjs/components/config-provider/locale/zh-CN.js +32 -0
- package/dist/cjs/components/config-provider/useDirection.js +16 -0
- package/dist/cjs/components/count-down/CountDown.js +20 -15
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +61 -84
- package/dist/cjs/components/datetime-picker/tokens.js +14 -3
- package/dist/cjs/components/dialog/Dialog.js +153 -121
- package/dist/cjs/components/dialog/imperative.js +17 -30
- package/dist/cjs/components/divider/Divider.js +26 -28
- package/dist/cjs/components/empty/Empty.js +35 -39
- package/dist/cjs/components/error-boundary/ErrorBoundary.js +73 -0
- package/dist/cjs/components/error-boundary/index.js +19 -0
- package/dist/cjs/components/field/Field.js +109 -106
- package/dist/cjs/components/flex/Flex.js +18 -18
- package/dist/cjs/components/flex/FlexItem.js +26 -27
- package/dist/cjs/components/form/Form.js +142 -161
- package/dist/cjs/components/form/FormItem.js +69 -97
- package/dist/cjs/components/form/FormList.js +49 -37
- package/dist/cjs/components/form/tokens.js +6 -3
- package/dist/cjs/components/form/utils.js +15 -34
- package/dist/cjs/components/grid/Grid.js +30 -29
- package/dist/cjs/components/grid/GridItem.js +84 -85
- package/dist/cjs/components/image/Image.js +55 -59
- package/dist/cjs/components/image/tokens.js +2 -2
- package/dist/cjs/components/image-preview/ImagePreview.js +124 -112
- package/dist/cjs/components/image-preview/imperative.js +4 -13
- package/dist/cjs/components/index.js +13 -0
- package/dist/cjs/components/input/Input.js +30 -22
- package/dist/cjs/components/loading/Loading.js +14 -15
- package/dist/cjs/components/nav-bar/NavBar.js +68 -83
- package/dist/cjs/components/nav-bar/tokens.js +1 -9
- package/dist/cjs/components/notice-bar/NoticeBar.js +74 -77
- package/dist/cjs/components/notify/Notify.js +88 -84
- package/dist/cjs/components/notify/imperative.js +20 -43
- package/dist/cjs/components/notify/tokens.js +1 -11
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +187 -209
- package/dist/cjs/components/overlay/Overlay.js +37 -52
- package/dist/cjs/components/overlay/tokens.js +5 -3
- package/dist/cjs/components/password-input/PasswordInput.js +98 -79
- package/dist/cjs/components/picker/Picker.js +440 -421
- package/dist/cjs/components/picker/tokens.js +1 -1
- package/dist/cjs/components/popup/Popup.js +263 -293
- package/dist/cjs/components/portal/Portal.js +12 -29
- package/dist/cjs/components/portal/PortalHost.js +151 -234
- package/dist/cjs/components/progress/Progress.js +51 -48
- package/dist/cjs/components/radio/Radio.js +45 -42
- package/dist/cjs/components/radio/RadioGroup.js +8 -40
- package/dist/cjs/components/radio/tokens.js +7 -10
- package/dist/cjs/components/safe-area-view/SafeAreaView.js +22 -26
- package/dist/cjs/components/search/Search.js +51 -43
- package/dist/cjs/components/selector/Selector.js +14 -13
- package/dist/cjs/components/share-sheet/ShareSheet.js +160 -161
- package/dist/cjs/components/sidebar/Sidebar.js +39 -45
- package/dist/cjs/components/sidebar/SidebarContext.js +1 -2
- package/dist/cjs/components/sidebar/SidebarItem.js +13 -16
- package/dist/cjs/components/sidebar/tokens.js +1 -3
- package/dist/cjs/components/skeleton/Skeleton.js +30 -37
- package/dist/cjs/components/skeleton/tokens.js +1 -2
- package/dist/cjs/components/slider/Slider.js +156 -135
- package/dist/cjs/components/space/Space.js +46 -69
- package/dist/cjs/components/stepper/Stepper.js +177 -155
- package/dist/cjs/components/swiper/Swiper.js +251 -253
- package/dist/cjs/components/swiper/SwiperPagIndicator.js +25 -27
- package/dist/cjs/components/swiper/tokens.js +10 -3
- package/dist/cjs/components/switch/Switch.js +13 -15
- package/dist/cjs/components/tabbar/Tabbar.js +35 -27
- package/dist/cjs/components/tabbar/TabbarContext.js +1 -2
- package/dist/cjs/components/tabbar/TabbarItem.js +65 -68
- package/dist/cjs/components/tabs/Tabs.js +286 -313
- package/dist/cjs/components/tag/Tag.js +46 -37
- package/dist/cjs/components/toast/Toast.js +90 -90
- package/dist/cjs/components/toast/imperative.js +16 -41
- package/dist/cjs/components/typography/Typography.js +3 -5
- package/dist/cjs/components/water-mark/WaterMark.js +31 -29
- package/dist/cjs/design-system/ThemeProvider.js +5 -11
- package/dist/cjs/design-system/createComponentTokensHook.js +11 -13
- package/dist/cjs/design-system/presets.js +2 -3
- package/dist/cjs/design-system/tokens.js +2 -11
- package/dist/cjs/hooks/animation/index.js +25 -0
- package/dist/cjs/hooks/animation/useAnimatedTransition.js +72 -0
- package/dist/cjs/hooks/animation/useReducedMotion.js +75 -0
- package/dist/cjs/hooks/aria/useAriaListBox.js +8 -16
- package/dist/cjs/hooks/aria/useAriaOverlay.js +3 -3
- package/dist/cjs/hooks/aria/useAriaPress.js +8 -21
- package/dist/cjs/hooks/aria/useAriaToggle.js +3 -3
- package/dist/cjs/hooks/gesture/useGestureScroll.js +60 -61
- package/dist/cjs/hooks/index.js +12 -0
- package/dist/cjs/hooks/overlay/OverlayStackStore.js +49 -69
- package/dist/cjs/hooks/overlay/useOverlayStack.js +13 -19
- package/dist/cjs/hooks/useControllableValue.js +10 -21
- package/dist/cjs/hooks/useCountDown.js +14 -22
- package/dist/cjs/hooks/useHairline.js +17 -29
- package/dist/cjs/hooks/useSafeAreaPadding.js +1 -4
- package/dist/cjs/index.js +67 -1
- package/dist/cjs/platform/animation.js +10 -2
- package/dist/cjs/platform/measure.js +18 -36
- package/dist/cjs/utils/color.js +21 -35
- package/dist/cjs/utils/compare.js +7 -12
- package/dist/cjs/utils/createPlatformShadow.js +28 -39
- package/dist/cjs/utils/date.js +20 -50
- package/dist/cjs/utils/deepMerge.js +16 -26
- package/dist/cjs/utils/hairline.js +74 -71
- package/dist/cjs/utils/index.js +22 -0
- package/dist/cjs/utils/number.js +21 -29
- package/dist/cjs/utils/render.js +27 -0
- package/dist/cjs/utils/rtl.js +25 -0
- package/dist/cjs/utils/string.js +8 -25
- package/dist/es/components/action-sheet/ActionSheet.js +99 -107
- package/dist/es/components/action-sheet/tokens.js +16 -27
- package/dist/es/components/area/Area.js +55 -68
- package/dist/es/components/area/tokens.js +6 -3
- package/dist/es/components/avatar/Avatar.js +25 -23
- package/dist/es/components/avatar/index.js +1 -2
- package/dist/es/components/badge/Badge.js +33 -33
- package/dist/es/components/badge/tokens.js +6 -8
- package/dist/es/components/button/Button.js +116 -152
- package/dist/es/components/button/ButtonGroup.js +9 -43
- package/dist/es/components/button/tokens.js +2 -3
- package/dist/es/components/calendar/Calendar.js +214 -225
- package/dist/es/components/calendar/tokens.js +3 -3
- package/dist/es/components/cascader/Cascader.js +180 -183
- package/dist/es/components/cascader/tokens.js +2 -2
- package/dist/es/components/cascader/useCascaderExtend.js +25 -29
- package/dist/es/components/cell/Cell.js +71 -84
- package/dist/es/components/cell/CellGroup.js +16 -28
- package/dist/es/components/checkbox/Checkbox.js +140 -133
- package/dist/es/components/checkbox/CheckboxGroup.js +5 -36
- package/dist/es/components/checkbox/tokens.js +7 -10
- package/dist/es/components/circle/Circle.js +25 -23
- package/dist/es/components/collapse/Collapse.js +77 -92
- package/dist/es/components/config-provider/ConfigProvider.js +10 -3
- package/dist/es/components/config-provider/DirectionContext.js +2 -0
- package/dist/es/components/config-provider/index.js +1 -0
- package/dist/es/components/config-provider/locale/en-US.js +32 -0
- package/dist/es/components/config-provider/locale/zh-CN.js +32 -0
- package/dist/es/components/config-provider/useDirection.js +3 -0
- package/dist/es/components/count-down/CountDown.js +23 -18
- package/dist/es/components/datetime-picker/DatetimePicker.js +61 -84
- package/dist/es/components/datetime-picker/tokens.js +14 -3
- package/dist/es/components/dialog/Dialog.js +154 -121
- package/dist/es/components/dialog/imperative.js +17 -30
- package/dist/es/components/divider/Divider.js +28 -29
- package/dist/es/components/empty/Empty.js +36 -39
- package/dist/es/components/error-boundary/ErrorBoundary.js +61 -0
- package/dist/es/components/error-boundary/index.js +1 -0
- package/dist/es/components/field/Field.js +109 -106
- package/dist/es/components/flex/Flex.js +18 -17
- package/dist/es/components/flex/FlexItem.js +27 -27
- package/dist/es/components/form/Form.js +143 -162
- package/dist/es/components/form/FormItem.js +68 -95
- package/dist/es/components/form/FormList.js +49 -37
- package/dist/es/components/form/tokens.js +6 -3
- package/dist/es/components/form/utils.js +15 -34
- package/dist/es/components/grid/Grid.js +30 -28
- package/dist/es/components/grid/GridItem.js +84 -84
- package/dist/es/components/image/Image.js +58 -62
- package/dist/es/components/image/tokens.js +2 -2
- package/dist/es/components/image-preview/ImagePreview.js +124 -112
- package/dist/es/components/image-preview/imperative.js +4 -13
- package/dist/es/components/index.js +3 -1
- package/dist/es/components/input/Input.js +31 -23
- package/dist/es/components/loading/Loading.js +16 -16
- package/dist/es/components/nav-bar/NavBar.js +68 -83
- package/dist/es/components/nav-bar/tokens.js +1 -3
- package/dist/es/components/notice-bar/NoticeBar.js +74 -76
- package/dist/es/components/notify/Notify.js +92 -87
- package/dist/es/components/notify/imperative.js +21 -44
- package/dist/es/components/notify/tokens.js +1 -5
- package/dist/es/components/number-keyboard/NumberKeyboard.js +187 -209
- package/dist/es/components/overlay/Overlay.js +36 -51
- package/dist/es/components/overlay/tokens.js +5 -3
- package/dist/es/components/password-input/PasswordInput.js +98 -79
- package/dist/es/components/picker/Picker.js +440 -421
- package/dist/es/components/picker/tokens.js +1 -1
- package/dist/es/components/popup/Popup.js +263 -292
- package/dist/es/components/portal/Portal.js +13 -29
- package/dist/es/components/portal/PortalHost.js +152 -234
- package/dist/es/components/progress/Progress.js +51 -48
- package/dist/es/components/radio/Radio.js +47 -44
- package/dist/es/components/radio/RadioGroup.js +10 -41
- package/dist/es/components/radio/tokens.js +7 -10
- package/dist/es/components/safe-area-view/SafeAreaView.js +22 -25
- package/dist/es/components/search/Search.js +52 -44
- package/dist/es/components/selector/Selector.js +14 -13
- package/dist/es/components/share-sheet/ShareSheet.js +162 -163
- package/dist/es/components/sidebar/Sidebar.js +41 -47
- package/dist/es/components/sidebar/SidebarContext.js +1 -2
- package/dist/es/components/sidebar/SidebarItem.js +13 -15
- package/dist/es/components/sidebar/tokens.js +1 -3
- package/dist/es/components/skeleton/Skeleton.js +30 -37
- package/dist/es/components/skeleton/tokens.js +1 -2
- package/dist/es/components/slider/Slider.js +156 -134
- package/dist/es/components/space/Space.js +48 -71
- package/dist/es/components/stepper/Stepper.js +178 -156
- package/dist/es/components/swiper/Swiper.js +252 -254
- package/dist/es/components/swiper/SwiperPagIndicator.js +25 -27
- package/dist/es/components/swiper/tokens.js +10 -3
- package/dist/es/components/switch/Switch.js +13 -15
- package/dist/es/components/tabbar/Tabbar.js +36 -28
- package/dist/es/components/tabbar/TabbarContext.js +1 -2
- package/dist/es/components/tabbar/TabbarItem.js +66 -69
- package/dist/es/components/tabs/Tabs.js +286 -313
- package/dist/es/components/tag/Tag.js +49 -39
- package/dist/es/components/toast/Toast.js +93 -91
- package/dist/es/components/toast/imperative.js +16 -41
- package/dist/es/components/typography/Typography.js +3 -5
- package/dist/es/components/water-mark/WaterMark.js +32 -30
- package/dist/es/design-system/ThemeProvider.js +5 -11
- package/dist/es/design-system/createComponentTokensHook.js +11 -13
- package/dist/es/design-system/presets.js +2 -3
- package/dist/es/design-system/tokens.js +1 -9
- package/dist/es/hooks/animation/index.js +2 -0
- package/dist/es/hooks/animation/useAnimatedTransition.js +53 -0
- package/dist/es/hooks/animation/useReducedMotion.js +54 -0
- package/dist/es/hooks/aria/useAriaListBox.js +8 -16
- package/dist/es/hooks/aria/useAriaOverlay.js +3 -3
- package/dist/es/hooks/aria/useAriaPress.js +8 -21
- package/dist/es/hooks/aria/useAriaToggle.js +3 -3
- package/dist/es/hooks/gesture/useGestureScroll.js +60 -61
- package/dist/es/hooks/index.js +1 -0
- package/dist/es/hooks/overlay/OverlayStackStore.js +49 -69
- package/dist/es/hooks/overlay/useOverlayStack.js +13 -19
- package/dist/es/hooks/useControllableValue.js +10 -21
- package/dist/es/hooks/useCountDown.js +14 -22
- package/dist/es/hooks/useHairline.js +16 -28
- package/dist/es/hooks/useSafeAreaPadding.js +1 -4
- package/dist/es/index.js +8 -1
- package/dist/es/platform/animation.js +9 -1
- package/dist/es/platform/measure.js +18 -36
- package/dist/es/utils/color.js +21 -35
- package/dist/es/utils/compare.js +7 -12
- package/dist/es/utils/createPlatformShadow.js +28 -39
- package/dist/es/utils/date.js +20 -50
- package/dist/es/utils/deepMerge.js +16 -26
- package/dist/es/utils/hairline.js +73 -65
- package/dist/es/utils/index.js +2 -0
- package/dist/es/utils/number.js +21 -29
- package/dist/es/utils/render.js +7 -0
- package/dist/es/utils/rtl.js +17 -0
- package/dist/es/utils/string.js +8 -25
- package/dist/types/components/action-sheet/ActionSheet.d.ts +1 -1
- package/dist/types/components/area/Area.d.ts +1 -1
- package/dist/types/components/area/tokens.d.ts +4 -0
- package/dist/types/components/avatar/Avatar.d.ts +1 -1
- package/dist/types/components/avatar/index.d.ts +1 -2
- package/dist/types/components/badge/Badge.d.ts +1 -1
- package/dist/types/components/button/Button.d.ts +1 -1
- package/dist/types/components/button/index.d.ts +1 -1
- package/dist/types/components/calendar/Calendar.d.ts +1 -1
- package/dist/types/components/cascader/Cascader.d.ts +1 -1
- package/dist/types/components/cell/Cell.d.ts +1 -1
- package/dist/types/components/cell/CellGroup.d.ts +1 -1
- package/dist/types/components/cell/index.d.ts +2 -2
- package/dist/types/components/checkbox/Checkbox.d.ts +1 -1
- package/dist/types/components/circle/Circle.d.ts +1 -1
- package/dist/types/components/collapse/Collapse.d.ts +1 -2
- package/dist/types/components/config-provider/DirectionContext.d.ts +3 -0
- package/dist/types/components/config-provider/index.d.ts +2 -1
- package/dist/types/components/config-provider/locale/en-US.d.ts +32 -0
- package/dist/types/components/config-provider/locale/zh-CN.d.ts +32 -0
- package/dist/types/components/config-provider/useDirection.d.ts +1 -0
- package/dist/types/components/count-down/CountDown.d.ts +1 -1
- package/dist/types/components/datetime-picker/DatetimePicker.d.ts +1 -1
- package/dist/types/components/datetime-picker/tokens.d.ts +12 -0
- package/dist/types/components/dialog/Dialog.d.ts +1 -1
- package/dist/types/components/divider/Divider.d.ts +1 -1
- package/dist/types/components/empty/Empty.d.ts +1 -1
- package/dist/types/components/error-boundary/ErrorBoundary.d.ts +6 -0
- package/dist/types/components/error-boundary/index.d.ts +2 -0
- package/dist/types/components/field/Field.d.ts +1 -1
- package/dist/types/components/flex/Flex.d.ts +1 -1
- package/dist/types/components/flex/FlexItem.d.ts +1 -1
- package/dist/types/components/flex/index.d.ts +2 -2
- package/dist/types/components/form/Form.d.ts +1 -1
- package/dist/types/components/form/FormItem.d.ts +2 -1
- package/dist/types/components/form/index.d.ts +2 -2
- package/dist/types/components/form/tokens.d.ts +4 -0
- package/dist/types/components/grid/Grid.d.ts +1 -1
- package/dist/types/components/grid/GridItem.d.ts +1 -1
- package/dist/types/components/grid/index.d.ts +2 -2
- package/dist/types/components/image/Image.d.ts +1 -1
- package/dist/types/components/image-preview/ImagePreview.d.ts +1 -1
- package/dist/types/components/index.d.ts +4 -1
- package/dist/types/components/input/Input.d.ts +3 -3
- package/dist/types/components/loading/Loading.d.ts +1 -1
- package/dist/types/components/nav-bar/NavBar.d.ts +1 -1
- package/dist/types/components/notice-bar/NoticeBar.d.ts +1 -1
- package/dist/types/components/notify/Notify.d.ts +2 -2
- package/dist/types/components/notify/index.d.ts +1 -1
- package/dist/types/components/overlay/Overlay.d.ts +1 -5
- package/dist/types/components/overlay/tokens.d.ts +3 -0
- package/dist/types/components/password-input/PasswordInput.d.ts +1 -1
- package/dist/types/components/picker/Picker.d.ts +5 -5
- package/dist/types/components/popup/Popup.d.ts +3 -42
- package/dist/types/components/portal/Portal.d.ts +9 -6
- package/dist/types/components/portal/PortalHost.d.ts +1 -1
- package/dist/types/components/radio/RadioGroup.d.ts +1 -1
- package/dist/types/components/safe-area-view/SafeAreaView.d.ts +1 -1
- package/dist/types/components/search/Search.d.ts +1 -1
- package/dist/types/components/share-sheet/ShareSheet.d.ts +1 -1
- package/dist/types/components/sidebar/Sidebar.d.ts +1 -1
- package/dist/types/components/sidebar/SidebarContext.d.ts +1 -1
- package/dist/types/components/sidebar/SidebarItem.d.ts +1 -1
- package/dist/types/components/sidebar/index.d.ts +2 -2
- package/dist/types/components/skeleton/Skeleton.d.ts +1 -1
- package/dist/types/components/slider/Slider.d.ts +1 -1
- package/dist/types/components/stepper/Stepper.d.ts +1 -1
- package/dist/types/components/swiper/Swiper.d.ts +1 -1
- package/dist/types/components/swiper/index.d.ts +1 -1
- package/dist/types/components/swiper/tokens.d.ts +8 -0
- package/dist/types/components/tabbar/Tabbar.d.ts +2 -2
- package/dist/types/components/tabbar/TabbarContext.d.ts +1 -1
- package/dist/types/components/tabbar/TabbarItem.d.ts +2 -2
- package/dist/types/components/tabs/Tabs.d.ts +1 -1
- package/dist/types/components/tabs/index.d.ts +1 -1
- package/dist/types/components/tag/Tag.d.ts +1 -1
- package/dist/types/components/toast/Toast.d.ts +2 -2
- package/dist/types/components/toast/index.d.ts +1 -1
- package/dist/types/components/water-mark/WaterMark.d.ts +1 -1
- package/dist/types/design-system/tokens.d.ts +0 -1
- package/dist/types/hooks/animation/index.d.ts +3 -0
- package/dist/types/hooks/animation/useAnimatedTransition.d.ts +13 -0
- package/dist/types/hooks/animation/useReducedMotion.d.ts +3 -0
- package/dist/types/hooks/aria/useAriaOverlay.d.ts +1 -1
- package/dist/types/hooks/gesture/useGestureScroll.d.ts +11 -10
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/overlay/OverlayStackStore.d.ts +8 -8
- package/dist/types/hooks/useHairline.d.ts +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/platform/animation.d.ts +8 -0
- package/dist/types/platform/measure.d.ts +1 -1
- package/dist/types/utils/compare.d.ts +1 -1
- package/dist/types/utils/createPlatformShadow.d.ts +2 -2
- package/dist/types/utils/date.d.ts +2 -2
- package/dist/types/utils/hairline.d.ts +5 -10
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/number.d.ts +2 -2
- package/dist/types/utils/render.d.ts +5 -0
- package/dist/types/utils/rtl.d.ts +5 -0
- package/package.json +10 -3
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { FlatList, Pressable, Text, View, useWindowDimensions } from "react-native";
|
|
4
4
|
import { Checked, Cross } from "react-native-system-icon";
|
|
5
5
|
import { useControllableValue } from "../../hooks";
|
|
6
|
-
import { shallowEqualArray } from "../../utils";
|
|
7
|
-
import { isFunction, isNumber,
|
|
6
|
+
import { shallowEqualArray, renderTextOrNode } from "../../utils";
|
|
7
|
+
import { isFunction, isNumber, isText } from "../../utils/validate";
|
|
8
8
|
import Popup from "../popup";
|
|
9
9
|
import Tabs from "../tabs";
|
|
10
|
+
import { useLocale } from "../config-provider/useLocale";
|
|
10
11
|
import { useCascaderTokens } from "./tokens";
|
|
11
12
|
import { useCascaderExtend } from "./useCascaderExtend";
|
|
12
13
|
const getFieldKeys = fieldNames => ({
|
|
@@ -14,29 +15,29 @@ const getFieldKeys = fieldNames => ({
|
|
|
14
15
|
valueKey: fieldNames?.value ?? "value",
|
|
15
16
|
childrenKey: fieldNames?.children ?? "children"
|
|
16
17
|
});
|
|
17
|
-
const
|
|
18
|
+
const resolveRows = (options = [], keys, values) => {
|
|
18
19
|
const selected = [];
|
|
19
20
|
let current = options;
|
|
20
|
-
|
|
21
|
+
values.forEach(val => {
|
|
21
22
|
if (!current || !current.length) return;
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
selected.push(
|
|
25
|
-
current =
|
|
23
|
+
const matched = current.find(o => o[keys.valueKey] === val);
|
|
24
|
+
if (matched) {
|
|
25
|
+
selected.push(matched);
|
|
26
|
+
current = matched[keys.childrenKey] ?? [];
|
|
26
27
|
}
|
|
27
28
|
});
|
|
28
29
|
return selected;
|
|
29
30
|
};
|
|
30
|
-
const
|
|
31
|
+
const CascaderImpl = props => {
|
|
31
32
|
const {
|
|
32
33
|
tokensOverride,
|
|
33
34
|
options = [],
|
|
34
|
-
title
|
|
35
|
-
placeholder
|
|
36
|
-
activeColor
|
|
35
|
+
title,
|
|
36
|
+
placeholder,
|
|
37
|
+
activeColor,
|
|
37
38
|
fieldNames,
|
|
38
39
|
optionRender,
|
|
39
|
-
showHeader
|
|
40
|
+
showHeader,
|
|
40
41
|
closeable,
|
|
41
42
|
closeIcon,
|
|
42
43
|
onChange,
|
|
@@ -44,54 +45,55 @@ const Cascader = props => {
|
|
|
44
45
|
onFinish,
|
|
45
46
|
onClickTab,
|
|
46
47
|
onTabChange,
|
|
47
|
-
swipeable
|
|
48
|
+
swipeable,
|
|
48
49
|
style,
|
|
49
50
|
testID,
|
|
50
51
|
children,
|
|
51
|
-
poppable
|
|
52
|
+
poppable,
|
|
52
53
|
visible: _visible,
|
|
53
54
|
defaultVisible: _defaultVisible,
|
|
54
55
|
onVisibleChange: _onVisibleChange,
|
|
55
|
-
closeOnClickOverlay
|
|
56
|
-
closeOnFinish
|
|
57
|
-
popupPlacement
|
|
58
|
-
popupRound
|
|
59
|
-
popupProps
|
|
60
|
-
loadingText
|
|
56
|
+
closeOnClickOverlay,
|
|
57
|
+
closeOnFinish,
|
|
58
|
+
popupPlacement,
|
|
59
|
+
popupRound,
|
|
60
|
+
popupProps,
|
|
61
|
+
loadingText,
|
|
61
62
|
...rest
|
|
62
63
|
} = props;
|
|
64
|
+
const locale = useLocale();
|
|
63
65
|
const tokens = useCascaderTokens(tokensOverride);
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
66
|
+
const resolvedTitle = title ?? locale?.vanCascader?.placeholder ?? tokens.defaults.title;
|
|
67
|
+
const resolvedPlaceholder = placeholder ?? locale?.vanCascader?.placeholder ?? tokens.defaults.placeholder;
|
|
68
|
+
const resolvedActiveColor = activeColor ?? tokens.colors.tabActive;
|
|
69
|
+
const resolvedShowHeader = showHeader ?? tokens.defaults.showHeader;
|
|
70
|
+
const resolvedSwipeable = swipeable ?? tokens.defaults.swipeable;
|
|
71
|
+
const resolvedPoppable = poppable ?? tokens.defaults.poppable;
|
|
72
|
+
const resolvedCloseOnClickOverlay = closeOnClickOverlay ?? tokens.defaults.closeOnClickOverlay;
|
|
73
|
+
const resolvedCloseOnFinish = closeOnFinish ?? tokens.defaults.closeOnFinish;
|
|
74
|
+
const resolvedPopupPlacement = popupPlacement ?? tokens.defaults.popupPlacement;
|
|
75
|
+
const resolvedPopupRound = popupRound ?? tokens.defaults.popupRound;
|
|
76
|
+
const resolvedLoadingText = loadingText ?? tokens.defaults.loadingText;
|
|
75
77
|
const [value, setValue] = useControllableValue(props, {
|
|
76
78
|
defaultValue: [],
|
|
77
79
|
trigger: "onChange"
|
|
78
80
|
});
|
|
79
81
|
const keys = getFieldKeys(fieldNames);
|
|
80
|
-
const
|
|
81
|
-
const [
|
|
82
|
-
const
|
|
82
|
+
const currentValue = Array.isArray(value) ? value : [];
|
|
83
|
+
const [pendingValue, setPendingValue] = useState(currentValue);
|
|
84
|
+
const showClose = closeable ?? tokens.defaults.closeable;
|
|
83
85
|
const [popupVisible, setPopupVisible] = useControllableValue(props, {
|
|
84
86
|
defaultValue: false,
|
|
85
87
|
valuePropName: "visible",
|
|
86
88
|
defaultValuePropName: "defaultVisible",
|
|
87
89
|
trigger: "onVisibleChange"
|
|
88
90
|
});
|
|
89
|
-
const
|
|
91
|
+
const current = resolvedPoppable ? pendingValue : currentValue;
|
|
90
92
|
const {
|
|
91
93
|
tabs,
|
|
92
94
|
items,
|
|
93
95
|
depth
|
|
94
|
-
} = useCascaderExtend(options, keys,
|
|
96
|
+
} = useCascaderExtend(options, keys, current);
|
|
95
97
|
const {
|
|
96
98
|
width: windowWidth
|
|
97
99
|
} = useWindowDimensions();
|
|
@@ -101,105 +103,105 @@ const Cascader = props => {
|
|
|
101
103
|
if (!width) return;
|
|
102
104
|
setMeasuredWidth(prev => prev === width ? prev : width);
|
|
103
105
|
}, []);
|
|
104
|
-
const
|
|
106
|
+
const currentRows = resolveRows(options, keys, currentValue);
|
|
105
107
|
const [activeTab, setActiveTab] = useState(0);
|
|
106
108
|
useEffect(() => {
|
|
107
|
-
const currentLength = Array.isArray(
|
|
109
|
+
const currentLength = Array.isArray(current) ? current.length : 0;
|
|
108
110
|
let tabIndex = currentLength;
|
|
109
111
|
if (tabIndex >= depth) tabIndex = Math.max(depth - 1, 0);
|
|
110
112
|
setActiveTab(prev => prev === tabIndex ? prev : tabIndex);
|
|
111
|
-
}, [
|
|
113
|
+
}, [current.length, depth]);
|
|
112
114
|
useEffect(() => {
|
|
113
|
-
if (!
|
|
114
|
-
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (!popupVisible) {
|
|
118
|
-
setPanelValue(prev => shallowEqualArray(prev, cascaderValue) ? prev : cascaderValue);
|
|
119
|
-
}
|
|
120
|
-
}, [cascaderValue, poppable, popupVisible]);
|
|
115
|
+
if (!resolvedPoppable || !popupVisible) setPendingValue(prev => shallowEqualArray(prev, currentValue) ? prev : currentValue);
|
|
116
|
+
}, [currentValue, resolvedPoppable, popupVisible]);
|
|
121
117
|
const openPopup = useCallback(() => {
|
|
122
|
-
if (!
|
|
123
|
-
|
|
118
|
+
if (!resolvedPoppable || popupVisible) return;
|
|
119
|
+
setPendingValue(prev => shallowEqualArray(prev, currentValue) ? prev : currentValue);
|
|
124
120
|
setPopupVisible(true);
|
|
125
|
-
}, [
|
|
121
|
+
}, [currentValue, resolvedPoppable, popupVisible, setPopupVisible]);
|
|
122
|
+
const onCloseRef = useRef(onClose),
|
|
123
|
+
onChangeRef = useRef(onChange),
|
|
124
|
+
onFinishRef = useRef(onFinish),
|
|
125
|
+
onClickTabRef = useRef(onClickTab),
|
|
126
|
+
onTabChangeRef = useRef(onTabChange);
|
|
127
|
+
onCloseRef.current = onClose;
|
|
128
|
+
onChangeRef.current = onChange;
|
|
129
|
+
onFinishRef.current = onFinish;
|
|
130
|
+
onClickTabRef.current = onClickTab;
|
|
131
|
+
onTabChangeRef.current = onTabChange;
|
|
126
132
|
const closePopup = useCallback(notify => {
|
|
127
|
-
if (!
|
|
133
|
+
if (!resolvedPoppable || !popupVisible) return;
|
|
128
134
|
setPopupVisible(false);
|
|
129
|
-
if (notify)
|
|
130
|
-
}, [
|
|
135
|
+
if (notify) onCloseRef.current?.();
|
|
136
|
+
}, [resolvedPoppable, popupVisible, setPopupVisible]);
|
|
131
137
|
const togglePopup = useCallback(() => {
|
|
132
|
-
if (!
|
|
138
|
+
if (!resolvedPoppable) return;
|
|
133
139
|
popupVisible ? closePopup(true) : openPopup();
|
|
134
|
-
}, [closePopup, openPopup,
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const handleClickTab = useCallback(
|
|
138
|
-
const index = isNumber(
|
|
140
|
+
}, [closePopup, openPopup, resolvedPoppable, popupVisible]);
|
|
141
|
+
const isRenderProps = isFunction(children);
|
|
142
|
+
const renderProps = isRenderProps ? children : null;
|
|
143
|
+
const handleClickTab = useCallback(e => {
|
|
144
|
+
const index = isNumber(e.index) ? e.index : Number(e.name);
|
|
139
145
|
if (Number.isNaN(index)) return;
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
}, [items, keys.textKey,
|
|
144
|
-
const handleTabChange = useCallback((tabValue,
|
|
145
|
-
const index = isNumber(
|
|
146
|
+
const tabName = items[index]?.[keys.textKey];
|
|
147
|
+
const tabText = isText(tabName) ? String(tabName) : resolvedPlaceholder;
|
|
148
|
+
onClickTabRef.current?.(index, tabText);
|
|
149
|
+
}, [items, keys.textKey, resolvedPlaceholder]);
|
|
150
|
+
const handleTabChange = useCallback((tabValue, indexExplicit) => {
|
|
151
|
+
const index = isNumber(indexExplicit) ? indexExplicit : Number(tabValue);
|
|
146
152
|
if (Number.isNaN(index)) return;
|
|
147
153
|
setActiveTab(index);
|
|
148
|
-
|
|
149
|
-
}, [
|
|
154
|
+
onTabChangeRef.current?.(index);
|
|
155
|
+
}, []);
|
|
150
156
|
const handleSelect = useCallback((option, tabIndex) => {
|
|
151
157
|
if (option.disabled) return;
|
|
152
158
|
const optionValue = option[keys.valueKey];
|
|
153
|
-
if (optionValue
|
|
154
|
-
const base = (
|
|
159
|
+
if (optionValue == null) return;
|
|
160
|
+
const base = (resolvedPoppable ? pendingValue : currentValue).slice(0, tabIndex);
|
|
155
161
|
const nextValue = [...base, optionValue];
|
|
156
|
-
const rows =
|
|
157
|
-
const
|
|
162
|
+
const rows = resolveRows(options, keys, nextValue);
|
|
163
|
+
const children = option[keys.childrenKey] ?? [];
|
|
158
164
|
const hasChildrenProp = Object.prototype.hasOwnProperty.call(option, keys.childrenKey);
|
|
159
|
-
const hasChildren =
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const isLeaf = !hasChildren && !
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
} else
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (isLeaf || reachDepth) {
|
|
170
|
-
if (poppable) {
|
|
165
|
+
const hasChildren = children.length > 0;
|
|
166
|
+
const isAsync = hasChildrenProp && !hasChildren;
|
|
167
|
+
const reachedDepth = nextValue.length >= depth;
|
|
168
|
+
const isLeaf = !hasChildren && !isAsync;
|
|
169
|
+
if (resolvedPoppable) {
|
|
170
|
+
setPendingValue(nextValue);
|
|
171
|
+
onChangeRef.current?.(nextValue, rows);
|
|
172
|
+
} else setValue(nextValue, rows);
|
|
173
|
+
if (isLeaf || reachedDepth) {
|
|
174
|
+
if (resolvedPoppable) {
|
|
171
175
|
setValue(nextValue, rows);
|
|
172
|
-
if (
|
|
176
|
+
if (resolvedCloseOnFinish) closePopup(true);
|
|
173
177
|
}
|
|
174
|
-
|
|
178
|
+
onFinishRef.current?.(nextValue, rows);
|
|
175
179
|
}
|
|
176
|
-
}, [
|
|
180
|
+
}, [currentValue, resolvedCloseOnFinish, closePopup, depth, keys, options, pendingValue, resolvedPoppable, setValue]);
|
|
177
181
|
const getEmptyText = useCallback(tabIndex => {
|
|
178
|
-
if (tabIndex <= 0) return
|
|
182
|
+
if (tabIndex <= 0) return resolvedPlaceholder;
|
|
179
183
|
const parent = items[tabIndex - 1];
|
|
180
|
-
if (!parent) return
|
|
184
|
+
if (!parent) return resolvedPlaceholder;
|
|
181
185
|
const hasChildrenProp = Object.prototype.hasOwnProperty.call(parent, keys.childrenKey);
|
|
182
|
-
if (!hasChildrenProp) return
|
|
186
|
+
if (!hasChildrenProp) return resolvedPlaceholder;
|
|
183
187
|
const children = parent[keys.childrenKey] ?? [];
|
|
184
|
-
const
|
|
185
|
-
return
|
|
186
|
-
}, [
|
|
188
|
+
const isAsync = children.length === 0 && current.length === tabIndex;
|
|
189
|
+
return isAsync ? resolvedLoadingText : resolvedPlaceholder;
|
|
190
|
+
}, [current.length, items, keys.childrenKey, resolvedLoadingText, resolvedPlaceholder]);
|
|
187
191
|
const renderTabs = () => {
|
|
188
|
-
if (!tabs.length) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const swipeableEnabled = !!swipeable;
|
|
202
|
-
const resolvedTabsWidth = measuredWidth || windowWidth || undefined;
|
|
192
|
+
if (!tabs.length) return /*#__PURE__*/React.createElement(CascaderOptionList, {
|
|
193
|
+
optionList: [],
|
|
194
|
+
tabIndex: 0,
|
|
195
|
+
selectedValue: current[0],
|
|
196
|
+
activeColor: resolvedActiveColor,
|
|
197
|
+
keys: keys,
|
|
198
|
+
optionRender: optionRender,
|
|
199
|
+
onSelect: handleSelect,
|
|
200
|
+
tokens: tokens,
|
|
201
|
+
emptyText: getEmptyText(0)
|
|
202
|
+
});
|
|
203
|
+
const swipeEnabled = !!resolvedSwipeable;
|
|
204
|
+
const renderTabsWidth = measuredWidth || windowWidth || undefined;
|
|
203
205
|
const tabBarStyle = {
|
|
204
206
|
height: tokens.sizing.headerHeight,
|
|
205
207
|
paddingHorizontal: tokens.spacing.tabNavPaddingHorizontal,
|
|
@@ -210,19 +212,19 @@ const Cascader = props => {
|
|
|
210
212
|
style: tokens.layout.tabsWrapper,
|
|
211
213
|
onLayout: handleTabsLayout
|
|
212
214
|
}, /*#__PURE__*/React.createElement(Tabs, {
|
|
213
|
-
style:
|
|
214
|
-
width:
|
|
215
|
+
style: renderTabsWidth ? {
|
|
216
|
+
width: renderTabsWidth
|
|
215
217
|
} : undefined,
|
|
216
218
|
active: activeTab,
|
|
217
219
|
onChange: handleTabChange,
|
|
218
220
|
onClickTab: handleClickTab,
|
|
219
221
|
align: "center",
|
|
220
|
-
swipeable:
|
|
222
|
+
swipeable: swipeEnabled,
|
|
221
223
|
swipeThreshold: 0,
|
|
222
224
|
scrollable: true,
|
|
223
225
|
animated: true,
|
|
224
226
|
duration: 300,
|
|
225
|
-
color:
|
|
227
|
+
color: resolvedActiveColor,
|
|
226
228
|
lineHeight: tokens.sizing.indicatorHeight,
|
|
227
229
|
titleActiveColor: tokens.colors.tabText,
|
|
228
230
|
titleInactiveColor: tokens.colors.tabInactive,
|
|
@@ -233,66 +235,60 @@ const Cascader = props => {
|
|
|
233
235
|
titleStyle: [tokens.layout.tabsTitle, {
|
|
234
236
|
fontSize: tokens.typography.tabsTitleSize
|
|
235
237
|
}],
|
|
236
|
-
contentStyle: !
|
|
237
|
-
}, tabs.map((optionList,
|
|
238
|
-
const selectedOption = items[
|
|
238
|
+
contentStyle: !swipeEnabled ? tokens.layout.tabsContentStatic : undefined
|
|
239
|
+
}, tabs.map((optionList, i) => {
|
|
240
|
+
const selectedOption = items[i];
|
|
239
241
|
const labelValue = selectedOption?.[keys.textKey];
|
|
240
|
-
const
|
|
241
|
-
const
|
|
242
|
-
const titleNode =
|
|
242
|
+
const label = isText(labelValue) ? String(labelValue) : "";
|
|
243
|
+
const usePlaceholder = !label;
|
|
244
|
+
const titleNode = _ => /*#__PURE__*/React.createElement(Text, {
|
|
243
245
|
style: [tokens.layout.tabTitleNode, {
|
|
244
|
-
color:
|
|
245
|
-
fontWeight:
|
|
246
|
+
color: usePlaceholder ? tokens.colors.tabInactive : tokens.colors.tabText,
|
|
247
|
+
fontWeight: usePlaceholder ? tokens.typography.tabTitlePlaceholderWeight : tokens.typography.tabTitleWeight
|
|
246
248
|
}]
|
|
247
|
-
},
|
|
249
|
+
}, usePlaceholder ? resolvedPlaceholder : label);
|
|
248
250
|
return /*#__PURE__*/React.createElement(Tabs.TabPane, {
|
|
249
|
-
key:
|
|
250
|
-
name:
|
|
251
|
+
key: i,
|
|
252
|
+
name: i,
|
|
251
253
|
title: titleNode
|
|
252
254
|
}, /*#__PURE__*/React.createElement(CascaderOptionList, {
|
|
253
255
|
optionList: optionList,
|
|
254
|
-
tabIndex:
|
|
255
|
-
selectedValue:
|
|
256
|
-
activeColor:
|
|
256
|
+
tabIndex: i,
|
|
257
|
+
selectedValue: current[i],
|
|
258
|
+
activeColor: resolvedActiveColor,
|
|
257
259
|
keys: keys,
|
|
258
260
|
optionRender: optionRender,
|
|
259
261
|
onSelect: handleSelect,
|
|
260
262
|
tokens: tokens,
|
|
261
|
-
emptyText: getEmptyText(
|
|
263
|
+
emptyText: getEmptyText(i)
|
|
262
264
|
}));
|
|
263
265
|
})));
|
|
264
266
|
};
|
|
265
|
-
const inlineChildren = !
|
|
267
|
+
const inlineChildren = !resolvedPoppable && !isRenderProps ? children : null;
|
|
266
268
|
const content = /*#__PURE__*/React.createElement(View, _extends({
|
|
267
269
|
testID: testID,
|
|
268
270
|
style: [tokens.layout.container, {
|
|
269
271
|
backgroundColor: tokens.colors.background
|
|
270
272
|
}, style]
|
|
271
|
-
}, rest),
|
|
273
|
+
}, rest), resolvedShowHeader ? /*#__PURE__*/React.createElement(View, {
|
|
272
274
|
style: [tokens.layout.header, {
|
|
273
275
|
height: tokens.sizing.headerHeight,
|
|
274
276
|
paddingHorizontal: tokens.spacing.headerPaddingHorizontal
|
|
275
277
|
}]
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}]
|
|
282
|
-
}, title) : title, resolvedCloseable ? /*#__PURE__*/React.createElement(Pressable, {
|
|
278
|
+
}, renderTextOrNode(resolvedTitle, [tokens.layout.title, {
|
|
279
|
+
color: tokens.colors.headerText,
|
|
280
|
+
fontSize: tokens.typography.titleSize,
|
|
281
|
+
fontWeight: tokens.typography.titleWeight
|
|
282
|
+
}]), showClose ? /*#__PURE__*/React.createElement(Pressable, {
|
|
283
283
|
hitSlop: 8,
|
|
284
284
|
onPress: () => {
|
|
285
|
-
if (
|
|
286
|
-
closePopup(true);
|
|
287
|
-
} else {
|
|
288
|
-
onClose?.();
|
|
289
|
-
}
|
|
285
|
+
if (resolvedPoppable) closePopup(true);else onCloseRef.current?.();
|
|
290
286
|
},
|
|
291
287
|
style: [tokens.layout.closeButton, {
|
|
292
288
|
marginLeft: tokens.spacing.closeButtonMarginLeft
|
|
293
289
|
}],
|
|
294
290
|
accessibilityRole: "button",
|
|
295
|
-
accessibilityLabel:
|
|
291
|
+
accessibilityLabel: locale?.vanCascader?.close ?? 'Close'
|
|
296
292
|
}, closeIcon ?? (state => /*#__PURE__*/React.createElement(Cross, {
|
|
297
293
|
size: tokens.sizing.closeIconSize,
|
|
298
294
|
fill: state.pressed ? tokens.colors.closeIconActive : tokens.colors.closeIcon,
|
|
@@ -303,19 +299,25 @@ const Cascader = props => {
|
|
|
303
299
|
paddingHorizontal: tokens.spacing.headerPaddingHorizontal
|
|
304
300
|
}]
|
|
305
301
|
}, inlineChildren) : null);
|
|
306
|
-
if (!
|
|
302
|
+
if (!resolvedPoppable) return content;
|
|
307
303
|
const {
|
|
308
|
-
closeOnOverlayPress:
|
|
304
|
+
closeOnOverlayPress: overlayCloseOnPress,
|
|
309
305
|
overlay: popupOverlay,
|
|
310
306
|
onOpen: popupOnOpen,
|
|
311
307
|
onOpened: popupOnOpened,
|
|
312
308
|
onClose: popupOnClose,
|
|
313
309
|
onClosed: popupOnClosed,
|
|
314
310
|
...popupRestProps
|
|
315
|
-
} =
|
|
316
|
-
const
|
|
317
|
-
const
|
|
318
|
-
const
|
|
311
|
+
} = popupProps ?? {};
|
|
312
|
+
const renderOverlay = popupOverlay ?? true;
|
|
313
|
+
const renderCloseOnPress = overlayCloseOnPress ?? resolvedCloseOnClickOverlay;
|
|
314
|
+
const popupOnCloseRef = useRef(popupOnClose);
|
|
315
|
+
popupOnCloseRef.current = popupOnClose;
|
|
316
|
+
const handlePopupClose = useCallback(() => {
|
|
317
|
+
popupOnCloseRef.current?.();
|
|
318
|
+
closePopup(true);
|
|
319
|
+
}, [closePopup]);
|
|
320
|
+
const controlActions = {
|
|
319
321
|
open: openPopup,
|
|
320
322
|
close: () => closePopup(true),
|
|
321
323
|
toggle: togglePopup
|
|
@@ -333,22 +335,19 @@ const Cascader = props => {
|
|
|
333
335
|
onClick: handlePress
|
|
334
336
|
});
|
|
335
337
|
}, [openPopup]);
|
|
336
|
-
const triggerNode =
|
|
337
|
-
const
|
|
338
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
338
|
+
const triggerNode = renderProps ? renderProps(currentValue, currentRows, controlActions) : isRenderProps ? null : children || null;
|
|
339
|
+
const renderTriggerNode = enhanceTriggerNode(triggerNode);
|
|
340
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, renderTriggerNode, /*#__PURE__*/React.createElement(Popup, _extends({
|
|
339
341
|
visible: popupVisible,
|
|
340
|
-
placement:
|
|
341
|
-
round:
|
|
342
|
-
closeOnOverlayPress:
|
|
343
|
-
overlay:
|
|
344
|
-
safeAreaInsetTop: popupRestProps?.safeAreaInsetTop
|
|
345
|
-
safeAreaInsetBottom: popupRestProps?.safeAreaInsetBottom
|
|
342
|
+
placement: resolvedPopupPlacement,
|
|
343
|
+
round: resolvedPopupRound,
|
|
344
|
+
closeOnOverlayPress: renderCloseOnPress,
|
|
345
|
+
overlay: renderOverlay,
|
|
346
|
+
safeAreaInsetTop: popupRestProps?.safeAreaInsetTop != null ? popupRestProps.safeAreaInsetTop : resolvedShowHeader && showClose,
|
|
347
|
+
safeAreaInsetBottom: popupRestProps?.safeAreaInsetBottom != null ? popupRestProps.safeAreaInsetBottom : resolvedPopupPlacement === 'bottom',
|
|
346
348
|
onOpen: popupOnOpen,
|
|
347
349
|
onOpened: popupOnOpened,
|
|
348
|
-
onClose:
|
|
349
|
-
popupOnClose?.();
|
|
350
|
-
closePopup(true);
|
|
351
|
-
},
|
|
350
|
+
onClose: handlePopupClose,
|
|
352
351
|
onClosed: popupOnClosed
|
|
353
352
|
}, popupRestProps, {
|
|
354
353
|
style: {
|
|
@@ -372,17 +371,16 @@ const CascaderOptionItem = /*#__PURE__*/React.memo(({
|
|
|
372
371
|
const disabled = !!option.disabled;
|
|
373
372
|
const baseColor = option.color ?? tokens.colors.optionText;
|
|
374
373
|
const textColor = disabled ? tokens.colors.optionDisabled : selected ? option.color ?? activeColor : baseColor;
|
|
374
|
+
const optionTextStyle = [tokens.layout.optionText, {
|
|
375
|
+
color: textColor,
|
|
376
|
+
fontSize: tokens.typography.optionTextSize
|
|
377
|
+
}, selected ? {
|
|
378
|
+
fontWeight: tokens.typography.optionTextActiveWeight
|
|
379
|
+
} : null];
|
|
375
380
|
const content = optionRender ? optionRender({
|
|
376
381
|
option,
|
|
377
382
|
selected
|
|
378
|
-
}) :
|
|
379
|
-
style: [tokens.layout.optionText, {
|
|
380
|
-
color: textColor,
|
|
381
|
-
fontSize: tokens.typography.optionTextSize
|
|
382
|
-
}, selected && {
|
|
383
|
-
fontWeight: tokens.typography.optionTextActiveWeight
|
|
384
|
-
}]
|
|
385
|
-
}, label) : isRenderable(label) ? label : null;
|
|
383
|
+
}) : renderTextOrNode(label, optionTextStyle);
|
|
386
384
|
return /*#__PURE__*/React.createElement(Pressable, {
|
|
387
385
|
testID: `cascader-option-${tabIndex}-${String(optionValue)}`,
|
|
388
386
|
style: ({
|
|
@@ -419,19 +417,6 @@ const CascaderOptionList = /*#__PURE__*/React.memo(({
|
|
|
419
417
|
tokens,
|
|
420
418
|
emptyText
|
|
421
419
|
}) => {
|
|
422
|
-
if (!optionList.length) {
|
|
423
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
424
|
-
style: [tokens.layout.optionList, {
|
|
425
|
-
height: tokens.sizing.optionListHeight
|
|
426
|
-
}]
|
|
427
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
428
|
-
style: [tokens.layout.empty, {
|
|
429
|
-
color: tokens.colors.placeholder,
|
|
430
|
-
paddingVertical: tokens.spacing.emptyPaddingVertical,
|
|
431
|
-
fontSize: tokens.typography.emptyTextSize
|
|
432
|
-
}]
|
|
433
|
-
}, emptyText));
|
|
434
|
-
}
|
|
435
420
|
const renderItem = useCallback(({
|
|
436
421
|
item
|
|
437
422
|
}) => /*#__PURE__*/React.createElement(CascaderOptionItem, {
|
|
@@ -445,6 +430,17 @@ const CascaderOptionList = /*#__PURE__*/React.memo(({
|
|
|
445
430
|
tokens: tokens
|
|
446
431
|
}), [activeColor, keys, onSelect, optionRender, selectedValue, tabIndex, tokens]);
|
|
447
432
|
const keyExtractor = useCallback(item => String(item[keys.valueKey]), [keys.valueKey]);
|
|
433
|
+
if (!optionList.length) return /*#__PURE__*/React.createElement(View, {
|
|
434
|
+
style: [tokens.layout.optionList, {
|
|
435
|
+
height: tokens.sizing.optionListHeight
|
|
436
|
+
}]
|
|
437
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
438
|
+
style: [tokens.layout.empty, {
|
|
439
|
+
color: tokens.colors.placeholder,
|
|
440
|
+
paddingVertical: tokens.spacing.emptyPaddingVertical,
|
|
441
|
+
fontSize: tokens.typography.emptyTextSize
|
|
442
|
+
}]
|
|
443
|
+
}, emptyText));
|
|
448
444
|
return /*#__PURE__*/React.createElement(FlatList, {
|
|
449
445
|
data: optionList,
|
|
450
446
|
style: [tokens.layout.optionList, {
|
|
@@ -462,4 +458,5 @@ const CascaderOptionList = /*#__PURE__*/React.memo(({
|
|
|
462
458
|
windowSize: 5
|
|
463
459
|
});
|
|
464
460
|
});
|
|
461
|
+
const Cascader = /*#__PURE__*/React.memo(CascaderImpl);
|
|
465
462
|
export default Cascader;
|
|
@@ -6,7 +6,7 @@ export const createCascaderTokens = foundations => {
|
|
|
6
6
|
radii
|
|
7
7
|
} = foundations;
|
|
8
8
|
const surfaceMuted = palette.default[100];
|
|
9
|
-
const placeholderText = "
|
|
9
|
+
const placeholderText = "Select";
|
|
10
10
|
return {
|
|
11
11
|
defaults: {
|
|
12
12
|
placeholder: placeholderText,
|
|
@@ -19,7 +19,7 @@ export const createCascaderTokens = foundations => {
|
|
|
19
19
|
closeOnFinish: true,
|
|
20
20
|
popupPlacement: "bottom",
|
|
21
21
|
popupRound: true,
|
|
22
|
-
loadingText: "
|
|
22
|
+
loadingText: "Loading..."
|
|
23
23
|
},
|
|
24
24
|
layout: {
|
|
25
25
|
container: {
|
|
@@ -1,33 +1,29 @@
|
|
|
1
|
+
const getDepth = (options, childrenKey) => {
|
|
2
|
+
let max = 1;
|
|
3
|
+
const traverse = (opts, level) => {
|
|
4
|
+
if (!opts?.length) return;
|
|
5
|
+
if (level > max) max = level;
|
|
6
|
+
opts.forEach(o => {
|
|
7
|
+
const has = Object.prototype.hasOwnProperty.call(o, childrenKey);
|
|
8
|
+
if (has && level + 1 > max) max = level + 1;
|
|
9
|
+
const ch = o[childrenKey];
|
|
10
|
+
if (ch?.length) traverse(ch, level + 1);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
traverse(options, 1);
|
|
14
|
+
return max;
|
|
15
|
+
};
|
|
1
16
|
export const useCascaderExtend = (options = [], keys, value) => {
|
|
2
|
-
const depth = (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (children && children.length) traverse(children, next);
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
traverse(options, 1);
|
|
16
|
-
return maxDepth;
|
|
17
|
-
})();
|
|
18
|
-
const tabs = (() => {
|
|
19
|
-
if (!value || !value.length) return [options];
|
|
20
|
-
return value.reduce((acc, val, index) => {
|
|
21
|
-
if (val == null) return acc;
|
|
22
|
-
const current = acc[index];
|
|
23
|
-
if (!current) return acc;
|
|
24
|
-
const next = current.find(option => option[keys.valueKey] === value[index]);
|
|
25
|
-
const children = next?.[keys.childrenKey];
|
|
26
|
-
if (children) acc.push(children);
|
|
27
|
-
return acc;
|
|
28
|
-
}, [options]);
|
|
29
|
-
})();
|
|
30
|
-
const items = !value || !value.length ? [] : value.map((val, index) => tabs[index]?.find(option => option[keys.valueKey] === val));
|
|
17
|
+
const depth = getDepth(options, keys.childrenKey);
|
|
18
|
+
const tabs = !value?.length ? [options] : value.reduce((acc, val, i) => {
|
|
19
|
+
if (val == null) return acc;
|
|
20
|
+
const cur = acc[i];
|
|
21
|
+
if (!cur) return acc;
|
|
22
|
+
const ch = cur.find(o => o[keys.valueKey] === value[i])?.[keys.childrenKey];
|
|
23
|
+
if (ch) acc.push(ch);
|
|
24
|
+
return acc;
|
|
25
|
+
}, [options]);
|
|
26
|
+
const items = !value?.length ? [] : value.map((val, i) => tabs[i]?.find(o => o[keys.valueKey] === val));
|
|
31
27
|
return {
|
|
32
28
|
tabs,
|
|
33
29
|
items,
|