@try-at-software/input-elements 1.2.2 → 1.2.3

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,7 +1,11 @@
1
+ import { FormText } from '../../Components';
1
2
  import { IBaseInputElementProps } from '../IBaseInputElementProps';
2
3
  export interface INumberInputProps extends IBaseInputElementProps {
3
4
  handleDecimalValues?: boolean;
4
5
  min?: number;
5
6
  max?: number;
6
7
  step?: number;
8
+ getMinErrorMessage?: (min: number, max: number | undefined) => FormText;
9
+ getMaxErrorMessage?: (min: number | undefined, max: number) => FormText;
10
+ decimalErrorMessage?: FormText;
7
11
  }
@@ -49,27 +49,25 @@ class NumberInput extends React.Component {
49
49
  React.createElement(Components_1.ErrorRenderer, { error: this.state.customWarning, messageBarType: react_1.MessageBarType.warning })));
50
50
  }
51
51
  handleUserInput(value, intermediateValue) {
52
- const changeResult = this.ensureValueConsistency(value);
53
- this.setState({ customWarning: changeResult.warning, intermediateValue: intermediateValue });
54
- if (changeResult.newValue !== undefined)
55
- this.props.onChange(changeResult.newValue);
52
+ const consistencyWarning = this.ensureValueConsistency(value);
53
+ this.setState({ customWarning: consistencyWarning, intermediateValue: intermediateValue });
54
+ if (consistencyWarning === undefined)
55
+ this.props.onChange(value);
56
56
  else
57
57
  this.props.invalidateInput();
58
58
  }
59
59
  ensureValueConsistency(value) {
60
+ var _a, _b, _c, _d, _e;
61
+ const { operativeProps } = this.props;
60
62
  const maxValue = this.getMaxValue();
61
- if (value > maxValue)
62
- return { warning: `The maximum value is ${maxValue}`, newValue: undefined };
63
63
  const minValue = this.getMinValue();
64
+ if (value > maxValue)
65
+ return (_b = (_a = operativeProps.getMaxErrorMessage) === null || _a === void 0 ? void 0 : _a.call(operativeProps, minValue, maxValue)) !== null && _b !== void 0 ? _b : `The maximum value is ${maxValue}`;
64
66
  if (value < minValue)
65
- return { warning: `The minimum value is ${minValue}`, newValue: undefined };
66
- const { operativeProps } = this.props;
67
+ return (_d = (_c = operativeProps.getMinErrorMessage) === null || _c === void 0 ? void 0 : _c.call(operativeProps, minValue, maxValue)) !== null && _d !== void 0 ? _d : `The minimum value is ${minValue}`;
67
68
  if (!operativeProps.handleDecimalValues && value % 1 !== 0)
68
- return {
69
- warning: 'Decimal values are not allowed',
70
- newValue: undefined
71
- };
72
- return { warning: '', newValue: value };
69
+ return (_e = operativeProps.decimalErrorMessage) !== null && _e !== void 0 ? _e : 'Decimal values are not allowed';
70
+ return undefined;
73
71
  }
74
72
  getMaxValue() {
75
73
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@try-at-software/input-elements",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "A package providing different input elements that are extensible and easily configurable for your custom needs.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",