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 @@
|
|
|
1
|
+
{"version":3,"file":"deep-merge.d.ts","sourceRoot":"","sources":["../../../../src/utils/deep-merge.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC9C,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GACtC,CAAC,CAAC;AAQR;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAiBlE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ColorToken, TerraTheme } from '#theme/types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a {@link ColorToken} to a concrete color string using the theme.
|
|
4
|
+
* Raw literals pass through unchanged.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* resolveThemeColor('text.default', theme) // → '#020618'
|
|
8
|
+
* resolveThemeColor('action.bg.primary', theme) // → '#009966'
|
|
9
|
+
* resolveThemeColor('#ff0000', theme) // → '#ff0000'
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveThemeColor(token: ColorToken | undefined, theme: TerraTheme): string | undefined;
|
|
12
|
+
//# sourceMappingURL=resolve-theme-color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-theme-color.d.ts","sourceRoot":"","sources":["../../../../src/utils/resolve-theme-color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAS3D;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,GAAG,SAAS,EAC7B,KAAK,EAAE,UAAU,GAChB,MAAM,GAAG,SAAS,CAKpB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FontWeightToken } from '#theme/types';
|
|
2
|
+
/** RN's sentinel for the platform default font (SF on iOS, Roboto on Android). */
|
|
3
|
+
export declare const SYSTEM_FONT = "System";
|
|
4
|
+
/** Numeric fontWeight applied when a weight token maps to the system font. */
|
|
5
|
+
export declare const FONT_WEIGHT_VALUE: Record<FontWeightToken, '400' | '500' | '600' | '700'>;
|
|
6
|
+
//# sourceMappingURL=typography.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typography.d.ts","sourceRoot":"","sources":["../../../../src/utils/typography.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,kFAAkF;AAClF,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC,8EAA8E;AAC9E,eAAO,MAAM,iBAAiB,EAAE,MAAM,CACpC,eAAe,EACf,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAM9B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rebuilds a nested object from a flat map of dotted-path keys.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* unflatten({ 'a.b.c': 1, 'a.b.d': 2 }) // → { a: { b: { c: 1, d: 2 } } }
|
|
6
|
+
*
|
|
7
|
+
* Used to turn the flat, Figma-style token data (tokens/*.ts) back into the
|
|
8
|
+
* nested runtime theme shape that components and Unistyles consume. The caller
|
|
9
|
+
* is responsible for asserting the resulting shape (e.g. `as TerraTheme`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function unflatten<T = unknown>(flat: Record<string, unknown>): T;
|
|
12
|
+
//# sourceMappingURL=unflatten.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unflatten.d.ts","sourceRoot":"","sources":["../../../../src/utils/unflatten.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAyBvE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-terra-ui",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Themeable React Native UI components built on react-native-unistyles",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"imports": {
|
|
8
|
+
"#*": "./src/*"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/index.tsx",
|
|
13
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
14
|
+
"default": "./lib/module/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./theme": {
|
|
17
|
+
"source": "./src/theme/index.ts",
|
|
18
|
+
"types": "./lib/typescript/src/theme/index.d.ts",
|
|
19
|
+
"default": "./lib/module/theme/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"lib",
|
|
26
|
+
"!**/__tests__",
|
|
27
|
+
"!**/__fixtures__",
|
|
28
|
+
"!**/__mocks__",
|
|
29
|
+
"!**/.*"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "bob build",
|
|
33
|
+
"clean": "del-cli lib",
|
|
34
|
+
"prepare": "bob build",
|
|
35
|
+
"typecheck": "tsc",
|
|
36
|
+
"lint": "biome check .",
|
|
37
|
+
"test": "jest"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"react-native",
|
|
41
|
+
"ios",
|
|
42
|
+
"android"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/earthling-std/react-native-terra-ui.git",
|
|
47
|
+
"directory": "packages/ui"
|
|
48
|
+
},
|
|
49
|
+
"author": "Hai Le <hai.le@elmosoftware.com.au> (https://github.com/earthling-std)",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/earthling-std/react-native-terra-ui/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/earthling-std/react-native-terra-ui#readme",
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@jest/globals": "^29.7.0",
|
|
60
|
+
"@react-native/babel-preset": "0.85.0",
|
|
61
|
+
"@react-native/jest-preset": "0.85.0",
|
|
62
|
+
"@testing-library/react-native": "^13.3.3",
|
|
63
|
+
"@types/react": "^19.2.0",
|
|
64
|
+
"babel-plugin-module-resolver": "^5.0.3",
|
|
65
|
+
"del-cli": "^7.0.0",
|
|
66
|
+
"jest": "^29.7.0",
|
|
67
|
+
"react": "19.2.0",
|
|
68
|
+
"react-native": "0.83.6",
|
|
69
|
+
"react-native-builder-bob": "^0.42.1",
|
|
70
|
+
"react-native-edge-to-edge": "1.8.1",
|
|
71
|
+
"react-native-nitro-modules": "0.35.9",
|
|
72
|
+
"react-native-reanimated": "^4.4.1",
|
|
73
|
+
"react-native-safe-area-context": "^5.8.0",
|
|
74
|
+
"react-native-svg": "15.15.4",
|
|
75
|
+
"react-native-unistyles": "^3.2.5",
|
|
76
|
+
"react-test-renderer": "19.2.0",
|
|
77
|
+
"typescript": "^6.0.3"
|
|
78
|
+
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"react": "*",
|
|
81
|
+
"react-native": "*",
|
|
82
|
+
"react-native-reanimated": ">=4.0.0",
|
|
83
|
+
"react-native-safe-area-context": ">=4.0.0",
|
|
84
|
+
"react-native-svg": ">=15.0.0",
|
|
85
|
+
"react-native-unistyles": ">=3.0.0"
|
|
86
|
+
},
|
|
87
|
+
"react-native-builder-bob": {
|
|
88
|
+
"source": "src",
|
|
89
|
+
"output": "lib",
|
|
90
|
+
"targets": [
|
|
91
|
+
[
|
|
92
|
+
"module",
|
|
93
|
+
{
|
|
94
|
+
"esm": true
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
[
|
|
98
|
+
"typescript",
|
|
99
|
+
{
|
|
100
|
+
"project": "tsconfig.build.json"
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
"jest": {
|
|
106
|
+
"preset": "@react-native/jest-preset",
|
|
107
|
+
"setupFilesAfterEnv": [
|
|
108
|
+
"<rootDir>/jest.setup.ts"
|
|
109
|
+
],
|
|
110
|
+
"modulePathIgnorePatterns": [
|
|
111
|
+
"<rootDir>/lib/"
|
|
112
|
+
],
|
|
113
|
+
"collectCoverageFrom": [
|
|
114
|
+
"src/theme/**/*.ts",
|
|
115
|
+
"src/utils/**/*.ts",
|
|
116
|
+
"src/components/**/*.{ts,tsx}",
|
|
117
|
+
"!src/**/__tests__/**"
|
|
118
|
+
],
|
|
119
|
+
"coverageThreshold": {
|
|
120
|
+
"global": {
|
|
121
|
+
"branches": 5,
|
|
122
|
+
"functions": 5,
|
|
123
|
+
"lines": 5,
|
|
124
|
+
"statements": 5
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"create-react-native-library": {
|
|
129
|
+
"type": "library",
|
|
130
|
+
"languages": "js",
|
|
131
|
+
"tools": [
|
|
132
|
+
"biome",
|
|
133
|
+
"jest"
|
|
134
|
+
],
|
|
135
|
+
"version": "0.62.2"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Text, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useUnistyles } from 'react-native-unistyles';
|
|
5
|
+
|
|
6
|
+
import { getImageComponent } from '#theme/configure';
|
|
7
|
+
import type { TerraTheme } from '#theme/types';
|
|
8
|
+
|
|
9
|
+
import { Icon } from '../icon';
|
|
10
|
+
import type {
|
|
11
|
+
AvatarColor,
|
|
12
|
+
AvatarProps,
|
|
13
|
+
AvatarShape,
|
|
14
|
+
AvatarSize,
|
|
15
|
+
AvatarVariant,
|
|
16
|
+
} from './types';
|
|
17
|
+
|
|
18
|
+
const SIZE_PX: Record<AvatarSize, number> = {
|
|
19
|
+
xs: 24,
|
|
20
|
+
sm: 32,
|
|
21
|
+
md: 40,
|
|
22
|
+
lg: 48,
|
|
23
|
+
xl: 64,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const INITIALS_FONT_SIZE: Record<AvatarSize, number> = {
|
|
27
|
+
xs: 9,
|
|
28
|
+
sm: 12,
|
|
29
|
+
md: 15,
|
|
30
|
+
lg: 18,
|
|
31
|
+
xl: 24,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function getInitials(name: string): string {
|
|
35
|
+
const parts = name.trim().split(/\s+/);
|
|
36
|
+
const first = parts[0]?.[0] ?? '';
|
|
37
|
+
const last = parts.length > 1 ? (parts[parts.length - 1]?.[0] ?? '') : '';
|
|
38
|
+
return (first + last).toUpperCase();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getBorderRadius(
|
|
42
|
+
shape: AvatarShape,
|
|
43
|
+
sizePx: number,
|
|
44
|
+
radiusMd: number
|
|
45
|
+
): number {
|
|
46
|
+
if (shape === 'circle') return sizePx / 2;
|
|
47
|
+
if (shape === 'rounded') return radiusMd;
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function resolveAvatarColors(
|
|
52
|
+
color: AvatarColor,
|
|
53
|
+
variant: AvatarVariant,
|
|
54
|
+
theme: TerraTheme
|
|
55
|
+
): { bg: string; fg: string } {
|
|
56
|
+
const c = theme.color;
|
|
57
|
+
const get = (key: string): string =>
|
|
58
|
+
(c as unknown as Record<string, string | undefined>)[key] ?? '';
|
|
59
|
+
if (color === 'default') {
|
|
60
|
+
return { bg: c['surface.sunken'], fg: c['text.muted'] };
|
|
61
|
+
}
|
|
62
|
+
if (color === 'accent') {
|
|
63
|
+
return variant === 'soft'
|
|
64
|
+
? { bg: c['action.bg.subtle'], fg: c['action.fg.subtle'] }
|
|
65
|
+
: { bg: c['action.bg.primary'], fg: c['action.fg.primary'] };
|
|
66
|
+
}
|
|
67
|
+
return variant === 'soft'
|
|
68
|
+
? {
|
|
69
|
+
bg: get(`status.bg.${color}.subtle`),
|
|
70
|
+
fg: get(`status.fg.${color}.subtle`),
|
|
71
|
+
}
|
|
72
|
+
: { bg: get(`status.bg.${color}`), fg: get(`status.fg.${color}`) };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function Avatar({
|
|
76
|
+
size = 'md',
|
|
77
|
+
shape = 'circle',
|
|
78
|
+
source,
|
|
79
|
+
name,
|
|
80
|
+
fallback,
|
|
81
|
+
contentFit = 'cover',
|
|
82
|
+
color = 'default',
|
|
83
|
+
variant = 'default',
|
|
84
|
+
style,
|
|
85
|
+
...rest
|
|
86
|
+
}: AvatarProps) {
|
|
87
|
+
const { theme } = useUnistyles();
|
|
88
|
+
const [hasError, setHasError] = useState(false);
|
|
89
|
+
|
|
90
|
+
const sizePx = SIZE_PX[size];
|
|
91
|
+
const borderRadius = getBorderRadius(shape, sizePx, theme.radius.md);
|
|
92
|
+
const showFallback = !source || hasError;
|
|
93
|
+
|
|
94
|
+
const { bg, fg } = resolveAvatarColors(color, variant, theme);
|
|
95
|
+
|
|
96
|
+
const fallbackContent =
|
|
97
|
+
fallback !== undefined ? (
|
|
98
|
+
fallback
|
|
99
|
+
) : name ? (
|
|
100
|
+
<Text
|
|
101
|
+
style={{
|
|
102
|
+
fontSize: INITIALS_FONT_SIZE[size],
|
|
103
|
+
fontWeight: '600',
|
|
104
|
+
color: fg,
|
|
105
|
+
includeFontPadding: false,
|
|
106
|
+
}}
|
|
107
|
+
numberOfLines={1}
|
|
108
|
+
>
|
|
109
|
+
{getInitials(name)}
|
|
110
|
+
</Text>
|
|
111
|
+
) : (
|
|
112
|
+
<Icon name="person" size={sizePx} color={fg} />
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const ImageComponent = getImageComponent();
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<View
|
|
119
|
+
{...rest}
|
|
120
|
+
style={[
|
|
121
|
+
{
|
|
122
|
+
width: sizePx,
|
|
123
|
+
height: sizePx,
|
|
124
|
+
borderRadius,
|
|
125
|
+
backgroundColor: bg,
|
|
126
|
+
alignItems: 'center',
|
|
127
|
+
justifyContent: 'center',
|
|
128
|
+
overflow: 'hidden',
|
|
129
|
+
},
|
|
130
|
+
style,
|
|
131
|
+
]}
|
|
132
|
+
>
|
|
133
|
+
{showFallback ? (
|
|
134
|
+
fallbackContent
|
|
135
|
+
) : (
|
|
136
|
+
<ImageComponent
|
|
137
|
+
source={source}
|
|
138
|
+
style={{ width: sizePx, height: sizePx }}
|
|
139
|
+
contentFit={contentFit}
|
|
140
|
+
accessibilityLabel={name}
|
|
141
|
+
onError={() => setHasError(true)}
|
|
142
|
+
/>
|
|
143
|
+
)}
|
|
144
|
+
</View>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type { TerraImageContentFit } from '#theme/types';
|
|
5
|
+
|
|
6
|
+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
7
|
+
export type AvatarShape = 'circle' | 'rounded' | 'square';
|
|
8
|
+
/** Semantic color scheme for the fallback state (initials / placeholder icon). */
|
|
9
|
+
export type AvatarColor =
|
|
10
|
+
| 'default'
|
|
11
|
+
| 'accent'
|
|
12
|
+
| 'success'
|
|
13
|
+
| 'warning'
|
|
14
|
+
| 'danger';
|
|
15
|
+
/** Visual weight of the fallback background. */
|
|
16
|
+
export type AvatarVariant = 'default' | 'soft';
|
|
17
|
+
|
|
18
|
+
export interface AvatarProps extends ViewProps {
|
|
19
|
+
/** Predefined size token. Defaults to `'md'`. */
|
|
20
|
+
size?: AvatarSize;
|
|
21
|
+
/** Corner shape. Defaults to `'circle'`. */
|
|
22
|
+
shape?: AvatarShape;
|
|
23
|
+
/** Remote URL or local asset. When omitted or on load error, the fallback is shown. */
|
|
24
|
+
source?: { uri: string } | number;
|
|
25
|
+
/** Used to derive initials when no `source` or `fallback` is provided. */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** Custom fallback content — takes priority over initials and the built-in placeholder. */
|
|
28
|
+
fallback?: ReactNode;
|
|
29
|
+
/** How the image fills its container. Defaults to `'cover'`. */
|
|
30
|
+
contentFit?: TerraImageContentFit;
|
|
31
|
+
/** Fallback color theme. Defaults to `'default'`. */
|
|
32
|
+
color?: AvatarColor;
|
|
33
|
+
/** Visual style variant. Defaults to `'default'`. */
|
|
34
|
+
variant?: AvatarVariant;
|
|
35
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type ComponentRef, forwardRef } from 'react';
|
|
2
|
+
import { View, type ViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useUnistyles } from 'react-native-unistyles';
|
|
5
|
+
|
|
6
|
+
import { Slot } from '../slot';
|
|
7
|
+
import {
|
|
8
|
+
BOX_STYLE_PROP_KEYS,
|
|
9
|
+
type BoxStyleProps,
|
|
10
|
+
resolveBoxStyle,
|
|
11
|
+
} from './utils';
|
|
12
|
+
|
|
13
|
+
export interface BoxProps extends ViewProps, BoxStyleProps {
|
|
14
|
+
/** Merge Box's style/props onto a single child instead of rendering a View. */
|
|
15
|
+
asChild?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const STYLE_KEYS = new Set<string>(BOX_STYLE_PROP_KEYS as readonly string[]);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Base layout primitive: a `View` styled through theme-token props.
|
|
22
|
+
* The only component family exposing token style-props.
|
|
23
|
+
*/
|
|
24
|
+
export const Box = forwardRef<ComponentRef<typeof View>, BoxProps>(function Box(
|
|
25
|
+
{ asChild, style, children, ...rest },
|
|
26
|
+
ref
|
|
27
|
+
) {
|
|
28
|
+
const { theme } = useUnistyles();
|
|
29
|
+
|
|
30
|
+
const styleProps: Record<string, unknown> = {};
|
|
31
|
+
const viewProps: Record<string, unknown> = {};
|
|
32
|
+
for (const key of Object.keys(rest)) {
|
|
33
|
+
const value = (rest as Record<string, unknown>)[key];
|
|
34
|
+
if (STYLE_KEYS.has(key)) styleProps[key] = value;
|
|
35
|
+
else viewProps[key] = value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const mergedStyle = [
|
|
39
|
+
resolveBoxStyle(styleProps as BoxStyleProps, theme),
|
|
40
|
+
style,
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
if (asChild) {
|
|
44
|
+
return (
|
|
45
|
+
<Slot
|
|
46
|
+
ownerName="Box"
|
|
47
|
+
slotProps={{ ...viewProps, style: mergedStyle, ref }}
|
|
48
|
+
>
|
|
49
|
+
{children}
|
|
50
|
+
</Slot>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<View ref={ref} style={mergedStyle} {...(viewProps as ViewProps)}>
|
|
56
|
+
{children}
|
|
57
|
+
</View>
|
|
58
|
+
);
|
|
59
|
+
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { StyleSheet, type ViewStyle } from 'react-native';
|
|
2
|
+
import type {
|
|
3
|
+
ColorToken,
|
|
4
|
+
RadiusKey,
|
|
5
|
+
SpacingKey,
|
|
6
|
+
TerraTheme,
|
|
7
|
+
} from '#theme/types';
|
|
8
|
+
import { resolveThemeColor } from '#utils/resolve-theme-color';
|
|
9
|
+
|
|
10
|
+
export type Align = 'start' | 'center' | 'end' | 'stretch' | 'baseline';
|
|
11
|
+
export type Justify =
|
|
12
|
+
| 'start'
|
|
13
|
+
| 'center'
|
|
14
|
+
| 'end'
|
|
15
|
+
| 'between'
|
|
16
|
+
| 'around'
|
|
17
|
+
| 'evenly';
|
|
18
|
+
export type BorderWidthInput = number | 'hairline';
|
|
19
|
+
|
|
20
|
+
/** Strips `readonly` so the style object can be built by mutation. */
|
|
21
|
+
type Mutable<T> = { -readonly [K in keyof T]: T[K] };
|
|
22
|
+
|
|
23
|
+
/** Token-driven style props accepted by `Box`. */
|
|
24
|
+
export interface BoxStyleProps {
|
|
25
|
+
// Spacing
|
|
26
|
+
p?: SpacingKey;
|
|
27
|
+
px?: SpacingKey;
|
|
28
|
+
py?: SpacingKey;
|
|
29
|
+
pt?: SpacingKey;
|
|
30
|
+
pr?: SpacingKey;
|
|
31
|
+
pb?: SpacingKey;
|
|
32
|
+
pl?: SpacingKey;
|
|
33
|
+
m?: SpacingKey;
|
|
34
|
+
mx?: SpacingKey;
|
|
35
|
+
my?: SpacingKey;
|
|
36
|
+
mt?: SpacingKey;
|
|
37
|
+
mr?: SpacingKey;
|
|
38
|
+
mb?: SpacingKey;
|
|
39
|
+
ml?: SpacingKey;
|
|
40
|
+
gap?: SpacingKey;
|
|
41
|
+
// Layout
|
|
42
|
+
/** Horizontal layout (`flexDirection: 'row'`). Defaults to column. */
|
|
43
|
+
row?: boolean;
|
|
44
|
+
align?: Align;
|
|
45
|
+
justify?: Justify;
|
|
46
|
+
wrap?: boolean;
|
|
47
|
+
flex?: number;
|
|
48
|
+
alignSelf?: Align;
|
|
49
|
+
// Visual
|
|
50
|
+
bg?: ColorToken;
|
|
51
|
+
radius?: RadiusKey;
|
|
52
|
+
borderWidth?: BorderWidthInput;
|
|
53
|
+
borderColor?: ColorToken;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const ALIGN_MAP: Record<Align, NonNullable<ViewStyle['alignItems']>> = {
|
|
57
|
+
start: 'flex-start',
|
|
58
|
+
center: 'center',
|
|
59
|
+
end: 'flex-end',
|
|
60
|
+
stretch: 'stretch',
|
|
61
|
+
baseline: 'baseline',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const JUSTIFY_MAP: Record<Justify, NonNullable<ViewStyle['justifyContent']>> = {
|
|
65
|
+
start: 'flex-start',
|
|
66
|
+
center: 'center',
|
|
67
|
+
end: 'flex-end',
|
|
68
|
+
between: 'space-between',
|
|
69
|
+
around: 'space-around',
|
|
70
|
+
evenly: 'space-evenly',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const space = (
|
|
74
|
+
theme: TerraTheme,
|
|
75
|
+
key: SpacingKey | undefined
|
|
76
|
+
): number | undefined => (key === undefined ? undefined : theme.spacing[key]);
|
|
77
|
+
|
|
78
|
+
/** Builds a `ViewStyle` from token-driven props using the active theme. */
|
|
79
|
+
export function resolveBoxStyle(
|
|
80
|
+
props: BoxStyleProps,
|
|
81
|
+
theme: TerraTheme
|
|
82
|
+
): ViewStyle {
|
|
83
|
+
const style: Mutable<ViewStyle> = {};
|
|
84
|
+
|
|
85
|
+
// Padding
|
|
86
|
+
const p = space(theme, props.p);
|
|
87
|
+
const px = space(theme, props.px);
|
|
88
|
+
const py = space(theme, props.py);
|
|
89
|
+
if (p !== undefined) style.padding = p;
|
|
90
|
+
if (px !== undefined) style.paddingHorizontal = px;
|
|
91
|
+
if (py !== undefined) style.paddingVertical = py;
|
|
92
|
+
const pt = space(theme, props.pt);
|
|
93
|
+
const pr = space(theme, props.pr);
|
|
94
|
+
const pb = space(theme, props.pb);
|
|
95
|
+
const pl = space(theme, props.pl);
|
|
96
|
+
if (pt !== undefined) style.paddingTop = pt;
|
|
97
|
+
if (pr !== undefined) style.paddingRight = pr;
|
|
98
|
+
if (pb !== undefined) style.paddingBottom = pb;
|
|
99
|
+
if (pl !== undefined) style.paddingLeft = pl;
|
|
100
|
+
|
|
101
|
+
// Margin
|
|
102
|
+
const m = space(theme, props.m);
|
|
103
|
+
const mx = space(theme, props.mx);
|
|
104
|
+
const my = space(theme, props.my);
|
|
105
|
+
if (m !== undefined) style.margin = m;
|
|
106
|
+
if (mx !== undefined) style.marginHorizontal = mx;
|
|
107
|
+
if (my !== undefined) style.marginVertical = my;
|
|
108
|
+
const mt = space(theme, props.mt);
|
|
109
|
+
const mr = space(theme, props.mr);
|
|
110
|
+
const mb = space(theme, props.mb);
|
|
111
|
+
const ml = space(theme, props.ml);
|
|
112
|
+
if (mt !== undefined) style.marginTop = mt;
|
|
113
|
+
if (mr !== undefined) style.marginRight = mr;
|
|
114
|
+
if (mb !== undefined) style.marginBottom = mb;
|
|
115
|
+
if (ml !== undefined) style.marginLeft = ml;
|
|
116
|
+
|
|
117
|
+
// Gap
|
|
118
|
+
const gap = space(theme, props.gap);
|
|
119
|
+
if (gap !== undefined) style.gap = gap;
|
|
120
|
+
|
|
121
|
+
// Layout
|
|
122
|
+
if (props.row !== undefined)
|
|
123
|
+
style.flexDirection = props.row ? 'row' : 'column';
|
|
124
|
+
if (props.align !== undefined) style.alignItems = ALIGN_MAP[props.align];
|
|
125
|
+
if (props.justify !== undefined) {
|
|
126
|
+
style.justifyContent = JUSTIFY_MAP[props.justify];
|
|
127
|
+
}
|
|
128
|
+
if (props.wrap !== undefined) style.flexWrap = props.wrap ? 'wrap' : 'nowrap';
|
|
129
|
+
if (props.flex !== undefined) style.flex = props.flex;
|
|
130
|
+
if (props.alignSelf !== undefined)
|
|
131
|
+
style.alignSelf = ALIGN_MAP[props.alignSelf];
|
|
132
|
+
|
|
133
|
+
// Visual
|
|
134
|
+
if (props.bg !== undefined) {
|
|
135
|
+
const bg = resolveThemeColor(props.bg, theme);
|
|
136
|
+
if (bg !== undefined) style.backgroundColor = bg;
|
|
137
|
+
}
|
|
138
|
+
if (props.radius !== undefined)
|
|
139
|
+
style.borderRadius = theme.radius[props.radius];
|
|
140
|
+
if (props.borderWidth !== undefined) {
|
|
141
|
+
style.borderWidth =
|
|
142
|
+
props.borderWidth === 'hairline'
|
|
143
|
+
? StyleSheet.hairlineWidth
|
|
144
|
+
: props.borderWidth;
|
|
145
|
+
}
|
|
146
|
+
if (props.borderColor !== undefined) {
|
|
147
|
+
const borderColor = resolveThemeColor(props.borderColor, theme);
|
|
148
|
+
if (borderColor !== undefined) style.borderColor = borderColor;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return style;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Keys of {@link BoxStyleProps}, used to split style props from view props. */
|
|
155
|
+
export const BOX_STYLE_PROP_KEYS: readonly (keyof BoxStyleProps)[] = [
|
|
156
|
+
'p',
|
|
157
|
+
'px',
|
|
158
|
+
'py',
|
|
159
|
+
'pt',
|
|
160
|
+
'pr',
|
|
161
|
+
'pb',
|
|
162
|
+
'pl',
|
|
163
|
+
'm',
|
|
164
|
+
'mx',
|
|
165
|
+
'my',
|
|
166
|
+
'mt',
|
|
167
|
+
'mr',
|
|
168
|
+
'mb',
|
|
169
|
+
'ml',
|
|
170
|
+
'gap',
|
|
171
|
+
'row',
|
|
172
|
+
'align',
|
|
173
|
+
'justify',
|
|
174
|
+
'wrap',
|
|
175
|
+
'flex',
|
|
176
|
+
'alignSelf',
|
|
177
|
+
'bg',
|
|
178
|
+
'radius',
|
|
179
|
+
'borderWidth',
|
|
180
|
+
'borderColor',
|
|
181
|
+
];
|