@limekex/bugreport-widget-react 0.2.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 +130 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +113 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @limekex/bugreport-widget-react
|
|
2
|
+
|
|
3
|
+
React wrapper for the BugReport Widget SDK. Provides a declarative `<BugReporter>` component with React hooks and SSR support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @limekex/bugreport-widget-react
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @limekex/bugreport-widget-react
|
|
11
|
+
# or
|
|
12
|
+
yarn add @limekex/bugreport-widget-react
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Basic Example
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { BugReporter } from '@limekex/bugreport-widget-react';
|
|
21
|
+
|
|
22
|
+
function App() {
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<h1>My App</h1>
|
|
26
|
+
|
|
27
|
+
<BugReporter
|
|
28
|
+
apiBaseUrl="https://gitreport.betait.no"
|
|
29
|
+
environment="production"
|
|
30
|
+
appVersion="1.2.3"
|
|
31
|
+
commitSha="abc123def"
|
|
32
|
+
/>
|
|
33
|
+
</>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### With Current User
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
<BugReporter
|
|
42
|
+
apiBaseUrl="https://gitreport.betait.no"
|
|
43
|
+
environment="staging"
|
|
44
|
+
currentUser={{
|
|
45
|
+
id: 'user-123',
|
|
46
|
+
email: 'john@example.com',
|
|
47
|
+
name: 'John Doe',
|
|
48
|
+
role: 'admin'
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### With Theme Customization
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
<BugReporter
|
|
57
|
+
apiBaseUrl="https://gitreport.betait.no"
|
|
58
|
+
environment="production"
|
|
59
|
+
theme={{
|
|
60
|
+
primaryColor: '#3b82f6',
|
|
61
|
+
buttonPosition: 'bottom-left',
|
|
62
|
+
zIndex: 9999
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Disabled in Development
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<BugReporter
|
|
71
|
+
apiBaseUrl="https://gitreport.betait.no"
|
|
72
|
+
environment={process.env.NODE_ENV}
|
|
73
|
+
enabled={process.env.NODE_ENV !== 'development'}
|
|
74
|
+
/>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Props
|
|
78
|
+
|
|
79
|
+
All props from the vanilla SDK are supported:
|
|
80
|
+
|
|
81
|
+
| Prop | Type | Required | Description |
|
|
82
|
+
|------|------|----------|-------------|
|
|
83
|
+
| `apiBaseUrl` | `string` | ✅ | Base URL of your bugreport-api service |
|
|
84
|
+
| `environment` | `string` | ✅ | Environment name (e.g., "production", "staging") |
|
|
85
|
+
| `enabled` | `boolean` | ❌ | Whether the widget is active (default: `true`) |
|
|
86
|
+
| `appVersion` | `string` | ❌ | Your app version string |
|
|
87
|
+
| `commitSha` | `string` | ❌ | Git commit SHA of the running build |
|
|
88
|
+
| `buildNumber` | `string` | ❌ | CI build number |
|
|
89
|
+
| `currentUser` | `object` | ❌ | Currently authenticated user |
|
|
90
|
+
| `getTraceContext` | `function` | ❌ | Function returning trace context (OpenTelemetry, Sentry) |
|
|
91
|
+
| `theme` | `object` | ❌ | Theme customization options |
|
|
92
|
+
|
|
93
|
+
## SSR Support
|
|
94
|
+
|
|
95
|
+
This component is **SSR-safe** and will only initialize on the client side. Safe to use with:
|
|
96
|
+
|
|
97
|
+
- Next.js (App Router & Pages Router)
|
|
98
|
+
- Remix
|
|
99
|
+
- Gatsby
|
|
100
|
+
- Any React SSR framework
|
|
101
|
+
|
|
102
|
+
No special configuration needed!
|
|
103
|
+
|
|
104
|
+
## TypeScript
|
|
105
|
+
|
|
106
|
+
Full TypeScript support with type definitions included.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { BugReporter, type BugReporterConfig } from '@limekex/bugreport-widget-react';
|
|
110
|
+
|
|
111
|
+
const config: BugReporterConfig = {
|
|
112
|
+
apiBaseUrl: 'https://gitreport.betait.no',
|
|
113
|
+
environment: 'production',
|
|
114
|
+
appVersion: '1.0.0'
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
<BugReporter {...config} />
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## How It Works
|
|
121
|
+
|
|
122
|
+
The component:
|
|
123
|
+
1. Checks if running in a browser (`typeof window !== 'undefined'`)
|
|
124
|
+
2. Initializes the vanilla SDK on mount
|
|
125
|
+
3. Destroys the widget on unmount
|
|
126
|
+
4. Re-initializes if props change
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React wrapper for the BugReport Widget SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides a declarative <BugReporter> component with SSR support.
|
|
5
|
+
*/
|
|
6
|
+
import { type BugReporterConfig } from '@limekex/bugreport-widget-sdk';
|
|
7
|
+
export type { BugReporterConfig } from '@limekex/bugreport-widget-sdk';
|
|
8
|
+
export interface BugReporterProps extends BugReporterConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Optional className for custom styling (applied to the button container if needed)
|
|
11
|
+
*/
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* BugReporter React Component
|
|
16
|
+
*
|
|
17
|
+
* Renders a floating bug report button that opens a modal when clicked.
|
|
18
|
+
* SSR-safe: will only initialize on the client side.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <BugReporter
|
|
23
|
+
* apiBaseUrl="https://gitreport.betait.no"
|
|
24
|
+
* environment="production"
|
|
25
|
+
* appVersion="1.2.3"
|
|
26
|
+
* />
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function BugReporter(props: BugReporterProps): null;
|
|
30
|
+
/**
|
|
31
|
+
* Hook for programmatic access to the widget (advanced usage)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* function MyComponent() {
|
|
36
|
+
* const { openModal } = useBugReporter({
|
|
37
|
+
* apiBaseUrl: "https://gitreport.betait.no",
|
|
38
|
+
* environment: "production"
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* return <button onClick={openModal}>Report Bug</button>;
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function useBugReporter(config: BugReporterConfig): {
|
|
46
|
+
/**
|
|
47
|
+
* Programmatically open the bug report modal
|
|
48
|
+
*/
|
|
49
|
+
openModal: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Programmatically close the bug report modal
|
|
52
|
+
*/
|
|
53
|
+
closeModal: () => void;
|
|
54
|
+
};
|
|
55
|
+
export default BugReporter;
|
|
56
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAExF,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,QAsClD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,iBAAiB;IA2BpD;;OAEG;;IAIH;;OAEG;;EAKN;AAED,eAAe,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React wrapper for the BugReport Widget SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides a declarative <BugReporter> component with SSR support.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useRef } from 'react';
|
|
7
|
+
import { initBugReporter } from '@limekex/bugreport-widget-sdk';
|
|
8
|
+
/**
|
|
9
|
+
* BugReporter React Component
|
|
10
|
+
*
|
|
11
|
+
* Renders a floating bug report button that opens a modal when clicked.
|
|
12
|
+
* SSR-safe: will only initialize on the client side.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <BugReporter
|
|
17
|
+
* apiBaseUrl="https://gitreport.betait.no"
|
|
18
|
+
* environment="production"
|
|
19
|
+
* appVersion="1.2.3"
|
|
20
|
+
* />
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function BugReporter(props) {
|
|
24
|
+
const { className, ...config } = props;
|
|
25
|
+
const widgetRef = useRef(null);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
// SSR safety: only initialize in browser environment
|
|
28
|
+
if (typeof window === 'undefined') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// Skip if disabled
|
|
32
|
+
if (config.enabled === false) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// Initialize widget
|
|
36
|
+
try {
|
|
37
|
+
widgetRef.current = initBugReporter(config);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error('[BugReporter] Initialization failed:', err);
|
|
41
|
+
}
|
|
42
|
+
// Cleanup on unmount
|
|
43
|
+
return () => {
|
|
44
|
+
if (widgetRef.current) {
|
|
45
|
+
try {
|
|
46
|
+
widgetRef.current.destroy();
|
|
47
|
+
widgetRef.current = null;
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
console.error('[BugReporter] Cleanup failed:', err);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}, [config.apiBaseUrl, config.environment, config.enabled]);
|
|
55
|
+
// This component doesn't render anything visible
|
|
56
|
+
// The SDK injects the button and modal into the DOM
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Hook for programmatic access to the widget (advanced usage)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* function MyComponent() {
|
|
65
|
+
* const { openModal } = useBugReporter({
|
|
66
|
+
* apiBaseUrl: "https://gitreport.betait.no",
|
|
67
|
+
* environment: "production"
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* return <button onClick={openModal}>Report Bug</button>;
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function useBugReporter(config) {
|
|
75
|
+
const widgetRef = useRef(null);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (typeof window === 'undefined' || config.enabled === false) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
widgetRef.current = initBugReporter(config);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
console.error('[useBugReporter] Initialization failed:', err);
|
|
85
|
+
}
|
|
86
|
+
return () => {
|
|
87
|
+
if (widgetRef.current) {
|
|
88
|
+
try {
|
|
89
|
+
widgetRef.current.destroy();
|
|
90
|
+
widgetRef.current = null;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.error('[useBugReporter] Cleanup failed:', err);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}, [config]);
|
|
98
|
+
return {
|
|
99
|
+
/**
|
|
100
|
+
* Programmatically open the bug report modal
|
|
101
|
+
*/
|
|
102
|
+
openModal: () => {
|
|
103
|
+
widgetRef.current?.open();
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* Programmatically close the bug report modal
|
|
107
|
+
*/
|
|
108
|
+
closeModal: () => {
|
|
109
|
+
widgetRef.current?.close();
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export default BugReporter;
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@limekex/bugreport-widget-react",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "React wrapper for the BugReport Widget SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc --project tsconfig.json",
|
|
22
|
+
"dev": "tsc --watch --project tsconfig.json"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"bug-report",
|
|
26
|
+
"bug-reporter",
|
|
27
|
+
"issue-tracker",
|
|
28
|
+
"react",
|
|
29
|
+
"react-component",
|
|
30
|
+
"github-issues"
|
|
31
|
+
],
|
|
32
|
+
"author": "limekex",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/limekex/bugreport-platform.git",
|
|
37
|
+
"directory": "packages/widget-react"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@limekex/bugreport-widget-sdk": "^0.2.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/react": "^18.2.0",
|
|
47
|
+
"react": "^18.2.0",
|
|
48
|
+
"typescript": "^5.9.3"
|
|
49
|
+
}
|
|
50
|
+
}
|