Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color accessibility UI #392

Merged
merged 8 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class App extends React.Component {
{
keyCode: keyCodes["i"],
handler: () => {
this.changeInspectMode();
this.setMapState("inspect");
}
},
{
Expand Down Expand Up @@ -166,7 +166,7 @@ export default class App extends React.Component {
selectedLayerIndex: 0,
sources: {},
vectorLayers: {},
inspectModeEnabled: false,
mapState: "map",
spec: styleSpec.latest,
isOpen: {
settings: false,
Expand All @@ -180,7 +180,6 @@ export default class App extends React.Component {
showTileBoundaries: queryUtil.asBool(queryObj, "show-tile-boundaries"),
showCollisionBoxes: queryUtil.asBool(queryObj, "show-collision-boxes")
},
mapFilter: queryObj["color-blindness-emulation"],
}

this.layerWatcher = new LayerWatcher({
Expand Down Expand Up @@ -362,9 +361,9 @@ export default class App extends React.Component {
this.onLayersChange(changedLayers)
}

changeInspectMode = () => {
setMapState = (newState) => {
this.setState({
inspectModeEnabled: !this.state.inspectModeEnabled
mapState: newState
})
}

Expand Down Expand Up @@ -446,17 +445,21 @@ export default class App extends React.Component {
mapElement = <div>TODO</div>
} else {
mapElement = <MapboxGlMap {...mapProps}
inspectModeEnabled={this.state.inspectModeEnabled}
inspectModeEnabled={this.state.mapState === "inspect"}
highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]}
onLayerSelect={this.onLayerSelect} />
}

const elementStyle = {};
if(this.state.mapFilter) {
elementStyle.filter = `url('#${this.state.mapFilter}')`;
let filterName;
if(this.state.mapState.match(/^filter-/)) {
filterName = this.state.mapState.replace(/^filter-/, "");
}
const elementStyle = {};
if (filterName) {
elementStyle.filter = `url('#${filterName}')`;
};

return <div style={elementStyle}>
return <div style={elementStyle} className="maputnik-map__container">
{mapElement}
</div>
}
Expand Down Expand Up @@ -485,12 +488,13 @@ export default class App extends React.Component {
const metadata = this.state.mapStyle.metadata || {}

const toolbar = <Toolbar
mapState={this.state.mapState}
mapStyle={this.state.mapStyle}
inspectModeEnabled={this.state.inspectModeEnabled}
inspectModeEnabled={this.state.mapState === "inspect"}
sources={this.state.sources}
onStyleChanged={this.onStyleChanged}
onStyleOpen={this.onStyleChanged}
onInspectModeToggle={this.changeInspectMode}
onSetMapState={this.setMapState}
onToggleModal={this.toggleModal.bind(this)}
/>

Expand Down
87 changes: 79 additions & 8 deletions src/components/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ 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'

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'

Expand Down Expand Up @@ -66,6 +71,22 @@ class ToolbarLinkHighlighted extends React.Component {
}
}

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>
}
}

class ToolbarAction extends React.Component {
static propTypes = {
children: PropTypes.node,
Expand Down Expand Up @@ -93,9 +114,10 @@ export default class Toolbar extends React.Component {
onStyleOpen: PropTypes.func.isRequired,
// A dict of source id's and the available source layers
sources: PropTypes.object.isRequired,
onInspectModeToggle: PropTypes.func.isRequired,
children: PropTypes.node,
onToggleModal: PropTypes.func,
onSetMapState: PropTypes.func,
mapState: PropTypes.string,
}

state = {
Expand All @@ -108,7 +130,48 @@ export default class Toolbar extends React.Component {
}
}

handleSelection(val) {
this.props.onSetMapState(val);
}

render() {
const views = [
{
id: "map",
title: "Map",
icon: <MapIcon/>,
},
{
id: "inspect",
title: "Inspect",
icon: <InspectionIcon/>,
},
{
id: "filter-deuteranopia",
title: "Map (deuteranopia)",
icon: <ColorIcon/>,
},
{
id: "filter-protanopia",
title: "Map (protanopia)",
icon: <ColorIcon/>,
},
{
id: "filter-tritanopia",
title: "Map (tritanopia)",
icon: <ColorIcon/>,
},
{
id: "filter-achromatopsia",
title: "Map (achromatopsia)",
icon: <ColorIcon/>,
},
];

const currentView = views.find((view) => {
return view.id === this.props.mapState;
});

return <div className='maputnik-toolbar'>
<div className="maputnik-toolbar__inner">
<div
Expand Down Expand Up @@ -146,13 +209,21 @@ export default class Toolbar extends React.Component {
<SettingsIcon />
<IconText>Style Settings</IconText>
</ToolbarAction>
<ToolbarAction wdKey="nav:inspect" onClick={this.props.onInspectModeToggle}>
<InspectionIcon />
<IconText>
{ this.props.inspectModeEnabled && <span>Map Mode</span> }
{ !this.props.inspectModeEnabled && <span>Inspect Mode</span> }
</IconText>
</ToolbarAction>

<ToolbarSelect wdKey="nav:inspect">
<ViewIcon/>
<IconText>View </IconText>
<select onChange={(e) => this.handleSelection(e.target.value)}>
{views.map((item) => {
return (
<option key={item.id} value={item.id}>
{item.title}
</option>
);
})}
</select>
</ToolbarSelect>

<ToolbarLink href={"https://github.com/maputnik/editor/wiki"}>
<HelpIcon />
<IconText>Help</IconText>
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/MapboxGlMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class MapboxGlMap extends React.Component {
render() {
if(IS_SUPPORTED) {
return <div
className="maputnik-map"
className="maputnik-map__map"
ref={x => this.container = x}
></div>
}
Expand Down
36 changes: 35 additions & 1 deletion src/styles/_components.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// MAP
.maputnik-map {
.maputnik-map__container {
display: flex;
position: fixed !important;
top: $toolbar-height + $toolbar-offset;
Expand All @@ -23,6 +23,11 @@
}
}

.maputnik-map__map {
width: 100%;
height: 100%;
}

// DOC LABEL
.maputnik-doc {
&-target {
Expand Down Expand Up @@ -165,3 +170,32 @@
color: $color-red;
}
}

.maputnik-dialog {
&__buttons {
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;
}
}
}
}
10 changes: 10 additions & 0 deletions src/styles/_toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@
@extend .maputnik-toolbar-link;
}

.maputnik-toolbar-select {
background: inherit;
border-width: 0;
@extend .maputnik-toolbar-link;
}

.maputnik-toolbar-select select {
margin-left: 4px;
}

.maputnik-icon-text {
padding-left: $margin-1;
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/modals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("modals", function() {
"geojson:example"
]));

browser.click(wd.$("nav:inspect"));
browser.selectByValue(wd.$("nav:inspect", "select"), "inspect");
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/functional/screenshots/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('screenshots', function() {
browser.waitForExist(".maputnik-toolbar-link");
browser.flushReactUpdates();

browser.click(wd.$("nav:inspect"))
browser.selectByValue(wd.$("nav:inspect", "select"), "inspect");
browser.flushReactUpdates();

browser.takeScreenShot("/inspect.png")
Expand Down