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
|
@@ -10,13 +10,12 @@ export const AvatarFallbackText = /*#__PURE__*/React.forwardRef(({
|
|
|
10
10
|
style
|
|
11
11
|
}, ref) => {
|
|
12
12
|
const tokens = useAvatarTokens();
|
|
13
|
-
const resolvedStyle = StyleSheet.flatten([tokens.layout.text, {
|
|
14
|
-
color: color ?? tokens.colors.text,
|
|
15
|
-
fontWeight: tokens.typography.fontWeight
|
|
16
|
-
}, style]);
|
|
17
13
|
return /*#__PURE__*/React.createElement(Text, {
|
|
18
14
|
ref: ref,
|
|
19
|
-
style:
|
|
15
|
+
style: StyleSheet.flatten([tokens.layout.text, {
|
|
16
|
+
color: color ?? tokens.colors.text,
|
|
17
|
+
fontWeight: tokens.typography.fontWeight
|
|
18
|
+
}, style]),
|
|
20
19
|
numberOfLines: 1
|
|
21
20
|
}, children);
|
|
22
21
|
});
|
|
@@ -37,17 +36,17 @@ export const AvatarImage = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
37
36
|
}));
|
|
38
37
|
});
|
|
39
38
|
AvatarImage.displayName = 'Avatar.Image';
|
|
40
|
-
|
|
39
|
+
const AvatarImpl = (props, ref) => {
|
|
41
40
|
const {
|
|
42
41
|
src,
|
|
43
42
|
source,
|
|
44
43
|
icon,
|
|
45
44
|
text,
|
|
46
|
-
size,
|
|
47
|
-
width,
|
|
48
|
-
height,
|
|
49
|
-
shape,
|
|
50
|
-
fit,
|
|
45
|
+
size: sizeProp,
|
|
46
|
+
width: widthProp,
|
|
47
|
+
height: heightProp,
|
|
48
|
+
shape: shapeProp,
|
|
49
|
+
fit: fitProp,
|
|
51
50
|
color,
|
|
52
51
|
backgroundColor,
|
|
53
52
|
style,
|
|
@@ -55,36 +54,35 @@ export const Avatar = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
55
54
|
contentStyle,
|
|
56
55
|
children,
|
|
57
56
|
tokensOverride,
|
|
58
|
-
...
|
|
57
|
+
...rest
|
|
59
58
|
} = props;
|
|
60
59
|
const tokens = useAvatarTokens(tokensOverride);
|
|
61
|
-
const resolvedSize =
|
|
62
|
-
const resolvedShape =
|
|
60
|
+
const resolvedSize = sizeProp ?? tokens.defaults.size;
|
|
61
|
+
const resolvedShape = shapeProp ?? tokens.defaults.shape;
|
|
63
62
|
const baseSize = isNumber(resolvedSize) ? resolvedSize : tokens.sizing.sizes[resolvedSize];
|
|
64
|
-
const avatarWidth =
|
|
65
|
-
const avatarHeight =
|
|
63
|
+
const avatarWidth = widthProp ?? baseSize;
|
|
64
|
+
const avatarHeight = heightProp ?? baseSize;
|
|
66
65
|
const borderRadius = resolvedShape === 'circle' ? Math.min(avatarWidth, avatarHeight) / 2 : Math.max(tokens.radii.squareMin, Math.min(avatarWidth, avatarHeight) / tokens.radii.squareDivisor);
|
|
67
66
|
const transparentContainerStyle = {
|
|
68
67
|
backgroundColor: tokens.colors.transparent
|
|
69
68
|
};
|
|
70
|
-
const fallbackText = text ? text.trim().slice(0, 2).toUpperCase() : undefined;
|
|
71
69
|
const fallbackContent = icon ? /*#__PURE__*/React.createElement(View, {
|
|
72
70
|
style: [tokens.layout.iconWrapper, {
|
|
73
71
|
width: Math.min(avatarWidth, tokens.sizing.iconMaxSize),
|
|
74
72
|
height: Math.min(avatarHeight, tokens.sizing.iconMaxSize)
|
|
75
73
|
}, contentStyle]
|
|
76
|
-
}, icon) :
|
|
74
|
+
}, icon) : text && /*#__PURE__*/React.createElement(AvatarFallbackText, {
|
|
77
75
|
color: color,
|
|
78
76
|
style: [{
|
|
79
77
|
fontSize: Math.min(avatarWidth, avatarHeight) * tokens.typography.fallbackTextScale
|
|
80
78
|
}, textStyle]
|
|
81
|
-
},
|
|
79
|
+
}, text.trim().slice(0, 2).toUpperCase());
|
|
82
80
|
const content = children ?? (src || source ? /*#__PURE__*/React.createElement(AvatarImage, {
|
|
83
81
|
src: src,
|
|
84
82
|
source: source,
|
|
85
83
|
containerStyle: transparentContainerStyle,
|
|
86
84
|
style: tokens.layout.image,
|
|
87
|
-
fit:
|
|
85
|
+
fit: fitProp ?? 'cover',
|
|
88
86
|
loadingText: null,
|
|
89
87
|
loadingSize: tokens.sizing.loadingSize,
|
|
90
88
|
showError: true,
|
|
@@ -92,13 +90,17 @@ export const Avatar = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
92
90
|
}) : fallbackContent);
|
|
93
91
|
return /*#__PURE__*/React.createElement(Pressable, _extends({
|
|
94
92
|
ref: ref,
|
|
93
|
+
accessibilityRole: "image",
|
|
94
|
+
accessibilityLabel: text ?? (src ? 'avatar' : undefined),
|
|
95
95
|
style: [tokens.layout.container, {
|
|
96
96
|
width: avatarWidth,
|
|
97
97
|
height: avatarHeight,
|
|
98
98
|
borderRadius,
|
|
99
99
|
backgroundColor: backgroundColor ?? tokens.colors.background
|
|
100
100
|
}, style]
|
|
101
|
-
},
|
|
102
|
-
}
|
|
103
|
-
|
|
101
|
+
}, rest), content);
|
|
102
|
+
};
|
|
103
|
+
const AvatarForwardRef = /*#__PURE__*/React.forwardRef(AvatarImpl);
|
|
104
|
+
AvatarForwardRef.displayName = 'Avatar';
|
|
105
|
+
export const Avatar = /*#__PURE__*/React.memo(AvatarForwardRef);
|
|
104
106
|
export default Avatar;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { Avatar as default } from './Avatar';
|
|
2
|
-
export { Avatar } from './Avatar';
|
|
1
|
+
export { Avatar, Avatar as default } from './Avatar';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
2
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
|
-
import { Pressable,
|
|
4
|
-
import { isNumericLike, isRenderable } from '../../utils';
|
|
3
|
+
import { Pressable, View } from 'react-native';
|
|
4
|
+
import { isNumericLike, isRenderable, renderTextOrNode } from '../../utils';
|
|
5
5
|
import { useBadgeTokens } from './tokens';
|
|
6
|
-
|
|
6
|
+
const BadgeImpl = (props, ref) => {
|
|
7
7
|
const {
|
|
8
8
|
children,
|
|
9
9
|
content,
|
|
@@ -12,9 +12,9 @@ export const Badge = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
12
12
|
dot: dotProp,
|
|
13
13
|
max,
|
|
14
14
|
offset,
|
|
15
|
-
showZero,
|
|
15
|
+
showZero: showZeroProp,
|
|
16
16
|
badgeStyle,
|
|
17
|
-
textStyle
|
|
17
|
+
textStyle,
|
|
18
18
|
onPress,
|
|
19
19
|
style,
|
|
20
20
|
tokensOverride,
|
|
@@ -22,51 +22,49 @@ export const Badge = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
22
22
|
} = props;
|
|
23
23
|
const tokens = useBadgeTokens(tokensOverride);
|
|
24
24
|
const dot = dotProp ?? tokens.defaults.dot;
|
|
25
|
-
const
|
|
25
|
+
const showZero = showZeroProp ?? tokens.defaults.showZero;
|
|
26
26
|
const hasChildren = React.Children.count(children) > 0;
|
|
27
27
|
const {
|
|
28
28
|
visible,
|
|
29
29
|
formattedContent
|
|
30
30
|
} = useMemo(() => {
|
|
31
31
|
const numericContent = isNumericLike(content) ? Number(content) : null;
|
|
32
|
-
const shouldHide = numericContent === 0 && !
|
|
32
|
+
const shouldHide = numericContent === 0 && !showZero;
|
|
33
33
|
const isVisible = dot || isRenderable(content) && !shouldHide;
|
|
34
34
|
if (!isVisible || dot) return {
|
|
35
35
|
visible: isVisible,
|
|
36
36
|
formattedContent: null
|
|
37
37
|
};
|
|
38
38
|
const numericMax = isNumericLike(max) ? Number(max) : null;
|
|
39
|
-
const
|
|
39
|
+
const formatted = numericContent !== null && numericMax !== null && numericContent > numericMax ? `${numericMax}+` : content;
|
|
40
40
|
return {
|
|
41
41
|
visible: true,
|
|
42
|
-
formattedContent:
|
|
42
|
+
formattedContent: formatted
|
|
43
43
|
};
|
|
44
|
-
}, [content, dot, max,
|
|
44
|
+
}, [content, dot, max, showZero]);
|
|
45
45
|
const [size, setSize] = useState({
|
|
46
46
|
width: 0,
|
|
47
47
|
height: 0
|
|
48
48
|
});
|
|
49
|
-
const handleLayout = useCallback(
|
|
49
|
+
const handleLayout = useCallback(event => {
|
|
50
50
|
const {
|
|
51
51
|
width,
|
|
52
52
|
height
|
|
53
|
-
} =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}, [size.width, size.height]);
|
|
53
|
+
} = event.nativeEvent.layout;
|
|
54
|
+
setSize(prev => prev.width === width && prev.height === height ? prev : {
|
|
55
|
+
width,
|
|
56
|
+
height
|
|
57
|
+
});
|
|
58
|
+
}, []);
|
|
61
59
|
const transformStyle = useMemo(() => {
|
|
62
60
|
if (!hasChildren) return undefined;
|
|
63
61
|
if (dot) {
|
|
64
|
-
const
|
|
62
|
+
const halfSize = tokens.sizing.dotSize / 2;
|
|
65
63
|
return {
|
|
66
64
|
transform: [{
|
|
67
|
-
translateX:
|
|
65
|
+
translateX: halfSize
|
|
68
66
|
}, {
|
|
69
|
-
translateY: -
|
|
67
|
+
translateY: -halfSize
|
|
70
68
|
}]
|
|
71
69
|
};
|
|
72
70
|
}
|
|
@@ -81,7 +79,7 @@ export const Badge = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
81
79
|
}]
|
|
82
80
|
};
|
|
83
81
|
}, [dot, hasChildren, size.height, size.width, tokens.sizing.dotSize]);
|
|
84
|
-
const
|
|
82
|
+
const badgeBoxStyle = useMemo(() => dot ? {
|
|
85
83
|
width: tokens.sizing.dotSize,
|
|
86
84
|
height: tokens.sizing.dotSize,
|
|
87
85
|
borderRadius: tokens.radii.dot,
|
|
@@ -96,13 +94,13 @@ export const Badge = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
96
94
|
borderColor: tokens.colors.border,
|
|
97
95
|
backgroundColor: color ?? tokens.colors.background
|
|
98
96
|
}, [color, dot, tokens.borders.width, tokens.colors.background, tokens.colors.border, tokens.colors.dot, tokens.radii.badge, tokens.radii.dot, tokens.sizing.dotSize, tokens.sizing.height, tokens.sizing.minWidth, tokens.sizing.paddingHorizontal, tokens.sizing.paddingVertical]);
|
|
99
|
-
const mergedTextStyle =
|
|
97
|
+
const mergedTextStyle = [tokens.layout.text, {
|
|
100
98
|
color: textColor ?? tokens.colors.text,
|
|
101
99
|
fontSize: tokens.typography.fontSize,
|
|
102
100
|
lineHeight: tokens.typography.lineHeight,
|
|
103
101
|
fontFamily: tokens.typography.fontFamily,
|
|
104
102
|
fontWeight: tokens.typography.fontWeight
|
|
105
|
-
},
|
|
103
|
+
}, textStyle];
|
|
106
104
|
const offsetStyle = useMemo(() => {
|
|
107
105
|
if (!offset) return undefined;
|
|
108
106
|
const [x, y] = offset;
|
|
@@ -117,14 +115,14 @@ export const Badge = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
117
115
|
const badgeElement = !visible ? null : /*#__PURE__*/React.createElement(View, {
|
|
118
116
|
pointerEvents: hasChildren ? 'none' : 'auto',
|
|
119
117
|
onLayout: hasChildren && !dot ? handleLayout : undefined,
|
|
120
|
-
style: [hasChildren ? tokens.layout.badgeAbsolute : tokens.layout.badgeStandalone,
|
|
121
|
-
}, !dot && (
|
|
122
|
-
|
|
123
|
-
}, formattedContent)));
|
|
118
|
+
style: [hasChildren ? tokens.layout.badgeAbsolute : tokens.layout.badgeStandalone, badgeBoxStyle, transformStyle, offsetStyle, badgeStyle, !hasChildren ? style : undefined]
|
|
119
|
+
}, !dot && renderTextOrNode(formattedContent, mergedTextStyle));
|
|
120
|
+
const accessibilityLabel = visible ? dot ? 'has new content' : `${formattedContent}` : undefined;
|
|
124
121
|
if (hasChildren) {
|
|
125
122
|
return onPress ? /*#__PURE__*/React.createElement(Pressable, _extends({
|
|
126
123
|
ref: ref,
|
|
127
124
|
onPress: onPress,
|
|
125
|
+
accessibilityLabel: accessibilityLabel,
|
|
128
126
|
style: ({
|
|
129
127
|
pressed
|
|
130
128
|
}) => [tokens.layout.wrapper, style, pressed && {
|
|
@@ -144,9 +142,11 @@ export const Badge = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
144
142
|
}) => [tokens.layout.pressableStandalone, pressed && {
|
|
145
143
|
opacity: tokens.defaults.pressedOpacity
|
|
146
144
|
}]
|
|
147
|
-
}, rest), badgeElement) :
|
|
145
|
+
}, rest), badgeElement) : /*#__PURE__*/React.cloneElement(badgeElement, {
|
|
148
146
|
ref,
|
|
149
147
|
...rest
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const BadgeForwardRef = /*#__PURE__*/React.forwardRef(BadgeImpl);
|
|
151
|
+
BadgeForwardRef.displayName = 'Badge';
|
|
152
|
+
export const Badge = /*#__PURE__*/React.memo(BadgeForwardRef);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { createComponentTokensHook } from '../../design-system';
|
|
2
|
+
const centered = {
|
|
3
|
+
alignItems: 'center',
|
|
4
|
+
justifyContent: 'center'
|
|
5
|
+
};
|
|
2
6
|
const createBadgeTokens = ({
|
|
3
7
|
palette,
|
|
4
8
|
spacing,
|
|
@@ -22,15 +26,13 @@ const createBadgeTokens = ({
|
|
|
22
26
|
position: 'absolute',
|
|
23
27
|
top: 0,
|
|
24
28
|
right: 0,
|
|
25
|
-
|
|
26
|
-
justifyContent: 'center',
|
|
29
|
+
...centered,
|
|
27
30
|
zIndex: 1
|
|
28
31
|
},
|
|
29
32
|
badgeStandalone: {
|
|
30
33
|
alignSelf: 'flex-start',
|
|
31
34
|
flexDirection: 'row',
|
|
32
|
-
|
|
33
|
-
justifyContent: 'center'
|
|
35
|
+
...centered
|
|
34
36
|
},
|
|
35
37
|
pressableStandalone: {
|
|
36
38
|
alignSelf: 'flex-start',
|
|
@@ -40,10 +42,6 @@ const createBadgeTokens = ({
|
|
|
40
42
|
textAlign: 'center',
|
|
41
43
|
includeFontPadding: false,
|
|
42
44
|
textAlignVertical: 'center'
|
|
43
|
-
},
|
|
44
|
-
icon: {
|
|
45
|
-
alignItems: 'center',
|
|
46
|
-
justifyContent: 'center'
|
|
47
45
|
}
|
|
48
46
|
},
|
|
49
47
|
colors: {
|
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useContext } from 'react';
|
|
2
|
+
import React, { useContext, useMemo } from 'react';
|
|
3
3
|
import { ActivityIndicator, Platform, Pressable, Text, View } from 'react-native';
|
|
4
4
|
import { withAlpha } from '../../utils/color';
|
|
5
5
|
import { createPlatformShadow } from '../../utils/createPlatformShadow';
|
|
6
|
+
import { createHairlineView } from '../../utils/hairline';
|
|
6
7
|
import { ensureSpace } from '../../utils/string';
|
|
7
|
-
import { isFiniteNumber, isFunction,
|
|
8
|
+
import { isFiniteNumber, isFunction, isString } from '../../utils';
|
|
8
9
|
import { useAriaPress } from '../../hooks';
|
|
9
10
|
import { ButtonGroupContext } from './ButtonContext';
|
|
10
11
|
import { useButtonTokens } from './tokens';
|
|
11
|
-
const clampShadowLevel = level =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return level;
|
|
12
|
+
const clampShadowLevel = level => level <= 1 ? 1 : level >= 3 ? 3 : level;
|
|
13
|
+
const ROUND_CORNER_STYLE = {
|
|
14
|
+
overflow: 'hidden'
|
|
15
15
|
};
|
|
16
|
-
const
|
|
17
|
-
if (isNumber(loadingSize)) {
|
|
18
|
-
return loadingSize;
|
|
19
|
-
}
|
|
20
|
-
const base = Math.max(iconSize, 16);
|
|
21
|
-
if (loadingSize === 'large') {
|
|
22
|
-
return base * 1.25;
|
|
23
|
-
}
|
|
24
|
-
return base;
|
|
25
|
-
};
|
|
26
|
-
export const Button = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
16
|
+
const ButtonImpl = (props, forwardedRef) => {
|
|
27
17
|
const group = useContext(ButtonGroupContext);
|
|
28
18
|
const {
|
|
29
19
|
text,
|
|
@@ -33,7 +23,7 @@ export const Button = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
|
33
23
|
type: typeProp,
|
|
34
24
|
size: sizeProp,
|
|
35
25
|
color,
|
|
36
|
-
textColor,
|
|
26
|
+
textColor: textColorProp,
|
|
37
27
|
plain: plainProp,
|
|
38
28
|
block: blockProp,
|
|
39
29
|
round: roundProp,
|
|
@@ -54,116 +44,36 @@ export const Button = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
|
54
44
|
style,
|
|
55
45
|
...pressableProps
|
|
56
46
|
} = props;
|
|
57
|
-
const
|
|
58
|
-
const type = typeProp ?? group?.type ??
|
|
59
|
-
const size = sizeProp ?? group?.size ??
|
|
60
|
-
const plain = plainProp ?? group?.plain ??
|
|
61
|
-
const block = blockProp ?? group?.block ??
|
|
62
|
-
const round = roundProp ?? group?.round ??
|
|
63
|
-
const square = squareProp ?? group?.square ??
|
|
64
|
-
const hairline = hairlineProp ?? group?.hairline ??
|
|
65
|
-
const iconPosition = iconPositionProp ?? group?.iconPosition ??
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const allowFontScaling = allowFontScalingProp ?? buttonTokens.defaults.allowFontScaling;
|
|
72
|
-
const isPlain = plain;
|
|
73
|
-
const tone = buttonTokens.colors.tones[type] ?? buttonTokens.colors.tones.default;
|
|
74
|
-
const sizeTokens = buttonTokens.sizing.sizes[size];
|
|
75
|
-
const normalizedColor = color;
|
|
76
|
-
let backgroundColor = normalizedColor ?? tone.background;
|
|
77
|
-
let borderColor = normalizedColor ?? tone.border;
|
|
78
|
-
let resolvedTextColor = textColor;
|
|
79
|
-
if (!resolvedTextColor) {
|
|
80
|
-
resolvedTextColor = normalizedColor ? '#ffffff' : tone.text;
|
|
81
|
-
}
|
|
82
|
-
if (isPlain) {
|
|
83
|
-
backgroundColor = buttonTokens.colors.backgroundPlain;
|
|
84
|
-
borderColor = normalizedColor ?? tone.border;
|
|
85
|
-
const fallbackTextColor = type === 'default' && !normalizedColor ? tone.text : normalizedColor ?? tone.border;
|
|
86
|
-
resolvedTextColor = textColor ?? fallbackTextColor;
|
|
87
|
-
}
|
|
88
|
-
const shouldRenderBorder = isPlain || type === 'default';
|
|
89
|
-
const resolvedBorderWidth = shouldRenderBorder ? hairline ? buttonTokens.borders.hairlineWidth : buttonTokens.borders.width : 0;
|
|
90
|
-
const borderRadius = square ? 0 : round ? sizeTokens.height / 2 : sizeTokens.radius;
|
|
47
|
+
const tokens = useButtonTokens(tokensOverride);
|
|
48
|
+
const type = typeProp ?? group?.type ?? tokens.defaults.type;
|
|
49
|
+
const size = sizeProp ?? group?.size ?? tokens.defaults.size;
|
|
50
|
+
const plain = plainProp ?? group?.plain ?? tokens.defaults.plain;
|
|
51
|
+
const block = blockProp ?? group?.block ?? tokens.defaults.block;
|
|
52
|
+
const round = roundProp ?? group?.round ?? tokens.defaults.round;
|
|
53
|
+
const square = squareProp ?? group?.square ?? tokens.defaults.square;
|
|
54
|
+
const hairline = hairlineProp ?? group?.hairline ?? tokens.defaults.hairline;
|
|
55
|
+
const iconPosition = iconPositionProp ?? group?.iconPosition ?? tokens.defaults.iconPosition;
|
|
56
|
+
const disabled = disabledProp ?? group?.disabled ?? tokens.defaults.disabled;
|
|
57
|
+
const loading = loadingProp ?? tokens.defaults.loading;
|
|
58
|
+
const loadingSize = loadingSizeProp ?? tokens.defaults.loadingSize;
|
|
59
|
+
const allowFontScaling = allowFontScalingProp ?? tokens.defaults.allowFontScaling;
|
|
60
|
+
const shadowValue = shadowProp ?? group?.shadow;
|
|
91
61
|
const isDisabled = disabled || loading;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
const iconWrapperStyle = iconPosition === 'left' ? {
|
|
108
|
-
marginRight: buttonTokens.spacing.iconGap
|
|
109
|
-
} : {
|
|
110
|
-
marginLeft: buttonTokens.spacing.iconGap
|
|
111
|
-
};
|
|
112
|
-
const loadingIconWrapperStyle = {
|
|
113
|
-
marginRight: buttonTokens.spacing.iconGap
|
|
114
|
-
};
|
|
115
|
-
const renderIcon = () => {
|
|
116
|
-
if (!icon) return null;
|
|
117
|
-
try {
|
|
118
|
-
const iconElement = isFunction(icon) ? icon(resolvedTextColor, sizeTokens.iconSize) : icon;
|
|
119
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
120
|
-
style: [buttonTokens.layout.iconWrapper, iconWrapperStyle]
|
|
121
|
-
}, iconElement);
|
|
122
|
-
} catch (error) {
|
|
123
|
-
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
124
|
-
console.warn('[Button] Failed to render icon:', error);
|
|
125
|
-
}
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
const renderLoading = () => {
|
|
130
|
-
const spinnerSize = resolveSpinnerSize(loadingSize, sizeTokens.iconSize);
|
|
131
|
-
const indicatorSize = isNumber(loadingSize) ? spinnerSize : loadingSize;
|
|
132
|
-
const defaultIndicator = /*#__PURE__*/React.createElement(ActivityIndicator, {
|
|
133
|
-
size: indicatorSize,
|
|
134
|
-
color: resolvedTextColor
|
|
135
|
-
});
|
|
136
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
137
|
-
style: [buttonTokens.layout.iconWrapper, loadingIconWrapperStyle]
|
|
138
|
-
}, loadingIndicator ?? defaultIndicator);
|
|
139
|
-
};
|
|
140
|
-
const label = loading && loadingText !== undefined ? loadingText : text !== undefined ? text : children;
|
|
141
|
-
const sharedLabelTextStyle = {
|
|
142
|
-
fontFamily: buttonTokens.typography.fontFamily,
|
|
143
|
-
fontWeight: buttonTokens.typography.fontWeight,
|
|
144
|
-
fontSize: sizeTokens.fontSize,
|
|
145
|
-
lineHeight: sizeTokens.fontSize * buttonTokens.typography.lineHeightMultiplier,
|
|
146
|
-
color: resolvedTextColor
|
|
147
|
-
};
|
|
148
|
-
const renderText = () => {
|
|
149
|
-
if (label === undefined || label === null) {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
const sharedTextStyle = sharedLabelTextStyle;
|
|
153
|
-
if (isText(label)) {
|
|
154
|
-
const content = isString(label) ? ensureSpace(label, true) : String(label);
|
|
155
|
-
return /*#__PURE__*/React.createElement(Text, {
|
|
156
|
-
style: [buttonTokens.layout.text, sharedTextStyle, textStyle],
|
|
157
|
-
numberOfLines: 1,
|
|
158
|
-
allowFontScaling: allowFontScaling,
|
|
159
|
-
maxFontSizeMultiplier: maxFontSizeMultiplier
|
|
160
|
-
}, content);
|
|
161
|
-
}
|
|
162
|
-
return label;
|
|
163
|
-
};
|
|
164
|
-
const content = /*#__PURE__*/React.createElement(View, {
|
|
165
|
-
style: [buttonTokens.layout.content, contentStyle]
|
|
166
|
-
}, loading ? /*#__PURE__*/React.createElement(React.Fragment, null, renderLoading(), renderText()) : /*#__PURE__*/React.createElement(React.Fragment, null, icon && iconPosition === 'left' && renderIcon(), renderText(), icon && iconPosition === 'right' && renderIcon()));
|
|
62
|
+
const tone = tokens.colors.tones[type] ?? tokens.colors.tones.default;
|
|
63
|
+
const sizeTokens = tokens.sizing.sizes[size];
|
|
64
|
+
const [backgroundColor, borderColor, textColor] = useMemo(() => {
|
|
65
|
+
if (plain) return [tokens.colors.backgroundPlain, color ?? tone.border, textColorProp ?? (type === 'default' && !color ? tone.text : color ?? tone.border)];
|
|
66
|
+
return [color ?? tone.background, color ?? tone.border, textColorProp ?? (color ? '#ffffff' : tone.text)];
|
|
67
|
+
}, [color, textColorProp, plain, type, tone, tokens.colors.backgroundPlain]);
|
|
68
|
+
const hasBorder = plain || type === 'default';
|
|
69
|
+
const useHairlineOverlay = hasBorder && hairline;
|
|
70
|
+
const borderWidth = hasBorder && !hairline ? tokens.borders.width : 0;
|
|
71
|
+
const borderRadius = square ? 0 : round ? sizeTokens.height / 2 : sizeTokens.radius;
|
|
72
|
+
const shadowStyle = useMemo(() => {
|
|
73
|
+
if (plain) return undefined;
|
|
74
|
+
const level = isFiniteNumber(shadowValue) ? clampShadowLevel(shadowValue) : shadowValue === true ? 2 : undefined;
|
|
75
|
+
return level ? createPlatformShadow(tokens.shadows[level]) : undefined;
|
|
76
|
+
}, [shadowValue, plain, tokens.shadows]);
|
|
167
77
|
const {
|
|
168
78
|
onPress,
|
|
169
79
|
onPressIn,
|
|
@@ -175,7 +85,6 @@ export const Button = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
|
175
85
|
android_ripple: androidRippleProp,
|
|
176
86
|
...viewProps
|
|
177
87
|
} = pressableProps;
|
|
178
|
-
const resolvedAccessibilityLabel = accessibilityLabel ?? (isText(label) ? String(label) : undefined);
|
|
179
88
|
const {
|
|
180
89
|
interactionProps,
|
|
181
90
|
states
|
|
@@ -185,41 +94,96 @@ export const Button = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
|
185
94
|
onPressStart: onPressIn || undefined,
|
|
186
95
|
onPressEnd: onPressOut || undefined
|
|
187
96
|
});
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
97
|
+
const opacity = disabled ? tokens.states.disabledOpacity : loading ? tokens.states.loadingOpacity : states.pressed ? tokens.states.pressedOpacity : 1;
|
|
98
|
+
const computedTextStyle = useMemo(() => ({
|
|
99
|
+
fontFamily: tokens.typography.fontFamily,
|
|
100
|
+
fontWeight: tokens.typography.fontWeight,
|
|
101
|
+
fontSize: sizeTokens.fontSize,
|
|
102
|
+
lineHeight: sizeTokens.fontSize * tokens.typography.lineHeightMultiplier,
|
|
103
|
+
color: textColor
|
|
104
|
+
}), [tokens.typography, sizeTokens.fontSize, textColor]);
|
|
105
|
+
const iconGap = tokens.spacing.iconGap;
|
|
106
|
+
const renderIcon = () => {
|
|
107
|
+
if (!icon) return null;
|
|
108
|
+
try {
|
|
109
|
+
const element = isFunction(icon) ? icon(textColor, sizeTokens.iconSize) : icon;
|
|
110
|
+
const margin = iconPosition === 'left' ? {
|
|
111
|
+
marginRight: iconGap
|
|
112
|
+
} : {
|
|
113
|
+
marginLeft: iconGap
|
|
114
|
+
};
|
|
115
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
116
|
+
style: [tokens.layout.iconWrapper, margin]
|
|
117
|
+
}, element);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (__DEV__) console.warn('[Button] Failed to render icon:', err);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
197
122
|
};
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
123
|
+
const renderLoading = () => /*#__PURE__*/React.createElement(View, {
|
|
124
|
+
style: [tokens.layout.iconWrapper, {
|
|
125
|
+
marginRight: iconGap
|
|
126
|
+
}]
|
|
127
|
+
}, loadingIndicator ?? /*#__PURE__*/React.createElement(ActivityIndicator, {
|
|
128
|
+
size: loadingSize,
|
|
129
|
+
color: textColor
|
|
130
|
+
}));
|
|
131
|
+
const label = loading && loadingText !== undefined ? loadingText : text !== undefined ? text : children;
|
|
132
|
+
const renderLabel = () => {
|
|
133
|
+
if (label == null) return null;
|
|
134
|
+
if (typeof label === 'string' || typeof label === 'number') {
|
|
135
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
136
|
+
style: [tokens.layout.text, computedTextStyle, textStyle],
|
|
137
|
+
numberOfLines: 1,
|
|
138
|
+
allowFontScaling: allowFontScaling,
|
|
139
|
+
maxFontSizeMultiplier: maxFontSizeMultiplier
|
|
140
|
+
}, isString(label) ? ensureSpace(label, true) : String(label));
|
|
141
|
+
}
|
|
142
|
+
return label;
|
|
143
|
+
};
|
|
144
|
+
const resolvedAccessibilityLabel = accessibilityLabel ?? (typeof label === 'string' || typeof label === 'number' ? String(label) : undefined);
|
|
145
|
+
const mergedAccessibilityState = useMemo(() => ({
|
|
203
146
|
...accessibilityState,
|
|
204
147
|
disabled: isDisabled,
|
|
205
148
|
busy: loading
|
|
206
|
-
};
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
149
|
+
}), [accessibilityState, isDisabled, loading]);
|
|
150
|
+
const resolvedAndroidRipple = useMemo(() => {
|
|
151
|
+
if (Platform.OS !== 'android') return androidRippleProp;
|
|
152
|
+
if (androidRippleProp) return androidRippleProp;
|
|
153
|
+
const rippleColor = rippleColorProp ?? (plain ? textColor : type === 'default' && !color ? withAlpha(textColor, 0.15) : tokens.colors.ripple);
|
|
154
|
+
return {
|
|
155
|
+
color: rippleColor,
|
|
156
|
+
borderless: false
|
|
157
|
+
};
|
|
158
|
+
}, [androidRippleProp, rippleColorProp, plain, textColor, type, color, tokens.colors.ripple]);
|
|
212
159
|
return /*#__PURE__*/React.createElement(Pressable, _extends({
|
|
213
160
|
ref: forwardedRef,
|
|
214
161
|
disabled: isDisabled,
|
|
215
|
-
style:
|
|
162
|
+
style: [tokens.layout.base, {
|
|
163
|
+
minHeight: sizeTokens.height,
|
|
164
|
+
paddingHorizontal: sizeTokens.paddingHorizontal,
|
|
165
|
+
borderRadius: borderRadius,
|
|
166
|
+
backgroundColor: backgroundColor,
|
|
167
|
+
borderColor: useHairlineOverlay ? 'transparent' : borderColor,
|
|
168
|
+
borderWidth: borderWidth,
|
|
169
|
+
opacity: opacity
|
|
170
|
+
}, Platform.OS === 'android' && borderRadius > 0 && !shadowStyle ? ROUND_CORNER_STYLE : null, block ? tokens.layout.block : null, shadowStyle, style],
|
|
216
171
|
android_ripple: resolvedAndroidRipple
|
|
217
172
|
}, interactionProps, {
|
|
218
173
|
accessibilityState: mergedAccessibilityState,
|
|
219
174
|
accessibilityRole: accessibilityRole ?? 'button',
|
|
220
175
|
accessibilityLabel: resolvedAccessibilityLabel,
|
|
221
176
|
accessibilityHint: accessibilityHint
|
|
222
|
-
}, viewProps),
|
|
223
|
-
|
|
224
|
-
|
|
177
|
+
}, viewProps), /*#__PURE__*/React.createElement(View, {
|
|
178
|
+
style: [tokens.layout.content, contentStyle]
|
|
179
|
+
}, loading ? /*#__PURE__*/React.createElement(React.Fragment, null, renderLoading(), renderLabel()) : /*#__PURE__*/React.createElement(React.Fragment, null, icon && iconPosition === 'left' && renderIcon(), renderLabel(), icon && iconPosition === 'right' && renderIcon())), useHairlineOverlay && /*#__PURE__*/React.createElement(View, {
|
|
180
|
+
style: createHairlineView({
|
|
181
|
+
position: 'all',
|
|
182
|
+
color: borderColor,
|
|
183
|
+
borderRadius
|
|
184
|
+
})
|
|
185
|
+
}));
|
|
186
|
+
};
|
|
187
|
+
const ButtonForwardRef = /*#__PURE__*/React.forwardRef(ButtonImpl);
|
|
188
|
+
export const Button = /*#__PURE__*/React.memo(ButtonForwardRef);
|
|
225
189
|
export default Button;
|