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

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.
@@ -13,4 +13,5 @@ export declare abstract class ChangingInputElement<TValue> extends InputElement
13
13
  /** @inheritdoc */
14
14
  resetValue(): void;
15
15
  protected abstract setInternalValue(value: TValue, isInitial: boolean): void;
16
+ protected abstract resetInternalValue(): void;
16
17
  }
@@ -27,8 +27,13 @@ class ChangingInputElement extends InputElement_1.InputElement {
27
27
  resetValue() {
28
28
  if (!this._valueIsSet && !this._initialValueIsSet)
29
29
  return;
30
- this.setInternalValue(undefined, false);
31
- this.updateInternally();
30
+ this._valueIsSet = false;
31
+ if (this._initialValueIsSet) {
32
+ this._initialValueIsSet = false;
33
+ this.setInitialValue(this.initialValue);
34
+ }
35
+ else
36
+ this.resetInternalValue();
32
37
  }
33
38
  }
34
39
  exports.ChangingInputElement = ChangingInputElement;
@@ -41,5 +41,7 @@ export declare class DynamicListInputElement<TValue> extends ExtendedInputElemen
41
41
  private reorder;
42
42
  private convert;
43
43
  protected setInternalValue(valueChange: IDynamicValueChange<TValue>[], isInitial: boolean): void;
44
+ /** @inheritdoc */
45
+ protected resetInternalValue(): void;
44
46
  private filterInputs;
45
47
  }
@@ -110,6 +110,10 @@ class DynamicListInputElement extends ExtendedInputElement_1.ExtendedInputElemen
110
110
  this._inputs = newInputs;
111
111
  (_a = this._componentRef.current) === null || _a === void 0 ? void 0 : _a.update(this._inputs);
112
112
  }
113
+ /** @inheritdoc */
114
+ resetInternalValue() {
115
+ this._inputs = [];
116
+ }
113
117
  filterInputs() {
114
118
  var _a;
115
119
  return (_a = this._inputs) === null || _a === void 0 ? void 0 : _a.filter((i) => !!(i === null || i === void 0 ? void 0 : i.input));
@@ -5,6 +5,7 @@ export interface IInvalidationOptions {
5
5
  export interface ISingleValueInputElementProps<TValue> {
6
6
  value: TValue;
7
7
  label: FormText;
8
+ isRequired: boolean;
8
9
  renderRequiredIndicator: boolean;
9
10
  errorMessage: FormText;
10
11
  onChange: (newValue: TValue) => void;
@@ -12,6 +12,9 @@ interface INumberInputState {
12
12
  export declare class NumberInput extends React.Component<ISingleValueInputElementProps<number> & IOperativeProps<INumberInputProps> & IDynamicProps<IBaseInputElementDynamicProps>, INumberInputState> {
13
13
  state: INumberInputState;
14
14
  render(): JSX.Element;
15
+ private handleChange;
16
+ private handleIncrement;
17
+ private handleDecrement;
15
18
  private handleUserInput;
16
19
  private ensureValueConsistency;
17
20
  private getMaxValue;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NumberInput = void 0;
4
- const react_1 = require("@fluentui/react");
5
4
  const React = require("react");
5
+ const react_1 = require("@fluentui/react");
6
6
  const Components_1 = require("../../Components");
7
7
  const delimiter = '.';
8
8
  class NumberInput extends React.Component {
@@ -13,40 +13,51 @@ class NumberInput extends React.Component {
13
13
  intermediateValue: (_a = this.props.value) === null || _a === void 0 ? void 0 : _a.toString(),
14
14
  customWarning: ''
15
15
  };
16
+ this.handleChange = (event) => {
17
+ const newValue = event.target.value;
18
+ const value = NumberInput.normalizeData(newValue);
19
+ const { isRequired } = this.props;
20
+ console.log(isRequired, value);
21
+ if (!isRequired && !value) {
22
+ this.setState({ intermediateValue: '', customWarning: '' });
23
+ this.props.onChange(undefined);
24
+ return;
25
+ }
26
+ if (!value || isNaN(Number(value))) {
27
+ this.setState({ intermediateValue: value, customWarning: 'The provided value is not a valid number.' });
28
+ this.props.invalidateInput();
29
+ return;
30
+ }
31
+ const numericValue = NumberInput.getNumericValue(value);
32
+ this.handleUserInput(numericValue, value);
33
+ };
34
+ this.handleIncrement = (value) => {
35
+ let numericValue = NumberInput.getNumericValue(value);
36
+ numericValue += this.getStep();
37
+ this.handleUserInput(numericValue, numericValue.toString());
38
+ };
39
+ this.handleDecrement = (value) => {
40
+ let numericValue = NumberInput.getNumericValue(value);
41
+ numericValue -= this.getStep();
42
+ this.handleUserInput(numericValue, numericValue.toString());
43
+ };
16
44
  }
17
45
  render() {
18
46
  var _a;
19
47
  if (!this.props)
20
48
  return null;
21
- const { dynamicProps, operativeProps } = this.props;
49
+ const { dynamicProps, errorMessage, operativeProps } = this.props;
50
+ const { customWarning } = this.state;
22
51
  return (React.createElement(React.Fragment, null,
23
52
  React.createElement(Components_1.LabelRenderer, { label: this.props.label, required: !!this.props.renderRequiredIndicator }),
24
53
  React.createElement(react_1.SpinButton, { "data-automationid": "number-input", inputProps: {
25
54
  autoFocus: !!operativeProps.autoFocus,
26
55
  placeholder: operativeProps.placeholder,
27
56
  disabled: !!dynamicProps.isDisabled,
28
- onChange: (event) => {
29
- const newValue = event.target.value;
30
- const value = NumberInput.normalizeData(newValue);
31
- if (!value || isNaN(Number(value))) {
32
- this.setState({ intermediateValue: value, customWarning: 'The provided value is not a valid number.' });
33
- this.props.invalidateInput();
34
- return;
35
- }
36
- const numericValue = NumberInput.getNumericValue(value);
37
- this.handleUserInput(numericValue, value);
38
- }
39
- }, value: (_a = this.state.intermediateValue) !== null && _a !== void 0 ? _a : '', onIncrement: (value) => {
40
- let numericValue = NumberInput.getNumericValue(value);
41
- numericValue += this.getStep();
42
- this.handleUserInput(numericValue, numericValue.toString());
43
- }, onDecrement: (value) => {
44
- let numericValue = NumberInput.getNumericValue(value);
45
- numericValue -= this.getStep();
46
- this.handleUserInput(numericValue, numericValue.toString());
47
- } }),
48
- React.createElement(Components_1.ErrorRenderer, { error: this.props.errorMessage, messageBarType: react_1.MessageBarType.warning }),
49
- React.createElement(Components_1.ErrorRenderer, { error: this.state.customWarning, messageBarType: react_1.MessageBarType.warning })));
57
+ onChange: this.handleChange
58
+ }, value: (_a = this.state.intermediateValue) !== null && _a !== void 0 ? _a : '', onIncrement: this.handleIncrement, onDecrement: this.handleDecrement }),
59
+ React.createElement(Components_1.ErrorRenderer, { error: errorMessage, messageBarType: react_1.MessageBarType.warning }),
60
+ React.createElement(Components_1.ErrorRenderer, { error: customWarning, messageBarType: react_1.MessageBarType.warning })));
50
61
  }
