You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -166,153 +166,43 @@ To make the picker visible, set the `visible` property of the `drive-picker` ele
166
166
167
167
After the picker dialog has been closed, the `visible` property will be reset to `false`.
168
168
169
-
### React and JSX
169
+
### React
170
170
171
-
To use the component in a React application, you can extend the global `JSX` namespace as follows:
171
+
For React applications, we recommend using the official React wrapper package: [`@googleworkspace/drive-picker-react`](https://www.npmjs.com/package/@googleworkspace/drive-picker-react).
The above snippet can be added to a declaration file (e.g. `app.d.ts`) in your React project.
199
-
200
-
#### Using Events in React/Next.js
201
-
202
-
When working with React or Next.js, you need to use `useEffect` and `useRef` to properly attach event listeners to the web component. Here's a complete example:
1.**Dynamic import**: In Next.js, import the component dynamically inside `useEffect` to avoid server-side rendering issues, since web components need to run in the browser.
280
-
281
-
2.**Proper cleanup**: Always remove event listeners in the cleanup function to prevent memory leaks.
282
-
283
-
3.**Wait for the element**: Make sure the ref is populated before adding event listeners.
173
+
Please refer to the [package documentation](../drive-picker-react/README.md) for usage instructions.
284
174
285
175
### Content Security Policy (CSP)
286
176
287
177
This library dynamically loads the Google API scripts (`https://apis.google.com/js/api.js` and `https://accounts.google.com/gsi/client`) if they are not already present. This may violate strict CSP settings that disallow dynamic script injection or restrict script sources.
288
178
289
179
To use this library in a strict CSP environment:
290
180
291
-
1.**Pre-load the scripts**: Manually include the Google API scripts in your HTML using `<script>` tags that comply with your CSP (e.g., using a `nonce` or allowing the domain).
181
+
1.**Pre-load the scripts**: Manually include the Google API scripts in your HTML using `<script>` tags that comply with your CSP (e.g., using a `nonce` or allowing the domain).
2. **Ensure global objects are available**: The library checks for `window.gapi` and `window.google.accounts.oauth2`. If these are present, it skips the dynamic injection.
188
+
2.**Ensure global objects are available**: The library checks for `window.gapi` and `window.google.accounts.oauth2`. If these are present, it skips the dynamic injection.
299
189
300
-
3. **Allow Google domains in CSP**: You must allow the picker's origin and other Google domains in your `Content-Security-Policy`. Here is a complete example:
190
+
3.**Allow Google domains in CSP**: You must allow the picker's origin and other Google domains in your `Content-Security-Policy`. Here is a complete example:
- The `frame-src` domains are required for the Picker iframe and authentication. The exact domains may vary, but these are the most common.
315
-
- `style-src: 'unsafe-inline'` may be required for some styles injected by the Picker. For a stricter policy, you can use [nonces](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src#unsafe_inline_styles).
203
+
**Notes:**
204
+
- The `frame-src` domains are required for the Picker iframe and authentication. The exact domains may vary, but these are the most common.
205
+
-`style-src: 'unsafe-inline'` may be required for some styles injected by the Picker. For a stricter policy, you can use [nonces](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src#unsafe_inline_styles).
316
206
317
207
**Note for Chrome Extensions (Manifest V3):**
318
208
The underlying Google Picker API relies on `gapi`, which is [not supported in Manifest V3 extensions](https://github.com/google/google-api-javascript-client/blob/master/docs/start.md#supported-environments). Therefore, this library may not function in that environment regardless of CSP settings.
0 commit comments