Skip to content

Commit

Permalink
docs: add hooks & etc content
Browse files Browse the repository at this point in the history
  • Loading branch information
pyjun01 committed Dec 14, 2023
1 parent 85d11e8 commit 84679cb
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 10 deletions.
10 changes: 5 additions & 5 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ export default defineConfig({
label: 'Hooks',
items: [
{
label: 'useMapContext ๐Ÿ› ',
label: 'useMapContext',
link: '/docs/api/use-map-context',
},
{
label: 'useImportLibrary ๐Ÿ› ',
label: 'useImportLibrary',
link: '/docs/api/use-import-library',
},
{
label: 'useApiLoadingStatus ๐Ÿ› ',
label: 'useApiLoadingStatus',
link: '/docs/api/use-api-loading-status',
},
],
Expand All @@ -106,11 +106,11 @@ export default defineConfig({
label: 'etc',
items: [
{
label: 'LoadingStatus ๐Ÿ› ',
label: 'LoadingStatus',
link: '/docs/api/loading-status',
},
{
label: 'appendLibImportScript ๐Ÿ› ',
label: 'appendLibImportScript',
link: '/docs/api/append-lib-import-script',
},
],
Expand Down
39 changes: 39 additions & 0 deletions docs/src/components/api/useMapContext/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useEffect } from "react";
import { GoogleMap, Marker, useMapContext } from "react-google-map-wrapper";

import { Container } from "../../Container";

function MapContent() {
const map = useMapContext();

console.log(map);

useEffect(() => {
setTimeout(() => {
map.fitBounds({
south: 37.5211158,
north: 37.5011158,
west: 127.098167,
east: 127.098167,
})
}, 3000);
}, []);

return (
<Marker lat={37.5111158} lng={127.098167} title='Lotte World' />
)
}

export function UseMapContextEx() {
return (
<Container>
<GoogleMap
className='h-[400px]'
zoom={16}
center={{ lat: 37.5111158, lng: 127.098167 }}
>
<MapContent />
</GoogleMap>
</Container>
)
}
4 changes: 3 additions & 1 deletion docs/src/content/docs/docs/api/append-lib-import-script.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ title: appendLibImportScript
description: description
---

๐Ÿ› ๐Ÿ› ๐Ÿ›  This documentation is currently in progress. ๐Ÿ› ๐Ÿ› ๐Ÿ› 
`appendLibImportScript` function add the inline bootstrap loader script to the header that Load the Maps JavaScript API.

<a href='./google-map-api-loader'>GoogleMapApiLoader</a> call this function, so you don't need to call it yourself. but if you want to preload Google Maps script, you can call it manually in the root file.
10 changes: 9 additions & 1 deletion docs/src/content/docs/docs/api/loading-status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ title: LoadingStatus
description: description
---

๐Ÿ› ๐Ÿ› ๐Ÿ›  This documentation is currently in progress. ๐Ÿ› ๐Ÿ› ๐Ÿ› 
`LoadingStatus` is enum for google map loading status.

```tsx
export enum LoadingStatus {
LOADING = 'LOADING', // loading
FAILURE = 'FAILURE', // loading failed
SUCCESS = 'SUCCESS', // loading finished
}
```
25 changes: 24 additions & 1 deletion docs/src/content/docs/docs/api/use-api-loading-status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,27 @@ title: useApiLoadingStatus
description: description
---

๐Ÿ› ๐Ÿ› ๐Ÿ›  This documentation is currently in progress. ๐Ÿ› ๐Ÿ› ๐Ÿ› 
`useApiLoadingStatus` hooks is used for get current <a href='./loading-status'>LoadingStatus</a>.

In most cases, you won't need to use it.

### Basic Example

```tsx
function App() {
const loadingStatus = useApiLoadingStatus();

return (
<GoogleMapApiLoader
apiKey='YOUR_API_KEY'
>
{
loadingStatus === LoadingStatus.SUCCESS && (
// now you can use Google Map API.
<MyMap />
)
}
</GoogleMapApiLoader>
);
}
```
9 changes: 8 additions & 1 deletion docs/src/content/docs/docs/api/use-import-library.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ title: useImportLibrary
description: description
---

๐Ÿ› ๐Ÿ› ๐Ÿ›  This documentation is currently in progress. ๐Ÿ› ๐Ÿ› ๐Ÿ› 
`useImportLibrary` hooks is a wrapper of <a href='https://developers.google.com/maps/documentation/javascript/reference/top-level#google.maps.importLibrary' target='_blank' rel='noreferrer'>importLibrary</a>

### function type

```ts
<Name extends LibraryName, Lib = LibraryMap[Name]>(libName: Name) => Lib | null;
```

46 changes: 45 additions & 1 deletion docs/src/content/docs/docs/api/use-map-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,48 @@ title: useMapContext
description: description
---

๐Ÿ› ๐Ÿ› ๐Ÿ›  This documentation is currently in progress. ๐Ÿ› ๐Ÿ› ๐Ÿ› 
import { UseMapContextEx } from '../../../../components/api/useMapContext';

`useMapContext` hooks read <a href='https://developers.google.com/maps/documentation/javascript/reference/map#Map' target='_blank' rel='noreferrer'>Map</a> instance of the <a href='./google-map'>GoogleMap</a> component.

### Basic Example

```tsx
function MapContent() {
const map = useMapContext();

console.log(map);

useEffect(() => {
setTimeout(() => { // refresh and watch the example below!
map.fitBounds({
south: 37.5211158,
north: 37.5011158,
west: 127.098167,
east: 127.098167,
})
}, 3000);
}, []);

return (
<Marker lat={37.5111158} lng={127.098167} title='Lotte World' />
);
}

function MyMap() {
return (
<GoogleMap
className='h-[400px]'
center={{ lat: 37.5111158, lng: 127.098167 }}
>
<MapContent />
</GoogleMap>
);
}
```

<UseMapContextEx client:only='react' />

### Alternative

You can use <a href='./google-map'>GoogleMap</a> event callbacks(`onLoad`, etc.) or `ref` props to get a <a href='https://developers.google.com/maps/documentation/javascript/reference/map#Map' target='_blank' rel='noreferrer'>Map</a> instance.

0 comments on commit 84679cb

Please sign in to comment.