maputnik/src/components/Toolbar.jsx

240 lines
6.7 KiB
React
Raw Normal View History

2016-12-20 11:44:22 +01:00
import React from 'react'
import PropTypes from 'prop-types'
2017-01-11 09:35:48 +01:00
import classnames from 'classnames'
2018-06-18 21:28:24 +02:00
import { Wrapper, Button, Menu, MenuItem } from 'react-aria-menubutton'
2016-09-08 19:47:29 +02:00
2016-09-10 14:47:06 +02:00
import MdFileDownload from 'react-icons/lib/md/file-download'
2016-12-28 16:23:33 +01:00
import OpenIcon from 'react-icons/lib/md/open-in-browser'
import SettingsIcon from 'react-icons/lib/md/settings'
import SourcesIcon from 'react-icons/lib/md/layers'
import HelpIcon from 'react-icons/lib/md/help-outline'
import InspectionIcon from 'react-icons/lib/md/find-in-page'
import SurveyIcon from 'react-icons/lib/md/assignment-turned-in'
2016-09-10 22:08:26 +02:00
2018-06-18 21:28:24 +02:00
import ColorIcon from 'react-icons/lib/md/color-lens'
import MapIcon from 'react-icons/lib/md/map'
import ViewIcon from 'react-icons/lib/md/remove-red-eye'
import logoImage from 'maputnik-design/logos/logo-color.svg'
import pkgJson from '../../package.json'
2016-12-20 11:44:22 +01:00
2016-09-08 19:47:29 +02:00
2017-11-08 09:47:36 +01:00
class IconText extends React.Component {
static propTypes = {
children: PropTypes.node,
}
render() {
return <span className="maputnik-icon-text">{this.props.children}</span>
}
2017-01-11 09:35:48 +01:00
}
2016-12-04 17:03:36 +01:00
2017-11-08 09:47:36 +01:00
class ToolbarLink extends React.Component {
static propTypes = {
className: PropTypes.string,
children: PropTypes.node,
2017-11-08 09:51:24 +01:00
href: PropTypes.string,
2018-06-03 11:00:50 +02:00
onToggleModal: PropTypes.func,
2017-11-08 09:47:36 +01:00
}
render() {
return <a
className={classnames('maputnik-toolbar-link', this.props.className)}
href={this.props.href}
rel="noopener noreferrer"
target="_blank"
2017-11-08 09:47:36 +01:00
>
{this.props.children}
</a>
}
2017-01-11 09:35:48 +01:00
}
2016-12-21 14:46:51 +01:00
class ToolbarLinkHighlighted extends React.Component {
static propTypes = {
className: PropTypes.string,
children: PropTypes.node,
href: PropTypes.string,
onToggleModal: PropTypes.func
}
render() {
return <a
2018-07-08 14:42:49 +02:00
className={classnames('maputnik-toolbar-link', "maputnik-toolbar-link--highlighted", this.props.className)}
href={this.props.href}
rel="noopener noreferrer"
target="_blank"
>
<span className="maputnik-toolbar-link-wrapper">
{this.props.children}
</span>
</a>
}
}
2017-11-08 09:47:36 +01:00
class ToolbarAction extends React.Component {
static propTypes = {
2017-11-08 09:51:24 +01:00
children: PropTypes.node,
2018-04-10 16:15:29 +02:00
onClick: PropTypes.func,
wdKey: PropTypes.string
2017-11-08 09:47:36 +01:00
}
render() {
2018-05-10 17:50:37 +02:00
return <button
2017-11-08 09:47:36 +01:00
className='maputnik-toolbar-action'
data-wd-key={this.props.wdKey}
2017-11-08 09:47:36 +01:00
onClick={this.props.onClick}
>
{this.props.children}
2018-05-10 17:50:37 +02:00
</button>
2017-11-08 09:47:36 +01:00
}
2016-12-22 14:18:07 +01:00
}
2016-12-22 11:27:53 +01:00
2016-12-20 11:44:22 +01:00
export default class Toolbar extends React.Component {
2016-12-04 17:03:36 +01:00
static propTypes = {
mapStyle: PropTypes.object.isRequired,
inspectModeEnabled: PropTypes.bool.isRequired,
onStyleChanged: PropTypes.func.isRequired,
2016-12-04 17:03:36 +01:00
// A new style has been uploaded
onStyleOpen: PropTypes.func.isRequired,
// A dict of source id's and the available source layers
sources: PropTypes.object.isRequired,
2018-06-03 11:18:55 +02:00
children: PropTypes.node,
onToggleModal: PropTypes.func,
2018-09-23 15:50:29 +02:00
onSetMapState: PropTypes.func,
mapState: PropTypes.string,
2016-12-16 16:52:16 +01:00
}
state = {
isOpen: {
settings: false,
sources: false,
open: false,
add: false,
export: false,
2016-12-16 16:52:16 +01:00
}
2016-12-04 17:03:36 +01:00
}
2018-06-18 21:28:24 +02:00
handleSelection(val) {
this.props.onSetMapState(val);
}
2016-12-22 16:54:22 +01:00
render() {
2018-06-18 21:28:24 +02:00
const views = [
{
id: "map",
title: "Map",
icon: <MapIcon/>,
},
{
id: "inspect",
title: "Inspect",
icon: <InspectionIcon/>,
},
{
id: "filter-deuteranopia",
2018-09-23 15:39:02 +02:00
title: "Map (deuteranopia)",
2018-06-18 21:28:24 +02:00
icon: <ColorIcon/>,
},
{
id: "filter-protanopia",
2018-09-23 15:39:02 +02:00
title: "Map (protanopia)",
2018-06-18 21:28:24 +02:00
icon: <ColorIcon/>,
},
{
id: "filter-tritanopia",
2018-09-23 15:39:02 +02:00
title: "Map (tritanopia)",
2018-06-18 21:28:24 +02:00
icon: <ColorIcon/>,
},
{
id: "filter-achromatopsia",
2018-09-23 15:39:02 +02:00
title: "Map (achromatopsia)",
2018-06-18 21:28:24 +02:00
icon: <ColorIcon/>,
},
];
2018-09-23 15:39:02 +02:00
const currentView = views.find((view) => {
return view.id === this.props.mapState;
});
2017-01-10 21:28:30 +01:00
return <div className='maputnik-toolbar'>
<div className="maputnik-toolbar__inner">
<div
className="maputnik-toolbar-logo-container"
>
<a className="maputnik-toolbar-skip" href="#skip-menu">
Skip navigation
</a>
<a
href="https://github.com/maputnik/editor"
2018-06-03 17:59:41 +02:00
rel="noopener noreferrer"
target="_blank"
className="maputnik-toolbar-logo"
>
<img src={logoImage} alt="Maputnik" />
<h1>Maputnik
<span className="maputnik-toolbar-version">v{pkgJson.version}</span>
</h1>
</a>
</div>
<div className="maputnik-toolbar__actions">
<ToolbarAction wdKey="nav:open" onClick={this.props.onToggleModal.bind(this, 'open')}>
<OpenIcon />
<IconText>Open</IconText>
</ToolbarAction>
<ToolbarAction wdKey="nav:export" onClick={this.props.onToggleModal.bind(this, 'export')}>
<MdFileDownload />
<IconText>Export</IconText>
</ToolbarAction>
<ToolbarAction wdKey="nav:sources" onClick={this.props.onToggleModal.bind(this, 'sources')}>
<SourcesIcon />
<IconText>Data Sources</IconText>
</ToolbarAction>
<ToolbarAction wdKey="nav:settings" onClick={this.props.onToggleModal.bind(this, 'settings')}>
<SettingsIcon />
<IconText>Style Settings</IconText>
</ToolbarAction>
2018-06-18 21:28:24 +02:00
<Wrapper
className='map-state-menu'
onSelection={(val) => this.handleSelection(val)}
>
<Button wdKey="nav:settings" className="maputnik-toolbar-action">
<ViewIcon/>
2018-09-23 15:39:02 +02:00
<IconText>View: {currentView.title}</IconText>
2018-06-18 21:28:24 +02:00
</Button>
<Menu>
<ul className="map-state-menu__menu">
{views.map((item) => {
return (
<li key={item.id}>
<MenuItem value={item.id}>
<button
className="maputnik-toolbar-action"
>
{item.icon}
<IconText>{item.title}</IconText>
</button>
</MenuItem>
</li>
);
})}
</ul>
</Menu>
</Wrapper>
<ToolbarLink href={"https://github.com/maputnik/editor/wiki"}>
<HelpIcon />
<IconText>Help</IconText>
</ToolbarLink>
<ToolbarLinkHighlighted href={"https://gregorywolanski.typeform.com/to/cPgaSY"}>
<SurveyIcon />
<IconText>Take the Maputnik Survey</IconText>
</ToolbarLinkHighlighted>
</div>
</div>
2016-12-04 17:03:36 +01:00
</div>
}
2016-09-08 19:47:29 +02:00
}