@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
52 lines • 2.57 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 cl from "clsx";
import React, { forwardRef } from "react";
import { useRenameCSS, useThemeInternal } from "../../theme/Theme.js";
import { BodyShort } from "../../typography/index.js";
import { useId } from "../../util/index.js";
import { useI18n } from "../../util/i18n/i18n.hooks.js";
import { InlineMessageIcon } from "../icon/InlineMessageIcon.js";
/**
* InlineMessage is used to highlight short messages next to other content.
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/inline-message)
* @see 🏷️ {@link InlineMessageProps}
* @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support
* @example
* ```jsx
* <InlineMessage status="error">
* Inline Errormessage
* </InlineMessage>
* ```
*
* @example
* As a link
* ```jsx
* <InlineMessage status="error" as={Link} href="#">
* Inline Errormessage
* </InlineMessage>
* ```
*/
export const InlineMessage = forwardRef((_a, forwardedRef) => {
var { as: Component = "div", children, className, status, size = "medium" } = _a, restProps = __rest(_a, ["as", "children", "className", "status", "size"]);
const { cn } = useRenameCSS();
const themeContext = useThemeInternal(false);
const translate = useI18n("global");
const statusId = useId();
const contentId = useId();
return (React.createElement(BodyShort, Object.assign({ ref: forwardedRef, className: cn("navds-inline-message", className), "data-color": status === "error" ? "danger" : status }, restProps, { size: size, as: Component, "data-size": size }),
React.createElement(InlineMessageIcon, { status: status }),
status && (React.createElement(BodyShort, { id: statusId, "aria-hidden": true, visuallyHidden: true }, `${translate(status)}: `)),
React.createElement("span", { "data-color": themeContext === null || themeContext === void 0 ? void 0 : themeContext.color, id: contentId, "aria-labelledby": cl(statusId, contentId) }, children)));
});
export default InlineMessage;
//# sourceMappingURL=InlineMessage.js.map