Skip to content

Commit b179daf

Browse files
committed
Create NumericOrDate
1 parent 9eeb72c commit b179daf

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Field from './Field';
2+
import {UnconnectedNumeric} from './Numeric';
3+
import {UnconnectedText} from './Text';
4+
import PropTypes from 'prop-types';
5+
import React, {Component} from 'react';
6+
import {connectToContainer} from 'lib';
7+
import {isDateTime} from 'plotly.js/src/lib';
8+
import {isJSDate} from 'plotly.js/src/lib/dates';
9+
10+
export class UnconnectedNumericOrDate extends Component {
11+
render() {
12+
const fullValueIsDate =
13+
typeof this.props.fullValue === 'string' &&
14+
(isDateTime(this.props.fullValue) || isJSDate(this.props.fullValue));
15+
16+
return fullValueIsDate ? (
17+
<UnconnectedText {...this.props} placeholder={'yyyy-mm-dd 00:00:00.00'} />
18+
) : (
19+
<UnconnectedNumeric {...this.props} />
20+
);
21+
}
22+
}
23+
24+
UnconnectedNumericOrDate.propTypes = {
25+
defaultValue: PropTypes.any,
26+
fullValue: PropTypes.any,
27+
min: PropTypes.number,
28+
max: PropTypes.number,
29+
multiValued: PropTypes.bool,
30+
hideArrows: PropTypes.bool,
31+
showSlider: PropTypes.bool,
32+
step: PropTypes.number,
33+
fullContainer: PropTypes.object,
34+
updatePlot: PropTypes.func,
35+
...Field.propTypes,
36+
};
37+
38+
export default connectToContainer(UnconnectedNumericOrDate);

src/components/fields/derived.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {UnconnectedDropdown} from './Dropdown';
33
import {UnconnectedDropdownCustom} from './DropdownCustom';
44
import {UnconnectedFlaglist} from './Flaglist';
55
import {UnconnectedNumeric} from './Numeric';
6+
import {UnconnectedNumericOrDate} from './NumericOrDate';
67
import {UnconnectedAxisRangeValue} from './AxisRangeValue';
78
import {UnconnectedRadio} from './Radio';
89
import Info from './Info';
@@ -196,6 +197,8 @@ export const AxesRange = connectToContainer(UnconnectedAxisRangeValue, {
196197
},
197198
});
198199

200+
export const NumericOrDate = connectToContainer(UnconnectedNumericOrDate);
201+
199202
export const NTicks = connectToContainer(UnconnectedNumeric, {
200203
modifyPlotProps: (props, context, plotProps) => {
201204
const {fullContainer} = plotProps;

src/components/fields/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
HoveronDropdown,
5656
HovermodeDropdown,
5757
TickFormat,
58+
NumericOrDate,
5859
} from './derived';
5960
import {LineDashSelector, LineShapeSelector} from './LineSelectors';
6061

@@ -118,4 +119,5 @@ export {
118119
LocationSelector,
119120
HoveronDropdown,
120121
HovermodeDropdown,
122+
NumericOrDate,
121123
};

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
HoveronDropdown,
5858
HovermodeDropdown,
5959
TickFormat,
60+
NumericOrDate,
6061
} from './fields';
6162

6263
import {
@@ -175,4 +176,5 @@ export {
175176
LocationSelector,
176177
HoveronDropdown,
177178
HovermodeDropdown,
179+
NumericOrDate,
178180
};

0 commit comments

Comments
 (0)