"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.useTextInput = void 0;
var _react = _interopRequireDefault(require("react"));
const useTextInput = ({
  initialValue,
  maxLength,
  onChange
}) => {
  const [value, setValue] = _react.default.useState(initialValue || '');
  const charCount = maxLength ? maxLength - value.length : undefined;
  const handleChange = e => {
    const newValue = e.target.value;
    if (maxLength === undefined || maxLength && newValue.length <= maxLength) {
      setValue(newValue);
      onChange == null || onChange(newValue);
    }
  };
  return {
    value,
    charCount,
    handleChange
  };
};
exports.useTextInput = useTextInput;
//# sourceMappingURL=useTextInput.js.map