@rio-cloud/rio-uikit 0.16.4-beta.26 → 0.16.4-beta.27

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.
@@ -26,7 +26,7 @@ const getCurrentCategoryElement = (children, currentCategoryId) => {
26
26
  };
27
27
  const renderTreesOffscreen = (children, categoryId) => {
28
28
  return React.Children.map(children, child => {
29
- const offscreenClasses = classNames('TreeOffscreenWrapper', child && child.props.id !== categoryId && 'position-offscreen');
29
+ const offscreenClasses = classNames('TreeOffscreenWrapper', 'height-100pct', child && child.props.id !== categoryId && 'position-offscreen');
30
30
  return _jsx("div", Object.assign({ className: offscreenClasses }, { children: child }));
31
31
  });
32
32
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import moment, { type Moment } from 'moment';
2
+ import type { Moment } from 'moment';
3
3
  import Datetime, { type DatetimepickerProps } from 'react-datetime';
4
4
  export type DatePickerProps = Omit<DatetimepickerProps, 'onChange' | 'initialValue'> & {
5
5
  /**
@@ -107,12 +107,12 @@ declare const DatePicker: React.ForwardRefExoticComponent<Omit<Datetime.Datetime
107
107
  /**
108
108
  * Default value of the DatePicker (date or moment).
109
109
  */
110
- initialValue?: Date | moment.Moment | undefined;
110
+ initialValue?: Date | Moment | undefined;
111
111
  /**
112
112
  * Value of the DatePicker (date or moment). Use this only if you want to use
113
113
  * this component as a controlled component
114
114
  */
115
- value?: string | Date | moment.Moment | undefined;
115
+ value?: string | Date | Moment | undefined;
116
116
  dateFormat?: string | boolean | undefined;
117
117
  timeFormat?: string | boolean | undefined;
118
118
  inputProps?: React.HTMLProps<HTMLInputElement> | undefined;
@@ -2,24 +2,23 @@ import { __rest } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useState, forwardRef } from 'react';
4
4
  import classNames from 'classnames';
5
- import moment from 'moment';
6
5
  import Datetime from 'react-datetime';
7
6
  import noop from 'lodash/fp/noop';
8
- import isEmpty from 'lodash/fp/isEmpty';
9
7
  const DEFAULT_LOCALE = 'en-GB';
10
8
  const DEFAULT_MIN_WIDTH = 0;
11
- const isValidDate = (date) => typeof date === 'object' && moment(date).isValid();
12
9
  const DatePicker = forwardRef((props, ref) => {
13
10
  const { id, dropup = false, alignRight = false, locale = DEFAULT_LOCALE, minWidth = DEFAULT_MIN_WIDTH, onChange = noop, mandatory = true, dateValidation, clearableInput = false, closeOnSelect = true, inputProps, className } = props, remainingProp = __rest(props, ["id", "dropup", "alignRight", "locale", "minWidth", "onChange", "mandatory", "dateValidation", "clearableInput", "closeOnSelect", "inputProps", "className"]);
14
11
  const [hasError, setHasError] = useState(false);
15
12
  const validateDate = (dateToValidate) => {
16
- if (dateValidation) {
17
- return dateValidation(dateToValidate);
18
- }
19
- // if the date is mandatory, convert it to a moment object to validate
20
- const value = isEmpty(dateToValidate) ? undefined : dateToValidate;
21
- const dateValue = typeof value === 'string' ? moment(value) : value;
22
- return isValidDate(dateValue);
13
+ // If the entered date complies with the defined dateFormat, the Datetime component
14
+ // returns a moment object, otherwise the return value is a string.
15
+ // Note, using a isValid() function from moment or the Date object itself will result in
16
+ // different outcome in various browsers.
17
+ // For instance `new Date('1')` or `moment('1')` are valid dates in Chrome where it defaults
18
+ // to "01/01/2001" whereas in Firefox it is an invalid date.
19
+ // The solution is to compare the entered value to the date format which is done by React Datetime.
20
+ const isDateObject = typeof dateToValidate === 'object';
21
+ return dateValidation ? dateValidation(dateToValidate) : isDateObject;
23
22
  };
24
23
  const handleChange = (date) => {
25
24
  const isValid = mandatory ? validateDate(date) : true;
@@ -7,7 +7,7 @@ const INITIAL_TICK = 700;
7
7
  const TICK_TIME = 50;
8
8
  const DEFAULT_DIGIT_PRECISION = 3;
9
9
  const NumberControl = forwardRef((props, ref) => {
10
- const { id, min = DEFAULT_MIN, max = DEFAULT_MAX, step = DEFAULT_STEP, value, onChange, onValueChanged = () => { }, disabled, bsSize, className, unit, inputAddon, errorMessage, warningMessage, messageWhiteSpace, digitPrecision = DEFAULT_DIGIT_PRECISION, placeholder } = props, remainingProps = __rest(props, ["id", "min", "max", "step", "value", "onChange", "onValueChanged", "disabled", "bsSize", "className", "unit", "inputAddon", "errorMessage", "warningMessage", "messageWhiteSpace", "digitPrecision", "placeholder"]);
10
+ const { id, min = DEFAULT_MIN, max = DEFAULT_MAX, step = DEFAULT_STEP, value, onChange, onValueChanged = () => { }, disabled, bsSize, className, unit, inputAddon, errorMessage, warningMessage, messageWhiteSpace, digitPrecision = DEFAULT_DIGIT_PRECISION, placeholder, noDefault } = props, remainingProps = __rest(props, ["id", "min", "max", "step", "value", "onChange", "onValueChanged", "disabled", "bsSize", "className", "unit", "inputAddon", "errorMessage", "warningMessage", "messageWhiteSpace", "digitPrecision", "placeholder", "noDefault"]);
11
11
  // Note, "onChange" should replace "onValueChanged" in the future but it's widely used
12
12
  const callback = onChange || onValueChanged;
13
13
  const timeout = useRef(null);
@@ -108,6 +108,6 @@ const NumberControl = forwardRef((props, ref) => {
108
108
  };
109
109
  const classes = classNames('NumberControl', className);
110
110
  const controls = (_jsxs("div", Object.assign({ className: 'display-flex padding-left-10' }, { children: [_jsx("div", Object.assign({ onMouseDown: handleMouseDownOnDecrement, onMouseUp: handleStopHolding, role: 'button', "aria-label": 'decrement-button', className: 'decrementButton text-color-gray hover-text-color-dark' }, { children: _jsx("div", { className: 'rioglyph rioglyph-minus scale-90' }) })), _jsx("div", Object.assign({ onMouseDown: handleMouseDownOnIncrement, onMouseUp: handleStopHolding, role: 'button', "aria-label": 'increment-button', className: 'incrementButton text-color-gray hover-text-color-dark margin-left-5' }, { children: _jsx("div", { className: 'rioglyph rioglyph-plus scale-90' }) }))] })));
111
- return (_jsx("div", Object.assign({}, remainingProps, { className: classes }, { children: _jsx(NumberInput, { id: id, ref: ref, min: min, max: max, value: internalValue, step: step, bsSize: bsSize, disabled: disabled, inputAddon: inputAddon, errorMessage: errorMessage, warningMessage: warningMessage, messageWhiteSpace: messageWhiteSpace, controls: controls, unit: unit, onChange: handleUpdatedNumberInputValue, digitPrecision: digitPrecision, placeholder: placeholder }) })));
111
+ return (_jsx("div", Object.assign({}, remainingProps, { className: classes }, { children: _jsx(NumberInput, { id: id, ref: ref, min: min, max: max, value: internalValue, step: step, bsSize: bsSize, disabled: disabled, inputAddon: inputAddon, errorMessage: errorMessage, warningMessage: warningMessage, messageWhiteSpace: messageWhiteSpace, controls: controls, unit: unit, onChange: handleUpdatedNumberInputValue, digitPrecision: digitPrecision, placeholder: placeholder, noDefault: noDefault }) })));
112
112
  });
113
113
  export default NumberControl;
@@ -24,6 +24,12 @@ export type NumberInputProps = {
24
24
  * @default 0
25
25
  */
26
26
  value?: number;
27
+ /**
28
+ * Lets you omit the default value of "0" when the vale is not defined.
29
+ * The input will be empty in this case.
30
+ * @default false
31
+ */
32
+ noDefault?: boolean;
27
33
  /**
28
34
  * The size of increment or decrement (only works with number type).
29
35
  * @default 1
@@ -33,9 +33,9 @@ const validKeys = [
33
33
  // Note: even if limits are set and input type is number, many browsers allow to enter invalid data
34
34
  // like entering characters or values outside the boundaries, hence we have to check the input here
35
35
  // See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number
36
- const getValueFromProps = (val, min, max, placeholder) => {
37
- // Show placeholders if given instead of 0
38
- if (val === undefined && placeholder) {
36
+ const getValueFromProps = (val, min, max, placeholder, noDefault) => {
37
+ // Show placeholder or nothing if given instead of 0 if requested for
38
+ if (val === undefined && (placeholder || noDefault)) {
39
39
  return '';
40
40
  }
41
41
  return clampNumber(Number(val), min, max) || DEFAULT_VALUE;
@@ -59,13 +59,13 @@ const isInvalidAfter = (key, possiblePreviousKeys, event, previousKeyRef) => {
59
59
  return event.key === key && possiblePreviousKeys.includes(previousKeyRef.current);
60
60
  };
61
61
  const NumberInput = forwardRef((props, ref) => {
62
- const { id, min: propMin, max: propMax, value: propValue, step = DEFAULT_STEP, disabled = false, onChange, onValueChanged = noop, bsSize = 'md', unit, inputAddon, errorMessage, warningMessage, messageWhiteSpace = 'normal', controls, placeholder, digitPrecision = DEFAULT_DIGIT_PRECISION, className = '' } = props, remainingProps = __rest(props, ["id", "min", "max", "value", "step", "disabled", "onChange", "onValueChanged", "bsSize", "unit", "inputAddon", "errorMessage", "warningMessage", "messageWhiteSpace", "controls", "placeholder", "digitPrecision", "className"]);
62
+ const { id, min: propMin, max: propMax, value: propValue, step = DEFAULT_STEP, disabled = false, noDefault = false, onChange, onValueChanged = noop, bsSize = 'md', unit, inputAddon, errorMessage, warningMessage, messageWhiteSpace = 'normal', controls, placeholder, digitPrecision = DEFAULT_DIGIT_PRECISION, className = '' } = props, remainingProps = __rest(props, ["id", "min", "max", "value", "step", "disabled", "noDefault", "onChange", "onValueChanged", "bsSize", "unit", "inputAddon", "errorMessage", "warningMessage", "messageWhiteSpace", "controls", "placeholder", "digitPrecision", "className"]);
63
63
  const previousKeyRef = useRef('');
64
64
  // Note, "onChange" should replace "onValueChanged" in the future but it's widely used
65
65
  const callback = onChange || onValueChanged;
66
66
  const min = convertNonIntegerToDefault(propMin, DEFAULT_MIN);
67
67
  const max = convertNonIntegerToDefault(propMax, DEFAULT_MAX);
68
- const value = getValueFromProps(propValue, min, max, placeholder);
68
+ const value = getValueFromProps(propValue, min, max, placeholder, noDefault);
69
69
  // Define local state and define initial values
70
70
  const [state, setState] = useState({
71
71
  value,
@@ -75,7 +75,7 @@ const NumberInput = forwardRef((props, ref) => {
75
75
  // Update internal value whenever the value prop from outside changes
76
76
  useAfterMount(() => {
77
77
  setState({
78
- value: getValueFromProps(propValue, min, max, placeholder),
78
+ value: getValueFromProps(propValue, min, max, placeholder, noDefault),
79
79
  enteredValue: value,
80
80
  isValid: true,
81
81
  });
@@ -137,6 +137,11 @@ const NumberInput = forwardRef((props, ref) => {
137
137
  callback();
138
138
  return;
139
139
  }
140
+ // If there is no value defined and a placeholder is given or the default is not wanted,
141
+ // keep the input empty
142
+ if (!state.value && (noDefault || placeholder)) {
143
+ return;
144
+ }
140
145
  // Otherwise, validate the input, round it according to digitPrecision,
141
146
  // and clamp the value if the entered value exceeds the limitations
142
147
  const convertedEnteredValue = convertNonIntegerToDefault(Number(lastEnteredValue), DEFAULT_VALUE);
@@ -152,7 +157,9 @@ const NumberInput = forwardRef((props, ref) => {
152
157
  const inputGroupClassNames = classNames('input-group', bsSize === 'sm' && 'input-group-sm', bsSize === 'lg' && 'input-group-lg');
153
158
  const inputClassNames = classNames('form-control', 'no-controls', bsSize === 'sm' && 'input-sm', bsSize === 'lg' && 'input-lg', className);
154
159
  const hasFeedback = errorMessage || warningMessage;
155
- const input = (_jsx("input", Object.assign({}, remainingProps, { id: id, type: 'number', step: step, min: min, max: max, value: state.isValid ? state.value : state.enteredValue, className: inputClassNames, disabled: disabled, onBlur: handleBlur, onChange: handleOnChange, onKeyDown: handleKeyDown, ref: ref, "aria-label": 'number-input', placeholder: placeholder, onWheel: handleWheel })));
160
+ const input = (_jsx("input", Object.assign({}, remainingProps, { id: id, type: 'number', step: step, min: min, max: max, value: state.isValid ? state.value : state.enteredValue, className: inputClassNames, disabled: disabled, onBlur: handleBlur,
161
+ // onChange={state.value ? handleOnChange : undefined}
162
+ onChange: handleOnChange, onKeyDown: handleKeyDown, ref: ref, "aria-label": 'number-input', placeholder: placeholder, onWheel: handleWheel })));
156
163
  return (_jsxs("div", Object.assign({ className: inputGroupClassNames }, { children: [inputAddon && (_jsx("div", Object.assign({ className: 'input-group-addon' }, { children: _jsx("span", { className: inputAddon }) }))), _jsxs("div", Object.assign({ className: 'form-control-feedback-wrapper' }, { children: [input, hasFeedback && (_jsxs(_Fragment, { children: [errorMessage && _jsx("span", { className: 'form-control-feedback rioglyph rioglyph-error-sign' }), warningMessage && _jsx("span", { className: 'form-control-feedback rioglyph rioglyph-warning-sign' }), _jsx("span", Object.assign({ className: `help-block white-space-${messageWhiteSpace}` }, { children: _jsx("span", { children: errorMessage || warningMessage }) }))] }))] })), (unit || controls) && (_jsxs("div", Object.assign({ className: `input-group-addon ${disabled ? 'disabled pointer-events-none' : ''}` }, { children: [unit && unit, controls && controls] })))] })));
157
164
  });
158
165
  export default NumberInput;
@@ -28,7 +28,7 @@ const getCurrentCategoryElement = (children, currentCategoryId) => {
28
28
  };
29
29
  const renderTreesOffscreen = (children, categoryId) => {
30
30
  return react_1.default.Children.map(children, child => {
31
- const offscreenClasses = (0, classnames_1.default)('TreeOffscreenWrapper', child && child.props.id !== categoryId && 'position-offscreen');
31
+ const offscreenClasses = (0, classnames_1.default)('TreeOffscreenWrapper', 'height-100pct', child && child.props.id !== categoryId && 'position-offscreen');
32
32
  return (0, jsx_runtime_1.jsx)("div", Object.assign({ className: offscreenClasses }, { children: child }));
33
33
  });
34
34
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import moment, { type Moment } from 'moment';
2
+ import type { Moment } from 'moment';
3
3
  import Datetime, { type DatetimepickerProps } from 'react-datetime';
4
4
  export type DatePickerProps = Omit<DatetimepickerProps, 'onChange' | 'initialValue'> & {
5
5
  /**
@@ -107,12 +107,12 @@ declare const DatePicker: React.ForwardRefExoticComponent<Omit<Datetime.Datetime
107
107
  /**
108
108
  * Default value of the DatePicker (date or moment).
109
109
  */
110
- initialValue?: Date | moment.Moment | undefined;
110
+ initialValue?: Date | Moment | undefined;
111
111
  /**
112
112
  * Value of the DatePicker (date or moment). Use this only if you want to use
113
113
  * this component as a controlled component
114
114
  */
115
- value?: string | Date | moment.Moment | undefined;
115
+ value?: string | Date | Moment | undefined;
116
116
  dateFormat?: string | boolean | undefined;
117
117
  timeFormat?: string | boolean | undefined;
118
118
  inputProps?: React.HTMLProps<HTMLInputElement> | undefined;
@@ -4,24 +4,23 @@ const tslib_1 = require("tslib");
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const classnames_1 = tslib_1.__importDefault(require("classnames"));
7
- const moment_1 = tslib_1.__importDefault(require("moment"));
8
7
  const react_datetime_1 = tslib_1.__importDefault(require("react-datetime"));
9
8
  const noop_1 = tslib_1.__importDefault(require("lodash/fp/noop"));
10
- const isEmpty_1 = tslib_1.__importDefault(require("lodash/fp/isEmpty"));
11
9
  const DEFAULT_LOCALE = 'en-GB';
12
10
  const DEFAULT_MIN_WIDTH = 0;
13
- const isValidDate = (date) => typeof date === 'object' && (0, moment_1.default)(date).isValid();
14
11
  const DatePicker = (0, react_1.forwardRef)((props, ref) => {
15
12
  const { id, dropup = false, alignRight = false, locale = DEFAULT_LOCALE, minWidth = DEFAULT_MIN_WIDTH, onChange = noop_1.default, mandatory = true, dateValidation, clearableInput = false, closeOnSelect = true, inputProps, className } = props, remainingProp = tslib_1.__rest(props, ["id", "dropup", "alignRight", "locale", "minWidth", "onChange", "mandatory", "dateValidation", "clearableInput", "closeOnSelect", "inputProps", "className"]);
16
13
  const [hasError, setHasError] = (0, react_1.useState)(false);
17
14
  const validateDate = (dateToValidate) => {
18
- if (dateValidation) {
19
- return dateValidation(dateToValidate);
20
- }
21
- // if the date is mandatory, convert it to a moment object to validate
22
- const value = (0, isEmpty_1.default)(dateToValidate) ? undefined : dateToValidate;
23
- const dateValue = typeof value === 'string' ? (0, moment_1.default)(value) : value;
24
- return isValidDate(dateValue);
15
+ // If the entered date complies with the defined dateFormat, the Datetime component
16
+ // returns a moment object, otherwise the return value is a string.
17
+ // Note, using a isValid() function from moment or the Date object itself will result in
18
+ // different outcome in various browsers.
19
+ // For instance `new Date('1')` or `moment('1')` are valid dates in Chrome where it defaults
20
+ // to "01/01/2001" whereas in Firefox it is an invalid date.
21
+ // The solution is to compare the entered value to the date format which is done by React Datetime.
22
+ const isDateObject = typeof dateToValidate === 'object';
23
+ return dateValidation ? dateValidation(dateToValidate) : isDateObject;
25
24
  };
26
25
  const handleChange = (date) => {
27
26
  const isValid = mandatory ? validateDate(date) : true;
@@ -9,7 +9,7 @@ const INITIAL_TICK = 700;
9
9
  const TICK_TIME = 50;
10
10
  const DEFAULT_DIGIT_PRECISION = 3;
11
11
  const NumberControl = (0, react_1.forwardRef)((props, ref) => {
12
- const { id, min = NumberInput_1.DEFAULT_MIN, max = NumberInput_1.DEFAULT_MAX, step = NumberInput_1.DEFAULT_STEP, value, onChange, onValueChanged = () => { }, disabled, bsSize, className, unit, inputAddon, errorMessage, warningMessage, messageWhiteSpace, digitPrecision = DEFAULT_DIGIT_PRECISION, placeholder } = props, remainingProps = tslib_1.__rest(props, ["id", "min", "max", "step", "value", "onChange", "onValueChanged", "disabled", "bsSize", "className", "unit", "inputAddon", "errorMessage", "warningMessage", "messageWhiteSpace", "digitPrecision", "placeholder"]);
12
+ const { id, min = NumberInput_1.DEFAULT_MIN, max = NumberInput_1.DEFAULT_MAX, step = NumberInput_1.DEFAULT_STEP, value, onChange, onValueChanged = () => { }, disabled, bsSize, className, unit, inputAddon, errorMessage, warningMessage, messageWhiteSpace, digitPrecision = DEFAULT_DIGIT_PRECISION, placeholder, noDefault } = props, remainingProps = tslib_1.__rest(props, ["id", "min", "max", "step", "value", "onChange", "onValueChanged", "disabled", "bsSize", "className", "unit", "inputAddon", "errorMessage", "warningMessage", "messageWhiteSpace", "digitPrecision", "placeholder", "noDefault"]);
13
13
  // Note, "onChange" should replace "onValueChanged" in the future but it's widely used
14
14
  const callback = onChange || onValueChanged;
15
15
  const timeout = (0, react_1.useRef)(null);
@@ -110,6 +110,6 @@ const NumberControl = (0, react_1.forwardRef)((props, ref) => {
110
110
  };
111
111
  const classes = (0, classnames_1.default)('NumberControl', className);
112
112
  const controls = ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: 'display-flex padding-left-10' }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ onMouseDown: handleMouseDownOnDecrement, onMouseUp: handleStopHolding, role: 'button', "aria-label": 'decrement-button', className: 'decrementButton text-color-gray hover-text-color-dark' }, { children: (0, jsx_runtime_1.jsx)("div", { className: 'rioglyph rioglyph-minus scale-90' }) })), (0, jsx_runtime_1.jsx)("div", Object.assign({ onMouseDown: handleMouseDownOnIncrement, onMouseUp: handleStopHolding, role: 'button', "aria-label": 'increment-button', className: 'incrementButton text-color-gray hover-text-color-dark margin-left-5' }, { children: (0, jsx_runtime_1.jsx)("div", { className: 'rioglyph rioglyph-plus scale-90' }) }))] })));
113
- return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, remainingProps, { className: classes }, { children: (0, jsx_runtime_1.jsx)(NumberInput_1.default, { id: id, ref: ref, min: min, max: max, value: internalValue, step: step, bsSize: bsSize, disabled: disabled, inputAddon: inputAddon, errorMessage: errorMessage, warningMessage: warningMessage, messageWhiteSpace: messageWhiteSpace, controls: controls, unit: unit, onChange: handleUpdatedNumberInputValue, digitPrecision: digitPrecision, placeholder: placeholder }) })));
113
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, remainingProps, { className: classes }, { children: (0, jsx_runtime_1.jsx)(NumberInput_1.default, { id: id, ref: ref, min: min, max: max, value: internalValue, step: step, bsSize: bsSize, disabled: disabled, inputAddon: inputAddon, errorMessage: errorMessage, warningMessage: warningMessage, messageWhiteSpace: messageWhiteSpace, controls: controls, unit: unit, onChange: handleUpdatedNumberInputValue, digitPrecision: digitPrecision, placeholder: placeholder, noDefault: noDefault }) })));
114
114
  });
