@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
28 lines • 2 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 { useId } from "../../../utils-external/index.js";
import { cl } from "../../../utils/helpers/index.js";
import { useI18n } from "../../../utils/i18n/i18n.hooks.js";
import { BaseAlertProvider, } from "./BaseAlertRoot.context.js";
import { baseAlertStatusToDataColor } from "./BaseAlertRoot.utils.js";
const BaseAlert = forwardRef((_a, forwardedRef) => {
var { children, className, size = "medium", "data-color": dataColor, type, global = false, status, as: Component = "section", "aria-label": ariaLabel, role } = _a, restProps = __rest(_a, ["children", "className", "size", "data-color", "type", "global", "status", "as", "aria-label", "role"]);
const statusId = useId();
const translate = useI18n("global");
const alertColor = status ? baseAlertStatusToDataColor(status) : dataColor;
return (React.createElement(BaseAlertProvider, { size: size, status: status, color: alertColor, statusId: type === "strong" ? statusId : undefined },
React.createElement(Component, Object.assign({ "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : (!status || Component === "div" ? undefined : translate(status)), ref: forwardedRef }, restProps, { className: cl(className, "aksel-base-alert"), "data-size": size, "data-color": alertColor, "data-variant": type, "data-global": global }),
React.createElement("div", { role: role }, children))));
});
export { BaseAlert };
//# sourceMappingURL=BaseAlertRoot.js.map