@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
41 lines • 2.67 kB
JavaScript
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 { Floating } from "../../overlays/floating/Floating.js";
import { useRenameCSS } from "../../theme/Theme.js";
import { BodyShort, ErrorMessage, Label } from "../../typography/index.js";
import { ReadOnlyIconWithTitle } from "../ReadOnlyIcon.js";
import ComboboxWrapper from "./ComboboxWrapper.js";
import FilteredOptions from "./FilteredOptions/FilteredOptions.js";
import { useInputContext } from "./Input/Input.context.js";
import { InputController } from "./Input/InputController.js";
export const Combobox = forwardRef((props, ref) => {
const { className, hideLabel = false, description, label } = props, rest = __rest(props, ["className", "hideLabel", "description", "label"]);
const { cn } = useRenameCSS();
const { error, errorId, hasError, inputDescriptionId, inputProps, showErrorMsg, size = "medium", readOnly, } = useInputContext();
return (React.createElement(Floating, null,
React.createElement(ComboboxWrapper, { className: className, hasError: hasError, inputProps: inputProps, inputSize: size },
React.createElement(Label, { htmlFor: inputProps.id, size: size, className: cn("navds-form-field__label", {
"navds-sr-only": hideLabel,
}) },
readOnly && React.createElement(ReadOnlyIconWithTitle, null),
label),
!!description && (React.createElement(BodyShort, { as: "div", className: cn("navds-form-field__description", {
"navds-sr-only": hideLabel,
}), id: inputDescriptionId, size: size }, description)),
React.createElement("div", { className: cn("navds-combobox__wrapper") },
React.createElement(InputController, Object.assign({ ref: ref }, rest)),
React.createElement(FilteredOptions, null)),
React.createElement("div", { className: cn("navds-form-field__error"), id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && (React.createElement(ErrorMessage, { size: size, showIcon: true }, error))))));
});
export default Combobox;
//# sourceMappingURL=Combobox.js.map