react-native-terra-ui 0.1.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 +70 -0
- package/lib/module/components/avatar/Avatar.js +121 -0
- package/lib/module/components/avatar/Avatar.js.map +1 -0
- package/lib/module/components/avatar/index.js +4 -0
- package/lib/module/components/avatar/index.js.map +1 -0
- package/lib/module/components/avatar/types.js +4 -0
- package/lib/module/components/avatar/types.js.map +1 -0
- package/lib/module/components/box/Box.js +49 -0
- package/lib/module/components/box/Box.js.map +1 -0
- package/lib/module/components/box/index.js +4 -0
- package/lib/module/components/box/index.js.map +1 -0
- package/lib/module/components/box/utils.js +95 -0
- package/lib/module/components/box/utils.js.map +1 -0
- package/lib/module/components/button/Button.js +281 -0
- package/lib/module/components/button/Button.js.map +1 -0
- package/lib/module/components/button/index.js +4 -0
- package/lib/module/components/button/index.js.map +1 -0
- package/lib/module/components/header/Header.js +25 -0
- package/lib/module/components/header/Header.js.map +1 -0
- package/lib/module/components/header/header-buttons.js +65 -0
- package/lib/module/components/header/header-buttons.js.map +1 -0
- package/lib/module/components/header/index.js +7 -0
- package/lib/module/components/header/index.js.map +1 -0
- package/lib/module/components/header/variants/LargeTitleHeader/index.js +335 -0
- package/lib/module/components/header/variants/LargeTitleHeader/index.js.map +1 -0
- package/lib/module/components/header/variants/TitleHeader/index.js +184 -0
- package/lib/module/components/header/variants/TitleHeader/index.js.map +1 -0
- package/lib/module/components/icon/Icon.js +53 -0
- package/lib/module/components/icon/Icon.js.map +1 -0
- package/lib/module/components/icon/index.js +4 -0
- package/lib/module/components/icon/index.js.map +1 -0
- package/lib/module/components/icon/utils.js +188 -0
- package/lib/module/components/icon/utils.js.map +1 -0
- package/lib/module/components/index.js +16 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/components/page-indicator/PageIndicator.js +49 -0
- package/lib/module/components/page-indicator/PageIndicator.js.map +1 -0
- package/lib/module/components/page-indicator/PageIndicatorRoot.js +24 -0
- package/lib/module/components/page-indicator/PageIndicatorRoot.js.map +1 -0
- package/lib/module/components/page-indicator/hooks/use-page-indicator-colors.js +24 -0
- package/lib/module/components/page-indicator/hooks/use-page-indicator-colors.js.map +1 -0
- package/lib/module/components/page-indicator/hooks/use-page-indicator-core.js +20 -0
- package/lib/module/components/page-indicator/hooks/use-page-indicator-core.js.map +1 -0
- package/lib/module/components/page-indicator/hooks/use-page-indicator-progress.js +68 -0
- package/lib/module/components/page-indicator/hooks/use-page-indicator-progress.js.map +1 -0
- package/lib/module/components/page-indicator/index.js +5 -0
- package/lib/module/components/page-indicator/index.js.map +1 -0
- package/lib/module/components/page-indicator/utils.js +127 -0
- package/lib/module/components/page-indicator/utils.js.map +1 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/InactiveDot.js +50 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/InactiveDot.js.map +1 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/LoadingOrbit.js +165 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/LoadingOrbit.js.map +1 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/TravelingPill.js +60 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/TravelingPill.js.map +1 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/index.js +87 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/index.js.map +1 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/utils.js +28 -0
- package/lib/module/components/page-indicator/variants/DotIndicator/utils.js.map +1 -0
- package/lib/module/components/page-indicator/variants/PillIndicator/PillIndicatorDot.js +53 -0
- package/lib/module/components/page-indicator/variants/PillIndicator/PillIndicatorDot.js.map +1 -0
- package/lib/module/components/page-indicator/variants/PillIndicator/index.js +76 -0
- package/lib/module/components/page-indicator/variants/PillIndicator/index.js.map +1 -0
- package/lib/module/components/page-indicator/variants/PillIndicator/utils.js +47 -0
- package/lib/module/components/page-indicator/variants/PillIndicator/utils.js.map +1 -0
- package/lib/module/components/portal/PortalContext.js +20 -0
- package/lib/module/components/portal/PortalContext.js.map +1 -0
- package/lib/module/components/portal/PortalHost.js +23 -0
- package/lib/module/components/portal/PortalHost.js.map +1 -0
- package/lib/module/components/portal/PortalProvider.js +40 -0
- package/lib/module/components/portal/PortalProvider.js.map +1 -0
- package/lib/module/components/portal/index.js +6 -0
- package/lib/module/components/portal/index.js.map +1 -0
- package/lib/module/components/screen/Screen.js +100 -0
- package/lib/module/components/screen/Screen.js.map +1 -0
- package/lib/module/components/screen/ScreenContext.js +66 -0
- package/lib/module/components/screen/ScreenContext.js.map +1 -0
- package/lib/module/components/screen/ScreenFlatList.js +75 -0
- package/lib/module/components/screen/ScreenFlatList.js.map +1 -0
- package/lib/module/components/screen/ScreenScrollView.js +82 -0
- package/lib/module/components/screen/ScreenScrollView.js.map +1 -0
- package/lib/module/components/screen/index.js +7 -0
- package/lib/module/components/screen/index.js.map +1 -0
- package/lib/module/components/screen/utils.js +13 -0
- package/lib/module/components/screen/utils.js.map +1 -0
- package/lib/module/components/slot/Slot.js +38 -0
- package/lib/module/components/slot/Slot.js.map +1 -0
- package/lib/module/components/slot/index.js +10 -0
- package/lib/module/components/slot/index.js.map +1 -0
- package/lib/module/components/slot/utils.js +55 -0
- package/lib/module/components/slot/utils.js.map +1 -0
- package/lib/module/components/spinner/Spinner.js +132 -0
- package/lib/module/components/spinner/Spinner.js.map +1 -0
- package/lib/module/components/spinner/index.js +4 -0
- package/lib/module/components/spinner/index.js.map +1 -0
- package/lib/module/components/surface/Surface.js +74 -0
- package/lib/module/components/surface/Surface.js.map +1 -0
- package/lib/module/components/surface/index.js +4 -0
- package/lib/module/components/surface/index.js.map +1 -0
- package/lib/module/components/text/Text.js +67 -0
- package/lib/module/components/text/Text.js.map +1 -0
- package/lib/module/components/text/index.js +4 -0
- package/lib/module/components/text/index.js.map +1 -0
- package/lib/module/components/toast/Toast.js +350 -0
- package/lib/module/components/toast/Toast.js.map +1 -0
- package/lib/module/components/toast/ToastProvider.js +272 -0
- package/lib/module/components/toast/ToastProvider.js.map +1 -0
- package/lib/module/components/toast/index.js +5 -0
- package/lib/module/components/toast/index.js.map +1 -0
- package/lib/module/components/toast/parts/ToastAnimatedItem.js +168 -0
- package/lib/module/components/toast/parts/ToastAnimatedItem.js.map +1 -0
- package/lib/module/components/toast/types.js +4 -0
- package/lib/module/components/toast/types.js.map +1 -0
- package/lib/module/components/toast/utils/controller.js +19 -0
- package/lib/module/components/toast/utils/controller.js.map +1 -0
- package/lib/module/context/ThemeProvider.js +66 -0
- package/lib/module/context/ThemeProvider.js.map +1 -0
- package/lib/module/context/index.js +4 -0
- package/lib/module/context/index.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/theme/configure.js +152 -0
- package/lib/module/theme/configure.js.map +1 -0
- package/lib/module/theme/index.js +22 -0
- package/lib/module/theme/index.js.map +1 -0
- package/lib/module/theme/runtime.js +25 -0
- package/lib/module/theme/runtime.js.map +1 -0
- package/lib/module/theme/theme.js +121 -0
- package/lib/module/theme/theme.js.map +1 -0
- package/lib/module/theme/tokens/dark.js +109 -0
- package/lib/module/theme/tokens/dark.js.map +1 -0
- package/lib/module/theme/tokens/light.js +115 -0
- package/lib/module/theme/tokens/light.js.map +1 -0
- package/lib/module/theme/tokens/primitives.js +228 -0
- package/lib/module/theme/tokens/primitives.js.map +1 -0
- package/lib/module/theme/types.js +4 -0
- package/lib/module/theme/types.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/accent-utils.js +52 -0
- package/lib/module/utils/accent-utils.js.map +1 -0
- package/lib/module/utils/color-utils.js +53 -0
- package/lib/module/utils/color-utils.js.map +1 -0
- package/lib/module/utils/deep-merge.js +28 -0
- package/lib/module/utils/deep-merge.js.map +1 -0
- package/lib/module/utils/resolve-theme-color.js +20 -0
- package/lib/module/utils/resolve-theme-color.js.map +1 -0
- package/lib/module/utils/typography.js +13 -0
- package/lib/module/utils/typography.js.map +1 -0
- package/lib/module/utils/unflatten.js +35 -0
- package/lib/module/utils/unflatten.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/components/avatar/Avatar.d.ts +3 -0
- package/lib/typescript/src/components/avatar/Avatar.d.ts.map +1 -0
- package/lib/typescript/src/components/avatar/index.d.ts +3 -0
- package/lib/typescript/src/components/avatar/index.d.ts.map +1 -0
- package/lib/typescript/src/components/avatar/types.d.ts +30 -0
- package/lib/typescript/src/components/avatar/types.d.ts.map +1 -0
- package/lib/typescript/src/components/box/Box.d.ts +12 -0
- package/lib/typescript/src/components/box/Box.d.ts.map +1 -0
- package/lib/typescript/src/components/box/index.d.ts +4 -0
- package/lib/typescript/src/components/box/index.d.ts.map +1 -0
- package/lib/typescript/src/components/box/utils.d.ts +39 -0
- package/lib/typescript/src/components/box/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/button/Button.d.ts +46 -0
- package/lib/typescript/src/components/button/Button.d.ts.map +1 -0
- package/lib/typescript/src/components/button/index.d.ts +3 -0
- package/lib/typescript/src/components/button/index.d.ts.map +1 -0
- package/lib/typescript/src/components/header/Header.d.ts +22 -0
- package/lib/typescript/src/components/header/Header.d.ts.map +1 -0
- package/lib/typescript/src/components/header/header-buttons.d.ts +16 -0
- package/lib/typescript/src/components/header/header-buttons.d.ts.map +1 -0
- package/lib/typescript/src/components/header/index.d.ts +7 -0
- package/lib/typescript/src/components/header/index.d.ts.map +1 -0
- package/lib/typescript/src/components/header/variants/LargeTitleHeader/index.d.ts +25 -0
- package/lib/typescript/src/components/header/variants/LargeTitleHeader/index.d.ts.map +1 -0
- package/lib/typescript/src/components/header/variants/TitleHeader/index.d.ts +28 -0
- package/lib/typescript/src/components/header/variants/TitleHeader/index.d.ts.map +1 -0
- package/lib/typescript/src/components/icon/Icon.d.ts +22 -0
- package/lib/typescript/src/components/icon/Icon.d.ts.map +1 -0
- package/lib/typescript/src/components/icon/index.d.ts +3 -0
- package/lib/typescript/src/components/icon/index.d.ts.map +1 -0
- package/lib/typescript/src/components/icon/utils.d.ts +4 -0
- package/lib/typescript/src/components/icon/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +14 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/PageIndicator.d.ts +48 -0
- package/lib/typescript/src/components/page-indicator/PageIndicator.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/PageIndicatorRoot.d.ts +13 -0
- package/lib/typescript/src/components/page-indicator/PageIndicatorRoot.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/hooks/use-page-indicator-colors.d.ts +14 -0
- package/lib/typescript/src/components/page-indicator/hooks/use-page-indicator-colors.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/hooks/use-page-indicator-core.d.ts +11 -0
- package/lib/typescript/src/components/page-indicator/hooks/use-page-indicator-core.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/hooks/use-page-indicator-progress.d.ts +19 -0
- package/lib/typescript/src/components/page-indicator/hooks/use-page-indicator-progress.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/index.d.ts +4 -0
- package/lib/typescript/src/components/page-indicator/index.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/utils.d.ts +36 -0
- package/lib/typescript/src/components/page-indicator/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/InactiveDot.d.ts +14 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/InactiveDot.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/LoadingOrbit.d.ts +11 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/LoadingOrbit.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/TravelingPill.d.ts +15 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/TravelingPill.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/index.d.ts +32 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/index.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/utils.d.ts +14 -0
- package/lib/typescript/src/components/page-indicator/variants/DotIndicator/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/variants/PillIndicator/PillIndicatorDot.d.ts +16 -0
- package/lib/typescript/src/components/page-indicator/variants/PillIndicator/PillIndicatorDot.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/variants/PillIndicator/index.d.ts +28 -0
- package/lib/typescript/src/components/page-indicator/variants/PillIndicator/index.d.ts.map +1 -0
- package/lib/typescript/src/components/page-indicator/variants/PillIndicator/utils.d.ts +21 -0
- package/lib/typescript/src/components/page-indicator/variants/PillIndicator/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/portal/PortalContext.d.ts +19 -0
- package/lib/typescript/src/components/portal/PortalContext.d.ts.map +1 -0
- package/lib/typescript/src/components/portal/PortalHost.d.ts +7 -0
- package/lib/typescript/src/components/portal/PortalHost.d.ts.map +1 -0
- package/lib/typescript/src/components/portal/PortalProvider.d.ts +11 -0
- package/lib/typescript/src/components/portal/PortalProvider.d.ts.map +1 -0
- package/lib/typescript/src/components/portal/index.d.ts +6 -0
- package/lib/typescript/src/components/portal/index.d.ts.map +1 -0
- package/lib/typescript/src/components/screen/Screen.d.ts +53 -0
- package/lib/typescript/src/components/screen/Screen.d.ts.map +1 -0
- package/lib/typescript/src/components/screen/ScreenContext.d.ts +64 -0
- package/lib/typescript/src/components/screen/ScreenContext.d.ts.map +1 -0
- package/lib/typescript/src/components/screen/ScreenFlatList.d.ts +26 -0
- package/lib/typescript/src/components/screen/ScreenFlatList.d.ts.map +1 -0
- package/lib/typescript/src/components/screen/ScreenScrollView.d.ts +36 -0
- package/lib/typescript/src/components/screen/ScreenScrollView.d.ts.map +1 -0
- package/lib/typescript/src/components/screen/index.d.ts +9 -0
- package/lib/typescript/src/components/screen/index.d.ts.map +1 -0
- package/lib/typescript/src/components/screen/utils.d.ts +10 -0
- package/lib/typescript/src/components/screen/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/slot/Slot.d.ts +17 -0
- package/lib/typescript/src/components/slot/Slot.d.ts.map +1 -0
- package/lib/typescript/src/components/slot/index.d.ts +8 -0
- package/lib/typescript/src/components/slot/index.d.ts.map +1 -0
- package/lib/typescript/src/components/slot/utils.d.ts +17 -0
- package/lib/typescript/src/components/slot/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/spinner/Spinner.d.ts +18 -0
- package/lib/typescript/src/components/spinner/Spinner.d.ts.map +1 -0
- package/lib/typescript/src/components/spinner/index.d.ts +3 -0
- package/lib/typescript/src/components/spinner/index.d.ts.map +1 -0
- package/lib/typescript/src/components/surface/Surface.d.ts +31 -0
- package/lib/typescript/src/components/surface/Surface.d.ts.map +1 -0
- package/lib/typescript/src/components/surface/index.d.ts +3 -0
- package/lib/typescript/src/components/surface/index.d.ts.map +1 -0
- package/lib/typescript/src/components/text/Text.d.ts +23 -0
- package/lib/typescript/src/components/text/Text.d.ts.map +1 -0
- package/lib/typescript/src/components/text/index.d.ts +3 -0
- package/lib/typescript/src/components/text/index.d.ts.map +1 -0
- package/lib/typescript/src/components/toast/Toast.d.ts +71 -0
- package/lib/typescript/src/components/toast/Toast.d.ts.map +1 -0
- package/lib/typescript/src/components/toast/ToastProvider.d.ts +4 -0
- package/lib/typescript/src/components/toast/ToastProvider.d.ts.map +1 -0
- package/lib/typescript/src/components/toast/index.d.ts +5 -0
- package/lib/typescript/src/components/toast/index.d.ts.map +1 -0
- package/lib/typescript/src/components/toast/parts/ToastAnimatedItem.d.ts +18 -0
- package/lib/typescript/src/components/toast/parts/ToastAnimatedItem.d.ts.map +1 -0
- package/lib/typescript/src/components/toast/types.d.ts +62 -0
- package/lib/typescript/src/components/toast/types.d.ts.map +1 -0
- package/lib/typescript/src/components/toast/utils/controller.d.ts +5 -0
- package/lib/typescript/src/components/toast/utils/controller.d.ts.map +1 -0
- package/lib/typescript/src/context/ThemeProvider.d.ts +29 -0
- package/lib/typescript/src/context/ThemeProvider.d.ts.map +1 -0
- package/lib/typescript/src/context/index.d.ts +3 -0
- package/lib/typescript/src/context/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/theme/configure.d.ts +47 -0
- package/lib/typescript/src/theme/configure.d.ts.map +1 -0
- package/lib/typescript/src/theme/index.d.ts +11 -0
- package/lib/typescript/src/theme/index.d.ts.map +1 -0
- package/lib/typescript/src/theme/runtime.d.ts +7 -0
- package/lib/typescript/src/theme/runtime.d.ts.map +1 -0
- package/lib/typescript/src/theme/theme.d.ts +22 -0
- package/lib/typescript/src/theme/theme.d.ts.map +1 -0
- package/lib/typescript/src/theme/tokens/dark.d.ts +100 -0
- package/lib/typescript/src/theme/tokens/dark.d.ts.map +1 -0
- package/lib/typescript/src/theme/tokens/light.d.ts +106 -0
- package/lib/typescript/src/theme/tokens/light.d.ts.map +1 -0
- package/lib/typescript/src/theme/tokens/primitives.d.ts +212 -0
- package/lib/typescript/src/theme/tokens/primitives.d.ts.map +1 -0
- package/lib/typescript/src/theme/types.d.ts +273 -0
- package/lib/typescript/src/theme/types.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +4 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/accent-utils.d.ts +4 -0
- package/lib/typescript/src/utils/accent-utils.d.ts.map +1 -0
- package/lib/typescript/src/utils/color-utils.d.ts +11 -0
- package/lib/typescript/src/utils/color-utils.d.ts.map +1 -0
- package/lib/typescript/src/utils/deep-merge.d.ts +11 -0
- package/lib/typescript/src/utils/deep-merge.d.ts.map +1 -0
- package/lib/typescript/src/utils/resolve-theme-color.d.ts +12 -0
- package/lib/typescript/src/utils/resolve-theme-color.d.ts.map +1 -0
- package/lib/typescript/src/utils/typography.d.ts +6 -0
- package/lib/typescript/src/utils/typography.d.ts.map +1 -0
- package/lib/typescript/src/utils/unflatten.d.ts +12 -0
- package/lib/typescript/src/utils/unflatten.d.ts.map +1 -0
- package/package.json +137 -0
- package/src/components/avatar/Avatar.tsx +146 -0
- package/src/components/avatar/index.ts +8 -0
- package/src/components/avatar/types.ts +35 -0
- package/src/components/box/Box.tsx +59 -0
- package/src/components/box/index.ts +8 -0
- package/src/components/box/utils.ts +181 -0
- package/src/components/button/Button.tsx +313 -0
- package/src/components/button/index.ts +8 -0
- package/src/components/header/Header.ts +22 -0
- package/src/components/header/header-buttons.tsx +103 -0
- package/src/components/header/index.ts +11 -0
- package/src/components/header/variants/LargeTitleHeader/index.tsx +390 -0
- package/src/components/header/variants/TitleHeader/index.tsx +194 -0
- package/src/components/icon/Icon.tsx +74 -0
- package/src/components/icon/index.ts +2 -0
- package/src/components/icon/utils.tsx +147 -0
- package/src/components/index.ts +13 -0
- package/src/components/page-indicator/PageIndicator.tsx +100 -0
- package/src/components/page-indicator/PageIndicatorRoot.tsx +41 -0
- package/src/components/page-indicator/hooks/use-page-indicator-colors.ts +65 -0
- package/src/components/page-indicator/hooks/use-page-indicator-core.ts +34 -0
- package/src/components/page-indicator/hooks/use-page-indicator-progress.ts +122 -0
- package/src/components/page-indicator/index.ts +13 -0
- package/src/components/page-indicator/utils.ts +208 -0
- package/src/components/page-indicator/variants/DotIndicator/InactiveDot.tsx +70 -0
- package/src/components/page-indicator/variants/DotIndicator/LoadingOrbit.tsx +201 -0
- package/src/components/page-indicator/variants/DotIndicator/TravelingPill.tsx +80 -0
- package/src/components/page-indicator/variants/DotIndicator/index.tsx +145 -0
- package/src/components/page-indicator/variants/DotIndicator/utils.ts +28 -0
- package/src/components/page-indicator/variants/PillIndicator/PillIndicatorDot.tsx +107 -0
- package/src/components/page-indicator/variants/PillIndicator/index.tsx +149 -0
- package/src/components/page-indicator/variants/PillIndicator/utils.ts +63 -0
- package/src/components/portal/PortalContext.tsx +27 -0
- package/src/components/portal/PortalHost.tsx +20 -0
- package/src/components/portal/PortalProvider.tsx +44 -0
- package/src/components/portal/index.ts +5 -0
- package/src/components/screen/Screen.tsx +163 -0
- package/src/components/screen/ScreenContext.tsx +144 -0
- package/src/components/screen/ScreenFlatList.tsx +121 -0
- package/src/components/screen/ScreenScrollView.tsx +130 -0
- package/src/components/screen/index.ts +8 -0
- package/src/components/screen/utils.ts +17 -0
- package/src/components/slot/Slot.tsx +56 -0
- package/src/components/slot/index.ts +8 -0
- package/src/components/slot/utils.ts +61 -0
- package/src/components/spinner/Spinner.tsx +153 -0
- package/src/components/spinner/index.ts +2 -0
- package/src/components/surface/Surface.tsx +100 -0
- package/src/components/surface/index.ts +2 -0
- package/src/components/text/Text.tsx +115 -0
- package/src/components/text/index.ts +2 -0
- package/src/components/toast/Toast.tsx +477 -0
- package/src/components/toast/ToastProvider.tsx +403 -0
- package/src/components/toast/index.ts +26 -0
- package/src/components/toast/parts/ToastAnimatedItem.tsx +184 -0
- package/src/components/toast/types.ts +75 -0
- package/src/components/toast/utils/controller.ts +23 -0
- package/src/context/ThemeProvider.tsx +97 -0
- package/src/context/index.ts +2 -0
- package/src/index.tsx +6 -0
- package/src/theme/configure.ts +215 -0
- package/src/theme/index.ts +72 -0
- package/src/theme/runtime.ts +27 -0
- package/src/theme/theme.ts +152 -0
- package/src/theme/tokens/dark.ts +117 -0
- package/src/theme/tokens/light.ts +123 -0
- package/src/theme/tokens/primitives.ts +232 -0
- package/src/theme/types.ts +384 -0
- package/src/types.ts +1 -0
- package/src/utils/accent-utils.ts +58 -0
- package/src/utils/color-utils.ts +51 -0
- package/src/utils/deep-merge.ts +36 -0
- package/src/utils/resolve-theme-color.ts +27 -0
- package/src/utils/typography.ts +15 -0
- package/src/utils/unflatten.ts +36 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useReducer,
|
|
8
|
+
useRef,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { Keyboard, Platform } from 'react-native';
|
|
11
|
+
|
|
12
|
+
import Animated, {
|
|
13
|
+
useAnimatedStyle,
|
|
14
|
+
useSharedValue,
|
|
15
|
+
withTiming,
|
|
16
|
+
} from 'react-native-reanimated';
|
|
17
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
18
|
+
import { ToastAnimatedItem } from './parts/ToastAnimatedItem';
|
|
19
|
+
import { DefaultToast } from './Toast';
|
|
20
|
+
import type {
|
|
21
|
+
ToastComponentProps,
|
|
22
|
+
ToastDuration,
|
|
23
|
+
ToastId,
|
|
24
|
+
ToastItem,
|
|
25
|
+
ToastManager,
|
|
26
|
+
ToastPlacement,
|
|
27
|
+
ToastProviderProps,
|
|
28
|
+
ToastShowConfig,
|
|
29
|
+
ToastShowOptions,
|
|
30
|
+
ToastShowOptionsWithComponent,
|
|
31
|
+
} from './types';
|
|
32
|
+
import { setToastManager } from './utils/controller';
|
|
33
|
+
|
|
34
|
+
type ToastAction =
|
|
35
|
+
| { type: 'show'; item: ToastItem }
|
|
36
|
+
| { type: 'hide'; ids: ToastId[] }
|
|
37
|
+
| { type: 'hideAll' }
|
|
38
|
+
| { type: 'hidePlacement'; placement: ToastPlacement };
|
|
39
|
+
|
|
40
|
+
const DEFAULT_DURATION = 4000;
|
|
41
|
+
const DEFAULT_MAX_VISIBLE_TOASTS = 3;
|
|
42
|
+
|
|
43
|
+
const ToastManagerContext = createContext<ToastManager | null>(null);
|
|
44
|
+
|
|
45
|
+
function toastReducer(state: ToastItem[], action: ToastAction): ToastItem[] {
|
|
46
|
+
switch (action.type) {
|
|
47
|
+
case 'show':
|
|
48
|
+
return [
|
|
49
|
+
...state.filter((toast) => toast.id !== action.item.id),
|
|
50
|
+
action.item,
|
|
51
|
+
];
|
|
52
|
+
case 'hide':
|
|
53
|
+
return state.filter((toast) => !action.ids.some((id) => id === toast.id));
|
|
54
|
+
case 'hideAll':
|
|
55
|
+
return [];
|
|
56
|
+
case 'hidePlacement':
|
|
57
|
+
return state.filter((toast) => toast.placement !== action.placement);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createDefaultToastComponent(
|
|
62
|
+
config: ToastShowConfig,
|
|
63
|
+
manager: ToastManager
|
|
64
|
+
) {
|
|
65
|
+
return ({ id, hide }: ToastComponentProps) => (
|
|
66
|
+
<DefaultToast
|
|
67
|
+
id={id}
|
|
68
|
+
hide={(toastId) => hide(String(toastId))}
|
|
69
|
+
variant={config.variant}
|
|
70
|
+
label={config.label}
|
|
71
|
+
description={config.description}
|
|
72
|
+
icon={config.icon}
|
|
73
|
+
actionLabel={config.actionLabel}
|
|
74
|
+
showCloseButton={config.showCloseButton}
|
|
75
|
+
onActionPress={() => config.onActionPress?.(manager)}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function isCustomToast(
|
|
81
|
+
options: ToastShowOptions
|
|
82
|
+
): options is ToastShowOptionsWithComponent {
|
|
83
|
+
return (
|
|
84
|
+
typeof options === 'object' && options !== null && 'component' in options
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function normalizePlacement(
|
|
89
|
+
placement: ToastPlacement | undefined,
|
|
90
|
+
fallback: ToastPlacement
|
|
91
|
+
): ToastPlacement {
|
|
92
|
+
return placement ?? fallback;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function normalizeDuration(
|
|
96
|
+
duration: ToastDuration | undefined,
|
|
97
|
+
fallback: number
|
|
98
|
+
): ToastDuration {
|
|
99
|
+
return duration ?? fallback;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function toastId(counter: number): ToastId {
|
|
103
|
+
return `toast-${Date.now()}-${counter}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function ToastProvider({
|
|
107
|
+
children,
|
|
108
|
+
defaultPlacement = 'top',
|
|
109
|
+
defaultDuration = DEFAULT_DURATION,
|
|
110
|
+
maxVisibleToasts = DEFAULT_MAX_VISIBLE_TOASTS,
|
|
111
|
+
offset,
|
|
112
|
+
}: ToastProviderProps) {
|
|
113
|
+
const [toasts, dispatch] = useReducer(toastReducer, []);
|
|
114
|
+
const toastsRef = useRef<ToastItem[]>([]);
|
|
115
|
+
const counterRef = useRef(0);
|
|
116
|
+
const timeoutsRef = useRef<Map<ToastId, ReturnType<typeof setTimeout>>>(
|
|
117
|
+
new Map()
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
toastsRef.current = toasts;
|
|
122
|
+
}, [toasts]);
|
|
123
|
+
|
|
124
|
+
const clearToastTimeout = useCallback((id: ToastId) => {
|
|
125
|
+
const timeout = timeoutsRef.current.get(id);
|
|
126
|
+
if (timeout) clearTimeout(timeout);
|
|
127
|
+
timeoutsRef.current.delete(id);
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
const hide = useCallback<ToastManager['hide']>(
|
|
131
|
+
(id) => {
|
|
132
|
+
if (id === 'all') {
|
|
133
|
+
for (const toast of toastsRef.current) {
|
|
134
|
+
clearToastTimeout(toast.id);
|
|
135
|
+
toast.onHide?.();
|
|
136
|
+
}
|
|
137
|
+
toastsRef.current = [];
|
|
138
|
+
dispatch({ type: 'hideAll' });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const lastToastId = toastsRef.current[toastsRef.current.length - 1]?.id;
|
|
142
|
+
const ids =
|
|
143
|
+
id === undefined
|
|
144
|
+
? lastToastId
|
|
145
|
+
? [lastToastId]
|
|
146
|
+
: []
|
|
147
|
+
: Array.isArray(id)
|
|
148
|
+
? id
|
|
149
|
+
: [id];
|
|
150
|
+
|
|
151
|
+
if (ids.length === 0) return;
|
|
152
|
+
|
|
153
|
+
for (const toastId of ids) {
|
|
154
|
+
clearToastTimeout(toastId);
|
|
155
|
+
toastsRef.current.find((toast) => toast.id === toastId)?.onHide?.();
|
|
156
|
+
}
|
|
157
|
+
toastsRef.current = toastsRef.current.filter(
|
|
158
|
+
(toast) => !ids.some((toastId) => toastId === toast.id)
|
|
159
|
+
);
|
|
160
|
+
dispatch({ type: 'hide', ids });
|
|
161
|
+
},
|
|
162
|
+
[clearToastTimeout]
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const managerRef = useRef<ToastManager>({
|
|
166
|
+
show: () => '',
|
|
167
|
+
hide,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const show = useCallback<ToastManager['show']>(
|
|
171
|
+
(options) => {
|
|
172
|
+
const nextId =
|
|
173
|
+
typeof options === 'object' && options !== null && 'id' in options
|
|
174
|
+
? (options.id ?? toastId(counterRef.current++))
|
|
175
|
+
: toastId(counterRef.current++);
|
|
176
|
+
|
|
177
|
+
const item =
|
|
178
|
+
typeof options === 'string'
|
|
179
|
+
? {
|
|
180
|
+
id: nextId,
|
|
181
|
+
component: createDefaultToastComponent(
|
|
182
|
+
{ label: options },
|
|
183
|
+
managerRef.current
|
|
184
|
+
),
|
|
185
|
+
duration: defaultDuration,
|
|
186
|
+
placement: defaultPlacement,
|
|
187
|
+
}
|
|
188
|
+
: isCustomToast(options)
|
|
189
|
+
? {
|
|
190
|
+
id: nextId,
|
|
191
|
+
component: options.component,
|
|
192
|
+
duration: normalizeDuration(options.duration, defaultDuration),
|
|
193
|
+
placement: normalizePlacement(
|
|
194
|
+
options.placement,
|
|
195
|
+
defaultPlacement
|
|
196
|
+
),
|
|
197
|
+
onHide: options.onHide,
|
|
198
|
+
}
|
|
199
|
+
: {
|
|
200
|
+
id: nextId,
|
|
201
|
+
component: createDefaultToastComponent(
|
|
202
|
+
options,
|
|
203
|
+
managerRef.current
|
|
204
|
+
),
|
|
205
|
+
duration: normalizeDuration(options.duration, defaultDuration),
|
|
206
|
+
placement: normalizePlacement(
|
|
207
|
+
options.placement,
|
|
208
|
+
defaultPlacement
|
|
209
|
+
),
|
|
210
|
+
onHide: options.onHide,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const oppositePlacement = item.placement === 'top' ? 'bottom' : 'top';
|
|
214
|
+
const oppositeToasts = toastsRef.current.filter(
|
|
215
|
+
(t) => t.placement === oppositePlacement
|
|
216
|
+
);
|
|
217
|
+
if (oppositeToasts.length > 0) {
|
|
218
|
+
for (const t of oppositeToasts) {
|
|
219
|
+
clearToastTimeout(t.id);
|
|
220
|
+
t.onHide?.();
|
|
221
|
+
}
|
|
222
|
+
toastsRef.current = toastsRef.current.filter(
|
|
223
|
+
(t) => t.placement !== oppositePlacement
|
|
224
|
+
);
|
|
225
|
+
dispatch({ type: 'hidePlacement', placement: oppositePlacement });
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
clearToastTimeout(item.id);
|
|
229
|
+
toastsRef.current = [
|
|
230
|
+
...toastsRef.current.filter((toast) => toast.id !== item.id),
|
|
231
|
+
item,
|
|
232
|
+
];
|
|
233
|
+
dispatch({ type: 'show', item });
|
|
234
|
+
if (
|
|
235
|
+
typeof options === 'object' &&
|
|
236
|
+
options !== null &&
|
|
237
|
+
'onShow' in options
|
|
238
|
+
) {
|
|
239
|
+
options.onShow?.();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (
|
|
243
|
+
item.duration !== 'persistent' &&
|
|
244
|
+
Number.isFinite(item.duration) &&
|
|
245
|
+
item.duration > 0
|
|
246
|
+
) {
|
|
247
|
+
const timeout = setTimeout(() => hide(item.id), item.duration);
|
|
248
|
+
timeoutsRef.current.set(item.id, timeout);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return item.id;
|
|
252
|
+
},
|
|
253
|
+
[clearToastTimeout, defaultDuration, defaultPlacement, hide]
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const manager = useMemo<ToastManager>(() => ({ show, hide }), [show, hide]);
|
|
257
|
+
managerRef.current = manager;
|
|
258
|
+
|
|
259
|
+
useEffect(() => {
|
|
260
|
+
setToastManager(manager);
|
|
261
|
+
return () => {
|
|
262
|
+
setToastManager(null);
|
|
263
|
+
for (const timeout of timeoutsRef.current.values()) {
|
|
264
|
+
clearTimeout(timeout);
|
|
265
|
+
}
|
|
266
|
+
timeoutsRef.current.clear();
|
|
267
|
+
};
|
|
268
|
+
}, [manager]);
|
|
269
|
+
|
|
270
|
+
const topToasts = toasts.filter((toast) => toast.placement === 'top');
|
|
271
|
+
const bottomToasts = toasts.filter((toast) => toast.placement === 'bottom');
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<ToastManagerContext.Provider value={manager}>
|
|
275
|
+
{children}
|
|
276
|
+
<ToastViewport
|
|
277
|
+
placement="top"
|
|
278
|
+
toasts={topToasts}
|
|
279
|
+
manager={manager}
|
|
280
|
+
maxVisibleToasts={maxVisibleToasts}
|
|
281
|
+
offset={offset}
|
|
282
|
+
/>
|
|
283
|
+
<ToastViewport
|
|
284
|
+
placement="bottom"
|
|
285
|
+
toasts={bottomToasts}
|
|
286
|
+
manager={manager}
|
|
287
|
+
maxVisibleToasts={maxVisibleToasts}
|
|
288
|
+
offset={offset}
|
|
289
|
+
/>
|
|
290
|
+
</ToastManagerContext.Provider>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
interface ToastViewportProps {
|
|
295
|
+
placement: ToastPlacement;
|
|
296
|
+
toasts: ToastItem[];
|
|
297
|
+
manager: ToastManager;
|
|
298
|
+
maxVisibleToasts: number;
|
|
299
|
+
offset?: ToastProviderProps['offset'];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function ToastViewport({
|
|
303
|
+
placement,
|
|
304
|
+
toasts,
|
|
305
|
+
manager,
|
|
306
|
+
maxVisibleToasts,
|
|
307
|
+
offset,
|
|
308
|
+
}: ToastViewportProps) {
|
|
309
|
+
const safeAreaInsets = useSafeAreaInsets();
|
|
310
|
+
const heights = useSharedValue<Record<ToastId, number>>({});
|
|
311
|
+
const total = useSharedValue(0);
|
|
312
|
+
const keyboardHeight = useSharedValue(0);
|
|
313
|
+
|
|
314
|
+
const baseBottom =
|
|
315
|
+
offset?.bottom ?? safeAreaInsets.bottom + (Platform.OS === 'ios' ? 6 : 12);
|
|
316
|
+
const baseTop =
|
|
317
|
+
offset?.top ?? safeAreaInsets.top + (Platform.OS === 'ios' ? 0 : 12);
|
|
318
|
+
|
|
319
|
+
useEffect(() => {
|
|
320
|
+
if (placement !== 'bottom') return;
|
|
321
|
+
const showEvent =
|
|
322
|
+
Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow';
|
|
323
|
+
const hideEvent =
|
|
324
|
+
Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide';
|
|
325
|
+
const showSub = Keyboard.addListener(showEvent, (e) => {
|
|
326
|
+
keyboardHeight.value = withTiming(e.endCoordinates.height);
|
|
327
|
+
});
|
|
328
|
+
const hideSub = Keyboard.addListener(hideEvent, () => {
|
|
329
|
+
keyboardHeight.value = withTiming(0);
|
|
330
|
+
});
|
|
331
|
+
return () => {
|
|
332
|
+
showSub.remove();
|
|
333
|
+
hideSub.remove();
|
|
334
|
+
};
|
|
335
|
+
}, [keyboardHeight, placement]);
|
|
336
|
+
|
|
337
|
+
const gap = Platform.OS === 'ios' ? 6 : 12;
|
|
338
|
+
|
|
339
|
+
const keyboardStyle = useAnimatedStyle(() => {
|
|
340
|
+
if (placement === 'top') return { top: baseTop };
|
|
341
|
+
if (keyboardHeight.value > 0) {
|
|
342
|
+
return { bottom: keyboardHeight.value + gap };
|
|
343
|
+
}
|
|
344
|
+
return { bottom: baseBottom };
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
useEffect(() => {
|
|
348
|
+
total.value = toasts.length;
|
|
349
|
+
const activeIds = new Set(toasts.map((toast) => toast.id));
|
|
350
|
+
const nextHeights: Record<ToastId, number> = {};
|
|
351
|
+
for (const [id, height] of Object.entries(heights.value)) {
|
|
352
|
+
if (activeIds.has(id)) {
|
|
353
|
+
nextHeights[id] = height;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
heights.value = nextHeights;
|
|
357
|
+
}, [heights, toasts, total]);
|
|
358
|
+
|
|
359
|
+
if (toasts.length === 0) return null;
|
|
360
|
+
|
|
361
|
+
return (
|
|
362
|
+
<Animated.View
|
|
363
|
+
pointerEvents="box-none"
|
|
364
|
+
style={[
|
|
365
|
+
{
|
|
366
|
+
position: 'absolute',
|
|
367
|
+
zIndex: 9999,
|
|
368
|
+
elevation: 9999,
|
|
369
|
+
left: offset?.left ?? safeAreaInsets.left + 12,
|
|
370
|
+
right: offset?.right ?? safeAreaInsets.right + 12,
|
|
371
|
+
},
|
|
372
|
+
keyboardStyle,
|
|
373
|
+
]}
|
|
374
|
+
>
|
|
375
|
+
{toasts.map((toast, index) => (
|
|
376
|
+
<ToastAnimatedItem
|
|
377
|
+
key={toast.id}
|
|
378
|
+
heights={heights}
|
|
379
|
+
id={toast.id}
|
|
380
|
+
index={index}
|
|
381
|
+
maxVisibleToasts={maxVisibleToasts}
|
|
382
|
+
placement={placement}
|
|
383
|
+
total={total}
|
|
384
|
+
>
|
|
385
|
+
{toast.component({
|
|
386
|
+
id: toast.id,
|
|
387
|
+
index,
|
|
388
|
+
hide: manager.hide,
|
|
389
|
+
show: manager.show,
|
|
390
|
+
})}
|
|
391
|
+
</ToastAnimatedItem>
|
|
392
|
+
))}
|
|
393
|
+
</Animated.View>
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export function useToast(): ToastManager {
|
|
398
|
+
const manager = useContext(ToastManagerContext);
|
|
399
|
+
if (!manager) {
|
|
400
|
+
throw new Error('useToast must be used within <TerraUIProvider>.');
|
|
401
|
+
}
|
|
402
|
+
return manager;
|
|
403
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
DefaultToastProps,
|
|
3
|
+
ToastActionProps,
|
|
4
|
+
ToastCloseProps,
|
|
5
|
+
ToastControls,
|
|
6
|
+
ToastDescriptionProps,
|
|
7
|
+
ToastIconProps,
|
|
8
|
+
ToastProps,
|
|
9
|
+
ToastTitleProps,
|
|
10
|
+
ToastVariant,
|
|
11
|
+
} from './Toast';
|
|
12
|
+
export { DefaultToast, Toast } from './Toast';
|
|
13
|
+
export { ToastProvider, useToast } from './ToastProvider';
|
|
14
|
+
export type {
|
|
15
|
+
ToastActionHelpers,
|
|
16
|
+
ToastComponentProps,
|
|
17
|
+
ToastDuration,
|
|
18
|
+
ToastId,
|
|
19
|
+
ToastItem,
|
|
20
|
+
ToastManager,
|
|
21
|
+
ToastPlacement,
|
|
22
|
+
ToastProviderProps,
|
|
23
|
+
ToastShowConfig,
|
|
24
|
+
ToastShowOptions,
|
|
25
|
+
ToastShowOptionsWithComponent,
|
|
26
|
+
} from './types';
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import Animated, {
|
|
5
|
+
Easing,
|
|
6
|
+
Extrapolation,
|
|
7
|
+
interpolate,
|
|
8
|
+
Keyframe,
|
|
9
|
+
type SharedValue,
|
|
10
|
+
useAnimatedStyle,
|
|
11
|
+
withSpring,
|
|
12
|
+
withTiming,
|
|
13
|
+
} from 'react-native-reanimated';
|
|
14
|
+
|
|
15
|
+
import type { ToastId, ToastPlacement } from '../types';
|
|
16
|
+
|
|
17
|
+
export interface ToastAnimatedItemProps {
|
|
18
|
+
children: ReactElement;
|
|
19
|
+
heights: SharedValue<Record<ToastId, number>>;
|
|
20
|
+
id: ToastId;
|
|
21
|
+
index: number;
|
|
22
|
+
maxVisibleToasts: number;
|
|
23
|
+
placement: ToastPlacement;
|
|
24
|
+
total: SharedValue<number>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const enteringTop = new Keyframe({
|
|
28
|
+
0: {
|
|
29
|
+
opacity: 1,
|
|
30
|
+
transform: [{ translateY: -100 }],
|
|
31
|
+
},
|
|
32
|
+
100: {
|
|
33
|
+
opacity: 1,
|
|
34
|
+
transform: [{ translateY: 0 }],
|
|
35
|
+
easing: Easing.out(Easing.cubic),
|
|
36
|
+
},
|
|
37
|
+
}).duration(260);
|
|
38
|
+
|
|
39
|
+
export const exitingTop = new Keyframe({
|
|
40
|
+
0: {
|
|
41
|
+
opacity: 1,
|
|
42
|
+
transform: [{ translateY: 0 }, { scale: 1 }],
|
|
43
|
+
},
|
|
44
|
+
100: {
|
|
45
|
+
opacity: 0.5,
|
|
46
|
+
transform: [{ translateY: -100 }, { scale: 0.97 }],
|
|
47
|
+
easing: Easing.bezier(0.4, 0, 1, 1),
|
|
48
|
+
},
|
|
49
|
+
}).duration(150);
|
|
50
|
+
|
|
51
|
+
export const enteringBottom = new Keyframe({
|
|
52
|
+
0: {
|
|
53
|
+
opacity: 1,
|
|
54
|
+
transform: [{ translateY: 100 }],
|
|
55
|
+
},
|
|
56
|
+
100: {
|
|
57
|
+
opacity: 1,
|
|
58
|
+
transform: [{ translateY: 0 }],
|
|
59
|
+
easing: Easing.out(Easing.cubic),
|
|
60
|
+
},
|
|
61
|
+
}).duration(260);
|
|
62
|
+
|
|
63
|
+
export const exitingBottom = new Keyframe({
|
|
64
|
+
0: {
|
|
65
|
+
opacity: 1,
|
|
66
|
+
transform: [{ translateY: 0 }, { scale: 1 }],
|
|
67
|
+
},
|
|
68
|
+
100: {
|
|
69
|
+
opacity: 0.5,
|
|
70
|
+
transform: [{ translateY: 100 }, { scale: 0.97 }],
|
|
71
|
+
easing: Easing.bezier(0.4, 0, 1, 1),
|
|
72
|
+
},
|
|
73
|
+
}).duration(150);
|
|
74
|
+
|
|
75
|
+
const opacityValue = [1, 0] as [number, number];
|
|
76
|
+
const opacityTimingConfig = { duration: 300 };
|
|
77
|
+
const translateYValue = [0, 10] as [number, number];
|
|
78
|
+
const translateYTimingConfig = { duration: 300 };
|
|
79
|
+
const scaleValue = [1, 0.97] as [number, number];
|
|
80
|
+
const scaleTimingConfig = { duration: 300 };
|
|
81
|
+
|
|
82
|
+
export function ToastAnimatedItem({
|
|
83
|
+
children,
|
|
84
|
+
heights,
|
|
85
|
+
id,
|
|
86
|
+
index,
|
|
87
|
+
maxVisibleToasts,
|
|
88
|
+
placement,
|
|
89
|
+
total,
|
|
90
|
+
}: ToastAnimatedItemProps) {
|
|
91
|
+
const containerStyle = useAnimatedStyle(() => {
|
|
92
|
+
const heightEntries = Object.entries(heights.value);
|
|
93
|
+
const lastToastId = heightEntries[heightEntries.length - 1]?.[0];
|
|
94
|
+
const lastToastHeight = lastToastId
|
|
95
|
+
? heights.value[lastToastId]
|
|
96
|
+
: undefined;
|
|
97
|
+
const totalValue = total.value;
|
|
98
|
+
const sign = placement === 'top' ? 1 : -1;
|
|
99
|
+
|
|
100
|
+
const inputRange = [totalValue - 1, totalValue - 2];
|
|
101
|
+
const opacityInputRange = [
|
|
102
|
+
totalValue - maxVisibleToasts,
|
|
103
|
+
totalValue - maxVisibleToasts - 1,
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
const opacity = interpolate(index, opacityInputRange, opacityValue);
|
|
107
|
+
const translateY = interpolate(
|
|
108
|
+
index,
|
|
109
|
+
inputRange,
|
|
110
|
+
[translateYValue[0], translateYValue[1] * sign],
|
|
111
|
+
Extrapolation.CLAMP
|
|
112
|
+
);
|
|
113
|
+
const scale = interpolate(index, inputRange, scaleValue, {
|
|
114
|
+
extrapolateLeft: Extrapolation.CLAMP,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
height: lastToastHeight
|
|
119
|
+
? withSpring(lastToastHeight, {
|
|
120
|
+
damping: 100,
|
|
121
|
+
stiffness: 1200,
|
|
122
|
+
mass: 3,
|
|
123
|
+
})
|
|
124
|
+
: undefined,
|
|
125
|
+
pointerEvents: opacity === 0 ? 'none' : 'auto',
|
|
126
|
+
opacity: withTiming(opacity, opacityTimingConfig),
|
|
127
|
+
transform: [
|
|
128
|
+
{ translateY: withTiming(translateY, translateYTimingConfig) },
|
|
129
|
+
{ scale: withTiming(scale, scaleTimingConfig) },
|
|
130
|
+
],
|
|
131
|
+
zIndex: 1000 + index,
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<Animated.View
|
|
137
|
+
entering={placement === 'top' ? enteringTop : enteringBottom}
|
|
138
|
+
exiting={placement === 'top' ? exitingTop : exitingBottom}
|
|
139
|
+
pointerEvents="box-none"
|
|
140
|
+
style={[
|
|
141
|
+
styles.position,
|
|
142
|
+
placement === 'top' ? styles.top : styles.bottom,
|
|
143
|
+
]}
|
|
144
|
+
>
|
|
145
|
+
<Animated.View style={containerStyle}>{children}</Animated.View>
|
|
146
|
+
<View
|
|
147
|
+
pointerEvents="none"
|
|
148
|
+
aria-hidden
|
|
149
|
+
importantForAccessibility="no-hide-descendants"
|
|
150
|
+
accessibilityElementsHidden
|
|
151
|
+
style={styles.measurement}
|
|
152
|
+
onLayout={(event) => {
|
|
153
|
+
const measuredHeight = event.nativeEvent.layout.height;
|
|
154
|
+
heights.value = {
|
|
155
|
+
...heights.value,
|
|
156
|
+
[id]: measuredHeight,
|
|
157
|
+
};
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
{process.env.NODE_ENV === 'test' ? null : children}
|
|
161
|
+
</View>
|
|
162
|
+
</Animated.View>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const styles = StyleSheet.create({
|
|
167
|
+
position: {
|
|
168
|
+
position: 'absolute',
|
|
169
|
+
left: 0,
|
|
170
|
+
right: 0,
|
|
171
|
+
},
|
|
172
|
+
top: {
|
|
173
|
+
top: 0,
|
|
174
|
+
},
|
|
175
|
+
bottom: {
|
|
176
|
+
bottom: 0,
|
|
177
|
+
},
|
|
178
|
+
measurement: {
|
|
179
|
+
position: 'absolute',
|
|
180
|
+
left: 0,
|
|
181
|
+
right: 0,
|
|
182
|
+
opacity: 0,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { ToastProps, ToastVariant } from './Toast';
|
|
4
|
+
|
|
5
|
+
export type ToastId = string;
|
|
6
|
+
export type ToastDuration = number | 'persistent';
|
|
7
|
+
export type ToastPlacement = 'top' | 'bottom';
|
|
8
|
+
|
|
9
|
+
export interface ToastActionHelpers {
|
|
10
|
+
show: ToastManager['show'];
|
|
11
|
+
hide: ToastManager['hide'];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ToastShowConfig extends Pick<ToastProps, 'variant'> {
|
|
15
|
+
id?: ToastId;
|
|
16
|
+
label?: ReactNode;
|
|
17
|
+
description?: ReactNode;
|
|
18
|
+
icon?: ReactNode | false;
|
|
19
|
+
actionLabel?: ReactNode;
|
|
20
|
+
onActionPress?: (helpers: ToastActionHelpers) => void;
|
|
21
|
+
duration?: ToastDuration;
|
|
22
|
+
placement?: ToastPlacement;
|
|
23
|
+
showCloseButton?: boolean;
|
|
24
|
+
onShow?: () => void;
|
|
25
|
+
onHide?: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ToastComponentProps {
|
|
29
|
+
id: ToastId;
|
|
30
|
+
index: number;
|
|
31
|
+
hide: ToastManager['hide'];
|
|
32
|
+
show: ToastManager['show'];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ToastShowOptionsWithComponent {
|
|
36
|
+
id?: ToastId;
|
|
37
|
+
component: (props: ToastComponentProps) => ReactElement;
|
|
38
|
+
duration?: ToastDuration;
|
|
39
|
+
placement?: ToastPlacement;
|
|
40
|
+
onShow?: () => void;
|
|
41
|
+
onHide?: () => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type ToastShowOptions =
|
|
45
|
+
| ToastShowConfig
|
|
46
|
+
| ToastShowOptionsWithComponent
|
|
47
|
+
| string;
|
|
48
|
+
|
|
49
|
+
export interface ToastItem {
|
|
50
|
+
id: ToastId;
|
|
51
|
+
component: (props: ToastComponentProps) => ReactElement;
|
|
52
|
+
duration: ToastDuration;
|
|
53
|
+
placement: ToastPlacement;
|
|
54
|
+
onHide?: () => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ToastManager {
|
|
58
|
+
show: (options: ToastShowOptions) => ToastId;
|
|
59
|
+
hide: (id?: ToastId | ToastId[] | 'all') => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ToastProviderProps {
|
|
63
|
+
children?: ReactNode;
|
|
64
|
+
defaultPlacement?: ToastPlacement;
|
|
65
|
+
defaultDuration?: number;
|
|
66
|
+
maxVisibleToasts?: number;
|
|
67
|
+
offset?: {
|
|
68
|
+
top?: number;
|
|
69
|
+
bottom?: number;
|
|
70
|
+
left?: number;
|
|
71
|
+
right?: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type { ToastVariant };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ToastId, ToastManager, ToastShowOptions } from '../types';
|
|
2
|
+
|
|
3
|
+
let activeManager: ToastManager | null = null;
|
|
4
|
+
|
|
5
|
+
export function setToastManager(manager: ToastManager | null): void {
|
|
6
|
+
activeManager = manager;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function showToast(options: ToastShowOptions): ToastId {
|
|
10
|
+
if (!activeManager) {
|
|
11
|
+
if (__DEV__) {
|
|
12
|
+
console.warn(
|
|
13
|
+
'[react-native-terra-ui] Toast.show() called before <TerraUIProvider> mounted.'
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
return activeManager.show(options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function hideToast(id?: ToastId | ToastId[] | 'all'): void {
|
|
22
|
+
activeManager?.hide(id);
|
|
23
|
+
}
|