"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.TextareaControl = void 0;
var _compose = require("@wordpress/compose");
var _element = require("@wordpress/element");
var _baseControl = _interopRequireDefault(require("../base-control"));
var _textareaControlStyles = require("./styles/textarea-control-styles");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function UnforwardedTextareaControl(props, ref) {
  const {
    __nextHasNoMarginBottom,
    label,
    hideLabelFromVision,
    value,
    help,
    onChange,
    rows = 4,
    className,
    ...additionalProps
  } = props;
  const instanceId = (0, _compose.useInstanceId)(TextareaControl);
  const id = `inspector-textarea-control-${instanceId}`;
  const onChangeValue = event => onChange(event.target.value);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_baseControl.default, {
    __nextHasNoMarginBottom: __nextHasNoMarginBottom,
    __associatedWPComponentName: "TextareaControl",
    label: label,
    hideLabelFromVision: hideLabelFromVision,
    id: id,
    help: help,
    className: className,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_textareaControlStyles.StyledTextarea, {
      className: "components-textarea-control__input",
      id: id,
      rows: rows,
      onChange: onChangeValue,
      "aria-describedby": !!help ? id + '__help' : undefined,
      value: value,
      ref: ref,
      ...additionalProps
    })
  });
}

/**
 * TextareaControls are TextControls that allow for multiple lines of text, and
 * wrap overflow text onto a new line. They are a fixed height and scroll
 * vertically when the cursor reaches the bottom of the field.
 *
 * ```jsx
 * import { TextareaControl } from '@wordpress/components';
 * import { useState } from '@wordpress/element';
 *
 * const MyTextareaControl = () => {
 *   const [ text, setText ] = useState( '' );
 *
 *   return (
 *     <TextareaControl
 *       __nextHasNoMarginBottom
 *       label="Text"
 *       help="Enter some text"
 *       value={ text }
 *       onChange={ ( value ) => setText( value ) }
 *     />
 *   );
 * };
 * ```
 */
const TextareaControl = exports.TextareaControl = (0, _element.forwardRef)(UnforwardedTextareaControl);
var _default = exports.default = TextareaControl;
//# sourceMappingURL=index.js.map