Skip to content

Commit 16fae9d

Browse files
authored
feat: add @googleworkspace/drive-picker-react package and a React example application. (#92)
1 parent 8dd5d99 commit 16fae9d

28 files changed

+2442
-25
lines changed

.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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<!--
3+
Copyright 2025 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<html lang="en">
19+
<head>
20+
<meta charset="UTF-8" />
21+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
22+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
23+
<title>Google Drive Picker</title>
24+
</head>
25+
<body>
26+
<div id="root"></div>
27+
<script type="module" src="/src/main.tsx"></script>
28+
</body>
29+
</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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {
18+
DrivePicker,
19+
DrivePickerDocsView,
20+
} from "@googleworkspace/drive-picker-react";
21+
import React from "react";
22+
23+
function App() {
24+
const CLIENT_ID = import.meta.env.VITE_CLIENT_ID;
25+
const APP_ID = import.meta.env.VITE_APP_ID;
26+
27+
const [events, setEvents] = React.useState<unknown[]>([]);
28+
29+
return (
30+
<>
31+
<DrivePicker
32+
client-id={CLIENT_ID}
33+
app-id={APP_ID}
34+
onOauthResponse={(e) => setEvents([...events, e.detail])}
35+
onPicked={(e) => setEvents([...events, e.detail])}
36+
onCanceled={(e) => setEvents([...events, e.detail])}
37+
>
38+
<DrivePickerDocsView owned-by-me="true" />
39+
</DrivePicker>
40+
{events.map((event, index) => (
41+
<pre className="event" key={index}>
42+
{JSON.stringify(event, null, 2)}
43+
</pre>
44+
))}
45+
</>
46+
);
47+
}
48+
49+
export default App;

examples/react/src/index.css

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
:root {
18+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
19+
line-height: 1.5;
20+
font-weight: 400;
21+
22+
color-scheme: light dark;
23+
color: rgba(255, 255, 255, 0.87);
24+
background-color: #242424;
25+
26+
font-synthesis: none;
27+
text-rendering: optimizeLegibility;
28+
-webkit-font-smoothing: antialiased;
29+
-moz-osx-font-smoothing: grayscale;
30+
}
31+
32+
a {
33+
font-weight: 500;
34+
color: #646cff;
35+
text-decoration: inherit;
36+
}
37+
a:hover {
38+
color: #535bf2;
39+
}
40+
41+
body {
42+
margin: 0;
43+
display: flex;
44+
place-items: center;
45+
min-width: 320px;
46+
min-height: 100vh;
47+
}
48+
49+
h1 {
50+
font-size: 3.2em;
51+
line-height: 1.1;
52+
}
53+
54+
button {
55+
border-radius: 8px;
56+
border: 1px solid transparent;
57+
padding: 0.6em 1.2em;
58+
font-size: 1em;
59+
font-weight: 500;
60+
font-family: inherit;
61+
background-color: #1a1a1a;
62+
cursor: pointer;
63+
transition: border-color 0.25s;
64+
}
65+
button:hover {
66+
border-color: #646cff;
67+
}
68+
button:focus,
69+
button:focus-visible {
70+
outline: 4px auto -webkit-focus-ring-color;
71+
}
72+
73+
@media (prefers-color-scheme: light) {
74+
:root {
75+
color: #213547;
76+
background-color: #ffffff;
77+
}
78+
a:hover {
79+
color: #747bff;
80+
}
81+
button {
82+
background-color: #f9f9f9;
83+
}
84+
}

examples/react/src/main.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import React from "react";
18+
import ReactDOM from "react-dom/client";
19+
import App from "./App.tsx";
20+
import "./index.css";
21+
22+
const rootElement = document.getElementById("root");
23+
if (!rootElement) {
24+
throw new Error("Failed to find the root element");
25+
}
26+
ReactDOM.createRoot(rootElement).render(
27+
<React.StrictMode>
28+
<App />
29+
</React.StrictMode>,
30+
);

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)