react-native-system-ui 0.0.7 → 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 +46 -31
- 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 +9 -2
|
@@ -1,52 +1,51 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Pressable, Text, View } from 'react-native';
|
|
4
4
|
import { useControllableValue } from '../../hooks';
|
|
5
|
-
import {
|
|
5
|
+
import { renderTextOrNode } from '../../utils';
|
|
6
|
+
import { isRenderable } from '../../utils/validate';
|
|
6
7
|
import Popup from '../popup';
|
|
8
|
+
import { useLocale } from '../config-provider/useLocale';
|
|
7
9
|
import { useCalendarTokens } from './tokens';
|
|
8
10
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
9
11
|
const isSameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
10
12
|
const startOfDay = date => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
return
|
|
13
|
+
const newDate = new Date(date);
|
|
14
|
+
newDate.setHours(0, 0, 0, 0);
|
|
15
|
+
return newDate;
|
|
14
16
|
};
|
|
15
17
|
const daysBetween = (a, b) => Math.round(Math.abs(startOfDay(a).getTime() - startOfDay(b).getTime()) / DAY_MS);
|
|
16
|
-
const toArrayValue = value =>
|
|
17
|
-
if (!value) return [];
|
|
18
|
-
return Array.isArray(value) ? value.filter(Boolean).map(date => new Date(date)) : [new Date(value)];
|
|
19
|
-
};
|
|
18
|
+
const toArrayValue = value => !value ? [] : Array.isArray(value) ? value.filter(Boolean).map(d => new Date(d)) : [new Date(value)];
|
|
20
19
|
const DEFAULT_MIN = new Date(new Date().getFullYear() - 10, 0, 1);
|
|
21
20
|
const DEFAULT_MAX = new Date(new Date().getFullYear() + 10, 11, 31);
|
|
22
|
-
const
|
|
21
|
+
const CalendarImpl = props => {
|
|
23
22
|
const {
|
|
24
23
|
tokensOverride,
|
|
25
24
|
value: _value,
|
|
26
25
|
defaultValue: _defaultValue,
|
|
27
26
|
minDate = DEFAULT_MIN,
|
|
28
27
|
maxDate = DEFAULT_MAX,
|
|
29
|
-
type
|
|
30
|
-
title
|
|
31
|
-
showSubtitle
|
|
32
|
-
showHeader
|
|
33
|
-
showConfirm
|
|
34
|
-
confirmText
|
|
35
|
-
weekStartsOn
|
|
28
|
+
type,
|
|
29
|
+
title,
|
|
30
|
+
showSubtitle,
|
|
31
|
+
showHeader,
|
|
32
|
+
showConfirm,
|
|
33
|
+
confirmText,
|
|
34
|
+
weekStartsOn,
|
|
36
35
|
weekdays,
|
|
37
36
|
formatMonthTitle,
|
|
38
|
-
allowSameDay
|
|
37
|
+
allowSameDay,
|
|
39
38
|
maxRange,
|
|
40
39
|
onOverRange,
|
|
41
|
-
poppable
|
|
40
|
+
poppable,
|
|
42
41
|
visible: _visible,
|
|
43
42
|
defaultVisible: _defaultVisible,
|
|
44
43
|
onVisibleChange: _onVisibleChange,
|
|
45
|
-
closeOnClickOverlay
|
|
46
|
-
closeOnConfirm
|
|
47
|
-
popupPlacement
|
|
48
|
-
popupRound
|
|
49
|
-
popupProps
|
|
44
|
+
closeOnClickOverlay,
|
|
45
|
+
closeOnConfirm,
|
|
46
|
+
popupPlacement,
|
|
47
|
+
popupRound,
|
|
48
|
+
popupProps,
|
|
50
49
|
onOpen,
|
|
51
50
|
onOpened,
|
|
52
51
|
onClose,
|
|
@@ -57,20 +56,22 @@ const Calendar = props => {
|
|
|
57
56
|
style,
|
|
58
57
|
...rest
|
|
59
58
|
} = props;
|
|
59
|
+
const locale = useLocale();
|
|
60
|
+
const calendarLocale = locale?.vanCalendar;
|
|
60
61
|
const tokens = useCalendarTokens(tokensOverride);
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
62
|
+
const resolvedTitle = title ?? calendarLocale?.title ?? tokens.defaults.title;
|
|
63
|
+
const resolvedShowSubtitle = showSubtitle ?? tokens.defaults.showSubtitle;
|
|
64
|
+
const resolvedShowHeader = showHeader ?? tokens.defaults.showHeader;
|
|
65
|
+
const resolvedConfirmText = confirmText ?? calendarLocale?.confirm ?? tokens.defaults.confirmText;
|
|
66
|
+
const resolvedWeekStartsOn = weekStartsOn ?? tokens.defaults.weekStartsOn;
|
|
67
|
+
const resolvedAllowSameDay = allowSameDay ?? tokens.defaults.allowSameDay;
|
|
68
|
+
const resolvedPoppable = poppable ?? tokens.defaults.poppable;
|
|
69
|
+
const resolvedCloseOnClickOverlay = closeOnClickOverlay ?? tokens.defaults.closeOnClickOverlay;
|
|
70
|
+
const resolvedCloseOnConfirm = closeOnConfirm ?? tokens.defaults.closeOnConfirm;
|
|
71
|
+
const resolvedPopupPlacement = popupPlacement ?? tokens.defaults.popupPlacement;
|
|
72
|
+
const resolvedPopupRound = popupRound ?? tokens.defaults.popupRound;
|
|
73
|
+
const resolvedType = type ?? tokens.defaults.type;
|
|
74
|
+
const resolvedShowConfirm = showConfirm ?? tokens.defaults.showConfirm[resolvedType];
|
|
74
75
|
const [popupVisible, setPopupVisible] = useControllableValue(props, {
|
|
75
76
|
defaultValue: false,
|
|
76
77
|
valuePropName: 'visible',
|
|
@@ -82,222 +83,230 @@ const Calendar = props => {
|
|
|
82
83
|
onClosed: popupOnClosed,
|
|
83
84
|
onOpen: popupOnOpen,
|
|
84
85
|
onOpened: popupOnOpened,
|
|
85
|
-
closeOnOverlayPress:
|
|
86
|
+
closeOnOverlayPress: overlayCloseOnPress,
|
|
86
87
|
overlay: popupOverlay,
|
|
87
88
|
...popupRestProps
|
|
88
|
-
} =
|
|
89
|
+
} = popupProps ?? {};
|
|
90
|
+
const callbacksRef = useRef({
|
|
91
|
+
onConfirm,
|
|
92
|
+
onOverRange,
|
|
93
|
+
popupOnOpen,
|
|
94
|
+
onOpen,
|
|
95
|
+
popupOnOpened,
|
|
96
|
+
onOpened,
|
|
97
|
+
popupOnClose,
|
|
98
|
+
onClose,
|
|
99
|
+
popupOnClosed,
|
|
100
|
+
onClosed
|
|
101
|
+
});
|
|
102
|
+
callbacksRef.current.onConfirm = onConfirm;
|
|
103
|
+
callbacksRef.current.onOverRange = onOverRange;
|
|
104
|
+
callbacksRef.current.popupOnOpen = popupOnOpen;
|
|
105
|
+
callbacksRef.current.onOpen = onOpen;
|
|
106
|
+
callbacksRef.current.popupOnOpened = popupOnOpened;
|
|
107
|
+
callbacksRef.current.onOpened = onOpened;
|
|
108
|
+
callbacksRef.current.popupOnClose = popupOnClose;
|
|
109
|
+
callbacksRef.current.onClose = onClose;
|
|
110
|
+
callbacksRef.current.popupOnClosed = popupOnClosed;
|
|
111
|
+
callbacksRef.current.onClosed = onClosed;
|
|
89
112
|
const closePopup = useCallback(() => {
|
|
90
|
-
if (!
|
|
113
|
+
if (!resolvedPoppable) return;
|
|
91
114
|
setPopupVisible(false);
|
|
92
|
-
}, [
|
|
115
|
+
}, [resolvedPoppable, setPopupVisible]);
|
|
93
116
|
const handlePopupOpen = useCallback(() => {
|
|
94
|
-
popupOnOpen?.();
|
|
95
|
-
onOpen?.();
|
|
96
|
-
}, [
|
|
117
|
+
callbacksRef.current.popupOnOpen?.();
|
|
118
|
+
callbacksRef.current.onOpen?.();
|
|
119
|
+
}, []);
|
|
97
120
|
const handlePopupOpened = useCallback(() => {
|
|
98
|
-
popupOnOpened?.();
|
|
99
|
-
onOpened?.();
|
|
100
|
-
}, [
|
|
121
|
+
callbacksRef.current.popupOnOpened?.();
|
|
122
|
+
callbacksRef.current.onOpened?.();
|
|
123
|
+
}, []);
|
|
101
124
|
const handlePopupClose = useCallback(() => {
|
|
102
125
|
closePopup();
|
|
103
|
-
popupOnClose?.();
|
|
104
|
-
onClose?.();
|
|
105
|
-
}, [closePopup
|
|
126
|
+
callbacksRef.current.popupOnClose?.();
|
|
127
|
+
callbacksRef.current.onClose?.();
|
|
128
|
+
}, [closePopup]);
|
|
106
129
|
const handlePopupClosed = useCallback(() => {
|
|
107
|
-
popupOnClosed?.();
|
|
108
|
-
onClosed?.();
|
|
109
|
-
}, [
|
|
110
|
-
const
|
|
111
|
-
const
|
|
130
|
+
callbacksRef.current.popupOnClosed?.();
|
|
131
|
+
callbacksRef.current.onClosed?.();
|
|
132
|
+
}, []);
|
|
133
|
+
const overlayCloseOnPressResolved = overlayCloseOnPress ?? resolvedCloseOnClickOverlay;
|
|
134
|
+
const overlayResolved = popupOverlay ?? true;
|
|
112
135
|
const [selectedValue, setSelectedValue] = useControllableValue(props, {
|
|
113
136
|
defaultValue: null,
|
|
114
137
|
valuePropName: 'value',
|
|
115
138
|
defaultValuePropName: 'defaultValue',
|
|
116
139
|
trigger: 'onSelect'
|
|
117
140
|
});
|
|
118
|
-
const value = normalizeValue(toArrayValue(selectedValue),
|
|
119
|
-
const [currentMonth, setCurrentMonth] = useState(() =>
|
|
120
|
-
const initial = value.length ? value[0] : new Date();
|
|
121
|
-
return clampMonth(initial, minDate, maxDate);
|
|
122
|
-
});
|
|
141
|
+
const value = normalizeValue(toArrayValue(selectedValue), resolvedType);
|
|
142
|
+
const [currentMonth, setCurrentMonth] = useState(() => clampMonth(value.length ? value[0] : new Date(), minDate, maxDate));
|
|
123
143
|
const firstValueTime = value.length ? value[0].getTime() : null;
|
|
124
144
|
const minDateTime = minDate.getTime();
|
|
125
145
|
const maxDateTime = maxDate.getTime();
|
|
126
146
|
useEffect(() => {
|
|
127
|
-
if (!value.length)
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
147
|
+
if (!value.length) return;
|
|
130
148
|
const first = clampMonth(value[0], minDate, maxDate);
|
|
131
149
|
setCurrentMonth(prev => isSameMonth(first, prev) ? prev : first);
|
|
132
150
|
}, [firstValueTime, minDateTime, maxDateTime]);
|
|
133
|
-
const monthDays = useMemo(() => buildMonth(currentMonth,
|
|
134
|
-
const
|
|
151
|
+
const monthDays = useMemo(() => buildMonth(currentMonth, resolvedWeekStartsOn), [currentMonth, resolvedWeekStartsOn]);
|
|
152
|
+
const monthDaysMapped = useMemo(() => monthDays.map(day => day ? {
|
|
135
153
|
day,
|
|
136
154
|
key: day.toISOString(),
|
|
137
155
|
timeValue: startOfDay(day).getTime(),
|
|
138
156
|
dateValue: day.getDate()
|
|
139
157
|
} : null), [monthDays]);
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
158
|
+
const minDayTime = startOfDay(minDate).getTime();
|
|
159
|
+
const maxDayTime = startOfDay(maxDate).getTime();
|
|
160
|
+
const resolvedWeekdays = weekdays ?? calendarLocale?.weekdays ?? tokens.defaults.weekdays;
|
|
161
|
+
const weekLabels = useMemo(() => reorderWeekdays(resolvedWeekdays, resolvedWeekStartsOn, tokens.defaults.weekdays), [resolvedWeekdays, tokens.defaults.weekdays, resolvedWeekStartsOn]);
|
|
162
|
+
const monthLabel = useMemo(() => formatMonthTitle ? formatMonthTitle(currentMonth) : calendarLocale?.monthTitle ? calendarLocale.monthTitle(currentMonth.getFullYear(), currentMonth.getMonth() + 1) : formatMonth(currentMonth), [currentMonth, formatMonthTitle, calendarLocale]);
|
|
144
163
|
const minMonthStart = startOfMonth(minDate);
|
|
145
164
|
const maxMonthStart = startOfMonth(maxDate);
|
|
146
165
|
const canGoPrev = currentMonth.getTime() > minMonthStart.getTime();
|
|
147
166
|
const canGoNext = currentMonth.getTime() < maxMonthStart.getTime();
|
|
148
|
-
const goToMonth = useCallback(delta =>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const confirmDisabled =
|
|
167
|
+
const goToMonth = useCallback(delta => setCurrentMonth(prev => clampMonth(new Date(prev.getFullYear(), prev.getMonth() + delta, 1), minDate, maxDate)), [minDate, maxDate]);
|
|
168
|
+
const goPrev = useCallback(() => goToMonth(-1), [goToMonth]);
|
|
169
|
+
const goNext = useCallback(() => goToMonth(1), [goToMonth]);
|
|
170
|
+
const confirmDisabled = resolvedType === 'range' ? value.length < 2 : value.length === 0;
|
|
152
171
|
const columnPadding = tokens.spacing.column / 2;
|
|
153
172
|
const maybeAutoConfirm = useCallback(next => {
|
|
154
|
-
if (
|
|
155
|
-
if (
|
|
156
|
-
if (
|
|
173
|
+
if (resolvedShowConfirm) return;
|
|
174
|
+
if (resolvedType === 'range' && next.length < 2) return;
|
|
175
|
+
if (resolvedType === 'multiple' && next.length === 0) return;
|
|
157
176
|
if (!next.length) return;
|
|
158
|
-
onConfirm?.(mapValue(next,
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
}, [showConfirm, type, onConfirm, poppable, closeOnConfirm, closePopup]);
|
|
177
|
+
callbacksRef.current.onConfirm?.(mapValue(next, resolvedType));
|
|
178
|
+
if (resolvedPoppable && resolvedCloseOnConfirm) closePopup();
|
|
179
|
+
}, [resolvedShowConfirm, resolvedType, resolvedPoppable, resolvedCloseOnConfirm, closePopup]);
|
|
163
180
|
const handleConfirm = useCallback(() => {
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (poppable && closeOnConfirm) {
|
|
169
|
-
closePopup();
|
|
170
|
-
}
|
|
171
|
-
}, [showConfirm, confirmDisabled, onConfirm, value, type, poppable, closeOnConfirm, closePopup]);
|
|
181
|
+
if (resolvedShowConfirm && confirmDisabled) return;
|
|
182
|
+
callbacksRef.current.onConfirm?.(mapValue(value, resolvedType));
|
|
183
|
+
if (resolvedPoppable && resolvedCloseOnConfirm) closePopup();
|
|
184
|
+
}, [resolvedShowConfirm, confirmDisabled, value, resolvedType, resolvedPoppable, resolvedCloseOnConfirm, closePopup]);
|
|
172
185
|
const isSelectionAllowed = useCallback(next => {
|
|
173
|
-
if (
|
|
186
|
+
if (resolvedType === 'range' && next.length === 2) {
|
|
174
187
|
const [start, end] = next;
|
|
175
|
-
if (!
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
188
|
+
if (!resolvedAllowSameDay && isSameDay(start, end)) return false;
|
|
178
189
|
if (maxRange && daysBetween(start, end) + 1 > maxRange) {
|
|
179
|
-
onOverRange?.(maxRange);
|
|
190
|
+
callbacksRef.current.onOverRange?.(maxRange);
|
|
180
191
|
return false;
|
|
181
192
|
}
|
|
182
193
|
}
|
|
183
|
-
if (
|
|
184
|
-
onOverRange?.(maxRange);
|
|
194
|
+
if (resolvedType === 'multiple' && maxRange && next.length > maxRange) {
|
|
195
|
+
callbacksRef.current.onOverRange?.(maxRange);
|
|
185
196
|
return false;
|
|
186
197
|
}
|
|
198
|
+
;
|
|
187
199
|
return true;
|
|
188
|
-
}, [
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
200
|
+
}, [resolvedType, resolvedAllowSameDay, maxRange]);
|
|
201
|
+
const handleSelectDayRef = useRef(undefined);
|
|
202
|
+
const handleSelectDay = useCallback(date => {
|
|
203
|
+
const dateTime = startOfDay(date).getTime();
|
|
204
|
+
if (dateTime < minDayTime || dateTime > maxDayTime) return;
|
|
194
205
|
let next = [];
|
|
195
|
-
const
|
|
196
|
-
switch (
|
|
206
|
+
const nextValue = value;
|
|
207
|
+
switch (resolvedType) {
|
|
197
208
|
case 'single':
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
209
|
+
next = [date];
|
|
210
|
+
break;
|
|
202
211
|
case 'multiple':
|
|
203
212
|
{
|
|
204
|
-
const
|
|
205
|
-
next =
|
|
213
|
+
const existing = nextValue.find(item => isSameDay(item, date));
|
|
214
|
+
next = existing ? nextValue.filter(item => !isSameDay(item, date)) : [...nextValue, date];
|
|
206
215
|
break;
|
|
207
216
|
}
|
|
208
217
|
case 'range':
|
|
209
218
|
{
|
|
210
|
-
if (
|
|
211
|
-
next = [
|
|
219
|
+
if (nextValue.length < 1 || nextValue.length > 1) {
|
|
220
|
+
next = [date];
|
|
212
221
|
} else {
|
|
213
|
-
const first =
|
|
214
|
-
if (isSameDay(first,
|
|
215
|
-
next =
|
|
222
|
+
const first = nextValue[0];
|
|
223
|
+
if (isSameDay(first, date)) {
|
|
224
|
+
next = resolvedAllowSameDay ? [first, date] : [date];
|
|
216
225
|
} else {
|
|
217
|
-
next = [first,
|
|
226
|
+
next = [first, date].sort((a, b) => a.getTime() - b.getTime());
|
|
218
227
|
}
|
|
219
228
|
}
|
|
220
229
|
break;
|
|
221
230
|
}
|
|
222
231
|
default:
|
|
223
|
-
next = [
|
|
224
|
-
}
|
|
225
|
-
const normalizedNext = normalizeValue(next, type);
|
|
226
|
-
if (!isSelectionAllowed(normalizedNext)) {
|
|
227
|
-
return;
|
|
232
|
+
next = [date];
|
|
228
233
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
+
;
|
|
235
|
+
const normalizedNextValue = normalizeValue(next, resolvedType);
|
|
236
|
+
if (!isSelectionAllowed(normalizedNextValue)) return;
|
|
237
|
+
setSelectedValue(mapValue(normalizedNextValue, resolvedType));
|
|
238
|
+
if (!resolvedShowConfirm) maybeAutoConfirm(normalizedNextValue);
|
|
239
|
+
}, [value, resolvedType, minDayTime, maxDayTime, resolvedAllowSameDay, isSelectionAllowed, setSelectedValue, resolvedShowConfirm, maybeAutoConfirm]);
|
|
240
|
+
handleSelectDayRef.current = handleSelectDay;
|
|
241
|
+
const selectDayPress = useCallback(date => handleSelectDayRef.current?.(date), []);
|
|
234
242
|
const valueTimes = useMemo(() => value.map(item => startOfDay(item).getTime()), [value]);
|
|
235
|
-
const
|
|
236
|
-
const rangeBounds =
|
|
237
|
-
const renderDay = useCallback((
|
|
238
|
-
if (!
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
}
|
|
243
|
+
const selected = useMemo(() => new Set(valueTimes), [valueTimes]);
|
|
244
|
+
const rangeBounds = resolvedType === 'range' && valueTimes.length === 2 ? [valueTimes[0], valueTimes[1]] : null;
|
|
245
|
+
const renderDay = useCallback((mapped, index) => {
|
|
246
|
+
if (!mapped) return /*#__PURE__*/React.createElement(View, {
|
|
247
|
+
key: `p-${index}`,
|
|
248
|
+
style: [tokens.layout.dayPlaceholder, {
|
|
249
|
+
paddingVertical: tokens.spacing.dayPaddingVertical,
|
|
250
|
+
paddingHorizontal: columnPadding
|
|
251
|
+
}]
|
|
252
|
+
});
|
|
247
253
|
const {
|
|
248
254
|
day,
|
|
249
255
|
key,
|
|
250
256
|
timeValue,
|
|
251
257
|
dateValue
|
|
252
|
-
} =
|
|
253
|
-
const isDisabled = timeValue <
|
|
254
|
-
const isSelected =
|
|
255
|
-
const inRange =
|
|
256
|
-
const
|
|
258
|
+
} = mapped;
|
|
259
|
+
const isDisabled = timeValue < minDayTime || timeValue > maxDayTime;
|
|
260
|
+
const isSelected = selected.has(timeValue);
|
|
261
|
+
const inRange = resolvedType === 'range' && rangeBounds && timeValue > rangeBounds[0] && timeValue < rangeBounds[1];
|
|
262
|
+
const dayStyles = [tokens.layout.dayText, {
|
|
257
263
|
borderRadius: tokens.radii.day,
|
|
258
264
|
color: tokens.colors.text,
|
|
259
265
|
minWidth: tokens.sizing.dayMinWidth
|
|
260
266
|
}];
|
|
261
|
-
if (isDisabled) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
dayStyle.push({
|
|
271
|
-
backgroundColor: color ?? tokens.colors.selectedBackground,
|
|
272
|
-
color: tokens.colors.selectedText
|
|
273
|
-
});
|
|
274
|
-
}
|
|
267
|
+
if (isDisabled) dayStyles.push({
|
|
268
|
+
color: tokens.colors.disabled
|
|
269
|
+
});else if (inRange) dayStyles.push({
|
|
270
|
+
backgroundColor: tokens.colors.rangeBackground
|
|
271
|
+
});else if (isSelected) dayStyles.push({
|
|
272
|
+
backgroundColor: color ?? tokens.colors.selectedBackground,
|
|
273
|
+
color: tokens.colors.selectedText
|
|
274
|
+
});
|
|
275
|
+
const accessibility = `${day.getFullYear()}-${String(day.getMonth() + 1).padStart(2, '0')}-${String(day.getDate()).padStart(2, '0')}${isSelected ? ', selected' : ''}${isDisabled ? ', disabled' : ''}`;
|
|
275
276
|
return /*#__PURE__*/React.createElement(Pressable, {
|
|
276
277
|
key: key,
|
|
278
|
+
accessibilityRole: "button",
|
|
279
|
+
accessibilityLabel: accessibility,
|
|
280
|
+
accessibilityState: {
|
|
281
|
+
selected: isSelected,
|
|
282
|
+
disabled: isDisabled
|
|
283
|
+
},
|
|
277
284
|
style: [tokens.layout.dayButton, {
|
|
278
285
|
paddingVertical: tokens.spacing.dayPaddingVertical,
|
|
279
286
|
paddingHorizontal: columnPadding
|
|
280
287
|
}],
|
|
281
288
|
disabled: isDisabled,
|
|
282
|
-
onPress: () =>
|
|
289
|
+
onPress: () => selectDayPress(day),
|
|
283
290
|
testID: getCalendarDayTestId(day)
|
|
284
291
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
285
|
-
style:
|
|
292
|
+
style: dayStyles
|
|
286
293
|
}, dateValue));
|
|
287
|
-
}, [
|
|
294
|
+
}, [selected, resolvedType, rangeBounds, minDayTime, maxDayTime, tokens, color, selectDayPress, columnPadding]);
|
|
288
295
|
const content = /*#__PURE__*/React.createElement(View, _extends({
|
|
289
296
|
style: [{
|
|
290
297
|
backgroundColor: tokens.colors.background,
|
|
291
298
|
padding: tokens.spacing.containerPadding,
|
|
292
299
|
borderRadius: tokens.radii.container
|
|
293
300
|
}, style]
|
|
294
|
-
}, rest),
|
|
301
|
+
}, rest), resolvedShowHeader ? /*#__PURE__*/React.createElement(View, {
|
|
295
302
|
style: [tokens.layout.header, {
|
|
296
303
|
marginBottom: tokens.spacing.headerMarginBottom
|
|
297
304
|
}]
|
|
298
305
|
}, /*#__PURE__*/React.createElement(Pressable, {
|
|
299
306
|
testID: "calendar-nav-prev",
|
|
300
|
-
|
|
307
|
+
accessibilityRole: "button",
|
|
308
|
+
accessibilityLabel: "previous month",
|
|
309
|
+
onPress: goPrev,
|
|
301
310
|
disabled: !canGoPrev
|
|
302
311
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
303
312
|
style: [tokens.layout.navText, {
|
|
@@ -308,20 +317,18 @@ const Calendar = props => {
|
|
|
308
317
|
}]
|
|
309
318
|
}, '<')), /*#__PURE__*/React.createElement(View, {
|
|
310
319
|
style: tokens.layout.headerCenter
|
|
311
|
-
},
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
color: tokens.colors.headerSubtitle,
|
|
320
|
-
fontSize: tokens.typography.headerSubtitleSize
|
|
321
|
-
}]
|
|
322
|
-
}, monthLabel) : monthLabel : null), /*#__PURE__*/React.createElement(Pressable, {
|
|
320
|
+
}, isRenderable(resolvedTitle) ? renderTextOrNode(resolvedTitle, [tokens.layout.headerTitle, {
|
|
321
|
+
color: tokens.colors.text,
|
|
322
|
+
fontSize: tokens.typography.headerTitleSize,
|
|
323
|
+
fontWeight: tokens.typography.headerTitleWeight
|
|
324
|
+
}]) : null, resolvedShowSubtitle ? renderTextOrNode(monthLabel, [tokens.layout.headerSubtitle, {
|
|
325
|
+
color: tokens.colors.headerSubtitle,
|
|
326
|
+
fontSize: tokens.typography.headerSubtitleSize
|
|
327
|
+
}]) : null), /*#__PURE__*/React.createElement(Pressable, {
|
|
323
328
|
testID: "calendar-nav-next",
|
|
324
|
-
|
|
329
|
+
accessibilityRole: "button",
|
|
330
|
+
accessibilityLabel: "next month",
|
|
331
|
+
onPress: goNext,
|
|
325
332
|
disabled: !canGoNext
|
|
326
333
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
327
334
|
style: [tokens.layout.navText, {
|
|
@@ -334,20 +341,18 @@ const Calendar = props => {
|
|
|
334
341
|
style: [tokens.layout.weekRow, {
|
|
335
342
|
marginBottom: tokens.spacing.weekRowMarginBottom
|
|
336
343
|
}]
|
|
337
|
-
}, weekLabels.map((label,
|
|
338
|
-
key: `
|
|
344
|
+
}, weekLabels.map((label, i) => /*#__PURE__*/React.createElement(View, {
|
|
345
|
+
key: `w-${i}`,
|
|
339
346
|
style: [tokens.layout.weekLabelItem, {
|
|
340
347
|
paddingHorizontal: columnPadding
|
|
341
348
|
}]
|
|
342
|
-
},
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}]
|
|
346
|
-
}, label) : label))), /*#__PURE__*/React.createElement(View, {
|
|
349
|
+
}, renderTextOrNode(label, [tokens.layout.weekLabel, {
|
|
350
|
+
color: tokens.colors.text
|
|
351
|
+
}])))), /*#__PURE__*/React.createElement(View, {
|
|
347
352
|
style: [tokens.layout.days, {
|
|
348
353
|
rowGap: tokens.spacing.row
|
|
349
354
|
}]
|
|
350
|
-
},
|
|
355
|
+
}, monthDaysMapped.map((mapped, i) => renderDay(mapped, i))), resolvedShowConfirm ? /*#__PURE__*/React.createElement(Pressable, {
|
|
351
356
|
style: [tokens.layout.confirmButton, {
|
|
352
357
|
backgroundColor: color ?? tokens.colors.selectedBackground,
|
|
353
358
|
opacity: confirmDisabled ? 0.5 : 1,
|
|
@@ -357,23 +362,19 @@ const Calendar = props => {
|
|
|
357
362
|
}],
|
|
358
363
|
onPress: handleConfirm,
|
|
359
364
|
disabled: confirmDisabled
|
|
360
|
-
},
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}, confirmText) : confirmText) : null);
|
|
366
|
-
if (!poppable) {
|
|
367
|
-
return content;
|
|
368
|
-
}
|
|
365
|
+
}, renderTextOrNode(resolvedConfirmText, [tokens.layout.confirmText, {
|
|
366
|
+
color: tokens.colors.confirmText,
|
|
367
|
+
fontWeight: tokens.typography.confirmTextWeight
|
|
368
|
+
}])) : null);
|
|
369
|
+
if (!resolvedPoppable) return content;
|
|
369
370
|
return /*#__PURE__*/React.createElement(Popup, _extends({
|
|
370
371
|
visible: popupVisible,
|
|
371
|
-
placement:
|
|
372
|
-
round:
|
|
373
|
-
closeOnOverlayPress:
|
|
374
|
-
overlay:
|
|
375
|
-
safeAreaInsetTop: popupRestProps?.safeAreaInsetTop
|
|
376
|
-
safeAreaInsetBottom: popupRestProps?.safeAreaInsetBottom
|
|
372
|
+
placement: resolvedPopupPlacement,
|
|
373
|
+
round: resolvedPopupRound,
|
|
374
|
+
closeOnOverlayPress: overlayCloseOnPressResolved,
|
|
375
|
+
overlay: overlayResolved,
|
|
376
|
+
safeAreaInsetTop: popupRestProps?.safeAreaInsetTop != null ? popupRestProps.safeAreaInsetTop : resolvedShowHeader,
|
|
377
|
+
safeAreaInsetBottom: popupRestProps?.safeAreaInsetBottom != null ? popupRestProps.safeAreaInsetBottom : resolvedPopupPlacement === 'bottom',
|
|
377
378
|
onOpen: handlePopupOpen,
|
|
378
379
|
onOpened: handlePopupOpened,
|
|
379
380
|
onClose: handlePopupClose,
|
|
@@ -381,25 +382,17 @@ const Calendar = props => {
|
|
|
381
382
|
}, popupRestProps), content);
|
|
382
383
|
};
|
|
383
384
|
function mapValue(value, type) {
|
|
384
|
-
if (type === 'single')
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
if (type === 'range' && value.length === 2) {
|
|
388
|
-
return value;
|
|
389
|
-
}
|
|
385
|
+
if (type === 'single') return value[0] ?? new Date();
|
|
386
|
+
if (type === 'range' && value.length === 2) return value;
|
|
390
387
|
return value;
|
|
391
388
|
}
|
|
392
389
|
function normalizeValue(value, type) {
|
|
393
|
-
if (type === 'single')
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
if (type === 'range') {
|
|
397
|
-
return value.slice(0, 2).sort((a, b) => a.getTime() - b.getTime());
|
|
398
|
-
}
|
|
390
|
+
if (type === 'single') return value.slice(0, 1);
|
|
391
|
+
if (type === 'range') return value.slice(0, 2).sort((a, b) => a.getTime() - b.getTime());
|
|
399
392
|
return value;
|
|
400
393
|
}
|
|
401
394
|
function formatMonth(date) {
|
|
402
|
-
return `${date.getFullYear()}
|
|
395
|
+
return `${date.getFullYear()}/${date.getMonth() + 1}`;
|
|
403
396
|
}
|
|
404
397
|
function reorderWeekdays(labels, start, fallback) {
|
|
405
398
|
const normalizedStart = (start % 7 + 7) % 7;
|
|
@@ -411,20 +404,14 @@ function buildMonth(month, weekStartsOn) {
|
|
|
411
404
|
const firstDay = startOfMonth(month);
|
|
412
405
|
const startOffset = (firstDay.getDay() - normalizedStart + 7) % 7;
|
|
413
406
|
const daysInMonth = new Date(month.getFullYear(), month.getMonth() + 1, 0).getDate();
|
|
414
|
-
const
|
|
415
|
-
for (let i = 0; i < startOffset; i += 1)
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
cells.push(new Date(month.getFullYear(), month.getMonth(), day));
|
|
420
|
-
}
|
|
421
|
-
while (cells.length < 42) {
|
|
422
|
-
cells.push(null);
|
|
423
|
-
}
|
|
424
|
-
return cells;
|
|
407
|
+
const calendar = [];
|
|
408
|
+
for (let i = 0; i < startOffset; i += 1) calendar.push(null);
|
|
409
|
+
for (let day = 1; day <= daysInMonth; day += 1) calendar.push(new Date(month.getFullYear(), month.getMonth(), day));
|
|
410
|
+
while (calendar.length < 42) calendar.push(null);
|
|
411
|
+
return calendar;
|
|
425
412
|
}
|
|
426
|
-
function getCalendarDayTestId(
|
|
427
|
-
return `calendar-day-${
|
|
413
|
+
function getCalendarDayTestId(date) {
|
|
414
|
+
return `calendar-day-${date.getFullYear()}-${`${date.getMonth() + 1}`.padStart(2, '0')}-${`${date.getDate()}`.padStart(2, '0')}`;
|
|
428
415
|
}
|
|
429
416
|
function startOfMonth(date) {
|
|
430
417
|
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
@@ -434,10 +421,12 @@ function clampMonth(date, min, max) {
|
|
|
434
421
|
const minMonth = startOfMonth(min);
|
|
435
422
|
const maxMonth = startOfMonth(max);
|
|
436
423
|
if (month.getTime() < minMonth.getTime()) return minMonth;
|
|
437
|
-
if (month.getTime() > maxMonth.getTime()) return
|
|
424
|
+
if (month.getTime() > maxMonth.getTime()) return max;
|
|
438
425
|
return month;
|
|
439
426
|
}
|
|
440
427
|
function isSameMonth(a, b) {
|
|
441
428
|
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
442
429
|
}
|
|
430
|
+
const Calendar = /*#__PURE__*/React.memo(CalendarImpl);
|
|
431
|
+
Calendar.displayName = 'Calendar';
|
|
443
432
|
export default Calendar;
|
|
@@ -11,7 +11,7 @@ export const createCalendarTokens = foundations => {
|
|
|
11
11
|
return {
|
|
12
12
|
defaults: {
|
|
13
13
|
type: "single",
|
|
14
|
-
title: "
|
|
14
|
+
title: "Select Date",
|
|
15
15
|
showSubtitle: true,
|
|
16
16
|
showHeader: true,
|
|
17
17
|
showConfirm: {
|
|
@@ -19,9 +19,9 @@ export const createCalendarTokens = foundations => {
|
|
|
19
19
|
range: true,
|
|
20
20
|
multiple: true
|
|
21
21
|
},
|
|
22
|
-
confirmText: "
|
|
22
|
+
confirmText: "Confirm",
|
|
23
23
|
weekStartsOn: 0,
|
|
24
|
-
weekdays: ["
|
|
24
|
+
weekdays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
25
25
|
allowSameDay: false,
|
|
26
26
|
poppable: false,
|
|
27
27
|
closeOnClickOverlay: true,
|