@widergy/energy-ui 3.46.0 → 3.48.0

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
@@ -1,3 +1,17 @@
1
+ # [3.48.0](https://github.com/widergy/energy-ui/compare/v3.47.0...v3.48.0) (2024-12-11)
2
+
3
+
4
+ ### Features
5
+
6
+ * [CGE-565] utvirtualkeyboard ([#541](https://github.com/widergy/energy-ui/issues/541)) ([d1d0d5e](https://github.com/widergy/energy-ui/commit/d1d0d5e5ff4a8cce1d1cec78e7b53cb9c49476a4))
7
+
8
+ # [3.47.0](https://github.com/widergy/energy-ui/compare/v3.46.0...v3.47.0) (2024-12-03)
9
+
10
+
11
+ ### Features
12
+
13
+ * added react-credit-cards ([#538](https://github.com/widergy/energy-ui/issues/538)) ([5364625](https://github.com/widergy/energy-ui/commit/5364625a91519253ca26892bee9103c5fef7c232))
14
+
1
15
  # [3.46.0](https://github.com/widergy/energy-ui/compare/v3.45.0...v3.46.0) (2024-12-02)
2
16
 
3
17
 
@@ -27,6 +27,7 @@ const UTAutocomplete = _ref => {
27
27
  ArrowIcon,
28
28
  autocompleteProps,
29
29
  classes = {},
30
+ dataTestId,
30
31
  disabled,
31
32
  field,
32
33
  fixedSizeListProps,
@@ -98,6 +99,14 @@ const UTAutocomplete = _ref => {
98
99
  label: textInputLabel,
99
100
  fullWidth: true,
100
101
  error: (0, _form.shouldShowErrors)(meta),
102
+ InputProps: {
103
+ ...params.InputProps,
104
+ inputProps: {
105
+ ...params.inputProps,
106
+ 'data-keyboard': input !== null && input !== void 0 && input.name ? "autocomplete-".concat(input.name) : null,
107
+ 'data-testid': dataTestId
108
+ }
109
+ },
101
110
  helperText: errorMessage ? /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
102
111
  className: classes.errorLabel,
103
112
  colorTheme: "error",
@@ -112,6 +121,7 @@ UTAutocomplete.propTypes = {
112
121
  ArrowIcon: _propTypes.elementType,
113
122
  autocompleteProps: _propTypes.object,
114
123
  classes: (0, _propTypes.objectOf)(_propTypes.string),
124
+ dataTestId: _propTypes.string,
115
125
  disabled: _propTypes.bool,
116
126
  input: _formTypes.inputPropTypes.isRequired,
117
127
  field: _formTypes.fieldType,
@@ -61,13 +61,9 @@ const UTBaseInputField = _ref => {
61
61
  }
62
62
  }, [onChange, type]);
63
63
  const handleKeyDown = (0, _react.useCallback)(event => {
64
- if (type === 'numeric') {
65
- const allowedKeys = ['Backspace', 'ArrowLeft', 'ArrowRight', 'Delete', 'Tab'];
66
- const isNumericKey = /^[0-9]$/;
67
- if (!isNumericKey.test(event.key) && !allowedKeys.includes(event.key)) {
68
- event.preventDefault();
69
- }
70
- }
64
+ const allowedKey = ['Backspace', 'ArrowLeft', 'ArrowRight', 'Delete', 'Tab'].includes(event.key);
65
+ const isNumericKey = /^[0-9]$/.test(event.key);
66
+ if (type === 'numeric' && !isNumericKey && !allowedKey) event.preventDefault();else if (!allowedKey) event.stopPropagation();
71
67
  }, [type]);
72
68
  const multiline = maxRows > 1;
73
69
  const hasCharactersCount = (0, _react.useMemo)(() => showCharacterCount && maxLength && !disabled && !readOnly, [showCharacterCount, maxLength, disabled, readOnly]);
@@ -24,7 +24,8 @@ const UTCBUInput = _ref => {
24
24
  } = _ref;
25
25
  const {
26
26
  onChange,
27
- value
27
+ value,
28
+ name
28
29
  } = input;
29
30
  const {
30
31
  placeholder,
@@ -57,6 +58,7 @@ const UTCBUInput = _ref => {
57
58
  },
58
59
  helperTextDataTestId: helperTextDataTestId,
59
60
  input: {
61
+ name,
60
62
  onChange: onChangeText,
61
63
  value: {
62
64
  [cbuNumberKey]: value[cbuNumberKey],
@@ -97,7 +97,10 @@ class UTCuit extends _react.PureComponent {
97
97
  const {
98
98
  documentDataTestId,
99
99
  prefixDataTestId,
100
- verificationCodeDataTestId
100
+ verificationCodeDataTestId,
101
+ input: {
102
+ name
103
+ }
101
104
  } = this.props;
102
105
  this.handleFocus();
103
106
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -116,7 +119,8 @@ class UTCuit extends _react.PureComponent {
116
119
  InputProps: {
117
120
  type: 'input',
118
121
  inputProps: {
119
- 'data-testid': prefixDataTestId
122
+ 'data-testid': prefixDataTestId,
123
+ 'data-keyboard': name ? "prefix-".concat(name) : null
120
124
  }
121
125
  },
122
126
  label: this.props.field.label,
@@ -135,7 +139,8 @@ class UTCuit extends _react.PureComponent {
135
139
  InputProps: {
136
140
  type: 'text',
137
141
  inputProps: {
138
- 'data-testid': documentDataTestId
142
+ 'data-testid': documentDataTestId,
143
+ 'data-keyboard': name ? "document-".concat(name) : null
139
144
  }
140
145
  },
141
146
  inputRef: this.documentRef,
@@ -154,7 +159,8 @@ class UTCuit extends _react.PureComponent {
154
159
  InputProps: {
155
160
  type: 'input',
156
161
  inputProps: {
157
- 'data-testid': verificationCodeDataTestId
162
+ 'data-testid': verificationCodeDataTestId,
163
+ 'data-keyboard': name ? "verificationCode-".concat(name) : null
158
164
  }
159
165
  },
160
166
  margin: "none",
@@ -223,7 +223,8 @@ class UTPhoneInput extends _react.PureComponent {
223
223
  input: inputClassName
224
224
  },
225
225
  inputProps: {
226
- 'data-testid': areaCodeDataTestId
226
+ 'data-testid': areaCodeDataTestId,
227
+ 'data-keyboard': input !== null && input !== void 0 && input.name ? "areaCode-".concat(input === null || input === void 0 ? void 0 : input.name) : null
227
228
  }
228
229
  }
229
230
  }, areaCodeFieldProps)), /*#__PURE__*/_react.default.createElement(_UTTooltip.default, {
@@ -256,7 +257,8 @@ class UTPhoneInput extends _react.PureComponent {
256
257
  input: inputClassName
257
258
  },
258
259
  inputProps: {
259
- 'data-testid': phoneNumberDataTestId
260
+ 'data-testid': phoneNumberDataTestId,
261
+ 'data-keyboard': input !== null && input !== void 0 && input.name ? "phoneNumber-".concat(input === null || input === void 0 ? void 0 : input.name) : null
260
262
  }
261
263
  }
262
264
  }, phoneNumberFieldProps)))), (error || (0, _form.shouldShowErrors)(meta)) && /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
@@ -25,6 +25,7 @@ const UTTextArea = _ref => {
25
25
  disabled,
26
26
  field,
27
27
  HelpIcon,
28
+ input,
28
29
  inputProps = {},
29
30
  onBlur,
30
31
  onChange,
@@ -64,6 +65,7 @@ const UTTextArea = _ref => {
64
65
  }, /*#__PURE__*/_react.default.createElement("textarea", _extends({}, inputProps, {
65
66
  className: "".concat(_stylesModule.default.textarea, " ").concat(textarea, " ").concat(classes.textarea),
66
67
  "data-testid": dataTestId,
68
+ "data-keyboard": input === null || input === void 0 ? void 0 : input.name,
67
69
  onChange: handleOnChange,
68
70
  onBlur: onBlur,
69
71
  onFocus: onFocus,
@@ -93,6 +95,7 @@ UTTextArea.propTypes = {
93
95
  disabled: _propTypes.bool,
94
96
  field: _formTypes.fieldType,
95
97
  HelpIcon: _propTypes.elementType,
98
+ input: _propTypes.object,
96
99
  inputProps: _formTypes.inputPropTypes,
97
100
  onBlur: _propTypes.func,
98
101
  onChange: _propTypes.func,
@@ -149,7 +149,8 @@ class UTTextInput extends _react.PureComponent {
149
149
  InputProps: {
150
150
  id: fieldId,
151
151
  inputProps: {
152
- 'data-testid': dataTestId
152
+ 'data-testid': dataTestId,
153
+ 'data-keyboard': (input === null || input === void 0 ? void 0 : input.name) || null
153
154
  },
154
155
  endAdornment: endAction && /*#__PURE__*/_react.default.createElement(_InputAdornment.default, {
155
156
  position: "end",
@@ -0,0 +1,197 @@
1
+ # UTVirtualKeyboard
2
+
3
+ ## Description
4
+
5
+ Configurable virtual keyboard intended for use within products running on devices without access to a physical keyboard or whose keyboard, either physical or virtual, can't be trusted.
6
+
7
+ ## Props
8
+
9
+ | Name | Type | Default | Description |
10
+ | ------------------- | ------------------ | ------- | -------------------------------------------------------- |
11
+ | `currentFieldValue` | `string \| number` | - | Current value of the field the keyboard is modifying. |
12
+ | `handleChangeValue` | `function` | - | Method used by the keyboard to update the field's value. |
13
+ | `handleOnEnter` | `function` | - | Method invoked when the `{enter}` key is pressed. |
14
+ | `show` | `boolean` | - | Whether the keyboard is rendered or not. |
15
+
16
+ ## Auxiliary Methods
17
+
18
+ This methods can be found in `utils/keyboardUtils.js` and are intended for general use of the keyboard, allowing it's use within forms, particularly `redux-form` components.
19
+ For any other case, custom methods can be used, as long as the keyboard gets the `current value` of the focused field, and the methods to execute `onEnter` and `onValueChange`.
20
+
21
+ ### clickForKeyboard
22
+
23
+ This method is intended to be used within a `click` `eventListener`. The objective of it's execution is to define whether or not to open the keyboard in response to a `click event`.
24
+ It requires to be instanced before being passed to the `event listener`.
25
+
26
+ ```jsx
27
+ const openKeyboard = clickForKeyboard(formList, setFieldIdentifiers, setShowKeyboard, showKeyboard);
28
+ ```
29
+
30
+ This instance expects:
31
+
32
+ | Argument | Type | Default | Description |
33
+ | --------------------- | ---------- | ------- | -------------------------------------------------------------------------------------------------------------- |
34
+ | `formList` | `object` | - | The `form` key (or it's equivalent) from the redux store that contains a list of every active form on the app. |
35
+ | `setFieldIdentifiers` | `function` | - | The `setState` `function` that modifies the `fieldIdentifiers` `object` in the parent component. |
36
+ | `setShowKeyboard` | `function` | - | The `setState` `function` that modifies the value of `showKeyboard` in the parent component. |
37
+ | `showKeyboard` | `boolean` | - | The value that defines whether the keyboard is rendered or not. |
38
+
39
+ After being instanced it can be passed to the `event listener` and it's able to handle the event as it's sent by the browser
40
+
41
+ ```jsx
42
+ window.addEventListener('click', openKeyboard);
43
+ ```
44
+
45
+ Always remember to `remove` `event listeners`, specially if you add them in a `useEffect`
46
+
47
+ ```jsx
48
+ seEffect(() => {
49
+ window.addEventListener('click', openKeyboard);
50
+ return () => {
51
+ window.removeEventListener('click', openKeyboard);
52
+ };
53
+ }, [{ dependencies }]);
54
+ ```
55
+
56
+ ### getIsInputForKeyboard
57
+
58
+ This method is used within `clickForKeyboard`, but it could be useful on it's own.
59
+
60
+ The idea behind this method is to check if the `clicked` element is an `input` o a `textarea` to define if it's posible to type within said element. If it's an `input` it alse checks that it's `type` is within those `inputs` that can be typed within.
61
+
62
+ | Argument | Type | Default | Description |
63
+ | ---------- | -------- | ------- | ------------------------------------------- |
64
+ | `nodeName` | `string` | - | The `nodeName` property of a `event.target` |
65
+ | `type` | `string` | - | The `type` property of a `event.target` |
66
+
67
+ ### getIsKeyboard
68
+
69
+ This method is used within `clickForKeyboard`, but it could be useful on it's own.
70
+
71
+ The idea behind this method is to check if the `clicked` element is part of the `UTVirtualKeyboard`
72
+
73
+ | Argument | Type | Default | Description |
74
+ | ------------- | -------- | ------- | --------------------------------------- |
75
+ | `eventTarget` | `object` | - | The `event.target` object |
76
+ | `type` | `string` | - | The `type` property of a `event.target` |
77
+
78
+ ### getFieldValue
79
+
80
+ This method is used to get the `current value` of the focused `field`. The search is made within the `form` `key` of the `redux store`.
81
+
82
+ | Argument | Type | Default | Description |
83
+ | -------------------- | ---------- | ------- | --------------------------------------------------------- |
84
+ | `currentIdentifiers` | `object` | - | The `fieldIdentifiers` `object` from the parent component |
85
+ | `fieldSelector` | `function` | - | A `selector` function to search within the state |
86
+ | `state` | `object` | - | The `form` key of the `redux state` |
87
+
88
+ ```jsx
89
+ const state = reduxStore.getState();
90
+ const { form: formList } = state;
91
+
92
+ const [fieldIdentifiers, setFieldIdentifiers] = useState(null);
93
+
94
+ const selector = formName => formValueSelector(formName);
95
+
96
+ const currentFieldValue = getFieldValue(fieldIdentifiers, selector, state);
97
+ ```
98
+
99
+ ### indentifyField
100
+
101
+ This method is used within `clickForKeyboard`, but it could be useful on it's own.
102
+
103
+ The idea behind this method is to get `identifying values` that allow to define which field to work upon when using the `UTVirtualKeyboard`
104
+
105
+ | Argument | Type | Default | Description |
106
+ | ------------- | -------- | ------- | -------------------------------------------------------------------------------------------------------------- |
107
+ | `eventTarget` | `object` | - | The `event.target` object |
108
+ | `forms` | `object` | - | The `form` key (or it's equivalent) from the redux store that contains a list of every active form on the app. |
109
+
110
+ ### preventPointerDown
111
+
112
+ This method is used within `clickForKeyboard`, but it could be useful on it's own.
113
+
114
+ The idea behind this method is to be used within a `pointerdown` `event listener`. It's sole function is to do a `preventDefault` of the
115
+ aforementioned event.
116
+
117
+ ## Keyboard Simplified Usage
118
+
119
+ ```jsx
120
+ import React, {useState} from 'react';
121
+
122
+ import { UTVirtualKeyboard } from '@widergy/energy-ui';
123
+
124
+ const Example = () => {
125
+ const [showKeyboard, setShowKeyboard] = useState(true);
126
+
127
+ let currentFieldValue = 'foo';
128
+
129
+ const handleChangeValue = () => currentFieldValue = 'bar';
130
+
131
+ const handleOnEnter () => {
132
+ console.log(currentFieldValue);
133
+ setShowKeyboard(false)
134
+ };
135
+
136
+ return (
137
+ <UTVirtualKeyboard
138
+ show={showKeyboard}
139
+ currentFieldValue={currentFieldValue}
140
+ handleChangeValue={handleKeyboardChangeValue}
141
+ handleOnEnter={handleKeyboardEnter}
142
+ />
143
+ );
144
+ };
145
+
146
+ export default Exampe;
147
+ ```
148
+
149
+ ## Keyboard Extended Usage (as implemented in UGTotem)
150
+
151
+ ```jsx
152
+ import React, { useEffect, useState } from 'react';
153
+ import { UTVirtualKeyboard, keyboardUtils } from '@widergy/energy-ui';
154
+
155
+ import reduxStore from 'redux/store';
156
+
157
+ const App = ({ location }) => {
158
+ const state = reduxStore.getState();
159
+ const { form: formList } = state;
160
+
161
+ const [showKeyboard, setShowKeyboard] = useState(false);
162
+ const [fieldIdentifiers, setFieldIdentifiers] = useState(null);
163
+
164
+ const openKeyboard = clickForKeyboard(formList, setFieldIdentifiers, setShowKeyboard, showKeyboard);
165
+
166
+ const selector = formName => formValueSelector(formName);
167
+
168
+ const currentFieldValue = getFieldValue(fieldIdentifiers, selector, state);
169
+
170
+ const handleKeyboardChangeValue = value => {
171
+ const { onChange } = fieldIdentifiers || {};
172
+ if (onChange)
173
+ onChange({
174
+ target: { value }
175
+ });
176
+ };
177
+ const handleKeyboardEnter = () => dispatch(submit(fieldIdentifiers?.formName));
178
+
179
+ useEffect(() => {
180
+ window.addEventListener('click', openKeyboard);
181
+ return () => {
182
+ window.removeEventListener('click', openKeyboard);
183
+ };
184
+ }, [showKeyboard, fieldIdentifiers, formList]);
185
+
186
+ useEffect(() => setShowKeyboard(false), [location]);
187
+
188
+ return (
189
+ <UTVirtualKeyboard
190
+ show={showKeyboard}
191
+ currentFieldValue={currentFieldValue}
192
+ handleChangeValue={handleKeyboardChangeValue}
193
+ handleOnEnter={handleKeyboardEnter}
194
+ />
195
+ );
196
+ };
197
+ ```
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WIDERGY_LAYOUTS_ES = exports.WIDERGY_DISPLAY = exports.UPPERCASE = exports.SPECIAL_KEYS = exports.SPECIAL_CHARACTERS = exports.DEFAULT = exports.CAPSLOCK_DELAY = exports.CAPSLOCKED = void 0;
7
+ const CAPSLOCK_DELAY = exports.CAPSLOCK_DELAY = 500;
8
+
9
+ // Layout names
10
+ const CAPSLOCKED = exports.CAPSLOCKED = 'capslocked';
11
+ const DEFAULT = exports.DEFAULT = 'default';
12
+ const SPECIAL_CHARACTERS = exports.SPECIAL_CHARACTERS = 'special_characters';
13
+ const UPPERCASE = exports.UPPERCASE = 'uppercase';
14
+
15
+ // Special keys
16
+ const ALT = 'alt';
17
+ const BKSP = 'bksp';
18
+ const LOCK = 'lock';
19
+ const SHIFT = 'shift';
20
+ const ENTER = 'enter';
21
+ const SPACE = 'space';
22
+ const SPECIAL_KEYS = exports.SPECIAL_KEYS = {
23
+ [ALT]: '{alt}',
24
+ [BKSP]: '{bksp}',
25
+ [DEFAULT]: '{default}',
26
+ [ENTER]: '{enter}',
27
+ [LOCK]: '{lock}',
28
+ [SHIFT]: '{shift}',
29
+ [SPACE]: '{space}'
30
+ };
31
+
32
+ // Static keyboard lines
33
+ const FIRST_LINE = 'q w e r t y u i o p';
34
+ const SECOND_LINE = 'a s d f g h j k l ñ';
35
+ const THIRD_LINE = '{shift} z x c v b n m {bksp}';
36
+ const FOURTH_LINE = '{alt} {space} {enter}';
37
+
38
+ // Uppercased lines
39
+ const UPPERCASED_THIRD_LINE = THIRD_LINE.toUpperCase().replace(SHIFT.toUpperCase(), SHIFT).replace(BKSP.toUpperCase(), BKSP);
40
+ const CAPSLOCKED_THIRD_LINE = UPPERCASED_THIRD_LINE.replace(SHIFT, LOCK);
41
+
42
+ // Special characters lines
43
+ const SPECIAL_CHARACTERS_FIRST_LINE = '1 2 3 4 5 6 7 8 9 0';
44
+ const SPECIAL_CHARACTERS_SECOND_LINE = "@ # $ & * ( ) ' \" , .";
45
+ const SPECIAL_CHARACTERS_THIRD_LINE = '{shift} % - + = / ; : ! ? {bksp}';
46
+ const SPECIAL_CHARACTERS_FOURTH_LINE = FOURTH_LINE.replace(ALT, DEFAULT);
47
+
48
+ // Final layouts
49
+ const WIDERGY_LAYOUTS_ES = exports.WIDERGY_LAYOUTS_ES = {
50
+ [DEFAULT]: [FIRST_LINE, SECOND_LINE, THIRD_LINE, FOURTH_LINE],
51
+ [UPPERCASE]: [FIRST_LINE.toUpperCase(), SECOND_LINE.toUpperCase(), UPPERCASED_THIRD_LINE, FOURTH_LINE],
52
+ [CAPSLOCKED]: [FIRST_LINE.toUpperCase(), SECOND_LINE.toUpperCase(), CAPSLOCKED_THIRD_LINE, FOURTH_LINE],
53
+ [SPECIAL_CHARACTERS]: [SPECIAL_CHARACTERS_FIRST_LINE, SPECIAL_CHARACTERS_SECOND_LINE, SPECIAL_CHARACTERS_THIRD_LINE, SPECIAL_CHARACTERS_FOURTH_LINE]
54
+ };
55
+
56
+ // Special keys displays
57
+ const WIDERGY_DISPLAY = exports.WIDERGY_DISPLAY = {
58
+ [SPECIAL_KEYS.alt]: '.?123',
59
+ [SPECIAL_KEYS.bksp]: '⌫',
60
+ [SPECIAL_KEYS.default]: 'ABC',
61
+ [SPECIAL_KEYS.enter]: '↲',
62
+ [SPECIAL_KEYS.lock]: '⇪',
63
+ [SPECIAL_KEYS.shift]: '⇧',
64
+ [SPECIAL_KEYS.space]: '⎵'
65
+ };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ require("react-simple-keyboard/build/css/index.css");
8
+ var _reactSimpleKeyboard = _interopRequireDefault(require("react-simple-keyboard"));
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _propTypes = require("prop-types");
11
+ var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
12
+ var _utils = require("./utils");
13
+ var _constants = require("./constants");
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ const UTVirtualKeyboard = _ref => {
18
+ let {
19
+ currentFieldValue,
20
+ handleChangeValue,
21
+ handleOnEnter,
22
+ show
23
+ } = _ref;
24
+ const [fieldValue, setFieldValue] = (0, _react.useState)(currentFieldValue);
25
+ const [layoutName, setLayoutName] = (0, _react.useState)(_constants.DEFAULT);
26
+ const [shiftPressTimeStamp, setShiftPressTimeStamp] = (0, _react.useState)(null);
27
+ const resetState = () => {
28
+ setFieldValue(currentFieldValue);
29
+ setShiftPressTimeStamp(null);
30
+ };
31
+ (0, _react.useEffect)(() => {
32
+ handleChangeValue(fieldValue);
33
+ }, [fieldValue]);
34
+ (0, _react.useEffect)(resetState, [handleChangeValue]);
35
+ (0, _react.useEffect)(() => setLayoutName(_constants.DEFAULT), [show]);
36
+ const handleKeyPress = pressedKey => {
37
+ if (Object.values(_constants.SPECIAL_KEYS).includes(pressedKey)) {
38
+ (0, _utils.localKeysHandle)({
39
+ fieldValue,
40
+ layoutName,
41
+ onEnter: handleOnEnter,
42
+ pressedKey,
43
+ setFieldValue,
44
+ setLayoutName,
45
+ setShiftPressTimeStamp,
46
+ shiftPressTimeStamp
47
+ });
48
+ return;
49
+ }
50
+ if (layoutName === _constants.UPPERCASE) {
51
+ (0, _utils.shiftSwitcher)(layoutName, setLayoutName);
52
+ }
53
+ setFieldValue("".concat(fieldValue || '').concat(pressedKey));
54
+ };
55
+ return show ? /*#__PURE__*/_react.default.createElement(_reactSimpleKeyboard.default, {
56
+ display: _constants.WIDERGY_DISPLAY,
57
+ layout: _constants.WIDERGY_LAYOUTS_ES,
58
+ layoutName: layoutName,
59
+ onKeyPress: handleKeyPress,
60
+ theme: _stylesModule.default.keyboard
61
+ }) : null;
62
+ };
63
+ UTVirtualKeyboard.propTypes = {
64
+ currentFieldValue: (0, _propTypes.oneOfType)([_propTypes.string, _propTypes.number]),
65
+ handleChangeValue: _propTypes.func,
66
+ handleOnEnter: _propTypes.func,
67
+ show: _propTypes.bool
68
+ };
69
+ var _default = exports.default = UTVirtualKeyboard;
@@ -0,0 +1,102 @@
1
+ $key-shadow: #00000038;
2
+
3
+ .keyboard {
4
+ background-color: var(--light04);
5
+ bottom: 0;
6
+ padding: 48px 12px;
7
+ position: sticky;
8
+ z-index: 1;
9
+
10
+ @media (orientation: landscape) {
11
+ padding: 32px 16px;
12
+ }
13
+
14
+ :global(.hg-rows) {
15
+ display: flex;
16
+ flex-direction: column;
17
+ grid-gap: 48px;
18
+ width: 100%;
19
+
20
+ @media (orientation: landscape) {
21
+ grid-gap: 18px;
22
+ }
23
+
24
+ :global(.hg-row) {
25
+ display: flex;
26
+ grid-gap: 16px;
27
+ justify-content: center;
28
+
29
+ @media (orientation: landscape) {
30
+ grid-gap: 18px;
31
+ }
32
+
33
+ :global(.hg-button) {
34
+ align-items: center;
35
+ background: var(--light01);
36
+ border-radius: 10px;
37
+ box-shadow: 0px 3px 0px 0px $key-shadow;
38
+ color: var(--gray04);
39
+ display: flex;
40
+ height: 184px;
41
+ justify-content: center;
42
+ max-width: 91px;
43
+ width: 91px;
44
+
45
+ > span {
46
+ font-size: 50px;
47
+ pointer-events: none;
48
+ }
49
+
50
+ @media (orientation: landscape) {
51
+ height: 92px;
52
+ max-width: 172px;
53
+ width: 172px;
54
+
55
+ > span {
56
+ font-size: 40px;
57
+ }
58
+ }
59
+ }
60
+
61
+ [data-skbtn="{alt}"],
62
+ [data-skbtn="{bksp}"],
63
+ [data-skbtn="{default}"],
64
+ [data-skbtn="{enter}"],
65
+ [data-skbtn="{lock}"],
66
+ [data-skbtn="{shift}"] {
67
+ background-color: var(--light03);
68
+ font-weight: 500;
69
+ min-width: 117px;
70
+
71
+ > span {
72
+ font-size: 40px;
73
+ }
74
+
75
+ @media (orientation: landscape) {
76
+ font-weight: 400;
77
+ min-width: 254px;
78
+ }
79
+ }
80
+
81
+ [data-skbtn="{bksp}"],
82
+ [data-skbtn="{enter}"] {
83
+ margin-left: auto;
84
+ }
85
+
86
+ [data-skbtn="{alt}"],
87
+ [data-skbtn="{default}"],
88
+ [data-skbtn="{lock}"],
89
+ [data-skbtn="{shift}"] {
90
+ margin-right: auto;
91
+ }
92
+
93
+ [data-skbtn="{space}"] {
94
+ min-width: 725px;
95
+
96
+ @media (orientation: landscape) {
97
+ min-width: 1228px;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shiftSwitcher = exports.localKeysHandle = void 0;
7
+ var _constants = require("./constants");
8
+ const shiftSwitcher = (layoutName, setLayoutName) => {
9
+ switch (layoutName) {
10
+ case _constants.DEFAULT:
11
+ setLayoutName(_constants.UPPERCASE);
12
+ break;
13
+ case _constants.UPPERCASE:
14
+ setLayoutName(_constants.DEFAULT);
15
+ break;
16
+ case _constants.SPECIAL_CHARACTERS:
17
+ setLayoutName(_constants.UPPERCASE);
18
+ break;
19
+ default:
20
+ break;
21
+ }
22
+ };
23
+ exports.shiftSwitcher = shiftSwitcher;
24
+ const localKeysHandle = _ref => {
25
+ let {
26
+ fieldValue,
27
+ layoutName,
28
+ onEnter,
29
+ pressedKey,
30
+ setFieldValue,
31
+ setLayoutName,
32
+ setShiftPressTimeStamp,
33
+ shiftPressTimeStamp
34
+ } = _ref;
35
+ switch (pressedKey) {
36
+ case _constants.SPECIAL_KEYS.alt:
37
+ setLayoutName(_constants.SPECIAL_CHARACTERS);
38
+ break;
39
+ case _constants.SPECIAL_KEYS.default:
40
+ setLayoutName(_constants.DEFAULT);
41
+ break;
42
+ case _constants.SPECIAL_KEYS.shift:
43
+ if (shiftPressTimeStamp && Date.now() - shiftPressTimeStamp < _constants.CAPSLOCK_DELAY) {
44
+ setLayoutName(_constants.CAPSLOCKED);
45
+ return;
46
+ }
47
+ setShiftPressTimeStamp(Date.now());
48
+ shiftSwitcher(layoutName, setLayoutName);
49
+ break;
50
+ case _constants.SPECIAL_KEYS.lock:
51
+ setLayoutName(layoutName === _constants.DEFAULT ? _constants.UPPERCASE : _constants.DEFAULT);
52
+ break;
53
+ case _constants.SPECIAL_KEYS.bksp:
54
+ setFieldValue(fieldValue ? fieldValue.slice(0, -1) : '');
55
+ break;
56
+ case _constants.SPECIAL_KEYS.enter:
57
+ onEnter();
58
+ break;
59
+ case _constants.SPECIAL_KEYS.space:
60
+ setFieldValue("".concat(fieldValue || '', ' '));
61
+ break;
62
+ default:
63
+ break;
64
+ }
65
+ };
66
+ exports.localKeysHandle = localKeysHandle;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NO_FORM = exports.KEYBOARD_ALLOWED_TYPES = exports.HANDLER_IDENTIFIER = void 0;
7
+ const HANDLER_IDENTIFIER = exports.HANDLER_IDENTIFIER = 'reactEvent';
8
+ const NO_FORM = exports.NO_FORM = 'NO_FORM';
9
+ const KEYBOARD_ALLOWED_TYPES = exports.KEYBOARD_ALLOWED_TYPES = ['date', 'datetime-local', 'email', 'month', 'number', 'password', 'search', 'tel', 'text'];
package/dist/index.js CHANGED
@@ -411,6 +411,12 @@ Object.defineProperty(exports, "UTValidation", {
411
411
  return _UTValidation.default;
412
412
  }
413
413
  });
414
+ Object.defineProperty(exports, "UTVirtualKeyboard", {
415
+ enumerable: true,
416
+ get: function () {
417
+ return _UTVirtualKeyboard.default;
418
+ }
419
+ });
414
420
  Object.defineProperty(exports, "UTVirtualizedList", {
415
421
  enumerable: true,
416
422
  get: function () {
@@ -441,9 +447,16 @@ Object.defineProperty(exports, "componentUtils", {
441
447
  return _componentUtils.default;
442
448
  }
443
449
  });
450
+ Object.defineProperty(exports, "keyboardUtils", {
451
+ enumerable: true,
452
+ get: function () {
453
+ return _keyboardUtils.default;
454
+ }
455
+ });
444
456
  var _AlertHandler = _interopRequireDefault(require("./components/UTAlert/AlertHandler"));
445
457
  var _componentUtils = _interopRequireDefault(require("./utils/componentUtils"));
446
458
  var _EnergyThemeProvider = _interopRequireDefault(require("./components/EnergyThemeProvider"));
459
+ var _keyboardUtils = _interopRequireDefault(require("./utils/keyboardUtils"));
447
460
  var _UTActionCard = _interopRequireDefault(require("./components/UTActionCard"));
448
461
  var _UTAlert = _interopRequireDefault(require("./components/UTAlert"));
449
462
  var _UTAttachment = _interopRequireDefault(require("./components/UTAttachment"));
@@ -511,6 +524,7 @@ var _UTTouchableWithoutFeedback = _interopRequireDefault(require("./components/U
511
524
  var _UTTracker = _interopRequireDefault(require("./components/UTTracker"));
512
525
  var _UTValidation = _interopRequireDefault(require("./components/UTValidation"));
513
526
  var _UTVirtualizedList = _interopRequireDefault(require("./components/UTVirtualizedList"));
527
+ var _UTVirtualKeyboard = _interopRequireDefault(require("./components/UTVirtualKeyboard"));
514
528
  var _UTWorkflowContainer = _interopRequireDefault(require("./components/UTWorkflowContainer"));
515
529
  var _WithLoading = _interopRequireDefault(require("./components/WithLoading"));
516
530
  var _WithTouch = _interopRequireDefault(require("./components/WithTouch"));
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.preventPointerDown = exports.identifyField = exports.getIsKeyboard = exports.getIsInputForKeyboard = exports.getFieldValue = exports.default = exports.clickForKeyboard = void 0;
7
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
8
+ var _keyboardConstants = require("../constants/keyboardConstants");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const preventPointerDown = e => e.preventDefault();
11
+ exports.preventPointerDown = preventPointerDown;
12
+ const identifyField = function () {
13
+ let eventTarget = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
14
+ let forms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15
+ const {
16
+ dataset: {
17
+ keyboard: inputName
18
+ }
19
+ } = eventTarget;
20
+ const fieldName = inputName.includes('-') ? inputName.split('-')[1] : inputName;
21
+ const fieldPrefix = inputName.includes('-') ? inputName.split('-')[0] : null;
22
+ const formsArray = Object.entries(forms);
23
+ // eslint-disable-next-line no-unused-vars
24
+ const [formName] = formsArray.find(_ref => {
25
+ let [_, {
26
+ registeredFields
27
+ }] = _ref;
28
+ return registeredFields ? Object.keys(registeredFields).includes(fieldName) : false;
29
+ }) || [_keyboardConstants.NO_FORM];
30
+ const eventHandlersKey = Object.keys(eventTarget).find(key => key.includes(_keyboardConstants.HANDLER_IDENTIFIER));
31
+ const {
32
+ onChange
33
+ } = eventTarget[eventHandlersKey] || {};
34
+ return {
35
+ fieldName,
36
+ fieldPrefix,
37
+ formName,
38
+ onChange
39
+ };
40
+ };
41
+ exports.identifyField = identifyField;
42
+ const getFieldValue = (currentIdentifiers, fieldSelector, state) => {
43
+ var _fieldSelector, _fieldSelector2, _fieldSelector3;
44
+ if (!(0, _isEmpty.default)(currentIdentifiers)) {
45
+ const {
46
+ fieldName,
47
+ fieldPrefix,
48
+ formName
49
+ } = currentIdentifiers || {};
50
+ switch (fieldPrefix) {
51
+ case 'areaCode':
52
+ case 'prefix':
53
+ return (_fieldSelector = fieldSelector(formName || '')(state, fieldName)) === null || _fieldSelector === void 0 ? void 0 : _fieldSelector.split('-')[0];
54
+ case 'phoneNumber':
55
+ case 'document':
56
+ return (_fieldSelector2 = fieldSelector(formName || '')(state, fieldName)) === null || _fieldSelector2 === void 0 ? void 0 : _fieldSelector2.split('-')[1];
57
+ case 'verificationCode':
58
+ return (_fieldSelector3 = fieldSelector(formName || '')(state, fieldName)) === null || _fieldSelector3 === void 0 ? void 0 : _fieldSelector3.split('-')[2];
59
+ default:
60
+ return fieldSelector(formName || '')(state, fieldName);
61
+ }
62
+ }
63
+ };
64
+ exports.getFieldValue = getFieldValue;
65
+ const getIsKeyboard = eventTarget => {
66
+ const {
67
+ dataset: {
68
+ skbtn,
69
+ skinstance
70
+ },
71
+ classList
72
+ } = eventTarget;
73
+ return skbtn || skinstance || [...classList].some(cssClass => cssClass.includes('hg-'));
74
+ };
75
+ exports.getIsKeyboard = getIsKeyboard;
76
+ const getIsInputForKeyboard = (nodeName, type) => nodeName === 'INPUT' && _keyboardConstants.KEYBOARD_ALLOWED_TYPES.includes(type) || nodeName === 'TEXTAREA';
77
+ exports.getIsInputForKeyboard = getIsInputForKeyboard;
78
+ const clickForKeyboard = (formList, setFieldIdentifiers, setShowKeyboard, showKeyboard) => _ref2 => {
79
+ let {
80
+ target: eventTarget
81
+ } = _ref2;
82
+ const {
83
+ nodeName,
84
+ type
85
+ } = eventTarget;
86
+ const isKeyboard = getIsKeyboard(eventTarget);
87
+ const isInputForKeyboard = getIsInputForKeyboard(nodeName, type);
88
+ if (isInputForKeyboard) {
89
+ const identifiers = identifyField(eventTarget, formList);
90
+ if (identifiers.fieldPrefix === 'autocomplete') {
91
+ window.addEventListener('pointerdown', preventPointerDown);
92
+ }
93
+ setFieldIdentifiers(identifiers);
94
+ if (!showKeyboard) {
95
+ setShowKeyboard(true);
96
+ }
97
+ } else if (!isInputForKeyboard && !isKeyboard) {
98
+ setShowKeyboard(false);
99
+ window.removeEventListener('pointerdown', preventPointerDown);
100
+ }
101
+ };
102
+ exports.clickForKeyboard = clickForKeyboard;
103
+ var _default = exports.default = {
104
+ identifyField,
105
+ getFieldValue,
106
+ getIsKeyboard,
107
+ getIsInputForKeyboard,
108
+ clickForKeyboard
109
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/energy-ui",
3
- "version": "3.46.0",
3
+ "version": "3.48.0",
4
4
  "description": "Widergy Web Components",
5
5
  "author": "widergy",
6
6
  "license": "MIT",
@@ -44,11 +44,13 @@
44
44
  "intro.js-react": "0.7.1",
45
45
  "numeral": "^2.0.6",
46
46
  "object-hash": "^3.0.0",
47
+ "react-credit-cards": "^0.7.0",
47
48
  "react-google-maps": ">=9.2.2",
48
49
  "react-google-recaptcha": "^3.1.0",
49
50
  "react-jss": "^8.6.1",
50
51
  "react-markdown": "^8.0.7",
51
52
  "react-perfect-scrollbar": "^1.5.3",
53
+ "react-simple-keyboard": "^3.8.28",
52
54
  "react-transition-group": "^4.2.2",
53
55
  "react-window": "^1.8.5",
54
56
  "rehype-raw": "^6.1.0",