@spaced-out/ui-design-system 0.1.109 → 0.1.110
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
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.1.110](https://github.com/spaced-out/ui-design-system/compare/v0.1.109...v0.1.110) (2024-07-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* 🔢 prevents users from typing exponent characters in the number input field based on a prop ([#240](https://github.com/spaced-out/ui-design-system/issues/240)) ([db982e2](https://github.com/spaced-out/ui-design-system/commit/db982e2fbf754a57b778ee5b35de1dd39853bcda))
|
|
11
|
+
|
|
5
12
|
### [0.1.109](https://github.com/spaced-out/ui-design-system/compare/v0.1.108...v0.1.109) (2024-07-11)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Input = exports.INPUT_TYPES = void 0;
|
|
6
|
+
exports.Input = exports.INPUT_TYPES = exports.EXPONENT_CHARACTER_LIST = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _classify = require("../../utils/classify");
|
|
9
9
|
var _Icon = require("../Icon");
|
|
@@ -13,6 +13,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
13
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
15
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
16
|
+
const EXPONENT_CHARACTER_LIST = ['E', 'e'];
|
|
17
|
+
exports.EXPONENT_CHARACTER_LIST = EXPONENT_CHARACTER_LIST;
|
|
16
18
|
const INPUT_TYPES = Object.freeze({
|
|
17
19
|
text: 'text',
|
|
18
20
|
number: 'number',
|
|
@@ -55,6 +57,8 @@ const Input_ = (props, ref) => {
|
|
|
55
57
|
required,
|
|
56
58
|
readOnly,
|
|
57
59
|
boxRef,
|
|
60
|
+
onKeyDown,
|
|
61
|
+
disallowExponents,
|
|
58
62
|
...inputProps
|
|
59
63
|
} = props;
|
|
60
64
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
@@ -68,6 +72,14 @@ const Input_ = (props, ref) => {
|
|
|
68
72
|
}
|
|
69
73
|
onIconRightClick && onIconRightClick(e);
|
|
70
74
|
};
|
|
75
|
+
const handleKeyDown = e => {
|
|
76
|
+
if (type === INPUT_TYPES.number && disallowExponents) {
|
|
77
|
+
if (EXPONENT_CHARACTER_LIST.includes(e.key)) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
onKeyDown?.(e);
|
|
82
|
+
};
|
|
71
83
|
return /*#__PURE__*/React.createElement("div", {
|
|
72
84
|
className: (0, _classify.classify)(_InputModule.default.wrapper, {
|
|
73
85
|
[_InputModule.default.filled]: controlledInputFilled ?? false,
|
|
@@ -107,7 +119,8 @@ const Input_ = (props, ref) => {
|
|
|
107
119
|
onFocus: onFocus,
|
|
108
120
|
onBlur: onBlur,
|
|
109
121
|
type: showPassword ? 'text' : type,
|
|
110
|
-
readOnly: readOnly && 'readOnly'
|
|
122
|
+
readOnly: readOnly && 'readOnly',
|
|
123
|
+
onKeyDown: handleKeyDown
|
|
111
124
|
})), type === 'color' && /*#__PURE__*/React.createElement("div", {
|
|
112
125
|
className: (0, _classify.classify)(_InputModule.default.colorText, _InputModule.default[size], {
|
|
113
126
|
[_InputModule.default.hasValue]: value
|
|
@@ -15,6 +15,8 @@ type ClassNames = $ReadOnly<{
|
|
|
15
15
|
iconRight?: string,
|
|
16
16
|
}>;
|
|
17
17
|
|
|
18
|
+
export const EXPONENT_CHARACTER_LIST = ['E', 'e'];
|
|
19
|
+
|
|
18
20
|
export const INPUT_TYPES = Object.freeze({
|
|
19
21
|
text: 'text',
|
|
20
22
|
number: 'number',
|
|
@@ -69,6 +71,11 @@ export type InputProps = {
|
|
|
69
71
|
min?: string,
|
|
70
72
|
max?: string,
|
|
71
73
|
autoComplete?: string,
|
|
74
|
+
/* Note(Nishant): Restricts typing `e` and `E` in the number input when
|
|
75
|
+
set to true. We have baked this condition in the keydown handler itself so
|
|
76
|
+
this would restrict and not show these exponent characters when typed
|
|
77
|
+
**/
|
|
78
|
+
disallowExponents?: boolean,
|
|
72
79
|
/** The step attribute is a number that specifies the granularity that the value must adhere to, or the special value any.
|
|
73
80
|
* Only values which are equal to the basis for stepping (min if specified, value otherwise, and an
|
|
74
81
|
* appropriate default value if neither of those is provided) are valid. */
|
|
@@ -102,6 +109,8 @@ const Input_ = (props: InputProps, ref): React.Node => {
|
|
|
102
109
|
required,
|
|
103
110
|
readOnly,
|
|
104
111
|
boxRef,
|
|
112
|
+
onKeyDown,
|
|
113
|
+
disallowExponents,
|
|
105
114
|
...inputProps
|
|
106
115
|
} = props;
|
|
107
116
|
|
|
@@ -121,6 +130,16 @@ const Input_ = (props: InputProps, ref): React.Node => {
|
|
|
121
130
|
onIconRightClick && onIconRightClick(e);
|
|
122
131
|
};
|
|
123
132
|
|
|
133
|
+
const handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
|
|
134
|
+
if (type === INPUT_TYPES.number && disallowExponents) {
|
|
135
|
+
if (EXPONENT_CHARACTER_LIST.includes(e.key)) {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
onKeyDown?.(e);
|
|
141
|
+
};
|
|
142
|
+
|
|
124
143
|
return (
|
|
125
144
|
<div
|
|
126
145
|
className={classify(css.wrapper, {
|
|
@@ -173,6 +192,7 @@ const Input_ = (props: InputProps, ref): React.Node => {
|
|
|
173
192
|
onBlur={onBlur}
|
|
174
193
|
type={showPassword ? 'text' : type}
|
|
175
194
|
readOnly={readOnly && 'readOnly'}
|
|
195
|
+
onKeyDown={handleKeyDown}
|
|
176
196
|
/>
|
|
177
197
|
{type === 'color' && (
|
|
178
198
|
<div
|