Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[website] add banner to demo app for survey (#117)
Shan Hebc2fc6c41f87
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.jsindex 3e97d3179..6e809c5da 100644--- a/examples/demo-app/src/app.js+++ b/examples/demo-app/src/app.js@@ -19,8 +19,11 @@// THE SOFTWARE.import React, {Component} from 'react';+import styled from 'styled-components';+import window from 'global/window';import {connect} from 'react-redux';-import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';+import Banner from './components/banner';+import Announcement from './components/announcement';import {loadSampleConfigurations} from './actions';import {replaceLoadDataModal} from './factories/load-data-modal';@@ -40,19 +43,72 @@ import {updateVisData, addDataToMap} from 'kepler.gl/actions';import Processors from 'kepler.gl/processors';/* eslint-enable no-unused-vars */+const bannerHeight = 30;++const GlobalStyleDiv = styled.div`+ font-family: ff-clan-web-pro, 'Helvetica Neue', Helvetica, sans-serif;+ font-weight: 400;+ font-size: 0.875em;+ line-height: 1.71429;++ *,+ *:before,+ *:after {+ -webkit-box-sizing: border-box;+ -moz-box-sizing: border-box;+ box-sizing: border-box;+ }+`;+class App extends Component {+ state = {+ showBanner: false,+ width: window.innerWidth,+ height: window.innerHeight+ };+componentWillMount() {// if we pass an id as part f the url// we ry to fetch along map configurationsconst {params: {id: sampleMapId} = {}} = this.props;this.props.dispatch(loadSampleConfigurations(sampleMapId));+ window.addEventListener('resize', this._onResize);+ this._onResize();}componentDidMount() {+ // delay 2s to show the banner+ if (!window.localStorage.getItem('kgHideBanner')) {+ window.setTimeout(this._showBanner, 3000);+ }// load sample data// this._loadSampleData();}+ componentWillUnmount() {+ window.remmoveEventListener('resize', this._onResize);+ }++ _onResize = () => {+ this.setState({+ width: window.innerWidth,+ height: window.innerHeight+ });+ };++ _showBanner = () => {+ this.setState({showBanner: true});+ };++ _hideBanner = () => {+ this.setState({showBanner: false});+ };++ _disableBanner = () => {+ this._hideBanner();+ window.localStorage.setItem('kgHideBanner', 'true');+ };+_loadSampleData() {this.props.dispatch(updateVisData(@@ -113,23 +169,39 @@ class App extends Component {}render() {+ const {showBanner, width, height} = this.state;return (- <div style={{position: 'absolute', width: '100%', height: '100%'}}>- <AutoSizer>- {({height, width}) => (- <KeplerGl- mapboxApiAccessToken={MAPBOX_TOKEN}- id="map"- /*- * Specify path to keplerGl state, because it is not mount at the root- */- getState={state => state.demo.keplerGl}- width={width}- height={height}- />+ <GlobalStyleDiv>+ <Banner+ show={this.state.showBanner}+ height={bannerHeight}+ onClose={this._hideBanner}+ >+ <Announcement onDisable={this._disableBanner}/>+ </Banner>+ <div+ style={{+ transition: 'margin 1s, height 1s',+ position: 'absolute',+ width: '100%',+ height: showBanner ? `calc(100% - ${bannerHeight}px)` : '100%',+ minHeight: `calc(100% - ${bannerHeight}px)`,+ marginTop: showBanner ? `${bannerHeight}px` : 0+ }}+ >+ <KeplerGl+ mapboxApiAccessToken={MAPBOX_TOKEN}+ id="map"+ /*+ * Specify path to keplerGl state, because it is not mount at the root+ */+ getState={state => state.demo.keplerGl}+ width={width}+ height={height - (showBanner ? bannerHeight : 0)}+ />)}- </AutoSizer>- </div>+ </div>+ </GlobalStyleDiv>);}}@@ -137,4 +209,7 @@ class App extends Component {const mapStateToProps = state => state;const dispatchToProps = dispatch => ({dispatch});-export default connect(mapStateToProps, dispatchToProps)(App);+export default connect(+ mapStateToProps,+ dispatchToProps+)(App);diff --git a/examples/demo-app/src/components/announcement.js b/examples/demo-app/src/components/announcement.jsnew file mode 100644index 000000000..8f623cd87--- /dev/null+++ b/examples/demo-app/src/components/announcement.js@@ -0,0 +1,55 @@+// Copyright (c) 2018 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++import React from 'react';+import styled from 'styled-components';++const StyledText = styled.div`+ font-size: 12px;+`;++const StyledLink = styled.a`+ text-decoration: underline !important;+ color: white;+ font-weight: 500;++ :hover {+ cursor: pointer;+ }+`;++const DisableBanner = styled.div`+ display: inline-block;+ margin-left: 20px;+`;+const FormLink = 'https://docs.google.com/forms/d/1o2VbSIKiRfoTJLi6nGzxNHgDA1Yu-UnNOHglPJvPWpc/edit';++const Announcement = ({onDisable}) => (+ <StyledText>+ <span>Thanks for your interests in kepler.gl. Please help us make it better by taking </span>+ <StyledLink target="_blank" href={FormLink}>this survey</StyledLink>.+ <span> It only takes 5 minutes!</span>+ {onDisable ? <DisableBanner>+ <StyledLink onClick={onDisable}>Already took it</StyledLink>+ </DisableBanner> : null}+ </StyledText>+);++export default Announcement;diff --git a/examples/demo-app/src/components/banner.js b/examples/demo-app/src/components/banner.jsnew file mode 100644index 000000000..d8d016b71--- /dev/null+++ b/examples/demo-app/src/components/banner.js@@ -0,0 +1,56 @@+// Copyright (c) 2018 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++import React from 'react';+import styled from 'styled-components';+import {Icons} from 'kepler.gl/components';++const StyledBanner = styled.div`+ align-items: center;+ background-color: ${props => props.bgColor};+ color: ${props => props.fontColor};+ display: flex;+ height: ${props => props.height}px;+ justify-content: space-between;+ padding: 0 40px;+ position: absolute;+ transition: top 1s;+ width: 100%;+ z-index: 9999;++ svg:hover {+ cursor: pointer;+ }+`;++const Banner = ({bgColor = '#1F7CF4', fontColor = '#FFFFFF', height = 30, children, onClose, show}) => (+ <StyledBanner className="top-banner"+ bgColor={bgColor}+ fontColor={fontColor}+ height={height}+ style={{top: show ? 0 : `-${height}px`}}>+ <div>+ {children}+ </div>+ <Icons.Delete height="14px" onClick={onClose}/>+ </StyledBanner>+);++export default Banner;