@cdx-ui/components 0.0.1-beta.50 → 0.0.1-beta.51
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/lib/commonjs/components/Button/index.js +4 -0
- package/lib/commonjs/components/Button/index.js.map +1 -1
- package/lib/commonjs/components/Button/styles.js +59 -0
- package/lib/commonjs/components/Button/styles.js.map +1 -1
- package/lib/commonjs/hooks/index.js +19 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/hooks/useForgeBottomTabScreenOptions.js +246 -0
- package/lib/commonjs/hooks/useForgeBottomTabScreenOptions.js.map +1 -0
- package/lib/commonjs/index.js +24 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/navigation/forgeTabIcon.js +43 -0
- package/lib/commonjs/navigation/forgeTabIcon.js.map +1 -0
- package/lib/commonjs/navigation/forgeTabIcon.native.js +35 -0
- package/lib/commonjs/navigation/forgeTabIcon.native.js.map +1 -0
- package/lib/commonjs/navigation/index.js +13 -0
- package/lib/commonjs/navigation/index.js.map +1 -0
- package/lib/commonjs/navigation/types.js +40 -0
- package/lib/commonjs/navigation/types.js.map +1 -0
- package/lib/module/components/Button/index.js +4 -0
- package/lib/module/components/Button/index.js.map +1 -1
- package/lib/module/components/Button/styles.js +59 -0
- package/lib/module/components/Button/styles.js.map +1 -1
- package/lib/module/hooks/index.js +4 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useForgeBottomTabScreenOptions.js +242 -0
- package/lib/module/hooks/useForgeBottomTabScreenOptions.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigation/forgeTabIcon.js +39 -0
- package/lib/module/navigation/forgeTabIcon.js.map +1 -0
- package/lib/module/navigation/forgeTabIcon.native.js +31 -0
- package/lib/module/navigation/forgeTabIcon.native.js.map +1 -0
- package/lib/module/navigation/index.js +4 -0
- package/lib/module/navigation/index.js.map +1 -0
- package/lib/module/navigation/types.js +38 -0
- package/lib/module/navigation/types.js.map +1 -0
- package/lib/typescript/components/Button/styles.d.ts +2 -0
- package/lib/typescript/components/Button/styles.d.ts.map +1 -1
- package/lib/typescript/hooks/index.d.ts +2 -0
- package/lib/typescript/hooks/index.d.ts.map +1 -0
- package/lib/typescript/hooks/useForgeBottomTabScreenOptions.d.ts +137 -0
- package/lib/typescript/hooks/useForgeBottomTabScreenOptions.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/navigation/forgeTabIcon.d.ts +27 -0
- package/lib/typescript/navigation/forgeTabIcon.d.ts.map +1 -0
- package/lib/typescript/navigation/forgeTabIcon.native.d.ts +15 -0
- package/lib/typescript/navigation/forgeTabIcon.native.d.ts.map +1 -0
- package/lib/typescript/navigation/index.d.ts +4 -0
- package/lib/typescript/navigation/index.d.ts.map +1 -0
- package/lib/typescript/navigation/types.d.ts +37 -0
- package/lib/typescript/navigation/types.d.ts.map +1 -0
- package/package.json +6 -4
- package/src/components/Button/index.tsx +2 -2
- package/src/components/Button/styles.ts +29 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useForgeBottomTabScreenOptions.ts +245 -0
- package/src/index.ts +2 -0
- package/src/navigation/forgeTabIcon.native.ts +36 -0
- package/src/navigation/forgeTabIcon.ts +33 -0
- package/src/navigation/index.ts +3 -0
- package/src/navigation/types.ts +55 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import type { ForgeTabIcon } from '@cdx-ui/icons/tab-icons';
|
|
3
|
+
import type { ForgeTabBarIcon } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* forgeTabIcon — web/JS-navigator implementation.
|
|
7
|
+
*
|
|
8
|
+
* Maps a {@link ForgeTabIcon} descriptor to a React Navigation `tabBarIcon`
|
|
9
|
+
* value that renders the same Forge UI icon on every platform:
|
|
10
|
+
*
|
|
11
|
+
* - **Web** (`createBottomTabNavigator`): renders the SVG icon component with
|
|
12
|
+
* `filled={focused}` and the navigator-supplied `color`/`size` — pair with
|
|
13
|
+
* `useForgeBottomTabScreenOptions` so tints come from design tokens.
|
|
14
|
+
* - **iOS/Android** (`createNativeBottomTabNavigator`): the `.native` module
|
|
15
|
+
* of this file returns a tinted template-image descriptor instead.
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { useForgeBottomTabScreenOptions, forgeTabIcon } from '@cdx-ui/components';
|
|
19
|
+
* import { HomeTabIcon } from '@cdx-ui/icons/tab-icons';
|
|
20
|
+
*
|
|
21
|
+
* <Tab.Screen
|
|
22
|
+
* name="Home"
|
|
23
|
+
* component={HomeScreen}
|
|
24
|
+
* options={{ title: 'Home', tabBarIcon: forgeTabIcon(HomeTabIcon) }}
|
|
25
|
+
* />
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function forgeTabIcon(icon: ForgeTabIcon): ForgeTabBarIcon {
|
|
29
|
+
const render = ({ focused, color, size }: { focused: boolean; color: string; size: number }) =>
|
|
30
|
+
createElement(icon.Component, { filled: focused, color, size });
|
|
31
|
+
|
|
32
|
+
return render as ForgeTabBarIcon;
|
|
33
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { ImageSourcePropType } from 'react-native';
|
|
3
|
+
import type { BottomTabNavigationOptions } from '@react-navigation/bottom-tabs';
|
|
4
|
+
import type { NativeBottomTabNavigationOptions } from '@react-navigation/bottom-tabs/unstable';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Structural mirror of the `image` arm of `NativeBottomTabIcon` from
|
|
8
|
+
* `@react-navigation/bottom-tabs/unstable`. Declared locally so
|
|
9
|
+
* `@cdx-ui/components` carries no runtime React Navigation dependency —
|
|
10
|
+
* the drift guards below fail the build if the upstream shape changes.
|
|
11
|
+
*/
|
|
12
|
+
export interface ForgeNativeBottomTabIcon {
|
|
13
|
+
type: 'image';
|
|
14
|
+
/** Metro-resolved asset (e.g. a static `require('./icon.png')`). */
|
|
15
|
+
source: ImageSourcePropType;
|
|
16
|
+
/**
|
|
17
|
+
* Render as a template image tinted with the tab bar's active/inactive
|
|
18
|
+
* tint color. iOS-only flag — Android always tints tab icons.
|
|
19
|
+
*/
|
|
20
|
+
tinted?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The value `forgeTabIcon()` returns — callable as `tabBarIcon` on **both**
|
|
25
|
+
* React Navigation bottom tab navigators. The intersection carries both call
|
|
26
|
+
* signatures; the platform-split implementation guarantees the matching one
|
|
27
|
+
* at runtime:
|
|
28
|
+
*
|
|
29
|
+
* - `createBottomTabNavigator` (web/JS) invokes it with
|
|
30
|
+
* `{ focused, color, size }` and renders the returned element.
|
|
31
|
+
* - `createNativeBottomTabNavigator` (iOS/Android) invokes it with
|
|
32
|
+
* `{ focused }` and receives a native icon descriptor.
|
|
33
|
+
*/
|
|
34
|
+
export type ForgeTabBarIcon = ((props: {
|
|
35
|
+
focused: boolean;
|
|
36
|
+
color: string;
|
|
37
|
+
size: number;
|
|
38
|
+
}) => ReactElement) &
|
|
39
|
+
((props: { focused: boolean }) => ForgeNativeBottomTabIcon);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Compile-time drift guards (see `useForgeBottomTabScreenOptions` for the
|
|
43
|
+
* pattern): `ForgeTabBarIcon` must stay assignable to the `tabBarIcon`
|
|
44
|
+
* option of both navigators. The `null as any` casts keep the runtime
|
|
45
|
+
* values `null` so tree-shakers eliminate them entirely.
|
|
46
|
+
*/
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
const _rnDriftGuardWeb: BottomTabNavigationOptions['tabBarIcon'] =
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
null as any as ForgeTabBarIcon;
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
53
|
+
const _rnDriftGuardNative: NativeBottomTabNavigationOptions['tabBarIcon'] =
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
null as any as ForgeTabBarIcon;
|