115
115
  exports.default = NumberControl;
@@ -24,6 +24,12 @@ export type NumberInputProps = {
24
24
  * @default 0
25
25
  */
26
26
  value?: number;
27
+ /**
28
+ * Lets you omit the default value of "0" when the vale is not defined.
29
+ * The input will be empty in this case.
30
+ * @default false
31
+ */
32
+ noDefault?: boolean;
27
33
  /**
28
34
  * The size of increment or decrement (only works with number type).
29
35
  * @default 1
@@ -36,9 +36,9 @@ const validKeys = [
36
36
  // Note: even if limits are set and input type is number, many browsers allow to enter invalid data
37
37
  // like entering characters or values outside the boundaries, hence we have to check the input here
38
38
  // See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number
39
- const getValueFromProps = (val, min, max, placeholder) => {
40
- // Show placeholders if given instead of 0
41
- if (val === undefined && placeholder) {
39
+ const getValueFromProps = (val, min, max, placeholder, noDefault) => {
40
+ // Show placeholder or nothing if given instead of 0 if requested for
41
+ if (val === undefined && (placeholder || noDefault)) {
42
42
  return '';
43
43
  }
44
44
  return clampNumber(Number(val), min, max) || exports.DEFAULT_VALUE;
@@ -63,13 +63,13 @@ const isInvalidAfter = (key, possiblePreviousKeys, event, previousKeyRef) => {
63
63
  return event.key === key && possiblePreviousKeys.includes(previousKeyRef.current);
64
64
  };
65
65
  const NumberInput = (0, react_1.forwardRef)((props, ref) => {
66
- const { id, min: propMin, max: propMax, value: propValue, step = exports.DEFAULT_STEP, disabled = false, onChange, onValueChanged = noop_1.default, bsSize = 'md', unit, inputAddon, errorMessage, warningMessage, messageWhiteSpace = 'normal', controls, placeholder, digitPrecision = DEFAULT_DIGIT_PRECISION, className = '' } = props, remainingProps = tslib_1.__rest(props, ["id", "min", "max", "value", "step", "disabled", "onChange", "onValueChanged", "bsSize", "unit", "inputAddon", "errorMessage", "warningMessage", "messageWhiteSpace", "controls", "placeholder", "digitPrecision", "className"]);
66
+ const { id, min: propMin, max: propMax, value: propValue, step = exports.DEFAULT_STEP, disabled = false, noDefault = false, onChange, onValueChanged = noop_1.default, bsSize = 'md', unit, inputAddon, errorMessage, warningMessage, messageWhiteSpace = 'normal', controls, placeholder, digitPrecision = DEFAULT_DIGIT_PRECISION, className = '' } = props, remainingProps = tslib_1.__rest(props, ["id", "min", "max", "value", "step", "disabled", "noDefault", "onChange", "onValueChanged", "bsSize", "unit", "inputAddon", "errorMessage", "warningMessage", "messageWhiteSpace", "controls", "placeholder", "digitPrecision", "className"]);
67
67
  const previousKeyRef = (0, react_1.useRef)('');
68
68
  // Note, "onChange" should replace "onValueChanged" in the future but it's widely used
69
69
  const callback = onChange || onValueChanged;
70
70
  const min = (0, exports.convertNonIntegerToDefault)(propMin, exports.DEFAULT_MIN);
71
71
  const max = (0, exports.convertNonIntegerToDefault)(propMax, exports.DEFAULT_MAX);
72
- const value = getValueFromProps(propValue, min, max, placeholder);
72
+ const value = getValueFromProps(propValue, min, max, placeholder, noDefault);
73
73
  // Define local state and define initial values
74
74
  const [state, setState] = (0, react_1.useState)({
75
75
  value,
@@ -79,7 +79,7 @@ const NumberInput = (0, react_1.forwardRef)((props, ref) => {
79
79
  // Update internal value whenever the value prop from outside changes
80
80
  (0, useAfterMount_1.default)(() => {
81
81
  setState({
82
- value: getValueFromProps(propValue, min, max, placeholder),
82
+ value: getValueFromProps(propValue, min, max, placeholder, noDefault),
83
83
  enteredValue: value,
84
84
  isValid: true,
85
85
  });
@@ -141,6 +141,11 @@ const NumberInput = (0, react_1.forwardRef)((props, ref) => {
141
141
  callback();
142
142
  return;
143
143
  }
144
+ // If there is no value defined and a placeholder is given or the default is not wanted,
145
+ // keep the input empty
146
+ if (!state.value && (noDefault || placeholder)) {
147
+ return;
148
+ }
144
149
  // Otherwise, validate the input, round it according to digitPrecision,
145
150
  // and clamp the value if the entered value exceeds the limitations
146
151
  const convertedEnteredValue = (0, exports.convertNonIntegerToDefault)(Number(lastEnteredValue), exports.DEFAULT_VALUE);
@@ -156,7 +161,9 @@ const NumberInput = (0, react_1.forwardRef)((props, ref) => {
156
161
  const inputGroupClassNames = (0, classnames_1.default)('input-group', bsSize === 'sm' && 'input-group-sm', bsSize === 'lg' && 'input-group-lg');
157
162
  const inputClassNames = (0, classnames_1.default)('form-control', 'no-controls', bsSize === 'sm' && 'input-sm', bsSize === 'lg' && 'input-lg', className);
158
163
  const hasFeedback = errorMessage || warningMessage;
159
- const input = ((0, jsx_runtime_1.jsx)("input", Object.assign({}, remainingProps, { id: id, type: 'number', step: step, min: min, max: max, value: state.isValid ? state.value : state.enteredValue, className: inputClassNames, disabled: disabled, onBlur: handleBlur, onChange: handleOnChange, onKeyDown: handleKeyDown, ref: ref, "aria-label": 'number-input', placeholder: placeholder, onWheel: handleWheel })));
164
+ const input = ((0, jsx_runtime_1.jsx)("input", Object.assign({}, remainingProps, { id: id, type: 'number', step: step, min: min, max: max, value: state.isValid ? state.value : state.enteredValue, className: inputClassNames, disabled: disabled, onBlur: handleBlur,
165
+ // onChange={state.value ? handleOnChange : undefined}
166
+ onChange: handleOnChange, onKeyDown: handleKeyDown, ref: ref, "aria-label": 'number-input', placeholder: placeholder, onWheel: handleWheel })));
160
167
  return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: inputGroupClassNames }, { children: [inputAddon && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'input-group-addon' }, { children: (0, jsx_runtime_1.jsx)("span", { className: inputAddon }) }))), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: 'form-control-feedback-wrapper' }, { children: [input, hasFeedback && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [errorMessage && (0, jsx_runtime_1.jsx)("span", { className: 'form-control-feedback rioglyph rioglyph-error-sign' }), warningMessage && (0, jsx_runtime_1.jsx)("span", { className: 'form-control-feedback rioglyph rioglyph-warning-sign' }), (0, jsx_runtime_1.jsx)("span", Object.assign({ className: `help-block white-space-${messageWhiteSpace}` }, { children: (0, jsx_runtime_1.jsx)("span", { children: errorMessage || warningMessage }) }))] }))] })), (unit || controls) && ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `input-group-addon ${disabled ? 'disabled pointer-events-none' : ''}` }, { children: [unit && unit, controls && controls] })))] })));
161
168
  });
162
169
  exports.default = NumberInput;
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.16.4-beta.26"
2
+ "version": "0.16.4-beta.27"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rio-cloud/rio-uikit",
3
- "version": "0.16.4-beta.26",
3
+ "version": "0.16.4-beta.27",
4
4
  "description": "The RIO UIKIT component library",
5
5
  "repository": "https://bitbucket.collaboration-man.com/projects/RIOFRONT/repos/uikit-web/browse",
6
6
  "scripts": {
@@ -144,4 +144,4 @@
144
144
  "Firefox ESR",
145
145
  "not dead"
146
146
  ]
147
- }
147
+ }
package/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.16.4-beta.26"
2
+ "version": "0.16.4-beta.27"
3
3
  }