@factorialco/f0-react-native 0.28.0 → 0.29.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.
Files changed (35) hide show
  1. package/README.md +42 -30
  2. package/lib/module/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.js +1 -1
  3. package/lib/module/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.js.map +1 -1
  4. package/lib/module/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.md +45 -8
  5. package/lib/module/components/primitives/F0Text/F0Text/F0Text.js +1 -1
  6. package/lib/module/components/primitives/F0Text/F0Text/F0Text.js.map +1 -1
  7. package/lib/module/components/primitives/F0Text/F0Text/F0Text.md +94 -38
  8. package/lib/module/components/primitives/F0Text/F0Text/F0Text.styles.js +1 -1
  9. package/lib/module/components/primitives/F0Text/F0Text/F0Text.styles.js.map +1 -1
  10. package/lib/module/components/primitives/F0Text/F0Text/F0Text.types.js +1 -1
  11. package/lib/module/components/primitives/F0Text/F0Text/F0Text.types.js.map +1 -1
  12. package/lib/module/lib/utils.js.map +1 -1
  13. package/lib/typescript/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.d.ts.map +1 -1
  14. package/lib/typescript/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.types.d.ts +14 -0
  15. package/lib/typescript/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.types.d.ts.map +1 -1
  16. package/lib/typescript/components/primitives/F0Text/F0Text/F0Text.d.ts.map +1 -1
  17. package/lib/typescript/components/primitives/F0Text/F0Text/F0Text.styles.d.ts +5 -4
  18. package/lib/typescript/components/primitives/F0Text/F0Text/F0Text.styles.d.ts.map +1 -1
  19. package/lib/typescript/components/primitives/F0Text/F0Text/F0Text.types.d.ts +22 -18
  20. package/lib/typescript/components/primitives/F0Text/F0Text/F0Text.types.d.ts.map +1 -1
  21. package/lib/typescript/lib/utils.d.ts +1 -2
  22. package/lib/typescript/lib/utils.d.ts.map +1 -1
  23. package/package.json +1 -1
  24. package/src/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.md +45 -8
  25. package/src/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.tsx +20 -8
  26. package/src/components/primitives/F0Text/AnimatedF0Text/AnimatedF0Text.types.ts +15 -0
  27. package/src/components/primitives/F0Text/AnimatedF0Text/__tests__/AnimatedF0Text.spec.tsx +220 -0
  28. package/src/components/primitives/F0Text/AnimatedF0Text/__tests__/__snapshots__/AnimatedF0Text.spec.tsx.snap +16 -16
  29. package/src/components/primitives/F0Text/F0Text/F0Text.md +94 -38
  30. package/src/components/primitives/F0Text/F0Text/F0Text.styles.ts +4 -3
  31. package/src/components/primitives/F0Text/F0Text/F0Text.tsx +17 -10
  32. package/src/components/primitives/F0Text/F0Text/F0Text.types.ts +22 -18
  33. package/src/components/primitives/F0Text/F0Text/__tests__/F0Text.spec.tsx +340 -16
  34. package/src/components/primitives/F0Text/F0Text/__tests__/__snapshots__/F0Text.spec.tsx.snap +36 -36
  35. package/src/lib/utils.ts +1 -2
@@ -40,18 +40,19 @@ import { F0Text } from "@factorialco/f0-react-native"
40
40
 
41
41
  ### Props
42
42
 
43
- | Prop | Type | Default | Description |
44
- | --------------- | ------------------- | ------------------- | ------------------------------------------------------- |
45
- | `variant` | `TypographyVariant` | `'body-sm-default'` | Typography variant with weight included |
46
- | `color` | `TextColor` | `'default'` | Text color from F0 semantic color system |
47
- | `align` | `TextAlign` | `'left'` | Text alignment (left, center, right, justify) |
48
- | `decoration` | `TextDecoration` | `'none'` | Text decoration (none, underline, line-through) |
49
- | `transform` | `TextTransform` | `'none'` | Text transform (none, uppercase, lowercase, capitalize) |
50
- | `numberOfLines` | `number` | `undefined` | Max lines before truncation with ellipsis |
43
+ | Prop | Type | Default | Description |
44
+ | --------------- | ------------------- | ------------------- | -------------------------------------------------------- |
45
+ | `variant` | `TypographyVariant` | `'body-sm-default'` | Typography variant with weight included |
46
+ | `color` | `TextColor` | `'default'` | Text color from F0 semantic color system |
47
+ | `align` | `TextAlign` | `'left'` | Text alignment (left, center, right, justify) |
48
+ | `decoration` | `TextDecoration` | `'none'` | Text decoration (none, underline, line-through) |
49
+ | `transform` | `TextTransform` | `'none'` | Text transform (none, uppercase, lowercase, capitalize) |
50
+ | `numberOfLines` | `number` | `undefined` | Max lines before truncation with ellipsis |
51
+ | `className` | `string` | `undefined` | Layout/positioning classes (margin, padding, flex, etc.) |
51
52
 
