@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
62 lines • 3.09 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 { useRenameCSS } from "../theme/Theme.js";
import { BodyLong } from "../typography/index.js";
import Bubble from "./Bubble.js";
export const VARIANTS = ["subtle", "info", "neutral"];
export const POSITIONS = ["left", "right"];
export const SIZES = ["medium", "small"];
/**
* A component for communicating a dialog between two or more parties.
*
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/chat)
* @see 🏷️ {@link ChatProps}
*
* @example
* ```jsx
* <Chat avatar="A" name="Alice" timestamp="01.01.21 14:00">
* <Chat.Bubble>Hello!</Chat.Bubble>
* <Chat.Bubble>How can I help you?</Chat.Bubble>
* </Chat>
* <Chat avatar="B" name="Bob" timestamp="01.01.21 14:01" position="right">
* <Chat.Bubble>Hi there!</Chat.Bubble>
* </Chat>
* ```
*/
export const Chat = forwardRef((_a, ref) => {
var { children, className, name, timestamp, avatar, position = "left", variant = "neutral", toptextPosition, size = "medium", toptextHeadingLevel = "3", "data-color": color } = _a, rest = __rest(_a, ["children", "className", "name", "timestamp", "avatar", "position", "variant", "toptextPosition", "size", "toptextHeadingLevel", "data-color"]);
const { cn } = useRenameCSS();
return (React.createElement("div", Object.assign({ ref: ref, className: cn("navds-chat", className, `navds-chat--${position}`, `navds-chat--top-text-${toptextPosition !== null && toptextPosition !== void 0 ? toptextPosition : position}`, `navds-chat--${size}`, `navds-chat--${variant}`), "data-color": color !== null && color !== void 0 ? color : variantToColor(variant) }, rest, { "data-variant": variant }),
avatar && (React.createElement("div", { className: cn("navds-chat__avatar"), "aria-hidden": true }, avatar)),
React.createElement(BodyLong, { as: "div", size: size, className: cn("navds-chat__bubble-wrapper") }, React.Children.map(children, (child, i) => {
if (!React.isValidElement(child)) {
return null;
}
return React.cloneElement(child, Object.assign({ name: name && i === 0 ? name : undefined, timestamp: timestamp && i === 0 ? timestamp : undefined, toptextHeadingLevel }, child.props));
}))));
});
function variantToColor(variant) {
switch (variant) {
case "neutral":
return "neutral";
case "subtle":
return "neutral";
case "info":
return "info";
default:
return "neutral";
}
}
Chat.Bubble = Bubble;
export default Chat;
//# sourceMappingURL=Chat.js.map