Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: standalone examples (CodeSandbox) #48

Merged
merged 19 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ additional scripts to start the example in the context of the library,
using the library itself and its dependencies instead of those locally
installed in the example folder.

> In the future, we want to add codesandbox-links for all examples that
> allow you to instantly start playing around with them.
All examples should contain a link to a CodeSandbox environment where the
example can be played with right away.

## Writing examples

Expand Down
30 changes: 18 additions & 12 deletions examples/_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@
This is an example to show how to setup a simple Google Maps Map with the `<Map/>` component of the Google Maps React
library.

## Instructions
## Google Maps API key

This example does not come with an API key. Running the examples locally requires a valid API key for the Google Maps Platform.
See [the official documentation][get-api-key] on how to create and configure your own key.

The API key has to be provided via an environment variable `GOOGLE_MAPS_API_KEY`. This can be done by creating a
file named `.env` in the example directory with the following content:

```shell title=".env"
GOOGLE_MAPS_API_KEY="<YOUR API KEY HERE>"
```

If you are on the CodeSandbox playground you can also choose to [provide the API key like this](https://codesandbox.io/docs/learn/environment/secrets)

## Development

Go into the example-directory and run

```shell
npm install
```

Then start the example with
To start the example with the local library run

```shell
npm start
npm run start-local
```

Running the examples locally requires a valid API key for the Google Maps Platform.
See [the official documentation][get-api-key] on how to create and configure your own key.

The API key has to be provided via an environment variable `GOOGLE_MAPS_API_KEY`. This can be done by creating a
file named `.env` in the example directory with the following content:

```shell title=".env"
GOOGLE_MAPS_API_KEY="<YOUR API KEY HERE>"
```
The regular `npm start` task is only used for the standalone versions of the example (CodeSandbox for example)

[get-api-key]: https://developers.google.com/maps/documentation/javascript/get-api-key
3 changes: 2 additions & 1 deletion examples/_template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
<body>
<div id="app"></div>
<script type="module">
import '../../website/src/styles.css';
import '@vis.gl/react-google-maps/examples.css';
import {renderToDom} from './src/app';

renderToDom(document.querySelector('#app'));
</script>
</body>
Expand Down
1 change: 1 addition & 0 deletions examples/_template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"scripts": {
"start": "vite",
"start-local": "vite --config ../vite.config.local.js",
"build": "vite build"
}
}
9 changes: 8 additions & 1 deletion examples/_template/src/control-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ function ControlPanel() {
<p>
Add a brief description of the example here and update the link below
</p>
<div className="source-link">

<div className="links">
<a
href="https://codesandbox.io/s/github/visgl/react-google-maps/tree/main/examples/_template"
target="_new">
Try on CodeSandbox ↗
</a>

<a
href="https://github.com/visgl/react-google-maps/tree/main/examples/_template"
target="_new">
Expand Down
8 changes: 1 addition & 7 deletions examples/_template/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import {defineConfig, loadEnv} from 'vite';
import {resolve} from 'node:path';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY} = loadEnv(mode, process.cwd(), '');
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
},
resolve: {
alias: {
'@vis.gl/react-google-maps': resolve('../../src/index.ts')
}
}
};
});
30 changes: 18 additions & 12 deletions examples/basic-map/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@
This is an example to show how to setup a simple Google Maps Map with the `<Map/>` component of the Google Maps React
library.

## Instructions
## Google Maps API key

This example does not come with an API key. Running the examples locally requires a valid API key for the Google Maps Platform.
See [the official documentation][get-api-key] on how to create and configure your own key.

The API key has to be provided via an environment variable `GOOGLE_MAPS_API_KEY`. This can be done by creating a
file named `.env` in the example directory with the following content:

```shell title=".env"
GOOGLE_MAPS_API_KEY="<YOUR API KEY HERE>"
```

