@gravity-ai/react 1.1.4 → 1.1.6
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 +149 -5
- package/dist/index.d.mts +102 -115
- package/dist/index.d.ts +102 -115
- package/dist/index.js +1217 -156
- package/dist/index.mjs +1216 -155
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,154 +1,142 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { CSSProperties, ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Ad response from the Gravity API
|
|
6
|
-
* This mirrors the type from @gravity-ai/api for convenience
|
|
7
|
-
*/
|
|
8
4
|
interface AdResponse {
|
|
9
|
-
/** The advertisement copy text */
|
|
10
5
|
adText: string;
|
|
11
|
-
/** Ad title */
|
|
12
6
|
title?: string;
|
|
13
|
-
/** Call-to-action text (e.g., 'Learn More', 'Shop Now') */
|
|
14
7
|
cta?: string;
|
|
15
|
-
/** Brand/advertiser name */
|
|
16
8
|
brandName?: string;
|
|
17
|
-
/** Landing page URL */
|
|
18
9
|
url?: string;
|
|
19
|
-
/** Favicon URL */
|
|
20
10
|
favicon?: string;
|
|
21
|
-
/** Impression tracking URL - fire this when ad is displayed */
|
|
22
11
|
impUrl?: string;
|
|
23
|
-
/** Click-through tracking URL - use this as href for ad clicks */
|
|
24
12
|
clickUrl?: string;
|
|
25
13
|
}
|
|
14
|
+
type GravityAdVariant = 'card' | 'inline' | 'minimal' | 'bubble' | 'contextual' | 'native' | 'footnote' | 'quote' | 'suggestion' | 'accent' | 'side-panel' | 'labeled' | 'spotlight' | 'embed' | 'split-action' | 'pill' | 'banner' | 'divider' | 'toolbar' | 'tooltip' | 'notification' | 'hyperlink' | 'text-link';
|
|
26
15
|
/**
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
type AdSize = 'small' | 'medium' | 'large' | 'responsive';
|
|
34
|
-
/**
|
|
35
|
-
* Props for the AdBanner component
|
|
16
|
+
* Style + className overrides for individual elements inside `<GravityAd />`.
|
|
17
|
+
*
|
|
18
|
+
* Each key maps 1:1 to a DOM element in the component's JSX tree.
|
|
19
|
+
* Pass `style` to merge onto the element's inline styles, or `className`
|
|
20
|
+
* to append a CSS class.
|
|
36
21
|
*/
|
|
37
|
-
interface
|
|
38
|
-
/**
|
|
22
|
+
interface GravityAdSlotProps {
|
|
23
|
+
/** Outer `<a>` wrapper (same as the top-level `style`/`className` props) */
|
|
24
|
+
container?: {
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
className?: string;
|
|
27
|
+
};
|
|
28
|
+
/** Inner padding/layout wrapper */
|
|
29
|
+
inner?: {
|
|
30
|
+
style?: CSSProperties;
|
|
31
|
+
className?: string;
|
|
32
|
+
};
|
|
33
|
+
/** Header row (favicon + brand + label) */
|
|
34
|
+
header?: {
|
|
35
|
+
style?: CSSProperties;
|
|
36
|
+
className?: string;
|
|
37
|
+
};
|
|
38
|
+
/** Favicon `<img>` */
|
|
39
|
+
favicon?: {
|
|
40
|
+
style?: CSSProperties;
|
|
41
|
+
className?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Brand name `<span>` */
|
|
44
|
+
brand?: {
|
|
45
|
+
style?: CSSProperties;
|
|
46
|
+
className?: string;
|
|
47
|
+
};
|
|
48
|
+
/** "Sponsored" label `<span>` */
|
|
49
|
+
label?: {
|
|
50
|
+
style?: CSSProperties;
|
|
51
|
+
className?: string;
|
|
52
|
+
};
|
|
53
|
+
/** Body wrapper (title + text) */
|
|
54
|
+
body?: {
|
|
55
|
+
style?: CSSProperties;
|
|
56
|
+
className?: string;
|
|
57
|
+
};
|
|
58
|
+
/** Title `<p>` */
|
|
59
|
+
title?: {
|
|
60
|
+
style?: CSSProperties;
|
|
61
|
+
className?: string;
|
|
62
|
+
};
|
|
63
|
+
/** Ad text `<p>` */
|
|
64
|
+
text?: {
|
|
65
|
+
style?: CSSProperties;
|
|
66
|
+
className?: string;
|
|
67
|
+
};
|
|
68
|
+
/** CTA button `<span>` */
|
|
69
|
+
cta?: {
|
|
70
|
+
style?: CSSProperties;
|
|
71
|
+
className?: string;
|
|
72
|
+
};
|
|
73
|
+
/** Icon wrapper (larger background container around favicon) */
|
|
74
|
+
iconWrapper?: {
|
|
75
|
+
style?: CSSProperties;
|
|
76
|
+
className?: string;
|
|
77
|
+
};
|
|
78
|
+
/** Colored accent bar (top of `accent` variant) */
|
|
79
|
+
accentBar?: {
|
|
80
|
+
style?: CSSProperties;
|
|
81
|
+
className?: string;
|
|
82
|
+
};
|
|
83
|
+
/** Secondary CTA (`split-action` variant) */
|
|
84
|
+
secondaryCta?: {
|
|
85
|
+
style?: CSSProperties;
|
|
86
|
+
className?: string;
|
|
87
|
+
};
|
|
88
|
+
/** Footer area */
|
|
89
|
+
footer?: {
|
|
90
|
+
style?: CSSProperties;
|
|
91
|
+
className?: string;
|
|
92
|
+
};
|
|
93
|
+
/** Tooltip arrow element */
|
|
94
|
+
arrow?: {
|
|
95
|
+
style?: CSSProperties;
|
|
96
|
+
className?: string;
|
|
97
|
+
};
|
|
98
|
+
/** Context header text (`contextual` variant) */
|
|
99
|
+
contextHeader?: {
|
|
100
|
+
style?: CSSProperties;
|
|
101
|
+
className?: string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
interface GravityAdProps {
|
|
39
105
|
ad: AdResponse | null;
|
|
40
|
-
|
|
41
|
-
theme?: AdTheme;
|
|
42
|
-
/** Size preset */
|
|
43
|
-
size?: AdSize;
|
|
44
|
-
/** Custom class name for the container */
|
|
106
|
+
variant?: GravityAdVariant;
|
|
45
107
|
className?: string;
|
|
46
|
-
/** Custom inline styles for the container */
|
|
47
108
|
style?: CSSProperties;
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
/** Custom class name for the ad text */
|
|
51
|
-
textClassName?: string;
|
|
52
|
-
/** Whether to show the "Sponsored" label */
|
|
109
|
+
/** Targeted style overrides for inner elements. */
|
|
110
|
+
slotProps?: GravityAdSlotProps;
|
|
53
111
|
showLabel?: boolean;
|
|
54
|
-
/** Custom label text (default: "Sponsored") */
|
|
55
112
|
labelText?: string;
|
|
56
|
-
/** Custom styles for the label */
|
|
57
|
-
labelStyle?: CSSProperties;
|
|
58
|
-
/** Custom click handler (called in addition to tracking) */
|
|
59
113
|
onClick?: () => void;
|
|
60
|
-
/** Callback when impression is tracked */
|
|
61
114
|
onImpression?: () => void;
|
|
62
|
-
/** Callback when click is tracked */
|
|
63
115
|
onClickTracked?: () => void;
|
|
64
|
-
/** Custom content to render when ad is null */
|
|
65
116
|
fallback?: ReactNode;
|
|
66
|
-
/** Whether to disable automatic impression tracking */
|
|
67
117
|
disableImpressionTracking?: boolean;
|
|
68
|
-
/** Whether to open link in new tab (default: true) */
|
|
69
118
|
openInNewTab?: boolean;
|
|
70
|
-
/** Custom border radius */
|
|
71
|
-
borderRadius?: number | string;
|
|
72
|
-
/** Custom background color (overrides theme) */
|
|
73
|
-
backgroundColor?: string;
|
|
74
|
-
/** Custom text color (overrides theme) */
|
|
75
|
-
textColor?: string;
|
|
76
|
-
/** Custom accent/brand color */
|
|
77
|
-
accentColor?: string;
|
|
78
119
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Props for the AdText component (minimal text-only rendering)
|
|
81
|
-
*/
|
|
82
120
|
interface AdTextProps {
|
|
83
|
-
/** The ad response from Gravity API */
|
|
84
121
|
ad: AdResponse | null;
|
|
85
|
-
/** Custom class name */
|
|
86
122
|
className?: string;
|
|
87
|
-
/** Custom inline styles */
|
|
88
123
|
style?: CSSProperties;
|
|
89
|
-
/** Custom click handler */
|
|
90
124
|
onClick?: () => void;
|
|
91
|
-
/** Callback when impression is tracked */
|
|
92
125
|
onImpression?: () => void;
|
|
93
|
-
/** Callback when click is tracked */
|
|
94
126
|
onClickTracked?: () => void;
|
|
95
|
-
/** Content to render when ad is null */
|
|
96
127
|
fallback?: ReactNode;
|
|
97
|
-
/** Whether to disable automatic impression tracking */
|
|
98
128
|
disableImpressionTracking?: boolean;
|
|
99
|
-
/** Whether to open link in new tab (default: true) */
|
|
100
129
|
openInNewTab?: boolean;
|
|
101
130
|
}
|
|
102
131
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```tsx
|
|
108
|
-
* import { AdBanner } from '@gravity-ai/react';
|
|
109
|
-
*
|
|
110
|
-
* function MyComponent() {
|
|
111
|
-
* const [ad, setAd] = useState(null);
|
|
112
|
-
*
|
|
113
|
-
* useEffect(() => {
|
|
114
|
-
* client.getAd({ messages, sessionId, placements }).then(res => setAd(res?.[0] || null));
|
|
115
|
-
* }, [messages]);
|
|
116
|
-
*
|
|
117
|
-
* return (
|
|
118
|
-
* <AdBanner
|
|
119
|
-
* ad={ad}
|
|
120
|
-
* theme="dark"
|
|
121
|
-
* size="medium"
|
|
122
|
-
* showLabel
|
|
123
|
-
* />
|
|
124
|
-
* );
|
|
125
|
-
* }
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
declare function AdBanner({ ad, theme, size, className, style, textStyle, textClassName, showLabel, labelText, labelStyle, onClick, onImpression, onClickTracked, fallback, disableImpressionTracking, openInNewTab, borderRadius, backgroundColor, textColor, accentColor, }: AdBannerProps): react_jsx_runtime.JSX.Element;
|
|
129
|
-
declare namespace AdBanner {
|
|
132
|
+
declare function GravityAd({ ad, variant, className, style, slotProps, showLabel, labelText, onClick, onImpression, onClickTracked, fallback, disableImpressionTracking, openInNewTab, }: GravityAdProps): react_jsx_runtime.JSX.Element;
|
|
133
|
+
declare namespace GravityAd {
|
|
130
134
|
var displayName: string;
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* Use this when you want full control over styling and just need the ad text
|
|
137
|
-
* with automatic tracking.
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```tsx
|
|
141
|
-
* import { AdText } from '@gravity-ai/react';
|
|
142
|
-
*
|
|
143
|
-
* function MyComponent() {
|
|
144
|
-
* return (
|
|
145
|
-
* <AdText
|
|
146
|
-
* ad={ad}
|
|
147
|
-
* className="my-custom-ad-style"
|
|
148
|
-
* />
|
|
149
|
-
* );
|
|
150
|
-
* }
|
|
151
|
-
* ```
|
|
138
|
+
* Unstyled text-only ad renderer with automatic tracking.
|
|
139
|
+
* Use when you want full control over presentation.
|
|
152
140
|
*/
|
|
153
141
|
declare function AdText({ ad, className, style, onClick, onImpression, onClickTracked, fallback, disableImpressionTracking, openInNewTab, }: AdTextProps): react_jsx_runtime.JSX.Element;
|
|
154
142
|
declare namespace AdText {
|
|
@@ -161,12 +149,11 @@ interface UseAdTrackingOptions {
|
|
|
161
149
|
onImpression?: () => void;
|
|
162
150
|
onClickTracked?: () => void;
|
|
163
151
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
*/
|
|
167
|
-
declare function useAdTracking({ ad, disableImpressionTracking, onImpression, onClickTracked, }: UseAdTrackingOptions): {
|
|
152
|
+
interface UseAdTrackingReturn {
|
|
153
|
+
containerRef: React.RefObject<HTMLElement | null>;
|
|
168
154
|
handleClick: () => void;
|
|
169
|
-
|
|
170
|
-
}
|
|
155
|
+
impressionFired: boolean;
|
|
156
|
+
}
|
|
157
|
+
declare function useAdTracking({ ad, disableImpressionTracking, onImpression, onClickTracked, }: UseAdTrackingOptions): UseAdTrackingReturn;
|
|
171
158
|
|
|
172
|
-
export {
|
|
159
|
+
export { type AdResponse, AdText, type AdTextProps, GravityAd, type GravityAdProps, type GravityAdSlotProps, type GravityAdVariant, useAdTracking };
|