@gravity-ai/react 1.1.0 → 1.1.2
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 +3 -157
- package/dist/index.d.mts +11 -16
- package/dist/index.d.ts +11 -16
- 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
|
-
##
|
|
13
|
+
## Documentation
|
|
14
14
|
|
|
15
|
-
|
|
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
|
-
|
|
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/dist/index.d.mts
CHANGED
|
@@ -4,29 +4,24 @@ import { CSSProperties, ReactNode } from 'react';
|
|
|
4
4
|
/**
|
|
5
5
|
* Ad response from the Gravity API
|
|
6
6
|
* This mirrors the type from @gravity-ai/api for convenience
|
|
7
|
-
* Includes optional v1 fields for backward compatibility
|
|
8
7
|
*/
|
|
9
8
|
interface AdResponse {
|
|
10
9
|
/** The advertisement copy text */
|
|
11
10
|
adText: string;
|
|
12
|
-
/**
|
|
13
|
-
impUrl?: string;
|
|
14
|
-
/** Click-through tracking URL */
|
|
15
|
-
clickUrl?: string;
|
|
16
|
-
/** Payout amount in USD */
|
|
17
|
-
payout?: number;
|
|
18
|
-
/** Unique ad identifier (v1) */
|
|
19
|
-
adId?: string;
|
|
20
|
-
/** Ad title (v1) */
|
|
11
|
+
/** Ad title */
|
|
21
12
|
title?: string;
|
|
22
|
-
/**
|
|
13
|
+
/** Call-to-action text (e.g., 'Learn More', 'Shop Now') */
|
|
14
|
+
cta?: string;
|
|
15
|
+
/** Brand/advertiser name */
|
|
23
16
|
brandName?: string;
|
|
24
|
-
/**
|
|
25
|
-
brandImage?: string;
|
|
26
|
-
/** Landing page URL (v1) */
|
|
17
|
+
/** Landing page URL */
|
|
27
18
|
url?: string;
|
|
28
|
-
/** Favicon URL
|
|
19
|
+
/** Favicon URL */
|
|
29
20
|
favicon?: string;
|
|
21
|
+
/** Impression tracking URL - fire this when ad is displayed */
|
|
22
|
+
impUrl?: string;
|
|
23
|
+
/** Click-through tracking URL - use this as href for ad clicks */
|
|
24
|
+
clickUrl?: string;
|
|
30
25
|
}
|
|
31
26
|
/**
|
|
32
27
|
* Visual theme presets for the ad banner
|
|
@@ -116,7 +111,7 @@ interface AdTextProps {
|
|
|
116
111
|
* const [ad, setAd] = useState(null);
|
|
117
112
|
*
|
|
118
113
|
* useEffect(() => {
|
|
119
|
-
* client.
|
|
114
|
+
* client.getAd({ messages, sessionId, placements }).then(res => setAd(res?.[0] || null));
|
|
120
115
|
* }, [messages]);
|
|
121
116
|
*
|
|
122
117
|
* return (
|
package/dist/index.d.ts
CHANGED
|
@@ -4,29 +4,24 @@ import { CSSProperties, ReactNode } from 'react';
|
|
|
4
4
|
/**
|
|
5
5
|
* Ad response from the Gravity API
|
|
6
6
|
* This mirrors the type from @gravity-ai/api for convenience
|
|
7
|
-
* Includes optional v1 fields for backward compatibility
|
|
8
7
|
*/
|
|
9
8
|
interface AdResponse {
|
|
10
9
|
/** The advertisement copy text */
|
|
11
10
|
adText: string;
|
|
12
|
-
/**
|
|
13
|
-
impUrl?: string;
|
|
14
|
-
/** Click-through tracking URL */
|
|
15
|
-
clickUrl?: string;
|
|
16
|
-
/** Payout amount in USD */
|
|
17
|
-
payout?: number;
|
|
18
|
-
/** Unique ad identifier (v1) */
|
|
19
|
-
adId?: string;
|
|
20
|
-
/** Ad title (v1) */
|
|
11
|
+
/** Ad title */
|
|
21
12
|
title?: string;
|
|
22
|
-
/**
|
|
13
|
+
/** Call-to-action text (e.g., 'Learn More', 'Shop Now') */
|
|
14
|
+
cta?: string;
|
|
15
|
+
/** Brand/advertiser name */
|
|
23
16
|
brandName?: string;
|
|
24
|
-
/**
|
|
25
|
-
brandImage?: string;
|
|
26
|
-
/** Landing page URL (v1) */
|
|
17
|
+
/** Landing page URL */
|
|
27
18
|
url?: string;
|
|
28
|
-
/** Favicon URL
|
|
19
|
+
/** Favicon URL */
|
|
29
20
|
favicon?: string;
|
|
21
|
+
/** Impression tracking URL - fire this when ad is displayed */
|
|
22
|
+
impUrl?: string;
|
|
23
|
+
/** Click-through tracking URL - use this as href for ad clicks */
|
|
24
|
+
clickUrl?: string;
|
|
30
25
|
}
|
|
31
26
|
/**
|
|
32
27
|
* Visual theme presets for the ad banner
|
|
@@ -116,7 +111,7 @@ interface AdTextProps {
|
|
|
116
111
|
* const [ad, setAd] = useState(null);
|
|
117
112
|
*
|
|
118
113
|
* useEffect(() => {
|
|
119
|
-
* client.
|
|
114
|
+
* client.getAd({ messages, sessionId, placements }).then(res => setAd(res?.[0] || null));
|
|
120
115
|
* }, [messages]);
|
|
121
116
|
*
|
|
122
117
|
* return (
|