@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,137 @@
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
+ /**
84
+ * The `screenOptions` shape returned by `useForgeBottomTabScreenOptions`.
85
+ *
86
+ * These are concrete types (not the broad `StyleProp<…>` React Navigation
87
+ * uses internally) so consumers get precise IDE completion. The compile-time
88
+ * drift guard below ensures this type stays assignable to
89
+ * `BottomTabNavigationOptions` — the TypeScript compiler will error if CDX UI
90
+ * adds a key or value that React Navigation no longer accepts.
91
+ *
92
+ * Pass directly as `screenOptions` on a `createNativeBottomTabNavigator` or
93
+ * `createBottomTabNavigator` navigator, or spread and override individual keys.
94
+ */
95
+ export interface ForgeReactNavigationBottomTabScreenOptions {
96
+ tabBarActiveTintColor: string;
97
+ tabBarInactiveTintColor: string;
98
+ tabBarStyle: {
99
+ backgroundColor: string;
100
+ };
101
+ tabBarLabelStyle: {
102
+ fontFamily: string;
103
+ /** Pixel size — React Navigation requires a number for tab label fontSize. */
104
+ fontSize: number;
105
+ fontWeight: TextStyle['fontWeight'];
106
+ };
107
+ tabBarBadgeStyle: {
108
+ backgroundColor: string;
109
+ };
110
+ }
111
+ /**
112
+ * Returns a `screenOptions` object for **React Navigation bottom tab
113
+ * navigators** (`@react-navigation/bottom-tabs` v7+), populated with CDX UI
114
+ * design-system token values.
115
+ *
116
+ * Must be called inside a React component or custom hook (React hook rules
117
+ * apply).
118
+ */
119
+ /**
120
+ * Deep-merges consumer overrides into a base `ForgeReactNavigationBottomTabScreenOptions`
121
+ * object. Nested style objects (`tabBarLabelStyle`, `tabBarStyle`,
122
+ * `tabBarBadgeStyle`) are merged property-by-property so consumers can override
123
+ * individual style properties without losing unrelated DS defaults.
124
+ *
125
+ * Use with `useForgeBottomTabScreenOptions` to apply targeted overrides:
126
+ *
127
+ * ```tsx
128
+ * const dsOptions = useForgeBottomTabScreenOptions();
129
+ * const screenOptions = mergeForgeBottomTabScreenOptions(dsOptions, {
130
+ * tabBarActiveTintColor: '#custom',
131
+ * tabBarLabelStyle: { fontFamily: 'MyFont' }, // fontSize + fontWeight preserved
132
+ * });
133
+ * ```
134
+ */
135
+ export declare function mergeForgeBottomTabScreenOptions(base: ForgeReactNavigationBottomTabScreenOptions, overrides: Partial<ForgeReactNavigationBottomTabScreenOptions>): ForgeReactNavigationBottomTabScreenOptions;
136
+ export declare function useForgeBottomTabScreenOptions(): ForgeReactNavigationBottomTabScreenOptions;
137
+ //# sourceMappingURL=useForgeBottomTabScreenOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForgeBottomTabScreenOptions.d.ts","sourceRoot":"","sources":["../../../src/hooks/useForgeBottomTabScreenOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAM9C;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,0CAA0C;IACzD,qBAAqB,EAAE,MAAM,CAAC;IAC9B,uBAAuB,EAAE,MAAM,CAAC;IAChC,WAAW,EAAE;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,gBAAgB,EAAE;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,8EAA8E;QAC9E,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;KACrC,CAAC;IACF,gBAAgB,EAAE;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAyED;;;;;;;GAOG;AACH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,0CAA0C,EAChD,SAAS,EAAE,OAAO,CAAC,0CAA0C,CAAC,GAC7D,0CAA0C,CAQ5C;AAED,wBAAgB,8BAA8B,IAAI,0CAA0C,CAwB3F"}
@@ -1,5 +1,7 @@
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';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { ForgeTabIcon } from '@cdx-ui/icons/tab-icons';
2
+ import type { ForgeTabBarIcon } from './types';
3
+ /**
4
+ * forgeTabIcon — web/JS-navigator implementation.
5
+ *
6
+ * Maps a {@link ForgeTabIcon} descriptor to a React Navigation `tabBarIcon`
7
+ * value that renders the same Forge UI icon on every platform:
8
+ *
9
+ * - **Web** (`createBottomTabNavigator`): renders the SVG icon component with
10
+ * `filled={focused}` and the navigator-supplied `color`/`size` — pair with
11
+ * `useForgeBottomTabScreenOptions` so tints come from design tokens.
12
+ * - **iOS/Android** (`createNativeBottomTabNavigator`): the `.native` module
13
+ * of this file returns a tinted template-image descriptor instead.
14
+ *
15
+ * ```tsx
16
+ * import { useForgeBottomTabScreenOptions, forgeTabIcon } from '@cdx-ui/components';
17
+ * import { HomeTabIcon } from '@cdx-ui/icons/tab-icons';
18
+ *
19
+ * <Tab.Screen
20
+ * name="Home"
21
+ * component={HomeScreen}
22
+ * options={{ title: 'Home', tabBarIcon: forgeTabIcon(HomeTabIcon) }}
23
+ * />
24
+ * ```
25
+ */
26
+ export declare function forgeTabIcon(icon: ForgeTabIcon): ForgeTabBarIcon;
27
+ //# sourceMappingURL=forgeTabIcon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forgeTabIcon.d.ts","sourceRoot":"","sources":["../../../src/navigation/forgeTabIcon.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,eAAe,CAKhE"}
@@ -0,0 +1,15 @@
1
+ import type { ForgeTabIcon } from '@cdx-ui/icons/tab-icons';
2
+ import type { ForgeTabBarIcon } from './types';
3
+ /**
4
+ * forgeTabIcon — iOS/Android implementation (see `forgeTabIcon.ts` for the
5
+ * full contract and usage example).
6
+ *
7
+ * Returns a `tabBarIcon` function for `createNativeBottomTabNavigator` that
8
+ * resolves the descriptor's pre-rasterized template PNGs: outlined at rest,
9
+ * filled when focused (iOS only — Android tabs use one static icon and
10
+ * express selection via tint). `tinted: true` makes the native tab bar apply
11
+ * `tabBarActiveTintColor` / `tabBarInactiveTintColor` at runtime, so theming
12
+ * and dark mode flow through `useForgeBottomTabScreenOptions` unchanged.
13
+ */
14
+ export declare function forgeTabIcon(icon: ForgeTabIcon): ForgeTabBarIcon;
15
+ //# sourceMappingURL=forgeTabIcon.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forgeTabIcon.native.d.ts","sourceRoot":"","sources":["../../../src/navigation/forgeTabIcon.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAA4B,eAAe,EAAE,MAAM,SAAS,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,eAAe,CAqBhE"}
@@ -0,0 +1,4 @@
1
+ export { forgeTabIcon } from './forgeTabIcon';
2
+ export type { ForgeNativeBottomTabIcon, ForgeTabBarIcon } from './types';
3
+ export type { ForgeTabIcon, ForgeTabIconNativeSources } from '@cdx-ui/icons/tab-icons';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/navigation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACzE,YAAY,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { ImageSourcePropType } from 'react-native';
3
+ /**
4
+ * Structural mirror of the `image` arm of `NativeBottomTabIcon` from
5
+ * `@react-navigation/bottom-tabs/unstable`. Declared locally so
6
+ * `@cdx-ui/components` carries no runtime React Navigation dependency —
7
+ * the drift guards below fail the build if the upstream shape changes.
8
+ */
9
+ export interface ForgeNativeBottomTabIcon {
10
+ type: 'image';
11
+ /** Metro-resolved asset (e.g. a static `require('./icon.png')`). */
12
+ source: ImageSourcePropType;
13
+ /**
14
+ * Render as a template image tinted with the tab bar's active/inactive
15
+ * tint color. iOS-only flag — Android always tints tab icons.
16
+ */
17
+ tinted?: boolean;
18
+ }
19
+ /**
20
+ * The value `forgeTabIcon()` returns — callable as `tabBarIcon` on **both**
21
+ * React Navigation bottom tab navigators. The intersection carries both call
22
+ * signatures; the platform-split implementation guarantees the matching one
23
+ * at runtime:
24
+ *
25
+ * - `createBottomTabNavigator` (web/JS) invokes it with
26
+ * `{ focused, color, size }` and renders the returned element.
27
+ * - `createNativeBottomTabNavigator` (iOS/Android) invokes it with
28
+ * `{ focused }` and receives a native icon descriptor.
29
+ */
30
+ export type ForgeTabBarIcon = ((props: {
31
+ focused: boolean;
32
+ color: string;
33
+ size: number;
34
+ }) => ReactElement) & ((props: {
35
+ focused: boolean;
36
+ }) => ForgeNativeBottomTabIcon);
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/navigation/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAIxD;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,OAAO,CAAC;IACd,oEAAoE;IACpE,MAAM,EAAE,mBAAmB,CAAC;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,EAAE;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,KAAK,YAAY,CAAC,GACjB,CAAC,CAAC,KAAK,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,KAAK,wBAAwB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdx-ui/components",
3
- "version": "0.0.1-beta.50",
3
+ "version": "0.0.1-beta.51",
4
4
  "main": "lib/commonjs/index.js",
