page.mdx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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`, `statePath`, `secure`, `keyboardType`, `multiline` | Text input field |
  31. | `Switch` | `statePath`, `label` | Toggle switch |
  32. | `Checkbox` | `statePath`, `label` | Checkbox with label |
  33. | `Slider` | `statePath`, `min`, `max`, `step` | Range slider |
  34. | `SearchBar` | `placeholder`, `statePath` | 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. ### ValidationProvider
  66. ```tsx
  67. <ValidationProvider>
  68. {children}
  69. </ValidationProvider>
  70. ```
  71. ## defineRegistry
  72. Create a type-safe component registry. Standard components are built-in -- only register custom components.
  73. ```tsx
  74. import { defineRegistry, type Components } from '@json-render/react-native';
  75. const { registry } = defineRegistry(catalog, {
  76. components: {
  77. Icon: ({ props }) => <Ionicons name={props.name} size={props.size ?? 24} />,
  78. } as Components<typeof catalog>,
  79. });
  80. ```
  81. ## Hooks
  82. ### useUIStream
  83. ```typescript
  84. const {
  85. spec, // Spec | null - current UI state
  86. isStreaming, // boolean - true while streaming
  87. error, // Error | null
  88. send, // (prompt: string) => Promise<void>
  89. clear, // () => void - reset spec and error
  90. } = useUIStream({
  91. api: string,
  92. onComplete?: (spec: Spec) => void,
  93. onError?: (error: Error) => void,
  94. });
  95. ```
  96. ### useStateStore
  97. ```typescript
  98. const { state, get, set, update } = useStateStore();
  99. ```
  100. ### useStateValue
  101. ```typescript
  102. const value = useStateValue(path: string);
  103. ```
  104. ### useStateBinding
  105. ```typescript
  106. const [value, setValue] = useStateBinding(path: string);
  107. ```
  108. ### useActions
  109. ```typescript
  110. const { execute } = useActions();
  111. ```
  112. ### useIsVisible
  113. ```typescript
  114. const isVisible = useIsVisible(condition?: VisibilityCondition);
  115. ```
  116. ## Catalog Exports
  117. ```typescript
  118. import { standardComponentDefinitions, standardActionDefinitions } from "@json-render/react-native/catalog";
  119. import { schema } from "@json-render/react-native/schema";
  120. ```
  121. | Export | Purpose |
  122. |--------|---------|
  123. | `standardComponentDefinitions` | Catalog definitions for all 25+ standard components |
  124. | `standardActionDefinitions` | Catalog definitions for standard actions (setState, navigate) |
  125. | `schema` | React Native element tree schema |