import React, { forwardRef } from "react"; import { useThemeInternal } from "../../theme/Theme"; import { BodyLong } from "../../typography"; import { type OverridableComponent, useId } from "../../utils-external"; import { cl } from "../../utils/helpers"; import { useI18n } from "../../utils/i18n/i18n.hooks"; import { InlineMessageIcon } from "../icon/InlineMessageIcon"; interface InlineMessageProps extends React.HTMLAttributes { /** * InlineMessage status. */ status: "info" | "success" | "warning" | "error"; /** * InlineMessage size. * @default "medium" */ size?: "medium" | "small"; /** * "data-color" has no effect on InlineMessage. */ "data-color"?: never; } /** * 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 * * Inline Errormessage * * ``` * * @example * As a link * ```jsx * * Inline Errormessage * * ``` */ export const InlineMessage: OverridableComponent< InlineMessageProps, HTMLDivElement > = forwardRef( ( { as: Component = "div", children, className, status, size = "medium", ...restProps }: InlineMessageProps & { as?: React.ElementType }, forwardedRef, ) => { const themeContext = useThemeInternal(); const translate = useI18n("global"); const statusId = useId(); const contentId = useId(); return ( {status && ( {`${translate(status)}: `} )} {/** biome-ignore lint/a11y/useAriaPropsSupportedByRole: Testing shows that this works. */} {children} ); }, ); export default InlineMessage; export type { InlineMessageProps };