5
5
  "module": "lib/module/index.js",
6
6
  "react-native": "src/index.ts",
@@ -67,11 +67,13 @@
67
67
  "@gorhom/bottom-sheet": "^5.2.6",
68
68
  "class-variance-authority": "^0.7.1",
69
69
  "uniwind": "1.6.1",
70
- "@cdx-ui/primitives": "0.0.1-beta.50",
71
- "@cdx-ui/utils": "0.0.1-beta.50",
72
- "@cdx-ui/icons": "0.0.1-beta.50"
70
+ "@cdx-ui/primitives": "0.0.1-beta.51",
71
+ "@cdx-ui/utils": "0.0.1-beta.51",
72
+ "@cdx-ui/icons": "0.0.1-beta.51"
73
73
  },
74
74
  "devDependencies": {
75
+ "@react-navigation/bottom-tabs": "*",
76
+ "react-native-screens": "*",
75
77
  "@types/react": "*",
76
78
  "@types/react-dom": "*",
77
79
  "react": "*",
@@ -175,9 +175,9 @@ ButtonGroup.displayName = 'Button.Group';
175
175
  export interface ButtonIconProps extends Omit<IconProps, 'children'> {}
176
176
 
177
177
  const ButtonIcon = ({ className, style, as, ...props }: ButtonIconProps) => {
178
- const { size } = useButtonStyleContext();
178
+ const { variant, color, size } = useButtonStyleContext();
179
179
 
180
- const computedClassName = cn(buttonIconVariants({ size }), className);
180
+ const computedClassName = cn(buttonIconVariants({ variant, color, size }), className);
181
181
 
182
182
  return <Icon as={as} className={computedClassName} style={style} {...props} />;
183
183
  };
@@ -351,12 +351,41 @@ export const buttonGroupVariants = cva([], {
351
351
 
352
352
  export const buttonIconVariants = cva([], {
353
353
  variants: {
354
+ variant: {
355
+ solid: [],
356
+ outline: [],
357
+ ghost: [],
358
+ },
359
+ color: {
360
+ action: [],
361
+ danger: [],
362
+ warning: [],
363
+ success: [],
364
+ info: [],
365
+ },
354
366
  size: {
355
367
  default: 'size-5',
356
368
  small: 'size-4',
357
369
  },
358
370
  },
371
+ compoundVariants: [
372
+ // ── solid × color (filled foreground icon) ──────────────────────
373
+ { variant: 'solid', color: 'action', className: 'text-content-action-on-strong' },
374
+ { variant: 'solid', color: 'danger', className: 'text-content-danger-on-strong' },
375
+ { variant: 'solid', color: 'warning', className: 'text-content-warning-on-strong' },
376
+ { variant: 'solid', color: 'success', className: 'text-content-success-on-strong' },
377
+ { variant: 'solid', color: 'info', className: 'text-content-info-on-strong' },
378
+
379
+ // ── outline/ghost × color (transparent foreground icon) ──────────
380
+ { variant: ['outline', 'ghost'], color: 'action', className: 'text-content-action' },
381
+ { variant: ['outline', 'ghost'], color: 'danger', className: 'text-content-danger' },
382
+ { variant: ['outline', 'ghost'], color: 'warning', className: 'text-content-warning' },
383
+ { variant: ['outline', 'ghost'], color: 'success', className: 'text-content-success' },
384
+ { variant: ['outline', 'ghost'], color: 'info', className: 'text-content-info' },
385
+ ],
359
386
  defaultVariants: {
387
+ variant: 'solid',
388
+ color: 'action',
360
389
  size: 'default',
361
390
  },
362
391
  });
@@ -0,0 +1,5 @@
1
+ export {
2
+ useForgeBottomTabScreenOptions,
3
+ mergeForgeBottomTabScreenOptions,
4
+ type ForgeReactNavigationBottomTabScreenOptions,
5
+ } from './useForgeBottomTabScreenOptions';
@@ -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
+ }