Skip to content

Commit

Permalink
docs(README.md): update to get a brief overview
Browse files Browse the repository at this point in the history
* Added "Documentation" section. Ref #128
  • Loading branch information
tomchentw committed Oct 13, 2015
1 parent d1ee981 commit a4a052c
Showing 1 changed file with 83 additions and 7 deletions.
90 changes: 83 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,97 @@
[![Version][npm-image]][npm-url]


## Installation
## Quick start: SimpleMap

Declare your Google Maps components using React components.

```js
import {GoogleMap, Marker} from "react-google-maps";

export default function SimpleMap (props) {
return (
<section style={{height: "100%"}}>
<GoogleMap containerProps={{
style: {
height: "100%",
},
}}
defaultZoom={3}
defaultCenter={{lat: -25.363882, lng: 131.044922}}
onClick={props.onMapClick}
>
{props.markers.map((marker, index) => {
return (
<Marker
{...marker}
onRightclick={() => props.onMarkerRightclick(index)} />
);
})}
</GoogleMap>
</section>
);
}
```


## Documentation

### Rule 1

Define `<GoogleMap>` component in the top level. Use `containerProps`, `containerTagName` to customized the wrapper DOM for the component.

Other components like `<Marker>` belongs to the children of `<GoogleMap>`. You already know this from the example code above.

### Rule 2

Everything in the `Methods` table in the [official documentation](https://developers.google.com/maps/documentation/javascript/3.exp/reference#Marker) of the component could be set via component's *props* directly. For example, a `<Marker>` component has the following *props*:

```sh
npm i --save react-google-maps
```
animation, attribution, clickable, cursor, draggable, icon, label, opacity, options, place, position, shape, title, visible, zIndex
```

### Rule 3

Every props mentioned in __Rule 2__ could be either [controlled](https://facebook.github.io/react/docs/forms.html#controlled-components) or [uncontrolled](https://facebook.github.io/react/docs/forms.html#uncontrolled-components) property. Free to use either one depends on your use case.

## Demo/Examples
### Rule 4

Anything that are inside components' `options` property could __ONLY__ be accessible via `props.options`. It's your responsibility to manage `props.options` object during the React lifetime for your component. My suggestion is, always use __Rule 3__ if possible. Only use `options` when it's necessary.

### Check the examples

Static hosted [demo site][demo] on GitHub. The code is located under [examples/gh-pages][examples_gh_pages] folder.


## Usage

This module requires to be bundled with build tools like [webpack][webpack] or browserify.
`react-google-maps` requires __React 0.14__

```sh
npm install --save react-google-maps
```

All components are available on the top-level export.

```js
import { GoogleMap, Marker, SearchBox } from "react-google-maps";
```

### Optimize bundle size

You could of course import from individual modules to save your [webpack][webpack]'s bundle size.

```js
import GoogleMap from "react-google-maps/lib/GoogleMap"; // Or import {default as GoogleMap} ...
```

### Additional Addons

Some addons component could __ONLY__ be accessible via direct import:

```js
import InfoBox from "react-google-maps/lib/addons/InfoBox";
```


## Development
Expand Down Expand Up @@ -51,7 +127,7 @@ docker-compose build

### With Mac

Install `node@^0.12.4`. Then,
Install `node`. Then,

```shell
npm install
Expand All @@ -64,7 +140,7 @@ Then open [http://localhost:8080/webpack-dev-server/](http://localhost:8080/webp

### With Windows

Install `node@^0.12.4`. Then,
Install `node`. Then,

```shell
npm install
Expand Down

0 comments on commit a4a052c

Please sign in to comment.