@gravity-ai/react 1.1.0 → 1.1.1

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 (2) hide show
  1. package/README.md +3 -157
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -10,166 +10,12 @@ npm install @gravity-ai/react
10
10
 
11
11
  > **Note:** This package has a peer dependency on React 17+.
12
12
 
13
- ## Quick Start
13
+ ## Documentation
14
14
 
15
- ```tsx
16
- import { Client } from '@gravity-ai/api';
17
- import { AdBanner } from '@gravity-ai/react';
18
- import { useEffect, useState } from 'react';
15
+ For full documentation, examples, and API reference, visit:
19
16
 
20
- const client = new Client('your-api-key');
21
-
22
- function ChatMessage({ messages }) {
23
- const [ad, setAd] = useState(null);
24
-
25
- useEffect(() => {
26
- client.getAd({
27
- messages,
28
- sessionId: 'session-123',
29
- numAds: 1,
30
- ui: {
31
- placements: [{ placement: 'below_response' }]
32
- },
33
- userId: 'user-456',
34
- testAd: true, // Use for testing (no impressions or clicks)
35
- }).then(res => setAd(res?.ads[0] || null));
36
- }, [messages]);
37
-
38
- return (
39
- <div>
40
- {/* Your chat content */}
41
- <AdBanner ad={ad} theme="dark" size="medium" />
42
- </div>
43
- );
44
- }
45
- ```
46
-
47
- ## Components
48
-
49
- ### `<AdBanner />`
50
-
51
- A fully-styled, customizable ad banner component.
52
-
53
- ```tsx
54
- import { AdBanner } from '@gravity-ai/react';
55
-
56
- <AdBanner
57
- ad={ad} // Takes a single ad object (e.g., response.ads[0])
58
- theme="dark" // 'light' | 'dark' | 'minimal' | 'branded'
59
- size="medium" // 'small' | 'medium' | 'large' | 'responsive'
60
- showLabel={true} // Show "Sponsored" label
61
- labelText="Ad" // Custom label text
62
- openInNewTab={true} // Open click URL in new tab
63
- onImpression={() => console.log('Impression tracked')}
64
- onClickTracked={() => console.log('Click tracked')}
65
- />
66
- ```
67
-
68
- #### Props
69
-
70
- | Prop | Type | Default | Description |
71
- |------|------|---------|-------------|
72
- | `ad` | `Ad \| null` | required | A single ad object (e.g., `response.ads[0]`) |
73
- | `theme` | `'light' \| 'dark' \| 'minimal' \| 'branded'` | `'light'` | Visual theme preset |
74
- | `size` | `'small' \| 'medium' \| 'large' \| 'responsive'` | `'medium'` | Size preset |
75
- | `className` | `string` | - | Custom class name for container |
76
- | `style` | `CSSProperties` | - | Custom inline styles |
77
- | `showLabel` | `boolean` | `true` | Show "Sponsored" label |
78
- | `labelText` | `string` | `'Sponsored'` | Custom label text |
79
- | `fallback` | `ReactNode` | `null` | Content when ad is null |
80
- | `openInNewTab` | `boolean` | `true` | Open link in new tab |
81
- | `backgroundColor` | `string` | - | Custom background (overrides theme) |
82
- | `textColor` | `string` | - | Custom text color (overrides theme) |
83
- | `accentColor` | `string` | - | Custom accent color |
84
- | `borderRadius` | `number \| string` | - | Custom border radius |
85
- | `disableImpressionTracking` | `boolean` | `false` | Disable auto impression tracking |
86
- | `onClick` | `() => void` | - | Custom click handler |
87
- | `onImpression` | `() => void` | - | Callback when impression fires |
88
- | `onClickTracked` | `() => void` | - | Callback when click is tracked |
89
-
90
- ### `<AdText />`
91
-
92
- A minimal text-only component for full styling control.
93
-
94
- ```tsx
95
- import { AdText } from '@gravity-ai/react';
96
-
97
- <AdText
98
- ad={adResponse}
99
- className="my-custom-class"
100
- style={{ color: 'blue' }}
101
- />
102
- ```
103
-
104
- #### Props
105
-
106
- | Prop | Type | Default | Description |
107
- |------|------|---------|-------------|
108
- | `ad` | `Ad \| null` | required | A single ad object (e.g., `response.ads[0]`) |
109
- | `className` | `string` | - | Custom class name |
110
- | `style` | `CSSProperties` | - | Custom inline styles |
111
- | `fallback` | `ReactNode` | `null` | Content when ad is null |
112
- | `openInNewTab` | `boolean` | `true` | Open link in new tab |
113
- | `disableImpressionTracking` | `boolean` | `false` | Disable auto tracking |
114
- | `onClick` | `() => void` | - | Custom click handler |
115
- | `onImpression` | `() => void` | - | Callback on impression |
116
- | `onClickTracked` | `() => void` | - | Callback on click |
117
-
118
- ## Hooks
119
-
120
- ### `useAdTracking`
121
-
122
- For building custom ad components with automatic tracking.
123
-
124
- ```tsx
125
- import { useAdTracking } from '@gravity-ai/react';
126
-
127
- function CustomAdComponent({ ad }) {
128
- const { handleClick } = useAdTracking({
129
- ad,
130
- onImpression: () => console.log('Viewed'),
131
- onClickTracked: () => console.log('Clicked'),
132
- });
133
-
134
- return (
135
- <a href={ad.clickUrl} onClick={handleClick}>
136
- {ad.adText}
137
- </a>
138
- );
139
- }
140
- ```
141
-
142
- ## Theming Examples
143
-
144
- ### Dark Theme
145
- ```tsx
146
- <AdBanner ad={ad} theme="dark" />
147
- ```
148
-
149
- ### Custom Colors
150
- ```tsx
151
- <AdBanner
152
- ad={ad}
153
- backgroundColor="#1e1b4b"
154
- textColor="#e0e7ff"
155
- accentColor="#818cf8"
156
- />
157
- ```
158
-
159
- ### Minimal (Inherit Parent Styles)
160
- ```tsx
161
- <AdBanner ad={ad} theme="minimal" showLabel={false} />
162
- ```
163
-
164
- ## TypeScript
165
-
166
- Full TypeScript support with exported types:
167
-
168
- ```tsx
169
- import type { Ad, AdBannerProps, AdTheme, AdSize } from '@gravity-ai/react';
170
- ```
17
+ **[https://www.trygravity.ai/api](https://www.trygravity.ai/api)**
171
18
 
172
19
  ## License
173
20
 
174
21
  MIT
175
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ai/react",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "React components for rendering Gravity AI advertisements",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",