@cdx-ui/components 0.0.1-beta.50 → 0.0.1-beta.52

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 (159) hide show
  1. package/lib/commonjs/components/AlertDialog/index.js +4 -3
  2. package/lib/commonjs/components/AlertDialog/index.js.map +1 -1
  3. package/lib/commonjs/components/Button/index.js +4 -0
  4. package/lib/commonjs/components/Button/index.js.map +1 -1
  5. package/lib/commonjs/components/Button/styles.js +59 -0
  6. package/lib/commonjs/components/Button/styles.js.map +1 -1
  7. package/lib/commonjs/components/Dialog/index.js +71 -16
  8. package/lib/commonjs/components/Dialog/index.js.map +1 -1
  9. package/lib/commonjs/components/Dialog/styles.js +60 -14
  10. package/lib/commonjs/components/Dialog/styles.js.map +1 -1
  11. package/lib/commonjs/figma/AlertDialog.Description.figma.js +20 -0
  12. package/lib/commonjs/figma/AlertDialog.Description.figma.js.map +1 -0
  13. package/lib/commonjs/figma/AlertDialog.Footer.figma.js +41 -0
  14. package/lib/commonjs/figma/AlertDialog.Footer.figma.js.map +1 -0
  15. package/lib/commonjs/figma/AlertDialog.Header.figma.js +28 -0
  16. package/lib/commonjs/figma/AlertDialog.Header.figma.js.map +1 -0
  17. package/lib/commonjs/figma/AlertDialog.Text.figma.js +20 -0
  18. package/lib/commonjs/figma/AlertDialog.Text.figma.js.map +1 -0
  19. package/lib/commonjs/figma/AlertDialog.Title.figma.js +27 -0
  20. package/lib/commonjs/figma/AlertDialog.Title.figma.js.map +1 -0
  21. package/lib/commonjs/figma/AlertDialog.figma.js +43 -0
  22. package/lib/commonjs/figma/AlertDialog.figma.js.map +1 -0
  23. package/lib/commonjs/figma/Dialog.Description.figma.js +20 -0
  24. package/lib/commonjs/figma/Dialog.Description.figma.js.map +1 -0
  25. package/lib/commonjs/figma/Dialog.Footer.figma.js +30 -0
  26. package/lib/commonjs/figma/Dialog.Footer.figma.js.map +1 -0
  27. package/lib/commonjs/figma/Dialog.Header.figma.js +29 -0
  28. package/lib/commonjs/figma/Dialog.Header.figma.js.map +1 -0
  29. package/lib/commonjs/figma/Dialog.Text.figma.js +20 -0
  30. package/lib/commonjs/figma/Dialog.Text.figma.js.map +1 -0
  31. package/lib/commonjs/figma/Dialog.Title.figma.js +27 -0
  32. package/lib/commonjs/figma/Dialog.Title.figma.js.map +1 -0
  33. package/lib/commonjs/figma/Dialog.figma.js +51 -0
  34. package/lib/commonjs/figma/Dialog.figma.js.map +1 -0
  35. package/lib/commonjs/hooks/index.js +19 -0
  36. package/lib/commonjs/hooks/index.js.map +1 -0
  37. package/lib/commonjs/hooks/useForgeBottomTabScreenOptions.js +246 -0
  38. package/lib/commonjs/hooks/useForgeBottomTabScreenOptions.js.map +1 -0
  39. package/lib/commonjs/index.js +24 -0
  40. package/lib/commonjs/index.js.map +1 -1
  41. package/lib/commonjs/navigation/forgeTabIcon.js +43 -0
  42. package/lib/commonjs/navigation/forgeTabIcon.js.map +1 -0
  43. package/lib/commonjs/navigation/forgeTabIcon.native.js +35 -0
  44. package/lib/commonjs/navigation/forgeTabIcon.native.js.map +1 -0
  45. package/lib/commonjs/navigation/index.js +13 -0
  46. package/lib/commonjs/navigation/index.js.map +1 -0
  47. package/lib/commonjs/navigation/types.js +40 -0
  48. package/lib/commonjs/navigation/types.js.map +1 -0
  49. package/lib/module/components/AlertDialog/index.js +4 -3
  50. package/lib/module/components/AlertDialog/index.js.map +1 -1
  51. package/lib/module/components/Button/index.js +4 -0
  52. package/lib/module/components/Button/index.js.map +1 -1
  53. package/lib/module/components/Button/styles.js +59 -0
  54. package/lib/module/components/Button/styles.js.map +1 -1
  55. package/lib/module/components/Dialog/index.js +74 -19
  56. package/lib/module/components/Dialog/index.js.map +1 -1
  57. package/lib/module/components/Dialog/styles.js +60 -14
  58. package/lib/module/components/Dialog/styles.js.map +1 -1
  59. package/lib/module/figma/AlertDialog.Description.figma.js +14 -0
  60. package/lib/module/figma/AlertDialog.Description.figma.js.map +1 -0
  61. package/lib/module/figma/AlertDialog.Footer.figma.js +35 -0
  62. package/lib/module/figma/AlertDialog.Footer.figma.js.map +1 -0
  63. package/lib/module/figma/AlertDialog.Header.figma.js +22 -0
  64. package/lib/module/figma/AlertDialog.Header.figma.js.map +1 -0
  65. package/lib/module/figma/AlertDialog.Text.figma.js +14 -0
  66. package/lib/module/figma/AlertDialog.Text.figma.js.map +1 -0
  67. package/lib/module/figma/AlertDialog.Title.figma.js +21 -0
  68. package/lib/module/figma/AlertDialog.Title.figma.js.map +1 -0
  69. package/lib/module/figma/AlertDialog.figma.js +37 -0
  70. package/lib/module/figma/AlertDialog.figma.js.map +1 -0
  71. package/lib/module/figma/Dialog.Description.figma.js +14 -0
  72. package/lib/module/figma/Dialog.Description.figma.js.map +1 -0
  73. package/lib/module/figma/Dialog.Footer.figma.js +24 -0
  74. package/lib/module/figma/Dialog.Footer.figma.js.map +1 -0
  75. package/lib/module/figma/Dialog.Header.figma.js +23 -0
  76. package/lib/module/figma/Dialog.Header.figma.js.map +1 -0
  77. package/lib/module/figma/Dialog.Text.figma.js +14 -0
  78. package/lib/module/figma/Dialog.Text.figma.js.map +1 -0
  79. package/lib/module/figma/Dialog.Title.figma.js +21 -0
  80. package/lib/module/figma/Dialog.Title.figma.js.map +1 -0
  81. package/lib/module/figma/Dialog.figma.js +45 -0
  82. package/lib/module/figma/Dialog.figma.js.map +1 -0
  83. package/lib/module/hooks/index.js +4 -0
  84. package/lib/module/hooks/index.js.map +1 -0
  85. package/lib/module/hooks/useForgeBottomTabScreenOptions.js +242 -0
  86. package/lib/module/hooks/useForgeBottomTabScreenOptions.js.map +1 -0
  87. package/lib/module/index.js +2 -0
  88. package/lib/module/index.js.map +1 -1
  89. package/lib/module/navigation/forgeTabIcon.js +39 -0
  90. package/lib/module/navigation/forgeTabIcon.js.map +1 -0
  91. package/lib/module/navigation/forgeTabIcon.native.js +31 -0
  92. package/lib/module/navigation/forgeTabIcon.native.js.map +1 -0
  93. package/lib/module/navigation/index.js +4 -0
  94. package/lib/module/navigation/index.js.map +1 -0
  95. package/lib/module/navigation/types.js +38 -0
  96. package/lib/module/navigation/types.js.map +1 -0
  97. package/lib/typescript/components/AlertDialog/index.d.ts +3 -2
  98. package/lib/typescript/components/AlertDialog/index.d.ts.map +1 -1
  99. package/lib/typescript/components/Avatar/styles.d.ts +4 -4
  100. package/lib/typescript/components/Button/styles.d.ts +2 -0
  101. package/lib/typescript/components/Button/styles.d.ts.map +1 -1
  102. package/lib/typescript/components/Dialog/index.d.ts +16 -10
  103. package/lib/typescript/components/Dialog/index.d.ts.map +1 -1
  104. package/lib/typescript/components/Dialog/styles.d.ts +16 -5
  105. package/lib/typescript/components/Dialog/styles.d.ts.map +1 -1
  106. package/lib/typescript/components/Heading/styles.d.ts +1 -1
  107. package/lib/typescript/components/Stack/styles.d.ts +2 -2
  108. package/lib/typescript/components/Text/styles.d.ts +1 -1
  109. package/lib/typescript/figma/AlertDialog.Description.figma.d.ts +8 -0
  110. package/lib/typescript/figma/AlertDialog.Description.figma.d.ts.map +1 -0
  111. package/lib/typescript/figma/AlertDialog.Footer.figma.d.ts +8 -0
  112. package/lib/typescript/figma/AlertDialog.Footer.figma.d.ts.map +1 -0
  113. package/lib/typescript/figma/AlertDialog.Header.figma.d.ts +8 -0
  114. package/lib/typescript/figma/AlertDialog.Header.figma.d.ts.map +1 -0
  115. package/lib/typescript/figma/AlertDialog.Text.figma.d.ts +8 -0
  116. package/lib/typescript/figma/AlertDialog.Text.figma.d.ts.map +1 -0
  117. package/lib/typescript/figma/AlertDialog.Title.figma.d.ts +8 -0
  118. package/lib/typescript/figma/AlertDialog.Title.figma.d.ts.map +1 -0
  119. package/lib/typescript/figma/AlertDialog.figma.d.ts +8 -0
  120. package/lib/typescript/figma/AlertDialog.figma.d.ts.map +1 -0
  121. package/lib/typescript/figma/Dialog.Description.figma.d.ts +8 -0
  122. package/lib/typescript/figma/Dialog.Description.figma.d.ts.map +1 -0
  123. package/lib/typescript/figma/Dialog.Footer.figma.d.ts +8 -0
  124. package/lib/typescript/figma/Dialog.Footer.figma.d.ts.map +1 -0
  125. package/lib/typescript/figma/Dialog.Header.figma.d.ts +8 -0
  126. package/lib/typescript/figma/Dialog.Header.figma.d.ts.map +1 -0
  127. package/lib/typescript/figma/Dialog.Text.figma.d.ts +8 -0
  128. package/lib/typescript/figma/Dialog.Text.figma.d.ts.map +1 -0
  129. package/lib/typescript/figma/Dialog.Title.figma.d.ts +8 -0
  130. package/lib/typescript/figma/Dialog.Title.figma.d.ts.map +1 -0
  131. package/lib/typescript/figma/Dialog.figma.d.ts +8 -0
  132. package/lib/typescript/figma/Dialog.figma.d.ts.map +1 -0
  133. package/lib/typescript/hooks/index.d.ts +2 -0
  134. package/lib/typescript/hooks/index.d.ts.map +1 -0
  135. package/lib/typescript/hooks/useForgeBottomTabScreenOptions.d.ts +137 -0
  136. package/lib/typescript/hooks/useForgeBottomTabScreenOptions.d.ts.map +1 -0
  137. package/lib/typescript/index.d.ts +2 -0
  138. package/lib/typescript/index.d.ts.map +1 -1
  139. package/lib/typescript/navigation/forgeTabIcon.d.ts +27 -0
  140. package/lib/typescript/navigation/forgeTabIcon.d.ts.map +1 -0
  141. package/lib/typescript/navigation/forgeTabIcon.native.d.ts +15 -0
  142. package/lib/typescript/navigation/forgeTabIcon.native.d.ts.map +1 -0
  143. package/lib/typescript/navigation/index.d.ts +4 -0
  144. package/lib/typescript/navigation/index.d.ts.map +1 -0
  145. package/lib/typescript/navigation/types.d.ts +37 -0
  146. package/lib/typescript/navigation/types.d.ts.map +1 -0
  147. package/package.json +6 -4
  148. package/src/components/AlertDialog/index.tsx +7 -5
  149. package/src/components/Button/index.tsx +2 -2
  150. package/src/components/Button/styles.ts +29 -0
  151. package/src/components/Dialog/index.tsx +95 -29
  152. package/src/components/Dialog/styles.ts +72 -30
  153. package/src/hooks/index.ts +5 -0
  154. package/src/hooks/useForgeBottomTabScreenOptions.ts +245 -0
  155. package/src/index.ts +2 -0
  156. package/src/navigation/forgeTabIcon.native.ts +36 -0
  157. package/src/navigation/forgeTabIcon.ts +33 -0
  158. package/src/navigation/index.ts +3 -0
  159. package/src/navigation/types.ts +55 -0
