@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
42 lines • 1.85 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { STYLES_NAME } from '../../constants/stylesName/stylesName';
import { useStyles } from '../../hooks/useStyles/useStyles';
import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary';
import { FallbackComponent } from '../../provider/errorBoundary/fallbackComponent';
import { AvatarStandAlone } from './avatarStandAlone';
import { AvatarContentType } from './types/content';
const AvatarComponent = React.forwardRef(({ icon, initials, image, size, cts, ...props }, ref) => {
const styles = useStyles(STYLES_NAME.AVATAR, size, cts);
let contentType = AvatarContentType.WITH_ICON;
if (icon) {
contentType = AvatarContentType.WITH_ICON;
}
if (initials) {
contentType = AvatarContentType.WITH_INITIALS;
}
if (image) {
contentType = AvatarContentType.WITH_IMAGE;
}
const contentStyles = styles[contentType];
return (_jsx(AvatarStandAlone, { ...props, ref: ref, contentType: contentType, icon: icon, image: image, initials: initials, styles: contentStyles }));
});
AvatarComponent.displayName = 'AvatarComponent';
const AvatarBoundary = (props, ref) => (_jsx(ErrorBoundary, { fallBackComponent: _jsx(FallbackComponent, { children: _jsx(AvatarStandAlone, { ...props, ref: ref }) }), children: _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.forwardRef(AvatarBoundary);
export { Avatar };
//# sourceMappingURL=avatar.js.map