UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

40 lines 2.02 kB
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 } from "../../../typography/index.js"; import { cl } from "../../../utils/helpers/index.js"; import { useI18n } from "../../../utils/i18n/i18n.hooks.js"; import { useBaseAlert } from "../root/BaseAlertRoot.context.js"; import { BaseAlertStatusIcon } from "../root/BaseAlertRoot.utils.js"; /** * @see 🏷️ {@link BaseAlertHeaderProps} * @example * ```jsx * <BaseAlert> * <BaseAlert.Header icon={<InformationSquareIcon aria-hidden />}> * <BaseAlert.Title>Info title</BaseAlert.Title> * </BaseAlert.Header> * </BaseAlert> * ``` */ const BaseAlertHeader = forwardRef((_a, forwardedRef) => { var { children, className, icon } = _a, restProps = __rest(_a, ["children", "className", "icon"]); const { status, color, statusId } = useBaseAlert(); const translate = useI18n("global"); const headerIcon = icon !== null && icon !== void 0 ? icon : (status ? React.createElement(BaseAlertStatusIcon, { status: status }) : null); return (React.createElement("div", Object.assign({ ref: forwardedRef }, restProps, { "data-color": color, className: cl(className, "aksel-base-alert__header") }), headerIcon && (React.createElement("div", { className: "aksel-base-alert__icon" }, headerIcon)), status && (React.createElement(BodyShort, { id: statusId, "aria-hidden": true, visuallyHidden: true }, `${translate(status)}: `)), children)); }); export { BaseAlertHeader }; //# sourceMappingURL=BaseAlertHeader.js.map