maputnik/src/components/Toolbar.jsx

237 lines
6.5 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'
import {detect} from 'detect-browser';
2016-09-08 19:47:29 +02:00
2018-10-06 17:06:21 +02:00
import {MdFileDownload, MdOpenInBrowser, MdSettings, MdLayers, MdHelpOutline, MdFindInPage, MdAssignmentTurnedIn} from 'react-icons/md'
2016-09-10 22:08:26 +02:00
2018-06-18 21:28:24 +02:00
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
// This is required because of <https://stackoverflow.com/a/49846426>, there isn't another way to detect support that I'm aware of.
const browser = detect();
const colorAccessibilityFiltersEnabled = ['chrome', 'firefox'].indexOf(browser.name) > -1;
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>
}
}
class ToolbarSelect extends React.Component {
static propTypes = {
children: PropTypes.node,
wdKey: PropTypes.string
}
render() {
return <div
className='maputnik-toolbar-select'
data-wd-key={this.props.wdKey}
>
{this.props.children}
</div>
}
}
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,
2019-05-29 19:59:26 +02:00
renderer: 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",
},
{
id: "inspect",
title: "Inspect",
disabled: this.props.renderer !== 'mbgljs',
2018-06-18 21:28:24 +02:00
},
{
id: "filter-deuteranopia",
2018-09-23 15:39:02 +02:00
title: "Map (deuteranopia)",
disabled: !colorAccessibilityFiltersEnabled,
2018-06-18 21:28:24 +02:00
},
{
id: "filter-protanopia",
2018-09-23 15:39:02 +02:00
title: "Map (protanopia)",
disabled: !colorAccessibilityFiltersEnabled,
2018-06-18 21:28:24 +02:00
},
{
id: "filter-tritanopia",
2018-09-23 15:39:02 +02:00
title: "Map (tritanopia)",
disabled: !colorAccessibilityFiltersEnabled,
2018-06-18 21:28:24 +02:00
},
{
id: "filter-achromatopsia",
2018-09-23 15:39:02 +02:00
title: "Map (achromatopsia)",
disabled: !colorAccessibilityFiltersEnabled,
2018-06-18 21:28:24 +02:00
},
];
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"
>
<span dangerouslySetInnerHTML={{__html: logoImage}} />
2018-10-04 16:42:39 +02:00
<h1>
<span className="maputnik-toolbar-name">{pkgJson.name}</span>
<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')}>
2018-10-06 17:06:21 +02:00
<MdOpenInBrowser />
<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')}>
2018-10-06 17:06:21 +02:00
<MdLayers />
<IconText>Data Sources</IconText>
</ToolbarAction>
<ToolbarAction wdKey="nav:settings" onClick={this.props.onToggleModal.bind(this, 'settings')}>
2018-10-06 17:06:21 +02:00
<MdSettings />
<IconText>Style Settings</IconText>
</ToolbarAction>
2018-06-18 21:28:24 +02:00
<ToolbarSelect wdKey="nav:inspect">
2018-10-06 17:06:21 +02:00
<MdFindInPage />
<IconText>View </IconText>
<select onChange={(e) => this.handleSelection(e.target.value)} value={currentView.id}>
{views.map((item) => {
return (
<option key={item.id} value={item.id} disabled={item.disabled}>
{item.title}
</option>
);
})}
</select>
</ToolbarSelect>
2018-06-18 21:28:24 +02:00
<ToolbarLink href={"https://github.com/maputnik/editor/wiki"}>
2018-10-06 17:06:21 +02:00
<MdHelpOutline />
<IconText>Help</IconText>
</ToolbarLink>
<ToolbarLinkHighlighted href={"https://gregorywolanski.typeform.com/to/cPgaSY"}>
2018-10-06 17:06:21 +02:00
<MdAssignmentTurnedIn />
<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
}