52
- All React Native `TextProps` are also supported (onPress, testID, etc.).
53
+ All React Native `TextProps` are also supported (onPress, testID, etc.), **except `style`** which is omitted from the type and filtered at runtime.
53
54
 
54
- **Note**: `className` and `style` props are **not available**. Use semantic props for typography. For spacing/layout, wrap F0Text in a View. Both props are filtered at runtime to prevent override via spread.
55
+ Typography is controlled exclusively by semantic props (variant, color, align, etc.) and always takes precedence any typography classes passed via `className` are automatically overridden by the semantic props via `twMerge`.
55
56
 
56
57
  ### Typography Variants
57
58
 
@@ -180,26 +181,33 @@ All variants use **Inter** font family with the weight included in the variant n
180
181
 
181
182
  ### Spacing & Layout
182
183
 
183
- F0Text doesn't accept `className` to prevent typography override. Use a View wrapper for spacing:
184
+ F0Text accepts `className` for layout and positioning. Typography classes in `className` are safely overridden by semantic props via `twMerge`:
184
185
 
185
186
  <!-- prettier-ignore -->
186
187
  ```tsx
187
188
  <>
188
- {/* Spacing with View wrapper */}
189
- <View className="mt-4 mb-2">
190
- <F0Text variant="body-sm-default">Text with margin</F0Text>
191
- </View>
189
+ {/* Spacing directly on the text */}
190
+ <F0Text variant="body-sm-default" className="mt-4 mb-2">
191
+ Text with margin
192
+ </F0Text>
192
193
 
193
- {/* Layout with View wrapper */}
194
- <View className="flex-1">
195
- <F0Text variant="body-sm-default">Flexible text</F0Text>
196
- </View>
194
+ {/* Layout directly on the text */}
195
+ <F0Text variant="body-sm-default" className="flex-1">
196
+ Flexible text
197
+ </F0Text>
197
198
 
198
199
  {/* Icon + Text pattern */}
199
200
  <View className="flex-row items-center gap-2">
200
201
  <F0Icon icon={Check} size="sm" />
201
- <F0Text variant="body-sm-default">Success message</F0Text>
202
+ <F0Text variant="body-sm-default" className="flex-1">
203
+ Success message
204
+ </F0Text>
202
205
  </View>
206
+
207
+ {/* Typography override attempts are safely ignored */}
208
+ <F0Text variant="body-sm-default" className="mt-4 font-bold text-red-500">
209
+ font-bold and text-red-500 are ignored; mt-4 is applied
210
+ </F0Text>
203
211
  </>
204
212
  ```
205
213
 
@@ -236,18 +244,16 @@ F0Text doesn't accept `className` to prevent typography override. Use a View wra
236
244
  <!-- prettier-ignore -->
237
245
  ```tsx
238
246
  <View className="rounded-lg bg-f0-background-secondary p-4">
239
- <View className="mb-2">
240
- <F0Text variant="heading-sm">Card Title</F0Text>
241
- </View>
247
+ <F0Text variant="heading-sm" className="mb-2">
248
+ Card Title
249
+ </F0Text>
242
250
  <F0Text variant="body-sm-default" color="secondary" numberOfLines={2}>
243
251
  This is a description that will be truncated after two lines if it's too
244
252
  long to fit in the available space.
245
253
  </F0Text>
246
- <View className="mt-2">
247
- <F0Text variant="body-xs-medium" color="tertiary">
248
- Last updated 2 hours ago
249
- </F0Text>
250
- </View>
254
+ <F0Text variant="body-xs-medium" color="tertiary" className="mt-2">
255
+ Last updated 2 hours ago
256
+ </F0Text>
251
257
  </View>
252
258
  ```
253
259
 
@@ -277,14 +283,59 @@ F0Text/ # Parent folder for text primitives
277
283
 
278
284
  ### Font Family
279
285
 
