react-native-system-ui 0.0.4 → 0.0.6
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/cjs/components/action-sheet/ActionSheet.js +28 -22
- package/dist/cjs/components/area/Area.js +72 -6
- package/dist/cjs/components/area/tokens.js +11 -0
- package/dist/cjs/components/avatar/Avatar.js +42 -10
- package/dist/cjs/components/badge/Badge.js +10 -10
- package/dist/cjs/components/badge/tokens.js +4 -0
- package/dist/cjs/components/button/Button.js +16 -65
- package/dist/cjs/components/button/ButtonContext.js +7 -10
- package/dist/cjs/components/button/ButtonGroup.js +13 -15
- package/dist/cjs/components/button/tokens.js +1 -5
- package/dist/cjs/components/calendar/Calendar.js +23 -12
- package/dist/cjs/components/cascader/Cascader.js +18 -13
- package/dist/cjs/components/cell/Cell.js +3 -3
- package/dist/cjs/components/cell/CellGroup.js +26 -21
- package/dist/cjs/components/checkbox/Checkbox.js +5 -4
- package/dist/cjs/components/checkbox/CheckboxContext.js +7 -10
- package/dist/cjs/components/checkbox/CheckboxGroup.js +24 -21
- package/dist/cjs/components/circle/Circle.js +6 -6
- package/dist/cjs/components/collapse/Collapse.js +10 -10
- package/dist/cjs/components/config-provider/locale/en-US.js +66 -4
- package/dist/cjs/components/config-provider/locale/zh-CN.js +74 -2
- package/dist/cjs/components/config-provider/tokens.js +11 -0
- package/dist/cjs/components/count-down/CountDown.js +6 -6
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +6 -6
- package/dist/cjs/components/datetime-picker/tokens.js +11 -0
- package/dist/cjs/components/dialog/Dialog.js +39 -34
- package/dist/cjs/components/dialog/tokens.js +1 -4
- package/dist/cjs/components/divider/Divider.js +36 -1
- package/dist/cjs/components/field/Field.js +303 -201
- package/dist/cjs/components/flex/Flex.js +7 -3
- package/dist/cjs/components/flex/FlexContext.js +7 -14
- package/dist/cjs/components/form/Form.js +112 -122
- package/dist/cjs/components/form/FormContext.js +7 -10
- package/dist/cjs/components/form/FormItem.js +30 -4
- package/dist/cjs/components/form/FormList.js +16 -3
- package/dist/cjs/components/form/tokens.js +11 -0
- package/dist/cjs/components/form/utils.js +2 -1
- package/dist/cjs/components/grid/Grid.js +45 -31
- package/dist/cjs/components/grid/GridContext.js +7 -10
- package/dist/cjs/components/grid/GridItem.js +22 -22
- package/dist/cjs/components/image/Image.js +17 -13
- package/dist/cjs/components/image-preview/ImagePreview.js +43 -41
- package/dist/cjs/components/index.js +43 -141
- package/dist/cjs/components/input/Input.js +19 -5
- package/dist/cjs/components/loading/Loading.js +10 -139
- package/dist/cjs/components/loading/tokens.js +0 -24
- package/dist/cjs/components/notice-bar/NoticeBar.js +45 -41
- package/dist/cjs/components/notify/Notify.js +72 -30
- package/dist/cjs/components/notify/imperative.js +2 -2
- package/dist/cjs/components/notify/tokens.js +11 -1
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +6 -6
- package/dist/cjs/components/overlay/Overlay.js +70 -77
- package/dist/cjs/components/overlay/index.js +13 -27
- package/dist/cjs/components/overlay/tokens.js +4 -31
- package/dist/cjs/components/password-input/PasswordInput.js +2 -41
- package/dist/cjs/components/password-input/tokens.js +53 -0
- package/dist/cjs/components/picker/Picker.js +618 -38
- package/dist/cjs/components/popup/Popup.js +60 -47
- package/dist/cjs/components/portal/Portal.js +39 -31
- package/dist/cjs/components/portal/PortalHost.js +258 -213
- package/dist/cjs/components/portal/tokens.js +11 -0
- package/dist/cjs/components/progress/Progress.js +77 -36
- package/dist/cjs/components/progress/index.js +6 -0
- package/dist/cjs/components/radio/Radio.js +35 -12
- package/dist/cjs/components/radio/RadioContext.js +7 -10
- package/dist/cjs/components/radio/RadioGroup.js +23 -20
- package/dist/cjs/components/safe-area-view/tokens.js +11 -0
- package/dist/cjs/components/search/Search.js +16 -16
- package/dist/cjs/components/selector/Selector.js +6 -6
- package/dist/cjs/components/share-sheet/ShareSheet.js +50 -46
- package/dist/cjs/components/sidebar/Sidebar.js +27 -22
- package/dist/cjs/components/sidebar/SidebarItem.js +27 -22
- package/dist/cjs/components/skeleton/Skeleton.js +34 -21
- package/dist/cjs/components/slider/Slider.js +135 -78
- package/dist/cjs/components/stepper/Stepper.js +12 -10
- package/dist/cjs/components/swiper/Swiper.js +247 -710
- package/dist/cjs/components/swiper/SwiperItem.js +5 -33
- package/dist/cjs/components/swiper/tokens.js +11 -0
- package/dist/cjs/components/switch/Switch.js +46 -98
- package/dist/cjs/components/switch/tokens.js +1 -55
- package/dist/cjs/components/tabbar/Tabbar.js +26 -22
- package/dist/cjs/components/tabbar/TabbarItem.js +23 -22
- package/dist/cjs/components/tabbar/tokens.js +0 -2
- package/dist/cjs/components/tabs/Tabs.js +268 -94
- package/dist/cjs/components/tabs/index.js +4 -5
- package/dist/cjs/components/toast/Toast.js +72 -27
- package/dist/cjs/components/toast/imperative.js +2 -2
- package/dist/cjs/hooks/gesture/useGestureScroll.js +1 -2
- package/dist/cjs/hooks/index.js +12 -12
- package/dist/cjs/hooks/overlay/index.js +27 -0
- package/dist/cjs/hooks/useHairline.js +0 -4
- package/dist/cjs/platform/scrollLock.js +1 -1
- package/dist/cjs/utils/compare.js +26 -0
- package/dist/cjs/utils/index.js +11 -0
- package/dist/es/components/action-sheet/ActionSheet.js +29 -23
- package/dist/es/components/area/Area.js +73 -7
- package/dist/es/components/area/tokens.js +5 -0
- package/dist/es/components/avatar/Avatar.js +42 -10
- package/dist/es/components/badge/Badge.js +11 -11
- package/dist/es/components/badge/tokens.js +4 -0
- package/dist/es/components/button/Button.js +17 -65
- package/dist/es/components/button/ButtonContext.js +1 -2
- package/dist/es/components/button/ButtonGroup.js +10 -12
- package/dist/es/components/button/tokens.js +1 -5
- package/dist/es/components/calendar/Calendar.js +24 -13
- package/dist/es/components/cascader/Cascader.js +16 -11
- package/dist/es/components/cell/Cell.js +4 -4
- package/dist/es/components/cell/CellGroup.js +25 -20
- package/dist/es/components/checkbox/Checkbox.js +5 -4
- package/dist/es/components/checkbox/CheckboxContext.js +1 -2
- package/dist/es/components/checkbox/CheckboxGroup.js +24 -21
- package/dist/es/components/circle/Circle.js +7 -7
- package/dist/es/components/collapse/Collapse.js +11 -11
- package/dist/es/components/config-provider/locale/en-US.js +66 -4
- package/dist/es/components/config-provider/locale/zh-CN.js +74 -2
- package/dist/es/components/config-provider/tokens.js +5 -0
- package/dist/es/components/count-down/CountDown.js +7 -7
- package/dist/es/components/datetime-picker/DatetimePicker.js +7 -7
- package/dist/es/components/datetime-picker/tokens.js +5 -0
- package/dist/es/components/dialog/Dialog.js +40 -35
- package/dist/es/components/dialog/tokens.js +1 -4
- package/dist/es/components/divider/Divider.js +36 -1
- package/dist/es/components/field/Field.js +304 -202
- package/dist/es/components/flex/Flex.js +5 -1
- package/dist/es/components/flex/FlexContext.js +1 -6
- package/dist/es/components/form/Form.js +89 -99
- package/dist/es/components/form/FormContext.js +1 -2
- package/dist/es/components/form/FormItem.js +32 -6
- package/dist/es/components/form/FormList.js +18 -5
- package/dist/es/components/form/tokens.js +5 -0
- package/dist/es/components/form/utils.js +1 -0
- package/dist/es/components/grid/Grid.js +43 -29
- package/dist/es/components/grid/GridContext.js +1 -2
- package/dist/es/components/grid/GridItem.js +24 -24
- package/dist/es/components/image/Image.js +18 -14
- package/dist/es/components/image-preview/ImagePreview.js +44 -42
- package/dist/es/components/index.js +2 -17
- package/dist/es/components/input/Input.js +20 -6
- package/dist/es/components/loading/Loading.js +10 -139
- package/dist/es/components/loading/tokens.js +0 -24
- package/dist/es/components/notice-bar/NoticeBar.js +46 -42
- package/dist/es/components/notify/Notify.js +72 -30
- package/dist/es/components/notify/imperative.js +2 -2
- package/dist/es/components/notify/tokens.js +5 -1
- package/dist/es/components/number-keyboard/NumberKeyboard.js +7 -7
- package/dist/es/components/overlay/Overlay.js +58 -75
- package/dist/es/components/overlay/index.js +3 -4
- package/dist/es/components/overlay/tokens.js +3 -29
- package/dist/es/components/password-input/PasswordInput.js +1 -40
- package/dist/es/components/password-input/tokens.js +41 -0
- package/dist/es/components/picker/Picker.js +610 -34
- package/dist/es/components/popup/Popup.js +62 -49
- package/dist/es/components/portal/Portal.js +37 -31
- package/dist/es/components/portal/PortalHost.js +257 -211
- package/dist/es/components/portal/tokens.js +5 -0
- package/dist/es/components/progress/Progress.js +76 -36
- package/dist/es/components/progress/index.js +2 -1
- package/dist/es/components/radio/Radio.js +37 -14
- package/dist/es/components/radio/RadioContext.js +1 -2
- package/dist/es/components/radio/RadioGroup.js +23 -20
- package/dist/es/components/safe-area-view/tokens.js +5 -0
- package/dist/es/components/search/Search.js +17 -17
- package/dist/es/components/selector/Selector.js +7 -7
- package/dist/es/components/share-sheet/ShareSheet.js +51 -47
- package/dist/es/components/sidebar/Sidebar.js +26 -21
- package/dist/es/components/sidebar/SidebarItem.js +26 -22
- package/dist/es/components/skeleton/Skeleton.js +35 -22
- package/dist/es/components/slider/Slider.js +132 -75
- package/dist/es/components/stepper/Stepper.js +13 -11
- package/dist/es/components/swiper/Swiper.js +248 -711
- package/dist/es/components/swiper/SwiperItem.js +1 -21
- package/dist/es/components/swiper/tokens.js +5 -0
- package/dist/es/components/switch/Switch.js +49 -101
- package/dist/es/components/switch/tokens.js +1 -49
- package/dist/es/components/tabbar/Tabbar.js +27 -23
- package/dist/es/components/tabbar/TabbarItem.js +22 -22
- package/dist/es/components/tabbar/tokens.js +0 -2
- package/dist/es/components/tabs/Tabs.js +264 -90
- package/dist/es/components/tabs/index.js +1 -2
- package/dist/es/components/toast/Toast.js +72 -28
- package/dist/es/components/toast/imperative.js +2 -2
- package/dist/es/hooks/gesture/useGestureScroll.js +1 -2
- package/dist/es/hooks/index.js +1 -1
- package/dist/es/hooks/overlay/index.js +3 -0
- package/dist/es/hooks/useHairline.js +0 -4
- package/dist/es/platform/scrollLock.js +1 -1
- package/dist/es/utils/compare.js +18 -0
- package/dist/es/utils/index.js +1 -1
- package/dist/types/components/area/tokens.d.ts +3 -0
- package/dist/types/components/avatar/Avatar.d.ts +4 -2
- package/dist/types/components/button/ButtonContext.d.ts +2 -16
- package/dist/types/components/button/ButtonGroup.d.ts +14 -1
- package/dist/types/components/button/index.d.ts +1 -1
- package/dist/types/components/checkbox/CheckboxContext.d.ts +2 -16
- package/dist/types/components/checkbox/CheckboxGroup.d.ts +15 -1
- package/dist/types/components/collapse/Collapse.d.ts +0 -1
- package/dist/types/components/config-provider/LocaleContext.d.ts +2 -74
- package/dist/types/components/config-provider/tokens.d.ts +3 -0
- package/dist/types/components/config-provider/useLocale.d.ts +1 -74
- package/dist/types/components/datetime-picker/tokens.d.ts +3 -0
- package/dist/types/components/flex/Flex.d.ts +6 -0
- package/dist/types/components/flex/FlexContext.d.ts +2 -8
- package/dist/types/components/form/Form.d.ts +15 -1
- package/dist/types/components/form/FormContext.d.ts +2 -17
- package/dist/types/components/form/tokens.d.ts +3 -0
- package/dist/types/components/form/utils.d.ts +1 -0
- package/dist/types/components/grid/Grid.d.ts +16 -1
- package/dist/types/components/grid/GridContext.d.ts +2 -17
- package/dist/types/components/index.d.ts +3 -33
- package/dist/types/components/loading/index.d.ts +1 -1
- package/dist/types/components/notify/Notify.d.ts +1 -0
- package/dist/types/components/overlay/Overlay.d.ts +6 -1
- package/dist/types/components/overlay/index.d.ts +2 -3
- package/dist/types/components/overlay/tokens.d.ts +2 -3
- package/dist/types/components/password-input/PasswordInput.d.ts +0 -39
- package/dist/types/components/password-input/tokens.d.ts +40 -0
- package/dist/types/components/picker/Picker.d.ts +18 -2
- package/dist/types/components/picker/index.d.ts +1 -1
- package/dist/types/components/portal/Portal.d.ts +4 -6
- package/dist/types/components/portal/PortalHost.d.ts +1 -15
- package/dist/types/components/portal/tokens.d.ts +3 -0
- package/dist/types/components/progress/Progress.d.ts +4 -0
- package/dist/types/components/progress/index.d.ts +2 -1
- package/dist/types/components/radio/RadioContext.d.ts +2 -13
- package/dist/types/components/radio/RadioGroup.d.ts +12 -1
- package/dist/types/components/safe-area-view/tokens.d.ts +3 -0
- package/dist/types/components/swiper/Swiper.d.ts +4 -2
- package/dist/types/components/swiper/SwiperItem.d.ts +1 -5
- package/dist/types/components/swiper/tokens.d.ts +3 -0
- package/dist/types/components/tabs/Tabs.d.ts +8 -4
- package/dist/types/components/tabs/index.d.ts +3 -1
- package/dist/types/components/toast/Toast.d.ts +1 -4
- package/dist/types/hooks/aria/useAriaListBox.d.ts +0 -6
- package/dist/types/hooks/aria/useAriaOverlay.d.ts +0 -10
- package/dist/types/hooks/aria/useAriaPress.d.ts +0 -20
- package/dist/types/hooks/aria/useAriaToggle.d.ts +0 -3
- package/dist/types/hooks/index.d.ts +1 -1
- package/dist/types/hooks/overlay/index.d.ts +2 -0
- package/dist/types/hooks/useHairline.d.ts +0 -21
- package/dist/types/utils/compare.d.ts +2 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +10 -48
- package/dist/cjs/components/area/utils.js +0 -74
- package/dist/cjs/components/cascader/utils.js +0 -20
- package/dist/cjs/components/config-provider/locale/base.js +0 -80
- package/dist/cjs/components/dropdown-menu/DropdownItem.js +0 -288
- package/dist/cjs/components/dropdown-menu/DropdownMenu.js +0 -340
- package/dist/cjs/components/dropdown-menu/DropdownMenuContext.js +0 -21
- package/dist/cjs/components/dropdown-menu/index.js +0 -25
- package/dist/cjs/components/dropdown-menu/tokens.js +0 -67
- package/dist/cjs/components/field/utils.js +0 -24
- package/dist/cjs/components/index-bar/IndexAnchor.js +0 -74
- package/dist/cjs/components/index-bar/IndexBar.js +0 -436
- package/dist/cjs/components/index-bar/index.js +0 -25
- package/dist/cjs/components/index-bar/tokens.js +0 -45
- package/dist/cjs/components/list/List.js +0 -165
- package/dist/cjs/components/list/index.js +0 -9
- package/dist/cjs/components/list/tokens.js +0 -39
- package/dist/cjs/components/notify/defaults.js +0 -15
- package/dist/cjs/components/pagination/Pagination.js +0 -160
- package/dist/cjs/components/pagination/index.js +0 -22
- package/dist/cjs/components/pagination/tokens.js +0 -103
- package/dist/cjs/components/picker/WheelPicker.js +0 -492
- package/dist/cjs/components/picker/utils.js +0 -138
- package/dist/cjs/components/pull-refresh/PullRefresh.js +0 -378
- package/dist/cjs/components/pull-refresh/index.js +0 -16
- package/dist/cjs/components/pull-refresh/tokens.js +0 -22
- package/dist/cjs/components/rate/Rate.js +0 -269
- package/dist/cjs/components/rate/index.js +0 -15
- package/dist/cjs/components/rate/tokens.js +0 -60
- package/dist/cjs/components/slider/utils.js +0 -60
- package/dist/cjs/components/swiper/useSwiperWeb.js +0 -209
- package/dist/cjs/components/swiper/utils.js +0 -49
- package/dist/cjs/components/tabs/TabPane.js +0 -9
- package/dist/cjs/components/tabs/useTabsAnimation.js +0 -74
- package/dist/cjs/components/tabs/useTabsScroll.js +0 -133
- package/dist/cjs/components/tabs/utils.js +0 -34
- package/dist/cjs/components/types.js +0 -1
- package/dist/cjs/components/uploader/Uploader.js +0 -557
- package/dist/cjs/components/uploader/index.js +0 -22
- package/dist/cjs/components/uploader/tokens.js +0 -58
- package/dist/cjs/components/uploader/utils.js +0 -72
- package/dist/cjs/hooks/usePresenceAnimation.js +0 -70
- package/dist/es/components/area/utils.js +0 -67
- package/dist/es/components/cascader/utils.js +0 -13
- package/dist/es/components/config-provider/locale/base.js +0 -74
- package/dist/es/components/dropdown-menu/DropdownItem.js +0 -269
- package/dist/es/components/dropdown-menu/DropdownMenu.js +0 -320
- package/dist/es/components/dropdown-menu/DropdownMenuContext.js +0 -7
- package/dist/es/components/dropdown-menu/index.js +0 -7
- package/dist/es/components/dropdown-menu/tokens.js +0 -61
- package/dist/es/components/field/utils.js +0 -17
- package/dist/es/components/index-bar/IndexAnchor.js +0 -55
- package/dist/es/components/index-bar/IndexBar.js +0 -417
- package/dist/es/components/index-bar/index.js +0 -7
- package/dist/es/components/index-bar/tokens.js +0 -39
- package/dist/es/components/list/List.js +0 -145
- package/dist/es/components/list/index.js +0 -2
- package/dist/es/components/list/tokens.js +0 -32
- package/dist/es/components/notify/defaults.js +0 -9
- package/dist/es/components/pagination/Pagination.js +0 -141
- package/dist/es/components/pagination/index.js +0 -4
- package/dist/es/components/pagination/tokens.js +0 -91
- package/dist/es/components/picker/WheelPicker.js +0 -473
- package/dist/es/components/picker/utils.js +0 -127
- package/dist/es/components/pull-refresh/PullRefresh.js +0 -359
- package/dist/es/components/pull-refresh/index.js +0 -3
- package/dist/es/components/pull-refresh/tokens.js +0 -16
- package/dist/es/components/rate/Rate.js +0 -250
- package/dist/es/components/rate/index.js +0 -3
- package/dist/es/components/rate/tokens.js +0 -53
- package/dist/es/components/slider/utils.js +0 -49
- package/dist/es/components/swiper/useSwiperWeb.js +0 -190
- package/dist/es/components/swiper/utils.js +0 -37
- package/dist/es/components/tabs/TabPane.js +0 -3
- package/dist/es/components/tabs/useTabsAnimation.js +0 -55
- package/dist/es/components/tabs/useTabsScroll.js +0 -114
- package/dist/es/components/tabs/utils.js +0 -19
- package/dist/es/components/types.js +0 -1
- package/dist/es/components/uploader/Uploader.js +0 -537
- package/dist/es/components/uploader/index.js +0 -4
- package/dist/es/components/uploader/tokens.js +0 -52
- package/dist/es/components/uploader/utils.js +0 -60
- package/dist/es/hooks/usePresenceAnimation.js +0 -51
- package/dist/types/components/area/utils.d.ts +0 -2
- package/dist/types/components/cascader/utils.d.ts +0 -6
- package/dist/types/components/config-provider/locale/base.d.ts +0 -74
- package/dist/types/components/dropdown-menu/DropdownItem.d.ts +0 -4
- package/dist/types/components/dropdown-menu/DropdownMenu.d.ts +0 -4
- package/dist/types/components/dropdown-menu/DropdownMenuContext.d.ts +0 -17
- package/dist/types/components/dropdown-menu/index.d.ts +0 -8
- package/dist/types/components/dropdown-menu/tokens.d.ts +0 -52
- package/dist/types/components/field/utils.d.ts +0 -4
- package/dist/types/components/index-bar/IndexAnchor.d.ts +0 -4
- package/dist/types/components/index-bar/IndexBar.d.ts +0 -4
- package/dist/types/components/index-bar/index.d.ts +0 -9
- package/dist/types/components/index-bar/tokens.d.ts +0 -31
- package/dist/types/components/list/List.d.ts +0 -4
- package/dist/types/components/list/index.d.ts +0 -3
- package/dist/types/components/list/tokens.d.ts +0 -4
- package/dist/types/components/notify/defaults.d.ts +0 -10
- package/dist/types/components/pagination/Pagination.d.ts +0 -5
- package/dist/types/components/pagination/index.d.ts +0 -5
- package/dist/types/components/pagination/tokens.d.ts +0 -2
- package/dist/types/components/picker/WheelPicker.d.ts +0 -21
- package/dist/types/components/picker/utils.d.ts +0 -17
- package/dist/types/components/pull-refresh/PullRefresh.d.ts +0 -5
- package/dist/types/components/pull-refresh/index.d.ts +0 -4
- package/dist/types/components/pull-refresh/tokens.d.ts +0 -10
- package/dist/types/components/rate/Rate.d.ts +0 -4
- package/dist/types/components/rate/index.d.ts +0 -4
- package/dist/types/components/rate/tokens.d.ts +0 -4
- package/dist/types/components/slider/utils.d.ts +0 -42
- package/dist/types/components/swiper/useSwiperWeb.d.ts +0 -41
- package/dist/types/components/swiper/utils.d.ts +0 -17
- package/dist/types/components/tabs/TabPane.d.ts +0 -4
- package/dist/types/components/tabs/useTabsAnimation.d.ts +0 -30
- package/dist/types/components/tabs/useTabsScroll.d.ts +0 -23
- package/dist/types/components/tabs/utils.d.ts +0 -5
- package/dist/types/components/types.d.ts +0 -59
- package/dist/types/components/uploader/Uploader.d.ts +0 -4
- package/dist/types/components/uploader/index.d.ts +0 -5
- package/dist/types/components/uploader/tokens.d.ts +0 -42
- package/dist/types/components/uploader/utils.d.ts +0 -11
- package/dist/types/hooks/usePresenceAnimation.d.ts +0 -20
- /package/dist/cjs/{components → hooks}/overlay/OverlayStackStore.js +0 -0
- /package/dist/cjs/{components → hooks}/overlay/useOverlayStack.js +0 -0
- /package/dist/es/{components → hooks}/overlay/OverlayStackStore.js +0 -0
- /package/dist/es/{components → hooks}/overlay/useOverlayStack.js +0 -0
- /package/dist/types/{components → hooks}/overlay/OverlayStackStore.d.ts +0 -0
- /package/dist/types/{components → hooks}/overlay/useOverlayStack.d.ts +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
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
2
|
import React, { useCallback, useContext, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
3
3
|
import { View } from 'react-native';
|
|
4
|
+
import { shallowEqualObject } from '../../utils';
|
|
4
5
|
import { isPromiseLike } from '../../utils/promise';
|
|
5
6
|
import { isNumber, isString, isText } from '../../utils/validate';
|
|
6
|
-
import {
|
|
7
|
-
|
|
7
|
+
import { FORM_ALL_FIELDS_KEY, getValueByName, normalizeTrigger, serializeNamePath, setValueByName } from './utils';
|
|
8
|
+
export const FormContext = /*#__PURE__*/React.createContext(null);
|
|
8
9
|
const runRuleValidation = (rule, value, values) => {
|
|
9
10
|
const message = rule.message ?? '表单验证未通过';
|
|
10
11
|
const empty = value == null || value === '' || Array.isArray(value) && value.length === 0;
|
|
@@ -24,21 +25,6 @@ const runRuleValidation = (rule, value, values) => {
|
|
|
24
25
|
const result = rule.validator(value, values);
|
|
25
26
|
return isPromiseLike(result) ? result.then(handle) : handle(result);
|
|
26
27
|
};
|
|
27
|
-
const shallowEqual = (prev, next) => {
|
|
28
|
-
if (prev === next) return true;
|
|
29
|
-
if (!prev || !next) return false;
|
|
30
|
-
const prevKeys = Object.keys(prev);
|
|
31
|
-
const nextKeys = Object.keys(next);
|
|
32
|
-
if (prevKeys.length !== nextKeys.length) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
for (const key of prevKeys) {
|
|
36
|
-
if (prev[key] !== next[key]) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
};
|
|
42
28
|
const InternalForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
43
29
|
const {
|
|
44
30
|
initialValues: initialValuesProp,
|
|
@@ -54,49 +40,55 @@ const InternalForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
54
40
|
} = props;
|
|
55
41
|
const defaultInitialValuesRef = useRef({});
|
|
56
42
|
const mergedInitialValues = initialValuesProp ?? defaultInitialValuesRef.current;
|
|
57
|
-
const [
|
|
58
|
-
const
|
|
43
|
+
const [, setFormVersion] = useState(0);
|
|
44
|
+
const errorsRef = useRef({});
|
|
59
45
|
const lastInitialValuesRef = useRef(mergedInitialValues);
|
|
60
46
|
const fieldsRef = useRef({});
|
|
61
47
|
const dependencyGraphRef = useRef(new Map());
|
|
62
|
-
const valuesRef = useRef(
|
|
63
|
-
const errorsRef = useRef(errors);
|
|
48
|
+
const valuesRef = useRef(mergedInitialValues);
|
|
64
49
|
const validationSeqRef = useRef({});
|
|
65
50
|
const subscribersRef = useRef(new Set());
|
|
51
|
+
const notify = useCallback((changedValues, nextValues) => {
|
|
52
|
+
subscribersRef.current.forEach(listener => listener(changedValues, nextValues));
|
|
53
|
+
}, []);
|
|
66
54
|
useEffect(() => {
|
|
67
|
-
if (
|
|
55
|
+
if (shallowEqualObject(lastInitialValuesRef.current, mergedInitialValues)) {
|
|
68
56
|
return;
|
|
69
57
|
}
|
|
70
58
|
lastInitialValuesRef.current = mergedInitialValues;
|
|
71
59
|
valuesRef.current = mergedInitialValues;
|
|
72
60
|
errorsRef.current = {};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
61
|
+
setFormVersion(version => version + 1);
|
|
62
|
+
notify({
|
|
63
|
+
[FORM_ALL_FIELDS_KEY]: true
|
|
64
|
+
}, mergedInitialValues);
|
|
65
|
+
}, [mergedInitialValues, notify]);
|
|
76
66
|
const setFieldErrors = useCallback((name, nextErrors) => {
|
|
77
67
|
const key = serializeNamePath(name);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (!
|
|
81
|
-
if (!prevErrors) return prev;
|
|
82
|
-
const clone = {
|
|
83
|
-
...prev
|
|
84
|
-
};
|
|
85
|
-
delete clone[key];
|
|
86
|
-
errorsRef.current = clone;
|
|
87
|
-
return clone;
|
|
88
|
-
}
|
|
89
|
-
if (prevErrors?.[0] === nextErrors[0] && prevErrors.length === nextErrors.length) {
|
|
90
|
-
return prev;
|
|
91
|
-
}
|
|
68
|
+
const prevErrors = errorsRef.current[key];
|
|
69
|
+
if (!nextErrors.length) {
|
|
70
|
+
if (!prevErrors) return;
|
|
92
71
|
const clone = {
|
|
93
|
-
...
|
|
94
|
-
[key]: nextErrors
|
|
72
|
+
...errorsRef.current
|
|
95
73
|
};
|
|
74
|
+
delete clone[key];
|
|
96
75
|
errorsRef.current = clone;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
76
|
+
notify({
|
|
77
|
+
[key]: getValueByName(valuesRef.current, name)
|
|
78
|
+
}, valuesRef.current);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (prevErrors?.[0] === nextErrors[0] && prevErrors.length === nextErrors.length) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
errorsRef.current = {
|
|
85
|
+
...errorsRef.current,
|
|
86
|
+
[key]: nextErrors
|
|
87
|
+
};
|
|
88
|
+
notify({
|
|
89
|
+
[key]: getValueByName(valuesRef.current, name)
|
|
90
|
+
}, valuesRef.current);
|
|
91
|
+
}, [notify]);
|
|
100
92
|
const registerField = useCallback((name, options) => {
|
|
101
93
|
const key = serializeNamePath(name);
|
|
102
94
|
const prev = fieldsRef.current[key];
|
|
@@ -131,12 +123,11 @@ const InternalForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
131
123
|
}
|
|
132
124
|
const existsInState = getValueByName(valuesRef.current, name);
|
|
133
125
|
if (existsInState === undefined) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
126
|
+
const next = setValueByName(valuesRef.current, name, options.initialValue);
|
|
127
|
+
valuesRef.current = next;
|
|
128
|
+
notify({
|
|
129
|
+
[key]: options.initialValue
|
|
130
|
+
}, next);
|
|
140
131
|
}
|
|
141
132
|
}
|
|
142
133
|
return () => {
|
|
@@ -154,9 +145,6 @@ const InternalForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
154
145
|
setFieldErrors(name, []);
|
|
155
146
|
};
|
|
156
147
|
}, [setFieldErrors]);
|
|
157
|
-
const notify = useCallback((changedValues, nextValues) => {
|
|
158
|
-
subscribersRef.current.forEach(listener => listener(changedValues, nextValues));
|
|
159
|
-
}, []);
|
|
160
148
|
const runFieldValidation = useCallback(async (name, trigger, valueOverride, valuesOverride) => {
|
|
161
149
|
const key = serializeNamePath(name);
|
|
162
150
|
const validationSeq = (validationSeqRef.current[key] ?? 0) + 1;
|
|
@@ -205,26 +193,24 @@ const InternalForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
205
193
|
}, [runFieldValidation]);
|
|
206
194
|
const setFieldValue = useCallback((name, value, trigger) => {
|
|
207
195
|
const nameKey = serializeNamePath(name);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
196
|
+
const prev = valuesRef.current;
|
|
197
|
+
const prevValue = getValueByName(prev, name);
|
|
198
|
+
if (prevValue === value) return;
|
|
199
|
+
const next = setValueByName(prev, name, value);
|
|
200
|
+
valuesRef.current = next;
|
|
201
|
+
onValuesChange?.(next, nameKey, value);
|
|
202
|
+
runFieldValidation(name, trigger, value, next);
|
|
203
|
+
const dependents = dependencyGraphRef.current.get(nameKey);
|
|
204
|
+
if (dependents?.size) {
|
|
205
|
+
for (const dependentKey of dependents) {
|
|
206
|
+
const meta = fieldsRef.current[dependentKey];
|
|
207
|
+
if (!meta) continue;
|
|
208
|
+
runFieldValidation(meta.name, trigger, getValueByName(next, meta.name), next);
|
|
222
209
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
});
|
|
210
|
+
}
|
|
211
|
+
notify({
|
|
212
|
+
[nameKey]: value
|
|
213
|
+
}, next);
|
|
228
214
|
}, [notify, onValuesChange, runFieldValidation]);
|
|
229
215
|
const formApi = {
|
|
230
216
|
submit: async () => {
|
|
@@ -237,16 +223,18 @@ const InternalForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
237
223
|
}
|
|
238
224
|
},
|
|
239
225
|
getFieldsValue: () => valuesRef.current,
|
|
240
|
-
setFieldsValue: next => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
226
|
+
setFieldsValue: (next, options) => {
|
|
227
|
+
const shouldValidate = options?.validate ?? false;
|
|
228
|
+
const prev = valuesRef.current;
|
|
229
|
+
let merged = prev;
|
|
230
|
+
const changed = {};
|
|
231
|
+
Object.keys(next).forEach(key => {
|
|
232
|
+
const newVal = next[key];
|
|
233
|
+
if (getValueByName(merged, key) === newVal) return;
|
|
234
|
+
changed[key] = newVal;
|
|
235
|
+
merged = setValueByName(merged, key, newVal);
|
|
236
|
+
onValuesChange?.(merged, key, newVal);
|
|
237
|
+
if (shouldValidate) {
|
|
250
238
|
runFieldValidation(key, undefined, newVal, merged);
|
|
251
239
|
const dependents = dependencyGraphRef.current.get(key);
|
|
252
240
|
if (dependents?.size) {
|
|
@@ -256,12 +244,11 @@ const InternalForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
256
244
|
runFieldValidation(meta.name, undefined, getValueByName(merged, meta.name), merged);
|
|
257
245
|
}
|
|
258
246
|
}
|
|
259
|
-
}
|
|
260
|
-
if (merged === prev) return prev;
|
|
261
|
-
valuesRef.current = merged;
|
|
262
|
-
notify(changed, merged);
|
|
263
|
-
return merged;
|
|
247
|
+
}
|
|
264
248
|
});
|
|
249
|
+
if (merged === prev) return;
|
|
250
|
+
valuesRef.current = merged;
|
|
251
|
+
notify(changed, merged);
|
|
265
252
|
},
|
|
266
253
|
resetFields: () => {
|
|
267
254
|
let next = lastInitialValuesRef.current;
|
|
@@ -272,25 +259,21 @@ const InternalForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
272
259
|
});
|
|
273
260
|
valuesRef.current = next;
|
|
274
261
|
errorsRef.current = {};
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
262
|
+
notify({
|
|
263
|
+
[FORM_ALL_FIELDS_KEY]: true
|
|
264
|
+
}, next);
|
|
278
265
|
},
|
|
279
266
|
validateFields,
|
|
280
267
|
getFieldError: name => errorsRef.current[serializeNamePath(name)] ?? []
|
|
281
268
|
};
|
|
282
269
|
useImperativeHandle(ref, () => formApi, [formApi]);
|
|
283
|
-
const getFieldError = useCallback(name => errors[serializeNamePath(name)], [errors]);
|
|
284
|
-
const getFieldValue = useCallback(name => getValueByName(values, name), [values]);
|
|
285
|
-
const contextValidateField = useCallback((name, trigger) => runFieldValidation(name, trigger), [runFieldValidation]);
|
|
286
270
|
const contextValue = {
|
|
287
|
-
|
|
288
|
-
getFieldValue,
|
|
271
|
+
getFieldValue: name => getValueByName(valuesRef.current, name),
|
|
289
272
|
setFieldValue,
|
|
290
273
|
registerField,
|
|
291
|
-
getFieldError,
|
|
292
|
-
validateField:
|
|
293
|
-
getFieldsValue: () =>
|
|
274
|
+
getFieldError: name => errorsRef.current[serializeNamePath(name)],
|
|
275
|
+
validateField: (name, trigger) => runFieldValidation(name, trigger),
|
|
276
|
+
getFieldsValue: () => valuesRef.current,
|
|
294
277
|
subscribe: listener => {
|
|
295
278
|
subscribersRef.current.add(listener);
|
|
296
279
|
return () => subscribersRef.current.delete(listener);
|
|
@@ -322,11 +305,18 @@ export const useWatch = (name, formRef) => {
|
|
|
322
305
|
useEffect(() => {
|
|
323
306
|
if (!context?.subscribe) return undefined;
|
|
324
307
|
return context.subscribe((changed, all) => {
|
|
308
|
+
if (FORM_ALL_FIELDS_KEY in changed) {
|
|
309
|
+
setValue(getSnapshot(all));
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
325
312
|
if (!names || names.some(key => serializeNamePath(key) in changed)) {
|
|
326
313
|
setValue(getSnapshot(all));
|
|
327
314
|
}
|
|
328
315
|
});
|
|
329
316
|
}, [context, getSnapshot, names]);
|
|
317
|
+
useEffect(() => {
|
|
318
|
+
setValue(getSnapshot());
|
|
319
|
+
}, [getSnapshot]);
|
|
330
320
|
return value;
|
|
331
321
|
};
|
|
332
322
|
export const FormSubscribe = ({
|
|
@@ -338,7 +328,7 @@ export const FormSubscribe = ({
|
|
|
338
328
|
useEffect(() => {
|
|
339
329
|
if (!context?.subscribe) return undefined;
|
|
340
330
|
return context.subscribe(next => {
|
|
341
|
-
if (to && !Object.keys(next).some(key => to.includes(key))) return;
|
|
331
|
+
if (to && !(FORM_ALL_FIELDS_KEY in next) && !Object.keys(next).some(key => to.includes(key))) return;
|
|
342
332
|
setChanged(next);
|
|
343
333
|
});
|
|
344
334
|
}, [context, to]);
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const FormContext = /*#__PURE__*/React.createContext(null);
|
|
1
|
+
export { FormContext } from './Form';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { useContext, useEffect, useRef } from 'react';
|
|
1
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { isFunction, isString } from '../../utils';
|
|
3
3
|
import { FormContext } from './FormContext';
|
|
4
|
-
import { normalizeTrigger } from './utils';
|
|
4
|
+
import { FORM_ALL_FIELDS_KEY, normalizeTrigger, serializeNamePath } from './utils';
|
|
5
5
|
const EMPTY_RULES = [];
|
|
6
6
|
export const FormItem = ({
|
|
7
7
|
name,
|
|
@@ -33,11 +33,37 @@ export const FormItem = ({
|
|
|
33
33
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
34
34
|
}
|
|
35
35
|
const normalizedRules = rules ?? EMPTY_RULES;
|
|
36
|
-
const prevValuesRef = useRef(context.
|
|
36
|
+
const prevValuesRef = useRef(context.getFieldsValue());
|
|
37
|
+
const [, forceUpdate] = useState(0);
|
|
38
|
+
const nameKey = name ? serializeNamePath(name) : undefined;
|
|
39
|
+
const subscribeAll = renderProps && !nameKey && !shouldUpdate;
|
|
37
40
|
useEffect(() => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if (!context?.subscribe) return undefined;
|
|
42
|
+
return context.subscribe((changed, all) => {
|
|
43
|
+
if (FORM_ALL_FIELDS_KEY in changed) {
|
|
44
|
+
forceUpdate(version => version + 1);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (subscribeAll) {
|
|
48
|
+
forceUpdate(version => version + 1);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (shouldUpdate) {
|
|
52
|
+
if (shouldUpdate(prevValuesRef.current, all)) {
|
|
53
|
+
forceUpdate(version => version + 1);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (nameKey && nameKey in changed) {
|
|
58
|
+
forceUpdate(version => version + 1);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}, [context, nameKey, shouldUpdate, subscribeAll]);
|
|
62
|
+
const currentValues = context.getFieldsValue();
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
prevValuesRef.current = currentValues;
|
|
65
|
+
}, [currentValues]);
|
|
66
|
+
const shouldRender = !shouldUpdate || shouldUpdate(prevValuesRef.current, currentValues);
|
|
41
67
|
useEffect(() => {
|
|
42
68
|
if (!name) return undefined;
|
|
43
69
|
return context.registerField(name, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, { useCallback, useContext, useEffect, useRef } from 'react';
|
|
1
|
+
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { FormContext } from './FormContext';
|
|
3
|
-
import { getValueByName } from './utils';
|
|
3
|
+
import { FORM_ALL_FIELDS_KEY, getValueByName, serializeNamePath } from './utils';
|
|
4
4
|
export const FormList = ({
|
|
5
5
|
name,
|
|
6
6
|
initialValue,
|
|
@@ -8,9 +8,15 @@ export const FormList = ({
|
|
|
8
8
|
}) => {
|
|
9
9
|
const context = useContext(FormContext);
|
|
10
10
|
const keyRef = useRef(0);
|
|
11
|
+
const nameKey = serializeNamePath(name);
|
|
12
|
+
const [listValue, setListValue] = useState(() => {
|
|
13
|
+
if (!context) return [];
|
|
14
|
+
const current = getValueByName(context.getFieldsValue(), name);
|
|
15
|
+
return Array.isArray(current) ? current : [];
|
|
16
|
+
});
|
|
11
17
|
const ensureInitial = useCallback(() => {
|
|
12
18
|
if (!context) return;
|
|
13
|
-
const current = getValueByName(context.
|
|
19
|
+
const current = getValueByName(context.getFieldsValue(), name);
|
|
14
20
|
if (current === undefined && initialValue !== undefined) {
|
|
15
21
|
context.setFieldValue(name, initialValue);
|
|
16
22
|
}
|
|
@@ -18,11 +24,18 @@ export const FormList = ({
|
|
|
18
24
|
useEffect(() => {
|
|
19
25
|
ensureInitial();
|
|
20
26
|
}, [ensureInitial]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!context?.subscribe) return undefined;
|
|
29
|
+
return context.subscribe((changed, all) => {
|
|
30
|
+
if (FORM_ALL_FIELDS_KEY in changed || nameKey in changed) {
|
|
31
|
+
const nextRaw = getValueByName(all, name);
|
|
32
|
+
setListValue(Array.isArray(nextRaw) ? nextRaw : []);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}, [context, name, nameKey]);
|
|
21
36
|
if (!context) {
|
|
22
37
|
return null;
|
|
23
38
|
}
|
|
24
|
-
const listValueRaw = getValueByName(context.values, name);
|
|
25
|
-
const listValue = Array.isArray(listValueRaw) ? listValueRaw : [];
|
|
26
39
|
const fields = listValue.map((_, index) => ({
|
|
27
40
|
name: index,
|
|
28
41
|
key: keyRef.current + index,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isNumber, isString } from '../../utils';
|
|
2
2
|
export const normalizeTrigger = trigger => trigger ? Array.isArray(trigger) ? trigger : [trigger] : [];
|
|
3
|
+
export const FORM_ALL_FIELDS_KEY = '__form_all__';
|
|
3
4
|
export const toNamePath = name => {
|
|
4
5
|
if (name === undefined || name === null) return [];
|
|
5
6
|
if (Array.isArray(name)) return name;
|
|
@@ -1,9 +1,9 @@
|
|
|
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 from 'react';
|
|
3
|
-
import { View } from 'react-native';
|
|
2
|
+
import React, { useMemo } from 'react';
|
|
3
|
+
import { Platform, View } from 'react-native';
|
|
4
4
|
import { createHairlineView } from '../../utils';
|
|
5
|
-
import { GridContext } from './GridContext';
|
|
6
5
|
import { useGridTokens } from './tokens';
|
|
6
|
+
export const GridContext = /*#__PURE__*/React.createContext(null);
|
|
7
7
|
export const Grid = props => {
|
|
8
8
|
const {
|
|
9
9
|
tokensOverride,
|
|
@@ -22,22 +22,28 @@ export const Grid = props => {
|
|
|
22
22
|
...rest
|
|
23
23
|
} = props;
|
|
24
24
|
const tokens = useGridTokens(tokensOverride);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
25
|
+
const columnNum = useMemo(() => {
|
|
26
|
+
const columnNumValue = columnNumProp ?? tokens.defaults.columnNum;
|
|
27
|
+
return Number.isFinite(columnNumValue) && columnNumValue > 0 ? Math.floor(columnNumValue) : tokens.defaults.columnNum;
|
|
28
|
+
}, [columnNumProp, tokens.defaults.columnNum]);
|
|
29
|
+
const gutter = useMemo(() => {
|
|
30
|
+
const gutterValue = gutterProp ?? tokens.defaults.gutter;
|
|
31
|
+
return Number.isFinite(gutterValue) && gutterValue > 0 ? gutterValue : 0;
|
|
32
|
+
}, [gutterProp, tokens.defaults.gutter]);
|
|
33
|
+
const border = useMemo(() => borderProp ?? tokens.defaults.border, [borderProp, tokens.defaults.border]);
|
|
34
|
+
const center = useMemo(() => centerProp ?? tokens.defaults.center, [centerProp, tokens.defaults.center]);
|
|
35
|
+
const square = useMemo(() => squareProp ?? tokens.defaults.square, [squareProp, tokens.defaults.square]);
|
|
36
|
+
const direction = useMemo(() => directionProp ?? tokens.defaults.direction, [directionProp, tokens.defaults.direction]);
|
|
37
|
+
const reverse = useMemo(() => reverseProp ?? tokens.defaults.reverse, [reverseProp, tokens.defaults.reverse]);
|
|
38
|
+
const clickable = useMemo(() => clickableProp ?? tokens.defaults.clickable, [clickableProp, tokens.defaults.clickable]);
|
|
39
|
+
const iconSize = useMemo(() => {
|
|
40
|
+
const iconSizeValue = iconSizeProp ?? tokens.defaults.iconSize;
|
|
41
|
+
return Number.isFinite(iconSizeValue) && iconSizeValue > 0 ? iconSizeValue : tokens.defaults.iconSize;
|
|
42
|
+
}, [iconSizeProp, tokens.defaults.iconSize]);
|
|
43
|
+
const childArray = useMemo(() => React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child)), [children]);
|
|
38
44
|
const showBorder = border && !gutter;
|
|
39
45
|
const borderColor = tokens.colors.border;
|
|
40
|
-
const topBorder = showBorder
|
|
46
|
+
const topBorder = useMemo(() => showBorder ? /*#__PURE__*/React.createElement(View, {
|
|
41
47
|
style: [tokens.layout.border, tokens.layout.borderTop, createHairlineView({
|
|
42
48
|
position: 'top',
|
|
43
49
|
color: borderColor,
|
|
@@ -45,8 +51,8 @@ export const Grid = props => {
|
|
|
45
51
|
right: 0,
|
|
46
52
|
top: 0
|
|
47
53
|
})]
|
|
48
|
-
});
|
|
49
|
-
const bottomBorder = showBorder
|
|
54
|
+
}) : null, [borderColor, showBorder, tokens.layout.border, tokens.layout.borderTop]);
|
|
55
|
+
const bottomBorder = useMemo(() => showBorder ? /*#__PURE__*/React.createElement(View, {
|
|
50
56
|
style: [tokens.layout.border, tokens.layout.borderBottom, createHairlineView({
|
|
51
57
|
position: 'bottom',
|
|
52
58
|
color: borderColor,
|
|
@@ -54,8 +60,8 @@ export const Grid = props => {
|
|
|
54
60
|
right: 0,
|
|
55
61
|
bottom: 0
|
|
56
62
|
})]
|
|
57
|
-
});
|
|
58
|
-
const contextValue = {
|
|
63
|
+
}) : null, [borderColor, showBorder, tokens.layout.border, tokens.layout.borderBottom]);
|
|
64
|
+
const contextValue = useMemo(() => ({
|
|
59
65
|
columnNum,
|
|
60
66
|
gutter,
|
|
61
67
|
border,
|
|
@@ -68,16 +74,24 @@ export const Grid = props => {
|
|
|
68
74
|
iconColor,
|
|
69
75
|
count: childArray.length,
|
|
70
76
|
tokens
|
|
71
|
-
};
|
|
77
|
+
}), [border, center, childArray.length, clickable, columnNum, direction, gutter, iconColor, iconSize, reverse, square, tokens]);
|
|
78
|
+
const webGridStyle = useMemo(() => Platform.OS === 'web' ? {
|
|
79
|
+
display: 'grid',
|
|
80
|
+
gridTemplateColumns: `repeat(${columnNum}, minmax(0, 1fr))`,
|
|
81
|
+
columnGap: gutter,
|
|
82
|
+
rowGap: gutter
|
|
83
|
+
} : undefined, [columnNum, gutter]);
|
|
84
|
+
const containerStyle = useMemo(() => [tokens.layout.container, Platform.OS === 'web' ? webGridStyle : gutter ? {
|
|
85
|
+
paddingLeft: gutter
|
|
86
|
+
} : undefined, style], [gutter, style, tokens.layout.container, webGridStyle]);
|
|
87
|
+
const renderedChildren = useMemo(() => childArray.map((child, index) => /*#__PURE__*/React.cloneElement(child, {
|
|
88
|
+
gridItemIndex: index,
|
|
89
|
+
key: child.key ?? index
|
|
90
|
+
})), [childArray]);
|
|
72
91
|
return /*#__PURE__*/React.createElement(GridContext.Provider, {
|
|
73
92
|
value: contextValue
|
|
74
93
|
}, /*#__PURE__*/React.createElement(View, _extends({
|
|
75
|
-
style:
|
|
76
|
-
|
|
77
|
-
} : undefined, style]
|
|
78
|
-
}, rest), topBorder, childArray.map((child, index) => /*#__PURE__*/React.cloneElement(child, {
|
|
79
|
-
gridItemIndex: index,
|
|
80
|
-
key: child.key ?? index
|
|
81
|
-
})), bottomBorder));
|
|
94
|
+
style: containerStyle
|
|
95
|
+
}, rest), topBorder, renderedChildren, bottomBorder));
|
|
82
96
|
};
|
|
83
97
|
Grid.displayName = 'Grid';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const GridContext = /*#__PURE__*/React.createContext(null);
|
|
1
|
+
export { GridContext } from './Grid';
|
|
@@ -1,6 +1,6 @@
|
|
|
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, { useContext } from 'react';
|
|
3
|
-
import { Pressable, Text, View } from 'react-native';
|
|
2
|
+
import React, { useContext, useMemo } from 'react';
|
|
3
|
+
import { Platform, Pressable, Text, View } from 'react-native';
|
|
4
4
|
import Badge from '../badge';
|
|
5
5
|
import { createHairlineView, isFunction, isRenderable, isText } from '../../utils';
|
|
6
6
|
import { GridContext } from './GridContext';
|
|
@@ -35,19 +35,19 @@ export const GridItem = props => {
|
|
|
35
35
|
iconColor,
|
|
36
36
|
count
|
|
37
37
|
} = context;
|
|
38
|
-
const widthPercent = `${100 / columnNum}
|
|
39
|
-
const isLastColumn = (gridItemIndex + 1) % columnNum === 0;
|
|
40
|
-
const rowIndex = Math.floor(gridItemIndex / columnNum);
|
|
41
|
-
const lastRowIndex = Math.floor((count - 1) / columnNum);
|
|
42
|
-
const contentWrapperStyle = [tokens.layout.itemContentBase, direction === 'horizontal' ? tokens.layout.itemHorizontal : tokens.layout.itemVertical, center && tokens.layout.itemCenter, reverse ? direction === 'horizontal' ? tokens.layout.itemReverseRow : tokens.layout.itemReverseColumn : null, square ? tokens.layout.itemContentSquare : null, {
|
|
38
|
+
const widthPercent = useMemo(() => `${100 / columnNum}%`, [columnNum]);
|
|
39
|
+
const isLastColumn = useMemo(() => (gridItemIndex + 1) % columnNum === 0, [columnNum, gridItemIndex]);
|
|
40
|
+
const rowIndex = useMemo(() => Math.floor(gridItemIndex / columnNum), [columnNum, gridItemIndex]);
|
|
41
|
+
const lastRowIndex = useMemo(() => Math.floor((count - 1) / columnNum), [columnNum, count]);
|
|
42
|
+
const contentWrapperStyle = useMemo(() => [tokens.layout.itemContentBase, direction === 'horizontal' ? tokens.layout.itemHorizontal : tokens.layout.itemVertical, center && tokens.layout.itemCenter, reverse ? direction === 'horizontal' ? tokens.layout.itemReverseRow : tokens.layout.itemReverseColumn : null, square ? tokens.layout.itemContentSquare : null, {
|
|
43
43
|
paddingHorizontal: tokens.spacing.paddingHorizontal,
|
|
44
44
|
paddingVertical: tokens.spacing.paddingVertical,
|
|
45
45
|
backgroundColor: tokens.colors.background
|
|
46
|
-
}, contentStyle];
|
|
46
|
+
}, contentStyle], [center, contentStyle, direction, reverse, square, tokens.colors.background, tokens.layout.itemContentBase, tokens.layout.itemContentSquare, tokens.layout.itemHorizontal, tokens.layout.itemReverseColumn, tokens.layout.itemReverseRow, tokens.layout.itemVertical, tokens.layout.itemCenter, tokens.spacing.paddingHorizontal, tokens.spacing.paddingVertical]);
|
|
47
47
|
const hasText = isRenderable(text);
|
|
48
|
-
const resolvedIconColor = iconColorProp ?? iconColor ?? tokens.colors.text;
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const resolvedIconColor = useMemo(() => iconColorProp ?? iconColor ?? tokens.colors.text, [iconColor, iconColorProp, tokens.colors.text]);
|
|
49
|
+
const innerContent = useMemo(() => {
|
|
50
|
+
if (children) return children;
|
|
51
51
|
let iconElement = null;
|
|
52
52
|
if (icon || badge || dot) {
|
|
53
53
|
const {
|
|
@@ -80,9 +80,9 @@ export const GridItem = props => {
|
|
|
80
80
|
}, textStyle],
|
|
81
81
|
numberOfLines: tokens.defaults.textNumberOfLines
|
|
82
82
|
}, text) : text);
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
const rightBorder = border && !gutter && !isLastColumn
|
|
83
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, iconElement, textElement);
|
|
84
|
+
}, [badge, center, children, direction, dot, hasText, icon, iconSize, resolvedIconColor, reverse, text, textStyle, tokens.colors.text, tokens.defaults.textNumberOfLines, tokens.layout.iconWrapper, tokens.layout.text, tokens.spacing.iconGap, tokens.typography.fontFamily, tokens.typography.fontSize, tokens.typography.fontWeight, tokens.typography.lineHeight]);
|
|
85
|
+
const rightBorder = useMemo(() => border && !gutter && !isLastColumn ? /*#__PURE__*/React.createElement(View, {
|
|
86
86
|
style: [tokens.layout.itemBorderRight, createHairlineView({
|
|
87
87
|
position: 'right',
|
|
88
88
|
color: tokens.colors.border,
|
|
@@ -90,8 +90,8 @@ export const GridItem = props => {
|
|
|
90
90
|
bottom: 0,
|
|
91
91
|
right: 0
|
|
92
92
|
})]
|
|
93
|
-
});
|
|
94
|
-
const bottomBorder = border && !gutter && rowIndex < lastRowIndex
|
|
93
|
+
}) : null, [border, gutter, isLastColumn, tokens.colors.border, tokens.layout.itemBorderRight]);
|
|
94
|
+
const bottomBorder = useMemo(() => border && !gutter && rowIndex < lastRowIndex ? /*#__PURE__*/React.createElement(View, {
|
|
95
95
|
style: [tokens.layout.itemBorderBottom, createHairlineView({
|
|
96
96
|
position: 'bottom',
|
|
97
97
|
color: tokens.colors.border,
|
|
@@ -99,17 +99,17 @@ export const GridItem = props => {
|
|
|
99
99
|
right: 0,
|
|
100
100
|
bottom: 0
|
|
101
101
|
})]
|
|
102
|
-
});
|
|
103
|
-
const content = /*#__PURE__*/React.createElement(View, {
|
|
102
|
+
}) : null, [border, gutter, lastRowIndex, rowIndex, tokens.colors.border, tokens.layout.itemBorderBottom]);
|
|
103
|
+
const content = useMemo(() => /*#__PURE__*/React.createElement(View, {
|
|
104
104
|
style: contentWrapperStyle
|
|
105
|
-
}, innerContent, rightBorder, bottomBorder);
|
|
106
|
-
const baseItemStyle = {
|
|
107
|
-
width: widthPercent,
|
|
105
|
+
}, innerContent, rightBorder, bottomBorder), [bottomBorder, contentWrapperStyle, innerContent, rightBorder]);
|
|
106
|
+
const baseItemStyle = useMemo(() => ({
|
|
107
|
+
width: Platform.OS === 'web' ? undefined : widthPercent,
|
|
108
108
|
flexGrow: 0,
|
|
109
109
|
flexShrink: 0,
|
|
110
|
-
paddingRight: gutter ? gutter : undefined,
|
|
111
|
-
marginTop: gutter && rowIndex > 0 ? gutter : undefined
|
|
112
|
-
};
|
|
110
|
+
paddingRight: Platform.OS === 'web' ? undefined : gutter ? gutter : undefined,
|
|
111
|
+
marginTop: Platform.OS === 'web' ? undefined : gutter && rowIndex > 0 ? gutter : undefined
|
|
112
|
+
}), [gutter, rowIndex, widthPercent]);
|
|
113
113
|
const isInteractive = clickable || isFunction(onPress);
|
|
114
114
|
if (isInteractive) {
|
|
115
115
|
return /*#__PURE__*/React.createElement(Pressable, _extends({
|