@formsnip/embed 1.0.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 +79 -0
- package/dist/FormSnip.d.ts +4 -0
- package/dist/FormSnip.d.ts.map +1 -0
- package/dist/components/FileUpload.d.ts +16 -0
- package/dist/components/FileUpload.d.ts.map +1 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +517 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +524 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/styles.d.ts +27 -0
- package/dist/utils/styles.d.ts.map +1 -0
- package/dist/utils/upload.d.ts +22 -0
- package/dist/utils/upload.d.ts.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @formsnip/embed
|
|
2
|
+
|
|
3
|
+
React component for embedding FormSnip forms in your React applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @formsnip/embed
|
|
9
|
+
# or
|
|
10
|
+
yarn add @formsnip/embed
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @formsnip/embed
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Basic Example
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { FormSnip } from '@formsnip/embed';
|
|
21
|
+
|
|
22
|
+
function App() {
|
|
23
|
+
return (
|
|
24
|
+
<div>
|
|
25
|
+
<FormSnip formId="your-form-id" />
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### With Custom Base URL
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { FormSnip } from '@formsnip/embed';
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
return (
|
|
38
|
+
<FormSnip
|
|
39
|
+
formId="your-form-id"
|
|
40
|
+
baseUrl="https://api.formsnip.com"
|
|
41
|
+
onSuccess={(data) => {
|
|
42
|
+
console.log('Form submitted successfully!', data);
|
|
43
|
+
}}
|
|
44
|
+
onError={(error) => {
|
|
45
|
+
console.error('Form submission error:', error);
|
|
46
|
+
}}
|
|
47
|
+
className="my-custom-class"
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Props
|
|
54
|
+
|
|
55
|
+
| Prop | Type | Required | Default | Description |
|
|
56
|
+
|------|------|----------|---------|-------------|
|
|
57
|
+
| `formId` | `string` | Yes | - | The ID of the form to embed |
|
|
58
|
+
| `baseUrl` | `string` | No | `'https://api.formsnip.com'` | The base URL of the FormSnip API |
|
|
59
|
+
| `onSuccess` | `(data: any) => void` | No | - | Callback fired when form is submitted successfully |
|
|
60
|
+
| `onError` | `(error: string) => void` | No | - | Callback fired when an error occurs |
|
|
61
|
+
| `className` | `string` | No | `''` | Additional CSS class names for the form container |
|
|
62
|
+
|
|
63
|
+
## Features
|
|
64
|
+
|
|
65
|
+
- ✅ Full form rendering with all field types
|
|
66
|
+
- ✅ File upload support (images, PDFs, videos, audio)
|
|
67
|
+
- ✅ Custom styling support (via embed styles from form settings)
|
|
68
|
+
- ✅ TypeScript support
|
|
69
|
+
- ✅ Error handling
|
|
70
|
+
- ✅ Loading states
|
|
71
|
+
|
|
72
|
+
## Requirements
|
|
73
|
+
|
|
74
|
+
- React >= 16.8.0
|
|
75
|
+
- React DOM >= 16.8.0
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormSnip.d.ts","sourceRoot":"","sources":["../src/FormSnip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAQ,aAAa,EAAsB,MAAM,SAAS,CAAC;AAOlE,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA4W5C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface FileUploadProps {
|
|
3
|
+
id: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
multiple?: boolean;
|
|
8
|
+
onFilesChange: (files: File[]) => void;
|
|
9
|
+
uploadedFiles?: string[];
|
|
10
|
+
uploading?: boolean;
|
|
11
|
+
error?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const FileUpload: React.FC<FileUploadProps>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=FileUpload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileUpload.d.ts","sourceRoot":"","sources":["../../src/components/FileUpload.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAIhD,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACvC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA2NhD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
interface FormField {
|
|
4
|
+
id: string;
|
|
5
|
+
type: 'text' | 'email' | 'textarea' | 'number' | 'date' | 'checkbox' | 'radio' | 'file';
|
|
6
|
+
label: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
required: boolean;
|
|
9
|
+
position: number;
|
|
10
|
+
isActive: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface Form {
|
|
13
|
+
_id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
fields: FormField[];
|
|
17
|
+
submitButtonText: string;
|
|
18
|
+
embedStyles?: {
|
|
19
|
+
field?: {
|
|
20
|
+
backgroundColor?: string;
|
|
21
|
+
color?: string;
|
|
22
|
+
borderColor?: string;
|
|
23
|
+
borderRadius?: number;
|
|
24
|
+
paddingX?: number;
|
|
25
|
+
paddingY?: number;
|
|
26
|
+
};
|
|
27
|
+
button?: {
|
|
28
|
+
backgroundColor?: string;
|
|
29
|
+
color?: string;
|
|
30
|
+
borderColor?: string;
|
|
31
|
+
borderRadius?: number;
|
|
32
|
+
paddingX?: number;
|
|
33
|
+
paddingY?: number;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
interface FormSnipProps {
|
|
38
|
+
formId: string;
|
|
39
|
+
baseUrl?: string;
|
|
40
|
+
onSuccess?: (data: any) => void;
|
|
41
|
+
onError?: (error: string) => void;
|
|
42
|
+
className?: string;
|
|
43
|
+
}
|
|
44
|
+
interface SubmissionResponse {
|
|
45
|
+
success: boolean;
|
|
46
|
+
data?: any;
|
|
47
|
+
message?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare const FormSnip: React.FC<FormSnipProps>;
|
|
51
|
+
|
|
52
|
+
interface FileUploadProps {
|
|
53
|
+
id: string;
|
|
54
|
+
label?: string;
|
|
55
|
+
required?: boolean;
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
multiple?: boolean;
|
|
58
|
+
onFilesChange: (files: File[]) => void;
|
|
59
|
+
uploadedFiles?: string[];
|
|
60
|
+
uploading?: boolean;
|
|
61
|
+
error?: string;
|
|
62
|
+
className?: string;
|
|
63
|
+
}
|
|
64
|
+
declare const FileUpload: React.FC<FileUploadProps>;
|
|
65
|
+
|
|
66
|
+
declare const ALLOWED_FILE_EXTENSIONS = ".jpg,.jpeg,.png,.gif,.webp,.svg,.pdf,.mp4,.mpeg,.mov,.avi,.webm,.mkv,.mp3,.wav,.ogg,.aac,.flac";
|
|
67
|
+
declare const MAX_TOTAL_FILE_SIZE: number;
|
|
68
|
+
interface UploadResult {
|
|
69
|
+
success: boolean;
|
|
70
|
+
fileKey?: string;
|
|
71
|
+
error?: string;
|
|
72
|
+
}
|
|
73
|
+
interface UploadMultipleResult {
|
|
74
|
+
success: boolean;
|
|
75
|
+
fileKeys?: string[];
|
|
76
|
+
errors?: string[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Upload a file to R2 via presigned URL
|
|
80
|
+
*/
|
|
81
|
+
declare function uploadFile(file: File, formId: string, baseUrl: string): Promise<UploadResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Upload multiple files to R2
|
|
84
|
+
*/
|
|
85
|
+
declare function uploadFiles(files: File[], formId: string, baseUrl: string): Promise<UploadMultipleResult>;
|
|
86
|
+
|
|
87
|
+
export { ALLOWED_FILE_EXTENSIONS, FileUpload, FormSnip, MAX_TOTAL_FILE_SIZE, uploadFile, uploadFiles };
|
|
88
|
+
export type { Form, FormField, FormSnipProps, SubmissionResponse, UploadMultipleResult, UploadResult };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}
|