280
- F0Text uses **Inter** font family through Tailwind/Uniwind font weight classes:
286
+ F0Text uses the **Inter** font family through Tailwind/Uniwind `font-*` utility classes,
287
+ which map to `--font-*` CSS variables defined in the app's `@theme`:
288
+
289
+ | Tailwind Class | CSS Variable | Font Name | Font Weight |
290
+ | --------------- | ----------------- | -------------- | ----------- |
291
+ | `font-normal` | `--font-normal` | Inter-Regular | 400 |
292
+ | `font-medium` | `--font-medium` | Inter-Medium | 500 |
293
+ | `font-semibold` | `--font-semibold` | Inter-SemiBold | 600 |
294
+ | `font-bold` | `--font-bold` | Inter-Bold | 700 |
295
+
296
+ #### Host App Font Setup
297
+
298
+ The consuming app must embed the Inter `.ttf` files and wire them up for both
299
+ iOS and Android. See the [README "Add Inter Fonts"](../../../../../README.md#5️⃣-add-inter-fonts-host-app) section for the full
300
+ step-by-step guide. The short version:
301
+
302
+ 1. **Name font files to match their PostScript name** (e.g. `Inter-Regular.ttf`
303
+ for PostScript name `Inter-Regular`). iOS resolves fonts by PostScript name,
304
+ Android by asset file name — matching them avoids platform-specific overrides.
305
+
306
+ 2. **Register via `expo-font`** config plugin in `app.json`:
307
+
308
+ ```json
309
+ [
310
+ "expo-font",
311
+ {
312
+ "fonts": [
313
+ "./assets/fonts/Inter/Inter-Regular.ttf",
314
+ "./assets/fonts/Inter/Inter-Medium.ttf",
315
+ "./assets/fonts/Inter/Inter-SemiBold.ttf",
316
+ "./assets/fonts/Inter/Inter-Bold.ttf"
317
+ ]
318
+ }
319
+ ]
320
+ ```
281
321
 
282
- | Tailwind Class | React Native Font Family | Font Weight |
283
- | --------------- | ------------------------ | ----------- |
284
- | `font-normal` | Inter-Regular | 400 |
285
- | `font-medium` | Inter-Medium | 500 |
286
- | `font-semibold` | Inter-SemiBold | 600 |
287
- | `font-bold` | Inter-Bold | 700 |
322
+ 3. **Define `@theme` variables** in `global.css`:
323
+
324
+ ```css
325
+ @theme {
326
+ --font-normal: "Inter-Regular";
327
+ --font-medium: "Inter-Medium";
328
+ --font-semibold: "Inter-SemiBold";
329
+ --font-bold: "Inter-Bold";
330
+ }
331
+ ```
332
+
333
+ The `@theme` values must match the file names (without `.ttf`). Uniwind maps
334
+ `font-normal`, `font-medium`, `font-semibold`, and `font-bold` utility classes
335
+ to these variables.
336
+
337
+ > **Rebuild required:** Font changes are picked up at native build time.
338
+ > Run `npx expo prebuild --clean` after adding or renaming font files.
288
339
 
289
340
  ## Accessibility
290
341
 
@@ -302,11 +353,16 @@ F0Text uses **Inter** font family through Tailwind/Uniwind font weight classes:
302
353
 
303
354
  <!-- prettier-ignore -->
304
355
  ```tsx
305
- // ✅ Good: Use appropriate variant
356
+ // ✅ Good: Use semantic props for typography
306
357
  <F0Text variant="body-md-semibold">Bold text</F0Text>
307
358
 
308
- // Bad: Don't try to override with className (not supported)
309
- // <F0Text className="font-bold">Text</F0Text>
359
+ // Good: Use className for layout
360
+ <F0Text variant="body-md-semibold" className="mt-4 flex-1">Bold text</F0Text>
361
+
362
+ // ❌ Bad: Don't use className for typography (it will be overridden)
363
+ <F0Text variant="body-sm-default" className="font-bold text-red-500">
364
+ font-bold and text-red-500 are silently ignored
365
+ </F0Text>
310
366
  ```
311
367
 
312
368
  <!-- prettier-ignore -->
@@ -2,11 +2,12 @@ import { tv, type VariantProps } from "tailwind-variants"
2
2
 
3
3
  /**
4
4
  * Text component variants using tailwind-variants
5
- * Font weights (font-normal, font-medium, font-semibold) map to
6
- * Inter font families (Inter-Regular, Inter-Medium, Inter-SemiBold)
5
+ * Font weights (font-normal, font-medium, font-semibold, font-bold) map to
6
+ * Inter font families (Inter-Regular, Inter-Medium, Inter-SemiBold, Inter-Bold)
7
+ * via --font-* CSS variables defined in @theme.
7
8
  */
8
9
  export const textVariants = tv({
9
- base: "",
10
+ base: "no-underline normal-case tracking-normal",
10
11
  variants: {
11
12
  variant: {
12
13
  // Heading variants
@@ -1,7 +1,7 @@
1
1
  import React from "react"
2
2
  import { Text as RNText } from "react-native"
3
3
 
4
- import { omitProps } from "../../../../lib/utils"
4
+ import { cn, omitProps } from "../../../../lib/utils"
5
5
 
6
6
  import { textVariants } from "./F0Text.styles"
7
7
  import { F0_TEXT_BANNED_PROPS, type F0TextProps } from "./F0Text.types"
@@ -9,10 +9,13 @@ import { F0_TEXT_BANNED_PROPS, type F0TextProps } from "./F0Text.types"
9
9
  /**
10
10
  * F0Text - Primitive Text component with semantic typography variants
11
11
  *
12
+ * Typography is controlled by semantic props and always takes precedence.
13
+ * `className` is accepted for layout/positioning (margin, padding, flex, etc.).
14
+ *
12
15
  * @example
13
16
  * <F0Text variant="heading-lg">Large Heading</F0Text>
14
17
  * <F0Text variant="body-sm-default" color="secondary">Secondary text</F0Text>
15
- * <F0Text variant="body-md-medium" numberOfLines={2}>Truncated text...</F0Text>
18
+ * <F0Text variant="body-sm-default" className="mt-4 flex-1">Positioned text</F0Text>
16
19
  */
17
20
  const F0TextComponent = React.forwardRef<RNText, F0TextProps>(
18
21
  (
@@ -22,6 +25,7 @@ const F0TextComponent = React.forwardRef<RNText, F0TextProps>(
22
25
  align = "left",
23
26
  decoration = "none",
24
27
  transform = "none",
28
+ className,
25
29
  children,
26
30
  numberOfLines,
27
31
  ...rest
@@ -30,14 +34,17 @@ const F0TextComponent = React.forwardRef<RNText, F0TextProps>(
30
34
  ) => {
31
35
  const textClassName = React.useMemo(
32
36
  () =>
33
- textVariants({
34
- variant,
35
- color,
36
- align,
37
- decoration,
38
- transform,
39
- }),
40
- [variant, color, align, decoration, transform]
37
+ cn(
38
+ className,
39
+ textVariants({
40
+ variant,
41
+ color,
42
+ align,
43
+ decoration,
44
+ transform,
45
+ })
46
+ ),
47
+ [variant, color, align, decoration, transform, className]
41
48
  )
42
49
 
43
50
  return (
@@ -1,11 +1,11 @@
1
1
  import type { TextProps as RNTextProps } from "react-native"
2
2
 
3
3
  /**
4
- * Props that must not be passed through to the underlying RN Text
5
- * (`style` and `className` are handled by F0 instead).
6
- * Used with omitProps for runtime safety.
4
+ * Props that must not be passed through to the underlying RN Text.
5
+ * `style` is blocked to enforce the semantic API; `className` is allowed
6
+ * for layout/positioning and merged with typography classes via twMerge.
7
7
  */
8
- export const F0_TEXT_BANNED_PROPS = ["style", "className"] as const
8
+ export const F0_TEXT_BANNED_PROPS = ["style"] as const
9
9
 
10
10
  /**
11
11
  * Typography variant types based on semantic design tokens
@@ -73,10 +73,14 @@ export const TEXT_TRANSFORMS = [
73
73
  export type TextTransform = (typeof TEXT_TRANSFORMS)[number]
74
74
 
75
75
  /**
76
- * Internal props for the F0Text component.
77
- * @private
76
+ * Props for the F0Text component.
77
+ *
78
+ * `className` is available for layout/positioning (margin, padding, flex, etc.).
79
+ * Typography is controlled exclusively by semantic props (variant, color, align, etc.)
80
+ * and always takes precedence — any typography classes in `className` are overridden.
81
+ * `style` is NOT available (omitted from RNTextProps and filtered at runtime).
78
82
  */
79
- interface F0TextPropsInternal extends Omit<RNTextProps, "style"> {
83
+ export interface F0TextProps extends Omit<RNTextProps, "style"> {
80
84
  /**
81
85
  * Semantic typography variant
82
86
  * @default "body-sm-default"
@@ -118,17 +122,17 @@ interface F0TextPropsInternal extends Omit<RNTextProps, "style"> {
118
122
  children?: React.ReactNode
119
123
 
120
124
  /**
121
- * Excluded from public API via Omit<F0TextPropsInternal, "className">.
122
- * @private
125
+ * Tailwind classes for layout and positioning.
126
+ *
127
+ * Allowed: margin, padding, flex, position, width, height, opacity, z-index, etc.
128
+ * Ignored: font-size, font-weight, line-height, letter-spacing, color, text-align,
129
+ * text-decoration, text-transform — these are controlled by semantic props and
130
+ * always take precedence via twMerge.
131
+ *
132
+ * @example
133
+ * className="mt-4 flex-1"
134
+ * className="mb-2 self-center"
135
+ * className="absolute top-0 left-0"
123
136
  */
124
137
  className?: string
125
138
  }
126
-
127
- /**
128
- * Public props for the F0Text component
129
- *
130
- * Note: `className` and `style` props are NOT available.
131
- * Use semantic props (variant, color, align, etc.) for typography.
132
- * For spacing/layout, wrap F0Text in a View with className.
133
- */
134
- export type F0TextProps = Omit<F0TextPropsInternal, "className">