@pingux/astro 2.32.0-alpha.15 → 2.32.0-alpha.16
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/lib/cjs/hooks/useField/index.d.ts +1 -0
- package/lib/cjs/hooks/useField/useField.d.ts +1686 -0
- package/lib/cjs/hooks/useField/useField.js +7 -16
- package/lib/cjs/hooks/useField/useField.test.d.ts +1 -0
- package/lib/cjs/hooks/useField/useField.test.js +6 -6
- package/lib/hooks/useField/useField.js +7 -16
- package/lib/hooks/useField/useField.test.js +6 -6
- package/package.json +1 -1
@@ -25,7 +25,7 @@ var _constants = require("../../components/Label/constants");
|
|
25
25
|
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
26
26
|
var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
|
27
27
|
var _ = require("..");
|
28
|
-
var _excluded = ["autocomplete", "autoComplete", "autoCorrect", "
|
28
|
+
var _excluded = ["autocomplete", "autoComplete", "autoCorrect", "className", "containerProps", "controlProps", "defaultValue", "hasAutoFocus", "hasNoStatusIndicator", "hintText", "id", "isDefaultSelected", "isDisabled", "isIndeterminate", "isReadOnly", "isRequired", "isRestrictiveMultivalues", "label", "labelMode", "labelProps", "maxLength", "name", "onBlur", "onChange", "onFocus", "placeholder", "role", "spellCheck", "status", "statusClasses", "type", "value", "wrapperProps"];
|
29
29
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
30
30
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
31
31
|
/**
|
@@ -33,24 +33,21 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
33
33
|
* @param {{}} props Props for the field
|
34
34
|
* @returns {{}} Prop objects to be spread into field components.
|
35
35
|
*/
|
36
|
-
|
37
|
-
|
36
|
+
|
37
|
+
// TODO: replace with LabelProps instead of ThemeUILabelProps
|
38
|
+
// once Label component is rewritten to ts
|
39
|
+
var useField = function useField(props) {
|
38
40
|
var autocomplete = props.autocomplete,
|
39
41
|
autoComplete = props.autoComplete,
|
40
42
|
autoCorrect = props.autoCorrect,
|
41
|
-
children = props.children,
|
42
43
|
className = props.className,
|
43
44
|
_props$containerProps = props.containerProps,
|
44
45
|
containerProps = _props$containerProps === void 0 ? {} : _props$containerProps,
|
45
46
|
_props$controlProps = props.controlProps,
|
46
47
|
controlProps = _props$controlProps === void 0 ? {} : _props$controlProps,
|
47
|
-
defaultText = props.defaultText,
|
48
48
|
defaultValue = props.defaultValue,
|
49
|
-
direction = props.direction,
|
50
|
-
disabledKeys = props.disabledKeys,
|
51
49
|
hasAutoFocus = props.hasAutoFocus,
|
52
50
|
hasNoStatusIndicator = props.hasNoStatusIndicator,
|
53
|
-
helperText = props.helperText,
|
54
51
|
hintText = props.hintText,
|
55
52
|
id = props.id,
|
56
53
|
isDefaultSelected = props.isDefaultSelected,
|
@@ -59,7 +56,6 @@ var useField = function useField() {
|
|
59
56
|
isReadOnly = props.isReadOnly,
|
60
57
|
isRequired = props.isRequired,
|
61
58
|
isRestrictiveMultivalues = props.isRestrictiveMultivalues,
|
62
|
-
isSelected = props.isSelected,
|
63
59
|
label = props.label,
|
64
60
|
labelMode = props.labelMode,
|
65
61
|
_props$labelProps = props.labelProps,
|
@@ -69,15 +65,9 @@ var useField = function useField() {
|
|
69
65
|
onBlur = props.onBlur,
|
70
66
|
_props$onChange = props.onChange,
|
71
67
|
onChange = _props$onChange === void 0 ? _noop["default"] : _props$onChange,
|
72
|
-
onClear = props.onClear,
|
73
68
|
onFocus = props.onFocus,
|
74
|
-
onFocusChange = props.onFocusChange,
|
75
|
-
onLoadMore = props.onLoadMore,
|
76
|
-
onOpenChange = props.onOpenChange,
|
77
|
-
onSelectionChange = props.onSelectionChange,
|
78
69
|
placeholder = props.placeholder,
|
79
70
|
role = props.role,
|
80
|
-
selectedKey = props.selectedKey,
|
81
71
|
spellCheck = props.spellCheck,
|
82
72
|
_props$status = props.status,
|
83
73
|
status = _props$status === void 0 ? _statuses["default"].DEFAULT : _props$status,
|
@@ -113,6 +103,7 @@ var useField = function useField() {
|
|
113
103
|
} else {
|
114
104
|
setHasValue(false);
|
115
105
|
}
|
106
|
+
|
116
107
|
// adding this function resolves the error brought up in UIP-5116
|
117
108
|
if (e.persist) {
|
118
109
|
e.persist();
|
@@ -152,7 +143,7 @@ var useField = function useField() {
|
|
152
143
|
isReadOnly: isReadOnly
|
153
144
|
}, "is-".concat(status), true), statusClasses), labelProps === null || labelProps === void 0 ? void 0 : labelProps.statusClasses)),
|
154
145
|
labelClasses = _useStatusClasses3.classNames;
|
155
|
-
var _getAriaAttributeProp = (0, _ariaAttributes.getAriaAttributeProps)(others),
|
146
|
+
var _getAriaAttributeProp = (0, _ariaAttributes.getAriaAttributeProps)((0, _omit["default"])(others, ['children', 'defaultText', 'direction', 'disabledKeys', 'helperText', 'isSelected', 'onClear', 'onFocusChange', 'onLoadMore', 'onOpenChange', 'onRemove', 'onSelectionChange', 'selectedKey'])),
|
156
147
|
ariaProps = _getAriaAttributeProp.ariaProps,
|
157
148
|
nonAriaProps = _getAriaAttributeProp.nonAriaProps;
|
158
149
|
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -63,11 +63,11 @@ var defaultProps = {
|
|
63
63
|
};
|
64
64
|
test('default useField', function () {
|
65
65
|
(0, _reactHooks.renderHook)(function () {
|
66
|
-
return (0, _useField["default"])();
|
66
|
+
return (0, _useField["default"])({});
|
67
67
|
});
|
68
68
|
});
|
69
69
|
test('should return props objects for field components', function () {
|
70
|
-
var _context, _context2;
|
70
|
+
var _defaultProps$contain, _context, _context2;
|
71
71
|
var _renderHook = (0, _reactHooks.renderHook)(function () {
|
72
72
|
return (0, _useField["default"])(defaultProps);
|
73
73
|
}),
|
@@ -79,7 +79,7 @@ test('should return props objects for field components', function () {
|
|
79
79
|
fieldLabelProps = _result$current.fieldLabelProps;
|
80
80
|
expect(fieldContainerProps).toEqual({
|
81
81
|
className: 'field-container has-value is-tested is-container',
|
82
|
-
id: defaultProps.containerProps.id,
|
82
|
+
id: (_defaultProps$contain = defaultProps.containerProps) === null || _defaultProps$contain === void 0 ? void 0 : _defaultProps$contain.id,
|
83
83
|
onBlur: expect.any(Function),
|
84
84
|
onFocus: expect.any(Function),
|
85
85
|
sx: expect.objectContaining({
|
@@ -154,7 +154,7 @@ test('should support autocomplete additionally', function () {
|
|
154
154
|
test('should return isFloatLabelActive class for container', function () {
|
155
155
|
var _renderHook3 = (0, _reactHooks.renderHook)(function (initialProps) {
|
156
156
|
return (0, _useField["default"])(_objectSpread(_objectSpread({}, initialProps), {}, {
|
157
|
-
placeholder:
|
157
|
+
placeholder: undefined
|
158
158
|
}));
|
159
159
|
}, {
|
160
160
|
initialProps: defaultProps
|
@@ -227,8 +227,8 @@ test('should return hasValue class for container when onChange updates internal
|
|
227
227
|
var numCalls = 0;
|
228
228
|
var _renderHook5 = (0, _reactHooks.renderHook)(function () {
|
229
229
|
return (0, _useField["default"])(_objectSpread(_objectSpread({}, defaultProps), {}, {
|
230
|
-
defaultValue:
|
231
|
-
placeholder:
|
230
|
+
defaultValue: undefined,
|
231
|
+
placeholder: undefined,
|
232
232
|
onChange: onChange,
|
233
233
|
value: ''
|
234
234
|
}));
|
@@ -9,7 +9,7 @@ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object
|
|
9
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
10
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["autocomplete", "autoComplete", "autoCorrect", "
|
12
|
+
var _excluded = ["autocomplete", "autoComplete", "autoCorrect", "className", "containerProps", "controlProps", "defaultValue", "hasAutoFocus", "hasNoStatusIndicator", "hintText", "id", "isDefaultSelected", "isDisabled", "isIndeterminate", "isReadOnly", "isRequired", "isRestrictiveMultivalues", "label", "labelMode", "labelProps", "maxLength", "name", "onBlur", "onChange", "onFocus", "placeholder", "role", "spellCheck", "status", "statusClasses", "type", "value", "wrapperProps"];
|
13
13
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
15
|
import { useEffect, useState } from 'react';
|
@@ -27,24 +27,21 @@ import { useStatusClasses } from '..';
|
|
27
27
|
* @param {{}} props Props for the field
|
28
28
|
* @returns {{}} Prop objects to be spread into field components.
|
29
29
|
*/
|
30
|
-
|
31
|
-
|
30
|
+
|
31
|
+
// TODO: replace with LabelProps instead of ThemeUILabelProps
|
32
|
+
// once Label component is rewritten to ts
|
33
|
+
var useField = function useField(props) {
|
32
34
|
var autocomplete = props.autocomplete,
|
33
35
|
autoComplete = props.autoComplete,
|
34
36
|
autoCorrect = props.autoCorrect,
|
35
|
-
children = props.children,
|
36
37
|
className = props.className,
|
37
38
|
_props$containerProps = props.containerProps,
|
38
39
|
containerProps = _props$containerProps === void 0 ? {} : _props$containerProps,
|
39
40
|
_props$controlProps = props.controlProps,
|
40
41
|
controlProps = _props$controlProps === void 0 ? {} : _props$controlProps,
|
41
|
-
defaultText = props.defaultText,
|
42
42
|
defaultValue = props.defaultValue,
|
43
|
-
direction = props.direction,
|
44
|
-
disabledKeys = props.disabledKeys,
|
45
43
|
hasAutoFocus = props.hasAutoFocus,
|
46
44
|
hasNoStatusIndicator = props.hasNoStatusIndicator,
|
47
|
-
helperText = props.helperText,
|
48
45
|
hintText = props.hintText,
|
49
46
|
id = props.id,
|
50
47
|
isDefaultSelected = props.isDefaultSelected,
|
@@ -53,7 +50,6 @@ var useField = function useField() {
|
|
53
50
|
isReadOnly = props.isReadOnly,
|
54
51
|
isRequired = props.isRequired,
|
55
52
|
isRestrictiveMultivalues = props.isRestrictiveMultivalues,
|
56
|
-
isSelected = props.isSelected,
|
57
53
|
label = props.label,
|
58
54
|
labelMode = props.labelMode,
|
59
55
|
_props$labelProps = props.labelProps,
|
@@ -63,15 +59,9 @@ var useField = function useField() {
|
|
63
59
|
onBlur = props.onBlur,
|
64
60
|
_props$onChange = props.onChange,
|
65
61
|
onChange = _props$onChange === void 0 ? noop : _props$onChange,
|
66
|
-
onClear = props.onClear,
|
67
62
|
onFocus = props.onFocus,
|
68
|
-
onFocusChange = props.onFocusChange,
|
69
|
-
onLoadMore = props.onLoadMore,
|
70
|
-
onOpenChange = props.onOpenChange,
|
71
|
-
onSelectionChange = props.onSelectionChange,
|
72
63
|
placeholder = props.placeholder,
|
73
64
|
role = props.role,
|
74
|
-
selectedKey = props.selectedKey,
|
75
65
|
spellCheck = props.spellCheck,
|
76
66
|
_props$status = props.status,
|
77
67
|
status = _props$status === void 0 ? statuses.DEFAULT : _props$status,
|
@@ -107,6 +97,7 @@ var useField = function useField() {
|
|
107
97
|
} else {
|
108
98
|
setHasValue(false);
|
109
99
|
}
|
100
|
+
|
110
101
|
// adding this function resolves the error brought up in UIP-5116
|
111
102
|
if (e.persist) {
|
112
103
|
e.persist();
|
@@ -146,7 +137,7 @@ var useField = function useField() {
|
|
146
137
|
isReadOnly: isReadOnly
|
147
138
|
}, "is-".concat(status), true), statusClasses), labelProps === null || labelProps === void 0 ? void 0 : labelProps.statusClasses)),
|
148
139
|
labelClasses = _useStatusClasses3.classNames;
|
149
|
-
var _getAriaAttributeProp = getAriaAttributeProps(others),
|
140
|
+
var _getAriaAttributeProp = getAriaAttributeProps(omit(others, ['children', 'defaultText', 'direction', 'disabledKeys', 'helperText', 'isSelected', 'onClear', 'onFocusChange', 'onLoadMore', 'onOpenChange', 'onRemove', 'onSelectionChange', 'selectedKey'])),
|
150
141
|
ariaProps = _getAriaAttributeProp.ariaProps,
|
151
142
|
nonAriaProps = _getAriaAttributeProp.nonAriaProps;
|
152
143
|
|
@@ -60,11 +60,11 @@ var defaultProps = {
|
|
60
60
|
};
|
61
61
|
test('default useField', function () {
|
62
62
|
renderHook(function () {
|
63
|
-
return useField();
|
63
|
+
return useField({});
|
64
64
|
});
|
65
65
|
});
|
66
66
|
test('should return props objects for field components', function () {
|
67
|
-
var _context, _context2;
|
67
|
+
var _defaultProps$contain, _context, _context2;
|
68
68
|
var _renderHook = renderHook(function () {
|
69
69
|
return useField(defaultProps);
|
70
70
|
}),
|
@@ -76,7 +76,7 @@ test('should return props objects for field components', function () {
|
|
76
76
|
fieldLabelProps = _result$current.fieldLabelProps;
|
77
77
|
expect(fieldContainerProps).toEqual({
|
78
78
|
className: 'field-container has-value is-tested is-container',
|
79
|
-
id: defaultProps.containerProps.id,
|
79
|
+
id: (_defaultProps$contain = defaultProps.containerProps) === null || _defaultProps$contain === void 0 ? void 0 : _defaultProps$contain.id,
|
80
80
|
onBlur: expect.any(Function),
|
81
81
|
onFocus: expect.any(Function),
|
82
82
|
sx: expect.objectContaining({
|
@@ -151,7 +151,7 @@ test('should support autocomplete additionally', function () {
|
|
151
151
|
test('should return isFloatLabelActive class for container', function () {
|
152
152
|
var _renderHook3 = renderHook(function (initialProps) {
|
153
153
|
return useField(_objectSpread(_objectSpread({}, initialProps), {}, {
|
154
|
-
placeholder:
|
154
|
+
placeholder: undefined
|
155
155
|
}));
|
156
156
|
}, {
|
157
157
|
initialProps: defaultProps
|
@@ -224,8 +224,8 @@ test('should return hasValue class for container when onChange updates internal
|
|
224
224
|
var numCalls = 0;
|
225
225
|
var _renderHook5 = renderHook(function () {
|
226
226
|
return useField(_objectSpread(_objectSpread({}, defaultProps), {}, {
|
227
|
-
defaultValue:
|
228
|
-
placeholder:
|
227
|
+
defaultValue: undefined,
|
228
|
+
placeholder: undefined,
|
229
229
|
onChange: onChange,
|
230
230
|
value: ''
|
231
231
|
}));
|