hocmai-feedback-widget 0.1.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 +129 -0
- package/dist/components/CropOverlay.d.ts +13 -0
- package/dist/components/FeedbackWidget.d.ts +24 -0
- package/dist/context/FeedbackContext.d.ts +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/support-feedback-lib.es.js +2855 -0
- package/dist/support-feedback-lib.umd.js +41 -0
- package/dist/utils/device.d.ts +8 -0
- package/dist/utils/screenshot.d.ts +8 -0
- package/dist/vite.svg +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Support Feedback Widget
|
|
2
|
+
|
|
3
|
+
A React library for collecting user feedback with screenshot capabilities, context support, and interactive region cropping.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
- **Context-Aware**: Support for multiple questions/items on a single page.
|
|
7
|
+
- **Screenshot Capture**: Automatic viewport capture with cropping/highlighting.
|
|
8
|
+
- **Image Protection**: Prevents right-click/download on sensitive screenshots.
|
|
9
|
+
- **Responsive**: Mobile-friendly "bottom sheet" style on small screens.
|
|
10
|
+
- **Customizable**: Theme colors, context data, and error types.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
### Via NPM/Yarn
|
|
15
|
+
```bash
|
|
16
|
+
npm install @antigravity/feedback-widget
|
|
17
|
+
# or
|
|
18
|
+
yarn add @antigravity/feedback-widget
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Local Installation
|
|
22
|
+
1. Build and pack the project:
|
|
23
|
+
```bash
|
|
24
|
+
npm run build
|
|
25
|
+
npm pack
|
|
26
|
+
```
|
|
27
|
+
2. Install the generated `.tgz` file in your target project:
|
|
28
|
+
```bash
|
|
29
|
+
npm install ./path/to/antigravity-feedback-widget-0.1.0.tgz
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### 1. Wrap your application
|
|
35
|
+
Wrap your root component (or the section of the app that needs feedback) with `FeedbackProvider`.
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { FeedbackProvider, type FeedbackData } from '@antigravity/feedback-widget';
|
|
39
|
+
// If styles are not automatically injected by your bundler, you might need:
|
|
40
|
+
// import '@antigravity/feedback-widget/dist/style.css';
|
|
41
|
+
|
|
42
|
+
function App() {
|
|
43
|
+
const handleSubmit = async (data: FeedbackData) => {
|
|
44
|
+
// Send data to your API
|
|
45
|
+
console.log('Feedback submitted:', data);
|
|
46
|
+
// data.screenshots contains base64 images
|
|
47
|
+
// data.deviceInfo contains browser/OS info
|
|
48
|
+
// data.errorType contains the selected category
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<FeedbackProvider onSubmit={handleSubmit} themeColor="#3b82f6">
|
|
53
|
+
<YourAppContent />
|
|
54
|
+
</FeedbackProvider>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Trigger Feedback Form
|
|
60
|
+
Use the `useFeedback` hook anywhere in your child components to open the widget for a specific item.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { useFeedback } from '@antigravity/feedback-widget';
|
|
64
|
+
|
|
65
|
+
const QuestionItem = ({ id, content }) => {
|
|
66
|
+
const { openFeedback } = useFeedback();
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div className="card">
|
|
70
|
+
<p>{content}</p>
|
|
71
|
+
<button
|
|
72
|
+
onClick={() => openFeedback(id, { source: 'QuestionItem', extra: 'details' })}
|
|
73
|
+
>
|
|
74
|
+
Report Error
|
|
75
|
+
</button>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 3. Standalone Component (Legacy)
|
|
82
|
+
If you only need a single widget instance and manage state manually:
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { FeedbackWidget } from '@antigravity/feedback-widget';
|
|
86
|
+
|
|
87
|
+
<FeedbackWidget
|
|
88
|
+
questionId="123"
|
|
89
|
+
isOpen={isOpen}
|
|
90
|
+
onClose={() => setIsOpen(false)}
|
|
91
|
+
onSubmit={handleSubmit}
|
|
92
|
+
/>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Props & Configuration
|
|
96
|
+
|
|
97
|
+
### FeedbackProvider
|
|
98
|
+
| Prop | Type | Required | Description |
|
|
99
|
+
|------|------|----------|-------------|
|
|
100
|
+
| `onSubmit` | `(data: FeedbackData) => Promise<void>` | Yes | Callback when feedback is sent. |
|
|
101
|
+
| `themeColor` | `string` | No | Primary color for buttons/highlights. Default: `#3b82f6`. |
|
|
102
|
+
| `children` | `ReactNode` | Yes | Your application content. |
|
|
103
|
+
|
|
104
|
+
### useFeedback Hook
|
|
105
|
+
Returns an object with:
|
|
106
|
+
- `openFeedback(questionId: string | number, contextData?: any)`: Opens the form with the specified ID.
|
|
107
|
+
### 4. Using with JavaScript (No TypeScript)
|
|
108
|
+
This library is fully compatible with standard JavaScript projects. The usage is identical, just without type annotations.
|
|
109
|
+
|
|
110
|
+
```jsx
|
|
111
|
+
import { FeedbackProvider, useFeedback } from '@antigravity/feedback-widget';
|
|
112
|
+
|
|
113
|
+
function App() {
|
|
114
|
+
const handleSubmit = async (data) => {
|
|
115
|
+
console.log('Feedback submitted:', data);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<FeedbackProvider onSubmit={handleSubmit}>
|
|
120
|
+
<YourAppContent />
|
|
121
|
+
</FeedbackProvider>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Note**: You won't get autocomplete for props, but the functionality remains the same.
|
|
127
|
+
|
|
128
|
+
<!-- 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
|
|
129
|
+
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 -->
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface Rect {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
interface CropOverlayProps {
|
|
9
|
+
onConfirm: (rect: Rect) => void;
|
|
10
|
+
onCancel: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare const CropOverlay: React.FC<CropOverlayProps>;
|
|
13
|
+
export default CropOverlay;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { getDeviceInfo } from '../utils/device';
|
|
3
|
+
export interface FeedbackData {
|
|
4
|
+
idQuestion: string | number;
|
|
5
|
+
idChildQuestion?: string | number;
|
|
6
|
+
errorDescription: string;
|
|
7
|
+
errorType: string;
|
|
8
|
+
listImage: string[];
|
|
9
|
+
deviceInfo: ReturnType<typeof getDeviceInfo>;
|
|
10
|
+
contextData?: any;
|
|
11
|
+
}
|
|
12
|
+
export interface FeedbackProps {
|
|
13
|
+
questionId: string | number;
|
|
14
|
+
questionIdChild?: string | number;
|
|
15
|
+
contextData?: Record<string, any>;
|
|
16
|
+
onSubmit: (data: FeedbackData) => Promise<void>;
|
|
17
|
+
themeColor?: string;
|
|
18
|
+
triggerComponent?: React.ReactNode;
|
|
19
|
+
isOpen?: boolean;
|
|
20
|
+
onOpen?: () => void;
|
|
21
|
+
onClose?: () => void;
|
|
22
|
+
}
|
|
23
|
+
declare const FeedbackWidget: React.FC<FeedbackProps>;
|
|
24
|
+
export default FeedbackWidget;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
import { FeedbackData } from '../components/FeedbackWidget';
|
|
3
|
+
interface FeedbackContextType {
|
|
4
|
+
openFeedback: (questionId: string | number, contextData?: any) => void;
|
|
5
|
+
closeFeedback: () => void;
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
activeQuestionId: string | number | null;
|
|
8
|
+
}
|
|
9
|
+
export declare const useFeedback: () => FeedbackContextType;
|
|
10
|
+
interface FeedbackProviderProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
onSubmit: (data: FeedbackData) => Promise<void>;
|
|
13
|
+
themeColor?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const FeedbackProvider: React.FC<FeedbackProviderProps>;
|
|
16
|
+
export {};
|
package/dist/index.d.ts
ADDED