1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.TextArea = exports.TextAreaBase = exports.TextAreResizeOrientation = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const React = tslib_1.__importStar(require("react"));
|
6 | const form_control_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/FormControl/form-control"));
|
7 | const c_form_control_textarea_Height_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/c_form_control_textarea_Height'));
|
8 | const react_styles_1 = require("@patternfly/react-styles");
|
9 | const helpers_1 = require("../../helpers");
|
10 | var TextAreResizeOrientation;
|
11 | (function (TextAreResizeOrientation) {
|
12 | TextAreResizeOrientation["horizontal"] = "horizontal";
|
13 | TextAreResizeOrientation["vertical"] = "vertical";
|
14 | TextAreResizeOrientation["both"] = "both";
|
15 | })(TextAreResizeOrientation = exports.TextAreResizeOrientation || (exports.TextAreResizeOrientation = {}));
|
16 | class TextAreaBase extends React.Component {
|
17 | constructor(props) {
|
18 | super(props);
|
19 | this.handleChange = (event) => {
|
20 |
|
21 | const field = event.currentTarget;
|
22 | if (this.props.autoResize && helpers_1.canUseDOM) {
|
23 | field.style.setProperty(c_form_control_textarea_Height_1.default.name, 'inherit');
|
24 | const computed = window.getComputedStyle(field);
|
25 |
|
26 | const height = parseInt(computed.getPropertyValue('border-top-width')) +
|
27 | parseInt(computed.getPropertyValue('padding-top')) +
|
28 | field.scrollHeight +
|
29 | parseInt(computed.getPropertyValue('padding-bottom')) +
|
30 | parseInt(computed.getPropertyValue('border-bottom-width'));
|
31 | field.style.setProperty(c_form_control_textarea_Height_1.default.name, `${height}px`);
|
32 | }
|
33 | if (this.props.onChange) {
|
34 | this.props.onChange(field.value, event);
|
35 | }
|
36 | };
|
37 | if (!props.id && !props['aria-label']) {
|
38 |
|
39 | console.error('TextArea: TextArea requires either an id or aria-label to be specified');
|
40 | }
|
41 | }
|
42 | render() {
|
43 | const _a = this.props, { className, value, validated, isRequired, isDisabled, isIconSprite, isReadOnly, resizeOrientation, innerRef, readOnly, disabled,
|
44 |
|
45 | autoResize, onChange } = _a,
|
46 |
|
47 | props = tslib_1.__rest(_a, ["className", "value", "validated", "isRequired", "isDisabled", "isIconSprite", "isReadOnly", "resizeOrientation", "innerRef", "readOnly", "disabled", "autoResize", "onChange"]);
|
48 | const orientation = `resize${helpers_1.capitalize(resizeOrientation)}`;
|
49 | return (React.createElement("textarea", Object.assign({ className: react_styles_1.css(form_control_1.default.formControl, isIconSprite && form_control_1.default.modifiers.iconSprite, className, resizeOrientation !== TextAreResizeOrientation.both && form_control_1.default.modifiers[orientation], validated === helpers_1.ValidatedOptions.success && form_control_1.default.modifiers.success, validated === helpers_1.ValidatedOptions.warning && form_control_1.default.modifiers.warning), onChange: this.handleChange }, (typeof this.props.defaultValue !== 'string' && { value }), { "aria-invalid": validated === helpers_1.ValidatedOptions.error, required: isRequired, disabled: isDisabled || disabled, readOnly: isReadOnly || readOnly, ref: innerRef }, props)));
|
50 | }
|
51 | }
|
52 | exports.TextAreaBase = TextAreaBase;
|
53 | TextAreaBase.displayName = 'TextArea';
|
54 | TextAreaBase.defaultProps = {
|
55 | innerRef: React.createRef(),
|
56 | className: '',
|
57 | isRequired: false,
|
58 | isDisabled: false,
|
59 | isIconSprite: false,
|
60 | validated: 'default',
|
61 | resizeOrientation: 'both',
|
62 | 'aria-label': null
|
63 | };
|
64 | exports.TextArea = React.forwardRef((props, ref) => (React.createElement(TextAreaBase, Object.assign({}, props, { innerRef: ref }))));
|
65 | exports.TextArea.displayName = 'TextArea';
|
66 |
|
\ | No newline at end of file |