@factorialco/f0-react-native 0.33.0 → 0.35.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 (71) hide show
  1. package/README.md +7 -5
  2. package/lib/module/components/Badge/index.js +1 -1
  3. package/lib/module/components/Badge/index.js.map +1 -1
  4. package/lib/module/components/Button/index.js +1 -1
  5. package/lib/module/components/Button/index.js.map +1 -1
  6. package/lib/module/components/F0Badge/F0Badge.js +2 -0
  7. package/lib/module/components/F0Badge/F0Badge.js.map +1 -0
  8. package/lib/module/components/F0Badge/F0Badge.md +67 -0
  9. package/lib/module/components/F0Badge/F0Badge.styles.js +2 -0
  10. package/lib/module/components/F0Badge/F0Badge.styles.js.map +1 -0
  11. package/lib/module/components/F0Badge/F0Badge.types.js +2 -0
  12. package/lib/module/components/F0Badge/F0Badge.types.js.map +1 -0
  13. package/lib/module/components/F0Badge/index.js +2 -0
  14. package/lib/module/components/F0Badge/index.js.map +1 -0
  15. package/lib/module/components/F0Button/F0Button.js +2 -0
  16. package/lib/module/components/F0Button/F0Button.js.map +1 -0
  17. package/lib/module/components/F0Button/F0Button.md +163 -0
  18. package/lib/module/components/F0Button/F0Button.styles.js +2 -0
  19. package/lib/module/components/F0Button/F0Button.styles.js.map +1 -0
  20. package/lib/module/components/F0Button/F0Button.types.js +2 -0
  21. package/lib/module/components/F0Button/F0Button.types.js.map +1 -0
  22. package/lib/module/components/F0Button/index.js +2 -0
  23. package/lib/module/components/F0Button/index.js.map +1 -0
  24. package/lib/module/components/Icon/index.js.map +1 -1
  25. package/lib/module/components/exports.js +1 -1
  26. package/lib/module/components/exports.js.map +1 -1
  27. package/lib/typescript/components/Badge/index.d.ts +28 -54
  28. package/lib/typescript/components/Badge/index.d.ts.map +1 -1
  29. package/lib/typescript/components/Button/index.d.ts +18 -0
  30. package/lib/typescript/components/Button/index.d.ts.map +1 -1
  31. package/lib/typescript/components/F0Badge/F0Badge.d.ts +5 -0
  32. package/lib/typescript/components/F0Badge/F0Badge.d.ts.map +1 -0
  33. package/lib/typescript/components/F0Badge/F0Badge.styles.d.ts +57 -0
  34. package/lib/typescript/components/F0Badge/F0Badge.styles.d.ts.map +1 -0
  35. package/lib/typescript/components/F0Badge/F0Badge.types.d.ts +19 -0
  36. package/lib/typescript/components/F0Badge/F0Badge.types.d.ts.map +1 -0
  37. package/lib/typescript/components/F0Badge/index.d.ts +4 -0
  38. package/lib/typescript/components/F0Badge/index.d.ts.map +1 -0
  39. package/lib/typescript/components/F0Button/F0Button.d.ts +6 -0
  40. package/lib/typescript/components/F0Button/F0Button.d.ts.map +1 -0
  41. package/lib/typescript/components/F0Button/F0Button.styles.d.ts +161 -0
  42. package/lib/typescript/components/F0Button/F0Button.styles.d.ts.map +1 -0
  43. package/lib/typescript/components/F0Button/F0Button.types.d.ts +47 -0
  44. package/lib/typescript/components/F0Button/F0Button.types.d.ts.map +1 -0
  45. package/lib/typescript/components/F0Button/index.d.ts +4 -0
  46. package/lib/typescript/components/F0Button/index.d.ts.map +1 -0
  47. package/lib/typescript/components/Icon/index.d.ts +5 -0
  48. package/lib/typescript/components/Icon/index.d.ts.map +1 -1
  49. package/lib/typescript/components/exports.d.ts +2 -0
  50. package/lib/typescript/components/exports.d.ts.map +1 -1
  51. package/package.json +1 -1
  52. package/src/components/Badge/__tests__/index.spec.tsx +29 -0
  53. package/src/components/Badge/index.tsx +38 -40
  54. package/src/components/Button/__snapshots__/index.spec.tsx.snap +11 -11
  55. package/src/components/Button/index.tsx +22 -2
  56. package/src/components/F0Badge/F0Badge.md +67 -0
  57. package/src/components/F0Badge/F0Badge.styles.ts +28 -0
  58. package/src/components/F0Badge/F0Badge.tsx +24 -0
  59. package/src/components/F0Badge/F0Badge.types.ts +34 -0
  60. package/src/components/F0Badge/__tests__/F0Badge.spec.tsx +63 -0
  61. package/src/components/F0Badge/__tests__/__snapshots__/F0Badge.spec.tsx.snap +651 -0
  62. package/src/components/F0Badge/index.ts +7 -0
  63. package/src/components/F0Button/F0Button.md +163 -0
  64. package/src/components/F0Button/F0Button.styles.ts +141 -0
  65. package/src/components/F0Button/F0Button.tsx +228 -0
  66. package/src/components/F0Button/F0Button.types.ts +82 -0
  67. package/src/components/F0Button/__tests__/F0Button.spec.tsx +285 -0
  68. package/src/components/F0Button/__tests__/__snapshots__/F0Button.spec.tsx.snap +966 -0
  69. package/src/components/F0Button/index.ts +7 -0
  70. package/src/components/Icon/index.tsx +5 -0
  71. package/src/components/exports.ts +2 -0
