Interactive interface for browsing global, full-resolution satellite imagery
implement styling of switches #2306
Benjamin King7ff91ce0d1a8
diff --git a/web/css/switch.css b/web/css/switch.cssnew file mode 100644index 000000000..9381639bd--- /dev/null+++ b/web/css/switch.css@@ -0,0 +1,61 @@+.react-switch {+ display: flex;+ margin-bottom: 7px;+}+.react-switch .switch-col {+ align-items: flex-start;+ display: flex;+ align-items: flex-start;+}+.react-switch-case {+ /* width: 30px;+ display: inline-block;+ position: relative; */+ width: 20%;+ align-items: flex-start;+}+.react-switch-label-case {+ /* width: 30px;+ display: inline-block;+ position: relative; */+ width: 80%;+}+.react-switch-checkbox {+ height: 0;+ width: 0;+ visibility: hidden;+}++.react-switch-label {+ display: flex;+ align-items: flex-start;+ justify-content: space-between;+ cursor: pointer;+ width: 30px;+ height: 15px;+ background: grey;+ border-radius: 30px;+ position: relative;+ transition: background-color .2s;+}++.react-switch-label .react-switch-button {+ content: '';+ position: absolute;+ left: 2px;+ width: 15px;+ height: 15px;+ border-radius: 15px;+ transition: 0.2s;+ background: #fff;+ box-shadow: 0 0 2px 0 rgba(10, 10, 10, 0.29);+}++.react-switch-checkbox:checked + .react-switch-label .react-switch-button {+ left: calc(100% - 2px);+ transform: translateX(-100%);+}++.react-switch-label:active .react-switch-button {+ width: 60px;+}\ No newline at end of filediff --git a/web/js/app.js b/web/js/app.jsindex f4ed8fd62..60ee40e55 100644--- a/web/js/app.js+++ b/web/js/app.js@@ -67,6 +67,7 @@ import '../css/dataDownload.css';import '../css/sidebar.css';import '../css/layers.css';import '../css/scrollbar.css';+import '../css/switch.css';import '../css/timeline.css';import '../css/anim.widget.css';import '../css/dateselector.css';diff --git a/web/js/components/layer/settings/classification-toggle.js b/web/js/components/layer/settings/classification-toggle.jsindex 9860bb65a..653685517 100644--- a/web/js/components/layer/settings/classification-toggle.js+++ b/web/js/components/layer/settings/classification-toggle.js@@ -1,29 +1,25 @@import React from 'react';import PropTypes from 'prop-types';-import { CustomInput } from 'reactstrap';-import { Checkbox } from '../../util/checkbox';+// import { CustomInput } from 'reactstrap';+import Switch from '../../util/switch';+import Scrollbar from '../../util/scrollbar';class ClassificationToggle extends React.Component {-render() {- const { layer, legend } = this.props;+ const { layer, legend, toggle } = this.props;const tooltips = legend.tooltips;return (<div className="layer-classification-toggle settings-component"><h2 className="wv-header">Category Enable/Disable</h2>- {legend.colors.map((color, index) => {- const id = legend.id + index;- const tooltip = tooltips[index];- return (- // <CustomInput key={id} type="switch" id={id} name={tooltip + ' switch'} label={tooltip} />- <Checkbox- key={id}- title={tooltip}- checked={false}- label={tooltip}- />- );- })}+ <Scrollbar style={{ maxHeight: '200px' }}>+ {legend.colors.map((color, index) => {+ const id = legend.id + index;+ const tooltip = tooltips[index];+ return (+ <Switch key={id} color={color} label={tooltip} active={true} toggle={() => toggle(index)} />+ );+ })}+ </Scrollbar></div>);diff --git a/web/js/components/layer/settings/settings.js b/web/js/components/layer/settings/settings.jsindex 856ed2b11..0fd1607e9 100644--- a/web/js/components/layer/settings/settings.js+++ b/web/js/components/layer/settings/settings.js@@ -24,7 +24,8 @@ import {import {setThresholdRangeAndSquash,setCustomPalette,- clearCustomPalette+ clearCustomPalette,+ setToggledClassification} from '../../../modules/palettes/actions';import {setFilterRange,@@ -163,7 +164,8 @@ class LayerSettings extends React.Component {setThresholdRange,paletteOrder,groupName,- layer+ layer,+ toggleClassification} = this.props;const paletteLegends = getPaletteLegends(layer.id);if (!paletteLegends) return '';@@ -176,7 +178,7 @@ class LayerSettings extends React.Component {if (len > 1) {return this.renderMultiColormapCustoms(paletteLegends);} else if (legend.type === 'classification' && legend.colors.length > 1) {- return (<ClassificationToggle legend={legend} />);+ return (<ClassificationToggle toggle={(classIndex) => toggleClassification(layer.id, classIndex, 0, groupName)} legend={legend} />);}return (<React.Fragment>@@ -311,6 +313,11 @@ function mapStateToProps(state, ownProps) {};}const mapDispatchToProps = dispatch => ({+ toggleClassification: (layerId, classIndex, index, groupName) => {+ dispatch(+ setToggledClassification(layerId, classIndex, index, groupName)+ );+ },setThresholdRange: (layerId, min, max, squash, index, groupName) => {dispatch(setThresholdRangeAndSquash(layerId, { min, max, squash }, index, groupName)diff --git a/web/js/components/util/switch.js b/web/js/components/util/switch.jsnew file mode 100644index 000000000..90cba514d--- /dev/null+++ b/web/js/components/util/switch.js@@ -0,0 +1,30 @@+import React from 'react';+// https://upmostly.com/tutorials/build-a-react-switch-toggle-component+const Switch = (props) => {+ const { color, active, toggle, label } = props;+ const style = color && active ? { backgroundColor: '#' + color } : {};+ return (+ <div className='react-switch'>+ <div className='react-switch-case switch-col'>+ <input+ className="react-switch-checkbox"+ id={`react-switch-new`}+ type="checkbox"+ checked={active}+ onChange={toggle}+ />+ <label+ className="react-switch-label"+ htmlFor={`react-switch-new`}+ style={style}+ >+ <span className={`react-switch-button`} />+ </label>++ </div>+ <div className='react-switch-label-case switch-col'>{label}</div>+ </div>+ );+};++export default Switch;\ No newline at end of filediff --git a/web/js/modules/palettes/actions.js b/web/js/modules/palettes/actions.jsindex 24cb37b0d..9f6e039b8 100644--- a/web/js/modules/palettes/actions.js+++ b/web/js/modules/palettes/actions.js@@ -151,3 +151,7 @@ export function loadedCustomPalettes(customs) {custom: customs};}+// TODO+export function setToggledClassification(layerId, classIndex, index, groupName) {++}\ No newline at end of file