@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
101 lines • 4.87 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Chat = exports.SIZES = exports.POSITIONS = exports.VARIANTS = void 0;
const react_1 = __importStar(require("react"));
const Theme_1 = require("../theme/Theme");
const typography_1 = require("../typography");
const Bubble_1 = __importDefault(require("./Bubble"));
exports.VARIANTS = ["subtle", "info", "neutral"];
exports.POSITIONS = ["left", "right"];
exports.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>
* ```
*/
exports.Chat = (0, react_1.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 } = (0, Theme_1.useRenameCSS)();
return (react_1.default.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_1.default.createElement("div", { className: cn("navds-chat__avatar"), "aria-hidden": true }, avatar)),
react_1.default.createElement(typography_1.BodyLong, { as: "div", size: size, className: cn("navds-chat__bubble-wrapper") }, react_1.default.Children.map(children, (child, i) => {
if (!react_1.default.isValidElement(child)) {
return null;
}
return react_1.default.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";
}
}
exports.Chat.Bubble = Bubble_1.default;
exports.default = exports.Chat;
//# sourceMappingURL=Chat.js.map