Skip to content

Commit c66e803

Browse files
committed
Create NumericOrDate
1 parent 7b017f3 commit c66e803

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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, isJSDate} from 'plotly.js/src/lib';
8+
9+
export class UnconnectedNumericOrDate extends Component {
10+
render() {
11+
const fullValueIsDate = isDateTime(this.props.fullValue) || isJSDate(this.props.fullValue);
12+
return fullValueIsDate ? (
13+
<UnconnectedText {...this.props} />
14+
) : (
15+
<UnconnectedNumeric {...this.props} />
16+
);
17+
}
18+
}
19+
20+
UnconnectedNumericOrDate.propTypes = {
21+
defaultValue: PropTypes.any,
22+
fullValue: PropTypes.any,
23+
min: PropTypes.number,
24+
max: PropTypes.number,
25+
multiValued: PropTypes.bool,
26+
hideArrows: PropTypes.bool,
27+
showSlider: PropTypes.bool,
28+
step: PropTypes.number,
29+
fullContainer: PropTypes.object,
30+
updatePlot: PropTypes.func,
31+
...Field.propTypes,
32+
};
33+
34+
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)