From 8591e3d869eea6455dbfdb04df446aa67864c499 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Tue, 14 Aug 2018 18:02:19 +0300 Subject: [PATCH] fix(Popup): rename onPopupClose to onClose BREAKING CHANGE: Popup onPopupClose prop is renamed to onClick --- docs/immutable-map.md | 10 ++++------ docs/popup.md | 36 +++++++++++++++++------------------ src/components/Popup/index.js | 12 ++++++------ 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/docs/immutable-map.md b/docs/immutable-map.md index 652a3824..4f60312e 100644 --- a/docs/immutable-map.md +++ b/docs/immutable-map.md @@ -1,5 +1,5 @@ ```jsx -const Immutable = require('immutable'); +const Immutable = require("immutable"); initialState = { mapStyle: null, @@ -12,12 +12,10 @@ initialState = { const styleUrl = `https://api.mapbox.com/styles/v1/mapbox/light-v9?access_token=${MAPBOX_ACCESS_TOKEN}`; -if (!state.mapStyle) { +if (!state.mapStyle && setState) { fetch(styleUrl) .then(r => r.json()) - .then(mapStyle => - setState({ mapStyle: Immutable.fromJS(mapStyle) }) - ); + .then(mapStyle => setState({ mapStyle: Immutable.fromJS(mapStyle) })); } setState({ viewport })} {...state.viewport} /> -``` \ No newline at end of file +``` diff --git a/docs/popup.md b/docs/popup.md index 644fd733..8502d2ad 100644 --- a/docs/popup.md +++ b/docs/popup.md @@ -1,28 +1,27 @@ ```jsx -const random = require("@turf/random"); - -const bbox = [-160, -70, 160, 70]; -const [longitude, latitude] = random.randomPosition(bbox); - initialState = { viewport: { latitude: 0, longitude: 0, zoom: 0 }, - isOpenPopup: true, - longitude, - latitude + isOpen: true, + longitude: 0, + latitude: 0 }; -const onClick = () => { - const [longitude, latitude] = random.randomPosition(bbox); - setState({ longitude, latitude, isOpenPopup: true }); +const onClick = ({ lngLat }) => { + setState(state => ({ + ...state, + longitude: lngLat.lng, + latitude: lngLat.lat, + isOpen: true + })); }; -const onPopupClose = () => { - setState({ isOpenPopup: false }); -} +const onClose = () => { + setState(state => ({ ...state, isOpen: false })); +}; const Element =
Popup
; @@ -33,15 +32,14 @@ const Element =
Popup
; onClick={onClick} {...state.viewport} > -{ - state.isOpenPopup && + {state.isOpen && ( - } -
; + )} + ``` diff --git a/src/components/Popup/index.js b/src/components/Popup/index.js index 27e9f208..83383e1b 100644 --- a/src/components/Popup/index.js +++ b/src/components/Popup/index.js @@ -23,8 +23,8 @@ type Props = { /* If true, the popup will closed when the map is clicked. */ closeOnClick?: boolean, - /** The onPopupClose callback is fired when the popup closed */ - onPopupClose?: Function, + /** The onClose callback is fired when the popup closed */ + onClose?: Function, /* * A string indicating the part of the Popup that should be positioned closest to the coordinate @@ -56,7 +56,7 @@ class Popup extends PureComponent { static defaultProps = { closeButton: true, closeOnClick: true, - onPopupClose: null, + onClose: null, anchor: null, offset: null }; @@ -69,7 +69,7 @@ class Popup extends PureComponent { offset, closeButton, closeOnClick, - onPopupClose, + onClose, anchor } = this.props; @@ -80,8 +80,8 @@ class Popup extends PureComponent { popup.setLngLat([longitude, latitude]).addTo(this._map); popup.setDOMContent(div); - if (onPopupClose) { - popup.on('close', onPopupClose); + if (onClose) { + popup.on('close', onClose); } this._popup = popup;