@@ -0,0 +1,245 @@
1
+ /**
2
+ * useForgeBottomTabScreenOptions
3
+ *
4
+ * Returns a `screenOptions` object for **React Navigation bottom tab navigators**
5
+ * (`@react-navigation/bottom-tabs` v7+), populated with CDX UI design-system
6
+ * token values.
7
+ *
8
+ * CDX UI does not import `@react-navigation` — the consumer passes the returned
9
+ * object to their own navigator. This keeps the dependency out of
10
+ * `@cdx-ui/components` and works with any React Navigation tab variant:
11
+ * `createNativeBottomTabNavigator` (iOS/Android) or `createBottomTabNavigator`
12
+ * (web/JS).
13
+ *
14
+ * **Not compatible with:**
15
+ * - Expo Router `<NativeTabs>` — uses different prop names
16
+ * - React Router or DOM tab components — these are not React Navigation
17
+ *
18
+ * ## Basic usage
19
+ *
20
+ * ```tsx
21
+ * import { useForgeBottomTabScreenOptions } from '@cdx-ui/components';
22
+ * import { createNativeBottomTabNavigator } from '@react-navigation/bottom-tabs/unstable';
23
+ *
24
+ * const Tab = createNativeBottomTabNavigator<AppTabs>();
25
+ *
26
+ * function AppTabs() {
27
+ * const screenOptions = useForgeBottomTabScreenOptions();
28
+ * return (
29
+ * <Tab.Navigator screenOptions={screenOptions}>
30
+ * <Tab.Screen name="Home" component={HomeScreen} />
31
+ * </Tab.Navigator>
32
+ * );
33
+ * }
34
+ * ```
35
+ *
36
+ * ## Overriding individual tokens
37
+ *
38
+ * Spread the returned object and override only the keys you need.
39
+ * Nested style objects (`tabBarLabelStyle`, `tabBarStyle`, `tabBarBadgeStyle`)
40
+ * must be spread individually to preserve unrelated DS defaults:
41
+ *
42
+ * ```tsx
43
+ * const dsOptions = useForgeBottomTabScreenOptions();
44
+ * const screenOptions = {
45
+ * ...dsOptions,
46
+ * tabBarActiveTintColor: '#custom',
47
+ * tabBarLabelStyle: { ...dsOptions.tabBarLabelStyle, fontFamily: 'MyFont' },
48
+ * };
49
+ * ```
50
+ *
51
+ * ## Token variable names
52
+ *
53
+ * | screenOption | CSS variable |
54
+ * | ---------------------------------- | ---------------------------------- |
55
+ * | tabBarActiveTintColor | --color-content-action |
56
+ * | tabBarInactiveTintColor | --color-content-secondary |
57
+ * | tabBarStyle.backgroundColor | --color-surface-primary |
58
+ * | tabBarLabelStyle.fontFamily | --font-body |
59
+ * | tabBarLabelStyle.fontSize | --text-xs (via `text-xs` class) |
60
+ * | tabBarLabelStyle.fontWeight | --font-weight-medium |
61
+ * | tabBarBadgeStyle.backgroundColor | --color-surface-danger-strong |
62
+ *
63
+ * ## Platform notes
64
+ *
65
+ * - `tabBarInactiveTintColor` has no effect on iOS — inactive items always use
66
+ * system grey.
67
+ * - `tabBarStyle.backgroundColor` is ignored on iOS 26+ (liquid glass takes
68
+ * over). It is honoured on iOS ≤18 and all Android versions.
69
+ * - The hook resolves CSS variables via Uniwind's `useCSSVariable`. If the
70
+ * Uniwind runtime is not set up (e.g. in a plain Jest test without a CSS
71
+ * context), each variable resolves to `undefined` and the hardcoded fallback
72
+ * is used instead — fallbacks intentionally match the CDX UI light-theme
73
+ * values.
74
+ * - `tabBarLabelStyle.fontSize` is resolved via Uniwind's
75
+ * `useResolveClassNames('text-xs')` rather than reading the rem-valued
76
+ * `--text-xs` variable directly. React Navigation v7 requires a numeric
77
+ * `fontSize`, and letting Uniwind resolve the class means the rem→px
78
+ * conversion uses the consumer's configured rem base (default 16px,
79
+ * overridable via the `polyfills.rem` Metro option) instead of a constant
80
+ * hardcoded here.
81
+ */
82
+ import type { TextStyle } from 'react-native';
83
+ import { useCSSVariable, useResolveClassNames } from 'uniwind';
84
+ import type { BottomTabNavigationOptions } from '@react-navigation/bottom-tabs';
85
+
86
+ // ── Types ────────────────────────────────────────────────────────────────────
87
+
88
+ /**
89
+ * The `screenOptions` shape returned by `useForgeBottomTabScreenOptions`.
90
+ *
91
+ * These are concrete types (not the broad `StyleProp<…>` React Navigation
92
+ * uses internally) so consumers get precise IDE completion. The compile-time
93
+ * drift guard below ensures this type stays assignable to
94
+ * `BottomTabNavigationOptions` — the TypeScript compiler will error if CDX UI
95
+ * adds a key or value that React Navigation no longer accepts.
96
+ *
97
+ * Pass directly as `screenOptions` on a `createNativeBottomTabNavigator` or
98
+ * `createBottomTabNavigator` navigator, or spread and override individual keys.
99
+ */
100
+ export interface ForgeReactNavigationBottomTabScreenOptions {
101
+ tabBarActiveTintColor: string;
102
+ tabBarInactiveTintColor: string;
103
+ tabBarStyle: { backgroundColor: string };
104
+ tabBarLabelStyle: {
105
+ fontFamily: string;
106
+ /** Pixel size — React Navigation requires a number for tab label fontSize. */
107
+ fontSize: number;
108
+ fontWeight: TextStyle['fontWeight'];
109
+ };
110
+ tabBarBadgeStyle: { backgroundColor: string };
111
+ }
112
+
113
+ /**
114
+ * Compile-time drift guard.
115
+ *
116
+ * `ForgeReactNavigationBottomTabScreenOptions` must be assignable to
117
+ * `BottomTabNavigationOptions`. TypeScript checks this assignment at build
118
+ * time — if React Navigation removes or incompatibly narrows one of our keys,
119
+ * this line becomes a type error before it reaches consumers.
120
+ *
121
+ * The `null as unknown as ...` cast keeps the runtime value `null` so tree-
122
+ * shakers eliminate the variable from the final bundle entirely.
123
+ */
124
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
125
+ const _rnDriftGuard: BottomTabNavigationOptions =
126
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127
+ null as any as ForgeReactNavigationBottomTabScreenOptions;
128
+
129
+ // ── Fallbacks ────────────────────────────────────────────────────────────────
130
+ //
131
+ // Resolved light-theme values for each token. Used when useCSSVariable returns
132
+ // undefined (no Uniwind CSS context in scope, e.g. Jest).
133
+
134
+ const FALLBACKS = {
135
+ activeTintColor: '#346099', // --color-brand-700 (--color-content-action)
136
+ inactiveTintColor: '#4a4c4f', // --color-base-800 (--color-content-secondary)
137
+ fontFamily: 'Inter', // --font-sans (--font-body)
138
+ fontSize: 12, // px (--text-xs)
139
+ fontWeight: '500' as TextStyle['fontWeight'], // (--font-weight-medium)
140
+ backgroundColor: '#ffffff', // --color-white (--color-surface-primary)
141
+ badgeBackgroundColor: '#c10007', // --color-red-700 (--color-surface-danger-strong)
142
+ } as const;
143
+
144
+ /**
145
+ * Coerces a Uniwind-resolved `fontSize` to a finite pixel number, falling
146
+ * back when the style could not be resolved (e.g. no Uniwind runtime in Jest).
147
+ *
148
+ * `useResolveClassNames('text-xs')` performs the rem→px conversion using
149
+ * Uniwind's configured rem base, so the value is already numeric on native.
150
+ * React Native Web may surface string values; unit-less and `px` strings are
151
+ * accepted, but anything else (`rem`, `em`, `%`) falls back rather than
152
+ * guessing a rem base here.
153
+ */
154
+ function toPx(value: string | number | undefined, fallbackPx: number): number {
155
+ if (typeof value === 'number') {
156
+ return Number.isFinite(value) ? value : fallbackPx;
157
+ }
158
+ if (typeof value !== 'string') return fallbackPx;
159
+ const trimmed = value.trim();
160
+ if (!/^-?\d*\.?\d+(px)?$/.test(trimmed)) return fallbackPx;
161
+ return parseFloat(trimmed);
162
+ }
163
+
164
+ /**
165
+ * Coerces a Uniwind `useCSSVariable` fontWeight value to a string.
166
+ *
167
+ * `--font-weight-*` variables are emitted as unit-less numbers (e.g. `500`),
168
+ * and `useCSSVariable` may return them as numbers. React Native's `TextStyle`
169
+ * accepts numeric fontWeight, but react-native-screens' native bottom tabs
170
+ * declare the corresponding host prop (`tabBarItemTitleFontWeight`) as a
171
+ * String — passing a number crashes Android Fabric with
172
+ * "java.lang.Double cannot be cast to java.lang.String".
173
+ */
174
+ function toFontWeight(
175
+ value: string | number | undefined,
176
+ fallback: TextStyle['fontWeight'],
177
+ ): TextStyle['fontWeight'] {
178
+ if (value === undefined) return fallback;
179
+ return String(value) as TextStyle['fontWeight'];
180
+ }
181
+
182
+ // ── Hook ─────────────────────────────────────────────────────────────────────
183
+
184
+ /**
185
+ * Returns a `screenOptions` object for **React Navigation bottom tab
186
+ * navigators** (`@react-navigation/bottom-tabs` v7+), populated with CDX UI
187
+ * design-system token values.
188
+ *
189
+ * Must be called inside a React component or custom hook (React hook rules
190
+ * apply).
191
+ */
192
+ /**
193
+ * Deep-merges consumer overrides into a base `ForgeReactNavigationBottomTabScreenOptions`
194
+ * object. Nested style objects (`tabBarLabelStyle`, `tabBarStyle`,
195
+ * `tabBarBadgeStyle`) are merged property-by-property so consumers can override
196
+ * individual style properties without losing unrelated DS defaults.
197
+ *
198
+ * Use with `useForgeBottomTabScreenOptions` to apply targeted overrides:
199
+ *
200
+ * ```tsx
201
+ * const dsOptions = useForgeBottomTabScreenOptions();
202
+ * const screenOptions = mergeForgeBottomTabScreenOptions(dsOptions, {
203
+ * tabBarActiveTintColor: '#custom',
204
+ * tabBarLabelStyle: { fontFamily: 'MyFont' }, // fontSize + fontWeight preserved
205
+ * });
206
+ * ```
207
+ */
208
+ export function mergeForgeBottomTabScreenOptions(
209
+ base: ForgeReactNavigationBottomTabScreenOptions,
210
+ overrides: Partial<ForgeReactNavigationBottomTabScreenOptions>,
211
+ ): ForgeReactNavigationBottomTabScreenOptions {
212
+ return {
213
+ ...base,
214
+ ...overrides,
215
+ tabBarLabelStyle: { ...base.tabBarLabelStyle, ...overrides.tabBarLabelStyle },
216
+ tabBarStyle: { ...base.tabBarStyle, ...overrides.tabBarStyle },
217
+ tabBarBadgeStyle: { ...base.tabBarBadgeStyle, ...overrides.tabBarBadgeStyle },
218
+ };
219
+ }
220
+
221
+ export function useForgeBottomTabScreenOptions(): ForgeReactNavigationBottomTabScreenOptions {
222
+ const activeTintColor = useCSSVariable('--color-content-action');
223
+ const inactiveTintColor = useCSSVariable('--color-content-secondary');
224
+ const fontFamily = useCSSVariable('--font-body');
225
+ const labelTextStyle = useResolveClassNames('text-xs');
226
+ const fontWeight = useCSSVariable('--font-weight-medium');
227
+ const backgroundColor = useCSSVariable('--color-surface-primary');
228
+ const badgeBackgroundColor = useCSSVariable('--color-surface-danger-strong');
229
+
230
+ return {
231
+ tabBarActiveTintColor: String(activeTintColor ?? FALLBACKS.activeTintColor),
232
+ tabBarInactiveTintColor: String(inactiveTintColor ?? FALLBACKS.inactiveTintColor),
233
+ tabBarStyle: {
234
+ backgroundColor: String(backgroundColor ?? FALLBACKS.backgroundColor),
235
+ },
236
+ tabBarLabelStyle: {
237
+ fontFamily: String(fontFamily ?? FALLBACKS.fontFamily),
238
+ fontSize: toPx(labelTextStyle?.fontSize, FALLBACKS.fontSize),
239
+ fontWeight: toFontWeight(fontWeight, FALLBACKS.fontWeight),
240
+ },
241
+ tabBarBadgeStyle: {
242
+ backgroundColor: String(badgeBackgroundColor ?? FALLBACKS.badgeBackgroundColor),
243
+ },
244
+ };
245
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  /// <reference types="uniwind/types" preserve="true" />
2
2
  export * from './components';
3
+ export * from './hooks';
4
+ export * from './navigation';
3
5
  export { View, ScrollView, KeyboardAvoidingView } from 'react-native';
4
6
  export { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context';
@@ -0,0 +1,36 @@
1
+ import type { ForgeTabIcon } from '@cdx-ui/icons/tab-icons';
2
+ import type { ForgeNativeBottomTabIcon, ForgeTabBarIcon } from './types';
3
+
4
+ /**
5
+ * forgeTabIcon — iOS/Android implementation (see `forgeTabIcon.ts` for the
6
+ * full contract and usage example).
7
+ *
8
+ * Returns a `tabBarIcon` function for `createNativeBottomTabNavigator` that
9
+ * resolves the descriptor's pre-rasterized template PNGs: outlined at rest,
10
+ * filled when focused (iOS only — Android tabs use one static icon and
11
+ * express selection via tint). `tinted: true` makes the native tab bar apply
12
+ * `tabBarActiveTintColor` / `tabBarInactiveTintColor` at runtime, so theming
13
+ * and dark mode flow through `useForgeBottomTabScreenOptions` unchanged.
14
+ */
15
+ export function forgeTabIcon(icon: ForgeTabIcon): ForgeTabBarIcon {
16
+ const { native } = icon;
17
+
18
+ if (!native) {
19
+ const name = icon.Component.displayName ?? 'icon';
20
+ throw new Error(
21
+ `forgeTabIcon: "${name}" has no native tab assets. Use a generated ` +
22
+ `descriptor from '@cdx-ui/icons/tab-icons' (curated in the icon ` +
23
+ `package's tab-icons.config.json), or pass a descriptor with your ` +
24
+ `own template PNGs: { native: { outlined: require(...), filled: ` +
25
+ `require(...) } } at a 24dp base size with @2x/@3x variants.`,
26
+ );
27
+ }
28
+
29
+ const resolve = ({ focused }: { focused: boolean }): ForgeNativeBottomTabIcon => ({
30
+ type: 'image',
31
+ source: focused ? native.filled : native.outlined,
32
+ tinted: true,
33
+ });
34
+
35
+ return resolve as ForgeTabBarIcon;
36
+ }
@@ -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;