@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
25 lines • 2.81 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AvatarStandAlone = exports.AvatarStandAloneComponent = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const dot_1 = require("../../components/dot/dot");
const link_1 = require("../../components/link/link");
const text_1 = require("../../components/text/text");
const component_1 = require("../../components/text/types/component");
const aria_1 = require("../../utils/aria/aria");
const type_1 = require("../button/types/type");
const elementOrIcon_1 = require("../elementOrIcon/elementOrIcon");
const avatar_styled_1 = require("./avatar.styled");
const content_1 = require("./types/content");
const AvatarStandAloneComponent = ({ contentType, backgroundColor = content_1.AvatarBackgroundColor.COLOR_DEFAULT, image, onClick, styles, dataTestId = 'avatar', maxLengthInitials = 2, ...props }, ref) => {
const ariaProps = (0, aria_1.pickAriaProps)(props);
const drawContent = () => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [props.dot?.number && ((0, jsx_runtime_1.jsx)(avatar_styled_1.AvatarDotStyled, { children: (0, jsx_runtime_1.jsx)(dot_1.Dot, { ...props.dot }) })), contentType === content_1.AvatarContentType.WITH_ICON && ((0, jsx_runtime_1.jsx)(elementOrIcon_1.ElementOrIcon, { color: styles?.containerBackgroundColor?.[backgroundColor]?.contentColor, customIconStyles: styles?.avatar, ...props.icon })), contentType === content_1.AvatarContentType.WITH_INITIALS && ((0, jsx_runtime_1.jsx)(text_1.Text, { "aria-hidden": true, color: styles?.containerBackgroundColor?.[backgroundColor]?.contentColor, component: component_1.TextComponentType.SPAN, customTypography: styles?.initials, ...props.initials, children: props.initials?.content?.substring(0, maxLengthInitials) }))] }));
return props.link ? ((0, jsx_runtime_1.jsx)(avatar_styled_1.AvatarLinkStyled, { ref: ref, backgroundColor: backgroundColor, "data-testid": dataTestId, image: image, styles: styles, children: (0, jsx_runtime_1.jsx)(link_1.Link, { "aria-label": props['aria-label'], ...props.link, children: drawContent() }) })) : ((0, jsx_runtime_1.jsx)(avatar_styled_1.AvatarStyled, { ref: ref, as: onClick ? 'button' : 'div', backgroundColor: backgroundColor, "data-testid": dataTestId, image: image, styles: styles, type: onClick && type_1.ButtonType.BUTTON, onClick: onClick, ...ariaProps, children: drawContent() }));
};
exports.AvatarStandAloneComponent = AvatarStandAloneComponent;
exports.AvatarStandAlone = react_1.default.forwardRef(exports.AvatarStandAloneComponent);
//# sourceMappingURL=avatarStandAlone.js.map