Initial color accessibility UI

This commit is contained in:
orangemug 2018-06-18 20:28:24 +01:00
parent afbdaecd0a
commit 85a28999fb
3 changed files with 109 additions and 17 deletions

View file

@ -104,7 +104,7 @@ export default class App extends React.Component {
{ {
keyCode: keyCodes["i"], keyCode: keyCodes["i"],
handler: () => { handler: () => {
this.changeInspectMode(); this.setMapState("inspect");
} }
}, },
{ {
@ -164,7 +164,7 @@ export default class App extends React.Component {
selectedLayerIndex: 0, selectedLayerIndex: 0,
sources: {}, sources: {},
vectorLayers: {}, vectorLayers: {},
inspectModeEnabled: false, mapState: "normal",
spec: styleSpec.latest, spec: styleSpec.latest,
isOpen: { isOpen: {
settings: false, settings: false,
@ -176,7 +176,6 @@ export default class App extends React.Component {
mapOptions: { mapOptions: {
showTileBoundaries: queryUtil.asBool(queryObj, "show-tile-boundaries") showTileBoundaries: queryUtil.asBool(queryObj, "show-tile-boundaries")
}, },
mapFilter: queryObj["color-blindness-emulation"],
} }
this.layerWatcher = new LayerWatcher({ this.layerWatcher = new LayerWatcher({
@ -341,9 +340,9 @@ export default class App extends React.Component {
this.onLayersChange(changedLayers) this.onLayersChange(changedLayers)
} }
changeInspectMode() { setMapState(newState) {
this.setState({ this.setState({
inspectModeEnabled: !this.state.inspectModeEnabled mapState: newState
}) })
} }
@ -423,13 +422,17 @@ export default class App extends React.Component {
mapElement = <OpenLayers3Map {...mapProps} /> mapElement = <OpenLayers3Map {...mapProps} />
} else { } else {
mapElement = <MapboxGlMap {...mapProps} mapElement = <MapboxGlMap {...mapProps}
inspectModeEnabled={this.state.inspectModeEnabled} inspectModeEnabled={this.state.mapState === "inspect"}
highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]} highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]}
onLayerSelect={this.onLayerSelect.bind(this)} /> onLayerSelect={this.onLayerSelect.bind(this)} />
} }
let filterName = "";
if(this.state.mapState.match(/^filter-/)) {
filterName = this.state.mapState.replace(/^filter-/, "");
}
const elementStyle = { const elementStyle = {
"filter": `url('#${this.state.mapFilter}')` "filter": `url('#${filterName}')`
}; };
return <div style={elementStyle}> return <div style={elementStyle}>
@ -457,12 +460,13 @@ export default class App extends React.Component {
const metadata = this.state.mapStyle.metadata || {} const metadata = this.state.mapStyle.metadata || {}
const toolbar = <Toolbar const toolbar = <Toolbar
mapState={this.state.mapState}
mapStyle={this.state.mapStyle} mapStyle={this.state.mapStyle}
inspectModeEnabled={this.state.inspectModeEnabled} inspectModeEnabled={this.state.mapState === "inspect"}
sources={this.state.sources} sources={this.state.sources}
onStyleChanged={this.onStyleChanged.bind(this)} onStyleChanged={this.onStyleChanged.bind(this)}
onStyleOpen={this.onStyleChanged.bind(this)} onStyleOpen={this.onStyleChanged.bind(this)}
onInspectModeToggle={this.changeInspectMode.bind(this)} onSetMapState={this.setMapState.bind(this)}
onToggleModal={this.toggleModal.bind(this)} onToggleModal={this.toggleModal.bind(this)}
/> />

View file

@ -2,6 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import FileReaderInput from 'react-file-reader-input' import FileReaderInput from 'react-file-reader-input'
import classnames from 'classnames' import classnames from 'classnames'
import { Wrapper, Button, Menu, MenuItem } from 'react-aria-menubutton'
import MdFileDownload from 'react-icons/lib/md/file-download' import MdFileDownload from 'react-icons/lib/md/file-download'
import MdFileUpload from 'react-icons/lib/md/file-upload' import MdFileUpload from 'react-icons/lib/md/file-upload'
@ -17,6 +18,11 @@ import MdFontDownload from 'react-icons/lib/md/font-download'
import HelpIcon from 'react-icons/lib/md/help-outline' import HelpIcon from 'react-icons/lib/md/help-outline'
import InspectionIcon from 'react-icons/lib/md/find-in-page' import InspectionIcon from 'react-icons/lib/md/find-in-page'
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 logoImage from 'maputnik-design/logos/logo-color.svg'
import pkgJson from '../../package.json' import pkgJson from '../../package.json'
@ -79,7 +85,6 @@ export default class Toolbar extends React.Component {
onStyleOpen: PropTypes.func.isRequired, onStyleOpen: PropTypes.func.isRequired,
// A dict of source id's and the available source layers // A dict of source id's and the available source layers
sources: PropTypes.object.isRequired, sources: PropTypes.object.isRequired,
onInspectModeToggle: PropTypes.func.isRequired,
children: PropTypes.node, children: PropTypes.node,
onToggleModal: PropTypes.func, onToggleModal: PropTypes.func,
} }
@ -97,7 +102,44 @@ export default class Toolbar extends React.Component {
} }
} }
handleSelection(val) {
this.props.onSetMapState(val);
}
render() { render() {
const views = [
{
id: "map",
title: "Map",
icon: <MapIcon/>,
},
{
id: "inspect",
title: "Inspect",
icon: <InspectionIcon/>,
},
{
id: "filter-deuteranopia",
title: "Filter deuteranopia",
icon: <ColorIcon/>,
},
{
id: "filter-protanopia",
title: "Filter protanopia",
icon: <ColorIcon/>,
},
{
id: "filter-tritanopia",
title: "Filter tritanopia",
icon: <ColorIcon/>,
},
{
id: "filter-achromatopsia",
title: "Filter achromatopsia",
icon: <ColorIcon/>,
},
];
return <div className='maputnik-toolbar'> return <div className='maputnik-toolbar'>
<div className="maputnik-toolbar__inner"> <div className="maputnik-toolbar__inner">
<div <div
@ -135,13 +177,36 @@ export default class Toolbar extends React.Component {
<SettingsIcon /> <SettingsIcon />
<IconText>Style Settings</IconText> <IconText>Style Settings</IconText>
</ToolbarAction> </ToolbarAction>
<ToolbarAction wdKey="nav:inspect" onClick={this.props.onInspectModeToggle}>
<InspectionIcon /> <Wrapper
<IconText> className='map-state-menu'
{ this.props.inspectModeEnabled && <span>Map Mode</span> } onSelection={(val) => this.handleSelection(val)}
{ !this.props.inspectModeEnabled && <span>Inspect Mode</span> } >
</IconText> <Button wdKey="nav:settings" className="maputnik-toolbar-action">
</ToolbarAction> <ViewIcon/>
<IconText>Change view</IconText>
</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"}> <ToolbarLink href={"https://github.com/maputnik/editor/wiki"}>
<HelpIcon /> <HelpIcon />
<IconText>Help</IconText> <IconText>Help</IconText>

View file

@ -141,3 +141,26 @@
text-align: right; text-align: right;
} }
} }
.map-state-menu {
display: inline-block;
&__menu {
position: absolute;
z-index: 999999;
background: $color-black;
display: flex;
flex-direction: column;
align-content: stretch;
li {
display: flex;
flex-direction: column;
button {
width: 100%;
text-align: left;
}
}
}
}