@@ -3,8 +3,11 @@ import { Pressable, Text, View } from "react-native"
3
3
  import { tv, type VariantProps } from "tailwind-variants"
4
4
 
5
5
  import { cn } from "../../lib/utils"
6
- import { F0Icon, type IconType, type IconColor } from "../primitives/F0Icon"
6
+ import { F0Icon, type IconColor, type IconType } from "../primitives/F0Icon"
7
7
 
8
+ /**
9
+ * @deprecated Use `F0Button` from `../F0Button` instead.
10
+ */
8
11
  export const variants = [
9
12
  "default",
10
13
  "outline",
@@ -13,9 +16,20 @@ export const variants = [
13
16
  "ghost",
14
17
  "promote",
15
18
  ] as const
19
+
20
+ /**
21
+ * @deprecated Use `F0ButtonVariant` from `../F0Button` instead.
22
+ */
16
23
  export type ButtonVariant = (typeof variants)[number]
17
24
 
25
+ /**
26
+ * @deprecated Use `BUTTON_SIZES` from `../F0Button` instead.
27
+ */
18
28
  export const sizes = ["sm", "md", "lg"] as const
29
+
30
+ /**
31
+ * @deprecated Use `F0ButtonSize` from `../F0Button` instead.
32
+ */
19
33
  export type ButtonSize = (typeof sizes)[number]
20
34
 
21
35
  const buttonVariants = tv({
@@ -115,6 +129,9 @@ const getTextColorClass = (variant: ButtonVariant, isPressed: boolean) => {
115
129
  }
116
130
  }
117
131
 
132
+ /**
133
+ * @deprecated Use `F0ButtonProps` from `../F0Button` instead.
134
+ */
118
135
  export interface ButtonProps extends VariantProps<typeof buttonVariants> {
119
136
  label: string
120
137
  onPress?: () => void | Promise<unknown>
@@ -129,6 +146,9 @@ export interface ButtonProps extends VariantProps<typeof buttonVariants> {
129
146
  fullWidth?: boolean
130
147
  }
131
148
 
149
+ /**
150
+ * @deprecated Use `F0Button` from `../F0Button` instead.
151
+ */
132
152
  export const Button = forwardRef<View, ButtonProps>(function Button(
133
153
  {
134
154
  label,
@@ -171,7 +191,7 @@ export const Button = forwardRef<View, ButtonProps>(function Button(
171
191
  const shouldShowPressed = isPressed && !isDisabled
172
192
 
173
193
  return (
174
- <View className={`flex ${fullWidth ? "flex-1" : "item-start"}`}>
194
+ <View className={`flex ${fullWidth ? "flex-1" : "items-start"}`}>
175
195
  <Pressable
176
196
  ref={ref}
177
197
  disabled={isDisabled}
@@ -0,0 +1,67 @@
1
+ # F0Badge
2
+
3
+ Semantic icon badge component for React Native in F0.
4
+
5
+ ## Overview
6
+
7
+ F0Badge renders an icon inside a circular badge with semantic color variants and size variants.
8
+
9
+ ## Usage
10
+
11
+ <!-- prettier-ignore -->
12
+ ```tsx
13
+ import { F0Badge } from "@factorialco/f0-react-native"
14
+ import { Add } from "@factorialco/f0-react-native/icons/app"
15
+
16
+ <F0Badge icon={Add} />
17
+ <F0Badge icon={Add} variant="highlight" />
18
+ <F0Badge icon={Add} size="lg" variant="positive" />
19
+ ```
20
+
21
+ ## Props
22
+
23
+ | Prop | Type | Default | Description |
24
+ | --------- | ---------------- | ----------- | --------------------------- |
25
+ | `icon` | `IconType` | required | Icon component to render |
26
+ | `variant` | `F0BadgeVariant` | `"neutral"` | Semantic visual variant |
27
+ | `size` | `F0BadgeSize` | `"md"` | Badge and icon size mapping |
28
+
29
+ ## Variants
30
+
31
+ - `neutral`
32
+ - `highlight`
33
+ - `positive`
34
+ - `critical`
35
+ - `warning`
36
+
37
+ ## Sizes
38
+
39
+ - `xs`
40
+ - `sm`
41
+ - `md`
42
+ - `lg`
43
+
44
+ ## Accessibility
45
+
46
+ F0Badge is decorative by default. Accessibility semantics come from the surrounding parent component unless explicitly handled by consumers.
47
+
48
+ ## Testing
49
+
50
+ Main tests:
51
+
52
+ - `src/components/F0Badge/__tests__/F0Badge.spec.tsx`
53
+
54
+ Coverage includes snapshots for variants and sizes, and icon-size mapping checks.
55
+
56
+ ## File Structure
57
+
58
+ ```
59
+ src/components/F0Badge/
60
+ ├── F0Badge.tsx
61
+ ├── F0Badge.types.ts
62
+ ├── F0Badge.styles.ts
63
+ ├── F0Badge.md
64
+ ├── index.ts
65
+ └── __tests__/
66
+ └── F0Badge.spec.tsx
67
+ ```
@@ -0,0 +1,28 @@
1
+ import { tv } from "tailwind-variants"
2
+
3
+ export const badgeVariantClasses = {
4
+ neutral: "bg-transparent text-f0-icon",
5
+ highlight: "text-f0-special-highlight",
6
+ positive: "bg-f0-background-positive-bold text-f0-foreground-inverse",
7
+ critical: "bg-f0-icon-critical text-f0-foreground-inverse",
8
+ warning: "bg-f0-background-warning-bold text-f0-foreground-inverse",
9
+ } as const
10
+
11
+ export const badgeSizeClasses = {
12
+ xs: "h-2.5 w-2.5",
13
+ sm: "h-3 w-3",
14
+ md: "h-5 w-5",
15
+ lg: "h-6 w-6",
16
+ } as const
17
+
18
+ export const badgeVariants = tv({
19
+ base: "flex shrink-0 items-center justify-center rounded-full",
20
+ variants: {
21
+ variant: badgeVariantClasses,
22
+ size: badgeSizeClasses,
23
+ },
24
+ defaultVariants: {
25
+ variant: "neutral",
26
+ size: "md",
27
+ },
28
+ })
@@ -0,0 +1,24 @@
1
+ import React from "react"
2
+
3
+ import { F0Icon } from "../primitives/F0Icon"
4
+
5
+ import { badgeVariants } from "./F0Badge.styles"
6
+ import { F0_BADGE_ICON_SIZES, type F0BadgeProps } from "./F0Badge.types"
7
+
8
+ const F0Badge = React.memo(function F0Badge({
9
+ variant = "neutral",
10
+ size = "md",
11
+ icon,
12
+ }: F0BadgeProps) {
13
+ return (
14
+ <F0Icon
15
+ className={badgeVariants({ variant, size })}
16
+ icon={icon}
17
+ size={F0_BADGE_ICON_SIZES[size]}
18
+ />
19
+ )
20
+ })
21
+
22
+ F0Badge.displayName = "F0Badge"
23
+
24
+ export { F0Badge }
@@ -0,0 +1,34 @@
1
+ import type { VariantProps } from "tailwind-variants"
2
+
3
+ import type { IconType } from "../primitives/F0Icon"
4
+
5
+ import {
6
+ badgeSizeClasses,
7
+ badgeVariantClasses,
8
+ type badgeVariants,
9
+ } from "./F0Badge.styles"
10
+
11
+ export type F0BadgeVariant = keyof typeof badgeVariantClasses
12
+
13
+ export const F0_BADGE_VARIANTS = Object.keys(
14
+ badgeVariantClasses
15
+ ) as ReadonlyArray<F0BadgeVariant>
16
+
17
+ export type F0BadgeSize = keyof typeof badgeSizeClasses
18
+
19
+ export const F0_BADGE_SIZES = Object.keys(
20
+ badgeSizeClasses
21
+ ) as ReadonlyArray<F0BadgeSize>
22
+
23
+ export const F0_BADGE_ICON_SIZES = {
24
+ xs: "xs",
25
+ sm: "xs",
26
+ md: "sm",
27
+ lg: "md",
28
+ } as const
29
+
30
+ export interface F0BadgeProps extends VariantProps<typeof badgeVariants> {
31
+ icon: IconType
32
+ variant?: F0BadgeVariant
33
+ size?: F0BadgeSize
34
+ }
@@ -0,0 +1,63 @@
1
+ import { render } from "@testing-library/react-native"
2
+ import React from "react"
3
+
4
+ import { Add } from "../../../icons/app"
5
+ import { F0Badge } from "../F0Badge"
6
+
7
+ const getClassName = (
8
+ json: ReturnType<ReturnType<typeof render>["toJSON"]>
9
+ ) => {
10
+ if (!json || Array.isArray(json)) return ""
11
+ return String(json.props.className ?? "")
12
+ }
13
+
14
+ describe("F0Badge", () => {
15
+ it("Snapshot - default", () => {
16
+ const { toJSON } = render(<F0Badge icon={Add} />)
17
+ expect(toJSON()).toMatchSnapshot()
18
+ })
19
+
20
+ it("Snapshot - all variants", () => {
21
+ const variants = [
22
+ "neutral",
23
+ "highlight",
24
+ "positive",
25
+ "critical",
26
+ "warning",
27
+ ] as const
28
+
29
+ variants.forEach((variant) => {
30
+ const { toJSON } = render(<F0Badge icon={Add} variant={variant} />)
31
+ expect(toJSON()).toMatchSnapshot()
32
+ })
33
+ })
34
+
35
+ it("Snapshot - all sizes", () => {
36
+ const sizes = ["xs", "sm", "md", "lg"] as const
37
+
38
+ sizes.forEach((size) => {
39
+ const { toJSON } = render(<F0Badge icon={Add} size={size} />)
40
+ expect(toJSON()).toMatchSnapshot()
41
+ })
42
+ })
43
+
44
+ it("maps xs badge size to xs icon size", () => {
45
+ const { toJSON } = render(<F0Badge icon={Add} size="xs" />)
46
+ expect(getClassName(toJSON())).toContain("stroke-xs")
47
+ })
48
+
49
+ it("maps sm badge size to xs icon size", () => {
50
+ const { toJSON } = render(<F0Badge icon={Add} size="sm" />)
51
+ expect(getClassName(toJSON())).toContain("stroke-xs")
52
+ })
53
+
54
+ it("maps md badge size to sm icon size", () => {
55
+ const { toJSON } = render(<F0Badge icon={Add} size="md" />)
56
+ expect(getClassName(toJSON())).toContain("stroke-sm")
57
+ })
58
+
59
+ it("maps lg badge size to md icon size", () => {
60
+ const { toJSON } = render(<F0Badge icon={Add} size="lg" />)
61
+ expect(getClassName(toJSON())).toContain("stroke-md")
62
+ })
63
+ })