From b99fd14e4b124b18734c723f3a9f43b5499b2d73 Mon Sep 17 00:00:00 2001 From: Tom Chen Date: Fri, 7 Aug 2015 19:11:15 +0800 Subject: [PATCH] feat(Rectangle): add new componet * Thanks to @alistairjcbrown * Closes #80 --- src/Rectangle.js | 64 ++++++++++++++++++++++++ src/creators/RectangleCreator.js | 74 ++++++++++++++++++++++++++++ src/eventLists/RectangleEventList.js | 16 ++++++ src/index.js | 1 + 4 files changed, 155 insertions(+) create mode 100644 src/Rectangle.js create mode 100644 src/creators/RectangleCreator.js create mode 100644 src/eventLists/RectangleEventList.js diff --git a/src/Rectangle.js b/src/Rectangle.js new file mode 100644 index 00000000..d894fb62 --- /dev/null +++ b/src/Rectangle.js @@ -0,0 +1,64 @@ +import { + default as React, + Component, +} from "react"; + +import { + default as RectangleCreator, + rectangleDefaultPropTypes, + rectangleControlledPropTypes, + rectangleEventPropTypes +} from "./creators/_RectangleCreator"; + +/* + * Original author: @alistairjcbrown + * Original PR: https://github.com/tomchentw/react-google-maps/pull/80 + */ +export default class Rectangle extends Component { + static propTypes = { + // Uncontrolled default[props] - used only in componentDidMount + ...rectangleDefaultPropTypes, + // Controlled [props] - used in componentDidMount/componentDidUpdate + ...rectangleControlledPropTypes, + // Event [onEventName] + ...rectangleEventPropTypes, + } + + // Public APIs + // + // https://developers.google.com/maps/documentation/javascript/3.exp/reference#Rectangle + // + // [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }).filter(function(it){ return it.match(/^get/) && !it.match(/^getMap/); }) + getBounds () { return this.state.rectangle.getBounds(); } + + getDraggable () { return this.state.rectangle.getDraggable(); } + + getEditable () { return this.state.rectangle.getEditable(); } + + getVisible () { return this.state.rectangle.getVisible(); } + // END - Public APIs + // + // https://developers.google.com/maps/documentation/javascript/3.exp/reference#Rectangle + + state = { + } + + componentDidMount () { + const {mapHolderRef, ...rectangleProps} = this.props; + const rectangle = RectangleCreator._createRectangle(mapHolderRef, rectangleProps); + + this.setState({ rectangle }); + } + + render () { + if (this.state.rectangle) { + return ( + + {this.props.children} + + ); + } else { + return (