maputnik/src/components/Toolbar.jsx

177 lines
5.1 KiB
React
Raw Normal View History

2016-12-20 11:44:22 +01:00
import React from 'react'
import FileReaderInput from 'react-file-reader-input'
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'
import MdFileUpload from 'react-icons/lib/md/file-upload'
2016-12-04 17:03:36 +01:00
import MdOpenInBrowser from 'react-icons/lib/md/open-in-browser'
2016-09-10 14:47:06 +02:00
import MdSettings from 'react-icons/lib/md/settings'
import MdInfo from 'react-icons/lib/md/info'
2016-09-10 14:47:06 +02:00
import MdLayers from 'react-icons/lib/md/layers'
import MdSave from 'react-icons/lib/md/save'
2016-12-04 17:03:36 +01:00
import MdStyle from 'react-icons/lib/md/style'
2016-09-10 22:08:26 +02:00
import MdMap from 'react-icons/lib/md/map'
2016-12-04 17:03:36 +01:00
import MdInsertEmoticon from 'react-icons/lib/md/insert-emoticon'
import MdFontDownload from 'react-icons/lib/md/font-download'
import MdHelpOutline from 'react-icons/lib/md/help-outline'
import MdFindInPage from 'react-icons/lib/md/find-in-page'
2016-09-10 22:08:26 +02:00
2016-12-20 11:44:22 +01:00
import SettingsModal from './modals/SettingsModal'
2016-12-21 16:11:08 +01:00
import SourcesModal from './modals/SourcesModal'
2016-12-22 11:27:53 +01:00
import OpenModal from './modals/OpenModal'
2016-12-20 11:44:22 +01:00
import style from '../libs/style'
2016-12-21 15:08:04 +01:00
import colors from '../config/colors'
import { margins, fontSizes } from '../config/scales'
2016-09-08 19:47:29 +02:00
2016-12-21 15:08:04 +01:00
const IconText = props => <span style={{ paddingLeft: margins[0] }}>
2016-12-04 17:03:36 +01:00
{props.children}
2016-12-21 15:08:04 +01:00
</span>
2016-12-04 17:03:36 +01:00
2016-12-22 11:37:32 +01:00
const actionStyle = {
display: "inline-block",
2016-12-22 14:18:07 +01:00
padding: 12.5,
2016-12-22 11:37:32 +01:00
fontSize: fontSizes[4],
cursor: "pointer",
2016-12-22 14:18:07 +01:00
color: colors.white,
2016-12-22 11:37:32 +01:00
textDecoration: 'none',
}
const ToolbarLink = props => <a
href={props.href}
target={"blank"}
style={{
...actionStyle,
...props.style,
}}>
{props.children}
</a>
2016-12-22 14:18:07 +01:00
class ToolbarAction extends React.Component {
static propTypes = {
onClick: React.PropTypes.func.isRequired,
}
2016-12-21 14:46:51 +01:00
2016-12-22 14:18:07 +01:00
constructor(props) {
super(props)
this.state = { hover: false }
}
render() {
return <a
onClick={this.props.onClick}
onMouseOver={e => this.setState({hover: true})}
onMouseOut={e => this.setState({hover: false})}
style={{
...actionStyle,
...this.props.style,
backgroundColor: this.state.hover ? colors.gray : null,
}}>
{this.props.children}
</a>
}
}
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 = {
2016-12-20 16:08:49 +01:00
mapStyle: React.PropTypes.object.isRequired,
2016-12-16 16:52:16 +01:00
onStyleChanged: React.PropTypes.func.isRequired,
2016-12-04 17:03:36 +01:00
// A new style has been uploaded
onStyleUpload: React.PropTypes.func.isRequired,
// Current style is requested for download
onStyleDownload: React.PropTypes.func.isRequired,
// Style is explicitely saved to local cache
onStyleSave: React.PropTypes.func,
2016-12-16 16:52:16 +01:00
}
constructor(props) {
super(props)
this.state = {
openSettingsModal: false,
2016-12-21 16:11:08 +01:00
openSourcesModal: false,
2016-12-22 11:27:53 +01:00
openOpenModal: false,
2016-12-16 16:52:16 +01:00
}
2016-12-04 17:03:36 +01:00
}
downloadButton() {
2016-12-21 15:08:04 +01:00
return <ToolbarAction onClick={this.props.onStyleDownload} big={true}>
<MdFileDownload />
<IconText>Download</IconText>
</ToolbarAction>
2016-12-04 17:03:36 +01:00
}
2016-09-10 14:56:59 +02:00
2016-12-16 16:52:16 +01:00
toggleSettings() {
this.setState({openSettingsModal: !this.state.openSettingsModal})
}
2016-09-09 16:58:48 +02:00
2016-12-21 16:11:08 +01:00
toggleSources() {
this.setState({openSourcesModal: !this.state.openSourcesModal})
2016-12-16 17:35:09 +01:00
}
2016-12-22 11:27:53 +01:00
toggleOpen() {
this.setState({openOpenModal: !this.state.openOpenModal})
}
2016-12-16 16:52:16 +01:00
render() {
2016-12-04 17:03:36 +01:00
return <div style={{
position: "fixed",
2016-12-20 20:36:02 +01:00
height: 40,
2016-12-04 17:03:36 +01:00
width: '100%',
zIndex: 100,
left: 0,
top: 0,
2016-12-20 11:44:22 +01:00
backgroundColor: colors.black
2016-12-04 17:03:36 +01:00
}}>
2016-12-22 14:21:53 +01:00
{this.state.openSettingsModal && <SettingsModal
mapStyle={this.props.mapStyle}
onStyleChanged={this.props.onStyleChanged}
isOpen={this.state.openSettingsModal}
2016-12-22 16:35:31 +01:00
onToggleOpen={this.toggleSettings.bind(this)}
2016-12-22 14:21:53 +01:00
/>
}
{this.state.openOpenModal &&<OpenModal
isOpen={this.state.openOpenModal}
2016-12-22 16:35:31 +01:00
onStyleOpen={this.props.onStyleUpload}
onToggleOpen={this.toggleOpen.bind(this)}
2016-12-22 14:21:53 +01:00
/>
}
{this.state.openSourcesModal && <SourcesModal
mapStyle={this.props.mapStyle}
onStyleChanged={this.props.onStyleChanged}
isOpen={this.state.openSourcesModal}
2016-12-22 16:35:31 +01:00
onToggleOpen={this.toggleSources.bind(this)}
2016-12-22 14:21:53 +01:00
/>
}
2016-12-21 15:08:04 +01:00
<ToolbarAction style={{
width: 180,
textAlign: 'left',
2016-12-22 14:18:07 +01:00
backgroundColor: colors.black,
padding: 5,
2016-12-21 15:08:04 +01:00
}}>
<img src="https://github.com/maputnik/editor/raw/master/media/maputnik.png" alt="Maputnik" style={{width: 30, height: 30, paddingRight: 5, verticalAlign: 'middle'}}/>
<span style={{fontSize: 20, verticalAlign: 'middle' }}>Maputnik</span>
</ToolbarAction>
2016-12-22 11:27:53 +01:00
<ToolbarAction onClick={this.toggleOpen.bind(this)}>
<MdOpenInBrowser />
<IconText>Open</IconText>
2016-12-21 15:08:04 +01:00
</ToolbarAction>
2016-12-04 17:03:36 +01:00
{this.downloadButton()}
2016-12-21 16:11:08 +01:00
<ToolbarAction onClick={this.toggleSources.bind(this)}>
2016-12-21 15:08:04 +01:00
<MdLayers />
2016-12-21 16:11:08 +01:00
<IconText>Sources</IconText>
2016-12-21 15:08:04 +01:00
</ToolbarAction>
<ToolbarAction onClick={this.toggleSettings.bind(this)}>
<MdSettings />
<IconText>Style Settings</IconText>
</ToolbarAction>
<ToolbarAction onClick={this.toggleSettings.bind(this)}>
<MdFindInPage />
<IconText>Inspect</IconText>
</ToolbarAction>
2016-12-22 11:37:32 +01:00
<ToolbarLink href={"https://github.com/maputnik/editor/wiki"}>
2016-12-21 15:08:04 +01:00
<MdHelpOutline />
<IconText>Help</IconText>
2016-12-22 11:37:32 +01:00
</ToolbarLink>
2016-12-04 17:03:36 +01:00
</div>
}
2016-09-08 19:47:29 +02:00
}