If you are on the CodeSandbox playground you can also choose to [provide the API key like this](https://codesandbox.io/docs/learn/environment/secrets)

## Development

Go into the example-directory and run

```shell
npm install
```

Then start the example with
To start the example with the local library run

```shell
npm start
npm run start-local
```

Running the examples locally requires a valid API key for the Google Maps Platform.
See [the official documentation][get-api-key] on how to create and configure your own key.

The API key has to be provided via an environment variable `GOOGLE_MAPS_API_KEY`. This can be done by creating a
file named `.env` in the example directory with the following content:

```shell title=".env"
GOOGLE_MAPS_API_KEY="<YOUR API KEY HERE>"
```
The regular `npm start` task is only used for the standalone versions of the example (CodeSandbox for example)

[get-api-key]: https://developers.google.com/maps/documentation/javascript/get-api-key
5 changes: 3 additions & 2 deletions examples/basic-map/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
</style>
</head>
<body>
<div id="app" style=""></div>
<div id="app"></div>
<script type="module">
import '../../website/src/styles.css';
import '@vis.gl/react-google-maps/examples.css';
import {renderToDom} from './src/app';

renderToDom(document.querySelector('#app'));
</script>
</body>
Expand Down
1 change: 1 addition & 0 deletions examples/basic-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"scripts": {
"start": "vite",
"start-local": "vite --config ../vite.config.local.js",
"build": "vite build"
}
}
8 changes: 7 additions & 1 deletion examples/basic-map/src/control-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ function ControlPanel() {
The simplest example possible, just rendering a google map with some
settings adjusted.
</p>
<div className="source-link">
<div className="links">
<a
href="https://codesandbox.io/s/github/visgl/react-google-maps/tree/main/examples/basic-map"
target="_new">
Try on CodeSandbox ↗
</a>

<a
href="https://github.com/visgl/react-google-maps/tree/main/examples/basic-map"
target="_new">
Expand Down
8 changes: 1 addition & 7 deletions examples/basic-map/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import {defineConfig, loadEnv} from 'vite';
import {resolve} from 'node:path';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY} = loadEnv(mode, process.cwd(), '');
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
},
resolve: {
alias: {
'@vis.gl/react-google-maps': resolve('../../src/index.ts')
}
}
};
});
32 changes: 19 additions & 13 deletions examples/change-map-id/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@

![image](https://user-images.githubusercontent.com/39244966/208682692-d5b23518-9e51-4a87-8121-29f71e41c777.png)

This is an example to show how to setup a simple Google Maps Map with the `<Map/>` component of the Google Maps React
This is an example to show how to change the map id of a simple Google Maps Map with the `<Map/>` component of the Google Maps React
library.

## Instructions
## Google Maps API key

This example does not come with an API key. Running the examples locally requires a valid API key for the Google Maps Platform.
See [the official documentation][get-api-key] on how to create and configure your own key.

The API key has to be provided via an environment variable `GOOGLE_MAPS_API_KEY`. This can be done by creating a
file named `.env` in the example directory with the following content:

```shell title=".env"
GOOGLE_MAPS_API_KEY="<YOUR API KEY HERE>"
```

If you are on the CodeSandbox playground you can also choose to [provide the API key like this](https://codesandbox.io/docs/learn/environment/secrets)

## Development

Go into the example-directory and run

```shell
npm install
```

Then start the example with
To start the example with the local library run

```shell
npm start
npm run start-local
```

Running the examples locally requires a valid API key for the Google Maps Platform.
See [the official documentation][get-api-key] on how to create and configure your own key.

The API key has to be provided via an environment variable `GOOGLE_MAPS_API_KEY`. This can be done by creating a
file named `.env` in the example directory with the following content:

```shell title=".env"
GOOGLE_MAPS_API_KEY="<YOUR API KEY HERE>"
```
The regular `npm start` task is only used for the standalone versions of the example (CodeSandbox for example)

[get-api-key]: https://developers.google.com/maps/documentation/javascript/get-api-key
2 changes: 1 addition & 1 deletion examples/change-map-id/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<body>
<div id="app"></div>
<script type="module">
import '../../website/src/styles.css';
import '@vis.gl/react-google-maps/examples.css';
import {renderToDom} from './src/app';

renderToDom(document.querySelector('#app'));
Expand Down
1 change: 1 addition & 0 deletions examples/change-map-id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"scripts": {
"start": "vite",
"start-local": "vite --config ../vite.config.local.js",
"build": "vite build"
}
}
4 changes: 2 additions & 2 deletions examples/change-map-id/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
} from '@vis.gl/react-google-maps';
import ControlPanel from './control-panel';

