x25 17.2.25 → 17.2.26

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.
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  declare type DateInputPropTypes = {
2
3
  readonly customClass?: any;
3
4
  readonly input: any;
@@ -16,21 +17,5 @@ declare type DateInputPropTypes = {
16
17
  readonly onChange?: (event: any) => void;
17
18
  readonly onRegisterRef?: (callback: (node: any) => void) => void;
18
19
  };
19
- declare type DateInputStateTypes = {
20
- value: string;
21
- };
22
- import React from "react";
23
- export declare class DateInput extends React.Component<DateInputPropTypes, DateInputStateTypes> {
24
- static defaultProps: {
25
- formatValue: (raw: string) => string;
26
- normalizeValue: (raw: string) => string;
27
- };
28
- state: DateInputStateTypes;
29
- handleBlur: () => void;
30
- handleKeyDown: (event: any) => void;
31
- handleChange: ({ target: { value } }: any) => void;
32
- UNSAFE_componentWillReceiveProps(nextProps: DateInputPropTypes): void;
33
- constructor(props: DateInputPropTypes);
34
- render(): JSX.Element;
35
- }
20
+ export declare const DateInput: (props: DateInputPropTypes) => JSX.Element;
36
21
  export {};
@@ -1,20 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable react/no-unsafe */
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
2
  var __assign = (this && this.__assign) || function () {
19
3
  __assign = Object.assign || function(t) {
20
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -34,82 +18,47 @@ exports.DateInput = void 0;
34
18
  var react_1 = __importDefault(require("react"));
35
19
  var classnames_1 = __importDefault(require("classnames"));
36
20
  var utility_1 = require("../utility");
37
- var normalizeRawDate = function (raw) {
38
- /* eslint-disable no-magic-numbers */
39
- if ((0, utility_1.isValidDate)(raw)) {
40
- return (0, utility_1.normalizeDate)(raw);
21
+ var validation_1 = require("../utility/validation");
22
+ var addZeroIfNeeded = function (raw) {
23
+ var nrOfElements = 3, canAddZero = ((typeof raw === "string") &&
24
+ (raw.split(".").length === nrOfElements));
25
+ if (!canAddZero) {
26
+ return raw;
27
+ }
28
+ var perform = function (value) { return (value.length === 1 ? "0".concat(value) : value); }, parts = raw.split("."), part1 = perform(parts[0]), part2 = perform(parts[1]), part3 = parts[2], newValue = [part1, part2, part3].join(".");
29
+ if ((0, validation_1.isValidDate)(newValue)) {
30
+ return newValue;
41
31
  }
42
32
  return raw;
33
+ }, normalizeRawDate = function (raw) {
34
+ if ((0, validation_1.isValidDate)(raw)) {
35
+ return (0, utility_1.normalizeDate)(raw);
36
+ }
37
+ return "";
43
38
  }, formatRawDate = function (raw) {
44
- /* eslint-disable no-magic-numbers */
45
39
  if (typeof raw !== "undefined") {
46
40
  return (0, utility_1.formatDate)(raw);
47
41
  }
48
42
  return "";
49
43
  };
50
- var DateInput = /** @class */ (function (_super) {
51
- __extends(DateInput, _super);
52
- function DateInput(props) {
53
- var _this = _super.call(this, props) || this;
54
- _this.state = {
55
- value: formatRawDate(props.input.value),
56
- };
57
- _this.handleKeyDown = function (event) {
58
- if (event.key === "Enter") {
59
- _this.handleBlur();
60
- }
61
- };
62
- _this.handleBlur = function () {
63
- var onBlur = _this.props.input.onBlur, _a = _this.props, input = _a.input, normalizeValue = _a.normalizeValue, currentValue = _this.state.value, normalizedValue = normalizeValue(currentValue), shouldRenderAgain = normalizedValue !== "" && currentValue !== normalizedValue;
64
- input.onChange(normalizedValue);
65
- /*
66
- * Swallow the event to prevent Redux Form from
67
- * extracting the form value
68
- */
69
- onBlur();
70
- if (shouldRenderAgain) {
71
- _this.setState({
72
- value: (0, utility_1.formatDate)(normalizedValue),
73
- });
74
- }
75
- };
76
- _this.handleChange = function (_a) {
77
- var value = _a.target.value;
78
- _this.props.input.onChange();
79
- /*
80
- * Update the internal state to trigger a re-render
81
- * using the formatted value
82
- */
83
- _this.setState({
84
- value: value,
85
- });
86
- };
87
- return _this;
88
- }
89
- DateInput.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
90
- var newValue = nextProps.input.value, currentValue = this.state.value, shouldRenderAgain = (0, utility_1.isValidDate)(newValue) && currentValue !== newValue;
91
- if (newValue === "") {
92
- this.setState({
93
- value: "",
94
- });
95
- }
96
- if (shouldRenderAgain) {
97
- this.setState({
98
- value: (0, utility_1.formatDate)(newValue),
99
- });
44
+ var DateInput = function (props) {
45
+ var customClass = props.customClass, input = props.input, onRegisterRef = props.onRegisterRef, tabIndex = props.tabIndex, placeholder = props.placeholder, _a = props.meta, submitting = _a.submitting, touched = _a.touched, error = _a.error, _b = react_1.default.useState(input.value), value = _b[0], setValue = _b[1], valueToShow = formatRawDate(value), updateValue = function (targetValue) {
46
+ var normalizedValue = normalizeRawDate(addZeroIfNeeded(targetValue));
47
+ setValue(targetValue);
48
+ props.input.onChange(normalizedValue);
49
+ }, handleBlur = function (_a) {
50
+ var targetValue = _a.target.value;
51
+ var newValue = addZeroIfNeeded(targetValue), hasChanged = targetValue !== newValue;
52
+ if (hasChanged) {
53
+ updateValue(newValue);
100
54
  }
55
+ }, handleChange = function (_a) {
56
+ var targetValue = _a.target.value;
57
+ updateValue(targetValue);
101
58
  };
102
- DateInput.prototype.render = function () {
103
- var _a = this.props, customClass = _a.customClass, input = _a.input, onRegisterRef = _a.onRegisterRef, _b = _a.meta, submitting = _b.submitting, touched = _b.touched, error = _b.error, tabIndex = _a.tabIndex, formatValue = _a.formatValue, placeholder = _a.placeholder;
104
- return (react_1.default.createElement("input", __assign({}, input, { className: (0, classnames_1.default)("form-control ".concat(customClass || ""), {
105
- "is-invalid": touched && error,
106
- }), disabled: submitting, id: input.name, onBlur: this.handleBlur, onChange: this.handleChange, onKeyDown: this.handleKeyDown, placeholder: placeholder || utility_1.words.DateFormat, ref: onRegisterRef, tabIndex: tabIndex, type: "text", value: formatValue(this.state.value) })));
107
- };
108
- DateInput.defaultProps = {
109
- formatValue: formatRawDate,
110
- normalizeValue: normalizeRawDate,
111
- };
112
- return DateInput;
113
- }(react_1.default.Component));
59
+ return (react_1.default.createElement("input", __assign({}, input, { className: (0, classnames_1.default)("form-control ".concat(customClass || ""), {
60
+ "is-invalid": touched && error,
61
+ }), disabled: submitting, id: input.name, onBlur: handleBlur, onChange: handleChange, placeholder: placeholder || utility_1.words.DateFormat, ref: onRegisterRef, tabIndex: tabIndex, type: "text", value: valueToShow })));
62
+ };
114
63
  exports.DateInput = DateInput;
115
64
  //# sourceMappingURL=DateInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DateInput.js","sourceRoot":"","sources":["../../src/Inputs/DateInput.tsx"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBpC,gDAA0B;AAC1B,0DAAoC;AACpC,sCAA2E;AAG3E,IAAM,gBAAgB,GAAG,UAAC,GAAW;IACnC,qCAAqC;IACnC,IAAI,IAAA,qBAAW,EAAC,GAAG,CAAC,EAAE;QACpB,OAAO,IAAA,uBAAa,EAAC,GAAG,CAAC,CAAC;KAC3B;IAED,OAAO,GAAG,CAAC;AACb,CAAC,EAED,aAAa,GAAG,UAAC,GAAW;IAC5B,qCAAqC;IACnC,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE;QAC9B,OAAO,IAAA,oBAAU,EAAC,GAAG,CAAC,CAAC;KACxB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEJ;IAA+B,6BAAwD;IAmCrF,mBAAa,KAAyB;QAAtC,YACE,kBAAM,KAAK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;SAC/B,CAAC,EACF,QAAQ,EAAE,UAAU,EACpB,EAAE,EAAE,KAAK,CAAC,IAAI,EACd,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,YAAY,EACtB,WAAW,EAAE,WAAW,IAAI,eAAK,CAAC,UAAU,EAC5C,GAAG,EAAE,aAAa,EAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,WAAW,IAClB,CACH,CAAC;AACJ,CAAC,CAAC;AAlDW,QAAA,SAAS,aAkDpB"}
@@ -1,14 +1,12 @@
1
- declare type DateTemplatePropTypes = {
1
+ /// <reference types="react" />
2
+ declare type DateInputPropTypes = {
2
3
  readonly customClass?: any;
3
4
  readonly input: any;
4
- readonly label?: string;
5
5
  readonly meta: {
6
6
  error?: string;
7
7
  submitting: boolean;
8
8
  touched: boolean;
9
9
  };
10
- readonly left?: string;
11
- readonly right?: string;
12
10
  readonly placeholder?: string;
13
11
  readonly value?: string;
14
12
  readonly tabIndex?: string;
@@ -18,22 +16,9 @@ declare type DateTemplatePropTypes = {
18
16
  readonly onBlur?: () => void;
19
17
  readonly onChange?: (event: any) => void;
20
18
  readonly onRegisterRef?: (callback: (node: any) => void) => void;
19
+ right?: string;
20
+ left?: string;
21
+ label: string;
21
22
  };
22
- declare type DateTemplateStateTypes = {
23
- value: string;
24
- };
25
- import React from "react";
26
- export declare class DateTemplate extends React.Component<DateTemplatePropTypes, DateTemplateStateTypes> {
27
- static defaultProps: {
28
- formatValue: (raw: string) => string;
29
- normalizeValue: (raw: string) => string;
30
- };
31
- state: DateTemplateStateTypes;
32
- handleBlur: () => void;
33
- handleKeyDown: (event: any) => void;
34
- handleChange: ({ target: { value } }: any) => void;
35
- UNSAFE_componentWillReceiveProps(nextProps: DateTemplatePropTypes): void;
36
- constructor(props: DateTemplatePropTypes);
37
- render(): JSX.Element;
38
- }
23
+ export declare const DateTemplate: (props: DateInputPropTypes) => JSX.Element;
39
24
  export {};
@@ -1,20 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable react/no-unsafe */
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
2
  var __assign = (this && this.__assign) || function () {
19
3
  __assign = Object.assign || function(t) {
20
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -34,88 +18,51 @@ exports.DateTemplate = void 0;
34
18
  var react_1 = __importDefault(require("react"));
35
19
  var classnames_1 = __importDefault(require("classnames"));
36
20
  var utility_1 = require("../utility");
37
- var normalizeRawDate = function (raw) {
38
- /* eslint-disable no-magic-numbers */
39
- if ((0, utility_1.isValidDate)(raw)) {
40
- return (0, utility_1.normalizeDate)(raw);
21
+ var validation_1 = require("../utility/validation");
22
+ var addZeroIfNeeded = function (raw) {
23
+ var nrOfElements = 3, canAddZero = ((typeof raw === "string") &&
24
+ (raw.split(".").length === nrOfElements));
25
+ if (!canAddZero) {
26
+ return raw;
27
+ }
28
+ var perform = function (value) { return (value.length === 1 ? "0".concat(value) : value); }, parts = raw.split("."), part1 = perform(parts[0]), part2 = perform(parts[1]), part3 = parts[2], newValue = [part1, part2, part3].join(".");
29
+ if ((0, validation_1.isValidDate)(newValue)) {
30
+ return newValue;
41
31
  }
42
32
  return raw;
33
+ }, normalizeRawDate = function (raw) {
34
+ if ((0, validation_1.isValidDate)(raw)) {
35
+ return (0, utility_1.normalizeDate)(raw);
36
+ }
37
+ return "";
43
38
  }, formatRawDate = function (raw) {
44
- /* eslint-disable no-magic-numbers */
45
39
  if (typeof raw !== "undefined") {
46
40
  return (0, utility_1.formatDate)(raw);
47
41
  }
48
42
  return "";
49
43
  };
50
- var DateTemplate = /** @class */ (function (_super) {
51
- __extends(DateTemplate, _super);
52
- function DateTemplate(props) {
53
- var _this = _super.call(this, props) || this;
54
- _this.state = {
55
- value: formatRawDate(props.input.value),
56
- };
57
- _this.handleKeyDown = function (event) {
58
- if (event.key === "Enter") {
59
- _this.handleBlur();
60
- }
61
- };
62
- _this.handleBlur = function () {
63
- var onBlur = _this.props.input.onBlur, _a = _this.props, input = _a.input, normalizeValue = _a.normalizeValue, currentValue = _this.state.value, normalizedValue = normalizeValue(currentValue), shouldRenderAgain = normalizedValue !== "" && currentValue !== normalizedValue;
64
- input.onChange(normalizedValue);
65
- /*
66
- * Swallow the event to prevent Redux Form from
67
- * extracting the form value
68
- */
69
- onBlur();
70
- if (shouldRenderAgain) {
71
- _this.setState({
72
- value: (0, utility_1.formatDate)(normalizedValue),
73
- });
74
- }
75
- };
76
- _this.handleChange = function (_a) {
77
- var value = _a.target.value;
78
- _this.props.input.onChange();
79
- /*
80
- * Update the internal state to trigger a re-render
81
- * using the formatted value
82
- */
83
- _this.setState({
84
- value: value,
85
- });
86
- };
87
- return _this;
88
- }
89
- DateTemplate.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
90
- var newValue = nextProps.input.value, currentValue = this.state.value, shouldRenderAgain = (0, utility_1.isValidDate)(newValue) && currentValue !== newValue;
91
- if (newValue === "") {
92
- this.setState({
93
- value: "",
94
- });
95
- }
96
- if (shouldRenderAgain) {
97
- this.setState({
98
- value: (0, utility_1.formatDate)(newValue),
99
- });
44
+ var DateTemplate = function (props) {
45
+ var customClass = props.customClass, input = props.input, onRegisterRef = props.onRegisterRef, tabIndex = props.tabIndex, placeholder = props.placeholder, _a = props.meta, submitting = _a.submitting, touched = _a.touched, error = _a.error, right = props.right, left = props.left, label = props.label, _b = react_1.default.useState(input.value), value = _b[0], setValue = _b[1], valueToShow = formatRawDate(value), updateValue = function (targetValue) {
46
+ var normalizedValue = normalizeRawDate(addZeroIfNeeded(targetValue));
47
+ setValue(targetValue);
48
+ props.input.onChange(normalizedValue);
49
+ }, handleBlur = function (_a) {
50
+ var targetValue = _a.target.value;
51
+ var newValue = addZeroIfNeeded(targetValue), hasChanged = targetValue !== newValue;
52
+ if (hasChanged) {
53
+ updateValue(newValue);
100
54
  }
55
+ }, handleChange = function (_a) {
56
+ var targetValue = _a.target.value;
57
+ updateValue(targetValue);
101
58
  };
102
- DateTemplate.prototype.render = function () {
103
- var _a = this.props, customClass = _a.customClass, input = _a.input, label = _a.label, onRegisterRef = _a.onRegisterRef, _b = _a.meta, submitting = _b.submitting, touched = _b.touched, error = _b.error, left = _a.left, right = _a.right, tabIndex = _a.tabIndex, formatValue = _a.formatValue, placeholder = _a.placeholder;
104
- return (react_1.default.createElement("div", { className: (0, classnames_1.default)("form-group row", {
105
- "is-invalid": touched && error,
106
- }) },
107
- react_1.default.createElement("label", { className: "".concat(left ? left : "col-md-4 text-md-right", " form-control-label"), htmlFor: input.name }, label),
108
- react_1.default.createElement("div", { className: right ? right : "col-md-8" },
109
- react_1.default.createElement("input", __assign({}, input, { "aria-label": label, className: (0, classnames_1.default)("form-control ".concat(customClass || ""), {
110
- "is-invalid": touched && error,
111
- }), disabled: submitting, id: input.name, onBlur: this.handleBlur, onChange: this.handleChange, onKeyDown: this.handleKeyDown, placeholder: placeholder || utility_1.words.DateFormat, ref: onRegisterRef, tabIndex: tabIndex, type: "text", value: formatValue(this.state.value) })),
112
- react_1.default.createElement("div", { className: "invalid-feedback" }, touched && error && (react_1.default.createElement("span", null, error))))));
113
- };
114
- DateTemplate.defaultProps = {
115
- formatValue: formatRawDate,
116
- normalizeValue: normalizeRawDate,
117
- };
118
- return DateTemplate;
119
- }(react_1.default.Component));
59
+ return (react_1.default.createElement("div", { className: (0, classnames_1.default)("form-group row", { "is-invalid": touched && error }) },
60
+ react_1.default.createElement("label", { className: "".concat(left ? left : "col-md-4 text-md-right", " form-control-label"), htmlFor: input.name }, label),
61
+ react_1.default.createElement("div", { className: right ? right : "col-md-8" },
62
+ react_1.default.createElement("input", __assign({}, input, { "aria-label": label, className: (0, classnames_1.default)("form-control ".concat(customClass || ""), {
63
+ "is-invalid": touched && error,
64
+ }), disabled: submitting, id: input.name, onBlur: handleBlur, onChange: handleChange, placeholder: placeholder || utility_1.words.DateFormat, ref: onRegisterRef, tabIndex: tabIndex, type: "text", value: valueToShow })),
65
+ react_1.default.createElement("div", { className: "invalid-feedback" }, touched && error && (react_1.default.createElement("span", null, error))))));
66
+ };
120
67
  exports.DateTemplate = DateTemplate;
121
68
  //# sourceMappingURL=DateTemplate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DateTemplate.js","sourceRoot":"","sources":["../../src/Inputs/DateTemplate.tsx"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BpC,gDAA0B;AAC1B,0DAAoC;AACpC,sCAA2E;AAG3E,IAAM,gBAAgB,GAAG,UAAC,GAAW;IACnC,qCAAqC;IACnC,IAAI,IAAA,qBAAW,EAAC,GAAG,CAAC,EAAE;QACpB,OAAO,IAAA,uBAAa,EAAC,GAAG,CAAC,CAAC;KAC3B;IAED,OAAO,GAAG,CAAC;AACb,CAAC,EAED,aAAa,GAAG,UAAC,GAAW;IAC5B,qCAAqC;IACnC,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE;QAC9B,OAAO,IAAA,oBAAU,EAAC,GAAG,CAAC,CAAC;KACxB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEJ;IAAkC,gCAA8D;IAoC9F,sBAAa,KAA4B;QAAzC,YACE,kBAAM,KAAK,CAAC,SAuDb;QAtDC,KAAI,CAAC,KAAK,GAAG;YACX,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;SACxC,CAAC;QAEF,K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CAAC;AArEW,QAAA,YAAY,gBAqEvB"}
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ /// <reference types="react" />
2
2
  declare type TypeInputPropTypes = {
3
3
  readonly change: (event: any) => void;
4
4
  readonly value: any;
@@ -10,19 +10,5 @@ declare type TypeInputPropTypes = {
10
10
  readonly name?: string;
11
11
  readonly placeholder?: string;
12
12
  };
13
- declare type TypeInputStateTypes = {
14
- value: string;
15
- isWaiting: boolean;
16
- };
17
- export declare class DelayInputChange extends React.Component<TypeInputPropTypes, TypeInputStateTypes> {
18
- state: TypeInputStateTypes;
19
- timeout: any;
20
- delayChange: (event: any) => void;
21
- handleKeyPressed: (event: any) => void;
22
- stopWaiting: (value: string) => void;
23
- UNSAFE_componentWillReceiveProps(nextProps: TypeInputPropTypes): void;
24
- constructor(props: TypeInputPropTypes);
25
- shouldComponentUpdate(nextProps: TypeInputPropTypes, nextState: TypeInputStateTypes): boolean;
26
- render(): JSX.Element;
27
- }
13
+ export declare const DelayInputChange: (props: TypeInputPropTypes) => JSX.Element;
28
14
  export {};
@@ -1,101 +1,65 @@
1
1
  "use strict";
2
- /* eslint-disable react/no-unsafe */
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
- var __importDefault = (this && this.__importDefault) || function (mod) {
19
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.DelayInputChange = void 0;
23
- var react_1 = __importDefault(require("react"));
24
- var delay = 700;
23
+ var react_1 = __importStar(require("react"));
25
24
  var Messages_1 = require("../Messages");
26
- var DelayInputChange = /** @class */ (function (_super) {
27
- __extends(DelayInputChange, _super);
28
- function DelayInputChange(props) {
29
- var _this = _super.call(this, props) || this;
30
- _this.timeout = null;
31
- _this.state = {
32
- isWaiting: false,
33
- value: _this.props.value,
34
- };
35
- _this.handleKeyPressed = function (event) {
36
- if (event.key === "Enter") {
37
- _this.stopWaiting(_this.state.value);
38
- }
39
- };
40
- _this.stopWaiting = function (value) {
41
- clearTimeout(_this.timeout);
42
- _this.setState({
43
- isWaiting: false,
44
- value: value,
45
- }, function () {
46
- _this.props.change({
25
+ var delay = 700;
26
+ var DelayInputChange = function (props) {
27
+ var _a = (0, react_1.useState)(0), timeoutValue = _a[0], setTimeoutValue = _a[1], _b = (0, react_1.useState)(false), isWaiting = _b[0], setIsWaiting = _b[1], _c = (0, react_1.useState)(props.value), value = _c[0], setValue = _c[1], stopWaiting = function (newValue) {
28
+ clearTimeout(timeoutValue);
29
+ setIsWaiting(false);
30
+ setValue(newValue);
31
+ props.change({
32
+ target: {
33
+ value: newValue,
34
+ },
35
+ });
36
+ }, handleKeyPressed = function (event) {
37
+ if (event.key === "Enter") {
38
+ stopWaiting(value);
39
+ }
40
+ }, delayChange = function (_a) {
41
+ var newValue = _a.target.value;
42
+ clearTimeout(timeoutValue);
43
+ if (value === "") {
44
+ stopWaiting(newValue);
45
+ }
46
+ else {
47
+ setIsWaiting(true);
48
+ setValue(newValue);
49
+ var newTimeout = setTimeout(function () {
50
+ setIsWaiting(false);
51
+ props.change({
47
52
  target: {
48
- value: value,
53
+ value: newValue,
49
54
  },
50
55
  });
51
- });
52
- };
53
- _this.delayChange = function (_a) {
54
- var value = _a.target.value;
55
- clearTimeout(_this.timeout);
56
- if (value === "") {
57
- _this.stopWaiting(value);
58
- }
59
- else {
60
- var that_1 = _this;
61
- that_1.setState({
62
- isWaiting: true,
63
- value: value,
64
- }, function () {
65
- that_1.timeout = setTimeout(function () {
66
- that_1.setState({
67
- isWaiting: false,
68
- });
69
- that_1.props.change({
70
- target: {
71
- value: value,
72
- },
73
- });
74
- }, _this.props.delay || delay);
75
- });
76
- }
77
- };
78
- return _this;
79
- }
80
- DelayInputChange.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
81
- if (this.props.value !== nextProps.value) {
82
- this.setState({
83
- value: nextProps.value,
84
- });
56
+ }, props.delay || delay);
57
+ setTimeoutValue(newTimeout);
85
58
  }
86
59
  };
87
- DelayInputChange.prototype.shouldComponentUpdate = function (nextProps, nextState) {
88
- return (this.props.value !== nextProps.value ||
89
- this.state.value !== nextState.value ||
90
- this.state.isWaiting !== nextState.isWaiting);
91
- };
92
- DelayInputChange.prototype.render = function () {
93
- var _a = this.state, value = _a.value, isWaiting = _a.isWaiting;
94
- return (react_1.default.createElement("div", { className: "delay-input" },
95
- react_1.default.createElement("input", { autoComplete: this.props.autoComplete, className: this.props.className, id: this.props.id, name: this.props.name, onChange: this.delayChange, onKeyPress: this.handleKeyPressed, placeholder: this.props.placeholder, tabIndex: this.props.tabIndex, value: value }),
96
- isWaiting ? react_1.default.createElement(Messages_1.LoadingMessage, { className: "loading-spinner d-inline-block", sm: true }) : null));
97
- };
98
- return DelayInputChange;
99
- }(react_1.default.Component));
60
+ return (react_1.default.createElement("div", { className: "delay-input" },
61
+ react_1.default.createElement("input", { autoComplete: props.autoComplete, className: props.className, id: props.id, name: props.name, onChange: delayChange, onKeyPress: handleKeyPressed, placeholder: props.placeholder, tabIndex: props.tabIndex, value: value }),
62
+ isWaiting ? react_1.default.createElement(Messages_1.LoadingMessage, { className: "loading-spinner d-inline-block", sm: true }) : null));
63
+ };
100
64
  exports.DelayInputChange = DelayInputChange;
101
65
  //# sourceMappingURL=DelayInputChange.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DelayInputChange.js","sourceRoot":"","sources":["../../src/Inputs/DelayInputChange.tsx"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;;;;;;AAEpC,gDAA0B;AAiB1B,IAAM,KAAK,GAAG,GAAG,CAAC;AAElB,wCAA6C;AAE7C;IAAsC,oCAAwD;IAe5F,0BAAa,KAAyB;QAAtC,YACE,kBAAM,KAAK,CAAC,SAwDb;QAvDC,KAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,KAAI,CAAC,KAAK,GAAG;YACX,SAAS,EAAG,KAAK;YACjB,KAAK,EAAO,KAAI,CAAC,KAAK,CAAC,KAAK;SAC7B,CAAC;QAEF,KAAI,CAAC,gBAAgB,GAAG,UAAC,KAAU;YACjC,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE;gBACzB,KAAI,CAAC,WAAW,CAAC,KAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aACpC;QACH,CAAC,CAAC;QAEF,KAAI,CAAC,WAAW,GAAG,UAAC,KAAa;YAC/B,YAAY,CAAC,KAAI,CAAC,OAAO,CAAC,CAAC;YAC3B,KAAI,CAAC,QAAQ,CAAC;gBACZ,SAAS,EAAE,KAAK;gBAChB,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I,EAAE,KAAK,CAAC,IAAI,EAChB,QAAQ,EAAE,WAAW,EACrB,UAAU,EAAE,gBAAgB,EAC5B,WAAW,EAAE,KAAK,CAAC,WAAW,EAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,KAAK,EAAE,KAAK,GACZ;QACD,SAAS,CAAC,CAAC,CAAC,8BAAC,yBAAc,IAAC,SAAS,EAAC,gCAAgC,EAAC,EAAE,SAAG,CAAC,CAAC,CAAC,IAAI,CAChF,CACP,CAAC;AACJ,CAAC,CAAC;AA7DF,QAAA,gBAAgB,oBA6Dd"}
@@ -1,39 +1,24 @@
1
+ /// <reference types="react" />
1
2
  declare type NumericPropTypes = {
2
- readonly currency?: boolean;
3
- readonly optional?: boolean;
4
- readonly size?: number;
5
- readonly customClass?: any;
6
- readonly input: any;
7
- readonly label?: string;
8
- readonly meta: {
3
+ currency?: boolean;
4
+ optional?: boolean;
5
+ size?: number;
6
+ customClass?: any;
7
+ input: any;
8
+ label?: string;
9
+ meta: {
9
10
  error?: string;
10
11
  submitting: boolean;
11
12
  touched: boolean;
12
13
  };
13
- readonly tabIndex?: number;
14
- readonly placeholder?: string;
15
- readonly value?: string;
16
- readonly formatValue: (raw: any, optional?: boolean) => string;
17
- readonly normalizeValue: (raw: any) => any;
18
- readonly onBlur?: () => void;
19
- readonly onChange?: (event: any) => void;
20
- readonly onRegisterRef?: any;
14
+ tabIndex?: number;
15
+ placeholder?: string;
16
+ value?: string;
17
+ formatValue: (raw: any, optional?: boolean) => string;
18
+ normalizeValue: (raw: any) => any;
19
+ onBlur?: () => void;
20
+ onChange?: (event: any) => void;
21
+ onRegisterRef?: any;
21
22
  };
22
- declare type NumericStateTypes = {
23
- value: any;
24
- };
25
- import React from "react";
26
- export declare class NumericInput extends React.Component<NumericPropTypes, NumericStateTypes> {
27
- static defaultProps: {
28
- formatValue: (word: any, optional?: boolean | undefined) => string;
29
- normalizeValue: (raw: string) => number;
30
- };
31
- state: NumericStateTypes;
32
- handleBlur: () => any;
33
- handleKeyDown: (event: any) => void;
34
- handleChange: ({ target: { value } }: any) => void;
35
- UNSAFE_componentWillReceiveProps(nextProps: NumericPropTypes): void;
36
- constructor(props: NumericPropTypes);
37
- render(): JSX.Element;
38
- }
23
+ export declare const NumericInput: (props: NumericPropTypes) => JSX.Element;
39
24
  export {};
@@ -1,20 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable react/no-unsafe */
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
19
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
@@ -23,54 +7,29 @@ exports.NumericInput = void 0;
23
7
  var react_1 = __importDefault(require("react"));
24
8
  var classnames_1 = __importDefault(require("classnames"));
25
9
  var utility_1 = require("../utility");
26
- var NumericInput = /** @class */ (function (_super) {
27
- __extends(NumericInput, _super);
28
- function NumericInput(props) {
29
- var _this = _super.call(this, props) || this;
30
- _this.state = {
31
- value: props.input.value,
32
- };
33
- _this.handleKeyDown = function (event) {
34
- if (event.key === "Enter") {
35
- _this.handleBlur();
36
- }
37
- };
38
- _this.handleBlur = function () {
39
- (0, utility_1.handleBlur)(_this);
40
- };
41
- _this.handleChange = function (_a) {
42
- var value = _a.target.value;
43
- _this.props.input.onChange();
44
- /*
45
- * Update the internal state to trigger a re-render
46
- * using the formatted value
47
- */
48
- _this.setState({
49
- value: value,
50
- });
51
- };
52
- return _this;
53
- }
54
- NumericInput.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
55
- (0, utility_1.cwrp)(this, nextProps);
56
- };
57
- NumericInput.prototype.render = function () {
58
- var _a = this.props, customClass = _a.customClass, input = _a.input, label = _a.label, currency = _a.currency, tabIndex = _a.tabIndex, onRegisterRef = _a.onRegisterRef, _b = _a.meta, submitting = _b.submitting, touched = _b.touched, error = _b.error, formatValue = _a.formatValue, size = _a.size, placeholder = _a.placeholder, inputComponent = (react_1.default.createElement("input", { "aria-label": label, className: (0, classnames_1.default)("form-control ".concat(customClass || ""), {
59
- "is-invalid": touched && error,
60
- }), disabled: submitting, id: input.name, maxLength: size, onBlur: this.handleBlur, onChange: this.handleChange, onFocus: input.onFocus, onKeyDown: this.handleKeyDown, placeholder: placeholder || label, ref: onRegisterRef, tabIndex: tabIndex, type: "text", value: formatValue(this.state.value, this.props.optional) }));
61
- if (typeof currency === "undefined" || currency === false) {
62
- return (react_1.default.createElement("div", { className: "form-group-inline" }, inputComponent));
10
+ var common_1 = require("./common");
11
+ var NumericInput = function (props) {
12
+ var customClass = props.customClass, input = props.input, label = props.label, currency = props.currency, tabIndex = props.tabIndex, onRegisterRef = props.onRegisterRef, _a = props.formatValue, formatValue = _a === void 0 ? utility_1.formatZeroValue : _a, size = props.size, placeholder = props.placeholder, _b = props.meta, submitting = _b.submitting, touched = _b.touched, error = _b.error, _c = react_1.default.useState(props.input.value), value = _c[0], setValue = _c[1], noCurrency = (typeof currency === "undefined" || currency === false), valueToShow = formatValue(value, props.optional), updateValue = function (targetValue) {
13
+ setValue(targetValue);
14
+ props.input.onChange((0, common_1.getFloatValueToStore)(targetValue));
15
+ }, handleBlur = function () {
16
+ var newValue = (0, common_1.clearFloatOnBlur)(value), hasChanged = value !== newValue;
17
+ if (hasChanged) {
18
+ updateValue(newValue);
63
19
  }
64
- return (react_1.default.createElement("div", { className: "input-group" },
65
- inputComponent,
66
- react_1.default.createElement("div", { className: "input-group-append" },
67
- react_1.default.createElement("span", { className: "input-group-text" }, currency))));
68
- };
69
- NumericInput.defaultProps = {
70
- formatValue: utility_1.formatZeroValue,
71
- normalizeValue: utility_1.normalizeFloat,
72
- };
73
- return NumericInput;
74
- }(react_1.default.Component));
20
+ }, handleChange = function (_a) {
21
+ var targetValue = _a.target.value;
22
+ updateValue(targetValue);
23
+ }, inputComponent = (react_1.default.createElement("input", { "aria-label": label, className: (0, classnames_1.default)("form-control ".concat(customClass || ""), {
24
+ "is-invalid": touched && error,
25
+ }), disabled: submitting, id: input.name, maxLength: size, onBlur: handleBlur, onChange: handleChange, placeholder: placeholder || label, ref: onRegisterRef, tabIndex: tabIndex, type: "text", value: valueToShow }));
26
+ if (noCurrency) {
27
+ return (react_1.default.createElement("div", { className: "form-group-inline" }, inputComponent));
28
+ }
29
+ return (react_1.default.createElement("div", { className: "input-group" },
30
+ inputComponent,
31
+ react_1.default.createElement("div", { className: "input-group-append" },
32
+ react_1.default.createElement("span", { className: "input-group-text" }, currency))));
33
+ };
75
34
  exports.NumericInput = NumericInput;
76
35
  //# sourceMappingURL=NumericInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../src/Inputs/NumericInput.tsx"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;;;;;;AA0BpC,gDAA0B;AAC1B,0DAAoC;AACpC,sCAA+E;AAE/E;IAAkC,gCAAoD;IAepF,sBAAa,KAAuB;QAApC,YACE,kBAAM,KAAK,CAAC,SA8Bb;QA7BC,KAAI,CAAC,KAAK,GAAG;YACX,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK;SACzB,CAAC;QAEF,KAAI,CAAC,aAAa,GAAG,UAAC,KAAU;YAC9B,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE;gBACzB,KAAI,CAAC,UAAU,EAAE,CAAC;aACnB;QACH,CAAC,CAAC;QAEF,KAAI,CAAC,UAAU,GAAG;YAChB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AK,SAAS,EAAC,oBAAoB;YACjC,wCAAM,SAAS,EAAC,kBAAkB,IAC/B,QAAQ,CACJ,CACH,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AApEF,QAAA,YAAY,gBAoEV"}
@@ -1,44 +1,29 @@
1
+ /// <reference types="react" />
1
2
  declare type NumericPropTypes = {
2
- readonly optional?: boolean;
3
- readonly size?: number;
4
- readonly customClass?: any;
5
- readonly divClass?: any;
6
- readonly input: any;
7
- readonly label?: string;
8
- readonly meta: {
3
+ optional?: boolean;
4
+ size?: number;
5
+ customClass?: any;
6
+ divClass?: any;
7
+ input: any;
8
+ label?: string;
9
+ meta: {
9
10
  error?: string;
10
11
  submitting: boolean;
11
12
  touched: boolean;
12
13
  };
13
- readonly placeholder?: string;
14
- readonly value?: string;
15
- readonly autoFocus?: boolean;
16
- readonly type: string;
17
- readonly inputClass?: string;
18
- readonly left?: string;
19
- readonly tabIndex?: number;
20
- readonly right?: string;
21
- readonly formatValue: (raw: any, optional?: boolean) => string;
22
- readonly normalizeValue: (raw: string | null) => any;
23
- readonly onBlur?: () => void;
24
- readonly onChange?: (event: any) => void;
25
- readonly onRegisterRef?: any;
14
+ placeholder?: string;
15
+ value?: string;
16
+ autoFocus?: boolean;
17
+ type: string;
18
+ inputClass?: string;
19
+ left?: string;
20
+ tabIndex?: number;
21
+ right?: string;
22
+ formatValue: (raw: any, optional?: boolean) => string;
23
+ normalizeValue: (raw: string | null) => any;
24
+ onBlur?: () => void;
25
+ onChange?: (event: any) => void;
26
+ onRegisterRef?: any;
26
27
  };
27
- declare type NumericStateTypes = {
28
- value: any;
29
- };
30
- import React from "react";
31
- export declare class NumericTemplate extends React.Component<NumericPropTypes, NumericStateTypes> {
32
- static defaultProps: {
33
- formatValue: (word: any, optional?: boolean | undefined) => string;
34
- normalizeValue: (raw: string) => number;
35
- };
36
- state: NumericStateTypes;
37
- handleBlur: () => void;
38
- handleKeyDown: (event: any) => void;
39
- handleChange: ({ target: { value } }: any) => void;
40
- UNSAFE_componentWillReceiveProps(nextProps: NumericPropTypes): void;
41
- constructor(props: NumericPropTypes);
42
- render(): JSX.Element;
43
- }
28
+ export declare const NumericTemplate: (props: NumericPropTypes) => JSX.Element;
44
29
  export {};
@@ -1,20 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable react/no-unsafe */
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
19
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
@@ -22,53 +6,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
6
  exports.NumericTemplate = void 0;
23
7
  var react_1 = __importDefault(require("react"));
24
8
  var classnames_1 = __importDefault(require("classnames"));
25
- var utility_1 = require("../utility");
26
- var NumericTemplate = /** @class */ (function (_super) {
27
- __extends(NumericTemplate, _super);
28
- function NumericTemplate(props) {
29
- var _this = _super.call(this, props) || this;
30
- _this.state = {
31
- value: props.input.value,
32
- };
33
- _this.handleKeyDown = function (event) {
34
- if (event.key === "Enter") {
35
- _this.handleBlur();
36
- }
37
- };
38
- _this.handleBlur = function () {
39
- (0, utility_1.handleBlur)(_this);
40
- };
41
- _this.handleChange = function (_a) {
42
- var value = _a.target.value;
43
- _this.props.input.onChange();
44
- /*
45
- * Update the internal state to trigger a re-render
46
- * using the formatted value
47
- */
48
- _this.setState({
49
- value: value,
50
- });
51
- };
52
- return _this;
53
- }
54
- NumericTemplate.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
55
- (0, utility_1.cwrp)(this, nextProps);
56
- };
57
- NumericTemplate.prototype.render = function () {
58
- var _a = this.props, input = _a.input, label = _a.label, onRegisterRef = _a.onRegisterRef, _b = _a.meta, submitting = _b.submitting, touched = _b.touched, error = _b.error, formatValue = _a.formatValue, type = _a.type, autoFocus = _a.autoFocus, inputClass = _a.inputClass, placeholder = _a.placeholder, left = _a.left, size = _a.size, right = _a.right, tabIndex = _a.tabIndex, divClass = _a.divClass, warningClass = "".concat(touched && error ? " is-invalid" : ""), customClass = "".concat(inputClass ? " ".concat(inputClass) : ""), classForInput = "form-control ".concat(warningClass).concat(customClass), classForDiv = "form-group row ".concat(divClass ? divClass : "");
59
- return (react_1.default.createElement("div", { className: (0, classnames_1.default)(classForDiv, {
60
- "is-invalid": touched && error,
61
- }) },
62
- react_1.default.createElement("label", { className: "".concat(left ? left : "col-md-4 text-md-right", " form-control-label"), htmlFor: input.name }, label),
63
- react_1.default.createElement("div", { className: right ? right : "col-md-8" },
64
- react_1.default.createElement("input", { "aria-label": label, autoFocus: autoFocus, className: classForInput, disabled: submitting, id: input.name, maxLength: size, onBlur: this.handleBlur, onChange: this.handleChange, onFocus: input.onFocus, onKeyDown: this.handleKeyDown, placeholder: placeholder, ref: onRegisterRef, tabIndex: tabIndex, type: type, value: formatValue(this.state.value, this.props.optional) }),
65
- react_1.default.createElement("div", { className: "invalid-feedback" }, touched && error && (react_1.default.createElement("span", null, error))))));
66
- };
67
- NumericTemplate.defaultProps = {
68
- formatValue: utility_1.formatZeroValue,
69
- normalizeValue: utility_1.normalizeFloat,
70
- };
71
- return NumericTemplate;
72
- }(react_1.default.Component));
9
+ var common_1 = require("./common");
10
+ var NumericTemplate = function (props) {
11
+ var input = props.input, right = props.right, tabIndex = props.tabIndex, divClass = props.divClass, label = props.label, onRegisterRef = props.onRegisterRef, _a = props.meta, submitting = _a.submitting, touched = _a.touched, error = _a.error, formatValue = props.formatValue, type = props.type, autoFocus = props.autoFocus, inputClass = props.inputClass, placeholder = props.placeholder, left = props.left, size = props.size, _b = react_1.default.useState(props.input.value), value = _b[0], setValue = _b[1], valueToShow = formatValue(value, props.optional), updateValue = function (targetValue) {
12
+ setValue(targetValue);
13
+ props.input.onChange((0, common_1.getFloatValueToStore)(targetValue));
14
+ }, handleBlur = function () {
15
+ var newValue = (0, common_1.clearFloatOnBlur)(value), hasChanged = value !== newValue;
16
+ if (hasChanged) {
17
+ updateValue(newValue);
18
+ }
19
+ }, handleChange = function (_a) {
20
+ var targetValue = _a.target.value;
21
+ updateValue(targetValue);
22
+ }, warningClass = "".concat(touched && error ? " is-invalid" : ""), customClass = "".concat(inputClass ? " ".concat(inputClass) : ""), classForInput = "form-control ".concat(warningClass).concat(customClass), classForDiv = "form-group row ".concat(divClass ? divClass : "");
23
+ return (react_1.default.createElement("div", { className: (0, classnames_1.default)(classForDiv, {
24
+ "is-invalid": touched && error,
25
+ }) },
26
+ react_1.default.createElement("label", { className: "".concat(left ? left : "col-md-4 text-md-right", " form-control-label"), htmlFor: input.name }, label),
27
+ react_1.default.createElement("div", { className: right ? right : "col-md-8" },
28
+ react_1.default.createElement("input", { "aria-label": label, autoFocus: autoFocus, className: classForInput, disabled: submitting, id: input.name, maxLength: size, onBlur: handleBlur, onChange: handleChange, placeholder: placeholder, ref: onRegisterRef, tabIndex: tabIndex, type: type, value: formatValue(valueToShow, props.optional) }),
29
+ react_1.default.createElement("div", { className: "invalid-feedback" }, touched && error && (react_1.default.createElement("span", null, error))))));
30
+ };
73
31
  exports.NumericTemplate = NumericTemplate;
74
32
  //# sourceMappingURL=NumericTemplate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NumericTemplate.js","sourceRoot":"","sources":["../../src/Inputs/NumericTemplate.tsx"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;;;;;;AA+BpC,gDAA0B;AAC1B,0DAAoC;AACpC,sCAA+E;AAE/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AAQ,CAAC,GAC/C;YACF,uCAAK,SAAS,EAAC,kBAAkB,IAC9B,OAAO,IAAI,KAAK,IAAI,CACnB,4CACG,KAAK,CACD,CACR,CACG,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AAvEF,QAAA,eAAe,mBAuEb"}
@@ -0,0 +1,2 @@
1
+ export function getFloatValueToStore(raw: any): number;
2
+ export function clearFloatOnBlur(value: any): any;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /* eslint-disable require-unicode-regexp */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.clearFloatOnBlur = exports.getFloatValueToStore = void 0;
5
+ var isFloat = function (raw) {
6
+ var floatRegex = /^-?\d+(?:[.]\d*?)?$/;
7
+ return floatRegex.test(raw);
8
+ }, floatToEnglishComma = function (raw) { return String(raw).replace(",", "."); }, floatToLocalComma = function (raw) { return String(raw).replace(".", ","); };
9
+ var getFloatValueToStore = function (raw) {
10
+ var parsedFloat = floatToEnglishComma(raw), parsedValue = parseFloat(parsedFloat), canGetNumericValue = isFloat(parsedFloat) && !isNaN(parsedValue);
11
+ if (canGetNumericValue) {
12
+ return parsedValue;
13
+ }
14
+ return 0;
15
+ }, clearFloatOnBlur = function (value) {
16
+ var parts = floatToLocalComma(value).split(","), shouldRemoveComma = parts.length === 2 && (parts[1] === "" || Number(parts[1]) === 0), shouldCutTo2Decimals = parts.length === 2 && parts[1].length > 2;
17
+ if (shouldRemoveComma) {
18
+ return parts[0];
19
+ }
20
+ if (shouldCutTo2Decimals) {
21
+ var beforeDot = parts[0], afterDot = parts[1].substring(0, 2);
22
+ return "".concat(beforeDot, ",").concat(afterDot);
23
+ }
24
+ return value;
25
+ };
26
+ exports.getFloatValueToStore = getFloatValueToStore, exports.clearFloatOnBlur = clearFloatOnBlur;
27
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/Inputs/common.js"],"names":[],"mappings":";AAAA,2CA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