-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from NGMarmaduke/map-controlls
Add Map `Control` and `ControlGroup` components
- Loading branch information
Showing
21 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.root, .map { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
.map { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.root { | ||
background: var(--color-white); | ||
border-color: var(--color-greyLighter); | ||
border-radius: 2px; | ||
border-style: solid; | ||
border-width: 1px; | ||
color: var(--color-grey); | ||
cursor: pointer; | ||
display: inline-block; | ||
font-family: var(--font-avenir); | ||
font-size: var(--fontsize-small-i); | ||
font-weight: 700; | ||
line-height: 1; | ||
padding: var(--size-sm-ii); | ||
text-decoration: none; | ||
text-transform: uppercase; | ||
} | ||
|
||
.root svg { | ||
vertical-align: top; | ||
} | ||
|
||
.root:hover { | ||
background: var(--color-greyLightest); | ||
color: var(--color-greyDark); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { PropTypes } from 'react'; | ||
import cx from 'classnames'; | ||
|
||
import css from './Control.css'; | ||
|
||
const Control = ({ className, children, ...rest }) => ( | ||
<button | ||
className={ cx(css.root, className) } | ||
{ ...rest } | ||
> | ||
{ children } | ||
</button> | ||
); | ||
|
||
Control.propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
export default Control; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
|
||
import Control from './Control'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
render(<Control>button</Control>, div); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.minus svg, | ||
.plus svg { | ||
stroke: transparent; | ||
fill: currentColor; | ||
stroke-linecap: round; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import iconHelper from '../../Icon/iconHelper'; | ||
|
||
import icons from './icons'; | ||
import css from './ControlIcon.css'; | ||
|
||
export default iconHelper(icons, css); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { storiesOf, action } from '@kadira/storybook'; | ||
import ControlIcon from './ControlIcon'; | ||
import Control from './Control'; | ||
|
||
storiesOf('Map Control', module) | ||
.add('Control', () => ( | ||
<Control onClick={ action('click') }> | ||
<ControlIcon name="plus" /> | ||
</Control> | ||
)) | ||
.add('Control with text', () => ( | ||
<Control onClick={ action('click') }> | ||
Just Text | ||
</Control> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import svgClean from '../../../utils/svgClean/svgClean'; | ||
|
||
import minus from './icons/icon-minus.svg'; | ||
import plus from './icons/icon-plus.svg'; | ||
|
||
export default { | ||
minus: svgClean(minus), | ||
plus: svgClean(plus), | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.control { | ||
border-radius: 0; | ||
border-top-width: 0; | ||
border-bottom-width: 0; | ||
display: block | ||
} | ||
|
||
.control:first-child { | ||
border-top-width: 1px; | ||
border-top-left-radius: 2px; | ||
border-top-right-radius: 2px; | ||
} | ||
|
||
.control:last-child { | ||
border-bottom-width: 1px; | ||
border-bottom-left-radius: 2px; | ||
border-bottom-right-radius: 2px; | ||
} | ||
|
||
.control + .control { | ||
padding-top: 0; | ||
} | ||
|
||
.control + .control:before { | ||
content: ''; | ||
display: block; | ||
border-top: 1px solid var(--color-greyLighter); | ||
padding-bottom: calc(var(--size-sm-ii) - 1px); | ||
box-sizing: border-box; | ||
margin-left: calc(var(--size-sm-iv) * -1); | ||
margin-right: calc(var(--size-sm-iv) * -1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, { Children, cloneElement, PropTypes } from 'react'; | ||
import cx from 'classnames'; | ||
|
||
import css from './ControlGroup.css'; | ||
|
||
const ControlGroup = ({ children, className }) => ( | ||
<div className={ cx(css.root, css.controlGroup, className) }> | ||
{ Children.map(children, child => | ||
cloneElement(child, { | ||
className: cx(css.control, child.props.className), | ||
}) | ||
) } | ||
</div> | ||
); | ||
|
||
ControlGroup.propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
export default ControlGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { storiesOf, action } from '@kadira/storybook'; | ||
import ControlIcon from '../Control/ControlIcon'; | ||
import Control from '../Control/Control'; | ||
import ControlGroup from './ControlGroup'; | ||
|
||
storiesOf('Map Control', module) | ||
.add('ControlGroup', () => ( | ||
<ControlGroup> | ||
<Control onClick={ action('click plus') }> | ||
<ControlIcon name="plus" /> | ||
</Control> | ||
<Control onClick={ action('click minus') }> | ||
<ControlIcon name="minus" /> | ||
</Control> | ||
</ControlGroup> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
|
||
import ControlGroup from './ControlGroup'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
render( | ||
<ControlGroup> | ||
<button>child</button> | ||
</ControlGroup>, | ||
div); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.root { | ||
width: 100%; | ||
height: 100%; | ||
position: relative; | ||
} | ||
|
||
.controlGroup { | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
margin: var(--size-regular); | ||
z-index: var(--z-mapControls); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { PropTypes, Component, cloneElement } from 'react'; | ||
import cx from 'classnames'; | ||
|
||
import Control from '../Control/Control'; | ||
import ControlGroup from '../ControlGroup/ControlGroup'; | ||
import ControlIcon from '../Control/ControlIcon'; | ||
|
||
import css from './ControlLayer.css'; | ||
|
||
import { DEFAULT_ZOOM } from '../../../constants/mapbox'; | ||
|
||
export default class ControlLayer extends Component { | ||
static propTypes = { | ||
className: PropTypes.string, | ||
controlGroupClassName: PropTypes.string, | ||
children: PropTypes.element.isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
const { children: { zoom } } = props; | ||
|
||
this.state = { | ||
zoom: zoom || DEFAULT_ZOOM, | ||
}; | ||
} | ||
|
||
handleZoomOut = () => { | ||
this.setState(({ zoom }) => ({ zoom: zoom - 1 })); | ||
}; | ||
|
||
handleZoomIn = () => { | ||
this.setState(({ zoom }) => ({ zoom: zoom + 1 })); | ||
}; | ||
|
||
handleMoveEnd = (...args) => { | ||
const { children: child } = this.props; | ||
const { onMoveEnd: childOnMoveEnd } = child.props; | ||
const { zoom } = args[1]; | ||
|
||
this.setState({ zoom }); | ||
if (typeof childOnMoveEnd === 'function') childOnMoveEnd(...args); | ||
}; | ||
|
||
render() { | ||
const { children: child, className, controlGroupClassName } = this.props; | ||
const { zoom } = this.state; | ||
|
||
return ( | ||
<div className={ cx(css.root, className) }> | ||
<ControlGroup className={ cx(css.controlGroup, controlGroupClassName) }> | ||
<Control onClick={ this.handleZoomIn }> | ||
<ControlIcon name="plus" /> | ||
</Control> | ||
<Control onClick={ this.handleZoomOut }> | ||
<ControlIcon name="minus" /> | ||
</Control> | ||
</ControlGroup> | ||
{ cloneElement(child, { | ||
zoom, | ||
onMoveEnd: this.handleMoveEnd, | ||
}) } | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@kadira/storybook'; | ||
|
||
import ControlLayer from './ControlLayer'; | ||
import BaseMap from '../BaseMap'; | ||
|
||
storiesOf('Map Control Layer', module) | ||
.add('Default', () => ( | ||
<div style={ { height: '96vh' } }> | ||
<ControlLayer> | ||
<BaseMap /> | ||
</ControlLayer> | ||
</div> | ||
)); |