Skip to content

Commit 002a2d4

Browse files
committed
feat: add @googleworkspace/drive-picker-react package and a React example application.
1 parent 8dd5d99 commit 002a2d4

28 files changed

Lines changed: 2266 additions & 25 deletions

.changeset/shiny-crews-play.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@googleworkspace/drive-picker-element": minor
3+
"@googleworkspace/drive-picker-react": minor
4+
"react-example": minor
5+
---
6+
7+
Add React wrapper package.

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# use biomejs
22
**/*.ts
3+
**/*.tsx
34
**/*.mjs
45
**/*.cjs
56
**/*.js

examples/react/.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VITE_CLIENT_ID=your-client-id
2+
VITE_APP_ID=your-app-id

examples/react/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# React Example
2+
3+
This example demonstrates how to use the `@googleworkspace/drive-picker-react` component.
4+
5+
## Setup
6+
7+
1. Create a `.env` file in this directory with the following content:
8+
9+
```
10+
VITE_CLIENT_ID="YOUR_CLIENT_ID"
11+
VITE_APP_ID="YOUR_APP_ID"
12+
```
13+
14+
Replace `YOUR_CLIENT_ID` and `YOUR_APP_ID` with your Google API credentials. See the [Google Picker API documentation](https://developers.google.com/drive/picker/guides/before-you-begin) for more information on how to get these.
15+
16+
2. Install dependencies from the root of the repository:
17+
18+
```sh
19+
pnpm install
20+
```
21+
22+
## Running the example
23+
24+
To run the example, run the following command from the root of the repository:
25+
26+
```sh
27+
pnpm --filter react-example dev
28+
```

examples/react/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Google Drive Picker</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

examples/react/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "react-example",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "tsc && vite build",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"react": "catalog:",
13+
"react-dom": "catalog:",
14+
"@googleworkspace/drive-picker-react": "workspace:*"
15+
},
16+
"devDependencies": {
17+
"@types/react": "catalog:",
18+
"@types/react-dom": "catalog:",
19+
"@vitejs/plugin-react": "^4.2.1",
20+
"typescript": "catalog:",
21+
"vite": "^5.2.0"
22+
}
23+
}

examples/react/src/App.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {
2+
DrivePicker,
3+
DrivePickerDocsView,
4+
} from "@googleworkspace/drive-picker-react";
5+
import React from "react";
6+
7+
function App() {
8+
const CLIENT_ID = import.meta.env.VITE_CLIENT_ID;
9+
const APP_ID = import.meta.env.VITE_APP_ID;
10+
11+
const [events, setEvents] = React.useState<unknown[]>([]);
12+
13+
return (
14+
<>
15+
<DrivePicker
16+
client-id={CLIENT_ID}
17+
app-id={APP_ID}
18+
onOauthResponse={(e) => setEvents([...events, e.detail])}
19+
onPicked={(e) => setEvents([...events, e.detail])}
20+
onCanceled={(e) => setEvents([...events, e.detail])}
21+
>
22+
<DrivePickerDocsView owned-by-me="true" />
23+
</DrivePicker>
24+
{events.map((event, index) => (
25+
<pre className="event" key={index}>
26+
{JSON.stringify(event, null, 2)}
27+
</pre>
28+
))}
29+
</>
30+
);
31+
}
32+
33+
export default App;

examples/react/src/index.css

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
:root {
2+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3+
line-height: 1.5;
4+
font-weight: 400;
5+
6+
color-scheme: light dark;
7+
color: rgba(255, 255, 255, 0.87);
8+
background-color: #242424;
9+
10+
font-synthesis: none;
11+
text-rendering: optimizeLegibility;
12+
-webkit-font-smoothing: antialiased;
13+
-moz-osx-font-smoothing: grayscale;
14+
}
15+
16+
a {
17+
font-weight: 500;
18+
color: #646cff;
19+
text-decoration: inherit;
20+
}
21+
a:hover {
22+
color: #535bf2;
23+
}
24+
25+
body {
26+
margin: 0;
27+
display: flex;
28+
place-items: center;
29+
min-width: 320px;
30+
min-height: 100vh;
31+
}
32+
33+
h1 {
34+
font-size: 3.2em;
35+
line-height: 1.1;
36+
}
37+
38+
button {
39+
border-radius: 8px;
40+
border: 1px solid transparent;
41+
padding: 0.6em 1.2em;
42+
font-size: 1em;
43+
font-weight: 500;
44+
font-family: inherit;
45+
background-color: #1a1a1a;
46+
cursor: pointer;
47+
transition: border-color 0.25s;
48+
}
49+
button:hover {
50+
border-color: #646cff;
51+
}
52+
button:focus,
53+
button:focus-visible {
54+
outline: 4px auto -webkit-focus-ring-color;
55+
}
56+
57+
@media (prefers-color-scheme: light) {
58+
:root {
59+
color: #213547;
60+
background-color: #ffffff;
61+
}
62+
a:hover {
63+
color: #747bff;
64+
}
65+
button {
66+
background-color: #f9f9f9;
67+
}
68+
}

examples/react/src/main.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom/client";
3+
import App from "./App.tsx";
4+
import "./index.css";
5+
6+
const rootElement = document.getElementById("root");
7+
if (!rootElement) {
8+
throw new Error("Failed to find the root element");
9+
}
10+
ReactDOM.createRoot(rootElement).render(
11+
<React.StrictMode>
12+
<App />
13+
</React.StrictMode>,
14+
);

examples/react/tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"useDefineForClassFields": true,
5+
"lib": ["esnext", "DOM", "DOM.Iterable"],
6+
"module": "ESNext",
7+
"skipLibCheck": true,
8+
"moduleResolution": "bundler",
9+
"allowImportingTsExtensions": true,
10+
"resolveJsonModule": true,
11+
"isolatedModules": true,
12+
"noEmit": true,
13+
"jsx": "react-jsx",
14+
"strict": true,
15+
"noUnusedLocals": true,
16+
"noUnusedParameters": true,
17+
"noFallthroughCasesInSwitch": true,
18+
"types": ["vite/client"]
19+
},
20+
"include": ["src"]
21+
}

0 commit comments

Comments
 (0)