react-lightning-design-system
Version:
Salesforce Lightning Design System components built with React
78 lines (76 loc) • 2.65 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["id", "className", "label", "required", "error", "cols", "tooltip", "tooltipIcon", "elementRef", "textareaRef", "onChange", "onValueChange", "readOnly", "htmlReadOnly"];
import React, { useId, useContext, useRef } from 'react';
import classnames from 'classnames';
import { Text } from './Text';
import { FormElement } from './FormElement';
import { FieldSetColumnContext } from './FieldSet';
import { useEventCallback } from './hooks';
import { createFC } from './common';
/**
*
*/
/**
*
*/
export var Textarea = createFC(function (props) {
var id = props.id,
className = props.className,
label = props.label,
required = props.required,
error = props.error,
cols = props.cols,
tooltip = props.tooltip,
tooltipIcon = props.tooltipIcon,
elementRef = props.elementRef,
textareaRef = props.textareaRef,
onChange_ = props.onChange,
onValueChange = props.onValueChange,
readOnly = props.readOnly,
htmlReadOnly = props.htmlReadOnly,
rprops = _objectWithoutProperties(props, _excluded);
var prevValueRef = useRef();
var onChange = useEventCallback(function (e) {
onChange_ === null || onChange_ === void 0 || onChange_(e);
onValueChange === null || onValueChange === void 0 || onValueChange(e.target.value, prevValueRef.current);
prevValueRef.current = e.target.value;
});
var _useContext = useContext(FieldSetColumnContext),
isFieldSetColumn = _useContext.isFieldSetColumn;
var errorId = useId();
var taClassNames = classnames(className, 'slds-textarea');
var textareaElem = readOnly ? /*#__PURE__*/React.createElement(Text, {
id: id,
type: "regular",
category: "body",
className: "slds-form-element__static"
}, rprops.value) : /*#__PURE__*/React.createElement("textarea", _extends({
id: id,
ref: textareaRef,
className: taClassNames,
readOnly: htmlReadOnly
}, rprops, {
onChange: onChange,
"aria-describedby": error ? errorId : undefined
}));
if (isFieldSetColumn || label || required || error || cols) {
var formElemProps = {
controlId: id,
label: label,
required: required,
error: error,
errorId: errorId,
cols: cols,
tooltip: tooltip,
tooltipIcon: tooltipIcon,
elementRef: elementRef,
readOnly: readOnly
};
return /*#__PURE__*/React.createElement(FormElement, formElemProps, textareaElem);
}
return textareaElem;
}, {
isFormElement: true
});
//# sourceMappingURL=Textarea.js.map