page.mdx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. export const metadata = { title: "@json-render/react-native API" }
  2. # @json-render/react-native
  3. React Native renderer with standard components, providers, and hooks.
  4. ## Standard Components
  5. ### Layout
  6. | Component | Props | Description |
  7. |-----------|-------|-------------|
  8. | `Container` | `padding`, `background`, `borderRadius`, `borderColor`, `flex` | Basic wrapper with styling |
  9. | `Row` | `gap`, `align`, `justify`, `flex`, `wrap` | Horizontal flex layout |
  10. | `Column` | `gap`, `align`, `justify`, `flex` | Vertical flex layout |
  11. | `ScrollContainer` | `direction` | Scrollable area (vertical or horizontal) |
  12. | `SafeArea` | `edges` | Safe area insets for notch/home indicator |
  13. | `Pressable` | `action`, `actionParams` | Touchable wrapper that triggers actions |
  14. | `Spacer` | `size`, `flex` | Fixed or flexible spacing |
  15. | `Divider` | `color`, `thickness` | Thin line separator |
  16. ### Content
  17. | Component | Props | Description |
  18. |-----------|-------|-------------|
  19. | `Heading` | `text`, `level`, `align`, `color` | Heading text (levels 1-6) |
  20. | `Paragraph` | `text`, `align`, `color` | Body text |
  21. | `Label` | `text`, `color`, `bold` | Small label text |
  22. | `Image` | `uri`, `width`, `height`, `resizeMode`, `borderRadius` | Image display |
  23. | `Avatar` | `uri`, `size`, `fallback` | Circular avatar |
  24. | `Badge` | `label`, `color`, `textColor` | Status badge |
  25. | `Chip` | `label`, `selected`, `color` | Tag/chip |
  26. ### Input
  27. | Component | Props | Description |
  28. |-----------|-------|-------------|
  29. | `Button` | `label`, `variant`, `size`, `disabled`, `action`, `actionParams` | Pressable button |
  30. | `TextInput` | `placeholder`, `value` (use `$bindState`), `secure`, `keyboardType`, `multiline` | Text input field |
  31. | `Switch` | `checked` (use `$bindState`), `label` | Toggle switch |
  32. | `Checkbox` | `checked` (use `$bindState`), `label` | Checkbox with label |
  33. | `Slider` | `value` (use `$bindState`), `min`, `max`, `step` | Range slider |
  34. | `SearchBar` | `placeholder`, `value` (use `$bindState`) | Search input |
  35. ### Feedback
  36. | Component | Props | Description |
  37. |-----------|-------|-------------|
  38. | `Spinner` | `size`, `color` | Loading indicator |
  39. | `ProgressBar` | `progress`, `color`, `trackColor` | Progress indicator |
  40. ### Composite
  41. | Component | Props | Description |
  42. |-----------|-------|-------------|
  43. | `Card` | `title`, `subtitle`, `padding` | Card container |
  44. | `ListItem` | `title`, `subtitle`, `leading`, `trailing`, `action`, `actionParams` | List row |
  45. | `Modal` | `visible`, `title` | Bottom sheet modal |
  46. ## Providers
  47. ### StateProvider
  48. ```tsx
  49. <StateProvider initialState={object}>
  50. {children}
  51. </StateProvider>
  52. ```
  53. ### ActionProvider
  54. ```tsx
  55. <ActionProvider handlers={Record<string, ActionHandler>}>
  56. {children}
  57. </ActionProvider>
  58. ```
  59. ### VisibilityProvider
  60. ```tsx
  61. <VisibilityProvider>
  62. {children}
  63. </VisibilityProvider>
  64. ```
  65. Conditions in specs use the `VisibilityCondition` format with `$state` paths (e.g. `{ "$state": "/path" }`, `{ "$state": "/path", "eq": value }`). See [visibility](/docs/visibility) for the full syntax.
  66. ### ValidationProvider
  67. ```tsx
  68. <ValidationProvider>
  69. {children}
  70. </ValidationProvider>
  71. ```
  72. ## defineRegistry
  73. Create a type-safe component registry. Standard components are built-in; only register custom components.
  74. ```tsx
  75. import { defineRegistry, type Components } from '@json-render/react-native';
  76. const { registry } = defineRegistry(catalog, {
  77. components: {
  78. Icon: ({ props }) => <Ionicons name={props.name} size={props.size ?? 24} />,
  79. } as Components<typeof catalog>,
  80. });
  81. ```
  82. ## Hooks
  83. ### useUIStream
  84. ```typescript
  85. const {
  86. spec, // Spec | null - current UI state
  87. isStreaming, // boolean - true while streaming
  88. error, // Error | null
  89. send, // (prompt: string) => Promise<void>
  90. clear, // () => void - reset spec and error
  91. } = useUIStream({
  92. api: string,
  93. onComplete?: (spec: Spec) => void,
  94. onError?: (error: Error) => void,
  95. });
  96. ```
  97. ### useStateStore
  98. ```typescript
  99. const { state, get, set, update } = useStateStore();
  100. ```
  101. ### useStateValue
  102. ```typescript
  103. const value = useStateValue(path: string);
  104. ```
  105. ### useStateBinding (deprecated)
  106. > **Deprecated.** Use `useBoundProp` with `$bindState` expressions instead.
  107. ```typescript
  108. const [value, setValue] = useStateBinding(path: string);
  109. ```
  110. ### useActions
  111. ```typescript
  112. const { execute } = useActions();
  113. ```
  114. ### useIsVisible
  115. ```typescript
  116. const isVisible = useIsVisible(condition?: VisibilityCondition);
  117. ```
  118. ## Catalog Exports
  119. ```typescript
  120. import { standardComponentDefinitions, standardActionDefinitions } from "@json-render/react-native/catalog";
  121. import { schema } from "@json-render/react-native/schema";
  122. ```
  123. | Export | Purpose |
  124. |--------|---------|
  125. | `standardComponentDefinitions` | Catalog definitions for all 25+ standard components |
  126. | `standardActionDefinitions` | Catalog definitions for standard actions (setState, navigate) |
  127. | `schema` | React Native element tree schema |