var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React from 'react';
import PropTypes from 'prop-types';
// Adapted from https://codepen.io/Momciloo/pen/bpyMbB
var getTextWidth = function (_a) {
    var className = _a.className, value = _a.value;
    if (!value) {
        return 0;
    }
    var testEl = document.createElement('span');
    testEl.className = className;
    testEl.textContent = value;
    // Let white space expand width
    testEl.style.whiteSpace = 'pre';
    // Render off-screen with no opacity so this doesn't flash in and appear for a frame
    testEl.style.position = 'fixed';
    testEl.style.left = '200vw';
    testEl.style.opacity = '0';
    // Undo any width-related styles so the text can expand as far as it needs to get a true width measurement
    testEl.style.minWidth = '0';
    testEl.style.width = 'auto';
    testEl.style.maxWidth = 'none';
    document.body.appendChild(testEl);
    var width = testEl.getBoundingClientRect().width;
    testEl.remove();
    return width;
};
var AutoExpandTextInput = function (_a) {
    var className = _a.className, defaultWidth = _a.defaultWidth, onChange = _a.onChange, value = _a.value, otherProps = __rest(_a, ["className", "defaultWidth", "onChange", "value"]);
    var width = getTextWidth({
        className: className,
        value: value,
    });
    return (React.createElement("input", __assign({ className: className, onChange: onChange, style: {
            width: width,
        }, value: value }, otherProps)));
};
AutoExpandTextInput.propTypes = {
    className: PropTypes.string,
    defaultWidth: PropTypes.number,
    onChange: PropTypes.func.isRequired,
    value: PropTypes.string.isRequired,
};
AutoExpandTextInput.defaultProps = {
    className: '',
    defaultWidth: null,
    onChange: getTextWidth,
};
export default AutoExpandTextInput;
//# sourceMappingURL=AutoExpandTextInput.js.map