51
62
  handleUserInput(value, intermediateValue) {
52
63
  const consistencyWarning = this.ensureValueConsistency(value);
@@ -26,6 +26,8 @@ export declare class SingleValueInputElement<TValue, TOperativeProps, TDynamicPr
26
26
  /** @inheritdoc */
27
27
  protected setInternalValue(value: TValue, isInitial: boolean): void;
28
28
  /** @inheritdoc */
29
+ protected resetInternalValue(): void;
30
+ /** @inheritdoc */
29
31
  get hasChanges(): boolean;
30
32
  /** @inheritdoc */
31
33
  value: TValue;
@@ -78,6 +78,17 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
78
78
  this.invalidValueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x());
79
79
  }
80
80
  /** @inheritdoc */
81
+ resetInternalValue() {
82
+ var _a;
83
+ this.setError(undefined);
84
+ this.value = undefined;
85
+ if (this._isInvalidated)
86
+ this._isInvalidated = false;
87
+ if ((_a = this._componentRef) === null || _a === void 0 ? void 0 : _a.current)
88
+ this._componentRef.current.update(undefined);
89
+ this.updateInternally();
90
+ }
91
+ /** @inheritdoc */
81
92
  get hasChanges() {
82
93
  var _a;
83
94
  return !!((_a = this._configuration) === null || _a === void 0 ? void 0 : _a.comparator)
@@ -102,7 +113,8 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
102
113
  React.createElement(SingleValueInputElementWrapper_1.SingleValueInputElementWrapper, { internalComponent: this.componentToRender, renderErrors: (_b = this._configuration) === null || _b === void 0 ? void 0 : _b.renderErrors, loadingIndicator: (_c = this._configuration) === null || _c === void 0 ? void 0 : _c.loadingComponent, inputProps: {
103
114
  label: (_d = this._configuration) === null || _d === void 0 ? void 0 : _d.label,
104
115
  value: this.value,
105
- renderRequiredIndicator: ((_e = this._configuration) === null || _e === void 0 ? void 0 : _e.renderRequiredIndicator) && ((_f = this._configuration) === null || _f === void 0 ? void 0 : _f.isRequired),
116
+ isRequired: this._configuration.isRequired,
117
+ renderRequiredIndicator: ((_e = this._configuration) === null || _e === void 0 ? void 0 : _e.isRequired) && ((_f = this._configuration) === null || _f === void 0 ? void 0 : _f.renderRequiredIndicator),
106
118
  errorMessage: this.errorMessage,
107
119
  onChange: (newValue) => this.setValue(newValue),
108
120
  invalidateInput: this.invalidateInput
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@try-at-software/input-elements",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
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",