@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.
Files changed (62) hide show
  1. package/lib/commonjs/components/Button/index.js +4 -0
  2. package/lib/commonjs/components/Button/index.js.map +1 -1
  3. package/lib/commonjs/components/Button/styles.js +59 -0
  4. package/lib/commonjs/components/Button/styles.js.map +1 -1
  5. package/lib/commonjs/hooks/index.js +19 -0
  6. package/lib/commonjs/hooks/index.js.map +1 -0
  7. package/lib/commonjs/hooks/useForgeBottomTabScreenOptions.js +246 -0
  8. package/lib/commonjs/hooks/useForgeBottomTabScreenOptions.js.map +1 -0
  9. package/lib/commonjs/index.js +24 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/navigation/forgeTabIcon.js +43 -0
  12. package/lib/commonjs/navigation/forgeTabIcon.js.map +1 -0
  13. package/lib/commonjs/navigation/forgeTabIcon.native.js +35 -0
  14. package/lib/commonjs/navigation/forgeTabIcon.native.js.map +1 -0
  15. package/lib/commonjs/navigation/index.js +13 -0
  16. package/lib/commonjs/navigation/index.js.map +1 -0
  17. package/lib/commonjs/navigation/types.js +40 -0
  18. package/lib/commonjs/navigation/types.js.map +1 -0
  19. package/lib/module/components/Button/index.js +4 -0
  20. package/lib/module/components/Button/index.js.map +1 -1
  21. package/lib/module/components/Button/styles.js +59 -0
  22. package/lib/module/components/Button/styles.js.map +1 -1
  23. package/lib/module/hooks/index.js +4 -0
  24. package/lib/module/hooks/index.js.map +1 -0
  25. package/lib/module/hooks/useForgeBottomTabScreenOptions.js +242 -0
  26. package/lib/module/hooks/useForgeBottomTabScreenOptions.js.map +1 -0
  27. package/lib/module/index.js +2 -0
  28. package/lib/module/index.js.map +1 -1
  29. package/lib/module/navigation/forgeTabIcon.js +39 -0
  30. package/lib/module/navigation/forgeTabIcon.js.map +1 -0
  31. package/lib/module/navigation/forgeTabIcon.native.js +31 -0
  32. package/lib/module/navigation/forgeTabIcon.native.js.map +1 -0
  33. package/lib/module/navigation/index.js +4 -0
  34. package/lib/module/navigation/index.js.map +1 -0
  35. package/lib/module/navigation/types.js +38 -0
  36. package/lib/module/navigation/types.js.map +1 -0
  37. package/lib/typescript/components/Button/styles.d.ts +2 -0
  38. package/lib/typescript/components/Button/styles.d.ts.map +1 -1
  39. package/lib/typescript/hooks/index.d.ts +2 -0
  40. package/lib/typescript/hooks/index.d.ts.map +1 -0
  41. package/lib/typescript/hooks/useForgeBottomTabScreenOptions.d.ts +137 -0
  42. package/lib/typescript/hooks/useForgeBottomTabScreenOptions.d.ts.map +1 -0
  43. package/lib/typescript/index.d.ts +2 -0
  44. package/lib/typescript/index.d.ts.map +1 -1
  45. package/lib/typescript/navigation/forgeTabIcon.d.ts +27 -0
  46. package/lib/typescript/navigation/forgeTabIcon.d.ts.map +1 -0
  47. package/lib/typescript/navigation/forgeTabIcon.native.d.ts +15 -0
  48. package/lib/typescript/navigation/forgeTabIcon.native.d.ts.map +1 -0
  49. package/lib/typescript/navigation/index.d.ts +4 -0
  50. package/lib/typescript/navigation/index.d.ts.map +1 -0
  51. package/lib/typescript/navigation/types.d.ts +37 -0
  52. package/lib/typescript/navigation/types.d.ts.map +1 -0
  53. package/package.json +6 -4
  54. package/src/components/Button/index.tsx +2 -2
  55. package/src/components/Button/styles.ts +29 -0
  56. package/src/hooks/index.ts +5 -0
  57. package/src/hooks/useForgeBottomTabScreenOptions.ts +245 -0
  58. package/src/index.ts +2 -0
  59. package/src/navigation/forgeTabIcon.native.ts +36 -0
  60. package/src/navigation/forgeTabIcon.ts +33 -0
  61. package/src/navigation/index.ts +3 -0
  62. 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,3 @@
1
+ export { forgeTabIcon } from './forgeTabIcon';
2
+ export type { ForgeNativeBottomTabIcon, ForgeTabBarIcon } from './types';
3
+ export type { ForgeTabIcon, ForgeTabIconNativeSources } from '@cdx-ui/icons/tab-icons';
@@ -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;