@pingux/astro 2.80.0 → 2.81.0-alpha.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/lib/cjs/components/TextField/TextField.d.ts +4 -0
- package/lib/cjs/components/TextField/TextField.js +5 -79
- package/lib/cjs/components/TextField/TextField.stories.d.ts +22 -0
- package/lib/cjs/components/TextField/TextField.stories.js +24 -0
- package/lib/cjs/components/TextField/TextField.test.d.ts +1 -0
- package/lib/cjs/components/TextField/TextField.test.js +11 -9
- package/lib/cjs/components/TextField/index.d.ts +1 -0
- package/lib/cjs/hooks/useField/useField.d.ts +2 -1
- package/lib/cjs/types/arrayField.d.ts +1 -1
- package/lib/cjs/types/copyText.d.ts +2 -0
- package/lib/cjs/types/helpHint.d.ts +1 -0
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +14 -3
- package/lib/cjs/types/textField.d.ts +65 -0
- package/lib/cjs/types/textField.js +6 -0
- package/lib/components/TextField/TextField.js +7 -81
- package/lib/components/TextField/TextField.stories.js +24 -0
- package/lib/components/TextField/TextField.test.js +11 -9
- package/lib/types/index.js +1 -0
- package/lib/types/textField.js +1 -0
- package/package.json +1 -1
@@ -18,14 +18,10 @@ exports["default"] = void 0;
|
|
18
18
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
19
19
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
20
20
|
var _react = _interopRequireWildcard(require("react"));
|
21
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
22
21
|
var _uuid = require("uuid");
|
23
22
|
var _ = require("../..");
|
24
23
|
var _hooks = require("../../hooks");
|
25
|
-
var _useColumnStyles = _interopRequireDefault(require("../../hooks/useColumnStyles"));
|
26
24
|
var _pendoID = require("../../utils/devUtils/constants/pendoID");
|
27
|
-
var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
|
28
|
-
var _fieldAttributes = require("../../utils/docUtils/fieldAttributes");
|
29
25
|
var _statusProp = require("../../utils/docUtils/statusProp");
|
30
26
|
var _react2 = require("@emotion/react");
|
31
27
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
@@ -43,19 +39,15 @@ var TextField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
43
39
|
fieldControlInputProps = _useField.fieldControlInputProps,
|
44
40
|
fieldControlWrapperProps = _useField.fieldControlWrapperProps,
|
45
41
|
fieldLabelProps = _useField.fieldLabelProps;
|
46
|
-
var inputRef = (0,
|
47
|
-
var labelRef = (0, _react.useRef)();
|
42
|
+
var inputRef = (0, _hooks.useLocalOrForwardRef)(ref);
|
43
|
+
var labelRef = (0, _react.useRef)(null);
|
48
44
|
(0, _hooks.usePropWarning)(props, 'disabled', 'isDisabled');
|
49
|
-
/* istanbul ignore next */
|
50
|
-
(0, _react.useImperativeHandle)(ref, function () {
|
51
|
-
return inputRef.current;
|
52
|
-
});
|
53
45
|
var _useLabelHeight = (0, _hooks.useLabelHeight)({
|
54
46
|
labelRef: labelRef,
|
55
47
|
inputRef: inputRef
|
56
48
|
}),
|
57
49
|
isLabelHigher = _useLabelHeight.isLabelHigher;
|
58
|
-
var columnStyleProps = (0,
|
50
|
+
var columnStyleProps = (0, _hooks.useColumnStyles)({
|
59
51
|
labelMode: props.labelMode
|
60
52
|
});
|
61
53
|
var helperTextId = (0, _uuid.v4)();
|
@@ -65,9 +57,9 @@ var TextField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
65
57
|
sx: _objectSpread(_objectSpread({}, columnStyleProps === null || columnStyleProps === void 0 ? void 0 : columnStyleProps.sx), fieldContainerProps === null || fieldContainerProps === void 0 ? void 0 : fieldContainerProps.sx)
|
66
58
|
}), (0, _react2.jsx)(_.Label, (0, _extends2["default"])({}, fieldLabelProps, {
|
67
59
|
ref: labelRef,
|
68
|
-
sx: isLabelHigher
|
60
|
+
sx: isLabelHigher ? {
|
69
61
|
gridRow: '1/5'
|
70
|
-
},
|
62
|
+
} : {},
|
71
63
|
helpHintProps: helpHintProps
|
72
64
|
})), (0, _react2.jsx)(_.Box, (0, _extends2["default"])({
|
73
65
|
variant: "forms.input.fieldControlWrapper"
|
@@ -81,72 +73,6 @@ var TextField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
81
73
|
id: helperTextId
|
82
74
|
}, helperText));
|
83
75
|
});
|
84
|
-
TextField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
85
|
-
/** The rendered label for the field. */
|
86
|
-
label: _propTypes["default"].node,
|
87
|
-
/** A string designating whether or not the label is a float label. */
|
88
|
-
labelMode: _propTypes["default"].string,
|
89
|
-
/** Text rendered below the input. */
|
90
|
-
helperText: _propTypes["default"].node,
|
91
|
-
/** The unique identifier for the input element. */
|
92
|
-
id: _propTypes["default"].string,
|
93
|
-
/** The name for the input element. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). */
|
94
|
-
name: _propTypes["default"].string,
|
95
|
-
/**
|
96
|
-
* Callback fired when the value is changed on the input element.
|
97
|
-
*
|
98
|
-
* @param {object} event The event source of the callback.
|
99
|
-
* You can pull out the new value by accessing `event.target.value` (string).
|
100
|
-
*/
|
101
|
-
onChange: _propTypes["default"].func,
|
102
|
-
/** The value for the input element (controlled). */
|
103
|
-
value: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),
|
104
|
-
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
105
|
-
autoComplete: _propTypes["default"].string,
|
106
|
-
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
107
|
-
autocomplete: _propTypes["default"].string,
|
108
|
-
/** A list of class names to apply to the input element. */
|
109
|
-
className: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].arrayOf(_propTypes["default"].string)]),
|
110
|
-
/** The default value for the input element. */
|
111
|
-
defaultValue: _propTypes["default"].string,
|
112
|
-
/** Whether the input element is automatically focused when loaded onto the page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautofocus). */
|
113
|
-
hasAutoFocus: _propTypes["default"].bool,
|
114
|
-
/** If present this prop will cause a help hint to render in the label of the field. */
|
115
|
-
hintText: _propTypes["default"].string,
|
116
|
-
/** Whether the field has a status indicator. */
|
117
|
-
hasNoStatusIndicator: _propTypes["default"].bool,
|
118
|
-
/** Props object that is spread directly into the helphint element. */
|
119
|
-
helpHintProps: _propTypes["default"].shape({}),
|
120
|
-
/** Whether the field is disabled. */
|
121
|
-
isDisabled: _propTypes["default"].bool,
|
122
|
-
/** Whether the input can be selected, but not changed by the user. */
|
123
|
-
isReadOnly: _propTypes["default"].bool,
|
124
|
-
/** Whether the field is required. */
|
125
|
-
isRequired: _propTypes["default"].bool,
|
126
|
-
/** Add max Length to input value */
|
127
|
-
maxLength: _propTypes["default"].number,
|
128
|
-
/**
|
129
|
-
* Callback fired when focus is lost on the input element.
|
130
|
-
*/
|
131
|
-
onBlur: _propTypes["default"].func,
|
132
|
-
/**
|
133
|
-
* Callback fired when focus is lost on the input element.
|
134
|
-
*/
|
135
|
-
onFocus: _propTypes["default"].func,
|
136
|
-
/** The placeholder text to display in the input element. */
|
137
|
-
placeholder: _propTypes["default"].string,
|
138
|
-
/** Provides a way to insert markup in specified places. */
|
139
|
-
slots: _propTypes["default"].shape({
|
140
|
-
/** The given node will be inserted before the input. */
|
141
|
-
beforeInput: _propTypes["default"].node,
|
142
|
-
/** The given node will be inserted into the field container. */
|
143
|
-
inContainer: _propTypes["default"].node
|
144
|
-
}),
|
145
|
-
/** Determines the type of input to use. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype). */
|
146
|
-
type: _propTypes["default"].string,
|
147
|
-
/** Props object that is spread directly into the input wrapper element. */
|
148
|
-
wrapperProps: _propTypes["default"].shape({})
|
149
|
-
}, _statusProp.statusPropTypes), _ariaAttributes.ariaAttributesBasePropTypes), _fieldAttributes.inputFieldAttributesBasePropTypes);
|
150
76
|
TextField.defaultProps = _objectSpread({
|
151
77
|
hasAutoFocus: false,
|
152
78
|
isDisabled: false,
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { StoryFn } from '@storybook/react';
|
2
|
+
import { TextFieldProps } from '../../types';
|
3
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
|
4
|
+
export default _default;
|
5
|
+
export declare const Default: StoryFn<TextFieldProps>;
|
6
|
+
export declare const SmallVariant: StoryFn<TextFieldProps>;
|
7
|
+
export declare const FloatLabel: StoryFn<TextFieldProps>;
|
8
|
+
export declare const LeftLabel: StoryFn<TextFieldProps>;
|
9
|
+
export declare const Controlled: StoryFn<TextFieldProps>;
|
10
|
+
export declare const Password: StoryFn<TextFieldProps>;
|
11
|
+
export declare const Disabled: StoryFn<TextFieldProps>;
|
12
|
+
export declare const ReadOnly: StoryFn<TextFieldProps>;
|
13
|
+
export declare const Required: StoryFn<TextFieldProps>;
|
14
|
+
export declare const DynamicRequired: StoryFn<TextFieldProps>;
|
15
|
+
export declare const Error: StoryFn<TextFieldProps>;
|
16
|
+
export declare const Success: StoryFn<TextFieldProps>;
|
17
|
+
export declare const Warning: StoryFn<TextFieldProps>;
|
18
|
+
export declare const WithHelpHint: StoryFn<TextFieldProps>;
|
19
|
+
export declare const WithHelpHintCustomWidth: StoryFn<TextFieldProps>;
|
20
|
+
export declare const WithoutStatusIndicator: StoryFn<TextFieldProps>;
|
21
|
+
export declare const MaxLength: StoryFn<TextFieldProps>;
|
22
|
+
export declare const WithSlots: StoryFn<TextFieldProps>;
|
@@ -104,7 +104,19 @@ var FloatLabel = function FloatLabel() {
|
|
104
104
|
labelMode: "float"
|
105
105
|
});
|
106
106
|
};
|
107
|
+
|
108
|
+
// Added to bypass color contrast issue
|
107
109
|
exports.FloatLabel = FloatLabel;
|
110
|
+
FloatLabel.parameters = {
|
111
|
+
a11y: {
|
112
|
+
config: {
|
113
|
+
rules: [{
|
114
|
+
id: 'color-contrast',
|
115
|
+
enabled: false
|
116
|
+
}]
|
117
|
+
}
|
118
|
+
}
|
119
|
+
};
|
108
120
|
var LeftLabel = function LeftLabel() {
|
109
121
|
return (0, _react2.jsx)(_index.Box, {
|
110
122
|
gap: "xl",
|
@@ -236,7 +248,19 @@ var WithHelpHintCustomWidth = function WithHelpHintCustomWidth() {
|
|
236
248
|
}
|
237
249
|
});
|
238
250
|
};
|
251
|
+
|
252
|
+
// Added to bypass color contrast issue
|
239
253
|
exports.WithHelpHintCustomWidth = WithHelpHintCustomWidth;
|
254
|
+
WithHelpHintCustomWidth.parameters = {
|
255
|
+
a11y: {
|
256
|
+
config: {
|
257
|
+
rules: [{
|
258
|
+
id: 'color-contrast',
|
259
|
+
enabled: false
|
260
|
+
}]
|
261
|
+
}
|
262
|
+
}
|
263
|
+
};
|
240
264
|
var WithoutStatusIndicator = function WithoutStatusIndicator() {
|
241
265
|
return (0, _react2.jsx)(_index.TextField, {
|
242
266
|
label: "Example Label",
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -58,16 +58,18 @@ test('text field with helper text', function () {
|
|
58
58
|
});
|
59
59
|
test('label will receive gridRow attribute if it will be higher than input', function () {
|
60
60
|
var originalOffsetHeight = (0, _getOwnPropertyDescriptor["default"])(HTMLElement.prototype, 'offsetHeight');
|
61
|
-
(
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
if (originalOffsetHeight) {
|
62
|
+
(0, _defineProperties["default"])(window.HTMLElement.prototype, {
|
63
|
+
offsetHeight: {
|
64
|
+
get: function get() {
|
65
|
+
return this.tagName === 'LABEL' ? 500 : 100;
|
66
|
+
}
|
65
67
|
}
|
66
|
-
}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
});
|
69
|
+
getComponent();
|
70
|
+
expect(_react2.screen.getByText(defaultProps.label)).toHaveStyle('grid-row: 1/5');
|
71
|
+
(0, _defineProperty["default"])(HTMLElement.prototype, 'offsetHeight', originalOffsetHeight);
|
72
|
+
}
|
71
73
|
});
|
72
74
|
test('form wrapper will have default max label column width when no custom width set', function () {
|
73
75
|
var labelMode = 'left';
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './TextField';
|
@@ -12,7 +12,7 @@ interface WrapperProps extends BoxProps {
|
|
12
12
|
[className: string]: boolean;
|
13
13
|
};
|
14
14
|
}
|
15
|
-
interface ContainerProps extends WrapperProps {
|
15
|
+
export interface ContainerProps extends WrapperProps {
|
16
16
|
isFloatLabelActive?: boolean;
|
17
17
|
'data-testid'?: string;
|
18
18
|
}
|
@@ -44,6 +44,7 @@ export interface ControlProps extends React.HTMLAttributes<Element> {
|
|
44
44
|
};
|
45
45
|
hasAutoFocus?: boolean;
|
46
46
|
isDefaultSelected?: boolean;
|
47
|
+
variant?: string;
|
47
48
|
}
|
48
49
|
export interface UseFieldProps<T> {
|
49
50
|
autocomplete?: string;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { ThemeUICSSObject } from 'theme-ui';
|
3
3
|
import { LabelProps, Status, ValidPositiveInteger } from '.';
|
4
|
-
type RenderFieldFunction = (id: string, fieldValue: string, onFieldValueChange: (e: React.ChangeEvent
|
4
|
+
type RenderFieldFunction = (id: string, fieldValue: string, onFieldValueChange: (e: React.ChangeEvent, fieldId: string) => void, onFieldDelete: (fieldId: string) => void, isDisabled: boolean, otherFieldProps?: Record<string, string>) => React.ReactNode;
|
5
5
|
export interface FieldValue {
|
6
6
|
id: string;
|
7
7
|
value?: string;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { RefObject } from 'react';
|
2
|
+
import { ThemeUIStyleObject } from 'theme-ui';
|
2
3
|
import { TestingAttributes } from './shared/test';
|
3
4
|
import { IconProps } from './icon';
|
4
5
|
import { IconButtonProps } from './iconButton';
|
@@ -24,4 +25,5 @@ export interface CopyTextProps extends HoverProps, TestingAttributes {
|
|
24
25
|
export interface CopyButtonProps {
|
25
26
|
iconProps?: IconProps;
|
26
27
|
onPress?: () => void;
|
28
|
+
sx?: ThemeUIStyleObject;
|
27
29
|
}
|
package/lib/cjs/types/index.d.ts
CHANGED
package/lib/cjs/types/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _context, _context2, _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10, _context11, _context12, _context13, _context14, _context15, _context16, _context17, _context18, _context19, _context20, _context21, _context22, _context23, _context24, _context25, _context26, _context27, _context28, _context29, _context30, _context31, _context32, _context33, _context34, _context35, _context36, _context37, _context38, _context39, _context40, _context41, _context42, _context43, _context44, _context45, _context46, _context47, _context48, _context49;
|
3
|
+
var _context, _context2, _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10, _context11, _context12, _context13, _context14, _context15, _context16, _context17, _context18, _context19, _context20, _context21, _context22, _context23, _context24, _context25, _context26, _context27, _context28, _context29, _context30, _context31, _context32, _context33, _context34, _context35, _context36, _context37, _context38, _context39, _context40, _context41, _context42, _context43, _context44, _context45, _context46, _context47, _context48, _context49, _context50;
|
4
4
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
5
5
|
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
6
6
|
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
@@ -524,8 +524,19 @@ _forEachInstanceProperty(_context47 = _Object$keys(_text)).call(_context47, func
|
|
524
524
|
}
|
525
525
|
});
|
526
526
|
});
|
527
|
+
var _textField = require("./textField");
|
528
|
+
_forEachInstanceProperty(_context48 = _Object$keys(_textField)).call(_context48, function (key) {
|
529
|
+
if (key === "default" || key === "__esModule") return;
|
530
|
+
if (key in exports && exports[key] === _textField[key]) return;
|
531
|
+
_Object$defineProperty(exports, key, {
|
532
|
+
enumerable: true,
|
533
|
+
get: function get() {
|
534
|
+
return _textField[key];
|
535
|
+
}
|
536
|
+
});
|
537
|
+
});
|
527
538
|
var _timefield = require("./timefield");
|
528
|
-
_forEachInstanceProperty(
|
539
|
+
_forEachInstanceProperty(_context49 = _Object$keys(_timefield)).call(_context49, function (key) {
|
529
540
|
if (key === "default" || key === "__esModule") return;
|
530
541
|
if (key in exports && exports[key] === _timefield[key]) return;
|
531
542
|
_Object$defineProperty(exports, key, {
|
@@ -536,7 +547,7 @@ _forEachInstanceProperty(_context48 = _Object$keys(_timefield)).call(_context48,
|
|
536
547
|
});
|
537
548
|
});
|
538
549
|
var _tooltipTrigger = require("./tooltipTrigger");
|
539
|
-
_forEachInstanceProperty(
|
550
|
+
_forEachInstanceProperty(_context50 = _Object$keys(_tooltipTrigger)).call(_context50, function (key) {
|
540
551
|
if (key === "default" || key === "__esModule") return;
|
541
552
|
if (key in exports && exports[key] === _tooltipTrigger[key]) return;
|
542
553
|
_Object$defineProperty(exports, key, {
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { ThemeUICSSObject } from 'theme-ui';
|
3
|
+
import { ContainerProps, ControlProps } from '../hooks/useField/useField';
|
4
|
+
import { HelpHintProps } from './helpHint';
|
5
|
+
import { Status } from './item';
|
6
|
+
import { LabelModeProps } from './label';
|
7
|
+
import { AriaRole, StyleProps, ValidPositiveInteger } from './shared';
|
8
|
+
export interface TextFieldProps extends StyleProps {
|
9
|
+
helperText?: string;
|
10
|
+
/** The rendered label for the field. */
|
11
|
+
label?: React.ReactNode;
|
12
|
+
/** A string designating whether or not the label is a float label. */
|
13
|
+
labelMode?: LabelModeProps;
|
14
|
+
/** The unique identifier for the input element. */
|
15
|
+
id?: string;
|
16
|
+
/** The name for the input element. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). */
|
17
|
+
name?: string;
|
18
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
19
|
+
autoComplete?: string;
|
20
|
+
/** The default value for the input element. */
|
21
|
+
defaultValue?: string;
|
22
|
+
/** Whether the input element is automatically focused when loaded onto the page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautofocus). */
|
23
|
+
hasAutoFocus?: boolean;
|
24
|
+
/** If present this prop will cause a help hint to render in the label of the field. */
|
25
|
+
hintText?: string;
|
26
|
+
/** Whether the field has a status indicator. */
|
27
|
+
hasNoStatusIndicator?: boolean;
|
28
|
+
helpHintProps?: HelpHintProps;
|
29
|
+
/** Whether the field is disabled. */
|
30
|
+
isDisabled?: boolean;
|
31
|
+
/** Whether the input can be selected; but not changed by the user. */
|
32
|
+
isReadOnly?: boolean;
|
33
|
+
/** Whether the field is required. */
|
34
|
+
isRequired?: boolean;
|
35
|
+
onChange?: (e: React.ChangeEvent) => void;
|
36
|
+
/**
|
37
|
+
* Callback fired when focus is lost on the input element.
|
38
|
+
*/
|
39
|
+
onBlur?: () => void;
|
40
|
+
/**
|
41
|
+
* Callback fired when focus is lost on the input element.
|
42
|
+
*/
|
43
|
+
onFocus?: () => void;
|
44
|
+
/** The placeholder text to display in the input element. */
|
45
|
+
placeholder?: string;
|
46
|
+
/** Provides a way to insert markup in specified places. */
|
47
|
+
slots?: {
|
48
|
+
/** The given node will be inserted before the input. */
|
49
|
+
beforeInput?: React.ReactNode;
|
50
|
+
/** The given node will be inserted into the field container. */
|
51
|
+
inContainer?: React.ReactNode;
|
52
|
+
};
|
53
|
+
/** Determines the type of input to use. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype). */
|
54
|
+
type?: string;
|
55
|
+
/** Props object that is spread directly into the input wrapper element. */
|
56
|
+
wrapperProps?: Record<string, unknown>;
|
57
|
+
status?: Status;
|
58
|
+
variant?: string;
|
59
|
+
controlProps?: ControlProps;
|
60
|
+
containerProps?: ContainerProps;
|
61
|
+
value?: string;
|
62
|
+
maxLength?: ValidPositiveInteger;
|
63
|
+
role?: AriaRole;
|
64
|
+
sx?: ThemeUICSSObject;
|
65
|
+
}
|
@@ -10,16 +10,12 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
11
|
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; }
|
12
12
|
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; }
|
13
|
-
import React, { forwardRef,
|
14
|
-
import PropTypes from 'prop-types';
|
13
|
+
import React, { forwardRef, useRef } from 'react';
|
15
14
|
import { v4 as uuid } from 'uuid';
|
16
15
|
import { Box, FieldHelperText, Input, Label } from '../..';
|
17
|
-
import { useField, useLabelHeight, usePropWarning } from '../../hooks';
|
18
|
-
import useColumnStyles from '../../hooks/useColumnStyles';
|
16
|
+
import { useColumnStyles, useField, useLabelHeight, useLocalOrForwardRef, usePropWarning } from '../../hooks';
|
19
17
|
import { getPendoID } from '../../utils/devUtils/constants/pendoID';
|
20
|
-
import {
|
21
|
-
import { inputFieldAttributesBasePropTypes } from '../../utils/docUtils/fieldAttributes';
|
22
|
-
import { statusDefaultProp, statusPropTypes } from '../../utils/docUtils/statusProp';
|
18
|
+
import { statusDefaultProp } from '../../utils/docUtils/statusProp';
|
23
19
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
24
20
|
var displayName = 'TextField';
|
25
21
|
var TextField = /*#__PURE__*/forwardRef(function (props, ref) {
|
@@ -32,13 +28,9 @@ var TextField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
32
28
|
fieldControlInputProps = _useField.fieldControlInputProps,
|
33
29
|
fieldControlWrapperProps = _useField.fieldControlWrapperProps,
|
34
30
|
fieldLabelProps = _useField.fieldLabelProps;
|
35
|
-
var inputRef =
|
36
|
-
var labelRef = useRef();
|
31
|
+
var inputRef = useLocalOrForwardRef(ref);
|
32
|
+
var labelRef = useRef(null);
|
37
33
|
usePropWarning(props, 'disabled', 'isDisabled');
|
38
|
-
/* istanbul ignore next */
|
39
|
-
useImperativeHandle(ref, function () {
|
40
|
-
return inputRef.current;
|
41
|
-
});
|
42
34
|
var _useLabelHeight = useLabelHeight({
|
43
35
|
labelRef: labelRef,
|
44
36
|
inputRef: inputRef
|
@@ -54,9 +46,9 @@ var TextField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
54
46
|
sx: _objectSpread(_objectSpread({}, columnStyleProps === null || columnStyleProps === void 0 ? void 0 : columnStyleProps.sx), fieldContainerProps === null || fieldContainerProps === void 0 ? void 0 : fieldContainerProps.sx)
|
55
47
|
}), ___EmotionJSX(Label, _extends({}, fieldLabelProps, {
|
56
48
|
ref: labelRef,
|
57
|
-
sx: isLabelHigher
|
49
|
+
sx: isLabelHigher ? {
|
58
50
|
gridRow: '1/5'
|
59
|
-
},
|
51
|
+
} : {},
|
60
52
|
helpHintProps: helpHintProps
|
61
53
|
})), ___EmotionJSX(Box, _extends({
|
62
54
|
variant: "forms.input.fieldControlWrapper"
|
@@ -70,72 +62,6 @@ var TextField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
70
62
|
id: helperTextId
|
71
63
|
}, helperText));
|
72
64
|
});
|
73
|
-
TextField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
74
|
-
/** The rendered label for the field. */
|
75
|
-
label: PropTypes.node,
|
76
|
-
/** A string designating whether or not the label is a float label. */
|
77
|
-
labelMode: PropTypes.string,
|
78
|
-
/** Text rendered below the input. */
|
79
|
-
helperText: PropTypes.node,
|
80
|
-
/** The unique identifier for the input element. */
|
81
|
-
id: PropTypes.string,
|
82
|
-
/** The name for the input element. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). */
|
83
|
-
name: PropTypes.string,
|
84
|
-
/**
|
85
|
-
* Callback fired when the value is changed on the input element.
|
86
|
-
*
|
87
|
-
* @param {object} event The event source of the callback.
|
88
|
-
* You can pull out the new value by accessing `event.target.value` (string).
|
89
|
-
*/
|
90
|
-
onChange: PropTypes.func,
|
91
|
-
/** The value for the input element (controlled). */
|
92
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
93
|
-
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
94
|
-
autoComplete: PropTypes.string,
|
95
|
-
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
96
|
-
autocomplete: PropTypes.string,
|
97
|
-
/** A list of class names to apply to the input element. */
|
98
|
-
className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
99
|
-
/** The default value for the input element. */
|
100
|
-
defaultValue: PropTypes.string,
|
101
|
-
/** Whether the input element is automatically focused when loaded onto the page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautofocus). */
|
102
|
-
hasAutoFocus: PropTypes.bool,
|
103
|
-
/** If present this prop will cause a help hint to render in the label of the field. */
|
104
|
-
hintText: PropTypes.string,
|
105
|
-
/** Whether the field has a status indicator. */
|
106
|
-
hasNoStatusIndicator: PropTypes.bool,
|
107
|
-
/** Props object that is spread directly into the helphint element. */
|
108
|
-
helpHintProps: PropTypes.shape({}),
|
109
|
-
/** Whether the field is disabled. */
|
110
|
-
isDisabled: PropTypes.bool,
|
111
|
-
/** Whether the input can be selected, but not changed by the user. */
|
112
|
-
isReadOnly: PropTypes.bool,
|
113
|
-
/** Whether the field is required. */
|
114
|
-
isRequired: PropTypes.bool,
|
115
|
-
/** Add max Length to input value */
|
116
|
-
maxLength: PropTypes.number,
|
117
|
-
/**
|
118
|
-
* Callback fired when focus is lost on the input element.
|
119
|
-
*/
|
120
|
-
onBlur: PropTypes.func,
|
121
|
-
/**
|
122
|
-
* Callback fired when focus is lost on the input element.
|
123
|
-
*/
|
124
|
-
onFocus: PropTypes.func,
|
125
|
-
/** The placeholder text to display in the input element. */
|
126
|
-
placeholder: PropTypes.string,
|
127
|
-
/** Provides a way to insert markup in specified places. */
|
128
|
-
slots: PropTypes.shape({
|
129
|
-
/** The given node will be inserted before the input. */
|
130
|
-
beforeInput: PropTypes.node,
|
131
|
-
/** The given node will be inserted into the field container. */
|
132
|
-
inContainer: PropTypes.node
|
133
|
-
}),
|
134
|
-
/** Determines the type of input to use. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype). */
|
135
|
-
type: PropTypes.string,
|
136
|
-
/** Props object that is spread directly into the input wrapper element. */
|
137
|
-
wrapperProps: PropTypes.shape({})
|
138
|
-
}, statusPropTypes), ariaAttributesBasePropTypes), inputFieldAttributesBasePropTypes);
|
139
65
|
TextField.defaultProps = _objectSpread({
|
140
66
|
hasAutoFocus: false,
|
141
67
|
isDisabled: false,
|
@@ -90,6 +90,18 @@ export var FloatLabel = function FloatLabel() {
|
|
90
90
|
labelMode: "float"
|
91
91
|
});
|
92
92
|
};
|
93
|
+
|
94
|
+
// Added to bypass color contrast issue
|
95
|
+
FloatLabel.parameters = {
|
96
|
+
a11y: {
|
97
|
+
config: {
|
98
|
+
rules: [{
|
99
|
+
id: 'color-contrast',
|
100
|
+
enabled: false
|
101
|
+
}]
|
102
|
+
}
|
103
|
+
}
|
104
|
+
};
|
93
105
|
export var LeftLabel = function LeftLabel() {
|
94
106
|
return ___EmotionJSX(Box, {
|
95
107
|
gap: "xl",
|
@@ -210,6 +222,18 @@ export var WithHelpHintCustomWidth = function WithHelpHintCustomWidth() {
|
|
210
222
|
}
|
211
223
|
});
|
212
224
|
};
|
225
|
+
|
226
|
+
// Added to bypass color contrast issue
|
227
|
+
WithHelpHintCustomWidth.parameters = {
|
228
|
+
a11y: {
|
229
|
+
config: {
|
230
|
+
rules: [{
|
231
|
+
id: 'color-contrast',
|
232
|
+
enabled: false
|
233
|
+
}]
|
234
|
+
}
|
235
|
+
}
|
236
|
+
};
|
213
237
|
export var WithoutStatusIndicator = function WithoutStatusIndicator() {
|
214
238
|
return ___EmotionJSX(TextField, {
|
215
239
|
label: "Example Label",
|
@@ -55,16 +55,18 @@ test('text field with helper text', function () {
|
|
55
55
|
});
|
56
56
|
test('label will receive gridRow attribute if it will be higher than input', function () {
|
57
57
|
var originalOffsetHeight = _Object$getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetHeight');
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
if (originalOffsetHeight) {
|
59
|
+
_Object$defineProperties(window.HTMLElement.prototype, {
|
60
|
+
offsetHeight: {
|
61
|
+
get: function get() {
|
62
|
+
return this.tagName === 'LABEL' ? 500 : 100;
|
63
|
+
}
|
62
64
|
}
|
63
|
-
}
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
});
|
66
|
+
getComponent();
|
67
|
+
expect(screen.getByText(defaultProps.label)).toHaveStyle('grid-row: 1/5');
|
68
|
+
_Object$defineProperty(HTMLElement.prototype, 'offsetHeight', originalOffsetHeight);
|
69
|
+
}
|
68
70
|
});
|
69
71
|
test('form wrapper will have default max label column width when no custom width set', function () {
|
70
72
|
var labelMode = 'left';
|
package/lib/types/index.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|