@fogui/react 0.1.0 → 0.3.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.
- package/README.md +96 -19
- package/dist/{index-BcLda68r.d.mts → ComponentRegistry-BFgVIcHz.d.mts} +52 -21
- package/dist/{index-BcLda68r.d.ts → ComponentRegistry-BFgVIcHz.d.ts} +52 -21
- package/dist/adapters/index.d.mts +140 -0
- package/dist/adapters/index.d.ts +140 -0
- package/dist/adapters/index.js +147 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +140 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/components/index.d.mts +51 -3
- package/dist/components/index.d.ts +51 -3
- package/dist/components/index.js +29 -7
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +28 -6
- package/dist/components/index.mjs.map +1 -1
- package/dist/index.d.mts +72 -5
- package/dist/index.d.ts +72 -5
- package/dist/index.js +27 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -57,6 +57,78 @@ function Chat() {
|
|
|
57
57
|
}
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
## Use Your Own Design System
|
|
61
|
+
|
|
62
|
+
FogUI is designed to work with **your existing UI components**. No need to adopt a new design language!
|
|
63
|
+
|
|
64
|
+
### Option 1: Shadcn/Radix UI
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { FogUIProvider } from '@fogui/react';
|
|
68
|
+
import { createShadcnAdapter } from '@fogui/react/adapters';
|
|
69
|
+
|
|
70
|
+
// Import YOUR Shadcn components
|
|
71
|
+
import { Card, CardHeader, CardContent, CardTitle, CardDescription } from '@/components/ui/card';
|
|
72
|
+
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from '@/components/ui/table';
|
|
73
|
+
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert';
|
|
74
|
+
|
|
75
|
+
// Create adapter with your components
|
|
76
|
+
const shadcnComponents = createShadcnAdapter({
|
|
77
|
+
Card, CardHeader, CardContent, CardTitle, CardDescription,
|
|
78
|
+
Table, TableHeader, TableBody, TableRow, TableHead, TableCell,
|
|
79
|
+
Alert, AlertTitle, AlertDescription,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
function App() {
|
|
83
|
+
return (
|
|
84
|
+
<FogUIProvider apiKey="fog_xxxx" components={shadcnComponents}>
|
|
85
|
+
<Chat />
|
|
86
|
+
</FogUIProvider>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Option 2: Custom Components (Any Design System)
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { FogUIProvider } from '@fogui/react';
|
|
95
|
+
|
|
96
|
+
// Map FogUI component types to YOUR components
|
|
97
|
+
const myComponents = {
|
|
98
|
+
card: ({ title, description, data }) => (
|
|
99
|
+
<div className="my-card">
|
|
100
|
+
<h3>{title}</h3>
|
|
101
|
+
<p>{description}</p>
|
|
102
|
+
{/* Render data however you want */}
|
|
103
|
+
</div>
|
|
104
|
+
),
|
|
105
|
+
table: MyTableComponent,
|
|
106
|
+
list: MyListComponent,
|
|
107
|
+
callout: MyAlertComponent,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
function App() {
|
|
111
|
+
return (
|
|
112
|
+
<FogUIProvider apiKey="fog_xxxx" components={myComponents}>
|
|
113
|
+
<Chat />
|
|
114
|
+
</FogUIProvider>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Self-Hosted Deployment
|
|
120
|
+
|
|
121
|
+
For enterprise/self-hosted deployments, specify a custom endpoint:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<FogUIProvider
|
|
125
|
+
apiKey="fog_xxxx"
|
|
126
|
+
endpoint="https://fogui.mycompany.com"
|
|
127
|
+
>
|
|
128
|
+
<App />
|
|
129
|
+
</FogUIProvider>
|
|
130
|
+
```
|
|
131
|
+
|
|
60
132
|
## API Reference
|
|
61
133
|
|
|
62
134
|
### `<FogUIProvider>`
|
|
@@ -64,14 +136,20 @@ function Chat() {
|
|
|
64
136
|
Wrap your app with this provider to configure FogUI.
|
|
65
137
|
|
|
66
138
|
```tsx
|
|
67
|
-
<FogUIProvider
|
|
139
|
+
<FogUIProvider
|
|
140
|
+
apiKey="fog_xxxx"
|
|
141
|
+
components={myComponents} // Optional: your design system
|
|
142
|
+
endpoint="https://custom.api" // Optional: self-hosted endpoint
|
|
143
|
+
>
|
|
68
144
|
<App />
|
|
69
145
|
</FogUIProvider>
|
|
70
146
|
```
|
|
71
147
|
|
|
72
148
|
| Prop | Type | Description |
|
|
73
149
|
|------|------|-------------|
|
|
74
|
-
| `apiKey` | `string` | Your FogUI API key
|
|
150
|
+
| `apiKey` | `string` | Your FogUI API key |
|
|
151
|
+
| `components` | `ComponentRegistry` | Custom component mapping (optional) |
|
|
152
|
+
| `endpoint` | `string` | Custom API endpoint (optional) |
|
|
75
153
|
|
|
76
154
|
### `useFogUI()`
|
|
77
155
|
|
|
@@ -96,26 +174,24 @@ Render the transformed UI response.
|
|
|
96
174
|
```tsx
|
|
97
175
|
<FogUIRenderer
|
|
98
176
|
response={transformResult.result}
|
|
99
|
-
componentRegistry={customComponents} // Optional
|
|
177
|
+
componentRegistry={customComponents} // Optional: override provider components
|
|
178
|
+
className="my-class" // Optional
|
|
179
|
+
style={{ maxWidth: 600 }} // Optional
|
|
100
180
|
/>
|
|
101
181
|
```
|
|
102
182
|
|
|
103
|
-
##
|
|
183
|
+
## Component Types
|
|
104
184
|
|
|
105
|
-
|
|
185
|
+
FogUI transforms LLM output into these component types:
|
|
106
186
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
card: MyCard,
|
|
114
|
-
table: MyTable,
|
|
115
|
-
};
|
|
187
|
+
| Type | Props | Description |
|
|
188
|
+
|------|-------|-------------|
|
|
189
|
+
| `card` | `{ title, description, data }` | Information card |
|
|
190
|
+
| `table` | `{ columns, rows, title }` | Data table |
|
|
191
|
+
| `list` | `{ title, items, ordered }` | Bullet or numbered list |
|
|
192
|
+
| `callout` | `{ title, message, variant }` | Alert/info box |
|
|
116
193
|
|
|
117
|
-
|
|
118
|
-
```
|
|
194
|
+
You can extend with custom types by adding them to your component registry.
|
|
119
195
|
|
|
120
196
|
## Get Your API Key
|
|
121
197
|
|
|
@@ -128,10 +204,11 @@ const customRegistry = {
|
|
|
128
204
|
|
|
129
205
|
> UI that materializes from nothing - like magic from the fog ✨
|
|
130
206
|
|
|
131
|
-
- **Your LLM, Your Keys** - We never see your API keys
|
|
132
|
-
- **Any LLM Provider** - Works with OpenAI, Claude, Gemini, etc.
|
|
133
|
-
- **
|
|
207
|
+
- **Your LLM, Your Keys** - We never see your LLM API keys
|
|
208
|
+
- **Any LLM Provider** - Works with OpenAI, Claude, Gemini, Llama, etc.
|
|
209
|
+
- **Your Design System** - Shadcn, MUI, Ant Design, or custom
|
|
134
210
|
- **TypeScript First** - Full type safety
|
|
211
|
+
- **Streaming Support** - Real-time UI updates
|
|
135
212
|
|
|
136
213
|
## License
|
|
137
214
|
|
|
@@ -78,6 +78,7 @@ interface ComponentBlock {
|
|
|
78
78
|
type: 'component';
|
|
79
79
|
componentType: string;
|
|
80
80
|
props: Record<string, unknown>;
|
|
81
|
+
children?: ComponentBlock[];
|
|
81
82
|
}
|
|
82
83
|
interface FogUIResponse {
|
|
83
84
|
thinking: ThinkingItem[];
|
|
@@ -91,34 +92,64 @@ interface FogUIResponse {
|
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Component registry type - maps componentType strings to React components.
|
|
97
|
+
*
|
|
98
|
+
* Each component receives props that match the FogUI DSL for that component type.
|
|
99
|
+
*/
|
|
100
|
+
type ComponentRegistry = Record<string, React.ComponentType<any>>;
|
|
101
|
+
/**
|
|
102
|
+
* Standard prop interfaces for built-in FogUI component types.
|
|
103
|
+
* Useful for implementing custom components that match the expected API.
|
|
104
|
+
*/
|
|
105
|
+
interface CardProps {
|
|
106
|
+
title?: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
data?: Record<string, unknown>;
|
|
109
|
+
children?: React.ReactNode;
|
|
110
|
+
}
|
|
111
|
+
interface ListProps {
|
|
112
|
+
title?: string;
|
|
113
|
+
items: unknown[];
|
|
114
|
+
ordered?: boolean;
|
|
107
115
|
}
|
|
116
|
+
interface TableProps {
|
|
117
|
+
columns: string[];
|
|
118
|
+
rows: Record<string, unknown>[];
|
|
119
|
+
title?: string;
|
|
120
|
+
}
|
|
121
|
+
interface CalloutProps {
|
|
122
|
+
title?: string;
|
|
123
|
+
message: string;
|
|
124
|
+
variant?: 'info' | 'warning' | 'tip' | 'error';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Merge multiple component registries with later registries taking precedence.
|
|
128
|
+
* Useful for layering: defaults → context → prop overrides.
|
|
129
|
+
*/
|
|
130
|
+
declare function mergeRegistries(...registries: (ComponentRegistry | undefined)[]): ComponentRegistry;
|
|
108
131
|
/**
|
|
109
|
-
*
|
|
132
|
+
* Create a component registry from an adapter.
|
|
133
|
+
* This is a convenience function for creating type-safe registries.
|
|
110
134
|
*
|
|
111
135
|
* @example
|
|
112
136
|
* ```tsx
|
|
113
|
-
* import {
|
|
137
|
+
* import { createRegistry } from '@fogui/react';
|
|
138
|
+
* import { Card } from '@/components/ui/card';
|
|
114
139
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
140
|
+
* const myRegistry = createRegistry({
|
|
141
|
+
* card: MyCardComponent,
|
|
142
|
+
* table: MyTableComponent,
|
|
143
|
+
* });
|
|
118
144
|
* ```
|
|
119
145
|
*/
|
|
120
|
-
declare function
|
|
121
|
-
|
|
146
|
+
declare function createRegistry(components: Partial<{
|
|
147
|
+
card: React.ComponentType<CardProps>;
|
|
148
|
+
list: React.ComponentType<ListProps>;
|
|
149
|
+
table: React.ComponentType<TableProps>;
|
|
150
|
+
callout: React.ComponentType<CalloutProps>;
|
|
151
|
+
[key: string]: React.ComponentType<any>;
|
|
152
|
+
}>): ComponentRegistry;
|
|
122
153
|
/**
|
|
123
154
|
* Default component registry mapping componentType to React components.
|
|
124
155
|
* Users can override this with their own components.
|
|
@@ -133,4 +164,4 @@ interface DynamicComponentProps {
|
|
|
133
164
|
*/
|
|
134
165
|
declare function DynamicComponent({ block, registry }: DynamicComponentProps): react_jsx_runtime.JSX.Element;
|
|
135
166
|
|
|
136
|
-
export { type ContentBlock as C, DynamicComponent as D, type FogUIConfig as F, type StreamEvent as S, type TransformOptions as T, type UseFogUIReturn as U, type TransformResult as a, type FogUIResponse as b, type TextBlock as c, type ComponentBlock as d, type ThinkingItem as e,
|
|
167
|
+
export { type ContentBlock as C, DynamicComponent as D, type FogUIConfig as F, type ListProps as L, type StreamEvent as S, type TransformOptions as T, type UseFogUIReturn as U, type TransformResult as a, type FogUIResponse as b, type TextBlock as c, type ComponentBlock as d, type ThinkingItem as e, defaultComponentRegistry as f, createRegistry as g, type CardProps as h, type TableProps as i, type CalloutProps as j, type ComponentRegistry as k, mergeRegistries as m };
|
|
@@ -78,6 +78,7 @@ interface ComponentBlock {
|
|
|
78
78
|
type: 'component';
|
|
79
79
|
componentType: string;
|
|
80
80
|
props: Record<string, unknown>;
|
|
81
|
+
children?: ComponentBlock[];
|
|
81
82
|
}
|
|
82
83
|
interface FogUIResponse {
|
|
83
84
|
thinking: ThinkingItem[];
|
|
@@ -91,34 +92,64 @@ interface FogUIResponse {
|
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Component registry type - maps componentType strings to React components.
|
|
97
|
+
*
|
|
98
|
+
* Each component receives props that match the FogUI DSL for that component type.
|
|
99
|
+
*/
|
|
100
|
+
type ComponentRegistry = Record<string, React.ComponentType<any>>;
|
|
101
|
+
/**
|
|
102
|
+
* Standard prop interfaces for built-in FogUI component types.
|
|
103
|
+
* Useful for implementing custom components that match the expected API.
|
|
104
|
+
*/
|
|
105
|
+
interface CardProps {
|
|
106
|
+
title?: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
data?: Record<string, unknown>;
|
|
109
|
+
children?: React.ReactNode;
|
|
110
|
+
}
|
|
111
|
+
interface ListProps {
|
|
112
|
+
title?: string;
|
|
113
|
+
items: unknown[];
|
|
114
|
+
ordered?: boolean;
|
|
107
115
|
}
|
|
116
|
+
interface TableProps {
|
|
117
|
+
columns: string[];
|
|
118
|
+
rows: Record<string, unknown>[];
|
|
119
|
+
title?: string;
|
|
120
|
+
}
|
|
121
|
+
interface CalloutProps {
|
|
122
|
+
title?: string;
|
|
123
|
+
message: string;
|
|
124
|
+
variant?: 'info' | 'warning' | 'tip' | 'error';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Merge multiple component registries with later registries taking precedence.
|
|
128
|
+
* Useful for layering: defaults → context → prop overrides.
|
|
129
|
+
*/
|
|
130
|
+
declare function mergeRegistries(...registries: (ComponentRegistry | undefined)[]): ComponentRegistry;
|
|
108
131
|
/**
|
|
109
|
-
*
|
|
132
|
+
* Create a component registry from an adapter.
|
|
133
|
+
* This is a convenience function for creating type-safe registries.
|
|
110
134
|
*
|
|
111
135
|
* @example
|
|
112
136
|
* ```tsx
|
|
113
|
-
* import {
|
|
137
|
+
* import { createRegistry } from '@fogui/react';
|
|
138
|
+
* import { Card } from '@/components/ui/card';
|
|
114
139
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
140
|
+
* const myRegistry = createRegistry({
|
|
141
|
+
* card: MyCardComponent,
|
|
142
|
+
* table: MyTableComponent,
|
|
143
|
+
* });
|
|
118
144
|
* ```
|
|
119
145
|
*/
|
|
120
|
-
declare function
|
|
121
|
-
|
|
146
|
+
declare function createRegistry(components: Partial<{
|
|
147
|
+
card: React.ComponentType<CardProps>;
|
|
148
|
+
list: React.ComponentType<ListProps>;
|
|
149
|
+
table: React.ComponentType<TableProps>;
|
|
150
|
+
callout: React.ComponentType<CalloutProps>;
|
|
151
|
+
[key: string]: React.ComponentType<any>;
|
|
152
|
+
}>): ComponentRegistry;
|
|
122
153
|
/**
|
|
123
154
|
* Default component registry mapping componentType to React components.
|
|
124
155
|
* Users can override this with their own components.
|
|
@@ -133,4 +164,4 @@ interface DynamicComponentProps {
|
|
|
133
164
|
*/
|
|
134
165
|
declare function DynamicComponent({ block, registry }: DynamicComponentProps): react_jsx_runtime.JSX.Element;
|
|
135
166
|
|
|
136
|
-
export { type ContentBlock as C, DynamicComponent as D, type FogUIConfig as F, type StreamEvent as S, type TransformOptions as T, type UseFogUIReturn as U, type TransformResult as a, type FogUIResponse as b, type TextBlock as c, type ComponentBlock as d, type ThinkingItem as e,
|
|
167
|
+
export { type ContentBlock as C, DynamicComponent as D, type FogUIConfig as F, type ListProps as L, type StreamEvent as S, type TransformOptions as T, type UseFogUIReturn as U, type TransformResult as a, type FogUIResponse as b, type TextBlock as c, type ComponentBlock as d, type ThinkingItem as e, defaultComponentRegistry as f, createRegistry as g, type CardProps as h, type TableProps as i, type CalloutProps as j, type ComponentRegistry as k, mergeRegistries as m };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { k as ComponentRegistry, h as CardProps, L as ListProps, i as TableProps, j as CalloutProps } from '../ComponentRegistry-BFgVIcHz.mjs';
|
|
3
|
+
import 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shadcn/Radix UI Adapter for FogUI
|
|
7
|
+
*
|
|
8
|
+
* This adapter creates a component registry that maps FogUI component types
|
|
9
|
+
* to Shadcn UI components. Since Shadcn components are copied into your project
|
|
10
|
+
* (not installed from npm), you pass your components to createShadcnAdapter().
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { FogUIProvider } from '@fogui/react';
|
|
15
|
+
* import { createShadcnAdapter } from '@fogui/react/adapters';
|
|
16
|
+
*
|
|
17
|
+
* // Import YOUR Shadcn components
|
|
18
|
+
* import { Card, CardHeader, CardContent, CardTitle, CardDescription } from '@/components/ui/card';
|
|
19
|
+
* import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from '@/components/ui/table';
|
|
20
|
+
* import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert';
|
|
21
|
+
*
|
|
22
|
+
* const components = createShadcnAdapter({
|
|
23
|
+
* Card, CardHeader, CardContent, CardTitle, CardDescription,
|
|
24
|
+
* Table, TableHeader, TableBody, TableRow, TableHead, TableCell,
|
|
25
|
+
* Alert, AlertTitle, AlertDescription,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* function App() {
|
|
29
|
+
* return (
|
|
30
|
+
* <FogUIProvider apiKey="fog_xxx" components={components}>
|
|
31
|
+
* <Chat />
|
|
32
|
+
* </FogUIProvider>
|
|
33
|
+
* );
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The Shadcn components you need to provide.
|
|
40
|
+
* All are optional - only provide what you have installed.
|
|
41
|
+
*/
|
|
42
|
+
interface ShadcnComponents {
|
|
43
|
+
Card?: React.ComponentType<any>;
|
|
44
|
+
CardHeader?: React.ComponentType<any>;
|
|
45
|
+
CardContent?: React.ComponentType<any>;
|
|
46
|
+
CardTitle?: React.ComponentType<any>;
|
|
47
|
+
CardDescription?: React.ComponentType<any>;
|
|
48
|
+
CardFooter?: React.ComponentType<any>;
|
|
49
|
+
Table?: React.ComponentType<any>;
|
|
50
|
+
TableHeader?: React.ComponentType<any>;
|
|
51
|
+
TableBody?: React.ComponentType<any>;
|
|
52
|
+
TableRow?: React.ComponentType<any>;
|
|
53
|
+
TableHead?: React.ComponentType<any>;
|
|
54
|
+
TableCell?: React.ComponentType<any>;
|
|
55
|
+
Alert?: React.ComponentType<any>;
|
|
56
|
+
AlertTitle?: React.ComponentType<any>;
|
|
57
|
+
AlertDescription?: React.ComponentType<any>;
|
|
58
|
+
Badge?: React.ComponentType<any>;
|
|
59
|
+
ScrollArea?: React.ComponentType<any>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a FogUI component registry from Shadcn components.
|
|
63
|
+
*
|
|
64
|
+
* @param components - Your Shadcn UI components
|
|
65
|
+
* @returns A ComponentRegistry for use with FogUIProvider
|
|
66
|
+
*/
|
|
67
|
+
declare function createShadcnAdapter(components: ShadcnComponents): ComponentRegistry;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Headless Adapter for FogUI
|
|
71
|
+
*
|
|
72
|
+
* This adapter provides maximum flexibility by giving you render props / hooks
|
|
73
|
+
* for each component type. You bring your own markup and styling.
|
|
74
|
+
* Perfect for Tailwind CSS, custom design systems, or any UI approach.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* import { FogUIProvider } from '@fogui/react';
|
|
79
|
+
* import { createHeadlessAdapter } from '@fogui/react/adapters';
|
|
80
|
+
*
|
|
81
|
+
* const components = createHeadlessAdapter({
|
|
82
|
+
* card: ({ title, description, data, children }) => (
|
|
83
|
+
* <div className="rounded-lg border p-4 shadow-sm">
|
|
84
|
+
* {title && <h3 className="font-bold text-lg">{title}</h3>}
|
|
85
|
+
* {description && <p className="text-gray-600">{description}</p>}
|
|
86
|
+
* {children}
|
|
87
|
+
* </div>
|
|
88
|
+
* ),
|
|
89
|
+
* table: ({ columns, rows }) => (
|
|
90
|
+
* <table className="w-full border-collapse">
|
|
91
|
+
* <thead>
|
|
92
|
+
* <tr>{columns.map(col => <th key={col}>{col}</th>)}</tr>
|
|
93
|
+
* </thead>
|
|
94
|
+
* <tbody>
|
|
95
|
+
* {rows.map((row, i) => (
|
|
96
|
+
* <tr key={i}>
|
|
97
|
+
* {columns.map(col => <td key={col}>{row[col]}</td>)}
|
|
98
|
+
* </tr>
|
|
99
|
+
* ))}
|
|
100
|
+
* </tbody>
|
|
101
|
+
* </table>
|
|
102
|
+
* ),
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* function App() {
|
|
106
|
+
* return (
|
|
107
|
+
* <FogUIProvider apiKey="fog_xxx" components={components}>
|
|
108
|
+
* <Chat />
|
|
109
|
+
* </FogUIProvider>
|
|
110
|
+
* );
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Configuration for creating a headless adapter.
|
|
117
|
+
* Each component is a simple React component that receives typed props.
|
|
118
|
+
*/
|
|
119
|
+
interface HeadlessConfig {
|
|
120
|
+
/** Custom card component */
|
|
121
|
+
card?: React.ComponentType<CardProps>;
|
|
122
|
+
/** Custom list component */
|
|
123
|
+
list?: React.ComponentType<ListProps>;
|
|
124
|
+
/** Custom table component */
|
|
125
|
+
table?: React.ComponentType<TableProps>;
|
|
126
|
+
/** Custom callout/alert component */
|
|
127
|
+
callout?: React.ComponentType<CalloutProps>;
|
|
128
|
+
/** Additional custom components */
|
|
129
|
+
[key: string]: React.ComponentType<any> | undefined;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Creates a FogUI component registry from custom components.
|
|
133
|
+
* This is the most flexible adapter - you provide complete components.
|
|
134
|
+
*
|
|
135
|
+
* @param config - Your custom component implementations
|
|
136
|
+
* @returns A ComponentRegistry for use with FogUIProvider
|
|
137
|
+
*/
|
|
138
|
+
declare function createHeadlessAdapter(config: HeadlessConfig): ComponentRegistry;
|
|
139
|
+
|
|
140
|
+
export { type HeadlessConfig, type ShadcnComponents, createHeadlessAdapter, createShadcnAdapter };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { k as ComponentRegistry, h as CardProps, L as ListProps, i as TableProps, j as CalloutProps } from '../ComponentRegistry-BFgVIcHz.js';
|
|
3
|
+
import 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shadcn/Radix UI Adapter for FogUI
|
|
7
|
+
*
|
|
8
|
+
* This adapter creates a component registry that maps FogUI component types
|
|
9
|
+
* to Shadcn UI components. Since Shadcn components are copied into your project
|
|
10
|
+
* (not installed from npm), you pass your components to createShadcnAdapter().
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { FogUIProvider } from '@fogui/react';
|
|
15
|
+
* import { createShadcnAdapter } from '@fogui/react/adapters';
|
|
16
|
+
*
|
|
17
|
+
* // Import YOUR Shadcn components
|
|
18
|
+
* import { Card, CardHeader, CardContent, CardTitle, CardDescription } from '@/components/ui/card';
|
|
19
|
+
* import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from '@/components/ui/table';
|
|
20
|
+
* import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert';
|
|
21
|
+
*
|
|
22
|
+
* const components = createShadcnAdapter({
|
|
23
|
+
* Card, CardHeader, CardContent, CardTitle, CardDescription,
|
|
24
|
+
* Table, TableHeader, TableBody, TableRow, TableHead, TableCell,
|
|
25
|
+
* Alert, AlertTitle, AlertDescription,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* function App() {
|
|
29
|
+
* return (
|
|
30
|
+
* <FogUIProvider apiKey="fog_xxx" components={components}>
|
|
31
|
+
* <Chat />
|
|
32
|
+
* </FogUIProvider>
|
|
33
|
+
* );
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The Shadcn components you need to provide.
|
|
40
|
+
* All are optional - only provide what you have installed.
|
|
41
|
+
*/
|
|
42
|
+
interface ShadcnComponents {
|
|
43
|
+
Card?: React.ComponentType<any>;
|
|
44
|
+
CardHeader?: React.ComponentType<any>;
|
|
45
|
+
CardContent?: React.ComponentType<any>;
|
|
46
|
+
CardTitle?: React.ComponentType<any>;
|
|
47
|
+
CardDescription?: React.ComponentType<any>;
|
|
48
|
+
CardFooter?: React.ComponentType<any>;
|
|
49
|
+
Table?: React.ComponentType<any>;
|
|
50
|
+
TableHeader?: React.ComponentType<any>;
|
|
51
|
+
TableBody?: React.ComponentType<any>;
|
|
52
|
+
TableRow?: React.ComponentType<any>;
|
|
53
|
+
TableHead?: React.ComponentType<any>;
|
|
54
|
+
TableCell?: React.ComponentType<any>;
|
|
55
|
+
Alert?: React.ComponentType<any>;
|
|
56
|
+
AlertTitle?: React.ComponentType<any>;
|
|
57
|
+
AlertDescription?: React.ComponentType<any>;
|
|
58
|
+
Badge?: React.ComponentType<any>;
|
|
59
|
+
ScrollArea?: React.ComponentType<any>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a FogUI component registry from Shadcn components.
|
|
63
|
+
*
|
|
64
|
+
* @param components - Your Shadcn UI components
|
|
65
|
+
* @returns A ComponentRegistry for use with FogUIProvider
|
|
66
|
+
*/
|
|
67
|
+
declare function createShadcnAdapter(components: ShadcnComponents): ComponentRegistry;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Headless Adapter for FogUI
|
|
71
|
+
*
|
|
72
|
+
* This adapter provides maximum flexibility by giving you render props / hooks
|
|
73
|
+
* for each component type. You bring your own markup and styling.
|
|
74
|
+
* Perfect for Tailwind CSS, custom design systems, or any UI approach.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* import { FogUIProvider } from '@fogui/react';
|
|
79
|
+
* import { createHeadlessAdapter } from '@fogui/react/adapters';
|
|
80
|
+
*
|
|
81
|
+
* const components = createHeadlessAdapter({
|
|
82
|
+
* card: ({ title, description, data, children }) => (
|
|
83
|
+
* <div className="rounded-lg border p-4 shadow-sm">
|
|
84
|
+
* {title && <h3 className="font-bold text-lg">{title}</h3>}
|
|
85
|
+
* {description && <p className="text-gray-600">{description}</p>}
|
|
86
|
+
* {children}
|
|
87
|
+
* </div>
|
|
88
|
+
* ),
|
|
89
|
+
* table: ({ columns, rows }) => (
|
|
90
|
+
* <table className="w-full border-collapse">
|
|
91
|
+
* <thead>
|
|
92
|
+
* <tr>{columns.map(col => <th key={col}>{col}</th>)}</tr>
|
|
93
|
+
* </thead>
|
|
94
|
+
* <tbody>
|
|
95
|
+
* {rows.map((row, i) => (
|
|
96
|
+
* <tr key={i}>
|
|
97
|
+
* {columns.map(col => <td key={col}>{row[col]}</td>)}
|
|
98
|
+
* </tr>
|
|
99
|
+
* ))}
|
|
100
|
+
* </tbody>
|
|
101
|
+
* </table>
|
|
102
|
+
* ),
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* function App() {
|
|
106
|
+
* return (
|
|
107
|
+
* <FogUIProvider apiKey="fog_xxx" components={components}>
|
|
108
|
+
* <Chat />
|
|
109
|
+
* </FogUIProvider>
|
|
110
|
+
* );
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Configuration for creating a headless adapter.
|
|
117
|
+
* Each component is a simple React component that receives typed props.
|
|
118
|
+
*/
|
|
119
|
+
interface HeadlessConfig {
|
|
120
|
+
/** Custom card component */
|
|
121
|
+
card?: React.ComponentType<CardProps>;
|
|
122
|
+
/** Custom list component */
|
|
123
|
+
list?: React.ComponentType<ListProps>;
|
|
124
|
+
/** Custom table component */
|
|
125
|
+
table?: React.ComponentType<TableProps>;
|
|
126
|
+
/** Custom callout/alert component */
|
|
127
|
+
callout?: React.ComponentType<CalloutProps>;
|
|
128
|
+
/** Additional custom components */
|
|
129
|
+
[key: string]: React.ComponentType<any> | undefined;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Creates a FogUI component registry from custom components.
|
|
133
|
+
* This is the most flexible adapter - you provide complete components.
|
|
134
|
+
*
|
|
135
|
+
* @param config - Your custom component implementations
|
|
136
|
+
* @returns A ComponentRegistry for use with FogUIProvider
|
|
137
|
+
*/
|
|
138
|
+
declare function createHeadlessAdapter(config: HeadlessConfig): ComponentRegistry;
|
|
139
|
+
|
|
140
|
+
export { type HeadlessConfig, type ShadcnComponents, createHeadlessAdapter, createShadcnAdapter };
|