3
3
Integrate Typeform Admin UI in your web app - as an iframe or a popup.
4
4
5
5
> [ !WARNING]
6
- > Please keep in mind this is an _ early alpha version_ , and currently we do not provide any support.
6
+ > Please keep in mind this is an _ early version_ , and [ we provide limited support] ( https://github.com/Typeform/button/issues ) at the moment .
7
7
8
- ## Usage
8
+ ## Usage in browser
9
9
10
10
As HTML button:
11
11
@@ -14,7 +14,7 @@ As HTML button:
14
14
<script src =" dist/button.js" ></script >
15
15
<script >
16
16
// you still need to implement the callback in JavaScript
17
- function handleSelect (action , { formId }) {
17
+ function handleSelect ({ action, formId }) {
18
18
console .log (` you have selected form with id ${ formId} ` )
19
19
}
20
20
</script >
@@ -27,27 +27,51 @@ Or using JavaScript:
27
27
<script src =" dist/button.js" ></script >
28
28
<script >
29
29
// you only need to configure settings once
30
- window .tfEmbedAdmin .configure ({ type: ' iframe' })
30
+ window .tfEmbedAdmin .setDefaultConfiguration ({ type: ' iframe' })
31
31
32
- const callback = (action , { formId }) => {
32
+ const callback = ({ action, formId }) => {
33
33
console .log (` you have selected form with id ${ formId} ` )
34
34
}
35
35
36
36
const selectTypeform = () => {
37
- window .tfEmbedAdmin .selectForm (callback)
37
+ window .tfEmbedAdmin .selectForm ({ callback } )
38
38
}
39
39
</script >
40
40
```
41
41
42
+ ## Usage as ESM module
43
+
44
+ Install the package as dependency via ` yarn ` :
45
+
46
+ ``` bash
47
+ yarn add @typeform/button
48
+ ```
49
+
50
+ Then you can use the SDK in your own application, e.g. in React:
51
+
52
+ ``` javascript
53
+ import { selectForm } from ' @typeform/button'
54
+
55
+ export const SelectFormButton = () => {
56
+ const handleSelect = () => {
57
+ selectForm ({
58
+ callback : ({ action, formId }) => console .log (` you just selected form id: ${ formId} ` ),
59
+ })
60
+ }
61
+
62
+ return < button onClick= {handleSelect}> select form< / button>
63
+ }
64
+ ```
65
+
42
66
## Options
43
67
44
68
There are 3 available methods:
45
69
46
- ### configure (config)
70
+ ### setDefaultConfiguration (config)
47
71
48
72
Configure the embed admin settings.
49
73
50
- It accepts ` config ` object:
74
+ It accepts an object with the following props :
51
75
52
76
| name | type | description | default value |
53
77
| ------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
@@ -57,28 +81,32 @@ It accepts `config` object:
57
81
Example with JavaScript:
58
82
59
83
``` javascript
60
- window .tfEmbedAdmin .configure ({
84
+ window .tfEmbedAdmin .setDefaultConfiguration ({
61
85
type: ' iframe' ,
62
86
appName: ' my-app' ,
63
87
})
64
88
```
65
89
66
90
When using HTML API you don't need to call this method separately. You need to specify config options on the button itself.
67
91
68
- ### selectForm(callback)
92
+ ### selectForm({ callback} )
69
93
70
94
Open embed admin to select form or create a new one.
71
95
72
- It accepts ` callback ` method :
96
+ It accepts an object with the following props :
73
97
74
98
| name | type | description |
75
99
| -------- | ------------------------------------------------------- | ----------------------------------------------------------------- |
76
- | callback | ` (action: string, payload: { formId: string }) => void ` | Method to be called when a form is selected in Typeform Admin UI. |
100
+ | callback | ` (payload: { action: string, formId: string }) => void ` | Method to be called when a form is selected in Typeform Admin UI. |
101
+ | type | ` "iframe" \| "popup" ` | Optional. See ` setDefaultConfiguration ` above. |
102
+ | appName | ` string ` | Optional. See ` setDefaultConfiguration ` above. |
77
103
78
104
Example with JavaScript:
79
105
80
106
``` javascript
81
- window .tfEmbedAdmin .selectForm ((action , id ) => console .log (` you just selected form id: ${ id} ` ))
107
+ window .tfEmbedAdmin .selectForm ({
108
+ callback : ({ action, formId }) => console .log (` you just selected form id: ${ formId} ` ),
109
+ })
82
110
```
83
111
84
112
Or with HTML API:
@@ -93,27 +121,32 @@ Or with HTML API:
93
121
select typeform
94
122
</button >
95
123
<script >
96
- function embedAdminCallback () {
124
+ function embedAdminCallback ({ action } ) {
97
125
// callback function needs to be available on global scope (window)
98
126
}
99
127
</script >
100
128
```
101
129
102
- ### editForm(formId, callback)
130
+ ### editForm({ formId, callback } )
103
131
104
132
Open embed admin to edit a specific form.
105
133
106
- It accepts ` formId ` string and ` callback ` method :
134
+ It accepts an object with the following props :
107
135
108
136
| name | type | description |
109
137
| -------- | ------------------------------------------------------- | --------------------------------------------------------------- |
110
138
| formId | ` string ` | ID of the typeform to edit |
111
- | callback | ` (action: string, payload: { formId: string }) => void ` | Method to be called when a form is edited in Typeform Admin UI. |
139
+ | callback | ` (payload: { action: string, formId: string }) => void ` | Method to be called when a form is edited in Typeform Admin UI. |
140
+ | type | ` "iframe" \| "popup" ` | Optional. See ` setDefaultConfiguration ` above. |
141
+ | appName | ` string ` | Optional. See ` setDefaultConfiguration ` above. |
112
142
113
143
Example with JavaScript:
114
144
115
145
``` javascript
116
- window .tfEmbedAdmin .editForm (myTypeformId, (action , id ) => console .log (` you just edited form id: ${ id} ` ))
146
+ window .tfEmbedAdmin .editForm ({
147
+ formId: myTypeformId,
148
+ callback : ({ action, formId }) => console .log (` you just edited form id: ${ formId} ` ),
149
+ })
117
150
```
118
151
119
152
Or with HTML API:
@@ -128,7 +161,7 @@ Or with HTML API:
128
161
edit typeform
129
162
</button >
130
163
<script >
131
- function embedAdminCallback () {
164
+ function embedAdminCallback ({ action, formId } ) {
132
165
// callback function needs to be available on global scope (window)
133
166
}
134
167
</script >
@@ -148,7 +181,7 @@ Or [open the demo in CodeSandbox](https://codesandbox.io/s/github/Typeform/butto
148
181
149
182
## Development
150
183
151
- Requiremenets :
184
+ Requirements :
152
185
153
186
- node >= 20
154
187
- yarn
@@ -173,6 +206,6 @@ yarn start
173
206
174
207
## Support and Contribution
175
208
176
- Please keep in mind this is an _ early alpha version_ , and currently we do not provide any support.
209
+ Please keep in mind this is an _ early version_ , and we provide limited support at the moment .
177
210
178
- However, feel free to [ open a Github Issue with your question] ( https://github.com/Typeform/button/issues ) we are open to discussion.
211
+ However, feel free to [ open a Github Issue with your question] ( https://github.com/Typeform/button/issues ) , we are open to discussion.
0 commit comments