const API_KEY = process.env.GOOGLE_MAPS_API_KEY as string;

const MapTypeId = {
HYBRID: 'hybrid',
ROADMAP: 'roadmap',
Expand Down Expand Up @@ -73,6 +71,8 @@ const MAP_CONFIGS: MapConfig[] = [
}
];

const API_KEY = process.env.GOOGLE_MAPS_API_KEY as string;

const App = () => {
const [mapConfig, setMapConfig] = useState<MapConfig>(MAP_CONFIGS[0]);
const [infowindowOpen, setInfowindowOpen] = useState(true);
Expand Down
8 changes: 7 additions & 1 deletion examples/change-map-id/src/control-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ function ControlPanel({
</select>
</div>

<div className="source-link">
<div className="links">
<a
href="https://codesandbox.io/s/github/visgl/react-google-maps/tree/main/examples/change-map-id"
target="_new">
Try on CodeSandbox ↗
</a>

<a
href="https://github.com/visgl/react-google-maps/tree/main/examples/change-map-id"
target="_new">
Expand Down
8 changes: 1 addition & 7 deletions examples/change-map-id/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import {defineConfig, loadEnv} from 'vite';
import {resolve} from 'node:path';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY} = loadEnv(mode, process.cwd(), '');
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
},
resolve: {
alias: {
'@vis.gl/react-google-maps': resolve('../../src/index.ts')
}
}
};
});
30 changes: 18 additions & 12 deletions examples/deckgl-overlay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@ to a `<Map>` component. (using the `GoogleMapsOverlay` from [@deck.gl/google-map

[@deck.gl/google-maps]: https://deck.gl/docs/api-reference/google-maps/overview

## Instructions
## Google Maps API key

This example does not come with an API key. Running the examples locally requires a valid API key for the Google Maps Platform.
See [the official documentation][get-api-key] on how to create and configure your own key.

The API key has to be provided via an environment variable `GOOGLE_MAPS_API_KEY`. This can be done by creating a
file named `.env` in the example directory with the following content:

```shell title=".env"
GOOGLE_MAPS_API_KEY="<YOUR API KEY HERE>"
```

If you are on the CodeSandbox playground you can also choose to [provide the API key like this](https://codesandbox.io/docs/learn/environment/secrets)

## Development

Go into the example-directory and run

```shell
npm install
```

Then start the example with
To start the example with the local library run

```shell
npm start
npm run start-local
```

Running the examples locally requires a valid API key for the Google Maps Platform.
See [the official documentation][get-api-key] on how to create and configure your own key.

The API key has to be provided via an environment variable `GOOGLE_MAPS_API_KEY`. This can be done by creating a
file named `.env` in the example directory with the following content:

```shell title=".env"
GOOGLE_MAPS_API_KEY="<YOUR API KEY HERE>"
```
The regular `npm start` task is only used for the standalone versions of the example (CodeSandbox for example)

[get-api-key]: https://developers.google.com/maps/documentation/javascript/get-api-key
3 changes: 2 additions & 1 deletion examples/deckgl-overlay/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
<body>
<div id="app"></div>
<script type="module">
import '../../website/src/styles.css';
import '@vis.gl/react-google-maps/examples.css';
import {renderToDom} from './src/app';

renderToDom(document.querySelector('#app'));
</script>
</body>
Expand Down
Loading