kitchen-simulator 5.0.0-test.15 → 5.0.0-test.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -11
- package/src/KitchenConfiguratorApp.jsx +1 -1
- package/src/_KitchenConfigurator.jsx +2 -46
- package/src/_index.js +2 -2
- package/src/actions/_export.js +35 -0
- package/src/components/atoms/Snackbar/index.jsx +0 -43
- package/src/components/atoms/radio-button/index.jsx +0 -20
- package/src/components/atoms/radio-button/styles.js +0 -56
- package/src/components/button/MainButton.jsx +0 -157
- package/src/components/button/ToggleMeasureButton.jsx +0 -65
- package/src/components/content.jsx +0 -136
- package/src/components/molecules/slider/index.jsx +0 -15
- package/src/components/molecules/slider/styles.js +0 -0
- package/src/components/molecules/slider/styles.scss +0 -3
- package/src/components/style/button.jsx +0 -95
- package/src/components/style/cancel-button.jsx +0 -20
- package/src/components/style/content-container.jsx +0 -29
- package/src/components/style/content-title.jsx +0 -20
- package/src/components/style/delete-button.jsx +0 -23
- package/src/components/style/export.jsx +0 -48
- package/src/components/style/form-block.jsx +0 -13
- package/src/components/style/form-color-input.jsx +0 -27
- package/src/components/style/form-label.jsx +0 -15
- package/src/components/style/form-number-input.jsx +0 -196
- package/src/components/style/form-number-input_2.jsx +0 -191
- package/src/components/style/form-select.jsx +0 -38
- package/src/components/style/form-slider.jsx +0 -36
- package/src/components/style/form-submit-button.jsx +0 -23
- package/src/components/style/form-text-input.jsx +0 -65
- package/src/components/tutorial-view/Modal.jsx +0 -584
- package/src/components/tutorial-view/style.css +0 -111
- package/src/components/tutorial-view/styles.js +0 -65
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import * as SharedStyle from '../../shared-style';
|
|
4
|
-
|
|
5
|
-
const BASE_STYLE = {
|
|
6
|
-
display: 'inline-block',
|
|
7
|
-
fontWeight: '400',
|
|
8
|
-
lineHeight: '1.25',
|
|
9
|
-
textAlign: 'center',
|
|
10
|
-
whiteSpace: 'nowrap',
|
|
11
|
-
verticalAlign: 'middle',
|
|
12
|
-
cursor: 'pointer',
|
|
13
|
-
WebkitUserSelect: 'none',
|
|
14
|
-
MozUserSelect: 'none',
|
|
15
|
-
MsUserSelect: 'none',
|
|
16
|
-
userSelect: 'none',
|
|
17
|
-
padding: '5px 14px',
|
|
18
|
-
fontSize: '14px',
|
|
19
|
-
color: SharedStyle.COLORS.black,
|
|
20
|
-
fonWeight: '400px',
|
|
21
|
-
transition: 'background-color 175ms ease, border 175ms ease',
|
|
22
|
-
outline: 'none',
|
|
23
|
-
borderRadius: '2px',
|
|
24
|
-
borderWidth: '1px',
|
|
25
|
-
borderType: 'solid',
|
|
26
|
-
width: '100%'
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const BASE_STYLE_SIZE = {
|
|
30
|
-
small: {
|
|
31
|
-
fontSize: '12px',
|
|
32
|
-
padding: '3px 8px'
|
|
33
|
-
},
|
|
34
|
-
normal: {},
|
|
35
|
-
large: {
|
|
36
|
-
padding: '8px 20px'
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export default class Button extends Component {
|
|
41
|
-
constructor(props) {
|
|
42
|
-
super(props);
|
|
43
|
-
this.state = { hover: false };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
render() {
|
|
47
|
-
let { hover } = this.state;
|
|
48
|
-
let {
|
|
49
|
-
type,
|
|
50
|
-
style: customStyle,
|
|
51
|
-
styleHover: customStyleHover,
|
|
52
|
-
children,
|
|
53
|
-
size,
|
|
54
|
-
...rest
|
|
55
|
-
} = this.props;
|
|
56
|
-
let styleMerged = Object.assign(
|
|
57
|
-
{},
|
|
58
|
-
BASE_STYLE,
|
|
59
|
-
BASE_STYLE_SIZE[size],
|
|
60
|
-
hover ? customStyleHover : customStyle
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<button
|
|
65
|
-
type={type}
|
|
66
|
-
onMouseEnter={e => this.setState({ hover: true })}
|
|
67
|
-
onMouseLeave={e => this.setState({ hover: false })}
|
|
68
|
-
style={styleMerged}
|
|
69
|
-
{...rest}
|
|
70
|
-
>
|
|
71
|
-
{children}
|
|
72
|
-
</button>
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
Button.defaultProps = {
|
|
78
|
-
type: 'button',
|
|
79
|
-
size: 'normal',
|
|
80
|
-
style: {
|
|
81
|
-
backgroundColor: '#e6e6e6',
|
|
82
|
-
borderColor: '#adadad'
|
|
83
|
-
},
|
|
84
|
-
styleHover: {
|
|
85
|
-
backgroundColor: '#d4d4d4',
|
|
86
|
-
borderColor: '#8c8c8c'
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
Button.propTypes = {
|
|
91
|
-
type: PropTypes.string,
|
|
92
|
-
style: PropTypes.object,
|
|
93
|
-
styleHover: PropTypes.object,
|
|
94
|
-
size: PropTypes.oneOf(['large', 'normal', 'small'])
|
|
95
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Button from './button';
|
|
3
|
-
|
|
4
|
-
const STYLE = {
|
|
5
|
-
borderColor: '#adadad',
|
|
6
|
-
backgroundColor: '#e6e6e6'
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const STYLE_HOVER = {
|
|
10
|
-
backgroundColor: '#d4d4d4',
|
|
11
|
-
borderColor: '#8c8c8c'
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default function CancelButton({ children, ...rest }) {
|
|
15
|
-
return (
|
|
16
|
-
<Button style={STYLE} styleHover={STYLE_HOVER} {...rest}>
|
|
17
|
-
{children}
|
|
18
|
-
</Button>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
const STYLE = {
|
|
5
|
-
padding: '0 20px',
|
|
6
|
-
overflowY: 'auto'
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default function ContentContainer({
|
|
10
|
-
children,
|
|
11
|
-
width,
|
|
12
|
-
height,
|
|
13
|
-
style = {}
|
|
14
|
-
}) {
|
|
15
|
-
return (
|
|
16
|
-
<div
|
|
17
|
-
style={{ width, height, ...STYLE, ...style }}
|
|
18
|
-
onWheel={event => event.stopPropagation()}
|
|
19
|
-
>
|
|
20
|
-
{children}
|
|
21
|
-
</div>
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
ContentContainer.propsType = {
|
|
26
|
-
width: PropTypes.number.isRequired,
|
|
27
|
-
height: PropTypes.number.isRequired,
|
|
28
|
-
style: PropTypes.object
|
|
29
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import * as SharedStyle from '../../shared-style';
|
|
4
|
-
|
|
5
|
-
const STYLE = {
|
|
6
|
-
color: SharedStyle.PRIMARY_COLOR.alt,
|
|
7
|
-
fontWeight: 300
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export default function ContentTitle({ children, style = {}, ...rest }) {
|
|
11
|
-
return (
|
|
12
|
-
<h1 style={{ ...STYLE, ...style }} {...rest}>
|
|
13
|
-
{children}
|
|
14
|
-
</h1>
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
ContentTitle.propsType = {
|
|
19
|
-
style: PropTypes.object
|
|
20
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Button from './button';
|
|
3
|
-
import * as SharedStyle from '../../shared-style';
|
|
4
|
-
|
|
5
|
-
const STYLE = {
|
|
6
|
-
borderColor: '#c12e2a',
|
|
7
|
-
backgroundColor: '#c9302c',
|
|
8
|
-
color: SharedStyle.COLORS.white
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const STYLE_HOVER = {
|
|
12
|
-
backgroundColor: '#972726',
|
|
13
|
-
borderColor: '#c12e2a',
|
|
14
|
-
color: SharedStyle.COLORS.white
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default function FormDeleteButton({ children, ...rest }) {
|
|
18
|
-
return (
|
|
19
|
-
<Button style={STYLE} styleHover={STYLE_HOVER} {...rest}>
|
|
20
|
-
{children}
|
|
21
|
-
</Button>
|
|
22
|
-
);
|
|
23
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import Button from './button';
|
|
2
|
-
import CancelButton from './cancel-button';
|
|
3
|
-
import ContentContainer from './content-container';
|
|
4
|
-
import ContentTitle from './content-title';
|
|
5
|
-
import DeleteButton from './delete-button';
|
|
6
|
-
import FormBlock from './form-block';
|
|
7
|
-
import FormColorInput from './form-color-input';
|
|
8
|
-
import FormLabel from './form-label';
|
|
9
|
-
import FormNumberInput from './form-number-input';
|
|
10
|
-
import FormSelect from './form-select';
|
|
11
|
-
import FormSlider from './form-slider';
|
|
12
|
-
import FormSubmitButton from './form-submit-button';
|
|
13
|
-
import FormTextInput from './form-text-input';
|
|
14
|
-
import FormNumberInput2 from './form-number-input_2';
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
Button,
|
|
18
|
-
CancelButton,
|
|
19
|
-
ContentContainer,
|
|
20
|
-
ContentTitle,
|
|
21
|
-
DeleteButton,
|
|
22
|
-
FormBlock,
|
|
23
|
-
FormColorInput,
|
|
24
|
-
FormLabel,
|
|
25
|
-
FormNumberInput,
|
|
26
|
-
FormSelect,
|
|
27
|
-
FormSlider,
|
|
28
|
-
FormSubmitButton,
|
|
29
|
-
FormTextInput,
|
|
30
|
-
FormNumberInput2
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default {
|
|
34
|
-
Button,
|
|
35
|
-
CancelButton,
|
|
36
|
-
ContentContainer,
|
|
37
|
-
ContentTitle,
|
|
38
|
-
DeleteButton,
|
|
39
|
-
FormBlock,
|
|
40
|
-
FormColorInput,
|
|
41
|
-
FormLabel,
|
|
42
|
-
FormNumberInput,
|
|
43
|
-
FormSelect,
|
|
44
|
-
FormSlider,
|
|
45
|
-
FormSubmitButton,
|
|
46
|
-
FormTextInput,
|
|
47
|
-
FormNumberInput2
|
|
48
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import FormTextInput from './form-text-input';
|
|
3
|
-
|
|
4
|
-
const STYLE = {
|
|
5
|
-
padding: 0,
|
|
6
|
-
border: 0
|
|
7
|
-
};
|
|
8
|
-
const EREG_NUMBER = /^.*$/;
|
|
9
|
-
|
|
10
|
-
export default function FormColorInput({ onChange, ...rest }) {
|
|
11
|
-
let onChangeCustom = event => {
|
|
12
|
-
let value = event.target.value;
|
|
13
|
-
if (EREG_NUMBER.test(value)) {
|
|
14
|
-
onChange(event);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<FormTextInput
|
|
20
|
-
type="color"
|
|
21
|
-
style={STYLE}
|
|
22
|
-
onChange={onChangeCustom}
|
|
23
|
-
autoComplete="off"
|
|
24
|
-
{...rest}
|
|
25
|
-
/>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
const BASE_STYLE = {
|
|
4
|
-
display: 'block',
|
|
5
|
-
marginBottom: '2px',
|
|
6
|
-
fontSize: '12px'
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default function FormLabel({ children, style, ...rest }) {
|
|
10
|
-
return (
|
|
11
|
-
<label style={{ ...BASE_STYLE, style }} {...rest}>
|
|
12
|
-
{children}
|
|
13
|
-
</label>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
4
|
-
KEYBOARD_BUTTON_CODE,
|
|
5
|
-
TEXT_COLOR_NEUTRAL_0,
|
|
6
|
-
SECONDARY_PURPLE_COLOR,
|
|
7
|
-
DEFAULT_FONT_FAMILY
|
|
8
|
-
} from '../../constants';
|
|
9
|
-
import styled from 'styled-components';
|
|
10
|
-
import { isValidNumber } from '../../utils/helper';
|
|
11
|
-
|
|
12
|
-
const StyledInput = styled.input`
|
|
13
|
-
display: block;
|
|
14
|
-
padding: 15px 25px 12px 0px;
|
|
15
|
-
width: 120px;
|
|
16
|
-
color: ${TEXT_COLOR_NEUTRAL_0};
|
|
17
|
-
background-color: rgb(255, 255, 255);
|
|
18
|
-
border: 2px solid;
|
|
19
|
-
text-align: right;
|
|
20
|
-
float: right;
|
|
21
|
-
font-family: ${DEFAULT_FONT_FAMILY};
|
|
22
|
-
font-size: 16px;
|
|
23
|
-
font-weight: 600;
|
|
24
|
-
line-height: 17px;
|
|
25
|
-
border-radius: 5px;
|
|
26
|
-
outline: 0;
|
|
27
|
-
:focus {
|
|
28
|
-
border-color: ${SECONDARY_PURPLE_COLOR};
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
export default class FormNumberInput extends Component {
|
|
33
|
-
constructor(props, context) {
|
|
34
|
-
super(props, context);
|
|
35
|
-
this.state = {
|
|
36
|
-
focus: false,
|
|
37
|
-
valid: true,
|
|
38
|
-
showedValue: props.value,
|
|
39
|
-
focusOn: false,
|
|
40
|
-
flag: true
|
|
41
|
-
};
|
|
42
|
-
this.input = React.createRef(null);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
componentDidMount() {
|
|
46
|
-
if (
|
|
47
|
-
this.input.current &&
|
|
48
|
-
['width', 'length'].includes(this.props.labelName.toLowerCase())
|
|
49
|
-
) {
|
|
50
|
-
this.input.current.focus();
|
|
51
|
-
this.input.current.select();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
componentWillReceiveProps(nextProps) {
|
|
56
|
-
if (
|
|
57
|
-
this.props.value !== nextProps.value ||
|
|
58
|
-
this.props.focus !== nextProps.focus
|
|
59
|
-
) {
|
|
60
|
-
this.setState({ showedValue: nextProps.value, focusOn: nextProps.focus });
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
componentDidUpdate(prevProps, preprevState) {
|
|
65
|
-
if (
|
|
66
|
-
this.props.value !== prevProps.value &&
|
|
67
|
-
prevProps.labelName !== 'Ceiling Height'
|
|
68
|
-
) {
|
|
69
|
-
this.input.current.focus();
|
|
70
|
-
this.input.current.select();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const { showedValue } = this.state;
|
|
74
|
-
const { min, max, isCeiling } = this.props;
|
|
75
|
-
|
|
76
|
-
if (!isCeiling) {
|
|
77
|
-
if (isValidNumber(min) && showedValue < min) {
|
|
78
|
-
this.setState({ showedValue: min });
|
|
79
|
-
} else if (isValidNumber(max) && showedValue > max) {
|
|
80
|
-
this.setState({ showedValue: max });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
render() {
|
|
87
|
-
let {
|
|
88
|
-
value,
|
|
89
|
-
min,
|
|
90
|
-
max,
|
|
91
|
-
precision,
|
|
92
|
-
onChange,
|
|
93
|
-
onValid,
|
|
94
|
-
onInvalid,
|
|
95
|
-
style,
|
|
96
|
-
placeholder,
|
|
97
|
-
isCeiling
|
|
98
|
-
} = this.props;
|
|
99
|
-
let regexp = new RegExp(`^-?([0-9]+)?\\.?([0-9]{0,${precision}})?$`);
|
|
100
|
-
|
|
101
|
-
let currValue = regexp.test(this.state.showedValue)
|
|
102
|
-
? this.state.showedValue
|
|
103
|
-
: parseFloat(this.state.showedValue).toFixed(precision);
|
|
104
|
-
|
|
105
|
-
let different =
|
|
106
|
-
parseFloat(this.props.value).toFixed(precision) !==
|
|
107
|
-
parseFloat(this.state.showedValue).toFixed(precision);
|
|
108
|
-
|
|
109
|
-
let saveFn = e => {
|
|
110
|
-
e.stopPropagation();
|
|
111
|
-
|
|
112
|
-
if (this.state.valid) {
|
|
113
|
-
let savedValue =
|
|
114
|
-
this.state.showedValue !== '' && this.state.showedValue !== '-'
|
|
115
|
-
? parseFloat(this.state.showedValue)
|
|
116
|
-
: 0;
|
|
117
|
-
|
|
118
|
-
this.setState({ showedValue: savedValue });
|
|
119
|
-
onChange({ target: { value: savedValue } });
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
return (
|
|
124
|
-
<StyledInput
|
|
125
|
-
id="form_number_input"
|
|
126
|
-
autoFocus={this.state.focusOn}
|
|
127
|
-
readOnly={!!this.props.disabled}
|
|
128
|
-
type="text"
|
|
129
|
-
value={currValue}
|
|
130
|
-
style={style}
|
|
131
|
-
onChange={evt => {
|
|
132
|
-
this.context.projectActions.copyProperties('ddddd');
|
|
133
|
-
let valid = regexp.test(evt.nativeEvent.target.value);
|
|
134
|
-
|
|
135
|
-
if (valid) {
|
|
136
|
-
this.setState({
|
|
137
|
-
showedValue: evt.nativeEvent.target.value,
|
|
138
|
-
flag: false
|
|
139
|
-
});
|
|
140
|
-
if (onValid) onValid(evt.nativeEvent);
|
|
141
|
-
} else {
|
|
142
|
-
if (onInvalid) onInvalid(evt.nativeEvent);
|
|
143
|
-
}
|
|
144
|
-
this.setState({ valid });
|
|
145
|
-
}}
|
|
146
|
-
onFocus={e => this.setState({ focusOn: true })}
|
|
147
|
-
onBlur={e => this.setState({ focusOn: false })}
|
|
148
|
-
ref={this.input}
|
|
149
|
-
onKeyDown={e => {
|
|
150
|
-
var keyCode = e.keyCode || e.which;
|
|
151
|
-
if (
|
|
152
|
-
keyCode == KEYBOARD_BUTTON_CODE.ENTER ||
|
|
153
|
-
keyCode == KEYBOARD_BUTTON_CODE.TAB
|
|
154
|
-
) {
|
|
155
|
-
saveFn(e);
|
|
156
|
-
this.input.current.blur();
|
|
157
|
-
}
|
|
158
|
-
if (keyCode == KEYBOARD_BUTTON_CODE.ESC) {
|
|
159
|
-
this.context.projectActions.rollback();
|
|
160
|
-
}
|
|
161
|
-
}}
|
|
162
|
-
placeholder={placeholder}
|
|
163
|
-
/>
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
FormNumberInput.propTypes = {
|
|
169
|
-
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
170
|
-
style: PropTypes.object,
|
|
171
|
-
onChange: PropTypes.func.isRequired,
|
|
172
|
-
onValid: PropTypes.func,
|
|
173
|
-
onInvalid: PropTypes.func,
|
|
174
|
-
min: PropTypes.number,
|
|
175
|
-
max: PropTypes.number,
|
|
176
|
-
precision: PropTypes.number,
|
|
177
|
-
placeholder: PropTypes.string,
|
|
178
|
-
labelName: PropTypes.string,
|
|
179
|
-
isCeiling: PropTypes.string
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
FormNumberInput.contextTypes = {
|
|
183
|
-
translator: PropTypes.object.isRequired,
|
|
184
|
-
projectActions: PropTypes.object.isRequired,
|
|
185
|
-
linesActions: PropTypes.object.isRequired
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
FormNumberInput.defaultProps = {
|
|
189
|
-
value: 0,
|
|
190
|
-
style: {},
|
|
191
|
-
min: Number.MIN_SAFE_INTEGER,
|
|
192
|
-
max: Number.MAX_SAFE_INTEGER,
|
|
193
|
-
precision: 2,
|
|
194
|
-
disabled: false,
|
|
195
|
-
labelName: 'default'
|
|
196
|
-
};
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import * as SharedStyle from '../../shared-style';
|
|
4
|
-
import { MdUpdate } from 'react-icons/md';
|
|
5
|
-
import { KEYBOARD_BUTTON_CODE } from '../../constants';
|
|
6
|
-
|
|
7
|
-
const STYLE_INPUT = {
|
|
8
|
-
display: 'block',
|
|
9
|
-
width: '100%',
|
|
10
|
-
padding: '0 2px',
|
|
11
|
-
fontSize: '13px',
|
|
12
|
-
lineHeight: '1.25',
|
|
13
|
-
color: SharedStyle.PRIMARY_COLOR.input,
|
|
14
|
-
backgroundColor: SharedStyle.COLORS.white,
|
|
15
|
-
backgroundImage: 'none',
|
|
16
|
-
border: '1px solid rgba(0,0,0,.15)',
|
|
17
|
-
outline: 'none',
|
|
18
|
-
height: '30px'
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const confirmStyle = {
|
|
22
|
-
position: 'absolute',
|
|
23
|
-
cursor: 'pointer',
|
|
24
|
-
width: '20px',
|
|
25
|
-
height: '20px',
|
|
26
|
-
right: '5px',
|
|
27
|
-
top: '5px',
|
|
28
|
-
backgroundColor: SharedStyle.SECONDARY_COLOR.main,
|
|
29
|
-
color: '#FFF',
|
|
30
|
-
transition: 'all 0.1s linear'
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default class FormNumberInput extends Component {
|
|
34
|
-
constructor(props, context) {
|
|
35
|
-
super(props, context);
|
|
36
|
-
this.state = {
|
|
37
|
-
focus: false,
|
|
38
|
-
valid: true,
|
|
39
|
-
showedValue: props.value,
|
|
40
|
-
disabled: props.disabled === true ? true : false,
|
|
41
|
-
focusOn: false
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
componentWillReceiveProps(nextProps) {
|
|
46
|
-
if (
|
|
47
|
-
this.props.value !== nextProps.value ||
|
|
48
|
-
this.props.focus !== nextProps.focus
|
|
49
|
-
) {
|
|
50
|
-
this.setState({ showedValue: nextProps.value, focusOn: nextProps.focus });
|
|
51
|
-
}
|
|
52
|
-
if (this.props.focus !== nextProps.focus) {
|
|
53
|
-
this.Input.focus();
|
|
54
|
-
this.Input.select();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
render() {
|
|
59
|
-
let {
|
|
60
|
-
value,
|
|
61
|
-
min,
|
|
62
|
-
max,
|
|
63
|
-
precision,
|
|
64
|
-
onChange,
|
|
65
|
-
onValid,
|
|
66
|
-
onInvalid,
|
|
67
|
-
style,
|
|
68
|
-
placeholder
|
|
69
|
-
} = this.props;
|
|
70
|
-
let numericInputStyle = { ...STYLE_INPUT, ...style };
|
|
71
|
-
if (this.state.focusOn)
|
|
72
|
-
numericInputStyle.border = `1px solid ${SharedStyle.SECONDARY_COLOR.main}`;
|
|
73
|
-
let regexp = new RegExp(`^-?([0-9]+)?\\.?([0-9]{0,${precision}})?$`);
|
|
74
|
-
|
|
75
|
-
if (!isNaN(min) && isFinite(min) && this.state.showedValue < min)
|
|
76
|
-
this.setState({ showedValue: min }); // value = min;
|
|
77
|
-
if (!isNaN(max) && isFinite(max) && this.state.showedValue > max)
|
|
78
|
-
this.setState({ showedValue: max }); // value = max;
|
|
79
|
-
|
|
80
|
-
let currValue = regexp.test(this.state.showedValue)
|
|
81
|
-
? this.state.showedValue
|
|
82
|
-
: parseFloat(this.state.showedValue).toFixed(precision);
|
|
83
|
-
|
|
84
|
-
let different =
|
|
85
|
-
parseFloat(this.props.value).toFixed(precision) !==
|
|
86
|
-
parseFloat(this.state.showedValue).toFixed(precision);
|
|
87
|
-
|
|
88
|
-
let saveFn = e => {
|
|
89
|
-
e.stopPropagation();
|
|
90
|
-
|
|
91
|
-
if (this.state.valid) {
|
|
92
|
-
let savedValue =
|
|
93
|
-
this.state.showedValue !== '' && this.state.showedValue !== '-'
|
|
94
|
-
? parseFloat(this.state.showedValue)
|
|
95
|
-
: 0;
|
|
96
|
-
|
|
97
|
-
this.setState({ showedValue: savedValue });
|
|
98
|
-
onChange({ target: { value: savedValue } });
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
return (
|
|
103
|
-
<div style={{ position: 'relative' }}>
|
|
104
|
-
<input
|
|
105
|
-
autoFocus={this.state.focusOn}
|
|
106
|
-
readOnly={this.state.disabled}
|
|
107
|
-
type="text"
|
|
108
|
-
value={currValue}
|
|
109
|
-
style={numericInputStyle}
|
|
110
|
-
onChange={evt => {
|
|
111
|
-
let valid = regexp.test(evt.nativeEvent.target.value);
|
|
112
|
-
|
|
113
|
-
if (valid) {
|
|
114
|
-
this.setState({ showedValue: evt.nativeEvent.target.value });
|
|
115
|
-
if (onValid) onValid(evt.nativeEvent);
|
|
116
|
-
} else {
|
|
117
|
-
if (onInvalid) onInvalid(evt.nativeEvent);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.setState({ valid });
|
|
121
|
-
}}
|
|
122
|
-
onFocus={e => this.setState({ focusOn: true })}
|
|
123
|
-
onBlur={e => this.setState({ focusOn: false })}
|
|
124
|
-
ref={ele => {
|
|
125
|
-
this.Input = ele;
|
|
126
|
-
}}
|
|
127
|
-
onKeyDown={e => {
|
|
128
|
-
var keyCode = e.keyCode || e.which;
|
|
129
|
-
if (
|
|
130
|
-
keyCode == KEYBOARD_BUTTON_CODE.ENTER ||
|
|
131
|
-
keyCode == KEYBOARD_BUTTON_CODE.TAB
|
|
132
|
-
) {
|
|
133
|
-
saveFn(e);
|
|
134
|
-
this.Input.blur();
|
|
135
|
-
}
|
|
136
|
-
if (keyCode == KEYBOARD_BUTTON_CODE.ESC) {
|
|
137
|
-
this.context.projectActions.rollback();
|
|
138
|
-
}
|
|
139
|
-
}}
|
|
140
|
-
placeholder={placeholder}
|
|
141
|
-
/>
|
|
142
|
-
<div
|
|
143
|
-
onClick={e => {
|
|
144
|
-
if (different) saveFn(e);
|
|
145
|
-
}}
|
|
146
|
-
title={this.context.translator.t('Confirm')}
|
|
147
|
-
style={{
|
|
148
|
-
...confirmStyle,
|
|
149
|
-
visibility: different ? 'visible' : 'hidden',
|
|
150
|
-
opacity: different ? '1' : '0'
|
|
151
|
-
}}
|
|
152
|
-
>
|
|
153
|
-
<MdUpdate
|
|
154
|
-
style={{
|
|
155
|
-
width: '100%',
|
|
156
|
-
height: '100%',
|
|
157
|
-
padding: '0.2em',
|
|
158
|
-
color: '#FFF'
|
|
159
|
-
}}
|
|
160
|
-
/>
|
|
161
|
-
</div>
|
|
162
|
-
</div>
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
FormNumberInput.propTypes = {
|
|
168
|
-
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
169
|
-
style: PropTypes.object,
|
|
170
|
-
onChange: PropTypes.func.isRequired,
|
|
171
|
-
onValid: PropTypes.func,
|
|
172
|
-
onInvalid: PropTypes.func,
|
|
173
|
-
min: PropTypes.number,
|
|
174
|
-
max: PropTypes.number,
|
|
175
|
-
precision: PropTypes.number,
|
|
176
|
-
placeholder: PropTypes.string
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
FormNumberInput.contextTypes = {
|
|
180
|
-
translator: PropTypes.object.isRequired,
|
|
181
|
-
projectActions: PropTypes.object.isRequired
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
FormNumberInput.defaultProps = {
|
|
185
|
-
value: 0,
|
|
186
|
-
style: {},
|
|
187
|
-
min: Number.MIN_SAFE_INTEGER,
|
|
188
|
-
max: Number.MAX_SAFE_INTEGER,
|
|
189
|
-
precision: 2,
|
|
190
|
-
disabled: false
|
|
191
|
-
};
|