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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.FormItem = void 0;
|
|
6
|
+
exports.default = exports.FormItem = void 0;
|
|
7
7
|
function _react() {
|
|
8
8
|
const data = _interopRequireWildcard(require("react"));
|
|
9
9
|
_react = function () {
|
|
@@ -16,7 +16,8 @@ var _FormContext = require("./FormContext");
|
|
|
16
16
|
var _utils2 = require("./utils");
|
|
17
17
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
18
18
|
const EMPTY_RULES = [];
|
|
19
|
-
const
|
|
19
|
+
const EMPTY_VALUES = {};
|
|
20
|
+
const FormItemImpl = ({
|
|
20
21
|
name,
|
|
21
22
|
label,
|
|
22
23
|
description,
|
|
@@ -34,140 +35,111 @@ const FormItem = ({
|
|
|
34
35
|
children
|
|
35
36
|
}) => {
|
|
36
37
|
const renderProps = typeof children === 'function';
|
|
37
|
-
const
|
|
38
|
-
if (!context) {
|
|
39
|
-
if (renderProps) {
|
|
40
|
-
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children({
|
|
41
|
-
getFieldValue: () => undefined,
|
|
42
|
-
getFieldsValue: () => ({}),
|
|
43
|
-
form: null
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
|
|
47
|
-
}
|
|
38
|
+
const ctx = (0, _react().useContext)(_FormContext.FormContext);
|
|
48
39
|
const normalizedRules = rules ?? EMPTY_RULES;
|
|
49
|
-
const prevValuesRef = (0, _react().useRef)(context.getFieldsValue());
|
|
50
|
-
const [, forceUpdate] = (0, _react().useState)(0);
|
|
51
40
|
const nameKey = name ? (0, _utils2.serializeNamePath)(name) : undefined;
|
|
52
|
-
const
|
|
41
|
+
const shouldAlwaysUpdate = renderProps && !nameKey && !shouldUpdate;
|
|
42
|
+
const previousValuesRef = (0, _react().useRef)(EMPTY_VALUES);
|
|
43
|
+
const [, forceUpdate] = (0, _react().useState)(0);
|
|
53
44
|
(0, _react().useEffect)(() => {
|
|
54
|
-
if (!
|
|
55
|
-
return
|
|
56
|
-
if (_utils2.FORM_ALL_FIELDS_KEY in
|
|
57
|
-
forceUpdate(
|
|
45
|
+
if (!ctx?.subscribe) return undefined;
|
|
46
|
+
return ctx.subscribe((changedValues, all) => {
|
|
47
|
+
if (_utils2.FORM_ALL_FIELDS_KEY in changedValues) {
|
|
48
|
+
forceUpdate(v => v + 1);
|
|
58
49
|
return;
|
|
59
50
|
}
|
|
60
|
-
if (
|
|
61
|
-
forceUpdate(
|
|
51
|
+
if (shouldAlwaysUpdate) {
|
|
52
|
+
forceUpdate(v => v + 1);
|
|
62
53
|
return;
|
|
63
54
|
}
|
|
64
55
|
if (shouldUpdate) {
|
|
65
|
-
if (shouldUpdate(
|
|
66
|
-
forceUpdate(version => version + 1);
|
|
67
|
-
}
|
|
56
|
+
if (shouldUpdate(previousValuesRef.current, all)) forceUpdate(v => v + 1);
|
|
68
57
|
return;
|
|
69
58
|
}
|
|
70
|
-
if (nameKey && nameKey in
|
|
71
|
-
forceUpdate(version => version + 1);
|
|
72
|
-
}
|
|
59
|
+
if (nameKey && nameKey in changedValues) forceUpdate(v => v + 1);
|
|
73
60
|
});
|
|
74
|
-
}, [
|
|
75
|
-
const currentValues =
|
|
61
|
+
}, [ctx, nameKey, shouldUpdate, shouldAlwaysUpdate]);
|
|
62
|
+
const currentValues = ctx?.getFieldsValue() ?? EMPTY_VALUES;
|
|
76
63
|
(0, _react().useEffect)(() => {
|
|
77
|
-
|
|
64
|
+
previousValuesRef.current = currentValues;
|
|
78
65
|
}, [currentValues]);
|
|
79
|
-
const shouldRender = !shouldUpdate || shouldUpdate(prevValuesRef.current, currentValues);
|
|
80
66
|
(0, _react().useEffect)(() => {
|
|
81
|
-
if (!name) return undefined;
|
|
82
|
-
return
|
|
67
|
+
if (!name || !ctx) return undefined;
|
|
68
|
+
return ctx.registerField(name, {
|
|
83
69
|
rules: normalizedRules,
|
|
84
70
|
dependencies,
|
|
85
71
|
initialValue,
|
|
86
72
|
validateTrigger: validateTrigger ?? trigger
|
|
87
73
|
});
|
|
88
|
-
}, [
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
74
|
+
}, [ctx, name, normalizedRules, dependencies, initialValue, validateTrigger, trigger]);
|
|
75
|
+
if (!ctx) {
|
|
76
|
+
if (renderProps) return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children({
|
|
77
|
+
getFieldValue: () => undefined,
|
|
78
|
+
getFieldsValue: () => EMPTY_VALUES,
|
|
79
|
+
form: null
|
|
80
|
+
}));
|
|
81
|
+
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
|
|
82
|
+
}
|
|
83
|
+
const shouldRender = !shouldUpdate || shouldUpdate(previousValuesRef.current, currentValues);
|
|
84
|
+
const modelValue = name ? ctx.getFieldValue(name) : undefined;
|
|
85
|
+
const mergedShowValidateMessage = showValidateMessage ?? ctx.showValidateMessage ?? true;
|
|
86
|
+
const fieldErrors = name ? ctx.getFieldError(name) : undefined;
|
|
87
|
+
const fieldError = mergedShowValidateMessage ? fieldErrors?.[0] : undefined;
|
|
88
|
+
const mergedRequired = required ?? normalizedRules.some(r => r.required);
|
|
89
|
+
const mergedValidateTrigger = (0, _utils2.normalizeTrigger)(validateTrigger ?? trigger);
|
|
95
90
|
if (renderProps) {
|
|
96
91
|
if (!shouldRender) return null;
|
|
97
|
-
|
|
98
|
-
getFieldValue:
|
|
99
|
-
getFieldsValue:
|
|
100
|
-
form:
|
|
101
|
-
});
|
|
102
|
-
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, node);
|
|
103
|
-
}
|
|
104
|
-
if (!name) {
|
|
105
|
-
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
|
|
92
|
+
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children({
|
|
93
|
+
getFieldValue: ctx.getFieldValue,
|
|
94
|
+
getFieldsValue: ctx.getFieldsValue,
|
|
95
|
+
form: ctx.form || null
|
|
96
|
+
}));
|
|
106
97
|
}
|
|
98
|
+
if (!name) return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
|
|
107
99
|
if (!shouldRender) return null;
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
const child = childArray[0];
|
|
100
|
+
const childrenArray = _react().default.Children.toArray(children);
|
|
101
|
+
if (childrenArray.length !== 1) return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
|
|
102
|
+
const child = childrenArray[0];
|
|
113
103
|
const handleChange = next => {
|
|
114
|
-
|
|
104
|
+
ctx.setFieldValue(name, next, trigger);
|
|
115
105
|
const original = child.props[trigger];
|
|
116
|
-
if ((0, _utils.isFunction)(original))
|
|
117
|
-
original(next);
|
|
118
|
-
}
|
|
106
|
+
if ((0, _utils.isFunction)(original)) original(next);
|
|
119
107
|
};
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
})();
|
|
124
|
-
const resolveValue = () => {
|
|
108
|
+
const displayName = child.type.displayName;
|
|
109
|
+
const isFieldLike = (0, _utils.isString)(displayName) && (displayName.includes('Field') || displayName.includes('Input'));
|
|
110
|
+
const resolvedValue = () => {
|
|
125
111
|
const childValue = child.props[valuePropName];
|
|
126
112
|
if (childValue !== undefined) return childValue;
|
|
127
|
-
if (
|
|
113
|
+
if (modelValue !== undefined) return modelValue;
|
|
128
114
|
if (isFieldLike && valuePropName === 'value') return '';
|
|
129
|
-
return
|
|
115
|
+
return modelValue;
|
|
130
116
|
};
|
|
131
117
|
const injectedProps = {
|
|
132
|
-
[valuePropName]:
|
|
118
|
+
[valuePropName]: resolvedValue(),
|
|
133
119
|
[trigger]: handleChange
|
|
134
120
|
};
|
|
135
|
-
|
|
121
|
+
mergedValidateTrigger.forEach(eventName => {
|
|
136
122
|
if (!eventName || eventName === trigger) return;
|
|
137
123
|
const original = child.props[eventName];
|
|
138
124
|
injectedProps[eventName] = (...args) => {
|
|
139
|
-
if ((0, _utils.isFunction)(original))
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
context.validateField(name, eventName);
|
|
125
|
+
if ((0, _utils.isFunction)(original)) original(...args);
|
|
126
|
+
ctx.validateField(name, eventName);
|
|
143
127
|
};
|
|
144
128
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (description && child.props.description === undefined) {
|
|
155
|
-
injectedProps.description = description;
|
|
156
|
-
}
|
|
157
|
-
if (intro && child.props.intro === undefined) {
|
|
158
|
-
injectedProps.intro = intro;
|
|
159
|
-
}
|
|
160
|
-
if (tooltip && child.props.tooltip === undefined) {
|
|
161
|
-
injectedProps.tooltip = tooltip;
|
|
162
|
-
}
|
|
163
|
-
if (mergedRequired && child.props.required === undefined) {
|
|
164
|
-
injectedProps.required = true;
|
|
165
|
-
}
|
|
166
|
-
if (firstError && child.props.errorMessage === undefined) {
|
|
129
|
+
const childProps = child.props;
|
|
130
|
+
if (label !== undefined && childProps.label === undefined) injectedProps.label = label;
|
|
131
|
+
if (ctx.colon !== undefined && injectedProps.label !== undefined && childProps.colon === undefined) injectedProps.colon = ctx.colon;
|
|
132
|
+
if (ctx.labelWidth !== undefined && childProps.labelWidth === undefined) injectedProps.labelWidth = ctx.labelWidth;
|
|
133
|
+
if (description && childProps.description === undefined) injectedProps.description = description;
|
|
134
|
+
if (intro && childProps.intro === undefined) injectedProps.intro = intro;
|
|
135
|
+
if (tooltip && childProps.tooltip === undefined) injectedProps.tooltip = tooltip;
|
|
136
|
+
if (mergedRequired && childProps.required === undefined) injectedProps.required = true;
|
|
137
|
+
if (fieldError && childProps.errorMessage === undefined) {
|
|
167
138
|
injectedProps.error = true;
|
|
168
|
-
injectedProps.errorMessage =
|
|
139
|
+
injectedProps.errorMessage = fieldError;
|
|
169
140
|
}
|
|
170
141
|
return /*#__PURE__*/_react().default.cloneElement(child, injectedProps);
|
|
171
142
|
};
|
|
172
|
-
|
|
173
|
-
FormItem.
|
|
143
|
+
FormItemImpl.displayName = 'FormItem';
|
|
144
|
+
const FormItem = exports.FormItem = /*#__PURE__*/_react().default.memo(FormItemImpl);
|
|
145
|
+
var _default = exports.default = FormItem;
|
|
@@ -14,25 +14,28 @@ function _react() {
|
|
|
14
14
|
var _FormContext = require("./FormContext");
|
|
15
15
|
var _utils = require("./utils");
|
|
16
16
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
17
|
+
const getList = (context, name) => {
|
|
18
|
+
const raw = (0, _utils.getValueByName)(context.getFieldsValue(), name);
|
|
19
|
+
return Array.isArray(raw) ? raw : [];
|
|
20
|
+
};
|
|
17
21
|
const FormList = ({
|
|
18
22
|
name,
|
|
19
23
|
initialValue,
|
|
20
24
|
children
|
|
21
25
|
}) => {
|
|
22
26
|
const context = (0, _react().useContext)(_FormContext.FormContext);
|
|
23
|
-
const
|
|
27
|
+
const keyCounterRef = (0, _react().useRef)(0),
|
|
28
|
+
keysRef = (0, _react().useRef)([]);
|
|
24
29
|
const nameKey = (0, _utils.serializeNamePath)(name);
|
|
25
|
-
const [listValue, setListValue] = (0, _react().useState)(() =>
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const [listValue, setListValue] = (0, _react().useState)(() => context ? getList(context, name) : []);
|
|
31
|
+
const syncKeys = (0, _react().useCallback)(length => {
|
|
32
|
+
const keys = keysRef.current;
|
|
33
|
+
while (keys.length < length) keys.push(keyCounterRef.current++);
|
|
34
|
+
if (keys.length > length) keysRef.current = keys.slice(0, length);
|
|
35
|
+
}, []);
|
|
30
36
|
const ensureInitial = (0, _react().useCallback)(() => {
|
|
31
37
|
if (!context) return;
|
|
32
|
-
|
|
33
|
-
if (current === undefined && initialValue !== undefined) {
|
|
34
|
-
context.setFieldValue(name, initialValue);
|
|
35
|
-
}
|
|
38
|
+
if ((0, _utils.getValueByName)(context.getFieldsValue(), name) === undefined && initialValue !== undefined) context.setFieldValue(name, initialValue);
|
|
36
39
|
}, [context, initialValue, name]);
|
|
37
40
|
(0, _react().useEffect)(() => {
|
|
38
41
|
ensureInitial();
|
|
@@ -41,38 +44,47 @@ const FormList = ({
|
|
|
41
44
|
if (!context?.subscribe) return undefined;
|
|
42
45
|
return context.subscribe((changed, all) => {
|
|
43
46
|
if (_utils.FORM_ALL_FIELDS_KEY in changed || nameKey in changed) {
|
|
44
|
-
const
|
|
45
|
-
|
|
47
|
+
const next = (0, _utils.getValueByName)(all, name);
|
|
48
|
+
const nl = Array.isArray(next) ? next : [];
|
|
49
|
+
syncKeys(nl.length);
|
|
50
|
+
setListValue(nl);
|
|
46
51
|
}
|
|
47
52
|
});
|
|
48
|
-
}, [context, name, nameKey]);
|
|
49
|
-
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}));
|
|
57
|
-
const add = (defaultValue, index) => {
|
|
58
|
-
const insertIndex = typeof index === 'number' ? index : listValue.length;
|
|
59
|
-
const next = [...listValue];
|
|
60
|
-
next.splice(insertIndex, 0, defaultValue);
|
|
61
|
-
context.setFieldValue(name, next);
|
|
62
|
-
keyRef.current += 1;
|
|
63
|
-
};
|
|
64
|
-
const remove = index => {
|
|
65
|
-
if (index < 0 || index >= listValue.length) return;
|
|
66
|
-
const next = listValue.slice(0, index).concat(listValue.slice(index + 1));
|
|
53
|
+
}, [context, name, nameKey, syncKeys]);
|
|
54
|
+
const add = (0, _react().useCallback)((defaultValue, index) => {
|
|
55
|
+
if (!context) return;
|
|
56
|
+
const arr = getList(context, name),
|
|
57
|
+
i = typeof index === 'number' ? index : arr.length,
|
|
58
|
+
next = [...arr];
|
|
59
|
+
next.splice(i, 0, defaultValue);
|
|
60
|
+
keysRef.current.splice(i, 0, keyCounterRef.current++);
|
|
67
61
|
context.setFieldValue(name, next);
|
|
68
|
-
};
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
const
|
|
72
|
-
|
|
62
|
+
}, [context, name]);
|
|
63
|
+
const remove = (0, _react().useCallback)(index => {
|
|
64
|
+
if (!context) return;
|
|
65
|
+
const arr = getList(context, name);
|
|
66
|
+
if (index < 0 || index >= arr.length) return;
|
|
67
|
+
keysRef.current.splice(index, 1);
|
|
68
|
+
context.setFieldValue(name, arr.slice(0, index).concat(arr.slice(index + 1)));
|
|
69
|
+
}, [context, name]);
|
|
70
|
+
const move = (0, _react().useCallback)((from, to) => {
|
|
71
|
+
if (!context) return;
|
|
72
|
+
const arr = getList(context, name);
|
|
73
|
+
if (from === to || from < 0 || to < 0 || from >= arr.length || to >= arr.length) return;
|
|
74
|
+
const next = [...arr],
|
|
75
|
+
item = next.splice(from, 1)[0];
|
|
73
76
|
next.splice(to, 0, item);
|
|
77
|
+
const [movedKey] = keysRef.current.splice(from, 1);
|
|
78
|
+
keysRef.current.splice(to, 0, movedKey);
|
|
74
79
|
context.setFieldValue(name, next);
|
|
75
|
-
};
|
|
80
|
+
}, [context, name]);
|
|
81
|
+
if (!context) return null;
|
|
82
|
+
syncKeys(listValue.length);
|
|
83
|
+
const fields = listValue.map((_, i) => ({
|
|
84
|
+
name: i,
|
|
85
|
+
key: keysRef.current[i],
|
|
86
|
+
isListField: true
|
|
87
|
+
}));
|
|
76
88
|
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children(fields, {
|
|
77
89
|
add,
|
|
78
90
|
remove,
|
|
@@ -5,7 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useFormTokens = void 0;
|
|
7
7
|
var _designSystem = require("../../design-system");
|
|
8
|
-
const createFormTokens = _foundations => {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const createFormTokens = _foundations => ({
|
|
9
|
+
defaults: {
|
|
10
|
+
showValidateMessage: true,
|
|
11
|
+
defaultValidationMessage: 'Validation failed'
|
|
12
|
+
}
|
|
13
|
+
});
|
|
11
14
|
const useFormTokens = exports.useFormTokens = (0, _designSystem.createComponentTokensHook)('form', createFormTokens);
|
|
@@ -12,30 +12,21 @@ const toNamePath = name => {
|
|
|
12
12
|
if (name === undefined || name === null) return [];
|
|
13
13
|
if (Array.isArray(name)) return name;
|
|
14
14
|
if ((0, _utils.isNumber)(name)) return [name];
|
|
15
|
-
if ((0, _utils.isString)(name))
|
|
16
|
-
return name.split('.');
|
|
17
|
-
}
|
|
15
|
+
if ((0, _utils.isString)(name)) return name.split('.');
|
|
18
16
|
return [String(name)];
|
|
19
17
|
};
|
|
20
18
|
exports.toNamePath = toNamePath;
|
|
21
|
-
const serializeNamePath = name =>
|
|
22
|
-
const path = toNamePath(name);
|
|
23
|
-
return path.join('.');
|
|
24
|
-
};
|
|
19
|
+
const serializeNamePath = name => toNamePath(name).join('.');
|
|
25
20
|
exports.serializeNamePath = serializeNamePath;
|
|
26
21
|
const getValueByName = (source, name) => {
|
|
27
|
-
|
|
28
|
-
return path.reduce((acc, key) => {
|
|
22
|
+
return toNamePath(name).reduce((acc, key) => {
|
|
29
23
|
if (acc == null) return acc;
|
|
30
|
-
const
|
|
24
|
+
const k = String(key);
|
|
31
25
|
if (Array.isArray(acc)) {
|
|
32
|
-
const
|
|
33
|
-
return Number.isFinite(
|
|
26
|
+
const i = Number(k);
|
|
27
|
+
return Number.isFinite(i) ? acc[i] : acc[k];
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
return acc[keyStr];
|
|
37
|
-
}
|
|
38
|
-
return undefined;
|
|
29
|
+
return typeof acc === 'object' ? acc[k] : undefined;
|
|
39
30
|
}, source);
|
|
40
31
|
};
|
|
41
32
|
exports.getValueByName = getValueByName;
|
|
@@ -47,28 +38,18 @@ const setValueByName = (source, name, value) => {
|
|
|
47
38
|
} : {};
|
|
48
39
|
let cursor = clone;
|
|
49
40
|
path.forEach((key, index) => {
|
|
50
|
-
const
|
|
51
|
-
|
|
41
|
+
const k = String(key),
|
|
42
|
+
ki = Number(k);
|
|
52
43
|
if (index === path.length - 1) {
|
|
53
|
-
if (Array.isArray(cursor) && Number.isFinite(
|
|
54
|
-
cursor[keyIndex] = value;
|
|
55
|
-
} else {
|
|
56
|
-
;
|
|
57
|
-
cursor[keyStr] = value;
|
|
58
|
-
}
|
|
44
|
+
if (Array.isArray(cursor) && Number.isFinite(ki)) cursor[ki] = value;else cursor[k] = value;
|
|
59
45
|
return;
|
|
60
46
|
}
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
...
|
|
47
|
+
const nv = Array.isArray(cursor) && Number.isFinite(ki) ? cursor[ki] : cursor[k];
|
|
48
|
+
const nc = nv === undefined || nv === null ? (0, _utils.isNumber)(path[index + 1]) ? [] : {} : Array.isArray(nv) ? [...nv] : typeof nv === 'object' ? {
|
|
49
|
+
...nv
|
|
64
50
|
} : {};
|
|
65
|
-
if (Array.isArray(cursor) && Number.isFinite(
|
|
66
|
-
|
|
67
|
-
} else {
|
|
68
|
-
;
|
|
69
|
-
cursor[keyStr] = nextContainer;
|
|
70
|
-
}
|
|
71
|
-
cursor = nextContainer;
|
|
51
|
+
if (Array.isArray(cursor) && Number.isFinite(ki)) cursor[ki] = nc;else cursor[k] = nc;
|
|
52
|
+
cursor = nc;
|
|
72
53
|
});
|
|
73
54
|
return clone;
|
|
74
55
|
};
|
|
@@ -23,7 +23,7 @@ var _tokens = require("./tokens");
|
|
|
23
23
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
24
24
|
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); }
|
|
25
25
|
const GridContext = exports.GridContext = /*#__PURE__*/_react().default.createContext(null);
|
|
26
|
-
const
|
|
26
|
+
const GridImpl = props => {
|
|
27
27
|
const {
|
|
28
28
|
tokensOverride,
|
|
29
29
|
children,
|
|
@@ -42,24 +42,24 @@ const Grid = props => {
|
|
|
42
42
|
} = props;
|
|
43
43
|
const tokens = (0, _tokens.useGridTokens)(tokensOverride);
|
|
44
44
|
const columnNum = (0, _react().useMemo)(() => {
|
|
45
|
-
const
|
|
46
|
-
return Number.isFinite(
|
|
45
|
+
const value = columnNumProp ?? tokens.defaults.columnNum;
|
|
46
|
+
return Number.isFinite(value) && value > 0 ? Math.floor(value) : tokens.defaults.columnNum;
|
|
47
47
|
}, [columnNumProp, tokens.defaults.columnNum]);
|
|
48
48
|
const gutter = (0, _react().useMemo)(() => {
|
|
49
|
-
const
|
|
50
|
-
return Number.isFinite(
|
|
49
|
+
const value = gutterProp ?? tokens.defaults.gutter;
|
|
50
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
51
51
|
}, [gutterProp, tokens.defaults.gutter]);
|
|
52
|
-
const border =
|
|
53
|
-
const center =
|
|
54
|
-
const square =
|
|
55
|
-
const direction =
|
|
56
|
-
const reverse =
|
|
57
|
-
const clickable =
|
|
52
|
+
const border = borderProp ?? tokens.defaults.border;
|
|
53
|
+
const center = centerProp ?? tokens.defaults.center;
|
|
54
|
+
const square = squareProp ?? tokens.defaults.square;
|
|
55
|
+
const direction = directionProp ?? tokens.defaults.direction;
|
|
56
|
+
const reverse = reverseProp ?? tokens.defaults.reverse;
|
|
57
|
+
const clickable = clickableProp ?? tokens.defaults.clickable;
|
|
58
58
|
const iconSize = (0, _react().useMemo)(() => {
|
|
59
|
-
const
|
|
60
|
-
return Number.isFinite(
|
|
59
|
+
const value = iconSizeProp ?? tokens.defaults.iconSize;
|
|
60
|
+
return Number.isFinite(value) && value > 0 ? value : tokens.defaults.iconSize;
|
|
61
61
|
}, [iconSizeProp, tokens.defaults.iconSize]);
|
|
62
|
-
const
|
|
62
|
+
const childrenArray = (0, _react().useMemo)(() => _react().default.Children.toArray(children).filter(child => /*#__PURE__*/_react().default.isValidElement(child)), [children]);
|
|
63
63
|
const showBorder = border && !gutter;
|
|
64
64
|
const borderColor = tokens.colors.border;
|
|
65
65
|
const topBorder = (0, _react().useMemo)(() => showBorder ? /*#__PURE__*/_react().default.createElement(_reactNative().View, {
|
|
@@ -81,19 +81,19 @@ const Grid = props => {
|
|
|
81
81
|
})]
|
|
82
82
|
}) : null, [borderColor, showBorder, tokens.layout.border, tokens.layout.borderBottom]);
|
|
83
83
|
const contextValue = (0, _react().useMemo)(() => ({
|
|
84
|
-
columnNum,
|
|
85
|
-
gutter,
|
|
86
|
-
border,
|
|
87
|
-
center,
|
|
88
|
-
square,
|
|
89
|
-
direction,
|
|
90
|
-
reverse,
|
|
91
|
-
clickable,
|
|
92
|
-
iconSize,
|
|
84
|
+
columnNum: columnNum,
|
|
85
|
+
gutter: gutter,
|
|
86
|
+
border: border,
|
|
87
|
+
center: center,
|
|
88
|
+
square: square,
|
|
89
|
+
direction: direction,
|
|
90
|
+
reverse: reverse,
|
|
91
|
+
clickable: clickable,
|
|
92
|
+
iconSize: iconSize,
|
|
93
93
|
iconColor,
|
|
94
|
-
count:
|
|
95
|
-
tokens
|
|
96
|
-
}), [border, center,
|
|
94
|
+
count: childrenArray.length,
|
|
95
|
+
tokens: tokens
|
|
96
|
+
}), [border, center, childrenArray.length, clickable, columnNum, direction, gutter, iconColor, iconSize, reverse, square, tokens]);
|
|
97
97
|
const webGridStyle = (0, _react().useMemo)(() => _reactNative().Platform.OS === 'web' ? {
|
|
98
98
|
display: 'grid',
|
|
99
99
|
gridTemplateColumns: `repeat(${columnNum}, minmax(0, 1fr))`,
|
|
@@ -103,15 +103,16 @@ const Grid = props => {
|
|
|
103
103
|
const containerStyle = (0, _react().useMemo)(() => [tokens.layout.container, _reactNative().Platform.OS === 'web' ? webGridStyle : gutter ? {
|
|
104
104
|
paddingLeft: gutter
|
|
105
105
|
} : undefined, style], [gutter, style, tokens.layout.container, webGridStyle]);
|
|
106
|
-
const renderedChildren = (0, _react().useMemo)(() =>
|
|
106
|
+
const renderedChildren = (0, _react().useMemo)(() => childrenArray.map((child, index) => /*#__PURE__*/_react().default.cloneElement(child, {
|
|
107
107
|
gridItemIndex: index,
|
|
108
108
|
key: child.key ?? index
|
|
109
|
-
})), [
|
|
109
|
+
})), [childrenArray]);
|
|
110
110
|
return /*#__PURE__*/_react().default.createElement(GridContext.Provider, {
|
|
111
111
|
value: contextValue
|
|
112
112
|
}, /*#__PURE__*/_react().default.createElement(_reactNative().View, _extends({
|
|
113
|
+
accessibilityRole: 'grid',
|
|
113
114
|
style: containerStyle
|
|
114
115
|
}, rest), topBorder, renderedChildren, bottomBorder));
|
|
115
116
|
};
|
|
116
|
-
exports.Grid =
|
|
117
|
+
const Grid = exports.Grid = /*#__PURE__*/_react().default.memo(GridImpl);
|
|
117
118
|
Grid.displayName = 'Grid';
|