@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
33 lines • 1.84 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 { XMarkIcon } from "@navikt/aksel-icons";
import { Button } from "../button/index.js";
import { useRenameCSS } from "../theme/Theme.js";
import { useI18n } from "../util/i18n/i18n.hooks.js";
import { useModalContext } from "./Modal.context.js";
const ModalHeader = forwardRef((_a, ref) => {
var { children, className, closeButton = true } = _a, rest = __rest(_a, ["children", "className", "closeButton"]);
const { cn } = useRenameCSS();
const context = useModalContext();
const translate = useI18n("global");
return (React.createElement("div", Object.assign({}, rest, { ref: ref, className: cn("navds-modal__header", className) }),
context.closeHandler && closeButton && (React.createElement(Button, { type: "button", className: cn("navds-modal__button"), size: "small", variant: "tertiary-neutral", onKeyDown: (event) => {
/* Prevents autofocus used in combination with holding down keys from closing modal */
if (["Enter", " "].includes(event.key) && event.repeat) {
event.preventDefault();
}
}, onClick: context.closeHandler, icon: React.createElement(XMarkIcon, { title: translate("close") }) })),
children));
});
export default ModalHeader;
//# sourceMappingURL=ModalHeader.js.map