Skip to content

Commit f77c7b5

Browse files
committed
start datetimepicker
1 parent 74e6d4a commit f77c7b5

File tree

9 files changed

+120
-5
lines changed

9 files changed

+120
-5
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"url": "https://github.com/plotly/react-chart-editor/issues"
88
},
99
"dependencies": {
10+
"@blueprintjs/core": "^3.10.0",
11+
"@blueprintjs/datetime": "^3.5.0",
1012
"@plotly/draft-js-export-html": "1.2.0",
1113
"classnames": "^2.2.5",
1214
"draft-js": "^0.10.4",
@@ -52,6 +54,7 @@
5254
"eslint-plugin-import": "^2.8.0",
5355
"eslint-plugin-react": "^7.4.0",
5456
"eslint-plugin-react-percy": "^0.2.1",
57+
"file-loader": "^2.0.0",
5558
"fs": "^0.0.1-security",
5659
"gl": "^4.0.4",
5760
"glob": "^7.1.2",
@@ -125,4 +128,4 @@
125128
"watch": "babel src --watch --out-dir lib --source-maps | node-sass -w src/styles/main.scss lib/react-chart-editor.css",
126129
"watch-test": "jest --watch"
127130
}
128-
}
131+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Field from './Field';
2+
import Picker from '../widgets/DateTimePicker';
3+
import PropTypes from 'prop-types';
4+
import React, {Component} from 'react';
5+
import {connectToContainer} from 'lib';
6+
7+
export class UnconnectedDateTimePicker extends Component {
8+
render() {
9+
return (
10+
<Field {...this.props}>
11+
<Picker
12+
value={this.props.fullValue}
13+
placeholder={this.props.placeholder}
14+
onUpdate={this.props.updatePlot}
15+
onChange={this.props.onChange}
16+
/>
17+
</Field>
18+
);
19+
}
20+
}
21+
22+
UnconnectedDateTimePicker.propTypes = {
23+
fullValue: PropTypes.string,
24+
onChange: PropTypes.func,
25+
onUpdate: PropTypes.func,
26+
placeholder: PropTypes.string,
27+
...Field.propTypes,
28+
};
29+
30+
export default connectToContainer(UnconnectedDateTimePicker);

src/components/fields/NumericOrDate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Field from './Field';
22
import {UnconnectedNumeric} from './Numeric';
3-
import {UnconnectedText} from './Text';
43
import PropTypes from 'prop-types';
54
import React, {Component} from 'react';
65
import {connectToContainer} from 'lib';
76
import {isDateTime} from 'plotly.js/src/lib';
87
import {isJSDate} from 'plotly.js/src/lib/dates';
8+
import {UnconnectedDateTimePicker} from './DateTimePicker';
99

