Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add reusable stateless arrow component

Ed Plato0f9674ad0e16
diff --git a/web/js/components/date-selector/input.js b/web/js/components/date-selector/input.js
index dbc308570..968798cfc 100644
--- a/web/js/components/date-selector/input.js
+++ b/web/js/components/date-selector/input.js
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
+import Arrow from '../util/arrow';
import util from '../../util/util';
/*
@@ -301,9 +302,20 @@ class DateInputColumn extends Component {
}
render() {
- const { fontSize, inputId, tabIndex, type, isValid } = this.props;
- const { selected, size, value } = this.state;
-
+ const {
+ fontSize,
+ inputId,
+ isValid,
+ tabIndex,
+ type
+ } = this.props;
+ const {
+ selected,
+ size,
+ value
+ } = this.state;
+
+ // conditional styling
const containerClassName = `input-wrapper ${selected ? 'selected ' : ''}input-wrapper-${type}`;
const containerBorderStyle = isValid ? {} : { borderColor: '#ff0000' };
const inputClassName = `button-input-group${isValid ? '' : ' invalid-input'}`;
@@ -313,15 +325,11 @@ class DateInputColumn extends Component {
className={containerClassName}
style={containerBorderStyle}
>
- <div
+ <Arrow
+ direction='up'
onClick={this.onClickUp}
- className="date-arrows date-arrow-up"
- data-interval={type}
- >
- <svg width="25" height="8">
- <path d="M 12.5,0 25,8 0,8 z" className="uparrow" />
- </svg>
- </div>
+ type={type}
+ />
<input
type="text"
ref={input => {
@@ -340,15 +348,11 @@ class DateInputColumn extends Component {
onBlur={this.blur}
onFocus={this.handleFocus}
/>
- <div
+ <Arrow
+ direction='down'
onClick={this.onClickDown}
- className="date-arrows date-arrow-down"
- data-interval={type}
- >
- <svg width="25" height="8">
- <path d="M 12.5,0 25,8 0,8 z" className="downarrow" />
- </svg>
- </div>
+ type={type}
+ />
</div>
);
}
diff --git a/web/js/components/timeline/timeline-controls/axis-timescale-change-controls.js b/web/js/components/timeline/timeline-controls/axis-timescale-change-controls.js
index e50852a54..577940755 100644
--- a/web/js/components/timeline/timeline-controls/axis-timescale-change-controls.js
+++ b/web/js/components/timeline/timeline-controls/axis-timescale-change-controls.js
@@ -1,6 +1,7 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import AxisTimeScaleChangeTooltip from './axis-timescale-change-tooltip';
+import Arrow from '../../util/arrow';
/*
* Up/down arrows for changing timeScale, also wrapper for tooltip
@@ -32,22 +33,16 @@ class AxisTimeScaleChangeControls extends PureComponent {
changeTimeScale={changeTimeScale}
hasSubdailyLayers={hasSubdailyLayers}
/>
- <div
+ <Arrow
+ direction='up'
onClick={this.onClickUp}
- className="date-arrows date-arrow-up"
- >
- <svg width="25" height="8">
- <path d="M 12.5,0 25,8 0,8 z" className="uparrow" />
- </svg>
- </div>
- <div
+ type='zoom-level-up'
+ />
+ <Arrow
+ direction='down'
onClick={this.onClickDown}
- className="date-arrows date-arrow-down"
- >
- <svg width="25" height="8">
- <path d="M 12.5,0 25,8 0,8 z" className="downarrow" />
- </svg>
- </div>
+ type='zoom-level-down'
+ />
</div>
);
}
diff --git a/web/js/components/util/arrow.js b/web/js/components/util/arrow.js
new file mode 100644
index 000000000..05c93996d
--- /dev/null
+++ b/web/js/components/util/arrow.js
@@ -0,0 +1,30 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+
+/*
+ * @function Arrow Up/Down
+ */
+const Arrow = ({ onClick, type, direction }) => {
+ const containerClassName = `date-arrows date-arrow-${direction}`;
+ const arrowClassName = `${direction}arrow`;
+
+ return (
+ <div
+ onClick={onClick}
+ className={containerClassName}
+ data-interval={type}
+ >
+ <svg width="25" height="8">
+ <path d="M 12.5,0 25,8 0,8 z" className={arrowClassName} />
+ </svg>
+ </div>
+ );
+};
+
+Arrow.propTypes = {
+ direction: PropTypes.string,
+ onClick: PropTypes.func,
+ type: PropTypes.string
+};
+
+export default Arrow;