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, { forwardRef } from "react";
import { BodyShort, ErrorMessage, Label } from "../../typography/index.js";
import { omit } from "../../utils-external/index.js";
import { cl } from "../../utils/helpers/index.js";
import { ReadOnlyIcon } from "../ReadOnlyIcon.js";
import { useFormField } from "../useFormField.js";
/**
 * A component that displays a text input field with a label.
 *
 * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/textfield)
 * @see 🏷️ {@link TextFieldProps}
 *
 * @example
 * ```jsx
 * <TextField label="Har du noen tilbakemeldinger?" />
 * ```
 */
export const TextField = forwardRef((props, ref) => {
    const { inputProps, errorId, showErrorMsg, hasError, size, inputDescriptionId, } = useFormField(props, "textField");
    const { label, className, description, htmlSize, hideLabel = false, type = "text", readOnly } = props, rest = __rest(props, ["label", "className", "description", "htmlSize", "hideLabel", "type", "readOnly"]);
    return (React.createElement("div", { className: cl(className, "aksel-form-field", `aksel-form-field--${size}`, {
            "aksel-text-field--error": hasError,
            "aksel-text-field--disabled": !!inputProps.disabled,
            "aksel-form-field--disabled": !!inputProps.disabled,
            "aksel-form-field--readonly": readOnly,
            "aksel-text-field--readonly": readOnly,
        }) },
        React.createElement(Label, { htmlFor: inputProps.id, size: size, className: cl("aksel-form-field__label", {
                "aksel-sr-only": hideLabel,
            }) },
            readOnly && React.createElement(ReadOnlyIcon, null),
            label),
        !!description && (React.createElement(BodyShort, { className: cl("aksel-form-field__description", {
                "aksel-sr-only": hideLabel,
            }), id: inputDescriptionId, size: size, as: "div" }, description)),
        React.createElement("input", Object.assign({}, omit(rest, ["error", "errorId", "size"]), inputProps, { ref: ref, type: type, readOnly: readOnly, className: cl("aksel-text-field__input", "aksel-body-short", `aksel-body-short--${size !== null && size !== void 0 ? size : "medium"}`), size: htmlSize })),
        React.createElement("div", { className: "aksel-form-field__error", id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && (React.createElement(ErrorMessage, { size: size, showIcon: true }, props.error)))));
});
export default TextField;
//# sourceMappingURL=TextField.js.map