1010
export class UnconnectedNumericOrDate extends Component {
1111
render() {
@@ -14,7 +14,7 @@ export class UnconnectedNumericOrDate extends Component {
1414
(isDateTime(this.props.fullValue) || isJSDate(this.props.fullValue));
1515

1616
return fullValueIsDate ? (
17-
<UnconnectedText {...this.props} placeholder={'yyyy-mm-dd 00:00:00.00'} />
17+
<UnconnectedDateTimePicker {...this.props} placeholder={'yyyy-mm-dd 00:00:00.00'} />
1818
) : (
1919
<UnconnectedNumeric {...this.props} />
2020
);

src/components/fields/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import DropdownCustom from './DropdownCustom';
3232
import MultiColorPicker from './MultiColorPicker';
3333
import RectanglePositioner from './RectanglePositioner';
3434
import LocationSelector from './LocationSelector';
35+
import DateTimePicker from './DateTimePicker';
3536
import {
3637
AnnotationArrowRef,
3738
AnnotationRef,
@@ -122,4 +123,5 @@ export {
122123
HovermodeDropdown,
123124
BinSize,
124125
NumericOrDate,
126+
DateTimePicker,
125127
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, {Component, Fragment} from 'react';
2+
import PropTypes from 'prop-types';
3+
import {DatePicker} from '@blueprintjs/datetime';
4+
import '@blueprintjs/datetime/lib/css/blueprint-datetime.css';
5+
import '@blueprintjs/core/lib/css/blueprint.css';
6+
import '@blueprintjs/icons/lib/css/blueprint-icons.css';
7+
import TextInput from './TextInput';
8+
9+
export default class DateTimePicker extends Component {
10+
constructor(props) {
11+
super(props);
12+
13+
this.state = {
14+
value: props.fullValue,
15+
expanded: false,
16+
};
17+
18+
this.onChange = this.onChange.bind(this);
19+
}
20+
21+
componentWillReceiveProps(nextProps) {
22+
// Reset the value to the graph's actual value
23+
if (nextProps.value !== this.state.value) {
24+
this.setState({
25+
value: nextProps.value,
26+
});
27+
}
28+
}
29+
30+
onChange(e) {
31+
const newValue = e.target.value;
32+
this.setState({value: newValue});
33+
this.props.onChange(newValue);
34+
}
35+
36+
render() {
37+
return (
38+
<Fragment>
39+
<TextInput value={this.state.value} />
40+
<span
41+
style={{width: '10px', backgroundColor: 'blue', color: '#fff'}}
42+
onClick={() => {
43+
this.setState({expanded: !this.state.expanded});
44+
}}
45+
>
46+
X
47+
</span>
48+
{this.state.expanded ? <DatePicker timePrecision={'millisecond'} /> : null}
49+
</Fragment>
50+
);
51+
}
52+
}
53+
54+
DateTimePicker.propTypes = {
55+
value: PropTypes.string.isRequired,
56+
onChange: PropTypes.func.isRequired,
57+
placeholder: PropTypes.string.isRequired,
58+
};

src/components/widgets/EditableText.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class EditableText extends Component {
2424
// Selects/highlights all of the text in the filename input
2525
handleFocus(event) {
2626
event.target.select();
27+
if (this.props.onFocus) {
28+
this.props.onFocus(event);
29+
}
2730
}
2831

2932
handleChange(event) {
@@ -35,11 +38,15 @@ class EditableText extends Component {
3538
}
3639

3740
handleUpdate(event) {
38-
const {onUpdate} = this.props;
41+
const {onUpdate, onBlur} = this.props;
3942

4043
if (onUpdate) {
4144
onUpdate(event.target.value);
4245
}
46+
47+
if (onBlur) {
48+
onBlur(event);
49+
}
4350
}
4451

4552
handleKeyPress(event) {
@@ -111,6 +118,8 @@ EditableText.propTypes = {
111118
readOnly: PropTypes.bool,
112119
type: PropTypes.oneOf(['text', 'password']),
113120
size: PropTypes.number,
121+
onFocus: PropTypes.func,
122+
onBlur: PropTypes.func,
114123
};
115124

116125
EditableText.defaultProps = {

src/components/widgets/TextInput.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default class TextInput extends Component {
2929
this.setState({value});
3030
}}
3131
onUpdate={this.props.onUpdate}
32+
onFocus={this.props.onFocus}
33+
onBlur={this.props.onBlur}
3234
/>
3335
);
3436
}
@@ -41,4 +43,6 @@ TextInput.propTypes = {
4143
onChange: PropTypes.func,
4244
placeholder: PropTypes.string,
4345
value: PropTypes.any,
46+
onFocus: PropTypes.func,
47+
onBlur: PropTypes.func,
4448
};

src/components/widgets/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Button from './Button';
22
import RadioBlocks from './RadioBlocks';
3+
import DateTimePicker from './DateTimePicker';
34
import TraceTypeSelector, {TraceTypeSelectorButton} from './TraceTypeSelector';
45

5-
export {Button, RadioBlocks, TraceTypeSelector, TraceTypeSelectorButton};
6+
export {Button, RadioBlocks, TraceTypeSelector, TraceTypeSelectorButton, DateTimePicker};

webpack.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ module.exports = {
3636
test: /\.(css|scss)?$/,
3737
use: ['style-loader', 'css-loader', 'sass-loader'],
3838
},
39+
{
40+
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
41+
use: [
42+
{
43+
loader: 'file-loader',
44+
},
45+
],
46+
},
3947
],
4048
},
4149

0 commit comments

Comments
 (0)