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,100 @@
|
|
|
1
|
+
import { type ComponentRef, forwardRef } from 'react';
|
|
2
|
+
import type { View, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useUnistyles } from 'react-native-unistyles';
|
|
5
|
+
|
|
6
|
+
import { getDefaultRadius, getSurfaceElevation } from '#theme/configure';
|
|
7
|
+
import type { ColorToken, ElevationKey } from '#theme/types';
|
|
8
|
+
|
|
9
|
+
import { type BorderWidthInput, Box, type BoxProps } from '../box';
|
|
10
|
+
|
|
11
|
+
/** Background level of a {@link Surface}. */
|
|
12
|
+
export type SurfaceVariant = 'base' | 'raised' | 'sunken' | 'transparent';
|
|
13
|
+
|
|
14
|
+
export interface SurfaceProps extends Omit<BoxProps, 'bg'> {
|
|
15
|
+
/** Background surface level. Defaults to `'base'`. */
|
|
16
|
+
variant?: SurfaceVariant;
|
|
17
|
+
/**
|
|
18
|
+
* Drop-shadow depth (platform-aware shadow + Android elevation).
|
|
19
|
+
* Defaults to `'sm'` for `variant="raised"`, otherwise the configured
|
|
20
|
+
* surface elevation (`'none'` if unset). Note: a shadow needs a
|
|
21
|
+
* non-transparent background to render, so `variant="transparent"` shows no
|
|
22
|
+
* shadow.
|
|
23
|
+
*/
|
|
24
|
+
elevation?: ElevationKey;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const VARIANT_BG: Record<SurfaceVariant, ColorToken> = {
|
|
28
|
+
base: 'surface.default',
|
|
29
|
+
raised: 'surface.raised',
|
|
30
|
+
sunken: 'surface.sunken',
|
|
31
|
+
transparent: 'transparent',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Variant-aware hairline borders improve edge definition when fills are close. */
|
|
35
|
+
const VARIANT_BORDER: Record<
|
|
36
|
+
SurfaceVariant,
|
|
37
|
+
{ borderWidth?: BorderWidthInput; borderColor?: ColorToken }
|
|
38
|
+
> = {
|
|
39
|
+
base: {},
|
|
40
|
+
raised: { borderWidth: 'hairline', borderColor: 'border.subtle' },
|
|
41
|
+
sunken: { borderWidth: 'hairline', borderColor: 'border.default' },
|
|
42
|
+
transparent: {},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const resolveElevation = (
|
|
46
|
+
variant: SurfaceVariant,
|
|
47
|
+
elevation?: ElevationKey
|
|
48
|
+
): ElevationKey => {
|
|
49
|
+
if (elevation !== undefined) return elevation;
|
|
50
|
+
if (variant === 'raised') return 'sm';
|
|
51
|
+
return getSurfaceElevation();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Themed container built on {@link Box}. Picks its background from a semantic
|
|
56
|
+
* surface `variant`, its corner radius from the configured `surface`
|
|
57
|
+
* default (overridable via `radius`), and an optional drop shadow via
|
|
58
|
+
* `elevation`. All other Box style-props are accepted.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* <Surface variant="raised" elevation="md" p="4" radius="lg">
|
|
63
|
+
* <Text variant="title-sm">Card title</Text>
|
|
64
|
+
* </Surface>
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export const Surface = forwardRef<ComponentRef<typeof View>, SurfaceProps>(
|
|
68
|
+
function Surface(
|
|
69
|
+
{
|
|
70
|
+
variant = 'base',
|
|
71
|
+
elevation,
|
|
72
|
+
radius,
|
|
73
|
+
borderWidth,
|
|
74
|
+
borderColor,
|
|
75
|
+
style,
|
|
76
|
+
...rest
|
|
77
|
+
},
|
|
78
|
+
ref
|
|
79
|
+
) {
|
|
80
|
+
const { theme } = useUnistyles();
|
|
81
|
+
const resolvedElevation = resolveElevation(variant, elevation);
|
|
82
|
+
const variantBorder = VARIANT_BORDER[variant];
|
|
83
|
+
const shadowStyle =
|
|
84
|
+
variant !== 'transparent' && resolvedElevation !== 'none'
|
|
85
|
+
? (theme.elevation[resolvedElevation] as ViewStyle)
|
|
86
|
+
: undefined;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Box
|
|
90
|
+
ref={ref}
|
|
91
|
+
bg={VARIANT_BG[variant]}
|
|
92
|
+
radius={radius ?? getDefaultRadius('surface')}
|
|
93
|
+
borderWidth={borderWidth ?? variantBorder.borderWidth}
|
|
94
|
+
borderColor={borderColor ?? variantBorder.borderColor}
|
|
95
|
+
style={shadowStyle ? [shadowStyle, style] : style}
|
|
96
|
+
{...rest}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
);
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type ComponentRef, forwardRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Text as RNText,
|
|
4
|
+
type TextProps as RNTextProps,
|
|
5
|
+
type TextStyle,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
|
|
8
|
+
import { useUnistyles } from 'react-native-unistyles';
|
|
9
|
+
import type {
|
|
10
|
+
ColorToken,
|
|
11
|
+
FontWeightToken,
|
|
12
|
+
HeadingTextVariant,
|
|
13
|
+
RoleTextVariant,
|
|
14
|
+
TextVariant,
|
|
15
|
+
} from '#theme/types';
|
|
16
|
+
import type { Mutable } from '#types';
|
|
17
|
+
import { resolveThemeColor } from '#utils/resolve-theme-color';
|
|
18
|
+
import { FONT_WEIGHT_VALUE, SYSTEM_FONT } from '#utils/typography';
|
|
19
|
+
|
|
20
|
+
export type TextAlign = 'left' | 'center' | 'right' | 'justify';
|
|
21
|
+
|
|
22
|
+
const HEADING_VARIANT_ALIAS: Record<HeadingTextVariant, RoleTextVariant> = {
|
|
23
|
+
h1: 'headline-lg',
|
|
24
|
+
h2: 'headline-md',
|
|
25
|
+
h3: 'title-lg',
|
|
26
|
+
h4: 'title-md',
|
|
27
|
+
h5: 'title-sm',
|
|
28
|
+
h6: 'label-lg',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function resolveTextVariant(variant: TextVariant): RoleTextVariant {
|
|
32
|
+
return variant in HEADING_VARIANT_ALIAS
|
|
33
|
+
? HEADING_VARIANT_ALIAS[variant as HeadingTextVariant]
|
|
34
|
+
: (variant as RoleTextVariant);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface TextProps extends RNTextProps {
|
|
38
|
+
/** Typographic role. Defaults to `body-md`. */
|
|
39
|
+
variant?: TextVariant;
|
|
40
|
+
/** Semantic color token (e.g. `content.secondary`, `status.danger.solid`). */
|
|
41
|
+
color?: ColorToken;
|
|
42
|
+
/** Override the variant's default weight. */
|
|
43
|
+
weight?: FontWeightToken;
|
|
44
|
+
align?: TextAlign;
|
|
45
|
+
italic?: boolean;
|
|
46
|
+
underline?: boolean;
|
|
47
|
+
strikeThrough?: boolean;
|
|
48
|
+
/** Truncate to a single line with a trailing ellipsis. */
|
|
49
|
+
isTruncated?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Themed text primitive. Reads its scale from `theme.typography` and resolves
|
|
54
|
+
* fonts by weight, honoring Dynamic Type with a per-variant scaling cap.
|
|
55
|
+
*/
|
|
56
|
+
export const Text = forwardRef<ComponentRef<typeof RNText>, TextProps>(
|
|
57
|
+
function Text(
|
|
58
|
+
{
|
|
59
|
+
variant = 'body-md',
|
|
60
|
+
color,
|
|
61
|
+
weight,
|
|
62
|
+
align,
|
|
63
|
+
italic,
|
|
64
|
+
underline,
|
|
65
|
+
strikeThrough,
|
|
66
|
+
isTruncated,
|
|
67
|
+
style,
|
|
68
|
+
numberOfLines,
|
|
69
|
+
ellipsizeMode,
|
|
70
|
+
maxFontSizeMultiplier,
|
|
71
|
+
...rest
|
|
72
|
+
},
|
|
73
|
+
ref
|
|
74
|
+
) {
|
|
75
|
+
const { theme } = useUnistyles();
|
|
76
|
+
const resolvedVariant = resolveTextVariant(variant);
|
|
77
|
+
const v = theme.typography.variants[resolvedVariant];
|
|
78
|
+
const effectiveWeight: FontWeightToken = weight ?? v.fontWeight;
|
|
79
|
+
const fontFamily = theme.typography.fonts[effectiveWeight];
|
|
80
|
+
const isSystemFont = fontFamily === SYSTEM_FONT;
|
|
81
|
+
|
|
82
|
+
const base: Mutable<TextStyle> = {
|
|
83
|
+
fontSize: v.fontSize,
|
|
84
|
+
lineHeight: v.lineHeight,
|
|
85
|
+
letterSpacing: v.letterSpacing,
|
|
86
|
+
color:
|
|
87
|
+
resolveThemeColor(color, theme) ??
|
|
88
|
+
(theme.color as unknown as Record<string, string | undefined>)[
|
|
89
|
+
'text.default'
|
|
90
|
+
] ??
|
|
91
|
+
'',
|
|
92
|
+
};
|
|
93
|
+
// System font: apply numeric weight. Custom font: family encodes the weight.
|
|
94
|
+
if (isSystemFont) base.fontWeight = FONT_WEIGHT_VALUE[effectiveWeight];
|
|
95
|
+
else base.fontFamily = fontFamily;
|
|
96
|
+
|
|
97
|
+
if (align) base.textAlign = align;
|
|
98
|
+
if (italic) base.fontStyle = 'italic';
|
|
99
|
+
if (underline && strikeThrough)
|
|
100
|
+
base.textDecorationLine = 'underline line-through';
|
|
101
|
+
else if (underline) base.textDecorationLine = 'underline';
|
|
102
|
+
else if (strikeThrough) base.textDecorationLine = 'line-through';
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<RNText
|
|
106
|
+
ref={ref}
|
|
107
|
+
style={[base, style]}
|
|
108
|
+
maxFontSizeMultiplier={maxFontSizeMultiplier ?? v.maxFontSizeMultiplier}
|
|
109
|
+
numberOfLines={isTruncated ? 1 : numberOfLines}
|
|
110
|
+
ellipsizeMode={isTruncated ? 'tail' : ellipsizeMode}
|
|
111
|
+
{...rest}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComponentRef,
|
|
3
|
+
createContext,
|
|
4
|
+
forwardRef,
|
|
5
|
+
type ReactNode,
|
|
6
|
+
useContext,
|
|
7
|
+
useId,
|
|
8
|
+
useMemo,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import type { GestureResponderEvent, PressableProps, View } from 'react-native';
|
|
11
|
+
import { Pressable, StyleSheet } from 'react-native';
|
|
12
|
+
|
|
13
|
+
import { useUnistyles } from 'react-native-unistyles';
|
|
14
|
+
|
|
15
|
+
import type { TerraIconName, TerraTheme } from '#theme/types';
|
|
16
|
+
|
|
17
|
+
import { Box } from '../box';
|
|
18
|
+
import { Button, type ButtonProps } from '../button';
|
|
19
|
+
import { Icon, type IconProps } from '../icon';
|
|
20
|
+
import { Surface, type SurfaceProps } from '../surface';
|
|
21
|
+
import { Text, type TextProps } from '../text';
|
|
22
|
+
import type { ToastId as StackToastId, ToastShowOptions } from './types';
|
|
23
|
+
import { hideToast, showToast } from './utils/controller';
|
|
24
|
+
|
|
25
|
+
export type ToastVariant =
|
|
26
|
+
| 'default'
|
|
27
|
+
| 'accent'
|
|
28
|
+
| 'info'
|
|
29
|
+
| 'success'
|
|
30
|
+
| 'warning'
|
|
31
|
+
| 'danger';
|
|
32
|
+
|
|
33
|
+
type ToastInstanceId = string | number;
|
|
34
|
+
|
|
35
|
+
export interface ToastControls {
|
|
36
|
+
hide?: (id: ToastInstanceId) => void;
|
|
37
|
+
id?: ToastInstanceId;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface ToastContextValue extends ToastControls {
|
|
41
|
+
nativeID: string;
|
|
42
|
+
variant: ToastVariant;
|
|
43
|
+
onClose?: () => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const ToastContext = createContext<ToastContextValue | null>(null);
|
|
47
|
+
|
|
48
|
+
function useToastContext(): ToastContextValue {
|
|
49
|
+
const context = useContext(ToastContext);
|
|
50
|
+
if (!context) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
'Toast compound components must be rendered inside <Toast>.'
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return context;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ToastColors {
|
|
59
|
+
bg: string;
|
|
60
|
+
border: string;
|
|
61
|
+
title: string;
|
|
62
|
+
description: string;
|
|
63
|
+
icon: string;
|
|
64
|
+
actionBg: string;
|
|
65
|
+
actionFg: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getToastColors(variant: ToastVariant, theme: TerraTheme): ToastColors {
|
|
69
|
+
const c = theme.color as unknown as Record<string, string | undefined>;
|
|
70
|
+
const get = (key: string): string => c[key] ?? '';
|
|
71
|
+
const base = {
|
|
72
|
+
bg: get('surface.default'),
|
|
73
|
+
border: get('border.subtle'),
|
|
74
|
+
description: get('text.muted'),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
switch (variant) {
|
|
78
|
+
case 'accent':
|
|
79
|
+
return {
|
|
80
|
+
...base,
|
|
81
|
+
title: get('action.fg.subtle'),
|
|
82
|
+
icon: get('text.accent'),
|
|
83
|
+
actionBg: get('action.bg.primary'),
|
|
84
|
+
actionFg: get('action.fg.primary'),
|
|
85
|
+
};
|
|
86
|
+
case 'info':
|
|
87
|
+
case 'success':
|
|
88
|
+
case 'warning':
|
|
89
|
+
case 'danger':
|
|
90
|
+
return {
|
|
91
|
+
...base,
|
|
92
|
+
title: get(`status.bg.${variant}`),
|
|
93
|
+
icon: get(`status.bg.${variant}`),
|
|
94
|
+
actionBg: get(`status.bg.${variant}`),
|
|
95
|
+
actionFg: get(`status.fg.${variant}`),
|
|
96
|
+
};
|
|
97
|
+
case 'default':
|
|
98
|
+
return {
|
|
99
|
+
...base,
|
|
100
|
+
title: get('text.default'),
|
|
101
|
+
icon: get('text.subtle'),
|
|
102
|
+
actionBg: get('action.bg.neutral.hover'),
|
|
103
|
+
actionFg: get('action.fg.neutral'),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface ToastProps extends Omit<SurfaceProps, 'id' | 'variant'> {
|
|
109
|
+
/** Visual tone for the toast. Defaults to `default`. */
|
|
110
|
+
variant?: ToastVariant;
|
|
111
|
+
/** Optional identifier passed back to `hide` when `Toast.Close` is pressed. */
|
|
112
|
+
id?: ToastInstanceId;
|
|
113
|
+
/** Imperative hide callback used by toast queues/providers. */
|
|
114
|
+
hide?: (id: ToastInstanceId) => void;
|
|
115
|
+
/** Local close callback used by `Toast.Close`. */
|
|
116
|
+
onClose?: () => void;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const ToastRoot = forwardRef<ComponentRef<typeof View>, ToastProps>(
|
|
120
|
+
function Toast(
|
|
121
|
+
{
|
|
122
|
+
variant = 'default',
|
|
123
|
+
id,
|
|
124
|
+
hide,
|
|
125
|
+
onClose,
|
|
126
|
+
children,
|
|
127
|
+
nativeID: nativeIDProp,
|
|
128
|
+
style,
|
|
129
|
+
accessibilityRole = 'alert',
|
|
130
|
+
...rest
|
|
131
|
+
},
|
|
132
|
+
ref
|
|
133
|
+
) {
|
|
134
|
+
const { theme } = useUnistyles();
|
|
135
|
+
const generatedNativeID = useId();
|
|
136
|
+
const nativeID = nativeIDProp ?? String(id ?? generatedNativeID);
|
|
137
|
+
const colors = getToastColors(variant, theme);
|
|
138
|
+
const contextValue = useMemo<ToastContextValue>(
|
|
139
|
+
() => ({ nativeID, variant, id, hide, onClose }),
|
|
140
|
+
[nativeID, variant, id, hide, onClose]
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<ToastContext.Provider value={contextValue}>
|
|
145
|
+
<Surface
|
|
146
|
+
ref={ref}
|
|
147
|
+
variant="raised"
|
|
148
|
+
elevation="md"
|
|
149
|
+
radius="xl"
|
|
150
|
+
p="4"
|
|
151
|
+
row
|
|
152
|
+
align="center"
|
|
153
|
+
gap="3"
|
|
154
|
+
accessibilityRole={accessibilityRole}
|
|
155
|
+
accessibilityLiveRegion="polite"
|
|
156
|
+
borderWidth="hairline"
|
|
157
|
+
nativeID={nativeID}
|
|
158
|
+
style={[
|
|
159
|
+
styles.root,
|
|
160
|
+
{
|
|
161
|
+
backgroundColor: colors.bg,
|
|
162
|
+
borderColor: colors.border,
|
|
163
|
+
},
|
|
164
|
+
style,
|
|
165
|
+
]}
|
|
166
|
+
{...rest}
|
|
167
|
+
>
|
|
168
|
+
{children}
|
|
169
|
+
</Surface>
|
|
170
|
+
</ToastContext.Provider>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
export interface ToastTitleProps extends TextProps {}
|
|
176
|
+
|
|
177
|
+
const ToastTitle = forwardRef<ComponentRef<typeof Text>, ToastTitleProps>(
|
|
178
|
+
function ToastTitle(
|
|
179
|
+
{
|
|
180
|
+
accessibilityRole = 'header',
|
|
181
|
+
color,
|
|
182
|
+
nativeID,
|
|
183
|
+
variant = 'label-lg',
|
|
184
|
+
weight,
|
|
185
|
+
...rest
|
|
186
|
+
},
|
|
187
|
+
ref
|
|
188
|
+
) {
|
|
189
|
+
const { theme } = useUnistyles();
|
|
190
|
+
const { nativeID: rootNativeID, variant: toastVariant } = useToastContext();
|
|
191
|
+
const colors = getToastColors(toastVariant, theme);
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<Text
|
|
195
|
+
ref={ref}
|
|
196
|
+
accessibilityRole={accessibilityRole}
|
|
197
|
+
color={color ?? colors.title}
|
|
198
|
+
nativeID={nativeID ?? `${rootNativeID}_label`}
|
|
199
|
+
variant={variant}
|
|
200
|
+
weight={weight ?? 'semibold'}
|
|
201
|
+
{...rest}
|
|
202
|
+
/>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
export interface ToastDescriptionProps extends TextProps {}
|
|
208
|
+
|
|
209
|
+
const ToastDescription = forwardRef<
|
|
210
|
+
ComponentRef<typeof Text>,
|
|
211
|
+
ToastDescriptionProps
|
|
212
|
+
>(function ToastDescription(
|
|
213
|
+
{ color, nativeID, variant = 'body-sm', ...rest },
|
|
214
|
+
ref
|
|
215
|
+
) {
|
|
216
|
+
const { theme } = useUnistyles();
|
|
217
|
+
const { nativeID: rootNativeID, variant: toastVariant } = useToastContext();
|
|
218
|
+
const colors = getToastColors(toastVariant, theme);
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<Text
|
|
222
|
+
ref={ref}
|
|
223
|
+
color={color ?? colors.description}
|
|
224
|
+
nativeID={nativeID ?? `${rootNativeID}_desc`}
|
|
225
|
+
variant={variant}
|
|
226
|
+
{...rest}
|
|
227
|
+
/>
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
export interface ToastActionProps
|
|
232
|
+
extends Omit<PressableProps, 'children' | 'disabled' | 'style'> {
|
|
233
|
+
children?: ReactNode;
|
|
234
|
+
/** Override the action button colour. Defaults to the parent Toast variant. */
|
|
235
|
+
variant?: ToastVariant;
|
|
236
|
+
fullWidth?: boolean;
|
|
237
|
+
isDisabled?: boolean;
|
|
238
|
+
size?: 'sm' | 'md' | 'lg';
|
|
239
|
+
style?: PressableProps['style'];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function renderActionChildren(children: ReactNode, color: string): ReactNode {
|
|
243
|
+
if (typeof children === 'string' || typeof children === 'number') {
|
|
244
|
+
return (
|
|
245
|
+
<Text variant="label-lg" weight="semibold" style={{ color }}>
|
|
246
|
+
{children}
|
|
247
|
+
</Text>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return children;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const ToastAction = forwardRef<
|
|
254
|
+
ComponentRef<typeof Pressable>,
|
|
255
|
+
ToastActionProps
|
|
256
|
+
>(function ToastAction(
|
|
257
|
+
{
|
|
258
|
+
children,
|
|
259
|
+
variant,
|
|
260
|
+
fullWidth = false,
|
|
261
|
+
isDisabled = false,
|
|
262
|
+
size = 'sm',
|
|
263
|
+
style,
|
|
264
|
+
onPress,
|
|
265
|
+
...rest
|
|
266
|
+
},
|
|
267
|
+
ref
|
|
268
|
+
) {
|
|
269
|
+
const { theme } = useUnistyles();
|
|
270
|
+
const { variant: toastVariant } = useToastContext();
|
|
271
|
+
const colors = getToastColors(variant ?? toastVariant, theme);
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<Pressable
|
|
275
|
+
ref={ref}
|
|
276
|
+
accessibilityRole="button"
|
|
277
|
+
accessibilityState={{ disabled: isDisabled }}
|
|
278
|
+
disabled={isDisabled}
|
|
279
|
+
onPress={isDisabled ? undefined : onPress}
|
|
280
|
+
{...rest}
|
|
281
|
+
style={(state) => [
|
|
282
|
+
styles.action,
|
|
283
|
+
styles[`action_${size}`],
|
|
284
|
+
fullWidth ? styles.actionFullWidth : null,
|
|
285
|
+
{
|
|
286
|
+
backgroundColor: colors.actionBg,
|
|
287
|
+
opacity:
|
|
288
|
+
state.pressed && !isDisabled
|
|
289
|
+
? theme.opacity.pressed
|
|
290
|
+
: isDisabled
|
|
291
|
+
? theme.opacity.disabled
|
|
292
|
+
: 1,
|
|
293
|
+
},
|
|
294
|
+
typeof style === 'function' ? style(state) : style,
|
|
295
|
+
]}
|
|
296
|
+
>
|
|
297
|
+
{renderActionChildren(children, colors.actionFg)}
|
|
298
|
+
</Pressable>
|
|
299
|
+
);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
export interface ToastCloseProps extends Omit<ButtonProps, 'children'> {
|
|
303
|
+
children?: ReactNode;
|
|
304
|
+
iconProps?: Omit<IconProps, 'name'>;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const ToastClose = forwardRef<ComponentRef<typeof Button>, ToastCloseProps>(
|
|
308
|
+
function ToastClose(
|
|
309
|
+
{
|
|
310
|
+
children,
|
|
311
|
+
iconProps,
|
|
312
|
+
size = 'sm',
|
|
313
|
+
fullWidth = false,
|
|
314
|
+
isIconOnly = true,
|
|
315
|
+
variant = 'ghost',
|
|
316
|
+
accessibilityLabel = 'Close',
|
|
317
|
+
onPress,
|
|
318
|
+
...rest
|
|
319
|
+
},
|
|
320
|
+
ref
|
|
321
|
+
) {
|
|
322
|
+
const { theme } = useUnistyles();
|
|
323
|
+
const { id, hide, onClose, variant: toastVariant } = useToastContext();
|
|
324
|
+
const colors = getToastColors(toastVariant, theme);
|
|
325
|
+
const handlePress = (event: GestureResponderEvent) => {
|
|
326
|
+
if (id !== undefined) hide?.(id);
|
|
327
|
+
onClose?.();
|
|
328
|
+
onPress?.(event);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<Button
|
|
333
|
+
ref={ref}
|
|
334
|
+
accessibilityLabel={accessibilityLabel}
|
|
335
|
+
fullWidth={fullWidth}
|
|
336
|
+
isIconOnly={isIconOnly}
|
|
337
|
+
onPress={handlePress}
|
|
338
|
+
size={size}
|
|
339
|
+
compact
|
|
340
|
+
variant={variant}
|
|
341
|
+
{...rest}
|
|
342
|
+
>
|
|
343
|
+
{children ?? (
|
|
344
|
+
<Icon
|
|
345
|
+
name="navigation.close"
|
|
346
|
+
size={iconProps?.size ?? 20}
|
|
347
|
+
color={iconProps?.color ?? colors.icon}
|
|
348
|
+
strokeWidth={iconProps?.strokeWidth}
|
|
349
|
+
style={iconProps?.style}
|
|
350
|
+
/>
|
|
351
|
+
)}
|
|
352
|
+
</Button>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
export interface ToastIconProps extends Omit<IconProps, 'name'> {
|
|
358
|
+
name?: TerraIconName;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const VARIANT_ICON: Partial<Record<ToastVariant, TerraIconName>> = {
|
|
362
|
+
info: 'status.info',
|
|
363
|
+
success: 'status.success',
|
|
364
|
+
warning: 'status.warning',
|
|
365
|
+
danger: 'status.danger',
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const ToastIcon = forwardRef<ComponentRef<typeof View>, ToastIconProps>(
|
|
369
|
+
function ToastIcon({ name, color, size = 20, ...rest }, ref) {
|
|
370
|
+
const { theme } = useUnistyles();
|
|
371
|
+
const { variant } = useToastContext();
|
|
372
|
+
const colors = getToastColors(variant, theme);
|
|
373
|
+
const iconName = name ?? VARIANT_ICON[variant] ?? 'status.info';
|
|
374
|
+
|
|
375
|
+
return (
|
|
376
|
+
<Icon
|
|
377
|
+
ref={ref}
|
|
378
|
+
color={color ?? colors.icon}
|
|
379
|
+
name={iconName}
|
|
380
|
+
size={size}
|
|
381
|
+
{...rest}
|
|
382
|
+
/>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
export interface DefaultToastProps extends Omit<ToastProps, 'children'> {
|
|
388
|
+
label?: ReactNode;
|
|
389
|
+
description?: ReactNode;
|
|
390
|
+
actionLabel?: ReactNode;
|
|
391
|
+
onActionPress?: (controls: ToastControls) => void;
|
|
392
|
+
icon?: ReactNode | false;
|
|
393
|
+
showCloseButton?: boolean;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export function DefaultToast({
|
|
397
|
+
label,
|
|
398
|
+
description,
|
|
399
|
+
actionLabel,
|
|
400
|
+
onActionPress,
|
|
401
|
+
icon,
|
|
402
|
+
showCloseButton,
|
|
403
|
+
id,
|
|
404
|
+
hide,
|
|
405
|
+
variant = 'default',
|
|
406
|
+
...rest
|
|
407
|
+
}: DefaultToastProps) {
|
|
408
|
+
const shouldRenderIcon = icon !== false && (icon || variant !== 'default');
|
|
409
|
+
const handleActionPress = () => {
|
|
410
|
+
onActionPress?.({ id, hide });
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
return (
|
|
414
|
+
<ToastRoot id={id} hide={hide} variant={variant} {...rest}>
|
|
415
|
+
{shouldRenderIcon ? (
|
|
416
|
+
<Box alignSelf="start">{icon ?? <ToastIcon />}</Box>
|
|
417
|
+
) : null}
|
|
418
|
+
<Box flex={1} gap="1">
|
|
419
|
+
{label ? <ToastTitle>{label}</ToastTitle> : null}
|
|
420
|
+
{description ? (
|
|
421
|
+
<ToastDescription>{description}</ToastDescription>
|
|
422
|
+
) : null}
|
|
423
|
+
</Box>
|
|
424
|
+
{actionLabel ? (
|
|
425
|
+
<ToastAction onPress={handleActionPress}>{actionLabel}</ToastAction>
|
|
426
|
+
) : null}
|
|
427
|
+
{showCloseButton ? <ToastClose /> : null}
|
|
428
|
+
</ToastRoot>
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
type ToastComponent = typeof ToastRoot & {
|
|
433
|
+
Title: typeof ToastTitle;
|
|
434
|
+
Description: typeof ToastDescription;
|
|
435
|
+
Action: typeof ToastAction;
|
|
436
|
+
Close: typeof ToastClose;
|
|
437
|
+
Icon: typeof ToastIcon;
|
|
438
|
+
show: (options: ToastShowOptions) => StackToastId;
|
|
439
|
+
hide: (id?: StackToastId | StackToastId[] | 'all') => void;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
export const Toast = ToastRoot as ToastComponent;
|
|
443
|
+
Toast.Title = ToastTitle;
|
|
444
|
+
Toast.Description = ToastDescription;
|
|
445
|
+
Toast.Action = ToastAction;
|
|
446
|
+
Toast.Close = ToastClose;
|
|
447
|
+
Toast.Icon = ToastIcon;
|
|
448
|
+
Toast.show = showToast;
|
|
449
|
+
Toast.hide = hideToast;
|
|
450
|
+
|
|
451
|
+
const styles = StyleSheet.create({
|
|
452
|
+
root: {
|
|
453
|
+
alignSelf: 'stretch',
|
|
454
|
+
minHeight: 64,
|
|
455
|
+
},
|
|
456
|
+
action: {
|
|
457
|
+
alignItems: 'center',
|
|
458
|
+
alignSelf: 'flex-start',
|
|
459
|
+
borderRadius: 9999,
|
|
460
|
+
justifyContent: 'center',
|
|
461
|
+
},
|
|
462
|
+
action_sm: {
|
|
463
|
+
minHeight: 36,
|
|
464
|
+
paddingHorizontal: 14,
|
|
465
|
+
},
|
|
466
|
+
action_md: {
|
|
467
|
+
minHeight: 44,
|
|
468
|
+
paddingHorizontal: 16,
|
|
469
|
+
},
|
|
470
|
+
action_lg: {
|
|
471
|
+
minHeight: 52,
|
|
472
|
+
paddingHorizontal: 20,
|
|
473
|
+
},
|
|
474
|
+
actionFullWidth: {
|
|
475
|
+
alignSelf: 'stretch',
|
|
476
|
+
},
|
|
477
|
+
});
|