UNPKG

@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

48 lines 2.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Avatar = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const stylesName_1 = require("../../constants/stylesName/stylesName"); const useStyles_1 = require("../../hooks/useStyles/useStyles"); const errorBoundary_1 = require("../../provider/errorBoundary/errorBoundary"); const fallbackComponent_1 = require("../../provider/errorBoundary/fallbackComponent"); const avatarStandAlone_1 = require("./avatarStandAlone"); const content_1 = require("./types/content"); const AvatarComponent = react_1.default.forwardRef(({ icon, initials, image, size, cts, ...props }, ref) => { const styles = (0, useStyles_1.useStyles)(stylesName_1.STYLES_NAME.AVATAR, size, cts); let contentType = content_1.AvatarContentType.WITH_ICON; if (icon) { contentType = content_1.AvatarContentType.WITH_ICON; } if (initials) { contentType = content_1.AvatarContentType.WITH_INITIALS; } if (image) { contentType = content_1.AvatarContentType.WITH_IMAGE; } const contentStyles = styles[contentType]; return ((0, jsx_runtime_1.jsx)(avatarStandAlone_1.AvatarStandAlone, { ...props, ref: ref, contentType: contentType, icon: icon, image: image, initials: initials, styles: contentStyles })); }); AvatarComponent.displayName = 'AvatarComponent'; const AvatarBoundary = (props, ref) => ((0, jsx_runtime_1.jsx)(errorBoundary_1.ErrorBoundary, { fallBackComponent: (0, jsx_runtime_1.jsx)(fallbackComponent_1.FallbackComponent, { children: (0, jsx_runtime_1.jsx)(avatarStandAlone_1.AvatarStandAlone, { ...props, ref: ref }) }), children: (0, jsx_runtime_1.jsx)(AvatarComponent, { ...props, ref: ref }) })); /** * @description * Avatar component is a component that shows an icon, image or initials. * @param {React.PropsWithChildren<IAvatar<S>>} props * @returns {JSX.Element} * @example * <Avatar * dataTestId="avatar" * icon={<Icon name="user" />} * initials="JD" * image="https://www.w3schools.com/howto/img_avatar.png" * size="M" * /> */ const Avatar = react_1.default.forwardRef(AvatarBoundary); exports.Avatar = Avatar; //# sourceMappingURL=avatar.js.map