@pie-lib/config-ui 10.12.2 → 10.13.1
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/CHANGELOG.md +29 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/number-text-field-custom.js +308 -0
- package/lib/number-text-field-custom.js.map +1 -0
- package/package.json +4 -4
- package/src/index.js +2 -0
- package/src/number-text-field-custom.jsx +225 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,35 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.13.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/config-ui@10.13.0...@pie-lib/config-ui@10.13.1) (2022-05-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @pie-lib/config-ui
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [10.13.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/config-ui@10.12.3...@pie-lib/config-ui@10.13.0) (2022-05-16)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **config-ui:** number text field UI improvements ([3b72537](https://github.com/pie-framework/pie-lib/commit/3b72537ebf29aab293bbb61d6be34888385a850b))
|
|
20
|
+
* **config-ui:** number text field UI improvements ([ed8cdb6](https://github.com/pie-framework/pie-lib/commit/ed8cdb6d6f15763c3b85c9d2dfbeadf49bbcd5d8))
|
|
21
|
+
* implemented custom number text field ([7e5dd09](https://github.com/pie-framework/pie-lib/commit/7e5dd09bb0d5ceb7e7214b8b2cc0b5ee1964b2bb))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## [10.12.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/config-ui@10.12.2...@pie-lib/config-ui@10.12.3) (2022-05-10)
|
|
28
|
+
|
|
29
|
+
**Note:** Version bump only for package @pie-lib/config-ui
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
6
35
|
## [10.12.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/config-ui@10.12.1...@pie-lib/config-ui@10.12.2) (2022-05-09)
|
|
7
36
|
|
|
8
37
|
**Note:** Version bump only for package @pie-lib/config-ui
|
package/lib/index.js
CHANGED
|
@@ -113,6 +113,12 @@ Object.defineProperty(exports, "NumberTextField", {
|
|
|
113
113
|
return _numberTextField["default"];
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
|
+
Object.defineProperty(exports, "NumberTextFieldCustom", {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function get() {
|
|
119
|
+
return _numberTextFieldCustom["default"];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
116
122
|
Object.defineProperty(exports, "Tabs", {
|
|
117
123
|
enumerable: true,
|
|
118
124
|
get: function get() {
|
|
@@ -174,6 +180,8 @@ var _renderUi = require("@pie-lib/render-ui");
|
|
|
174
180
|
|
|
175
181
|
var _numberTextField = _interopRequireDefault(require("./number-text-field"));
|
|
176
182
|
|
|
183
|
+
var _numberTextFieldCustom = _interopRequireDefault(require("./number-text-field-custom"));
|
|
184
|
+
|
|
177
185
|
var _twoChoice = _interopRequireWildcard(require("./two-choice"));
|
|
178
186
|
|
|
179
187
|
var _tagsInput = _interopRequireDefault(require("./tags-input"));
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAEA;;;;AACA;;AACA;;AACA;;AAEA","sourcesContent":["import AlertDialog from './alert-dialog';\nimport FeedbackConfig, {\n FeedbackSelector,\n buildDefaults as feedbackConfigDefaults\n} from './feedback-config';\nimport { InputCheckbox, InputSwitch, InputRadio } from './inputs';\nimport Langs, { LanguageControls } from './langs';\nimport Tabs from './tabs';\nimport Checkbox from './checkbox';\nimport FormSection from './form-section';\nimport Help from './help';\nimport Input from './input';\nimport { InputContainer } from '@pie-lib/render-ui';\nimport NumberTextField from './number-text-field';\nimport NumberTextFieldCustom from './number-text-field-custom';\nimport TwoChoice, { NChoice } from './two-choice';\nimport TagsInput from './tags-input';\nimport MuiBox from './mui-box';\nimport ChoiceConfiguration from './choice-configuration';\nimport * as layout from './layout';\n\nimport * as choiceUtils from './choice-utils';\nimport withStatefulModel from './with-stateful-model';\nimport Toggle from './settings/toggle';\nimport DisplaySize from './settings/display-size';\n\nimport * as settings from './settings';\n\nexport {\n AlertDialog,\n FeedbackConfig,\n FeedbackSelector,\n feedbackConfigDefaults,\n InputCheckbox,\n InputSwitch,\n InputRadio,\n Langs,\n LanguageControls,\n Tabs,\n Checkbox,\n FormSection,\n Help,\n Input,\n InputContainer,\n NumberTextField,\n NumberTextFieldCustom,\n TwoChoice,\n NChoice,\n TagsInput,\n MuiBox,\n ChoiceConfiguration,\n layout,\n choiceUtils,\n withStatefulModel,\n Toggle,\n DisplaySize,\n settings\n};\n"],"file":"index.js"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = exports.NumberTextFieldCustom = void 0;
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));
|
|
15
|
+
|
|
16
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
17
|
+
|
|
18
|
+
var _styles = require("@material-ui/core/styles");
|
|
19
|
+
|
|
20
|
+
var _isFinite = _interopRequireDefault(require("lodash/isFinite"));
|
|
21
|
+
|
|
22
|
+
var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
|
|
23
|
+
|
|
24
|
+
var _InputAdornment = _interopRequireDefault(require("@material-ui/core/InputAdornment"));
|
|
25
|
+
|
|
26
|
+
var _Remove = _interopRequireDefault(require("@material-ui/icons/Remove"));
|
|
27
|
+
|
|
28
|
+
var _Add = _interopRequireDefault(require("@material-ui/icons/Add"));
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
|
+
|
|
32
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
33
|
+
|
|
34
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
35
|
+
|
|
36
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
37
|
+
|
|
38
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
39
|
+
|
|
40
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
41
|
+
|
|
42
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
43
|
+
|
|
44
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
45
|
+
|
|
46
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
47
|
+
|
|
48
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
49
|
+
|
|
50
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
51
|
+
|
|
52
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
53
|
+
|
|
54
|
+
var styles = function styles(theme) {
|
|
55
|
+
return {
|
|
56
|
+
input: {
|
|
57
|
+
'& input[type=number]': {
|
|
58
|
+
'-moz-appearance': 'textfield'
|
|
59
|
+
},
|
|
60
|
+
'& input[type=number]::-webkit-outer-spin-button': {
|
|
61
|
+
'-webkit-appearance': 'none',
|
|
62
|
+
margin: 0
|
|
63
|
+
},
|
|
64
|
+
'& input[type=number]::-webkit-inner-spin-button': {
|
|
65
|
+
'-webkit-appearance': 'none',
|
|
66
|
+
margin: 0
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
iconButton: {
|
|
70
|
+
padding: '2px'
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
var fallbackNumber = function fallbackNumber(min, max) {
|
|
76
|
+
if (!(0, _isFinite["default"])(min) && !(0, _isFinite["default"])(max)) {
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!(0, _isFinite["default"])(min) && (0, _isFinite["default"])(max)) {
|
|
81
|
+
return max;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if ((0, _isFinite["default"])(min)) {
|
|
85
|
+
return min;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var NumberTextFieldCustom = /*#__PURE__*/function (_React$Component) {
|
|
90
|
+
_inherits(NumberTextFieldCustom, _React$Component);
|
|
91
|
+
|
|
92
|
+
var _super = _createSuper(NumberTextFieldCustom);
|
|
93
|
+
|
|
94
|
+
function NumberTextFieldCustom(props) {
|
|
95
|
+
var _this;
|
|
96
|
+
|
|
97
|
+
_classCallCheck(this, NumberTextFieldCustom);
|
|
98
|
+
|
|
99
|
+
_this = _super.call(this, props);
|
|
100
|
+
|
|
101
|
+
_defineProperty(_assertThisInitialized(_this), "onBlur", function (event) {
|
|
102
|
+
var onlyIntegersAllowed = _this.props.onlyIntegersAllowed;
|
|
103
|
+
var value = event.target.value;
|
|
104
|
+
var rawNumber = onlyIntegersAllowed ? parseInt(value) : parseFloat(value);
|
|
105
|
+
|
|
106
|
+
var number = _this.clamp(rawNumber);
|
|
107
|
+
|
|
108
|
+
if (number !== _this.state.value) {
|
|
109
|
+
_this.setState({
|
|
110
|
+
value: number.toString()
|
|
111
|
+
}, function () {
|
|
112
|
+
return _this.props.onChange(event, number);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
var _value = _this.clamp(props.value);
|
|
118
|
+
|
|
119
|
+
_this.state = {
|
|
120
|
+
value: _value
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (_value !== props.value) {
|
|
124
|
+
_this.props.onChange({}, _value);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
_this.onChange = _this.onChange.bind(_assertThisInitialized(_this));
|
|
128
|
+
return _this;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
_createClass(NumberTextFieldCustom, [{
|
|
132
|
+
key: "UNSAFE_componentWillReceiveProps",
|
|
133
|
+
value: function UNSAFE_componentWillReceiveProps(props) {
|
|
134
|
+
var value = this.clamp(props.value);
|
|
135
|
+
this.setState({
|
|
136
|
+
value: value
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
key: "clamp",
|
|
141
|
+
value: function clamp(value) {
|
|
142
|
+
var _this$props = this.props,
|
|
143
|
+
min = _this$props.min,
|
|
144
|
+
max = _this$props.max;
|
|
145
|
+
|
|
146
|
+
if (!(0, _isFinite["default"])(value)) {
|
|
147
|
+
return fallbackNumber(min, max);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if ((0, _isFinite["default"])(max)) {
|
|
151
|
+
value = Math.min(value, max);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if ((0, _isFinite["default"])(min)) {
|
|
155
|
+
value = Math.max(value, min);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
}, {
|
|
161
|
+
key: "onChange",
|
|
162
|
+
value: function onChange(event) {
|
|
163
|
+
var value = event.target.value;
|
|
164
|
+
this.setState({
|
|
165
|
+
value: value
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}, {
|
|
169
|
+
key: "changeValue",
|
|
170
|
+
value: function changeValue(event) {
|
|
171
|
+
var sign = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
172
|
+
var shouldUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
var _this$props2 = this.props,
|
|
175
|
+
step = _this$props2.step,
|
|
176
|
+
onlyIntegersAllowed = _this$props2.onlyIntegersAllowed,
|
|
177
|
+
onChange = _this$props2.onChange;
|
|
178
|
+
var value = this.state.value;
|
|
179
|
+
var rawNumber = onlyIntegersAllowed ? parseInt(value) : parseFloat(value);
|
|
180
|
+
var updatedValue = (rawNumber * 10000 + step * sign * 10000) / 10000;
|
|
181
|
+
var number = this.clamp(updatedValue);
|
|
182
|
+
this.setState({
|
|
183
|
+
value: number.toString()
|
|
184
|
+
}, function () {
|
|
185
|
+
if (shouldUpdate) {
|
|
186
|
+
onChange(event, number);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}, {
|
|
191
|
+
key: "render",
|
|
192
|
+
value: function render() {
|
|
193
|
+
var _this2 = this;
|
|
194
|
+
|
|
195
|
+
var _this$props3 = this.props,
|
|
196
|
+
className = _this$props3.className,
|
|
197
|
+
classes = _this$props3.classes,
|
|
198
|
+
label = _this$props3.label,
|
|
199
|
+
disabled = _this$props3.disabled,
|
|
200
|
+
error = _this$props3.error,
|
|
201
|
+
min = _this$props3.min,
|
|
202
|
+
max = _this$props3.max,
|
|
203
|
+
inputClassName = _this$props3.inputClassName,
|
|
204
|
+
disableUnderline = _this$props3.disableUnderline,
|
|
205
|
+
helperText = _this$props3.helperText,
|
|
206
|
+
variant = _this$props3.variant,
|
|
207
|
+
textAlign = _this$props3.textAlign;
|
|
208
|
+
var value = this.state.value;
|
|
209
|
+
var names = (0, _classnames["default"])(className, classes.input);
|
|
210
|
+
return /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
|
|
211
|
+
variant: variant,
|
|
212
|
+
inputRef: function inputRef(ref) {
|
|
213
|
+
return _this2.inputRef = ref;
|
|
214
|
+
},
|
|
215
|
+
disabled: disabled,
|
|
216
|
+
label: label,
|
|
217
|
+
value: value,
|
|
218
|
+
error: error,
|
|
219
|
+
helperText: helperText,
|
|
220
|
+
onChange: this.onChange,
|
|
221
|
+
onBlur: this.onBlur,
|
|
222
|
+
onKeyPress: function onKeyPress(e) {
|
|
223
|
+
// once the Enter key is pressed, we force input blur
|
|
224
|
+
if (e.key === 'Enter' && _this2.inputRef) {
|
|
225
|
+
_this2.inputRef.blur();
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
onKeyDown: function onKeyDown(e) {
|
|
229
|
+
if (e.key === 'ArrowUp') {
|
|
230
|
+
_this2.changeValue(e);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (e.key === 'ArrowDown') {
|
|
234
|
+
_this2.changeValue(e, -1);
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
type: "number",
|
|
238
|
+
className: names,
|
|
239
|
+
InputProps: {
|
|
240
|
+
className: inputClassName,
|
|
241
|
+
disableUnderline: disableUnderline,
|
|
242
|
+
startAdornment: /*#__PURE__*/_react["default"].createElement(_InputAdornment["default"], {
|
|
243
|
+
position: "start"
|
|
244
|
+
}, /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
|
|
245
|
+
className: classes.iconButton,
|
|
246
|
+
disabled: disabled,
|
|
247
|
+
onClick: function onClick(e) {
|
|
248
|
+
return _this2.changeValue(e, -1, true);
|
|
249
|
+
}
|
|
250
|
+
}, /*#__PURE__*/_react["default"].createElement(_Remove["default"], {
|
|
251
|
+
fontSize: "small"
|
|
252
|
+
}))),
|
|
253
|
+
endAdornment: /*#__PURE__*/_react["default"].createElement(_InputAdornment["default"], {
|
|
254
|
+
position: "end"
|
|
255
|
+
}, /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
|
|
256
|
+
className: classes.iconButton,
|
|
257
|
+
disabled: disabled,
|
|
258
|
+
onClick: function onClick(e) {
|
|
259
|
+
return _this2.changeValue(e, 1, true);
|
|
260
|
+
}
|
|
261
|
+
}, /*#__PURE__*/_react["default"].createElement(_Add["default"], {
|
|
262
|
+
fontSize: "small"
|
|
263
|
+
})))
|
|
264
|
+
},
|
|
265
|
+
inputProps: {
|
|
266
|
+
style: {
|
|
267
|
+
textAlign: textAlign
|
|
268
|
+
},
|
|
269
|
+
min: min,
|
|
270
|
+
max: max
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}]);
|
|
275
|
+
|
|
276
|
+
return NumberTextFieldCustom;
|
|
277
|
+
}(_react["default"].Component);
|
|
278
|
+
|
|
279
|
+
exports.NumberTextFieldCustom = NumberTextFieldCustom;
|
|
280
|
+
|
|
281
|
+
_defineProperty(NumberTextFieldCustom, "propTypes", {
|
|
282
|
+
classes: _propTypes["default"].object.isRequired,
|
|
283
|
+
className: _propTypes["default"].string,
|
|
284
|
+
disabled: _propTypes["default"].bool,
|
|
285
|
+
error: _propTypes["default"].bool,
|
|
286
|
+
inputClassName: _propTypes["default"].string,
|
|
287
|
+
onChange: _propTypes["default"].func.isRequired,
|
|
288
|
+
onlyIntegersAllowed: _propTypes["default"].bool,
|
|
289
|
+
value: _propTypes["default"].number,
|
|
290
|
+
min: _propTypes["default"].number,
|
|
291
|
+
max: _propTypes["default"].number,
|
|
292
|
+
step: _propTypes["default"].number,
|
|
293
|
+
label: _propTypes["default"].string,
|
|
294
|
+
disableUnderline: _propTypes["default"].bool,
|
|
295
|
+
variant: _propTypes["default"].string
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
_defineProperty(NumberTextFieldCustom, "defaultProps", {
|
|
299
|
+
step: 1,
|
|
300
|
+
textAlign: 'center',
|
|
301
|
+
variant: 'standard',
|
|
302
|
+
onlyIntegersAllowed: false
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
var _default = (0, _styles.withStyles)(styles)(NumberTextFieldCustom);
|
|
306
|
+
|
|
307
|
+
exports["default"] = _default;
|
|
308
|
+
//# sourceMappingURL=number-text-field-custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/number-text-field-custom.jsx"],"names":["styles","theme","input","margin","iconButton","padding","fallbackNumber","min","max","NumberTextFieldCustom","props","event","onlyIntegersAllowed","value","target","rawNumber","parseInt","parseFloat","number","clamp","state","setState","toString","onChange","bind","Math","sign","shouldUpdate","preventDefault","step","updatedValue","className","classes","label","disabled","error","inputClassName","disableUnderline","helperText","variant","textAlign","names","ref","inputRef","onBlur","e","key","blur","changeValue","startAdornment","endAdornment","style","React","Component","PropTypes","object","isRequired","string","bool","func"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAAAC,KAAK;AAAA,SAAK;AACvBC,IAAAA,KAAK,EAAE;AACL,8BAAwB;AACtB,2BAAmB;AADG,OADnB;AAIL,yDAAmD;AACjD,8BAAsB,MAD2B;AAEjDC,QAAAA,MAAM,EAAE;AAFyC,OAJ9C;AAQL,yDAAmD;AACjD,8BAAsB,MAD2B;AAEjDA,QAAAA,MAAM,EAAE;AAFyC;AAR9C,KADgB;AAcvBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,OAAO,EAAE;AADC;AAdW,GAAL;AAAA,CAApB;;AAmBA,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACC,GAAD,EAA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AAI,EAAE,CADc;AAEpBW,EAAAA,SAAS,EAAE,QAFS;AAGpBD,EAAAA,OAAO,EAAE,UAHW;AAIpB3B,EAAAA,mBAAmB,EAAE;AAJD,C;;eAkKT,wBAAWZ,MAAX,EAAmBS,qBAAnB,C","sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\nimport TextField from '@material-ui/core/TextField';\nimport classNames from 'classnames';\nimport { withStyles } from '@material-ui/core/styles';\nimport isFinite from 'lodash/isFinite';\nimport IconButton from '@material-ui/core/IconButton';\nimport InputAdornment from '@material-ui/core/InputAdornment';\nimport Remove from '@material-ui/icons/Remove';\nimport Add from '@material-ui/icons/Add';\n\nconst styles = theme => ({\n input: {\n '& input[type=number]': {\n '-moz-appearance': 'textfield'\n },\n '& input[type=number]::-webkit-outer-spin-button': {\n '-webkit-appearance': 'none',\n margin: 0\n },\n '& input[type=number]::-webkit-inner-spin-button': {\n '-webkit-appearance': 'none',\n margin: 0\n }\n },\n iconButton: {\n padding: '2px'\n }\n});\n\nconst fallbackNumber = (min, max) => {\n if (!isFinite(min) && !isFinite(max)) {\n return 0;\n }\n\n if (!isFinite(min) && isFinite(max)) {\n return max;\n }\n\n if (isFinite(min)) {\n return min;\n }\n};\n\nexport class NumberTextFieldCustom extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n disabled: PropTypes.bool,\n error: PropTypes.bool,\n inputClassName: PropTypes.string,\n onChange: PropTypes.func.isRequired,\n onlyIntegersAllowed: PropTypes.bool,\n value: PropTypes.number,\n min: PropTypes.number,\n max: PropTypes.number,\n step: PropTypes.number,\n label: PropTypes.string,\n disableUnderline: PropTypes.bool,\n variant: PropTypes.string\n };\n\n static defaultProps = {\n step: 1,\n textAlign: 'center',\n variant: 'standard',\n onlyIntegersAllowed: false\n };\n\n constructor(props) {\n super(props);\n\n const value = this.clamp(props.value);\n\n this.state = {\n value\n };\n\n if (value !== props.value) {\n this.props.onChange({}, value);\n }\n\n this.onChange = this.onChange.bind(this);\n }\n\n UNSAFE_componentWillReceiveProps(props) {\n const value = this.clamp(props.value);\n\n this.setState({ value });\n }\n\n clamp(value) {\n const { min, max } = this.props;\n\n if (!isFinite(value)) {\n return fallbackNumber(min, max);\n }\n\n if (isFinite(max)) {\n value = Math.min(value, max);\n }\n\n if (isFinite(min)) {\n value = Math.max(value, min);\n }\n\n return value;\n }\n\n onBlur = event => {\n const { onlyIntegersAllowed } = this.props;\n const { value } = event.target;\n const rawNumber = onlyIntegersAllowed ? parseInt(value) : parseFloat(value);\n const number = this.clamp(rawNumber);\n\n if (number !== this.state.value) {\n this.setState({ value: number.toString() }, () => this.props.onChange(event, number));\n }\n };\n\n onChange(event) {\n const { value } = event.target;\n\n this.setState({ value });\n }\n\n changeValue(event, sign = 1, shouldUpdate = false) {\n event.preventDefault();\n\n const { step, onlyIntegersAllowed, onChange } = this.props;\n const { value } = this.state;\n const rawNumber = onlyIntegersAllowed ? parseInt(value) : parseFloat(value);\n const updatedValue = (rawNumber * 10000 + step * sign * 10000) / 10000;\n const number = this.clamp(updatedValue);\n\n this.setState({ value: number.toString() }, () => {\n if (shouldUpdate) {\n onChange(event, number);\n }\n });\n }\n\n render() {\n const {\n className,\n classes,\n label,\n disabled,\n error,\n min,\n max,\n inputClassName,\n disableUnderline,\n helperText,\n variant,\n textAlign\n } = this.props;\n const { value } = this.state;\n const names = classNames(className, classes.input);\n\n return (\n <TextField\n variant={variant}\n inputRef={ref => (this.inputRef = ref)}\n disabled={disabled}\n label={label}\n value={value}\n error={error}\n helperText={helperText}\n onChange={this.onChange}\n onBlur={this.onBlur}\n onKeyPress={e => {\n // once the Enter key is pressed, we force input blur\n if (e.key === 'Enter' && this.inputRef) {\n this.inputRef.blur();\n }\n }}\n onKeyDown={e => {\n if (e.key === 'ArrowUp') {\n this.changeValue(e);\n }\n\n if (e.key === 'ArrowDown') {\n this.changeValue(e, -1);\n }\n }}\n type=\"number\"\n className={names}\n InputProps={{\n className: inputClassName,\n disableUnderline: disableUnderline,\n startAdornment: (\n <InputAdornment position=\"start\">\n <IconButton\n className={classes.iconButton}\n disabled={disabled}\n onClick={e => this.changeValue(e, -1, true)}\n >\n <Remove fontSize=\"small\" />\n </IconButton>\n </InputAdornment>\n ),\n endAdornment: (\n <InputAdornment position=\"end\">\n <IconButton\n className={classes.iconButton}\n disabled={disabled}\n onClick={e => this.changeValue(e, 1, true)}\n >\n <Add fontSize=\"small\" />\n </IconButton>\n </InputAdornment>\n )\n }}\n inputProps={{\n style: { textAlign },\n min,\n max\n }}\n />\n );\n }\n}\n\nexport default withStyles(styles)(NumberTextFieldCustom);\n"],"file":"number-text-field-custom.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/config-ui",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.13.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@material-ui/core": "^3.8.3",
|
|
12
12
|
"@material-ui/icons": "^3.0.2",
|
|
13
|
-
"@pie-lib/editable-html": "^7.22.
|
|
13
|
+
"@pie-lib/editable-html": "^7.22.4",
|
|
14
14
|
"@pie-lib/icons": "^2.4.25",
|
|
15
|
-
"@pie-lib/render-ui": "^4.12.
|
|
15
|
+
"@pie-lib/render-ui": "^4.12.7",
|
|
16
16
|
"classnames": "^2.2.6",
|
|
17
17
|
"debug": "^4.1.1",
|
|
18
18
|
"lodash": "^4.17.11",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^16.8.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "611d47d0ed9fb2591be8f26cc78a40049e5e70a5"
|
|
30
30
|
}
|
package/src/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import Help from './help';
|
|
|
12
12
|
import Input from './input';
|
|
13
13
|
import { InputContainer } from '@pie-lib/render-ui';
|
|
14
14
|
import NumberTextField from './number-text-field';
|
|
15
|
+
import NumberTextFieldCustom from './number-text-field-custom';
|
|
15
16
|
import TwoChoice, { NChoice } from './two-choice';
|
|
16
17
|
import TagsInput from './tags-input';
|
|
17
18
|
import MuiBox from './mui-box';
|
|
@@ -42,6 +43,7 @@ export {
|
|
|
42
43
|
Input,
|
|
43
44
|
InputContainer,
|
|
44
45
|
NumberTextField,
|
|
46
|
+
NumberTextFieldCustom,
|
|
45
47
|
TwoChoice,
|
|
46
48
|
NChoice,
|
|
47
49
|
TagsInput,
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import TextField from '@material-ui/core/TextField';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
6
|
+
import isFinite from 'lodash/isFinite';
|
|
7
|
+
import IconButton from '@material-ui/core/IconButton';
|
|
8
|
+
import InputAdornment from '@material-ui/core/InputAdornment';
|
|
9
|
+
import Remove from '@material-ui/icons/Remove';
|
|
10
|
+
import Add from '@material-ui/icons/Add';
|
|
11
|
+
|
|
12
|
+
const styles = theme => ({
|
|
13
|
+
input: {
|
|
14
|
+
'& input[type=number]': {
|
|
15
|
+
'-moz-appearance': 'textfield'
|
|
16
|
+
},
|
|
17
|
+
'& input[type=number]::-webkit-outer-spin-button': {
|
|
18
|
+
'-webkit-appearance': 'none',
|
|
19
|
+
margin: 0
|
|
20
|
+
},
|
|
21
|
+
'& input[type=number]::-webkit-inner-spin-button': {
|
|
22
|
+
'-webkit-appearance': 'none',
|
|
23
|
+
margin: 0
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
iconButton: {
|
|
27
|
+
padding: '2px'
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const fallbackNumber = (min, max) => {
|
|
32
|
+
if (!isFinite(min) && !isFinite(max)) {
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!isFinite(min) && isFinite(max)) {
|
|
37
|
+
return max;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (isFinite(min)) {
|
|
41
|
+
return min;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export class NumberTextFieldCustom extends React.Component {
|
|
46
|
+
static propTypes = {
|
|
47
|
+
classes: PropTypes.object.isRequired,
|
|
48
|
+
className: PropTypes.string,
|
|
49
|
+
disabled: PropTypes.bool,
|
|
50
|
+
error: PropTypes.bool,
|
|
51
|
+
inputClassName: PropTypes.string,
|
|
52
|
+
onChange: PropTypes.func.isRequired,
|
|
53
|
+
onlyIntegersAllowed: PropTypes.bool,
|
|
54
|
+
value: PropTypes.number,
|
|
55
|
+
min: PropTypes.number,
|
|
56
|
+
max: PropTypes.number,
|
|
57
|
+
step: PropTypes.number,
|
|
58
|
+
label: PropTypes.string,
|
|
59
|
+
disableUnderline: PropTypes.bool,
|
|
60
|
+
variant: PropTypes.string
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
static defaultProps = {
|
|
64
|
+
step: 1,
|
|
65
|
+
textAlign: 'center',
|
|
66
|
+
variant: 'standard',
|
|
67
|
+
onlyIntegersAllowed: false
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
constructor(props) {
|
|
71
|
+
super(props);
|
|
72
|
+
|
|
73
|
+
const value = this.clamp(props.value);
|
|
74
|
+
|
|
75
|
+
this.state = {
|
|
76
|
+
value
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
if (value !== props.value) {
|
|
80
|
+
this.props.onChange({}, value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.onChange = this.onChange.bind(this);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
87
|
+
const value = this.clamp(props.value);
|
|
88
|
+
|
|
89
|
+
this.setState({ value });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
clamp(value) {
|
|
93
|
+
const { min, max } = this.props;
|
|
94
|
+
|
|
95
|
+
if (!isFinite(value)) {
|
|
96
|
+
return fallbackNumber(min, max);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (isFinite(max)) {
|
|
100
|
+
value = Math.min(value, max);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (isFinite(min)) {
|
|
104
|
+
value = Math.max(value, min);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
onBlur = event => {
|
|
111
|
+
const { onlyIntegersAllowed } = this.props;
|
|
112
|
+
const { value } = event.target;
|
|
113
|
+
const rawNumber = onlyIntegersAllowed ? parseInt(value) : parseFloat(value);
|
|
114
|
+
const number = this.clamp(rawNumber);
|
|
115
|
+
|
|
116
|
+
if (number !== this.state.value) {
|
|
117
|
+
this.setState({ value: number.toString() }, () => this.props.onChange(event, number));
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
onChange(event) {
|
|
122
|
+
const { value } = event.target;
|
|
123
|
+
|
|
124
|
+
this.setState({ value });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
changeValue(event, sign = 1, shouldUpdate = false) {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
|
|
130
|
+
const { step, onlyIntegersAllowed, onChange } = this.props;
|
|
131
|
+
const { value } = this.state;
|
|
132
|
+
const rawNumber = onlyIntegersAllowed ? parseInt(value) : parseFloat(value);
|
|
133
|
+
const updatedValue = (rawNumber * 10000 + step * sign * 10000) / 10000;
|
|
134
|
+
const number = this.clamp(updatedValue);
|
|
135
|
+
|
|
136
|
+
this.setState({ value: number.toString() }, () => {
|
|
137
|
+
if (shouldUpdate) {
|
|
138
|
+
onChange(event, number);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
render() {
|
|
144
|
+
const {
|
|
145
|
+
className,
|
|
146
|
+
classes,
|
|
147
|
+
label,
|
|
148
|
+
disabled,
|
|
149
|
+
error,
|
|
150
|
+
min,
|
|
151
|
+
max,
|
|
152
|
+
inputClassName,
|
|
153
|
+
disableUnderline,
|
|
154
|
+
helperText,
|
|
155
|
+
variant,
|
|
156
|
+
textAlign
|
|
157
|
+
} = this.props;
|
|
158
|
+
const { value } = this.state;
|
|
159
|
+
const names = classNames(className, classes.input);
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<TextField
|
|
163
|
+
variant={variant}
|
|
164
|
+
inputRef={ref => (this.inputRef = ref)}
|
|
165
|
+
disabled={disabled}
|
|
166
|
+
label={label}
|
|
167
|
+
value={value}
|
|
168
|
+
error={error}
|
|
169
|
+
helperText={helperText}
|
|
170
|
+
onChange={this.onChange}
|
|
171
|
+
onBlur={this.onBlur}
|
|
172
|
+
onKeyPress={e => {
|
|
173
|
+
// once the Enter key is pressed, we force input blur
|
|
174
|
+
if (e.key === 'Enter' && this.inputRef) {
|
|
175
|
+
this.inputRef.blur();
|
|
176
|
+
}
|
|
177
|
+
}}
|
|
178
|
+
onKeyDown={e => {
|
|
179
|
+
if (e.key === 'ArrowUp') {
|
|
180
|
+
this.changeValue(e);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (e.key === 'ArrowDown') {
|
|
184
|
+
this.changeValue(e, -1);
|
|
185
|
+
}
|
|
186
|
+
}}
|
|
187
|
+
type="number"
|
|
188
|
+
className={names}
|
|
189
|
+
InputProps={{
|
|
190
|
+
className: inputClassName,
|
|
191
|
+
disableUnderline: disableUnderline,
|
|
192
|
+
startAdornment: (
|
|
193
|
+
<InputAdornment position="start">
|
|
194
|
+
<IconButton
|
|
195
|
+
className={classes.iconButton}
|
|
196
|
+
disabled={disabled}
|
|
197
|
+
onClick={e => this.changeValue(e, -1, true)}
|
|
198
|
+
>
|
|
199
|
+
<Remove fontSize="small" />
|
|
200
|
+
</IconButton>
|
|
201
|
+
</InputAdornment>
|
|
202
|
+
),
|
|
203
|
+
endAdornment: (
|
|
204
|
+
<InputAdornment position="end">
|
|
205
|
+
<IconButton
|
|
206
|
+
className={classes.iconButton}
|
|
207
|
+
disabled={disabled}
|
|
208
|
+
onClick={e => this.changeValue(e, 1, true)}
|
|
209
|
+
>
|
|
210
|
+
<Add fontSize="small" />
|
|
211
|
+
</IconButton>
|
|
212
|
+
</InputAdornment>
|
|
213
|
+
)
|
|
214
|
+
}}
|
|
215
|
+
inputProps={{
|
|
216
|
+
style: { textAlign },
|
|
217
|
+
min,
|
|
218
|
+
max
|
|
219
|
+
}}
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export default withStyles(styles)(NumberTextFieldCustom);
|